-rw-r--r-- | kabc/addressbook.cpp | 70 | ||||
-rw-r--r-- | kabc/addressbook.h | 5 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 20 | ||||
-rw-r--r-- | kaddressbook/kabcore.h | 2 | ||||
-rw-r--r-- | kaddressbook/xxport/vcard_xxport.cpp | 1 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.cpp | 5 | ||||
-rw-r--r-- | libkdepim/ksyncmanager.h | 5 |
7 files changed, 90 insertions, 18 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 5fb49eb..295cf03 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,676 +1,734 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /*US | 28 | /*US |
29 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | ||
42 | #include <qfile.h> | ||
41 | 43 | ||
42 | #include <kglobal.h> | 44 | #include <kglobal.h> |
43 | #include <klocale.h> | 45 | #include <klocale.h>> |
46 | #include <kmessagebox.h> | ||
44 | #include <kdebug.h> | 47 | #include <kdebug.h> |
45 | #include <libkcal/syncdefines.h> | 48 | #include <libkcal/syncdefines.h> |
46 | #include "addressbook.h" | 49 | #include "addressbook.h" |
47 | #include "resource.h" | 50 | #include "resource.h" |
51 | #include "vcardconverter.h" | ||
52 | #include "vcardparser/vcardtool.h" | ||
48 | 53 | ||
49 | //US #include "addressbook.moc" | 54 | //US #include "addressbook.moc" |
50 | 55 | ||
51 | using namespace KABC; | 56 | using namespace KABC; |
52 | 57 | ||
53 | struct AddressBook::AddressBookData | 58 | struct AddressBook::AddressBookData |
54 | { | 59 | { |
55 | Addressee::List mAddressees; | 60 | Addressee::List mAddressees; |
56 | Addressee::List mRemovedAddressees; | 61 | Addressee::List mRemovedAddressees; |
57 | Field::List mAllFields; | 62 | Field::List mAllFields; |
58 | KConfig *mConfig; | 63 | KConfig *mConfig; |
59 | KRES::Manager<Resource> *mManager; | 64 | KRES::Manager<Resource> *mManager; |
60 | //US ErrorHandler *mErrorHandler; | 65 | //US ErrorHandler *mErrorHandler; |
61 | }; | 66 | }; |
62 | 67 | ||
63 | struct AddressBook::Iterator::IteratorData | 68 | struct AddressBook::Iterator::IteratorData |
64 | { | 69 | { |
65 | Addressee::List::Iterator mIt; | 70 | Addressee::List::Iterator mIt; |
66 | }; | 71 | }; |
67 | 72 | ||
68 | struct AddressBook::ConstIterator::ConstIteratorData | 73 | struct AddressBook::ConstIterator::ConstIteratorData |
69 | { | 74 | { |
70 | Addressee::List::ConstIterator mIt; | 75 | Addressee::List::ConstIterator mIt; |
71 | }; | 76 | }; |
72 | 77 | ||
73 | AddressBook::Iterator::Iterator() | 78 | AddressBook::Iterator::Iterator() |
74 | { | 79 | { |
75 | d = new IteratorData; | 80 | d = new IteratorData; |
76 | } | 81 | } |
77 | 82 | ||
78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 83 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
79 | { | 84 | { |
80 | d = new IteratorData; | 85 | d = new IteratorData; |
81 | d->mIt = i.d->mIt; | 86 | d->mIt = i.d->mIt; |
82 | } | 87 | } |
83 | 88 | ||
84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 89 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
85 | { | 90 | { |
86 | if( this == &i ) return *this; // guard against self assignment | 91 | if( this == &i ) return *this; // guard against self assignment |
87 | delete d; // delete the old data the Iterator was completely constructed before | 92 | delete d; // delete the old data the Iterator was completely constructed before |
88 | d = new IteratorData; | 93 | d = new IteratorData; |
89 | d->mIt = i.d->mIt; | 94 | d->mIt = i.d->mIt; |
90 | return *this; | 95 | return *this; |
91 | } | 96 | } |
92 | 97 | ||
93 | AddressBook::Iterator::~Iterator() | 98 | AddressBook::Iterator::~Iterator() |
94 | { | 99 | { |
95 | delete d; | 100 | delete d; |
96 | } | 101 | } |
97 | 102 | ||
98 | const Addressee &AddressBook::Iterator::operator*() const | 103 | const Addressee &AddressBook::Iterator::operator*() const |
99 | { | 104 | { |
100 | return *(d->mIt); | 105 | return *(d->mIt); |
101 | } | 106 | } |
102 | 107 | ||
103 | Addressee &AddressBook::Iterator::operator*() | 108 | Addressee &AddressBook::Iterator::operator*() |
104 | { | 109 | { |
105 | return *(d->mIt); | 110 | return *(d->mIt); |
106 | } | 111 | } |
107 | 112 | ||
108 | Addressee *AddressBook::Iterator::operator->() | 113 | Addressee *AddressBook::Iterator::operator->() |
109 | { | 114 | { |
110 | return &(*(d->mIt)); | 115 | return &(*(d->mIt)); |
111 | } | 116 | } |
112 | 117 | ||
113 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 118 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
114 | { | 119 | { |
115 | (d->mIt)++; | 120 | (d->mIt)++; |
116 | return *this; | 121 | return *this; |
117 | } | 122 | } |
118 | 123 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 124 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
120 | { | 125 | { |
121 | (d->mIt)++; | 126 | (d->mIt)++; |
122 | return *this; | 127 | return *this; |
123 | } | 128 | } |
124 | 129 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 130 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
126 | { | 131 | { |
127 | (d->mIt)--; | 132 | (d->mIt)--; |
128 | return *this; | 133 | return *this; |
129 | } | 134 | } |
130 | 135 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 136 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
132 | { | 137 | { |
133 | (d->mIt)--; | 138 | (d->mIt)--; |
134 | return *this; | 139 | return *this; |
135 | } | 140 | } |
136 | 141 | ||
137 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 142 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
138 | { | 143 | { |
139 | return ( d->mIt == it.d->mIt ); | 144 | return ( d->mIt == it.d->mIt ); |
140 | } | 145 | } |
141 | 146 | ||
142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 147 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
143 | { | 148 | { |
144 | return ( d->mIt != it.d->mIt ); | 149 | return ( d->mIt != it.d->mIt ); |
145 | } | 150 | } |
146 | 151 | ||
147 | 152 | ||
148 | AddressBook::ConstIterator::ConstIterator() | 153 | AddressBook::ConstIterator::ConstIterator() |
149 | { | 154 | { |
150 | d = new ConstIteratorData; | 155 | d = new ConstIteratorData; |
151 | } | 156 | } |
152 | 157 | ||
153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 158 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
154 | { | 159 | { |
155 | d = new ConstIteratorData; | 160 | d = new ConstIteratorData; |
156 | d->mIt = i.d->mIt; | 161 | d->mIt = i.d->mIt; |
157 | } | 162 | } |
158 | 163 | ||
159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 164 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
160 | { | 165 | { |
161 | if( this == &i ) return *this; // guard for self assignment | 166 | if( this == &i ) return *this; // guard for self assignment |
162 | delete d; // delete the old data because the Iterator was really constructed before | 167 | delete d; // delete the old data because the Iterator was really constructed before |
163 | d = new ConstIteratorData; | 168 | d = new ConstIteratorData; |
164 | d->mIt = i.d->mIt; | 169 | d->mIt = i.d->mIt; |
165 | return *this; | 170 | return *this; |
166 | } | 171 | } |
167 | 172 | ||
168 | AddressBook::ConstIterator::~ConstIterator() | 173 | AddressBook::ConstIterator::~ConstIterator() |
169 | { | 174 | { |
170 | delete d; | 175 | delete d; |
171 | } | 176 | } |
172 | 177 | ||
173 | const Addressee &AddressBook::ConstIterator::operator*() const | 178 | const Addressee &AddressBook::ConstIterator::operator*() const |
174 | { | 179 | { |
175 | return *(d->mIt); | 180 | return *(d->mIt); |
176 | } | 181 | } |
177 | 182 | ||
178 | const Addressee* AddressBook::ConstIterator::operator->() const | 183 | const Addressee* AddressBook::ConstIterator::operator->() const |
179 | { | 184 | { |
180 | return &(*(d->mIt)); | 185 | return &(*(d->mIt)); |
181 | } | 186 | } |
182 | 187 | ||
183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
184 | { | 189 | { |
185 | (d->mIt)++; | 190 | (d->mIt)++; |
186 | return *this; | 191 | return *this; |
187 | } | 192 | } |
188 | 193 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
190 | { | 195 | { |
191 | (d->mIt)++; | 196 | (d->mIt)++; |
192 | return *this; | 197 | return *this; |
193 | } | 198 | } |
194 | 199 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
196 | { | 201 | { |
197 | (d->mIt)--; | 202 | (d->mIt)--; |
198 | return *this; | 203 | return *this; |
199 | } | 204 | } |
200 | 205 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 206 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
202 | { | 207 | { |
203 | (d->mIt)--; | 208 | (d->mIt)--; |
204 | return *this; | 209 | return *this; |
205 | } | 210 | } |
206 | 211 | ||
207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
208 | { | 213 | { |
209 | return ( d->mIt == it.d->mIt ); | 214 | return ( d->mIt == it.d->mIt ); |
210 | } | 215 | } |
211 | 216 | ||
212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 217 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
213 | { | 218 | { |
214 | return ( d->mIt != it.d->mIt ); | 219 | return ( d->mIt != it.d->mIt ); |
215 | } | 220 | } |
216 | 221 | ||
217 | 222 | ||
218 | AddressBook::AddressBook() | 223 | AddressBook::AddressBook() |
219 | { | 224 | { |
220 | init(0, "contact"); | 225 | init(0, "contact"); |
221 | } | 226 | } |
222 | 227 | ||
223 | AddressBook::AddressBook( const QString &config ) | 228 | AddressBook::AddressBook( const QString &config ) |
224 | { | 229 | { |
225 | init(config, "contact"); | 230 | init(config, "contact"); |
226 | } | 231 | } |
227 | 232 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 233 | AddressBook::AddressBook( const QString &config, const QString &family ) |
229 | { | 234 | { |
230 | init(config, family); | 235 | init(config, family); |
231 | 236 | ||
232 | } | 237 | } |
233 | 238 | ||
234 | // the default family is "contact" | 239 | // the default family is "contact" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 240 | void AddressBook::init(const QString &config, const QString &family ) |
236 | { | 241 | { |
237 | blockLSEchange = false; | 242 | blockLSEchange = false; |
238 | d = new AddressBookData; | 243 | d = new AddressBookData; |
239 | QString fami = family; | 244 | QString fami = family; |
240 | if (config != 0) { | 245 | if (config != 0) { |
241 | if ( family == "syncContact" ) { | 246 | if ( family == "syncContact" ) { |
242 | qDebug("creating sync config "); | 247 | qDebug("creating sync config "); |
243 | fami = "contact"; | 248 | fami = "contact"; |
244 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 249 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
245 | con->setGroup( "General" ); | 250 | con->setGroup( "General" ); |
246 | con->writeEntry( "ResourceKeys", QString("sync") ); | 251 | con->writeEntry( "ResourceKeys", QString("sync") ); |
247 | con->writeEntry( "Standard", QString("sync") ); | 252 | con->writeEntry( "Standard", QString("sync") ); |
248 | con->setGroup( "Resource_sync" ); | 253 | con->setGroup( "Resource_sync" ); |
249 | con->writeEntry( "FileName", config ); | 254 | con->writeEntry( "FileName", config ); |
250 | con->writeEntry( "FileFormat", QString("vcard") ); | 255 | con->writeEntry( "FileFormat", QString("vcard") ); |
251 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 256 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
252 | con->writeEntry( "ResourceName", QString("sync_res") ); | 257 | con->writeEntry( "ResourceName", QString("sync_res") ); |
253 | if ( config.right(4) == ".xml" ) | 258 | if ( config.right(4) == ".xml" ) |
254 | con->writeEntry( "ResourceType", QString("qtopia") ); | 259 | con->writeEntry( "ResourceType", QString("qtopia") ); |
255 | else if ( config == "sharp" ) { | 260 | else if ( config == "sharp" ) { |
256 | con->writeEntry( "ResourceType", QString("sharp") ); | 261 | con->writeEntry( "ResourceType", QString("sharp") ); |
257 | } else { | 262 | } else { |
258 | con->writeEntry( "ResourceType", QString("file") ); | 263 | con->writeEntry( "ResourceType", QString("file") ); |
259 | } | 264 | } |
260 | //con->sync(); | 265 | //con->sync(); |
261 | d->mConfig = con; | 266 | d->mConfig = con; |
262 | } | 267 | } |
263 | else | 268 | else |
264 | d->mConfig = new KConfig( locateLocal("config", config) ); | 269 | d->mConfig = new KConfig( locateLocal("config", config) ); |
265 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 270 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
266 | } | 271 | } |
267 | else { | 272 | else { |
268 | d->mConfig = 0; | 273 | d->mConfig = 0; |
269 | // qDebug("AddressBook::init 1 config=0"); | 274 | // qDebug("AddressBook::init 1 config=0"); |
270 | } | 275 | } |
271 | 276 | ||
272 | //US d->mErrorHandler = 0; | 277 | //US d->mErrorHandler = 0; |
273 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 278 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
274 | d->mManager->readConfig( d->mConfig ); | 279 | d->mManager->readConfig( d->mConfig ); |
275 | if ( family == "syncContact" ) { | 280 | if ( family == "syncContact" ) { |
276 | KRES::Manager<Resource> *manager = d->mManager; | 281 | KRES::Manager<Resource> *manager = d->mManager; |
277 | KRES::Manager<Resource>::ActiveIterator it; | 282 | KRES::Manager<Resource>::ActiveIterator it; |
278 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 283 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
279 | (*it)->setAddressBook( this ); | 284 | (*it)->setAddressBook( this ); |
280 | if ( !(*it)->open() ) | 285 | if ( !(*it)->open() ) |
281 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 286 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
282 | } | 287 | } |
283 | Resource *res = standardResource(); | 288 | Resource *res = standardResource(); |
284 | if ( !res ) { | 289 | if ( !res ) { |
285 | qDebug("ERROR: no standard resource"); | 290 | qDebug("ERROR: no standard resource"); |
286 | res = manager->createResource( "file" ); | 291 | res = manager->createResource( "file" ); |
287 | if ( res ) | 292 | if ( res ) |
288 | { | 293 | { |
289 | addResource( res ); | 294 | addResource( res ); |
290 | } | 295 | } |
291 | else | 296 | else |
292 | qDebug(" No resource available!!!"); | 297 | qDebug(" No resource available!!!"); |
293 | } | 298 | } |
294 | setStandardResource( res ); | 299 | setStandardResource( res ); |
295 | manager->writeConfig(); | 300 | manager->writeConfig(); |
296 | } | 301 | } |
297 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 302 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
298 | "X-Department", "KADDRESSBOOK" ); | 303 | "X-Department", "KADDRESSBOOK" ); |
299 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
300 | "X-Profession", "KADDRESSBOOK" ); | 305 | "X-Profession", "KADDRESSBOOK" ); |
301 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
302 | "X-AssistantsName", "KADDRESSBOOK" ); | 307 | "X-AssistantsName", "KADDRESSBOOK" ); |
303 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
304 | "X-ManagersName", "KADDRESSBOOK" ); | 309 | "X-ManagersName", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 310 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
306 | "X-SpousesName", "KADDRESSBOOK" ); | 311 | "X-SpousesName", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
308 | "X-Office", "KADDRESSBOOK" ); | 313 | "X-Office", "KADDRESSBOOK" ); |
309 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
310 | "X-IMAddress", "KADDRESSBOOK" ); | 315 | "X-IMAddress", "KADDRESSBOOK" ); |
311 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
312 | "X-Anniversary", "KADDRESSBOOK" ); | 317 | "X-Anniversary", "KADDRESSBOOK" ); |
313 | 318 | ||
314 | //US added this field to become compatible with Opie/qtopia addressbook | 319 | //US added this field to become compatible with Opie/qtopia addressbook |
315 | // values can be "female" or "male" or "". An empty field represents undefined. | 320 | // values can be "female" or "male" or "". An empty field represents undefined. |
316 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
317 | "X-Gender", "KADDRESSBOOK" ); | 322 | "X-Gender", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
319 | "X-Children", "KADDRESSBOOK" ); | 324 | "X-Children", "KADDRESSBOOK" ); |
320 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
321 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
322 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
323 | "X-ExternalID", "KADDRESSBOOK" ); | 328 | "X-ExternalID", "KADDRESSBOOK" ); |
324 | } | 329 | } |
325 | 330 | ||
326 | AddressBook::~AddressBook() | 331 | AddressBook::~AddressBook() |
327 | { | 332 | { |
328 | delete d->mConfig; d->mConfig = 0; | 333 | delete d->mConfig; d->mConfig = 0; |
329 | delete d->mManager; d->mManager = 0; | 334 | delete d->mManager; d->mManager = 0; |
330 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
331 | delete d; d = 0; | 336 | delete d; d = 0; |
332 | } | 337 | } |
333 | 338 | ||
334 | bool AddressBook::load() | 339 | bool AddressBook::load() |
335 | { | 340 | { |
336 | 341 | ||
337 | 342 | ||
338 | clear(); | 343 | clear(); |
339 | 344 | ||
340 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
341 | bool ok = true; | 346 | bool ok = true; |
342 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
343 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
344 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
345 | ok = false; | 350 | ok = false; |
346 | } | 351 | } |
347 | 352 | ||
348 | // mark all addressees as unchanged | 353 | // mark all addressees as unchanged |
349 | Addressee::List::Iterator addrIt; | 354 | Addressee::List::Iterator addrIt; |
350 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
351 | (*addrIt).setChanged( false ); | 356 | (*addrIt).setChanged( false ); |
352 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
353 | if ( !id.isEmpty() ) { | 358 | if ( !id.isEmpty() ) { |
354 | //qDebug("setId aa %s ", id.latin1()); | 359 | //qDebug("setId aa %s ", id.latin1()); |
355 | (*addrIt).setIDStr(id ); | 360 | (*addrIt).setIDStr(id ); |
356 | } | 361 | } |
357 | } | 362 | } |
358 | blockLSEchange = true; | 363 | blockLSEchange = true; |
359 | return ok; | 364 | return ok; |
360 | } | 365 | } |
361 | 366 | ||
362 | bool AddressBook::save( Ticket *ticket ) | 367 | bool AddressBook::save( Ticket *ticket ) |
363 | { | 368 | { |
364 | kdDebug(5700) << "AddressBook::save()"<< endl; | 369 | kdDebug(5700) << "AddressBook::save()"<< endl; |
365 | 370 | ||
366 | if ( ticket->resource() ) { | 371 | if ( ticket->resource() ) { |
367 | deleteRemovedAddressees(); | 372 | deleteRemovedAddressees(); |
368 | return ticket->resource()->save( ticket ); | 373 | return ticket->resource()->save( ticket ); |
369 | } | 374 | } |
370 | 375 | ||
371 | return false; | 376 | return false; |
372 | } | 377 | } |
378 | void AddressBook::export2File( QString fileName ) | ||
379 | { | ||
380 | |||
381 | QFile outFile( fileName ); | ||
382 | if ( !outFile.open( IO_WriteOnly ) ) { | ||
383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | ||
384 | KMessageBox::error( 0, text.arg( fileName ) ); | ||
385 | return ; | ||
386 | } | ||
387 | QTextStream t( &outFile ); | ||
388 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
389 | Iterator it; | ||
390 | KABC::VCardConverter::Version version; | ||
391 | version = KABC::VCardConverter::v3_0; | ||
392 | for ( it = begin(); it != end(); ++it ) { | ||
393 | if ( !(*it).IDStr().isEmpty() ) { | ||
394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | ||
395 | } | ||
396 | KABC::VCardConverter converter; | ||
397 | QString vcard; | ||
398 | //Resource *resource() const; | ||
399 | converter.addresseeToVCard( *it, vcard, version ); | ||
400 | t << vcard << "\r\n"; | ||
401 | } | ||
402 | outFile.close(); | ||
403 | } | ||
404 | void AddressBook::importFromFile( QString fileName ) | ||
405 | { | ||
406 | |||
407 | KABC::Addressee::List list; | ||
408 | QFile file( fileName ); | ||
409 | |||
410 | file.open( IO_ReadOnly ); | ||
411 | QByteArray rawData = file.readAll(); | ||
412 | file.close(); | ||
413 | |||
414 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | ||
415 | KABC::VCardTool tool; | ||
416 | list = tool.parseVCards( data ); | ||
417 | |||
418 | KABC::Addressee::List::Iterator it; | ||
419 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
420 | (*it).setResource( 0 ); | ||
421 | insertAddressee( (*it), false, true ); | ||
422 | } | ||
423 | |||
424 | } | ||
425 | |||
373 | bool AddressBook::saveAB() | 426 | bool AddressBook::saveAB() |
374 | { | 427 | { |
375 | bool ok = true; | 428 | bool ok = true; |
376 | 429 | ||
377 | deleteRemovedAddressees(); | 430 | deleteRemovedAddressees(); |
378 | Iterator ait; | 431 | Iterator ait; |
379 | for ( ait = begin(); ait != end(); ++ait ) { | 432 | for ( ait = begin(); ait != end(); ++ait ) { |
380 | if ( !(*ait).IDStr().isEmpty() ) { | 433 | if ( !(*ait).IDStr().isEmpty() ) { |
381 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 434 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
382 | } | 435 | } |
383 | } | 436 | } |
384 | KRES::Manager<Resource>::ActiveIterator it; | 437 | KRES::Manager<Resource>::ActiveIterator it; |
385 | KRES::Manager<Resource> *manager = d->mManager; | 438 | KRES::Manager<Resource> *manager = d->mManager; |
386 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 439 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
387 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 440 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
388 | Ticket *ticket = requestSaveTicket( *it ); | 441 | Ticket *ticket = requestSaveTicket( *it ); |
389 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 442 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
390 | if ( !ticket ) { | 443 | if ( !ticket ) { |
391 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 444 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
392 | .arg( (*it)->resourceName() ) ); | 445 | .arg( (*it)->resourceName() ) ); |
393 | return false; | 446 | return false; |
394 | } | 447 | } |
395 | 448 | ||
396 | //if ( !save( ticket ) ) | 449 | //if ( !save( ticket ) ) |
397 | if ( ticket->resource() ) { | 450 | if ( ticket->resource() ) { |
398 | if ( ! ticket->resource()->save( ticket ) ) | 451 | if ( ! ticket->resource()->save( ticket ) ) |
399 | ok = false; | 452 | ok = false; |
400 | } else | 453 | } else |
401 | ok = false; | 454 | ok = false; |
402 | 455 | ||
403 | } | 456 | } |
404 | } | 457 | } |
405 | return ok; | 458 | return ok; |
406 | } | 459 | } |
407 | 460 | ||
408 | AddressBook::Iterator AddressBook::begin() | 461 | AddressBook::Iterator AddressBook::begin() |
409 | { | 462 | { |
410 | Iterator it = Iterator(); | 463 | Iterator it = Iterator(); |
411 | it.d->mIt = d->mAddressees.begin(); | 464 | it.d->mIt = d->mAddressees.begin(); |
412 | return it; | 465 | return it; |
413 | } | 466 | } |
414 | 467 | ||
415 | AddressBook::ConstIterator AddressBook::begin() const | 468 | AddressBook::ConstIterator AddressBook::begin() const |
416 | { | 469 | { |
417 | ConstIterator it = ConstIterator(); | 470 | ConstIterator it = ConstIterator(); |
418 | it.d->mIt = d->mAddressees.begin(); | 471 | it.d->mIt = d->mAddressees.begin(); |
419 | return it; | 472 | return it; |
420 | } | 473 | } |
421 | 474 | ||
422 | AddressBook::Iterator AddressBook::end() | 475 | AddressBook::Iterator AddressBook::end() |
423 | { | 476 | { |
424 | Iterator it = Iterator(); | 477 | Iterator it = Iterator(); |
425 | it.d->mIt = d->mAddressees.end(); | 478 | it.d->mIt = d->mAddressees.end(); |
426 | return it; | 479 | return it; |
427 | } | 480 | } |
428 | 481 | ||
429 | AddressBook::ConstIterator AddressBook::end() const | 482 | AddressBook::ConstIterator AddressBook::end() const |
430 | { | 483 | { |
431 | ConstIterator it = ConstIterator(); | 484 | ConstIterator it = ConstIterator(); |
432 | it.d->mIt = d->mAddressees.end(); | 485 | it.d->mIt = d->mAddressees.end(); |
433 | return it; | 486 | return it; |
434 | } | 487 | } |
435 | 488 | ||
436 | void AddressBook::clear() | 489 | void AddressBook::clear() |
437 | { | 490 | { |
438 | d->mAddressees.clear(); | 491 | d->mAddressees.clear(); |
439 | } | 492 | } |
440 | 493 | ||
441 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 494 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
442 | { | 495 | { |
443 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 496 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
444 | 497 | ||
445 | if ( !resource ) | 498 | if ( !resource ) |
446 | { | 499 | { |
447 | qDebug("AddressBook::requestSaveTicket no resource" ); | 500 | qDebug("AddressBook::requestSaveTicket no resource" ); |
448 | resource = standardResource(); | 501 | resource = standardResource(); |
449 | } | 502 | } |
450 | 503 | ||
451 | KRES::Manager<Resource>::ActiveIterator it; | 504 | KRES::Manager<Resource>::ActiveIterator it; |
452 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 505 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
453 | if ( (*it) == resource ) { | 506 | if ( (*it) == resource ) { |
454 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 507 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
455 | return 0; | 508 | return 0; |
456 | else | 509 | else |
457 | return (*it)->requestSaveTicket(); | 510 | return (*it)->requestSaveTicket(); |
458 | } | 511 | } |
459 | } | 512 | } |
460 | 513 | ||
461 | return 0; | 514 | return 0; |
462 | } | 515 | } |
463 | 516 | ||
464 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 517 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
465 | { | 518 | { |
466 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 519 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
467 | //qDebug("block insert "); | 520 | //qDebug("block insert "); |
468 | return; | 521 | return; |
469 | } | 522 | } |
470 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 523 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
471 | bool found = false; | 524 | bool found = false; |
472 | Addressee::List::Iterator it; | 525 | Addressee::List::Iterator it; |
473 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 526 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
474 | if ( a.uid() == (*it).uid() ) { | 527 | if ( a.uid() == (*it).uid() ) { |
475 | 528 | ||
476 | bool changed = false; | 529 | bool changed = false; |
477 | Addressee addr = a; | 530 | Addressee addr = a; |
478 | if ( addr != (*it) ) | 531 | if ( addr != (*it) ) |
479 | changed = true; | 532 | changed = true; |
480 | 533 | ||
481 | (*it) = a; | 534 | if ( takeResource ) { |
482 | if ( (*it).resource() == 0 ) | 535 | Resource * res = (*it).resource(); |
483 | (*it).setResource( standardResource() ); | 536 | (*it) = a; |
484 | 537 | (*it).setResource( res ); | |
538 | } else { | ||
539 | (*it) = a; | ||
540 | if ( (*it).resource() == 0 ) | ||
541 | (*it).setResource( standardResource() ); | ||
542 | } | ||
485 | if ( changed ) { | 543 | if ( changed ) { |
486 | if ( setRev ) { | 544 | if ( setRev ) { |
487 | 545 | ||
488 | // get rid of micro seconds | 546 | // get rid of micro seconds |
489 | QDateTime dt = QDateTime::currentDateTime(); | 547 | QDateTime dt = QDateTime::currentDateTime(); |
490 | QTime t = dt.time(); | 548 | QTime t = dt.time(); |
491 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 549 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
492 | (*it).setRevision( dt ); | 550 | (*it).setRevision( dt ); |
493 | } | 551 | } |
494 | (*it).setChanged( true ); | 552 | (*it).setChanged( true ); |
495 | } | 553 | } |
496 | 554 | ||
497 | found = true; | 555 | found = true; |
498 | } else { | 556 | } else { |
499 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 557 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
500 | QString name = (*it).uid().mid( 19 ); | 558 | QString name = (*it).uid().mid( 19 ); |
501 | Addressee b = a; | 559 | Addressee b = a; |
502 | QString id = b.getID( name ); | 560 | QString id = b.getID( name ); |
503 | if ( ! id.isEmpty() ) { | 561 | if ( ! id.isEmpty() ) { |
504 | QString des = (*it).note(); | 562 | QString des = (*it).note(); |
505 | int startN; | 563 | int startN; |
506 | if( (startN = des.find( id ) ) >= 0 ) { | 564 | if( (startN = des.find( id ) ) >= 0 ) { |
507 | int endN = des.find( ",", startN+1 ); | 565 | int endN = des.find( ",", startN+1 ); |
508 | des = des.left( startN ) + des.mid( endN+1 ); | 566 | des = des.left( startN ) + des.mid( endN+1 ); |
509 | (*it).setNote( des ); | 567 | (*it).setNote( des ); |
510 | } | 568 | } |
511 | } | 569 | } |
512 | } | 570 | } |
513 | } | 571 | } |
514 | } | 572 | } |
515 | if ( found ) | 573 | if ( found ) |
516 | return; | 574 | return; |
517 | d->mAddressees.append( a ); | 575 | d->mAddressees.append( a ); |
518 | Addressee& addr = d->mAddressees.last(); | 576 | Addressee& addr = d->mAddressees.last(); |
519 | if ( addr.resource() == 0 ) | 577 | if ( addr.resource() == 0 ) |
520 | addr.setResource( standardResource() ); | 578 | addr.setResource( standardResource() ); |
521 | 579 | ||
522 | addr.setChanged( true ); | 580 | addr.setChanged( true ); |
523 | } | 581 | } |
524 | 582 | ||
525 | void AddressBook::removeAddressee( const Addressee &a ) | 583 | void AddressBook::removeAddressee( const Addressee &a ) |
526 | { | 584 | { |
527 | Iterator it; | 585 | Iterator it; |
528 | Iterator it2; | 586 | Iterator it2; |
529 | bool found = false; | 587 | bool found = false; |
530 | for ( it = begin(); it != end(); ++it ) { | 588 | for ( it = begin(); it != end(); ++it ) { |
531 | if ( a.uid() == (*it).uid() ) { | 589 | if ( a.uid() == (*it).uid() ) { |
532 | found = true; | 590 | found = true; |
533 | it2 = it; | 591 | it2 = it; |
534 | } else { | 592 | } else { |
535 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 593 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
536 | QString name = (*it).uid().mid( 19 ); | 594 | QString name = (*it).uid().mid( 19 ); |
537 | Addressee b = a; | 595 | Addressee b = a; |
538 | QString id = b.getID( name ); | 596 | QString id = b.getID( name ); |
539 | if ( ! id.isEmpty() ) { | 597 | if ( ! id.isEmpty() ) { |
540 | QString des = (*it).note(); | 598 | QString des = (*it).note(); |
541 | if( des.find( id ) < 0 ) { | 599 | if( des.find( id ) < 0 ) { |
542 | des += id + ","; | 600 | des += id + ","; |
543 | (*it).setNote( des ); | 601 | (*it).setNote( des ); |
544 | } | 602 | } |
545 | } | 603 | } |
546 | } | 604 | } |
547 | 605 | ||
548 | } | 606 | } |
549 | } | 607 | } |
550 | 608 | ||
551 | if ( found ) | 609 | if ( found ) |
552 | removeAddressee( it2 ); | 610 | removeAddressee( it2 ); |
553 | 611 | ||
554 | } | 612 | } |
555 | 613 | ||
556 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 614 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
557 | { | 615 | { |
558 | Iterator it = begin(); | 616 | Iterator it = begin(); |
559 | Iterator it2 ; | 617 | Iterator it2 ; |
560 | QDateTime dt ( QDate( 2004,1,1) ); | 618 | QDateTime dt ( QDate( 2004,1,1) ); |
561 | while ( it != end() ) { | 619 | while ( it != end() ) { |
562 | (*it).setRevision( dt ); | 620 | (*it).setRevision( dt ); |
563 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 621 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
564 | (*it).setIDStr(""); | 622 | (*it).setIDStr(""); |
565 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 623 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
566 | it2 = it; | 624 | it2 = it; |
567 | //qDebug("removing %s ",(*it).uid().latin1() ); | 625 | //qDebug("removing %s ",(*it).uid().latin1() ); |
568 | ++it; | 626 | ++it; |
569 | removeAddressee( it2 ); | 627 | removeAddressee( it2 ); |
570 | } else { | 628 | } else { |
571 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 629 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
572 | ++it; | 630 | ++it; |
573 | } | 631 | } |
574 | } | 632 | } |
575 | deleteRemovedAddressees(); | 633 | deleteRemovedAddressees(); |
576 | } | 634 | } |
577 | 635 | ||
578 | void AddressBook::removeAddressee( const Iterator &it ) | 636 | void AddressBook::removeAddressee( const Iterator &it ) |
579 | { | 637 | { |
580 | d->mRemovedAddressees.append( (*it) ); | 638 | d->mRemovedAddressees.append( (*it) ); |
581 | d->mAddressees.remove( it.d->mIt ); | 639 | d->mAddressees.remove( it.d->mIt ); |
582 | } | 640 | } |
583 | 641 | ||
584 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 642 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
585 | { | 643 | { |
586 | Iterator it; | 644 | Iterator it; |
587 | for ( it = begin(); it != end(); ++it ) { | 645 | for ( it = begin(); it != end(); ++it ) { |
588 | if ( a.uid() == (*it).uid() ) { | 646 | if ( a.uid() == (*it).uid() ) { |
589 | return it; | 647 | return it; |
590 | } | 648 | } |
591 | } | 649 | } |
592 | return end(); | 650 | return end(); |
593 | } | 651 | } |
594 | 652 | ||
595 | Addressee AddressBook::findByUid( const QString &uid ) | 653 | Addressee AddressBook::findByUid( const QString &uid ) |
596 | { | 654 | { |
597 | Iterator it; | 655 | Iterator it; |
598 | for ( it = begin(); it != end(); ++it ) { | 656 | for ( it = begin(); it != end(); ++it ) { |
599 | if ( uid == (*it).uid() ) { | 657 | if ( uid == (*it).uid() ) { |
600 | return *it; | 658 | return *it; |
601 | } | 659 | } |
602 | } | 660 | } |
603 | return Addressee(); | 661 | return Addressee(); |
604 | } | 662 | } |
605 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 663 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
606 | { | 664 | { |
607 | //qDebug("AddressBook::preExternSync "); | 665 | //qDebug("AddressBook::preExternSync "); |
608 | AddressBook::Iterator it; | 666 | AddressBook::Iterator it; |
609 | for ( it = begin(); it != end(); ++it ) { | 667 | for ( it = begin(); it != end(); ++it ) { |
610 | (*it).setID( csd, (*it).externalUID() ); | 668 | (*it).setID( csd, (*it).externalUID() ); |
611 | (*it).computeCsum( csd ); | 669 | (*it).computeCsum( csd ); |
612 | } | 670 | } |
613 | mergeAB( aBook ,csd ); | 671 | mergeAB( aBook ,csd ); |
614 | } | 672 | } |
615 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 673 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
616 | { | 674 | { |
617 | //qDebug("AddressBook::postExternSync "); | 675 | //qDebug("AddressBook::postExternSync "); |
618 | AddressBook::Iterator it; | 676 | AddressBook::Iterator it; |
619 | for ( it = begin(); it != end(); ++it ) { | 677 | for ( it = begin(); it != end(); ++it ) { |
620 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 678 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
621 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 679 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
622 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 680 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
623 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 681 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
624 | if ( ad.isEmpty() ) { | 682 | if ( ad.isEmpty() ) { |
625 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 683 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
626 | } else { | 684 | } else { |
627 | (*it).computeCsum( csd ); | 685 | (*it).computeCsum( csd ); |
628 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 686 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
629 | ad.setID( csd, (*it).externalUID() ); | 687 | ad.setID( csd, (*it).externalUID() ); |
630 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 688 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
631 | aBook->insertAddressee( ad ); | 689 | aBook->insertAddressee( ad ); |
632 | } | 690 | } |
633 | } | 691 | } |
634 | } | 692 | } |
635 | } | 693 | } |
636 | 694 | ||
637 | bool AddressBook::containsExternalUid( const QString& uid ) | 695 | bool AddressBook::containsExternalUid( const QString& uid ) |
638 | { | 696 | { |
639 | Iterator it; | 697 | Iterator it; |
640 | for ( it = begin(); it != end(); ++it ) { | 698 | for ( it = begin(); it != end(); ++it ) { |
641 | if ( uid == (*it).externalUID( ) ) | 699 | if ( uid == (*it).externalUID( ) ) |
642 | return true; | 700 | return true; |
643 | } | 701 | } |
644 | return false; | 702 | return false; |
645 | } | 703 | } |
646 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 704 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
647 | { | 705 | { |
648 | Iterator it; | 706 | Iterator it; |
649 | for ( it = begin(); it != end(); ++it ) { | 707 | for ( it = begin(); it != end(); ++it ) { |
650 | if ( uid == (*it).getID( profile ) ) | 708 | if ( uid == (*it).getID( profile ) ) |
651 | return (*it); | 709 | return (*it); |
652 | } | 710 | } |
653 | return Addressee(); | 711 | return Addressee(); |
654 | } | 712 | } |
655 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 713 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
656 | { | 714 | { |
657 | Iterator it; | 715 | Iterator it; |
658 | Addressee ad; | 716 | Addressee ad; |
659 | for ( it = begin(); it != end(); ++it ) { | 717 | for ( it = begin(); it != end(); ++it ) { |
660 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 718 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
661 | if ( !ad.isEmpty() ) { | 719 | if ( !ad.isEmpty() ) { |
662 | (*it).mergeContact( ad ); | 720 | (*it).mergeContact( ad ); |
663 | } | 721 | } |
664 | } | 722 | } |
665 | #if 0 | 723 | #if 0 |
666 | // test only | 724 | // test only |
667 | for ( it = begin(); it != end(); ++it ) { | 725 | for ( it = begin(); it != end(); ++it ) { |
668 | 726 | ||
669 | qDebug("uid %s ", (*it).uid().latin1()); | 727 | qDebug("uid %s ", (*it).uid().latin1()); |
670 | } | 728 | } |
671 | #endif | 729 | #endif |
672 | } | 730 | } |
673 | 731 | ||
674 | #if 0 | 732 | #if 0 |
675 | Addressee::List AddressBook::getExternLastSyncAddressees() | 733 | Addressee::List AddressBook::getExternLastSyncAddressees() |
676 | { | 734 | { |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 8f62f0d..3603ec1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,340 +1,341 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_ADDRESSBOOK_H | 28 | #ifndef KABC_ADDRESSBOOK_H |
29 | #define KABC_ADDRESSBOOK_H | 29 | #define KABC_ADDRESSBOOK_H |
30 | 30 | ||
31 | #include <qobject.h> | 31 | #include <qobject.h> |
32 | 32 | ||
33 | #include <kresources/manager.h> | 33 | #include <kresources/manager.h> |
34 | #include <qptrlist.h> | 34 | #include <qptrlist.h> |
35 | 35 | ||
36 | #include "addressee.h" | 36 | #include "addressee.h" |
37 | #include "field.h" | 37 | #include "field.h" |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class ErrorHandler; | 41 | class ErrorHandler; |
42 | class Resource; | 42 | class Resource; |
43 | class Ticket; | 43 | class Ticket; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | @short Address Book | 46 | @short Address Book |
47 | 47 | ||
48 | This class provides access to a collection of address book entries. | 48 | This class provides access to a collection of address book entries. |
49 | */ | 49 | */ |
50 | class AddressBook : public QObject | 50 | class AddressBook : public QObject |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); | 54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); |
55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); | 55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); |
56 | friend class StdAddressBook; | 56 | friend class StdAddressBook; |
57 | 57 | ||
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | @short Address Book Iterator | 60 | @short Address Book Iterator |
61 | 61 | ||
62 | This class provides an iterator for address book entries. | 62 | This class provides an iterator for address book entries. |
63 | */ | 63 | */ |
64 | class Iterator | 64 | class Iterator |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Iterator(); | 67 | Iterator(); |
68 | Iterator( const Iterator & ); | 68 | Iterator( const Iterator & ); |
69 | ~Iterator(); | 69 | ~Iterator(); |
70 | 70 | ||
71 | Iterator &operator=( const Iterator & ); | 71 | Iterator &operator=( const Iterator & ); |
72 | const Addressee &operator*() const; | 72 | const Addressee &operator*() const; |
73 | Addressee &operator*(); | 73 | Addressee &operator*(); |
74 | Addressee* operator->(); | 74 | Addressee* operator->(); |
75 | Iterator &operator++(); | 75 | Iterator &operator++(); |
76 | Iterator &operator++(int); | 76 | Iterator &operator++(int); |
77 | Iterator &operator--(); | 77 | Iterator &operator--(); |
78 | Iterator &operator--(int); | 78 | Iterator &operator--(int); |
79 | bool operator==( const Iterator &it ); | 79 | bool operator==( const Iterator &it ); |
80 | bool operator!=( const Iterator &it ); | 80 | bool operator!=( const Iterator &it ); |
81 | 81 | ||
82 | struct IteratorData; | 82 | struct IteratorData; |
83 | IteratorData *d; | 83 | IteratorData *d; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | @short Address Book Const Iterator | 87 | @short Address Book Const Iterator |
88 | 88 | ||
89 | This class provides a const iterator for address book entries. | 89 | This class provides a const iterator for address book entries. |
90 | */ | 90 | */ |
91 | class ConstIterator | 91 | class ConstIterator |
92 | { | 92 | { |
93 | public: | 93 | public: |
94 | ConstIterator(); | 94 | ConstIterator(); |
95 | ConstIterator( const ConstIterator & ); | 95 | ConstIterator( const ConstIterator & ); |
96 | ~ConstIterator(); | 96 | ~ConstIterator(); |
97 | 97 | ||
98 | ConstIterator &operator=( const ConstIterator & ); | 98 | ConstIterator &operator=( const ConstIterator & ); |
99 | const Addressee &operator*() const; | 99 | const Addressee &operator*() const; |
100 | const Addressee* operator->() const; | 100 | const Addressee* operator->() const; |
101 | ConstIterator &operator++(); | 101 | ConstIterator &operator++(); |
102 | ConstIterator &operator++(int); | 102 | ConstIterator &operator++(int); |
103 | ConstIterator &operator--(); | 103 | ConstIterator &operator--(); |
104 | ConstIterator &operator--(int); | 104 | ConstIterator &operator--(int); |
105 | bool operator==( const ConstIterator &it ); | 105 | bool operator==( const ConstIterator &it ); |
106 | bool operator!=( const ConstIterator &it ); | 106 | bool operator!=( const ConstIterator &it ); |
107 | 107 | ||
108 | struct ConstIteratorData; | 108 | struct ConstIteratorData; |
109 | ConstIteratorData *d; | 109 | ConstIteratorData *d; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Constructs a address book object. | 113 | Constructs a address book object. |
114 | 114 | ||
115 | @param format File format class. | 115 | @param format File format class. |
116 | */ | 116 | */ |
117 | AddressBook(); | 117 | AddressBook(); |
118 | AddressBook( const QString &config ); | 118 | AddressBook( const QString &config ); |
119 | AddressBook( const QString &config, const QString &family ); | 119 | AddressBook( const QString &config, const QString &family ); |
120 | virtual ~AddressBook(); | 120 | virtual ~AddressBook(); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | Requests a ticket for saving the addressbook. Calling this function locks | 123 | Requests a ticket for saving the addressbook. Calling this function locks |
124 | the addressbook for all other processes. If the address book is already | 124 | the addressbook for all other processes. If the address book is already |
125 | locked the function returns 0. You need the returned @ref Ticket object | 125 | locked the function returns 0. You need the returned @ref Ticket object |
126 | for calling the @ref save() function. | 126 | for calling the @ref save() function. |
127 | 127 | ||
128 | @see save() | 128 | @see save() |
129 | */ | 129 | */ |
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | 145 | void export2File( QString fileName ); | |
146 | void importFromFile( QString fileName ); | ||
146 | /** | 147 | /** |
147 | Returns a iterator for first entry of address book. | 148 | Returns a iterator for first entry of address book. |
148 | */ | 149 | */ |
149 | Iterator begin(); | 150 | Iterator begin(); |
150 | 151 | ||
151 | /** | 152 | /** |
152 | Returns a const iterator for first entry of address book. | 153 | Returns a const iterator for first entry of address book. |
153 | */ | 154 | */ |
154 | ConstIterator begin() const; | 155 | ConstIterator begin() const; |
155 | 156 | ||
156 | /** | 157 | /** |
157 | Returns a iterator for first entry of address book. | 158 | Returns a iterator for first entry of address book. |
158 | */ | 159 | */ |
159 | Iterator end(); | 160 | Iterator end(); |
160 | 161 | ||
161 | /** | 162 | /** |
162 | Returns a const iterator for first entry of address book. | 163 | Returns a const iterator for first entry of address book. |
163 | */ | 164 | */ |
164 | ConstIterator end() const; | 165 | ConstIterator end() const; |
165 | 166 | ||
166 | /** | 167 | /** |
167 | Removes all entries from address book. | 168 | Removes all entries from address book. |
168 | */ | 169 | */ |
169 | void clear(); | 170 | void clear(); |
170 | 171 | ||
171 | /** | 172 | /** |
172 | Insert an Addressee object into address book. If an object with the same | 173 | Insert an Addressee object into address book. If an object with the same |
173 | unique id already exists in the address book it it replaced by the new | 174 | unique id already exists in the address book it it replaced by the new |
174 | one. If not the new object is appended to the address book. | 175 | one. If not the new object is appended to the address book. |
175 | */ | 176 | */ |
176 | void insertAddressee( const Addressee &, bool setRev = true ); | 177 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
177 | 178 | ||
178 | /** | 179 | /** |
179 | Removes entry from the address book. | 180 | Removes entry from the address book. |
180 | */ | 181 | */ |
181 | void removeAddressee( const Addressee & ); | 182 | void removeAddressee( const Addressee & ); |
182 | 183 | ||
183 | /** | 184 | /** |
184 | This is like @ref removeAddressee() just above, with the difference that | 185 | This is like @ref removeAddressee() just above, with the difference that |
185 | the first element is a iterator, returned by @ref begin(). | 186 | the first element is a iterator, returned by @ref begin(). |
186 | */ | 187 | */ |
187 | void removeAddressee( const Iterator & ); | 188 | void removeAddressee( const Iterator & ); |
188 | 189 | ||
189 | /** | 190 | /** |
190 | Find the specified entry in address book. Returns end(), if the entry | 191 | Find the specified entry in address book. Returns end(), if the entry |
191 | couldn't be found. | 192 | couldn't be found. |
192 | */ | 193 | */ |
193 | Iterator find( const Addressee & ); | 194 | Iterator find( const Addressee & ); |
194 | 195 | ||
195 | /** | 196 | /** |
196 | Find the entry specified by an unique id. Returns an empty Addressee | 197 | Find the entry specified by an unique id. Returns an empty Addressee |
197 | object, if the address book does not contain an entry with this id. | 198 | object, if the address book does not contain an entry with this id. |
198 | */ | 199 | */ |
199 | Addressee findByUid( const QString & ); | 200 | Addressee findByUid( const QString & ); |
200 | 201 | ||
201 | 202 | ||
202 | /** | 203 | /** |
203 | Returns a list of all addressees in the address book. This list can | 204 | Returns a list of all addressees in the address book. This list can |
204 | be sorted with @ref KABC::AddresseeList for example. | 205 | be sorted with @ref KABC::AddresseeList for example. |
205 | */ | 206 | */ |
206 | Addressee::List allAddressees(); | 207 | Addressee::List allAddressees(); |
207 | 208 | ||
208 | /** | 209 | /** |
209 | Find all entries with the specified name in the address book. Returns | 210 | Find all entries with the specified name in the address book. Returns |
210 | an empty list, if no entries could be found. | 211 | an empty list, if no entries could be found. |
211 | */ | 212 | */ |
212 | Addressee::List findByName( const QString & ); | 213 | Addressee::List findByName( const QString & ); |
213 | 214 | ||
214 | /** | 215 | /** |
215 | Find all entries with the specified email address in the address book. | 216 | Find all entries with the specified email address in the address book. |
216 | Returns an empty list, if no entries could be found. | 217 | Returns an empty list, if no entries could be found. |
217 | */ | 218 | */ |
218 | Addressee::List findByEmail( const QString & ); | 219 | Addressee::List findByEmail( const QString & ); |
219 | 220 | ||
220 | /** | 221 | /** |
221 | Find all entries wich have the specified category in the address book. | 222 | Find all entries wich have the specified category in the address book. |
222 | Returns an empty list, if no entries could be found. | 223 | Returns an empty list, if no entries could be found. |
223 | */ | 224 | */ |
224 | Addressee::List findByCategory( const QString & ); | 225 | Addressee::List findByCategory( const QString & ); |
225 | 226 | ||
226 | /** | 227 | /** |
227 | Return a string identifying this addressbook. | 228 | Return a string identifying this addressbook. |
228 | */ | 229 | */ |
229 | virtual QString identifier(); | 230 | virtual QString identifier(); |
230 | 231 | ||
231 | /** | 232 | /** |
232 | Used for debug output. | 233 | Used for debug output. |
233 | */ | 234 | */ |
234 | void dump() const; | 235 | void dump() const; |
235 | 236 | ||
236 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 237 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
237 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 238 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
238 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 239 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
239 | 240 | ||
240 | /** | 241 | /** |
241 | Return list of all Fields known to the address book which are associated | 242 | Return list of all Fields known to the address book which are associated |
242 | with the given field category. | 243 | with the given field category. |
243 | */ | 244 | */ |
244 | Field::List fields( int category = Field::All ); | 245 | Field::List fields( int category = Field::All ); |
245 | 246 | ||
246 | /** | 247 | /** |
247 | Add custom field to address book. | 248 | Add custom field to address book. |
248 | 249 | ||
249 | @param label User visible label of the field. | 250 | @param label User visible label of the field. |
250 | @param category Ored list of field categories. | 251 | @param category Ored list of field categories. |
251 | @param key Identifier used as key for reading and writing the field. | 252 | @param key Identifier used as key for reading and writing the field. |
252 | @param app String used as application key for reading and writing | 253 | @param app String used as application key for reading and writing |
253 | the field. | 254 | the field. |
254 | */ | 255 | */ |
255 | bool addCustomField( const QString &label, int category = Field::All, | 256 | bool addCustomField( const QString &label, int category = Field::All, |
256 | const QString &key = QString::null, | 257 | const QString &key = QString::null, |
257 | const QString &app = QString::null ); | 258 | const QString &app = QString::null ); |
258 | 259 | ||
259 | 260 | ||
260 | /** | 261 | /** |
261 | Add address book resource. | 262 | Add address book resource. |
262 | */ | 263 | */ |
263 | bool addResource( Resource * ); | 264 | bool addResource( Resource * ); |
264 | 265 | ||
265 | /** | 266 | /** |
266 | Remove address book resource. | 267 | Remove address book resource. |
267 | */ | 268 | */ |
268 | bool removeResource( Resource * ); | 269 | bool removeResource( Resource * ); |
269 | 270 | ||
270 | /** | 271 | /** |
271 | Return pointer list of all resources. | 272 | Return pointer list of all resources. |
272 | */ | 273 | */ |
273 | QPtrList<Resource> resources(); | 274 | QPtrList<Resource> resources(); |
274 | 275 | ||
275 | /** | 276 | /** |
276 | Set the @p ErrorHandler, that is used by @ref error() to | 277 | Set the @p ErrorHandler, that is used by @ref error() to |
277 | provide gui-independend error messages. | 278 | provide gui-independend error messages. |
278 | */ | 279 | */ |
279 | void setErrorHandler( ErrorHandler * ); | 280 | void setErrorHandler( ErrorHandler * ); |
280 | 281 | ||
281 | /** | 282 | /** |
282 | Shows gui independend error messages. | 283 | Shows gui independend error messages. |
283 | */ | 284 | */ |
284 | void error( const QString& ); | 285 | void error( const QString& ); |
285 | 286 | ||
286 | /** | 287 | /** |
287 | Query all resources to clean up their lock files | 288 | Query all resources to clean up their lock files |
288 | */ | 289 | */ |
289 | void cleanUp(); | 290 | void cleanUp(); |
290 | 291 | ||
291 | // sync stuff | 292 | // sync stuff |
292 | //Addressee::List getExternLastSyncAddressees(); | 293 | //Addressee::List getExternLastSyncAddressees(); |
293 | void resetTempSyncStat(); | 294 | void resetTempSyncStat(); |
294 | QStringList uidList(); | 295 | QStringList uidList(); |
295 | void removeSyncAddressees( bool removeDeleted = false ); | 296 | void removeSyncAddressees( bool removeDeleted = false ); |
296 | void mergeAB( AddressBook *aBook, const QString& profile ); | 297 | void mergeAB( AddressBook *aBook, const QString& profile ); |
297 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 298 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
298 | bool containsExternalUid( const QString& uid ); | 299 | bool containsExternalUid( const QString& uid ); |
299 | 300 | ||
300 | void preExternSync( AddressBook* aBook, const QString& csd ); | 301 | void preExternSync( AddressBook* aBook, const QString& csd ); |
301 | void postExternSync( AddressBook* aBook, const QString& csd ); | 302 | void postExternSync( AddressBook* aBook, const QString& csd ); |
302 | signals: | 303 | signals: |
303 | /** | 304 | /** |
304 | Emitted, when the address book has changed on disk. | 305 | Emitted, when the address book has changed on disk. |
305 | */ | 306 | */ |
306 | void addressBookChanged( AddressBook * ); | 307 | void addressBookChanged( AddressBook * ); |
307 | 308 | ||
308 | /** | 309 | /** |
309 | Emitted, when the address book has been locked for writing. | 310 | Emitted, when the address book has been locked for writing. |
310 | */ | 311 | */ |
311 | void addressBookLocked( AddressBook * ); | 312 | void addressBookLocked( AddressBook * ); |
312 | 313 | ||
313 | /** | 314 | /** |
314 | Emitted, when the address book has been unlocked. | 315 | Emitted, when the address book has been unlocked. |
315 | */ | 316 | */ |
316 | void addressBookUnlocked( AddressBook * ); | 317 | void addressBookUnlocked( AddressBook * ); |
317 | 318 | ||
318 | protected: | 319 | protected: |
319 | void deleteRemovedAddressees(); | 320 | void deleteRemovedAddressees(); |
320 | void setStandardResource( Resource * ); | 321 | void setStandardResource( Resource * ); |
321 | Resource *standardResource(); | 322 | Resource *standardResource(); |
322 | KRES::Manager<Resource> *resourceManager(); | 323 | KRES::Manager<Resource> *resourceManager(); |
323 | 324 | ||
324 | void init(const QString &config, const QString &family); | 325 | void init(const QString &config, const QString &family); |
325 | 326 | ||
326 | private: | 327 | private: |
327 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 328 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
328 | 329 | ||
329 | 330 | ||
330 | struct AddressBookData; | 331 | struct AddressBookData; |
331 | AddressBookData *d; | 332 | AddressBookData *d; |
332 | bool blockLSEchange; | 333 | bool blockLSEchange; |
333 | }; | 334 | }; |
334 | 335 | ||
335 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 336 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
336 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 337 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
337 | 338 | ||
338 | } | 339 | } |
339 | 340 | ||
340 | #endif | 341 | #endif |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index 83fede4..6404410 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -1494,387 +1494,387 @@ void KABCore::addGUIClient( KXMLGUIClient *client ) | |||
1494 | 1494 | ||
1495 | 1495 | ||
1496 | void KABCore::configurationChanged() | 1496 | void KABCore::configurationChanged() |
1497 | { | 1497 | { |
1498 | mExtensionManager->reconfigure(); | 1498 | mExtensionManager->reconfigure(); |
1499 | } | 1499 | } |
1500 | 1500 | ||
1501 | void KABCore::addressBookChanged() | 1501 | void KABCore::addressBookChanged() |
1502 | { | 1502 | { |
1503 | /*US | 1503 | /*US |
1504 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); | 1504 | QDictIterator<AddresseeEditorDialog> it( mEditorDict ); |
1505 | while ( it.current() ) { | 1505 | while ( it.current() ) { |
1506 | if ( it.current()->dirty() ) { | 1506 | if ( it.current()->dirty() ) { |
1507 | QString text = i18n( "Data has been changed externally. Unsaved " | 1507 | QString text = i18n( "Data has been changed externally. Unsaved " |
1508 | "changes will be lost." ); | 1508 | "changes will be lost." ); |
1509 | KMessageBox::information( this, text ); | 1509 | KMessageBox::information( this, text ); |
1510 | } | 1510 | } |
1511 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); | 1511 | it.current()->setAddressee( mAddressBook->findByUid( it.currentKey() ) ); |
1512 | ++it; | 1512 | ++it; |
1513 | } | 1513 | } |
1514 | */ | 1514 | */ |
1515 | if (mEditorDialog) | 1515 | if (mEditorDialog) |
1516 | { | 1516 | { |
1517 | if (mEditorDialog->dirty()) | 1517 | if (mEditorDialog->dirty()) |
1518 | { | 1518 | { |
1519 | QString text = i18n( "Data has been changed externally. Unsaved " | 1519 | QString text = i18n( "Data has been changed externally. Unsaved " |
1520 | "changes will be lost." ); | 1520 | "changes will be lost." ); |
1521 | KMessageBox::information( this, text ); | 1521 | KMessageBox::information( this, text ); |
1522 | } | 1522 | } |
1523 | QString currentuid = mEditorDialog->addressee().uid(); | 1523 | QString currentuid = mEditorDialog->addressee().uid(); |
1524 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); | 1524 | mEditorDialog->setAddressee( mAddressBook->findByUid( currentuid ) ); |
1525 | } | 1525 | } |
1526 | mViewManager->refreshView(); | 1526 | mViewManager->refreshView(); |
1527 | // mDetails->refreshView(); | 1527 | // mDetails->refreshView(); |
1528 | 1528 | ||
1529 | 1529 | ||
1530 | } | 1530 | } |
1531 | 1531 | ||
1532 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, | 1532 | AddresseeEditorDialog *KABCore::createAddresseeEditorDialog( QWidget *parent, |
1533 | const char *name ) | 1533 | const char *name ) |
1534 | { | 1534 | { |
1535 | 1535 | ||
1536 | if ( mEditorDialog == 0 ) { | 1536 | if ( mEditorDialog == 0 ) { |
1537 | mEditorDialog = new AddresseeEditorDialog( this, parent, | 1537 | mEditorDialog = new AddresseeEditorDialog( this, parent, |
1538 | name ? name : "editorDialog" ); | 1538 | name ? name : "editorDialog" ); |
1539 | 1539 | ||
1540 | 1540 | ||
1541 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), | 1541 | connect( mEditorDialog, SIGNAL( contactModified( const KABC::Addressee& ) ), |
1542 | SLOT( contactModified( const KABC::Addressee& ) ) ); | 1542 | SLOT( contactModified( const KABC::Addressee& ) ) ); |
1543 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), | 1543 | //connect( mEditorDialog, SIGNAL( editorDestroyed( const QString& ) ), |
1544 | // SLOT( slotEditorDestroyed( const QString& ) ) ; | 1544 | // SLOT( slotEditorDestroyed( const QString& ) ) ; |
1545 | } | 1545 | } |
1546 | 1546 | ||
1547 | return mEditorDialog; | 1547 | return mEditorDialog; |
1548 | } | 1548 | } |
1549 | 1549 | ||
1550 | void KABCore::slotEditorDestroyed( const QString &uid ) | 1550 | void KABCore::slotEditorDestroyed( const QString &uid ) |
1551 | { | 1551 | { |
1552 | //mEditorDict.remove( uid ); | 1552 | //mEditorDict.remove( uid ); |
1553 | } | 1553 | } |
1554 | 1554 | ||
1555 | void KABCore::initGUI() | 1555 | void KABCore::initGUI() |
1556 | { | 1556 | { |
1557 | #ifndef KAB_EMBEDDED | 1557 | #ifndef KAB_EMBEDDED |
1558 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1558 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1559 | topLayout->setSpacing( KDialogBase::spacingHint() ); | 1559 | topLayout->setSpacing( KDialogBase::spacingHint() ); |
1560 | 1560 | ||
1561 | mExtensionBarSplitter = new QSplitter( this ); | 1561 | mExtensionBarSplitter = new QSplitter( this ); |
1562 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); | 1562 | mExtensionBarSplitter->setOrientation( Qt::Vertical ); |
1563 | 1563 | ||
1564 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); | 1564 | mDetailsSplitter = new QSplitter( mExtensionBarSplitter ); |
1565 | 1565 | ||
1566 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1566 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1567 | mIncSearchWidget = new IncSearchWidget( viewSpace ); | 1567 | mIncSearchWidget = new IncSearchWidget( viewSpace ); |
1568 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1568 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1569 | SLOT( incrementalSearch( const QString& ) ) ); | 1569 | SLOT( incrementalSearch( const QString& ) ) ); |
1570 | 1570 | ||
1571 | mViewManager = new ViewManager( this, viewSpace ); | 1571 | mViewManager = new ViewManager( this, viewSpace ); |
1572 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1572 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1573 | 1573 | ||
1574 | mDetails = new ViewContainer( mDetailsSplitter ); | 1574 | mDetails = new ViewContainer( mDetailsSplitter ); |
1575 | 1575 | ||
1576 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1576 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1577 | 1577 | ||
1578 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1578 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1579 | 1579 | ||
1580 | topLayout->addWidget( mExtensionBarSplitter ); | 1580 | topLayout->addWidget( mExtensionBarSplitter ); |
1581 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); | 1581 | topLayout->setStretchFactor( mExtensionBarSplitter, 100 ); |
1582 | topLayout->addWidget( mJumpButtonBar ); | 1582 | topLayout->addWidget( mJumpButtonBar ); |
1583 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); | 1583 | topLayout->setStretchFactor( mJumpButtonBar, 1 ); |
1584 | 1584 | ||
1585 | mXXPortManager = new XXPortManager( this, this ); | 1585 | mXXPortManager = new XXPortManager( this, this ); |
1586 | 1586 | ||
1587 | #else //KAB_EMBEDDED | 1587 | #else //KAB_EMBEDDED |
1588 | //US initialize viewMenu before settingup viewmanager. | 1588 | //US initialize viewMenu before settingup viewmanager. |
1589 | // Viewmanager needs this menu to plugin submenues. | 1589 | // Viewmanager needs this menu to plugin submenues. |
1590 | viewMenu = new QPopupMenu( this ); | 1590 | viewMenu = new QPopupMenu( this ); |
1591 | settingsMenu = new QPopupMenu( this ); | 1591 | settingsMenu = new QPopupMenu( this ); |
1592 | //filterMenu = new QPopupMenu( this ); | 1592 | //filterMenu = new QPopupMenu( this ); |
1593 | ImportMenu = new QPopupMenu( this ); | 1593 | ImportMenu = new QPopupMenu( this ); |
1594 | ExportMenu = new QPopupMenu( this ); | 1594 | ExportMenu = new QPopupMenu( this ); |
1595 | syncMenu = new QPopupMenu( this ); | 1595 | syncMenu = new QPopupMenu( this ); |
1596 | changeMenu= new QPopupMenu( this ); | 1596 | changeMenu= new QPopupMenu( this ); |
1597 | 1597 | ||
1598 | //US since we have no splitter for the embedded system, setup | 1598 | //US since we have no splitter for the embedded system, setup |
1599 | // a layout with two frames. One left and one right. | 1599 | // a layout with two frames. One left and one right. |
1600 | 1600 | ||
1601 | QBoxLayout *topLayout; | 1601 | QBoxLayout *topLayout; |
1602 | 1602 | ||
1603 | // = new QHBoxLayout( this ); | 1603 | // = new QHBoxLayout( this ); |
1604 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); | 1604 | // QBoxLayout *topLayout = (QBoxLayout*)layout(); |
1605 | 1605 | ||
1606 | // QWidget *mainBox = new QWidget( this ); | 1606 | // QWidget *mainBox = new QWidget( this ); |
1607 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); | 1607 | // QBoxLayout * mainBoxLayout = new QHBoxLayout(mainBox); |
1608 | 1608 | ||
1609 | #ifdef DESKTOP_VERSION | 1609 | #ifdef DESKTOP_VERSION |
1610 | topLayout = new QHBoxLayout( this ); | 1610 | topLayout = new QHBoxLayout( this ); |
1611 | 1611 | ||
1612 | 1612 | ||
1613 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1613 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1614 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1614 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1615 | 1615 | ||
1616 | topLayout->addWidget(mMiniSplitter ); | 1616 | topLayout->addWidget(mMiniSplitter ); |
1617 | 1617 | ||
1618 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); | 1618 | mExtensionBarSplitter = new KDGanttMinimizeSplitter( Qt::Vertical,mMiniSplitter ); |
1619 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1619 | mExtensionBarSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1620 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); | 1620 | mViewManager = new ViewManager( this, mExtensionBarSplitter ); |
1621 | mDetails = new ViewContainer( mMiniSplitter ); | 1621 | mDetails = new ViewContainer( mMiniSplitter ); |
1622 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); | 1622 | mExtensionManager = new ExtensionManager( this, mExtensionBarSplitter ); |
1623 | #else | 1623 | #else |
1624 | if ( QApplication::desktop()->width() > 480 ) { | 1624 | if ( QApplication::desktop()->width() > 480 ) { |
1625 | topLayout = new QHBoxLayout( this ); | 1625 | topLayout = new QHBoxLayout( this ); |
1626 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); | 1626 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Horizontal, this); |
1627 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); | 1627 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Right ); |
1628 | } else { | 1628 | } else { |
1629 | 1629 | ||
1630 | topLayout = new QHBoxLayout( this ); | 1630 | topLayout = new QHBoxLayout( this ); |
1631 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); | 1631 | mMiniSplitter = new KDGanttMinimizeSplitter( Qt::Vertical, this); |
1632 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); | 1632 | mMiniSplitter->setMinimizeDirection ( KDGanttMinimizeSplitter::Down ); |
1633 | } | 1633 | } |
1634 | 1634 | ||
1635 | topLayout->addWidget(mMiniSplitter ); | 1635 | topLayout->addWidget(mMiniSplitter ); |
1636 | mViewManager = new ViewManager( this, mMiniSplitter ); | 1636 | mViewManager = new ViewManager( this, mMiniSplitter ); |
1637 | mDetails = new ViewContainer( mMiniSplitter ); | 1637 | mDetails = new ViewContainer( mMiniSplitter ); |
1638 | 1638 | ||
1639 | 1639 | ||
1640 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); | 1640 | mExtensionManager = new ExtensionManager( this, mMiniSplitter ); |
1641 | #endif | 1641 | #endif |
1642 | //eh->hide(); | 1642 | //eh->hide(); |
1643 | // topLayout->addWidget(mExtensionManager ); | 1643 | // topLayout->addWidget(mExtensionManager ); |
1644 | 1644 | ||
1645 | 1645 | ||
1646 | /*US | 1646 | /*US |
1647 | #ifndef KAB_NOSPLITTER | 1647 | #ifndef KAB_NOSPLITTER |
1648 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1648 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1649 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1649 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1650 | topLayout->setSpacing( 10 ); | 1650 | topLayout->setSpacing( 10 ); |
1651 | 1651 | ||
1652 | mDetailsSplitter = new QSplitter( this ); | 1652 | mDetailsSplitter = new QSplitter( this ); |
1653 | 1653 | ||
1654 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); | 1654 | QVBox *viewSpace = new QVBox( mDetailsSplitter ); |
1655 | 1655 | ||
1656 | mViewManager = new ViewManager( this, viewSpace ); | 1656 | mViewManager = new ViewManager( this, viewSpace ); |
1657 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1657 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1658 | 1658 | ||
1659 | mDetails = new ViewContainer( mDetailsSplitter ); | 1659 | mDetails = new ViewContainer( mDetailsSplitter ); |
1660 | 1660 | ||
1661 | topLayout->addWidget( mDetailsSplitter ); | 1661 | topLayout->addWidget( mDetailsSplitter ); |
1662 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1662 | topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1663 | #else //KAB_NOSPLITTER | 1663 | #else //KAB_NOSPLITTER |
1664 | QHBoxLayout *topLayout = new QHBoxLayout( this ); | 1664 | QHBoxLayout *topLayout = new QHBoxLayout( this ); |
1665 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); | 1665 | //US topLayout->setSpacing( KDialogBase::spacingHint() ); |
1666 | topLayout->setSpacing( 10 ); | 1666 | topLayout->setSpacing( 10 ); |
1667 | 1667 | ||
1668 | // mDetailsSplitter = new QSplitter( this ); | 1668 | // mDetailsSplitter = new QSplitter( this ); |
1669 | 1669 | ||
1670 | QVBox *viewSpace = new QVBox( this ); | 1670 | QVBox *viewSpace = new QVBox( this ); |
1671 | 1671 | ||
1672 | mViewManager = new ViewManager( this, viewSpace ); | 1672 | mViewManager = new ViewManager( this, viewSpace ); |
1673 | viewSpace->setStretchFactor( mViewManager, 1 ); | 1673 | viewSpace->setStretchFactor( mViewManager, 1 ); |
1674 | 1674 | ||
1675 | mDetails = new ViewContainer( this ); | 1675 | mDetails = new ViewContainer( this ); |
1676 | 1676 | ||
1677 | topLayout->addWidget( viewSpace ); | 1677 | topLayout->addWidget( viewSpace ); |
1678 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); | 1678 | // topLayout->setStretchFactor( mDetailsSplitter, 100 ); |
1679 | topLayout->addWidget( mDetails ); | 1679 | topLayout->addWidget( mDetails ); |
1680 | #endif //KAB_NOSPLITTER | 1680 | #endif //KAB_NOSPLITTER |
1681 | */ | 1681 | */ |
1682 | 1682 | ||
1683 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); | 1683 | syncManager = new KSyncManager((QWidget*)this, (KSyncInterface*)this, KSyncManager::KAPI, KABPrefs::instance(), syncMenu); |
1684 | syncManager->setBlockSave(false); | 1684 | syncManager->setBlockSave(false); |
1685 | 1685 | ||
1686 | connect(syncManager , SIGNAL( save() ), this, SLOT( save() ) ); | 1686 | connect(syncManager , SIGNAL( request_file() ), this, SLOT( syncFileRequest() ) ); |
1687 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); | 1687 | connect(syncManager , SIGNAL( getFile( bool )), this, SLOT(getFile( bool ) ) ); |
1688 | syncManager->setDefaultFileName(locateLocal( "apps","kabc/std.vcf") ); | 1688 | syncManager->setDefaultFileName( sentSyncFile()); |
1689 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); | 1689 | //connect(syncManager , SIGNAL( ), this, SLOT( ) ); |
1690 | 1690 | ||
1691 | #endif //KAB_EMBEDDED | 1691 | #endif //KAB_EMBEDDED |
1692 | initActions(); | 1692 | initActions(); |
1693 | 1693 | ||
1694 | #ifdef KAB_EMBEDDED | 1694 | #ifdef KAB_EMBEDDED |
1695 | addActionsManually(); | 1695 | addActionsManually(); |
1696 | //US make sure the export and import menues are initialized before creating the xxPortManager. | 1696 | //US make sure the export and import menues are initialized before creating the xxPortManager. |
1697 | mXXPortManager = new XXPortManager( this, this ); | 1697 | mXXPortManager = new XXPortManager( this, this ); |
1698 | 1698 | ||
1699 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); | 1699 | // LR mIncSearchWidget = new IncSearchWidget( mMainWindow->getIconToolBar() ); |
1700 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); | 1700 | //mMainWindow->toolBar()->insertWidget(-1, 4, mIncSearchWidget); |
1701 | // mActionQuit->plug ( mMainWindow->toolBar()); | 1701 | // mActionQuit->plug ( mMainWindow->toolBar()); |
1702 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); | 1702 | //mIncSearchWidget = new IncSearchWidget( mMainWindow->toolBar() ); |
1703 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); | 1703 | //mMainWindow->toolBar()->insertWidget(-1, 0, mIncSearchWidget); |
1704 | // mIncSearchWidget->hide(); | 1704 | // mIncSearchWidget->hide(); |
1705 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 1705 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
1706 | SLOT( incrementalSearch( const QString& ) ) ); | 1706 | SLOT( incrementalSearch( const QString& ) ) ); |
1707 | 1707 | ||
1708 | 1708 | ||
1709 | mJumpButtonBar = new JumpButtonBar( this, this ); | 1709 | mJumpButtonBar = new JumpButtonBar( this, this ); |
1710 | 1710 | ||
1711 | topLayout->addWidget( mJumpButtonBar ); | 1711 | topLayout->addWidget( mJumpButtonBar ); |
1712 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); | 1712 | //US topLayout->setStretchFactor( mJumpButtonBar, 10 ); |
1713 | 1713 | ||
1714 | // mMainWindow->getIconToolBar()->raise(); | 1714 | // mMainWindow->getIconToolBar()->raise(); |
1715 | 1715 | ||
1716 | #endif //KAB_EMBEDDED | 1716 | #endif //KAB_EMBEDDED |
1717 | 1717 | ||
1718 | } | 1718 | } |
1719 | void KABCore::initActions() | 1719 | void KABCore::initActions() |
1720 | { | 1720 | { |
1721 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); | 1721 | //US qDebug("KABCore::initActions(): mIsPart %i", mIsPart); |
1722 | 1722 | ||
1723 | #ifndef KAB_EMBEDDED | 1723 | #ifndef KAB_EMBEDDED |
1724 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), | 1724 | connect( QApplication::clipboard(), SIGNAL( dataChanged() ), |
1725 | SLOT( clipboardDataChanged() ) ); | 1725 | SLOT( clipboardDataChanged() ) ); |
1726 | #endif //KAB_EMBEDDED | 1726 | #endif //KAB_EMBEDDED |
1727 | 1727 | ||
1728 | // file menu | 1728 | // file menu |
1729 | if ( mIsPart ) { | 1729 | if ( mIsPart ) { |
1730 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, | 1730 | mActionMail = new KAction( i18n( "&Mail" ), "mail_generic", 0, this, |
1731 | SLOT( sendMail() ), actionCollection(), | 1731 | SLOT( sendMail() ), actionCollection(), |
1732 | "kaddressbook_mail" ); | 1732 | "kaddressbook_mail" ); |
1733 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, | 1733 | mActionPrint = new KAction( i18n( "&Print" ), "fileprint", CTRL + Key_P, this, |
1734 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); | 1734 | SLOT( print() ), actionCollection(), "kaddressbook_print" ); |
1735 | 1735 | ||
1736 | } else { | 1736 | } else { |
1737 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); | 1737 | mActionMail = KStdAction::mail( this, SLOT( sendMail() ), actionCollection() ); |
1738 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); | 1738 | mActionPrint = KStdAction::print( this, SLOT( print() ), actionCollection() ); |
1739 | } | 1739 | } |
1740 | 1740 | ||
1741 | 1741 | ||
1742 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, | 1742 | mActionSave = new KAction( i18n( "&Save" ), "filesave", CTRL+Key_S, this, |
1743 | SLOT( save() ), actionCollection(), "file_sync" ); | 1743 | SLOT( save() ), actionCollection(), "file_sync" ); |
1744 | 1744 | ||
1745 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, | 1745 | mActionNewContact = new KAction( i18n( "&New Contact..." ), "filenew", CTRL+Key_N, this, |
1746 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); | 1746 | SLOT( newContact() ), actionCollection(), "file_new_contact" ); |
1747 | 1747 | ||
1748 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, | 1748 | mActionMailVCard = new KAction(i18n("Mail &vCard..."), "mail_post_to", 0, |
1749 | this, SLOT( mailVCard() ), | 1749 | this, SLOT( mailVCard() ), |
1750 | actionCollection(), "file_mail_vcard"); | 1750 | actionCollection(), "file_mail_vcard"); |
1751 | 1751 | ||
1752 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, | 1752 | mActionExport2phone = new KAction( i18n( "Selected to phone" ), "ex2phone", 0, this, |
1753 | SLOT( export2phone() ), actionCollection(), | 1753 | SLOT( export2phone() ), actionCollection(), |
1754 | "kaddressbook_ex2phone" ); | 1754 | "kaddressbook_ex2phone" ); |
1755 | 1755 | ||
1756 | mActionBeamVCard = 0; | 1756 | mActionBeamVCard = 0; |
1757 | mActionBeam = 0; | 1757 | mActionBeam = 0; |
1758 | 1758 | ||
1759 | #ifndef DESKTOP_VERSION | 1759 | #ifndef DESKTOP_VERSION |
1760 | if ( Ir::supported() ) { | 1760 | if ( Ir::supported() ) { |
1761 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, | 1761 | mActionBeamVCard = new KAction( i18n( "Beam selected v&Card(s)" ), "beam", 0, this, |
1762 | SLOT( beamVCard() ), actionCollection(), | 1762 | SLOT( beamVCard() ), actionCollection(), |
1763 | "kaddressbook_beam_vcard" ); | 1763 | "kaddressbook_beam_vcard" ); |
1764 | 1764 | ||
1765 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, | 1765 | mActionBeam = new KAction( i18n( "&Beam personal vCard" ), "beam", 0, this, |
1766 | SLOT( beamMySelf() ), actionCollection(), | 1766 | SLOT( beamMySelf() ), actionCollection(), |
1767 | "kaddressbook_beam_myself" ); | 1767 | "kaddressbook_beam_myself" ); |
1768 | } | 1768 | } |
1769 | #endif | 1769 | #endif |
1770 | 1770 | ||
1771 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, | 1771 | mActionEditAddressee = new KAction( i18n( "&Edit Contact..." ), "edit", 0, |
1772 | this, SLOT( editContact2() ), | 1772 | this, SLOT( editContact2() ), |
1773 | actionCollection(), "file_properties" ); | 1773 | actionCollection(), "file_properties" ); |
1774 | 1774 | ||
1775 | #ifdef KAB_EMBEDDED | 1775 | #ifdef KAB_EMBEDDED |
1776 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); | 1776 | // mActionQuit = KStdAction::quit( mMainWindow, SLOT( exit() ), actionCollection() ); |
1777 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, | 1777 | mActionQuit = new KAction( i18n( "&Exit" ), "exit", 0, |
1778 | mMainWindow, SLOT( exit() ), | 1778 | mMainWindow, SLOT( exit() ), |
1779 | actionCollection(), "quit" ); | 1779 | actionCollection(), "quit" ); |
1780 | #endif //KAB_EMBEDDED | 1780 | #endif //KAB_EMBEDDED |
1781 | 1781 | ||
1782 | // edit menu | 1782 | // edit menu |
1783 | if ( mIsPart ) { | 1783 | if ( mIsPart ) { |
1784 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, | 1784 | mActionCopy = new KAction( i18n( "&Copy" ), "editcopy", CTRL + Key_C, this, |
1785 | SLOT( copyContacts() ), actionCollection(), | 1785 | SLOT( copyContacts() ), actionCollection(), |
1786 | "kaddressbook_copy" ); | 1786 | "kaddressbook_copy" ); |
1787 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, | 1787 | mActionCut = new KAction( i18n( "Cu&t" ), "editcut", CTRL + Key_X, this, |
1788 | SLOT( cutContacts() ), actionCollection(), | 1788 | SLOT( cutContacts() ), actionCollection(), |
1789 | "kaddressbook_cut" ); | 1789 | "kaddressbook_cut" ); |
1790 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, | 1790 | mActionPaste = new KAction( i18n( "&Paste" ), "editpaste", CTRL + Key_V, this, |
1791 | SLOT( pasteContacts() ), actionCollection(), | 1791 | SLOT( pasteContacts() ), actionCollection(), |
1792 | "kaddressbook_paste" ); | 1792 | "kaddressbook_paste" ); |
1793 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, | 1793 | mActionSelectAll = new KAction( i18n( "Select &All" ), CTRL + Key_A, this, |
1794 | SLOT( selectAllContacts() ), actionCollection(), | 1794 | SLOT( selectAllContacts() ), actionCollection(), |
1795 | "kaddressbook_select_all" ); | 1795 | "kaddressbook_select_all" ); |
1796 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, | 1796 | mActionUndo = new KAction( i18n( "&Undo" ), "undo", CTRL + Key_Z, this, |
1797 | SLOT( undo() ), actionCollection(), | 1797 | SLOT( undo() ), actionCollection(), |
1798 | "kaddressbook_undo" ); | 1798 | "kaddressbook_undo" ); |
1799 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, | 1799 | mActionRedo = new KAction( i18n( "Re&do" ), "redo", CTRL + SHIFT + Key_Z, |
1800 | this, SLOT( redo() ), actionCollection(), | 1800 | this, SLOT( redo() ), actionCollection(), |
1801 | "kaddressbook_redo" ); | 1801 | "kaddressbook_redo" ); |
1802 | } else { | 1802 | } else { |
1803 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); | 1803 | mActionCopy = KStdAction::copy( this, SLOT( copyContacts() ), actionCollection() ); |
1804 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); | 1804 | mActionCut = KStdAction::cut( this, SLOT( cutContacts() ), actionCollection() ); |
1805 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); | 1805 | mActionPaste = KStdAction::paste( this, SLOT( pasteContacts() ), actionCollection() ); |
1806 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); | 1806 | mActionSelectAll = KStdAction::selectAll( this, SLOT( selectAllContacts() ), actionCollection() ); |
1807 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); | 1807 | mActionUndo = KStdAction::undo( this, SLOT( undo() ), actionCollection() ); |
1808 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); | 1808 | mActionRedo = KStdAction::redo( this, SLOT( redo() ), actionCollection() ); |
1809 | } | 1809 | } |
1810 | 1810 | ||
1811 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", | 1811 | mActionDelete = new KAction( i18n( "&Delete Contact" ), "editdelete", |
1812 | Key_Delete, this, SLOT( deleteContacts() ), | 1812 | Key_Delete, this, SLOT( deleteContacts() ), |
1813 | actionCollection(), "edit_delete" ); | 1813 | actionCollection(), "edit_delete" ); |
1814 | 1814 | ||
1815 | mActionUndo->setEnabled( false ); | 1815 | mActionUndo->setEnabled( false ); |
1816 | mActionRedo->setEnabled( false ); | 1816 | mActionRedo->setEnabled( false ); |
1817 | 1817 | ||
1818 | // settings menu | 1818 | // settings menu |
1819 | #ifdef KAB_EMBEDDED | 1819 | #ifdef KAB_EMBEDDED |
1820 | //US special menuentry to configure the addressbook resources. On KDE | 1820 | //US special menuentry to configure the addressbook resources. On KDE |
1821 | // you do that through the control center !!! | 1821 | // you do that through the control center !!! |
1822 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, | 1822 | mActionConfigResources = new KAction( i18n( "Configure &Resources..." ), "configure_resources", 0, this, |
1823 | SLOT( configureResources() ), actionCollection(), | 1823 | SLOT( configureResources() ), actionCollection(), |
1824 | "kaddressbook_configure_resources" ); | 1824 | "kaddressbook_configure_resources" ); |
1825 | #endif //KAB_EMBEDDED | 1825 | #endif //KAB_EMBEDDED |
1826 | 1826 | ||
1827 | if ( mIsPart ) { | 1827 | if ( mIsPart ) { |
1828 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, | 1828 | mActionConfigKAddressbook = new KAction( i18n( "&Configure KAddressBook..." ), "configure", 0, this, |
1829 | SLOT( openConfigDialog() ), actionCollection(), | 1829 | SLOT( openConfigDialog() ), actionCollection(), |
1830 | "kaddressbook_configure" ); | 1830 | "kaddressbook_configure" ); |
1831 | 1831 | ||
1832 | mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, | 1832 | mActionConfigShortcuts = new KAction( i18n( "Configure S&hortcuts..." ), "configure_shortcuts", 0, |
1833 | this, SLOT( configureKeyBindings() ), actionCollection(), | 1833 | this, SLOT( configureKeyBindings() ), actionCollection(), |
1834 | "kaddressbook_configure_shortcuts" ); | 1834 | "kaddressbook_configure_shortcuts" ); |
1835 | #ifdef KAB_EMBEDDED | 1835 | #ifdef KAB_EMBEDDED |
1836 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); | 1836 | mActionConfigureToolbars = KStdAction::configureToolbars( this, SLOT( mMainWindow->configureToolbars() ), actionCollection() ); |
1837 | mActionConfigureToolbars->setEnabled( false ); | 1837 | mActionConfigureToolbars->setEnabled( false ); |
1838 | #endif //KAB_EMBEDDED | 1838 | #endif //KAB_EMBEDDED |
1839 | 1839 | ||
1840 | } else { | 1840 | } else { |
1841 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); | 1841 | mActionConfigKAddressbook = KStdAction::preferences( this, SLOT( openConfigDialog() ), actionCollection() ); |
1842 | 1842 | ||
1843 | mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); | 1843 | mActionKeyBindings = KStdAction::keyBindings( this, SLOT( configureKeyBindings() ), actionCollection() ); |
1844 | } | 1844 | } |
1845 | 1845 | ||
1846 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, | 1846 | mActionJumpBar = new KToggleAction( i18n( "Show Jump Bar" ), 0, 0, |
1847 | actionCollection(), "options_show_jump_bar" ); | 1847 | actionCollection(), "options_show_jump_bar" ); |
1848 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); | 1848 | connect( mActionJumpBar, SIGNAL( toggled( bool ) ), SLOT( setJumpButtonBarVisible( bool ) ) ); |
1849 | 1849 | ||
1850 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, | 1850 | mActionDetails = new KToggleAction( i18n( "Show Details" ), "listview", 0, |
1851 | actionCollection(), "options_show_details" ); | 1851 | actionCollection(), "options_show_details" ); |
1852 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); | 1852 | connect( mActionDetails, SIGNAL( toggled( bool ) ), SLOT( setDetailsVisible( bool ) ) ); |
1853 | 1853 | ||
1854 | // misc | 1854 | // misc |
1855 | // only enable LDAP lookup if we can handle the protocol | 1855 | // only enable LDAP lookup if we can handle the protocol |
1856 | #ifndef KAB_EMBEDDED | 1856 | #ifndef KAB_EMBEDDED |
1857 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { | 1857 | if ( KProtocolInfo::isKnownProtocol( KURL( "ldap://localhost" ) ) ) { |
1858 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, | 1858 | new KAction( i18n( "&Lookup Addresses in Directory" ), "find", 0, |
1859 | this, SLOT( openLDAPDialog() ), actionCollection(), | 1859 | this, SLOT( openLDAPDialog() ), actionCollection(), |
1860 | "ldap_lookup" ); | 1860 | "ldap_lookup" ); |
1861 | } | 1861 | } |
1862 | #else //KAB_EMBEDDED | 1862 | #else //KAB_EMBEDDED |
1863 | //qDebug("KABCore::initActions() LDAP has to be implemented"); | 1863 | //qDebug("KABCore::initActions() LDAP has to be implemented"); |
1864 | #endif //KAB_EMBEDDED | 1864 | #endif //KAB_EMBEDDED |
1865 | 1865 | ||
1866 | 1866 | ||
1867 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, | 1867 | mActionWhoAmI = new KAction( i18n( "Set Who Am I" ), "personal", 0, this, |
1868 | SLOT( setWhoAmI() ), actionCollection(), | 1868 | SLOT( setWhoAmI() ), actionCollection(), |
1869 | "set_personal" ); | 1869 | "set_personal" ); |
1870 | 1870 | ||
1871 | 1871 | ||
1872 | 1872 | ||
1873 | 1873 | ||
1874 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, | 1874 | mActionCategories = new KAction( i18n( "Set Categories" ), 0, this, |
1875 | SLOT( setCategories() ), actionCollection(), | 1875 | SLOT( setCategories() ), actionCollection(), |
1876 | "edit_set_categories" ); | 1876 | "edit_set_categories" ); |
1877 | 1877 | ||
1878 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, | 1878 | mActionRemoveVoice = new KAction( i18n( "Remove \"voice\"..." ), 0, this, |
1879 | SLOT( removeVoice() ), actionCollection(), | 1879 | SLOT( removeVoice() ), actionCollection(), |
1880 | "remove_voice" ); | 1880 | "remove_voice" ); |
@@ -2673,199 +2673,209 @@ bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBo | |||
2673 | inR = remote->findByUid( uid ); | 2673 | inR = remote->findByUid( uid ); |
2674 | if ( inR.isEmpty() ) { | 2674 | if ( inR.isEmpty() ) { |
2675 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2675 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2676 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2676 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2677 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2677 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2678 | local->removeAddressee( inL ); | 2678 | local->removeAddressee( inL ); |
2679 | ++deletedAddresseeL; | 2679 | ++deletedAddresseeL; |
2680 | } else { | 2680 | } else { |
2681 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2681 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2682 | inL.removeID(mCurrentSyncDevice ); | 2682 | inL.removeID(mCurrentSyncDevice ); |
2683 | ++addedAddresseeR; | 2683 | ++addedAddresseeR; |
2684 | inL.setRevision( modifiedCalendar ); | 2684 | inL.setRevision( modifiedCalendar ); |
2685 | local->insertAddressee( inL, false ); | 2685 | local->insertAddressee( inL, false ); |
2686 | inR = inL; | 2686 | inR = inL; |
2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2687 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2688 | inR.setResource( 0 ); | 2688 | inR.setResource( 0 ); |
2689 | remote->insertAddressee( inR, false ); | 2689 | remote->insertAddressee( inR, false ); |
2690 | } | 2690 | } |
2691 | } | 2691 | } |
2692 | } else { | 2692 | } else { |
2693 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2693 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2694 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2694 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2695 | local->removeAddressee( inL ); | 2695 | local->removeAddressee( inL ); |
2696 | ++deletedAddresseeL; | 2696 | ++deletedAddresseeL; |
2697 | } else { | 2697 | } else { |
2698 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2698 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2699 | ++addedAddresseeR; | 2699 | ++addedAddresseeR; |
2700 | inL.setRevision( modifiedCalendar ); | 2700 | inL.setRevision( modifiedCalendar ); |
2701 | local->insertAddressee( inL, false ); | 2701 | local->insertAddressee( inL, false ); |
2702 | inR = inL; | 2702 | inR = inL; |
2703 | inR.setResource( 0 ); | 2703 | inR.setResource( 0 ); |
2704 | remote->insertAddressee( inR, false ); | 2704 | remote->insertAddressee( inR, false ); |
2705 | } | 2705 | } |
2706 | } | 2706 | } |
2707 | } | 2707 | } |
2708 | } | 2708 | } |
2709 | } | 2709 | } |
2710 | ++incCounter; | 2710 | ++incCounter; |
2711 | } | 2711 | } |
2712 | el.clear(); | 2712 | el.clear(); |
2713 | syncManager->hideProgressBar(); | 2713 | syncManager->hideProgressBar(); |
2714 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2714 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2715 | // get rid of micro seconds | 2715 | // get rid of micro seconds |
2716 | QTime t = mLastAddressbookSync.time(); | 2716 | QTime t = mLastAddressbookSync.time(); |
2717 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2717 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2718 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2718 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2719 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2719 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2720 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2720 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2721 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2721 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2722 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2722 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2723 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2723 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2724 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2724 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2725 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2725 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2726 | addresseeRSync.setNote( "" ) ; | 2726 | addresseeRSync.setNote( "" ) ; |
2727 | addresseeLSync.setNote( "" ); | 2727 | addresseeLSync.setNote( "" ); |
2728 | 2728 | ||
2729 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2729 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2730 | remote->insertAddressee( addresseeRSync, false ); | 2730 | remote->insertAddressee( addresseeRSync, false ); |
2731 | local->insertAddressee( addresseeLSync, false ); | 2731 | local->insertAddressee( addresseeLSync, false ); |
2732 | QString mes; | 2732 | QString mes; |
2733 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); | 2733 | mes .sprintf( i18n("Synchronization summary:\n\n %d items added to local\n %d items added to remote\n %d items updated on local\n %d items updated on remote\n %d items deleted on local\n %d items deleted on remote\n"),addedAddressee, addedAddresseeR, changedLocal, changedRemote, deletedAddresseeL, deletedAddresseeR ); |
2734 | if ( syncManager->mShowSyncSummary ) { | 2734 | if ( syncManager->mShowSyncSummary ) { |
2735 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2735 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2736 | } | 2736 | } |
2737 | qDebug( mes ); | 2737 | qDebug( mes ); |
2738 | return syncOK; | 2738 | return syncOK; |
2739 | } | 2739 | } |
2740 | 2740 | ||
2741 | 2741 | ||
2742 | //this is a overwritten callbackmethods from the syncinterface | 2742 | //this is a overwritten callbackmethods from the syncinterface |
2743 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2743 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2744 | { | 2744 | { |
2745 | 2745 | ||
2746 | //pending prepare addresseeview for output | 2746 | //pending prepare addresseeview for output |
2747 | //pending detect, if remote file has REV field. if not switch to external sync | 2747 | //pending detect, if remote file has REV field. if not switch to external sync |
2748 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2748 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2749 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2749 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2750 | 2750 | ||
2751 | AddressBook abLocal(filename,"syncContact"); | 2751 | AddressBook abLocal(filename,"syncContact"); |
2752 | bool syncOK = false; | 2752 | bool syncOK = false; |
2753 | if ( abLocal.load() ) { | 2753 | if ( abLocal.load() ) { |
2754 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2754 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2755 | bool external = false; | 2755 | bool external = false; |
2756 | bool isXML = false; | 2756 | bool isXML = false; |
2757 | if ( filename.right(4) == ".xml") { | 2757 | if ( filename.right(4) == ".xml") { |
2758 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2758 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2759 | isXML = true; | 2759 | isXML = true; |
2760 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2760 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2761 | } else { | 2761 | } else { |
2762 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2762 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2763 | if ( ! lse.isEmpty() ) { | 2763 | if ( ! lse.isEmpty() ) { |
2764 | if ( lse.familyName().left(4) == "!E: " ) | 2764 | if ( lse.familyName().left(4) == "!E: " ) |
2765 | external = true; | 2765 | external = true; |
2766 | } else { | 2766 | } else { |
2767 | bool found = false; | 2767 | bool found = false; |
2768 | AddressBook::Iterator it; | 2768 | AddressBook::Iterator it; |
2769 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2769 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2770 | if ( (*it).revision().date().year() > 2003 ) { | 2770 | if ( (*it).revision().date().year() > 2003 ) { |
2771 | found = true; | 2771 | found = true; |
2772 | break; | 2772 | break; |
2773 | } | 2773 | } |
2774 | } | 2774 | } |
2775 | external = ! found; | 2775 | external = ! found; |
2776 | } | 2776 | } |
2777 | 2777 | ||
2778 | if ( external ) { | 2778 | if ( external ) { |
2779 | qDebug("Setting vcf mode to external "); | 2779 | qDebug("Setting vcf mode to external "); |
2780 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2780 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2781 | AddressBook::Iterator it; | 2781 | AddressBook::Iterator it; |
2782 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2782 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2783 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2783 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2784 | (*it).computeCsum( mCurrentSyncDevice ); | 2784 | (*it).computeCsum( mCurrentSyncDevice ); |
2785 | } | 2785 | } |
2786 | } | 2786 | } |
2787 | } | 2787 | } |
2788 | //AddressBook::Iterator it; | 2788 | //AddressBook::Iterator it; |
2789 | //QStringList vcards; | 2789 | //QStringList vcards; |
2790 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2790 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2791 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2791 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2792 | //} | 2792 | //} |
2793 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2793 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2794 | if ( syncOK ) { | 2794 | if ( syncOK ) { |
2795 | if ( syncManager->mWriteBackFile ) | 2795 | if ( syncManager->mWriteBackFile ) |
2796 | { | 2796 | { |
2797 | if ( external ) | 2797 | if ( external ) |
2798 | abLocal.removeSyncAddressees( !isXML); | 2798 | abLocal.removeSyncAddressees( !isXML); |
2799 | qDebug("Saving remote AB "); | 2799 | qDebug("Saving remote AB "); |
2800 | abLocal.saveAB(); | 2800 | abLocal.saveAB(); |
2801 | if ( isXML ) { | 2801 | if ( isXML ) { |
2802 | // afterwrite processing | 2802 | // afterwrite processing |
2803 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2803 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2804 | } | 2804 | } |
2805 | } | 2805 | } |
2806 | } | 2806 | } |
2807 | setModified(); | 2807 | setModified(); |
2808 | 2808 | ||
2809 | } | 2809 | } |
2810 | if ( syncOK ) | 2810 | if ( syncOK ) |
2811 | mViewManager->refreshView(); | 2811 | mViewManager->refreshView(); |
2812 | return syncOK; | 2812 | return syncOK; |
2813 | #if 0 | 2813 | #if 0 |
2814 | 2814 | ||
2815 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2815 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2816 | getEventViewerDialog()->setSyncMode( true ); | 2816 | getEventViewerDialog()->setSyncMode( true ); |
2817 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2817 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2818 | getEventViewerDialog()->setSyncMode( false ); | 2818 | getEventViewerDialog()->setSyncMode( false ); |
2819 | if ( syncOK ) { | 2819 | if ( syncOK ) { |
2820 | if ( KOPrefs::instance()->mWriteBackFile ) | 2820 | if ( KOPrefs::instance()->mWriteBackFile ) |
2821 | { | 2821 | { |
2822 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2822 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2823 | storage->save(); | 2823 | storage->save(); |
2824 | } | 2824 | } |
2825 | } | 2825 | } |
2826 | setModified(); | 2826 | setModified(); |
2827 | } | 2827 | } |
2828 | 2828 | ||
2829 | #endif | 2829 | #endif |
2830 | } | 2830 | } |
2831 | 2831 | ||
2832 | 2832 | ||
2833 | //this is a overwritten callbackmethods from the syncinterface | 2833 | //this is a overwritten callbackmethods from the syncinterface |
2834 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2834 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2835 | { | 2835 | { |
2836 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2836 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2837 | 2837 | ||
2838 | AddressBook abLocal( resource,"syncContact"); | 2838 | AddressBook abLocal( resource,"syncContact"); |
2839 | bool syncOK = false; | 2839 | bool syncOK = false; |
2840 | if ( abLocal.load() ) { | 2840 | if ( abLocal.load() ) { |
2841 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2841 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2842 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2842 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2843 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2843 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2844 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2844 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2845 | if ( syncOK ) { | 2845 | if ( syncOK ) { |
2846 | if ( syncManager->mWriteBackFile ) { | 2846 | if ( syncManager->mWriteBackFile ) { |
2847 | abLocal.saveAB(); | 2847 | abLocal.saveAB(); |
2848 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2848 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2849 | } | 2849 | } |
2850 | } | 2850 | } |
2851 | setModified(); | 2851 | setModified(); |
2852 | } | 2852 | } |
2853 | if ( syncOK ) | 2853 | if ( syncOK ) |
2854 | mViewManager->refreshView(); | 2854 | mViewManager->refreshView(); |
2855 | return syncOK; | 2855 | return syncOK; |
2856 | 2856 | ||
2857 | } | 2857 | } |
2858 | 2858 | ||
2859 | void KABCore::getFile( bool success ) | 2859 | void KABCore::getFile( bool success ) |
2860 | { | 2860 | { |
2861 | if ( ! success ) { | 2861 | if ( ! success ) { |
2862 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 2862 | setCaption( i18n("Error receiving file. Nothing changed!") ); |
2863 | return; | 2863 | return; |
2864 | } | 2864 | } |
2865 | //mView->watchSavedFile(); | 2865 | mAddressBook->importFromFile( sentSyncFile() ); |
2866 | //mView->openCalendar( defaultFileName() ); | ||
2867 | // pending: reload received file! | ||
2868 | setCaption( i18n("Pi-Sync successful!") ); | 2866 | setCaption( i18n("Pi-Sync successful!") ); |
2869 | } | 2867 | } |
2868 | void KABCore::syncFileRequest() | ||
2869 | { | ||
2870 | mAddressBook->export2File( sentSyncFile() ); | ||
2871 | } | ||
2872 | QString KABCore::sentSyncFile() | ||
2873 | { | ||
2874 | #ifdef _WIN32_ | ||
2875 | return locateLocal( "tmp", "syncab.ics" ); | ||
2876 | #else | ||
2877 | return QString( "/tmp/kapitempfile.vcf" ); | ||
2878 | #endif | ||
2879 | } | ||
2870 | 2880 | ||
2871 | 2881 | ||
diff --git a/kaddressbook/kabcore.h b/kaddressbook/kabcore.h index 355e828..987369d 100644 --- a/kaddressbook/kabcore.h +++ b/kaddressbook/kabcore.h | |||
@@ -154,326 +154,328 @@ class KABCore : public QWidget, public KSyncInterface | |||
154 | 154 | ||
155 | /** | 155 | /** |
156 | Opens the preferred mail composer with all selected contacts as | 156 | Opens the preferred mail composer with all selected contacts as |
157 | arguments. | 157 | arguments. |
158 | */ | 158 | */ |
159 | void sendMail(); | 159 | void sendMail(); |
160 | 160 | ||
161 | /** | 161 | /** |
162 | Opens the preferred mail composer with the given contacts as | 162 | Opens the preferred mail composer with the given contacts as |
163 | arguments. | 163 | arguments. |
164 | */ | 164 | */ |
165 | void sendMail( const QString& email ); | 165 | void sendMail( const QString& email ); |
166 | 166 | ||
167 | 167 | ||
168 | void mailVCard(); | 168 | void mailVCard(); |
169 | void mailVCard(const QStringList& uids); | 169 | void mailVCard(const QStringList& uids); |
170 | 170 | ||
171 | /** | 171 | /** |
172 | Beams the "WhoAmI contact. | 172 | Beams the "WhoAmI contact. |
173 | */ | 173 | */ |
174 | void beamMySelf(); | 174 | void beamMySelf(); |
175 | 175 | ||
176 | void beamVCard(); | 176 | void beamVCard(); |
177 | void export2phone(); | 177 | void export2phone(); |
178 | void beamVCard(const QStringList& uids); | 178 | void beamVCard(const QStringList& uids); |
179 | void beamDone( Ir *ir ); | 179 | void beamDone( Ir *ir ); |
180 | 180 | ||
181 | 181 | ||
182 | /** | 182 | /** |
183 | Starts the preferred web browser with the given URL as argument. | 183 | Starts the preferred web browser with the given URL as argument. |
184 | */ | 184 | */ |
185 | void browse( const QString& url ); | 185 | void browse( const QString& url ); |
186 | 186 | ||
187 | /** | 187 | /** |
188 | Select all contacts in the view. | 188 | Select all contacts in the view. |
189 | */ | 189 | */ |
190 | void selectAllContacts(); | 190 | void selectAllContacts(); |
191 | 191 | ||
192 | /** | 192 | /** |
193 | Deletes all selected contacts from the address book. | 193 | Deletes all selected contacts from the address book. |
194 | */ | 194 | */ |
195 | void deleteContacts(); | 195 | void deleteContacts(); |
196 | 196 | ||
197 | /** | 197 | /** |
198 | Deletes given contacts from the address book. | 198 | Deletes given contacts from the address book. |
199 | 199 | ||
200 | @param uids The uids of the contacts, which shall be deleted. | 200 | @param uids The uids of the contacts, which shall be deleted. |
201 | */ | 201 | */ |
202 | void deleteContacts( const QStringList &uids ); | 202 | void deleteContacts( const QStringList &uids ); |
203 | 203 | ||
204 | /** | 204 | /** |
205 | Copys the selected contacts into clipboard for later pasting. | 205 | Copys the selected contacts into clipboard for later pasting. |
206 | */ | 206 | */ |
207 | void copyContacts(); | 207 | void copyContacts(); |
208 | 208 | ||
209 | /** | 209 | /** |
210 | Cuts the selected contacts and stores them for later pasting. | 210 | Cuts the selected contacts and stores them for later pasting. |
211 | */ | 211 | */ |
212 | void cutContacts(); | 212 | void cutContacts(); |
213 | 213 | ||
214 | /** | 214 | /** |
215 | Paste contacts from clipboard into the address book. | 215 | Paste contacts from clipboard into the address book. |
216 | */ | 216 | */ |
217 | void pasteContacts(); | 217 | void pasteContacts(); |
218 | 218 | ||
219 | /** | 219 | /** |
220 | Paste given contacts into the address book. | 220 | Paste given contacts into the address book. |
221 | 221 | ||
222 | @param list The list of addressee, which shall be pasted. | 222 | @param list The list of addressee, which shall be pasted. |
223 | */ | 223 | */ |
224 | void pasteContacts( KABC::Addressee::List &list ); | 224 | void pasteContacts( KABC::Addressee::List &list ); |
225 | 225 | ||
226 | /** | 226 | /** |
227 | Sets the whoAmI contact, that is used by many other programs to | 227 | Sets the whoAmI contact, that is used by many other programs to |
228 | get personal information about the current user. | 228 | get personal information about the current user. |
229 | */ | 229 | */ |
230 | void setWhoAmI(); | 230 | void setWhoAmI(); |
231 | 231 | ||
232 | /** | 232 | /** |
233 | Displays the category dialog and applies the result to all | 233 | Displays the category dialog and applies the result to all |
234 | selected contacts. | 234 | selected contacts. |
235 | */ | 235 | */ |
236 | void setCategories(); | 236 | void setCategories(); |
237 | 237 | ||
238 | /** | 238 | /** |
239 | Sets the field list of the Incremental Search Widget. | 239 | Sets the field list of the Incremental Search Widget. |
240 | */ | 240 | */ |
241 | void setSearchFields( const KABC::Field::List &fields ); | 241 | void setSearchFields( const KABC::Field::List &fields ); |
242 | 242 | ||
243 | /** | 243 | /** |
244 | Search with the current search field for a contact, that matches | 244 | Search with the current search field for a contact, that matches |
245 | the given text, and selects it in the view. | 245 | the given text, and selects it in the view. |
246 | */ | 246 | */ |
247 | void incrementalSearch( const QString& text ); | 247 | void incrementalSearch( const QString& text ); |
248 | 248 | ||
249 | /** | 249 | /** |
250 | Marks the address book as modified. | 250 | Marks the address book as modified. |
251 | */ | 251 | */ |
252 | void setModified(); | 252 | void setModified(); |
253 | /** | 253 | /** |
254 | Marks the address book as modified without refreshing the view. | 254 | Marks the address book as modified without refreshing the view. |
255 | */ | 255 | */ |
256 | void setModifiedWOrefresh(); | 256 | void setModifiedWOrefresh(); |
257 | 257 | ||
258 | /** | 258 | /** |
259 | Marks the address book as modified concerning the argument. | 259 | Marks the address book as modified concerning the argument. |
260 | */ | 260 | */ |
261 | void setModified( bool modified ); | 261 | void setModified( bool modified ); |
262 | 262 | ||
263 | /** | 263 | /** |
264 | Returns whether the address book is modified. | 264 | Returns whether the address book is modified. |
265 | */ | 265 | */ |
266 | bool modified() const; | 266 | bool modified() const; |
267 | 267 | ||
268 | /** | 268 | /** |
269 | Called whenever an contact is modified in the contact editor | 269 | Called whenever an contact is modified in the contact editor |
270 | dialog or the quick edit. | 270 | dialog or the quick edit. |
271 | */ | 271 | */ |
272 | void contactModified( const KABC::Addressee &addr ); | 272 | void contactModified( const KABC::Addressee &addr ); |
273 | 273 | ||
274 | /** | 274 | /** |
275 | DCOP METHODS. | 275 | DCOP METHODS. |
276 | */ | 276 | */ |
277 | void addEmail( QString addr ); | 277 | void addEmail( QString addr ); |
278 | void importVCard( const KURL& url, bool showPreview ); | 278 | void importVCard( const KURL& url, bool showPreview ); |
279 | void importVCard( const QString& vCard, bool showPreview ); | 279 | void importVCard( const QString& vCard, bool showPreview ); |
280 | void newContact(); | 280 | void newContact(); |
281 | QString getNameByPhone( const QString& phone ); | 281 | QString getNameByPhone( const QString& phone ); |
282 | /** | 282 | /** |
283 | END DCOP METHODS | 283 | END DCOP METHODS |
284 | */ | 284 | */ |
285 | 285 | ||
286 | /** | 286 | /** |
287 | Saves the contents of the AddressBook back to disk. | 287 | Saves the contents of the AddressBook back to disk. |
288 | */ | 288 | */ |
289 | void save(); | 289 | void save(); |
290 | 290 | ||
291 | /** | 291 | /** |
292 | Undos the last command using the undo stack. | 292 | Undos the last command using the undo stack. |
293 | */ | 293 | */ |
294 | void undo(); | 294 | void undo(); |
295 | 295 | ||
296 | /** | 296 | /** |
297 | Redos the last command that was undone, using the redo stack. | 297 | Redos the last command that was undone, using the redo stack. |
298 | */ | 298 | */ |
299 | void redo(); | 299 | void redo(); |
300 | 300 | ||
301 | /** | 301 | /** |
302 | Shows the edit dialog for the given uid. If the uid is QString::null, | 302 | Shows the edit dialog for the given uid. If the uid is QString::null, |
303 | the method will try to find a selected addressee in the view. | 303 | the method will try to find a selected addressee in the view. |
304 | */ | 304 | */ |
305 | void editContact( const QString &uid /*US = QString::null*/ ); | 305 | void editContact( const QString &uid /*US = QString::null*/ ); |
306 | //US added a second method without defaultparameter | 306 | //US added a second method without defaultparameter |
307 | void editContact2(); | 307 | void editContact2(); |
308 | 308 | ||
309 | /** | 309 | /** |
310 | Shows or edits the detail view for the given uid. If the uid is QString::null, | 310 | Shows or edits the detail view for the given uid. If the uid is QString::null, |
311 | the method will try to find a selected addressee in the view. | 311 | the method will try to find a selected addressee in the view. |
312 | */ | 312 | */ |
313 | void executeContact( const QString &uid /*US = QString::null*/ ); | 313 | void executeContact( const QString &uid /*US = QString::null*/ ); |
314 | 314 | ||
315 | /** | 315 | /** |
316 | Launches the configuration dialog. | 316 | Launches the configuration dialog. |
317 | */ | 317 | */ |
318 | void openConfigDialog(); | 318 | void openConfigDialog(); |
319 | 319 | ||
320 | /** | 320 | /** |
321 | Launches the ldap search dialog. | 321 | Launches the ldap search dialog. |
322 | */ | 322 | */ |
323 | void openLDAPDialog(); | 323 | void openLDAPDialog(); |
324 | 324 | ||
325 | /** | 325 | /** |
326 | Creates a KAddressBookPrinter, which will display the print | 326 | Creates a KAddressBookPrinter, which will display the print |
327 | dialog and do the printing. | 327 | dialog and do the printing. |
328 | */ | 328 | */ |
329 | void print(); | 329 | void print(); |
330 | 330 | ||
331 | /** | 331 | /** |
332 | Registers a new GUI client, so plugins can register its actions. | 332 | Registers a new GUI client, so plugins can register its actions. |
333 | */ | 333 | */ |
334 | void addGUIClient( KXMLGUIClient *client ); | 334 | void addGUIClient( KXMLGUIClient *client ); |
335 | 335 | ||
336 | void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); | 336 | void requestForNameEmailUidList(const QString& sourceChannel, const QString& sessionuid); |
337 | void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); | 337 | void requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid); |
338 | void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid); | 338 | void requestForBirthdayList(const QString& sourceChannel, const QString& sessionuid); |
339 | 339 | ||
340 | 340 | ||
341 | signals: | 341 | signals: |
342 | void contactSelected( const QString &name ); | 342 | void contactSelected( const QString &name ); |
343 | void contactSelected( const QPixmap &pixmap ); | 343 | void contactSelected( const QPixmap &pixmap ); |
344 | public slots: | 344 | public slots: |
345 | void getFile( bool success ); | 345 | void getFile( bool success ); |
346 | void syncFileRequest(); | ||
346 | void setDetailsVisible( bool visible ); | 347 | void setDetailsVisible( bool visible ); |
347 | void setDetailsToState(); | 348 | void setDetailsToState(); |
348 | // void slotSyncMenu( int ); | 349 | // void slotSyncMenu( int ); |
349 | private slots: | 350 | private slots: |
350 | void setJumpButtonBarVisible( bool visible ); | 351 | void setJumpButtonBarVisible( bool visible ); |
351 | void importFromOL(); | 352 | void importFromOL(); |
352 | void extensionModified( const KABC::Addressee::List &list ); | 353 | void extensionModified( const KABC::Addressee::List &list ); |
353 | void extensionChanged( int id ); | 354 | void extensionChanged( int id ); |
354 | void clipboardDataChanged(); | 355 | void clipboardDataChanged(); |
355 | void updateActionMenu(); | 356 | void updateActionMenu(); |
356 | void configureKeyBindings(); | 357 | void configureKeyBindings(); |
357 | void removeVoice(); | 358 | void removeVoice(); |
358 | #ifdef KAB_EMBEDDED | 359 | #ifdef KAB_EMBEDDED |
359 | void configureResources(); | 360 | void configureResources(); |
360 | #endif //KAB_EMBEDDED | 361 | #endif //KAB_EMBEDDED |
361 | 362 | ||
362 | void slotEditorDestroyed( const QString &uid ); | 363 | void slotEditorDestroyed( const QString &uid ); |
363 | void configurationChanged(); | 364 | void configurationChanged(); |
364 | void addressBookChanged(); | 365 | void addressBookChanged(); |
365 | 366 | ||
366 | private: | 367 | private: |
367 | void initGUI(); | 368 | void initGUI(); |
368 | void initActions(); | 369 | void initActions(); |
369 | 370 | ||
370 | AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, | 371 | AddresseeEditorDialog *createAddresseeEditorDialog( QWidget *parent, |
371 | const char *name = 0 ); | 372 | const char *name = 0 ); |
372 | 373 | ||
373 | KXMLGUIClient *mGUIClient; | 374 | KXMLGUIClient *mGUIClient; |
374 | 375 | ||
375 | KABC::AddressBook *mAddressBook; | 376 | KABC::AddressBook *mAddressBook; |
376 | 377 | ||
377 | ViewManager *mViewManager; | 378 | ViewManager *mViewManager; |
378 | // QSplitter *mDetailsSplitter; | 379 | // QSplitter *mDetailsSplitter; |
379 | KDGanttMinimizeSplitter *mExtensionBarSplitter; | 380 | KDGanttMinimizeSplitter *mExtensionBarSplitter; |
380 | ViewContainer *mDetails; | 381 | ViewContainer *mDetails; |
381 | KDGanttMinimizeSplitter* mMiniSplitter; | 382 | KDGanttMinimizeSplitter* mMiniSplitter; |
382 | XXPortManager *mXXPortManager; | 383 | XXPortManager *mXXPortManager; |
383 | JumpButtonBar *mJumpButtonBar; | 384 | JumpButtonBar *mJumpButtonBar; |
384 | IncSearchWidget *mIncSearchWidget; | 385 | IncSearchWidget *mIncSearchWidget; |
385 | ExtensionManager *mExtensionManager; | 386 | ExtensionManager *mExtensionManager; |
386 | 387 | ||
387 | KCMultiDialog *mConfigureDialog; | 388 | KCMultiDialog *mConfigureDialog; |
388 | 389 | ||
389 | #ifndef KAB_EMBEDDED | 390 | #ifndef KAB_EMBEDDED |
390 | LDAPSearchDialog *mLdapSearchDialog; | 391 | LDAPSearchDialog *mLdapSearchDialog; |
391 | #endif //KAB_EMBEDDED | 392 | #endif //KAB_EMBEDDED |
392 | // QDict<AddresseeEditorDialog> mEditorDict; | 393 | // QDict<AddresseeEditorDialog> mEditorDict; |
393 | AddresseeEditorDialog *mEditorDialog; | 394 | AddresseeEditorDialog *mEditorDialog; |
394 | bool mReadWrite; | 395 | bool mReadWrite; |
395 | bool mModified; | 396 | bool mModified; |
396 | bool mIsPart; | 397 | bool mIsPart; |
397 | bool mMultipleViewsAtOnce; | 398 | bool mMultipleViewsAtOnce; |
398 | 399 | ||
399 | 400 | ||
400 | //US file menu | 401 | //US file menu |
401 | KAction *mActionMail; | 402 | KAction *mActionMail; |
402 | KAction *mActionBeam; | 403 | KAction *mActionBeam; |
403 | KAction *mActionExport2phone; | 404 | KAction *mActionExport2phone; |
404 | KAction* mActionPrint; | 405 | KAction* mActionPrint; |
405 | KAction* mActionNewContact; | 406 | KAction* mActionNewContact; |
406 | KAction *mActionSave; | 407 | KAction *mActionSave; |
407 | KAction *mActionEditAddressee; | 408 | KAction *mActionEditAddressee; |
408 | KAction *mActionMailVCard; | 409 | KAction *mActionMailVCard; |
409 | KAction *mActionBeamVCard; | 410 | KAction *mActionBeamVCard; |
410 | 411 | ||
411 | KAction *mActionQuit; | 412 | KAction *mActionQuit; |
412 | 413 | ||
413 | //US edit menu | 414 | //US edit menu |
414 | KAction *mActionCopy; | 415 | KAction *mActionCopy; |
415 | KAction *mActionCut; | 416 | KAction *mActionCut; |
416 | KAction *mActionPaste; | 417 | KAction *mActionPaste; |
417 | KAction *mActionSelectAll; | 418 | KAction *mActionSelectAll; |
418 | KAction *mActionUndo; | 419 | KAction *mActionUndo; |
419 | KAction *mActionRedo; | 420 | KAction *mActionRedo; |
420 | KAction *mActionDelete; | 421 | KAction *mActionDelete; |
421 | 422 | ||
422 | //US settings menu | 423 | //US settings menu |
423 | KAction *mActionConfigResources; | 424 | KAction *mActionConfigResources; |
424 | KAction *mActionConfigKAddressbook; | 425 | KAction *mActionConfigKAddressbook; |
425 | KAction *mActionConfigShortcuts; | 426 | KAction *mActionConfigShortcuts; |
426 | KAction *mActionConfigureToolbars; | 427 | KAction *mActionConfigureToolbars; |
427 | KAction *mActionKeyBindings; | 428 | KAction *mActionKeyBindings; |
428 | KToggleAction *mActionJumpBar; | 429 | KToggleAction *mActionJumpBar; |
429 | KToggleAction *mActionDetails; | 430 | KToggleAction *mActionDetails; |
430 | KAction *mActionWhoAmI; | 431 | KAction *mActionWhoAmI; |
431 | KAction *mActionCategories; | 432 | KAction *mActionCategories; |
432 | KAction *mActionAboutKAddressbook; | 433 | KAction *mActionAboutKAddressbook; |
433 | KAction *mActionLicence; | 434 | KAction *mActionLicence; |
434 | KAction *mActionFaq; | 435 | KAction *mActionFaq; |
435 | 436 | ||
436 | KAction *mActionDeleteView; | 437 | KAction *mActionDeleteView; |
437 | 438 | ||
438 | QPopupMenu *viewMenu; | 439 | QPopupMenu *viewMenu; |
439 | QPopupMenu *filterMenu; | 440 | QPopupMenu *filterMenu; |
440 | QPopupMenu *settingsMenu; | 441 | QPopupMenu *settingsMenu; |
441 | QPopupMenu *changeMenu; | 442 | QPopupMenu *changeMenu; |
442 | //US QAction *mActionSave; | 443 | //US QAction *mActionSave; |
443 | QPopupMenu *ImportMenu; | 444 | QPopupMenu *ImportMenu; |
444 | QPopupMenu *ExportMenu; | 445 | QPopupMenu *ExportMenu; |
445 | //LR additional methods | 446 | //LR additional methods |
446 | KAction *mActionRemoveVoice; | 447 | KAction *mActionRemoveVoice; |
447 | KAction * mActionImportOL; | 448 | KAction * mActionImportOL; |
448 | 449 | ||
449 | #ifndef KAB_EMBEDDED | 450 | #ifndef KAB_EMBEDDED |
450 | KAddressBookService *mAddressBookService; | 451 | KAddressBookService *mAddressBookService; |
451 | #endif //KAB_EMBEDDED | 452 | #endif //KAB_EMBEDDED |
452 | 453 | ||
453 | class KABCorePrivate; | 454 | class KABCorePrivate; |
454 | KABCorePrivate *d; | 455 | KABCorePrivate *d; |
455 | //US bool mBlockSaveFlag; | 456 | //US bool mBlockSaveFlag; |
456 | 457 | ||
457 | #ifdef KAB_EMBEDDED | 458 | #ifdef KAB_EMBEDDED |
458 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient | 459 | KAddressBookMain *mMainWindow; // should be the same like mGUIClient |
459 | #endif //KAB_EMBEDDED | 460 | #endif //KAB_EMBEDDED |
460 | 461 | ||
461 | //this are the overwritten callbackmethods from the syncinterface | 462 | //this are the overwritten callbackmethods from the syncinterface |
462 | virtual bool sync(KSyncManager* manager, QString filename, int mode); | 463 | virtual bool sync(KSyncManager* manager, QString filename, int mode); |
463 | virtual bool syncExternal(KSyncManager* manager, QString resource); | 464 | virtual bool syncExternal(KSyncManager* manager, QString resource); |
464 | 465 | ||
465 | 466 | ||
466 | // LR ******************************* | 467 | // LR ******************************* |
467 | // sync stuff! | 468 | // sync stuff! |
469 | QString sentSyncFile(); | ||
468 | QPopupMenu *syncMenu; | 470 | QPopupMenu *syncMenu; |
469 | KSyncManager* syncManager; | 471 | KSyncManager* syncManager; |
470 | int mGlobalSyncMode; | 472 | int mGlobalSyncMode; |
471 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); | 473 | bool synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode); |
472 | KABC::Addressee getLastSyncAddressee(); | 474 | KABC::Addressee getLastSyncAddressee(); |
473 | QDateTime mLastAddressbookSync; | 475 | QDateTime mLastAddressbookSync; |
474 | int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); | 476 | int takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ); |
475 | // ********************* | 477 | // ********************* |
476 | 478 | ||
477 | }; | 479 | }; |
478 | 480 | ||
479 | #endif | 481 | #endif |
diff --git a/kaddressbook/xxport/vcard_xxport.cpp b/kaddressbook/xxport/vcard_xxport.cpp index acf6419..3079d42 100644 --- a/kaddressbook/xxport/vcard_xxport.cpp +++ b/kaddressbook/xxport/vcard_xxport.cpp | |||
@@ -1,256 +1,257 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KAddressbook. | 2 | This file is part of KAddressbook. |
3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2003 Tobias Koenig <tokoe@kde.org> |
4 | 4 | ||
5 | This program is free software; you can redistribute it and/or modify | 5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by | 6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or | 7 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. | 8 | (at your option) any later version. |
9 | 9 | ||
10 | This program is distributed in the hope that it will be useful, | 10 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. | 13 | GNU General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU General Public License | 15 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software | 16 | along with this program; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
18 | 18 | ||
19 | As a special exception, permission is given to link this program | 19 | As a special exception, permission is given to link this program |
20 | with any edition of Qt, and distribute the resulting executable, | 20 | with any edition of Qt, and distribute the resulting executable, |
21 | without including the source code for Qt in the source distribution. | 21 | without including the source code for Qt in the source distribution. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | /* | 24 | /* |
25 | Enhanced Version of the file for platform independent KDE tools. | 25 | Enhanced Version of the file for platform independent KDE tools. |
26 | Copyright (c) 2004 Ulf Schenk | 26 | Copyright (c) 2004 Ulf Schenk |
27 | 27 | ||
28 | $Id$ | 28 | $Id$ |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <qfile.h> | 31 | #include <qfile.h> |
32 | #include <qtextstream.h> | 32 | #include <qtextstream.h> |
33 | 33 | ||
34 | #include <kabc/vcardconverter.h> | 34 | #include <kabc/vcardconverter.h> |
35 | #include <kabc/vcardparser/vcardtool.h> | 35 | #include <kabc/vcardparser/vcardtool.h> |
36 | #include <kfiledialog.h> | 36 | #include <kfiledialog.h> |
37 | #ifndef KAB_EMBEDDED | 37 | #ifndef KAB_EMBEDDED |
38 | #include <kio/netaccess.h> | 38 | #include <kio/netaccess.h> |
39 | #endif //KAB_EMBEDDED | 39 | #endif //KAB_EMBEDDED |
40 | 40 | ||
41 | #include <klocale.h> | 41 | #include <klocale.h> |
42 | #include <kmessagebox.h> | 42 | #include <kmessagebox.h> |
43 | #include <ktempfile.h> | 43 | #include <ktempfile.h> |
44 | #include <kurl.h> | 44 | #include <kurl.h> |
45 | 45 | ||
46 | #include "xxportmanager.h" | 46 | #include "xxportmanager.h" |
47 | 47 | ||
48 | #include "vcard_xxport.h" | 48 | #include "vcard_xxport.h" |
49 | 49 | ||
50 | #ifndef KAB_EMBEDDED | 50 | #ifndef KAB_EMBEDDED |
51 | 51 | ||
52 | class VCardXXPortFactory : public XXPortFactory | 52 | class VCardXXPortFactory : public XXPortFactory |
53 | { | 53 | { |
54 | public: | 54 | public: |
55 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 55 | XXPortObject *xxportObject( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
56 | { | 56 | { |
57 | return new VCardXXPort( ab, parent, name ); | 57 | return new VCardXXPort( ab, parent, name ); |
58 | } | 58 | } |
59 | }; | 59 | }; |
60 | #endif //KAB_EMBEDDED | 60 | #endif //KAB_EMBEDDED |
61 | 61 | ||
62 | 62 | ||
63 | extern "C" | 63 | extern "C" |
64 | { | 64 | { |
65 | #ifndef KAB_EMBEDDED | 65 | #ifndef KAB_EMBEDDED |
66 | void *init_libkaddrbk_vcard_xxport() | 66 | void *init_libkaddrbk_vcard_xxport() |
67 | #else //KAB_EMBEDDED | 67 | #else //KAB_EMBEDDED |
68 | void *init_microkaddrbk_vcard_xxport() | 68 | void *init_microkaddrbk_vcard_xxport() |
69 | #endif //KAB_EMBEDDED | 69 | #endif //KAB_EMBEDDED |
70 | { | 70 | { |
71 | return ( new VCardXXPortFactory() ); | 71 | return ( new VCardXXPortFactory() ); |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | 75 | ||
76 | VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) | 76 | VCardXXPort::VCardXXPort( KABC::AddressBook *ab, QWidget *parent, const char *name ) |
77 | : XXPortObject( ab, parent, name ) | 77 | : XXPortObject( ab, parent, name ) |
78 | { | 78 | { |
79 | createImportAction( i18n( "Import vCard..." ) ); | 79 | createImportAction( i18n( "Import vCard..." ) ); |
80 | //US KABC::VCardConverter does not support the export of 2.1 addressbooks. | 80 | //US KABC::VCardConverter does not support the export of 2.1 addressbooks. |
81 | //US createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); | 81 | //US createExportAction( i18n( "Export vCard 2.1..." ), "v21" ); |
82 | createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); | 82 | createExportAction( i18n( "Export vCard 3.0..." ), "v30" ); |
83 | } | 83 | } |
84 | 84 | ||
85 | bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) | 85 | bool VCardXXPort::exportContacts( const KABC::AddresseeList &list, const QString &data ) |
86 | { | 86 | { |
87 | QString name; | 87 | QString name; |
88 | 88 | ||
89 | if ( list.count() == 1 ) | 89 | if ( list.count() == 1 ) |
90 | name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; | 90 | name = list[ 0 ].givenName() + "_" + list[ 0 ].familyName() + ".vcf"; |
91 | else | 91 | else |
92 | name = "addressbook.vcf"; | 92 | name = "addressbook.vcf"; |
93 | 93 | ||
94 | #ifndef KAB_EMBEDDED | 94 | #ifndef KAB_EMBEDDED |
95 | QString fileName = KFileDialog::getSaveFileName( name ); | 95 | QString fileName = KFileDialog::getSaveFileName( name ); |
96 | #else //KAB_EMBEDDED | 96 | #else //KAB_EMBEDDED |
97 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); | 97 | QString fileName = KFileDialog::getSaveFileName( name, i18n("Save file"), parentWidget() ); |
98 | #endif //KAB_EMBEDDED | 98 | #endif //KAB_EMBEDDED |
99 | 99 | ||
100 | if ( fileName.isEmpty() ) | 100 | if ( fileName.isEmpty() ) |
101 | return false; | 101 | return false; |
102 | 102 | ||
103 | QFile outFile( fileName ); | 103 | QFile outFile( fileName ); |
104 | if ( !outFile.open( IO_WriteOnly ) ) { | 104 | if ( !outFile.open( IO_WriteOnly ) ) { |
105 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 105 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
106 | KMessageBox::error( parentWidget(), text.arg( fileName ) ); | 106 | KMessageBox::error( parentWidget(), text.arg( fileName ) ); |
107 | return false; | 107 | return false; |
108 | } | 108 | } |
109 | 109 | ||
110 | QTextStream t( &outFile ); | 110 | QTextStream t( &outFile ); |
111 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 111 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
112 | 112 | ||
113 | KABC::Addressee::List::ConstIterator it; | 113 | KABC::Addressee::List::ConstIterator it; |
114 | for ( it = list.begin(); it != list.end(); ++it ) { | 114 | for ( it = list.begin(); it != list.end(); ++it ) { |
115 | KABC::VCardConverter converter; | 115 | KABC::VCardConverter converter; |
116 | QString vcard; | 116 | QString vcard; |
117 | 117 | ||
118 | KABC::VCardConverter::Version version; | 118 | KABC::VCardConverter::Version version; |
119 | if ( data == "v21" ) | 119 | if ( data == "v21" ) |
120 | version = KABC::VCardConverter::v2_1; | 120 | version = KABC::VCardConverter::v2_1; |
121 | else | 121 | else |
122 | version = KABC::VCardConverter::v3_0; | 122 | version = KABC::VCardConverter::v3_0; |
123 | 123 | ||
124 | version = KABC::VCardConverter::v2_1; | ||
124 | converter.addresseeToVCard( *it, vcard, version ); | 125 | converter.addresseeToVCard( *it, vcard, version ); |
125 | t << vcard << "\r\n\r\n"; | 126 | t << vcard << "\r\n\r\n"; |
126 | } | 127 | } |
127 | 128 | ||
128 | outFile.close(); | 129 | outFile.close(); |
129 | 130 | ||
130 | return true; | 131 | return true; |
131 | } | 132 | } |
132 | 133 | ||
133 | KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const | 134 | KABC::AddresseeList VCardXXPort::importContacts( const QString& ) const |
134 | { | 135 | { |
135 | QString fileName; | 136 | QString fileName; |
136 | KABC::AddresseeList addrList; | 137 | KABC::AddresseeList addrList; |
137 | KURL url; | 138 | KURL url; |
138 | 139 | ||
139 | #ifndef KAB_EMBEDDED | 140 | #ifndef KAB_EMBEDDED |
140 | if ( !XXPortManager::importData.isEmpty() ) | 141 | if ( !XXPortManager::importData.isEmpty() ) |
141 | addrList = parseVCard( XXPortManager::importData ); | 142 | addrList = parseVCard( XXPortManager::importData ); |
142 | else { | 143 | else { |
143 | if ( XXPortManager::importURL.isEmpty() ) | 144 | if ( XXPortManager::importURL.isEmpty() ) |
144 | { | 145 | { |
145 | url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); | 146 | url = KFileDialog::getLoadFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); |
146 | } | 147 | } |
147 | else | 148 | else |
148 | url = XXPortManager::importURL; | 149 | url = XXPortManager::importURL; |
149 | 150 | ||
150 | if ( url.isEmpty() ) | 151 | if ( url.isEmpty() ) |
151 | return addrList; | 152 | return addrList; |
152 | 153 | ||
153 | QString caption( i18n( "vCard Import Failed" ) ); | 154 | QString caption( i18n( "vCard Import Failed" ) ); |
154 | if ( KIO::NetAccess::download( url, fileName ) ) { | 155 | if ( KIO::NetAccess::download( url, fileName ) ) { |
155 | QFile file( fileName ); | 156 | QFile file( fileName ); |
156 | 157 | ||
157 | file.open( IO_ReadOnly ); | 158 | file.open( IO_ReadOnly ); |
158 | QByteArray rawData = file.readAll(); | 159 | QByteArray rawData = file.readAll(); |
159 | file.close(); | 160 | file.close(); |
160 | 161 | ||
161 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 162 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
162 | addrList = parseVCard( data ); | 163 | addrList = parseVCard( data ); |
163 | 164 | ||
164 | if ( !url.isLocalFile() ) | 165 | if ( !url.isLocalFile() ) |
165 | KIO::NetAccess::removeTempFile( fileName ); | 166 | KIO::NetAccess::removeTempFile( fileName ); |
166 | 167 | ||
167 | } else { | 168 | } else { |
168 | QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); | 169 | QString text = i18n( "<qt>Unable to access <b>%1</b>.</qt>" ); |
169 | KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); | 170 | KMessageBox::error( parentWidget(), text.arg( url.url() ), caption ); |
170 | } | 171 | } |
171 | 172 | ||
172 | } | 173 | } |
173 | 174 | ||
174 | 175 | ||
175 | #else //KAB_EMBEDDED | 176 | #else //KAB_EMBEDDED |
176 | 177 | ||
177 | 178 | ||
178 | if ( !XXPortManager::importData.isEmpty() ) | 179 | if ( !XXPortManager::importData.isEmpty() ) |
179 | addrList = parseVCard( XXPortManager::importData ); | 180 | addrList = parseVCard( XXPortManager::importData ); |
180 | else { | 181 | else { |
181 | if ( XXPortManager::importURL.isEmpty() ) | 182 | if ( XXPortManager::importURL.isEmpty() ) |
182 | { | 183 | { |
183 | fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); | 184 | fileName = KFileDialog::getOpenFileName( QString::null, i18n("Select vCard to Import"), parentWidget() ); |
184 | if ( fileName.isEmpty() ) | 185 | if ( fileName.isEmpty() ) |
185 | return addrList; | 186 | return addrList; |
186 | 187 | ||
187 | } | 188 | } |
188 | else | 189 | else |
189 | { | 190 | { |
190 | //US url = XXPortManager::importURL; | 191 | //US url = XXPortManager::importURL; |
191 | qDebug("VCardXXPort::importContacts Urls at the moment not supported"); | 192 | qDebug("VCardXXPort::importContacts Urls at the moment not supported"); |
192 | if ( url.isEmpty() ) | 193 | if ( url.isEmpty() ) |
193 | return addrList; | 194 | return addrList; |
194 | 195 | ||
195 | } | 196 | } |
196 | 197 | ||
197 | 198 | ||
198 | QFile file( fileName ); | 199 | QFile file( fileName ); |
199 | 200 | ||
200 | file.open( IO_ReadOnly ); | 201 | file.open( IO_ReadOnly ); |
201 | QByteArray rawData = file.readAll(); | 202 | QByteArray rawData = file.readAll(); |
202 | file.close(); | 203 | file.close(); |
203 | 204 | ||
204 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 205 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
205 | addrList = parseVCard( data ); | 206 | addrList = parseVCard( data ); |
206 | 207 | ||
207 | } | 208 | } |
208 | #endif //KAB_EMBEDDED | 209 | #endif //KAB_EMBEDDED |
209 | 210 | ||
210 | return addrList; | 211 | return addrList; |
211 | } | 212 | } |
212 | 213 | ||
213 | KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const | 214 | KABC::AddresseeList VCardXXPort::parseVCard( const QString &data ) const |
214 | { | 215 | { |
215 | 216 | ||
216 | KABC::VCardTool tool; | 217 | KABC::VCardTool tool; |
217 | KABC::AddresseeList addrList; | 218 | KABC::AddresseeList addrList; |
218 | addrList = tool.parseVCards( data ); | 219 | addrList = tool.parseVCards( data ); |
219 | // LR : I switched to the code, which is in current cvs HEAD | 220 | // LR : I switched to the code, which is in current cvs HEAD |
220 | /* | 221 | /* |
221 | uint numVCards = data.contains( "BEGIN:VCARD", false ); | 222 | uint numVCards = data.contains( "BEGIN:VCARD", false ); |
222 | QStringList dataList = QStringList::split( "\r\n\r\n", data ); | 223 | QStringList dataList = QStringList::split( "\r\n\r\n", data ); |
223 | 224 | ||
224 | for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) { | 225 | for ( uint i = 0; i < numVCards && i < dataList.count(); ++i ) { |
225 | KABC::Addressee addr; | 226 | KABC::Addressee addr; |
226 | bool ok = false; | 227 | bool ok = false; |
227 | 228 | ||
228 | if ( dataList[ i ].contains( "VERSION:3.0" ) ) | 229 | if ( dataList[ i ].contains( "VERSION:3.0" ) ) |
229 | ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 ); | 230 | ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v3_0 ); |
230 | else if ( dataList[ i ].contains( "VERSION:2.1" ) ) | 231 | else if ( dataList[ i ].contains( "VERSION:2.1" ) ) |
231 | ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 ); | 232 | ok = converter.vCardToAddressee( dataList[ i ], addr, KABC::VCardConverter::v2_1 ); |
232 | else { | 233 | else { |
233 | KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) ); | 234 | KMessageBox::sorry( parentWidget(), i18n( "Not supported vCard version." ) ); |
234 | continue; | 235 | continue; |
235 | } | 236 | } |
236 | 237 | ||
237 | if ( !addr.isEmpty() && ok ) | 238 | if ( !addr.isEmpty() && ok ) |
238 | addrList.append( addr ); | 239 | addrList.append( addr ); |
239 | else { | 240 | else { |
240 | QString text = i18n( "The selected file does not include a valid vCard. " | 241 | QString text = i18n( "The selected file does not include a valid vCard. " |
241 | "Please check the file and try again." ); | 242 | "Please check the file and try again." ); |
242 | KMessageBox::sorry( parentWidget(), text ); | 243 | KMessageBox::sorry( parentWidget(), text ); |
243 | } | 244 | } |
244 | } | 245 | } |
245 | */ | 246 | */ |
246 | if ( addrList.isEmpty() ) { | 247 | if ( addrList.isEmpty() ) { |
247 | QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" ); | 248 | QString text = i18n( "The selected file does not\ninclude a valid vCard.\nPlease check the file and try again.\n" ); |
248 | KMessageBox::sorry( parentWidget(), text ); | 249 | KMessageBox::sorry( parentWidget(), text ); |
249 | } | 250 | } |
250 | return addrList; | 251 | return addrList; |
251 | } | 252 | } |
252 | 253 | ||
253 | 254 | ||
254 | #ifndef KAB_EMBEDDED | 255 | #ifndef KAB_EMBEDDED |
255 | #include "vcard_xxport.moc" | 256 | #include "vcard_xxport.moc" |
256 | #endif //KAB_EMBEDDED | 257 | #endif //KAB_EMBEDDED |
diff --git a/libkdepim/ksyncmanager.cpp b/libkdepim/ksyncmanager.cpp index 5d48884..ea543dd 100644 --- a/libkdepim/ksyncmanager.cpp +++ b/libkdepim/ksyncmanager.cpp | |||
@@ -86,385 +86,386 @@ void KSyncManager::fillSyncMenu() | |||
86 | mSyncMenu->insertSeparator(); | 86 | mSyncMenu->insertSeparator(); |
87 | if ( mServerSocket == 0 ) { | 87 | if ( mServerSocket == 0 ) { |
88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); | 88 | mSyncMenu->insertItem( i18n("Enable Pi-Sync"), 2 ); |
89 | } else { | 89 | } else { |
90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); | 90 | mSyncMenu->insertItem( i18n("Disable Pi-Sync"), 3 ); |
91 | } | 91 | } |
92 | mSyncMenu->insertSeparator(); | 92 | mSyncMenu->insertSeparator(); |
93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); | 93 | mSyncMenu->insertItem( i18n("Multiple sync"), 1 ); |
94 | mSyncMenu->insertSeparator(); | 94 | mSyncMenu->insertSeparator(); |
95 | 95 | ||
96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 96 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
97 | config.setGroup("General"); | 97 | config.setGroup("General"); |
98 | QStringList prof = config.readListEntry("SyncProfileNames"); | 98 | QStringList prof = config.readListEntry("SyncProfileNames"); |
99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); | 99 | mLocalMachineName = config.readEntry("LocalMachineName","undefined"); |
100 | if ( prof.count() < 2 ) { | 100 | if ( prof.count() < 2 ) { |
101 | prof.clear(); | 101 | prof.clear(); |
102 | prof << i18n("Sharp_DTM"); | 102 | prof << i18n("Sharp_DTM"); |
103 | prof << i18n("Local_file"); | 103 | prof << i18n("Local_file"); |
104 | KSyncProfile* temp = new KSyncProfile (); | 104 | KSyncProfile* temp = new KSyncProfile (); |
105 | temp->setName( prof[0] ); | 105 | temp->setName( prof[0] ); |
106 | temp->writeConfig(&config); | 106 | temp->writeConfig(&config); |
107 | temp->setName( prof[1] ); | 107 | temp->setName( prof[1] ); |
108 | temp->writeConfig(&config); | 108 | temp->writeConfig(&config); |
109 | config.setGroup("General"); | 109 | config.setGroup("General"); |
110 | config.writeEntry("SyncProfileNames",prof); | 110 | config.writeEntry("SyncProfileNames",prof); |
111 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); | 111 | config.writeEntry("ExternSyncProfiles","Sharp_DTM"); |
112 | config.sync(); | 112 | config.sync(); |
113 | delete temp; | 113 | delete temp; |
114 | } | 114 | } |
115 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); | 115 | mExternSyncProfiles = config.readListEntry("ExternSyncProfiles"); |
116 | mSyncProfileNames = prof; | 116 | mSyncProfileNames = prof; |
117 | unsigned int i; | 117 | unsigned int i; |
118 | for ( i = 0; i < prof.count(); ++i ) { | 118 | for ( i = 0; i < prof.count(); ++i ) { |
119 | mSyncMenu->insertItem( prof[i], 1000+i ); | 119 | mSyncMenu->insertItem( prof[i], 1000+i ); |
120 | if ( i == 2 ) | 120 | if ( i == 2 ) |
121 | mSyncMenu->insertSeparator(); | 121 | mSyncMenu->insertSeparator(); |
122 | } | 122 | } |
123 | QDir app_dir; | 123 | QDir app_dir; |
124 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available | 124 | //US do not display SharpDTM if app is pwmpi, or no sharpfiles available |
125 | if ( mTargetApp == PWMPI) { | 125 | if ( mTargetApp == PWMPI) { |
126 | mSyncMenu->removeItem( 1000 ); | 126 | mSyncMenu->removeItem( 1000 ); |
127 | } | 127 | } |
128 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { | 128 | else if (!app_dir.exists(QDir::homeDirPath()+"/Applications/dtm" ) ) { |
129 | mSyncMenu->setItemEnabled( 1000, false ); | 129 | mSyncMenu->setItemEnabled( 1000, false ); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | void KSyncManager::slotSyncMenu( int action ) | 133 | void KSyncManager::slotSyncMenu( int action ) |
134 | { | 134 | { |
135 | //qDebug("syncaction %d ", action); | 135 | //qDebug("syncaction %d ", action); |
136 | if ( action == 0 ) { | 136 | if ( action == 0 ) { |
137 | 137 | ||
138 | // seems to be a Qt2 event handling bug | 138 | // seems to be a Qt2 event handling bug |
139 | // syncmenu.clear causes a segfault at first time | 139 | // syncmenu.clear causes a segfault at first time |
140 | // when we call it after the main event loop, it is ok | 140 | // when we call it after the main event loop, it is ok |
141 | // same behaviour when calling OM/Pi via QCOP for the first time | 141 | // same behaviour when calling OM/Pi via QCOP for the first time |
142 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); | 142 | QTimer::singleShot ( 1, this, SLOT ( confSync() ) ); |
143 | //confSync(); | 143 | //confSync(); |
144 | 144 | ||
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | if ( action == 1 ) { | 147 | if ( action == 1 ) { |
148 | multiSync( true ); | 148 | multiSync( true ); |
149 | return; | 149 | return; |
150 | } | 150 | } |
151 | if ( action == 2 ) { | 151 | if ( action == 2 ) { |
152 | enableQuick(); | 152 | enableQuick(); |
153 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 153 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
154 | return; | 154 | return; |
155 | } | 155 | } |
156 | if ( action == 3 ) { | 156 | if ( action == 3 ) { |
157 | delete mServerSocket; | 157 | delete mServerSocket; |
158 | mServerSocket = 0; | 158 | mServerSocket = 0; |
159 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); | 159 | QTimer::singleShot ( 1, this, SLOT ( fillSyncMenu() ) ); |
160 | return; | 160 | return; |
161 | } | 161 | } |
162 | 162 | ||
163 | if (blockSave()) | 163 | if (blockSave()) |
164 | return; | 164 | return; |
165 | 165 | ||
166 | setBlockSave(true); | 166 | setBlockSave(true); |
167 | 167 | ||
168 | mCurrentSyncProfile = action - 1000 ; | 168 | mCurrentSyncProfile = action - 1000 ; |
169 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; | 169 | mCurrentSyncDevice = mSyncProfileNames[mCurrentSyncProfile] ; |
170 | mCurrentSyncName = mLocalMachineName ; | 170 | mCurrentSyncName = mLocalMachineName ; |
171 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 171 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
172 | KSyncProfile* temp = new KSyncProfile (); | 172 | KSyncProfile* temp = new KSyncProfile (); |
173 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); | 173 | temp->setName(mSyncProfileNames[mCurrentSyncProfile]); |
174 | temp->readConfig(&config); | 174 | temp->readConfig(&config); |
175 | mAskForPreferences = temp->getAskForPreferences(); | 175 | mAskForPreferences = temp->getAskForPreferences(); |
176 | mSyncAlgoPrefs = temp->getSyncPrefs(); | 176 | mSyncAlgoPrefs = temp->getSyncPrefs(); |
177 | mWriteBackFile = temp->getWriteBackFile(); | 177 | mWriteBackFile = temp->getWriteBackFile(); |
178 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 178 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
179 | mWriteBackInFuture = 0; | 179 | mWriteBackInFuture = 0; |
180 | if ( temp->getWriteBackFuture() ) | 180 | if ( temp->getWriteBackFuture() ) |
181 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 181 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
182 | mShowSyncSummary = temp->getShowSummaryAfterSync(); | 182 | mShowSyncSummary = temp->getShowSummaryAfterSync(); |
183 | if ( action == 1000 ) { | 183 | if ( action == 1000 ) { |
184 | syncSharp(); | 184 | syncSharp(); |
185 | 185 | ||
186 | } else if ( action == 1001 ) { | 186 | } else if ( action == 1001 ) { |
187 | syncLocalFile(); | 187 | syncLocalFile(); |
188 | 188 | ||
189 | } else if ( action == 1002 ) { | 189 | } else if ( action == 1002 ) { |
190 | quickSyncLocalFile(); | 190 | quickSyncLocalFile(); |
191 | 191 | ||
192 | } else if ( action >= 1003 ) { | 192 | } else if ( action >= 1003 ) { |
193 | if ( temp->getIsLocalFileSync() ) { | 193 | if ( temp->getIsLocalFileSync() ) { |
194 | switch(mTargetApp) | 194 | switch(mTargetApp) |
195 | { | 195 | { |
196 | case (KAPI): | 196 | case (KAPI): |
197 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 197 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
198 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 198 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
199 | break; | 199 | break; |
200 | case (KOPI): | 200 | case (KOPI): |
201 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 201 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
202 | mLastSyncedLocalFile = temp->getRemoteFileName(); | 202 | mLastSyncedLocalFile = temp->getRemoteFileName(); |
203 | break; | 203 | break; |
204 | case (PWMPI): | 204 | case (PWMPI): |
205 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 205 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
206 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 206 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
207 | break; | 207 | break; |
208 | default: | 208 | default: |
209 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 209 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
210 | break; | 210 | break; |
211 | 211 | ||
212 | } | 212 | } |
213 | } else { | 213 | } else { |
214 | if ( temp->getIsPhoneSync() ) { | 214 | if ( temp->getIsPhoneSync() ) { |
215 | mPhoneDevice = temp->getPhoneDevice( ) ; | 215 | mPhoneDevice = temp->getPhoneDevice( ) ; |
216 | mPhoneConnection = temp->getPhoneConnection( ); | 216 | mPhoneConnection = temp->getPhoneConnection( ); |
217 | mPhoneModel = temp->getPhoneModel( ); | 217 | mPhoneModel = temp->getPhoneModel( ); |
218 | syncPhone(); | 218 | syncPhone(); |
219 | } else if ( temp->getIsPiSync() ) { | 219 | } else if ( temp->getIsPiSync() ) { |
220 | mPassWordPiSync = temp->getRemotePw(); | 220 | mPassWordPiSync = temp->getRemotePw(); |
221 | mActiveSyncPort = temp->getRemotePort(); | 221 | mActiveSyncPort = temp->getRemotePort(); |
222 | mActiveSyncIP = temp->getRemoteIP(); | 222 | mActiveSyncIP = temp->getRemoteIP(); |
223 | syncPi(); | 223 | syncPi(); |
224 | } | 224 | } |
225 | syncRemote( temp ); | 225 | syncRemote( temp ); |
226 | 226 | ||
227 | } | 227 | } |
228 | } | 228 | } |
229 | delete temp; | 229 | delete temp; |
230 | setBlockSave(false); | 230 | setBlockSave(false); |
231 | } | 231 | } |
232 | void KSyncManager::enableQuick() | 232 | void KSyncManager::enableQuick() |
233 | { | 233 | { |
234 | QDialog dia ( 0, "input-dialog", true ); | 234 | QDialog dia ( 0, "input-dialog", true ); |
235 | QLineEdit lab ( &dia ); | 235 | QLineEdit lab ( &dia ); |
236 | QVBoxLayout lay( &dia ); | 236 | QVBoxLayout lay( &dia ); |
237 | lab.setText( mPrefs->mPassiveSyncPort ); | 237 | lab.setText( mPrefs->mPassiveSyncPort ); |
238 | lay.setMargin(7); | 238 | lay.setMargin(7); |
239 | lay.setSpacing(7); | 239 | lay.setSpacing(7); |
240 | int po = 9197+mTargetApp; | 240 | int po = 9197+mTargetApp; |
241 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); | 241 | QLabel label ( i18n("Port number (Default: %1)").arg(po), &dia ); |
242 | lay.addWidget( &label); | 242 | lay.addWidget( &label); |
243 | lay.addWidget( &lab); | 243 | lay.addWidget( &lab); |
244 | 244 | ||
245 | QLineEdit lepw ( &dia ); | 245 | QLineEdit lepw ( &dia ); |
246 | lepw.setText( mPrefs->mPassiveSyncPw ); | 246 | lepw.setText( mPrefs->mPassiveSyncPw ); |
247 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); | 247 | QLabel label2 ( i18n("Password to enable\naccess from remote:"), &dia ); |
248 | lay.addWidget( &label2); | 248 | lay.addWidget( &label2); |
249 | lay.addWidget( &lepw); | 249 | lay.addWidget( &lepw); |
250 | dia.setFixedSize( 230,80 ); | 250 | dia.setFixedSize( 230,80 ); |
251 | dia.setCaption( i18n("Enter port for Pi-Sync") ); | 251 | dia.setCaption( i18n("Enter port for Pi-Sync") ); |
252 | QPushButton pb ( "OK", &dia); | 252 | QPushButton pb ( "OK", &dia); |
253 | lay.addWidget( &pb ); | 253 | lay.addWidget( &pb ); |
254 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); | 254 | connect(&pb, SIGNAL( clicked() ), &dia, SLOT ( accept() ) ); |
255 | dia.show(); | 255 | dia.show(); |
256 | if ( ! dia.exec() ) | 256 | if ( ! dia.exec() ) |
257 | return; | 257 | return; |
258 | dia.hide(); | 258 | dia.hide(); |
259 | qApp->processEvents(); | 259 | qApp->processEvents(); |
260 | mPrefs->mPassiveSyncPw = lepw.text(); | 260 | mPrefs->mPassiveSyncPw = lepw.text(); |
261 | mPrefs->mPassiveSyncPort = lab.text(); | 261 | mPrefs->mPassiveSyncPort = lab.text(); |
262 | bool ok; | 262 | bool ok; |
263 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); | 263 | Q_UINT16 port = mPrefs->mPassiveSyncPort.toUInt(&ok); |
264 | if ( ! ok ) { | 264 | if ( ! ok ) { |
265 | KMessageBox::information( 0, i18n("No valid port")); | 265 | KMessageBox::information( 0, i18n("No valid port")); |
266 | return; | 266 | return; |
267 | } | 267 | } |
268 | //qDebug("port %d ", port); | 268 | //qDebug("port %d ", port); |
269 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); | 269 | mServerSocket = new KServerSocket ( mPrefs->mPassiveSyncPw, port ,1 ); |
270 | mServerSocket->setFileName( defaultFileName() ); | 270 | mServerSocket->setFileName( defaultFileName() ); |
271 | //qDebug("connected "); | 271 | //qDebug("connected "); |
272 | if ( !mServerSocket->ok() ) { | 272 | if ( !mServerSocket->ok() ) { |
273 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); | 273 | KMessageBox::information( 0, i18n("Failed to bind or\nlisten to the port!")); |
274 | delete mServerSocket; | 274 | delete mServerSocket; |
275 | mServerSocket = 0; | 275 | mServerSocket = 0; |
276 | return; | 276 | return; |
277 | } | 277 | } |
278 | connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); | 278 | //connect( mServerSocket, SIGNAL ( saveFile() ),this, SIGNAL ( save() ) ); |
279 | connect( mServerSocket, SIGNAL ( request_file() ),this, SIGNAL ( request_file() ) ); | ||
279 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); | 280 | connect( mServerSocket, SIGNAL ( file_received( bool ) ), this, SIGNAL ( getFile( bool ) ) ); |
280 | } | 281 | } |
281 | 282 | ||
282 | void KSyncManager::syncLocalFile() | 283 | void KSyncManager::syncLocalFile() |
283 | { | 284 | { |
284 | 285 | ||
285 | QString fn =mLastSyncedLocalFile; | 286 | QString fn =mLastSyncedLocalFile; |
286 | QString ext; | 287 | QString ext; |
287 | 288 | ||
288 | switch(mTargetApp) | 289 | switch(mTargetApp) |
289 | { | 290 | { |
290 | case (KAPI): | 291 | case (KAPI): |
291 | ext = "(*.vcf)"; | 292 | ext = "(*.vcf)"; |
292 | break; | 293 | break; |
293 | case (KOPI): | 294 | case (KOPI): |
294 | ext = "(*.ics/*.vcs)"; | 295 | ext = "(*.ics/*.vcs)"; |
295 | break; | 296 | break; |
296 | case (PWMPI): | 297 | case (PWMPI): |
297 | ext = "(*.pwm)"; | 298 | ext = "(*.pwm)"; |
298 | break; | 299 | break; |
299 | default: | 300 | default: |
300 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); | 301 | qDebug("KSyncManager::syncLocalFile: invalid apptype selected"); |
301 | break; | 302 | break; |
302 | 303 | ||
303 | } | 304 | } |
304 | 305 | ||
305 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); | 306 | fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename"+ext), mParent ); |
306 | if ( fn == "" ) | 307 | if ( fn == "" ) |
307 | return; | 308 | return; |
308 | if ( syncWithFile( fn, false ) ) { | 309 | if ( syncWithFile( fn, false ) ) { |
309 | qDebug("syncLocalFile() successful "); | 310 | qDebug("syncLocalFile() successful "); |
310 | } | 311 | } |
311 | 312 | ||
312 | } | 313 | } |
313 | bool KSyncManager::syncWithFile( QString fn , bool quick ) | 314 | bool KSyncManager::syncWithFile( QString fn , bool quick ) |
314 | { | 315 | { |
315 | bool ret = false; | 316 | bool ret = false; |
316 | QFileInfo info; | 317 | QFileInfo info; |
317 | info.setFile( fn ); | 318 | info.setFile( fn ); |
318 | QString mess; | 319 | QString mess; |
319 | bool loadbup = true; | 320 | bool loadbup = true; |
320 | if ( !info. exists() ) { | 321 | if ( !info. exists() ) { |
321 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); | 322 | mess = i18n( "Sync file \n...%1\ndoes not exist!\nNothing synced!\n").arg(fn.right( 30) ); |
322 | int result = QMessageBox::warning( mParent, i18n("Warning!"), | 323 | int result = QMessageBox::warning( mParent, i18n("Warning!"), |
323 | mess ); | 324 | mess ); |
324 | return ret; | 325 | return ret; |
325 | } | 326 | } |
326 | int result = 0; | 327 | int result = 0; |
327 | if ( !quick ) { | 328 | if ( !quick ) { |
328 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); | 329 | mess = i18n("Sync with file \n...%1\nfrom:\n%2\n").arg(fn.right( 25)).arg(KGlobal::locale()->formatDateTime(info.lastModified (), true, false )); |
329 | result = QMessageBox::warning( mParent, i18n("Warning!"), | 330 | result = QMessageBox::warning( mParent, i18n("Warning!"), |
330 | mess, | 331 | mess, |
331 | i18n("Sync"), i18n("Cancel"), 0, | 332 | i18n("Sync"), i18n("Cancel"), 0, |
332 | 0, 1 ); | 333 | 0, 1 ); |
333 | if ( result ) | 334 | if ( result ) |
334 | return false; | 335 | return false; |
335 | } | 336 | } |
336 | if ( mAskForPreferences ) | 337 | if ( mAskForPreferences ) |
337 | edit_sync_options(); | 338 | edit_sync_options(); |
338 | if ( result == 0 ) { | 339 | if ( result == 0 ) { |
339 | //qDebug("Now sycing ... "); | 340 | //qDebug("Now sycing ... "); |
340 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) | 341 | if ( ret = mImplementation->sync( this, fn, mSyncAlgoPrefs ) ) |
341 | mParent->setCaption( i18n("Synchronization successful") ); | 342 | mParent->setCaption( i18n("Synchronization successful") ); |
342 | else | 343 | else |
343 | mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); | 344 | mParent->setCaption( i18n("Sync cancelled or failed. Nothing synced.") ); |
344 | if ( ! quick ) | 345 | if ( ! quick ) |
345 | mLastSyncedLocalFile = fn; | 346 | mLastSyncedLocalFile = fn; |
346 | } | 347 | } |
347 | return ret; | 348 | return ret; |
348 | } | 349 | } |
349 | void KSyncManager::quickSyncLocalFile() | 350 | void KSyncManager::quickSyncLocalFile() |
350 | { | 351 | { |
351 | 352 | ||
352 | if ( syncWithFile( mLastSyncedLocalFile, false ) ) { | 353 | if ( syncWithFile( mLastSyncedLocalFile, false ) ) { |
353 | qDebug("quick syncLocalFile() successful "); | 354 | qDebug("quick syncLocalFile() successful "); |
354 | 355 | ||
355 | } | 356 | } |
356 | } | 357 | } |
357 | void KSyncManager::multiSync( bool askforPrefs ) | 358 | void KSyncManager::multiSync( bool askforPrefs ) |
358 | { | 359 | { |
359 | if (blockSave()) | 360 | if (blockSave()) |
360 | return; | 361 | return; |
361 | setBlockSave(true); | 362 | setBlockSave(true); |
362 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); | 363 | QString question = i18n("Do you really want\nto multiple sync\nwith all checked profiles?\nSyncing takes some\ntime - all profiles\nare synced twice!"); |
363 | if ( QMessageBox::information( mParent, i18n("Sync"), | 364 | if ( QMessageBox::information( mParent, i18n("Sync"), |
364 | question, | 365 | question, |
365 | i18n("Yes"), i18n("No"), | 366 | i18n("Yes"), i18n("No"), |
366 | 0, 0 ) != 0 ) { | 367 | 0, 0 ) != 0 ) { |
367 | setBlockSave(false); | 368 | setBlockSave(false); |
368 | mParent->setCaption(i18n("Aborted! Nothing synced!")); | 369 | mParent->setCaption(i18n("Aborted! Nothing synced!")); |
369 | return; | 370 | return; |
370 | } | 371 | } |
371 | mCurrentSyncDevice = i18n("Multiple profiles") ; | 372 | mCurrentSyncDevice = i18n("Multiple profiles") ; |
372 | mSyncAlgoPrefs = mRingSyncAlgoPrefs; | 373 | mSyncAlgoPrefs = mRingSyncAlgoPrefs; |
373 | if ( askforPrefs ) { | 374 | if ( askforPrefs ) { |
374 | edit_sync_options(); | 375 | edit_sync_options(); |
375 | mRingSyncAlgoPrefs = mSyncAlgoPrefs; | 376 | mRingSyncAlgoPrefs = mSyncAlgoPrefs; |
376 | } | 377 | } |
377 | mParent->setCaption(i18n("Multiple sync started.") ); | 378 | mParent->setCaption(i18n("Multiple sync started.") ); |
378 | qApp->processEvents(); | 379 | qApp->processEvents(); |
379 | int num = ringSync() ; | 380 | int num = ringSync() ; |
380 | if ( num > 1 ) | 381 | if ( num > 1 ) |
381 | ringSync(); | 382 | ringSync(); |
382 | setBlockSave(false); | 383 | setBlockSave(false); |
383 | if ( num ) | 384 | if ( num ) |
384 | emit save(); | 385 | emit save(); |
385 | if ( num ) | 386 | if ( num ) |
386 | mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); | 387 | mParent->setCaption(i18n("%1 profiles synced. Multiple sync completed!").arg(num) ); |
387 | else | 388 | else |
388 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); | 389 | mParent->setCaption(i18n("Nothing synced! No profiles defined for multisync!")); |
389 | return; | 390 | return; |
390 | } | 391 | } |
391 | int KSyncManager::ringSync() | 392 | int KSyncManager::ringSync() |
392 | { | 393 | { |
393 | int syncedProfiles = 0; | 394 | int syncedProfiles = 0; |
394 | unsigned int i; | 395 | unsigned int i; |
395 | QTime timer; | 396 | QTime timer; |
396 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); | 397 | KConfig config ( locateLocal( "config","ksyncprofilesrc" ) ); |
397 | QStringList syncProfileNames = mSyncProfileNames; | 398 | QStringList syncProfileNames = mSyncProfileNames; |
398 | KSyncProfile* temp = new KSyncProfile (); | 399 | KSyncProfile* temp = new KSyncProfile (); |
399 | mAskForPreferences = false; | 400 | mAskForPreferences = false; |
400 | for ( i = 0; i < syncProfileNames.count(); ++i ) { | 401 | for ( i = 0; i < syncProfileNames.count(); ++i ) { |
401 | mCurrentSyncProfile = i; | 402 | mCurrentSyncProfile = i; |
402 | temp->setName(syncProfileNames[mCurrentSyncProfile]); | 403 | temp->setName(syncProfileNames[mCurrentSyncProfile]); |
403 | temp->readConfig(&config); | 404 | temp->readConfig(&config); |
404 | 405 | ||
405 | QString includeInRingSync; | 406 | QString includeInRingSync; |
406 | switch(mTargetApp) | 407 | switch(mTargetApp) |
407 | { | 408 | { |
408 | case (KAPI): | 409 | case (KAPI): |
409 | includeInRingSync = temp->getIncludeInRingSyncAB(); | 410 | includeInRingSync = temp->getIncludeInRingSyncAB(); |
410 | break; | 411 | break; |
411 | case (KOPI): | 412 | case (KOPI): |
412 | includeInRingSync = temp->getIncludeInRingSync(); | 413 | includeInRingSync = temp->getIncludeInRingSync(); |
413 | break; | 414 | break; |
414 | case (PWMPI): | 415 | case (PWMPI): |
415 | includeInRingSync = temp->getIncludeInRingSyncPWM(); | 416 | includeInRingSync = temp->getIncludeInRingSyncPWM(); |
416 | break; | 417 | break; |
417 | default: | 418 | default: |
418 | qDebug("KSyncManager::ringSync: invalid apptype selected"); | 419 | qDebug("KSyncManager::ringSync: invalid apptype selected"); |
419 | break; | 420 | break; |
420 | 421 | ||
421 | } | 422 | } |
422 | 423 | ||
423 | 424 | ||
424 | if ( includeInRingSync && ( i < 1 || i > 2 )) { | 425 | if ( includeInRingSync && ( i < 1 || i > 2 )) { |
425 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); | 426 | mParent->setCaption(i18n("Profile ")+syncProfileNames[mCurrentSyncProfile]+ i18n(" is synced ... ")); |
426 | ++syncedProfiles; | 427 | ++syncedProfiles; |
427 | // mAskForPreferences = temp->getAskForPreferences(); | 428 | // mAskForPreferences = temp->getAskForPreferences(); |
428 | mWriteBackFile = temp->getWriteBackFile(); | 429 | mWriteBackFile = temp->getWriteBackFile(); |
429 | mWriteBackExistingOnly = temp->getWriteBackExisting(); | 430 | mWriteBackExistingOnly = temp->getWriteBackExisting(); |
430 | mWriteBackInFuture = 0; | 431 | mWriteBackInFuture = 0; |
431 | if ( temp->getWriteBackFuture() ) | 432 | if ( temp->getWriteBackFuture() ) |
432 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); | 433 | mWriteBackInFuture = temp->getWriteBackFutureWeeks( ); |
433 | mShowSyncSummary = false; | 434 | mShowSyncSummary = false; |
434 | mCurrentSyncDevice = syncProfileNames[i] ; | 435 | mCurrentSyncDevice = syncProfileNames[i] ; |
435 | mCurrentSyncName = mLocalMachineName; | 436 | mCurrentSyncName = mLocalMachineName; |
436 | if ( i == 0 ) { | 437 | if ( i == 0 ) { |
437 | syncSharp(); | 438 | syncSharp(); |
438 | } else { | 439 | } else { |
439 | if ( temp->getIsLocalFileSync() ) { | 440 | if ( temp->getIsLocalFileSync() ) { |
440 | switch(mTargetApp) | 441 | switch(mTargetApp) |
441 | { | 442 | { |
442 | case (KAPI): | 443 | case (KAPI): |
443 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) | 444 | if ( syncWithFile( temp->getRemoteFileNameAB( ), false ) ) |
444 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); | 445 | mLastSyncedLocalFile = temp->getRemoteFileNameAB(); |
445 | break; | 446 | break; |
446 | case (KOPI): | 447 | case (KOPI): |
447 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) | 448 | if ( syncWithFile( temp->getRemoteFileName( ), false ) ) |
448 | mLastSyncedLocalFile = temp->getRemoteFileName(); | 449 | mLastSyncedLocalFile = temp->getRemoteFileName(); |
449 | break; | 450 | break; |
450 | case (PWMPI): | 451 | case (PWMPI): |
451 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) | 452 | if ( syncWithFile( temp->getRemoteFileNamePWM( ), false ) ) |
452 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); | 453 | mLastSyncedLocalFile = temp->getRemoteFileNamePWM(); |
453 | break; | 454 | break; |
454 | default: | 455 | default: |
455 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); | 456 | qDebug("KSyncManager::slotSyncMenu: invalid apptype selected"); |
456 | break; | 457 | break; |
457 | } | 458 | } |
458 | } else { | 459 | } else { |
459 | if ( temp->getIsPhoneSync() ) { | 460 | if ( temp->getIsPhoneSync() ) { |
460 | mPhoneDevice = temp->getPhoneDevice( ) ; | 461 | mPhoneDevice = temp->getPhoneDevice( ) ; |
461 | mPhoneConnection = temp->getPhoneConnection( ); | 462 | mPhoneConnection = temp->getPhoneConnection( ); |
462 | mPhoneModel = temp->getPhoneModel( ); | 463 | mPhoneModel = temp->getPhoneModel( ); |
463 | syncPhone(); | 464 | syncPhone(); |
464 | } else | 465 | } else |
465 | syncRemote( temp, false ); | 466 | syncRemote( temp, false ); |
466 | 467 | ||
467 | } | 468 | } |
468 | } | 469 | } |
469 | timer.start(); | 470 | timer.start(); |
470 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); | 471 | mParent->setCaption(i18n("Multiple sync in progress ... please wait!") ); |
@@ -739,385 +740,385 @@ QString KSyncManager::syncFileName() | |||
739 | { | 740 | { |
740 | case (KAPI): | 741 | case (KAPI): |
741 | fn = "addressbook.vcf"; | 742 | fn = "addressbook.vcf"; |
742 | break; | 743 | break; |
743 | case (KOPI): | 744 | case (KOPI): |
744 | fn = "synccalendar.ics"; | 745 | fn = "synccalendar.ics"; |
745 | break; | 746 | break; |
746 | case (PWMPI): | 747 | case (PWMPI): |
747 | fn = "manager.pwm"; | 748 | fn = "manager.pwm"; |
748 | break; | 749 | break; |
749 | default: | 750 | default: |
750 | break; | 751 | break; |
751 | } | 752 | } |
752 | #ifdef _WIN32_ | 753 | #ifdef _WIN32_ |
753 | return locateLocal( "tmp", fn ); | 754 | return locateLocal( "tmp", fn ); |
754 | #else | 755 | #else |
755 | return (QString( "/tmp/" )+ fn ); | 756 | return (QString( "/tmp/" )+ fn ); |
756 | #endif | 757 | #endif |
757 | } | 758 | } |
758 | 759 | ||
759 | void KSyncManager::syncPi() | 760 | void KSyncManager::syncPi() |
760 | { | 761 | { |
761 | qApp->processEvents(); | 762 | qApp->processEvents(); |
762 | bool ok; | 763 | bool ok; |
763 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); | 764 | Q_UINT16 port = mActiveSyncPort.toUInt(&ok); |
764 | if ( ! ok ) { | 765 | if ( ! ok ) { |
765 | mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); | 766 | mParent->setCaption( i18n("Sorry, no valid port.Syncing cancelled.") ); |
766 | return; | 767 | return; |
767 | } | 768 | } |
768 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); | 769 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, port, mActiveSyncIP, this ); |
769 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); | 770 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int )), this, SLOT(deleteCommandSocket(KCommandSocket*, int)) ); |
770 | mParent->setCaption( i18n("Sending request for remote file ...") ); | 771 | mParent->setCaption( i18n("Sending request for remote file ...") ); |
771 | commandSocket->readFile( syncFileName() ); | 772 | commandSocket->readFile( syncFileName() ); |
772 | } | 773 | } |
773 | 774 | ||
774 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) | 775 | void KSyncManager::deleteCommandSocket(KCommandSocket*s, int state) |
775 | { | 776 | { |
776 | qDebug("MainWindow::deleteCommandSocket %d", state); | 777 | qDebug("MainWindow::deleteCommandSocket %d", state); |
777 | 778 | ||
778 | //enum { success, errorW, errorR, quiet }; | 779 | //enum { success, errorW, errorR, quiet }; |
779 | if ( state == KCommandSocket::errorR ) { | 780 | if ( state == KCommandSocket::errorR ) { |
780 | mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); | 781 | mParent->setCaption( i18n("ERROR: Receiving remote file failed.") ); |
781 | delete s; | 782 | delete s; |
782 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 783 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
783 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 784 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
784 | commandSocket->sendStop(); | 785 | commandSocket->sendStop(); |
785 | return; | 786 | return; |
786 | 787 | ||
787 | } else if ( state == KCommandSocket::errorW ) { | 788 | } else if ( state == KCommandSocket::errorW ) { |
788 | mParent->setCaption( i18n("ERROR:Writing back file failed.") ); | 789 | mParent->setCaption( i18n("ERROR:Writing back file failed.") ); |
789 | 790 | ||
790 | } else if ( state == KCommandSocket::successR ) { | 791 | } else if ( state == KCommandSocket::successR ) { |
791 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); | 792 | QTimer::singleShot( 1, this , SLOT ( readFileFromSocket())); |
792 | 793 | ||
793 | } else if ( state == KCommandSocket::successW ) { | 794 | } else if ( state == KCommandSocket::successW ) { |
794 | mParent->setCaption( i18n("Pi-Sync succesful!") ); | 795 | mParent->setCaption( i18n("Pi-Sync succesful!") ); |
795 | } | 796 | } |
796 | 797 | ||
797 | delete s; | 798 | delete s; |
798 | } | 799 | } |
799 | 800 | ||
800 | void KSyncManager::readFileFromSocket() | 801 | void KSyncManager::readFileFromSocket() |
801 | { | 802 | { |
802 | QString fileName = syncFileName(); | 803 | QString fileName = syncFileName(); |
803 | mParent->setCaption( i18n("Remote file saved to temp file.") ); | 804 | mParent->setCaption( i18n("Remote file saved to temp file.") ); |
804 | if ( ! syncWithFile( fileName , true ) ) { | 805 | if ( ! syncWithFile( fileName , true ) ) { |
805 | mParent->setCaption( i18n("Syncing failed.") ); | 806 | mParent->setCaption( i18n("Syncing failed.") ); |
806 | qDebug("Syncing failed "); | 807 | qDebug("Syncing failed "); |
807 | return; | 808 | return; |
808 | } | 809 | } |
809 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); | 810 | KCommandSocket* commandSocket = new KCommandSocket( mPassWordPiSync, mActiveSyncPort.toUInt(), mActiveSyncIP, this ); |
810 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); | 811 | connect( commandSocket, SIGNAL(commandFinished( KCommandSocket*, int)), this, SLOT(deleteCommandSocket(KCommandSocket*, int )) ); |
811 | if ( mWriteBackFile ) | 812 | if ( mWriteBackFile ) |
812 | commandSocket->writeFile( fileName ); | 813 | commandSocket->writeFile( fileName ); |
813 | else { | 814 | else { |
814 | commandSocket->sendStop(); | 815 | commandSocket->sendStop(); |
815 | mParent->setCaption( i18n("Pi-Sync succesful!") ); | 816 | mParent->setCaption( i18n("Pi-Sync succesful!") ); |
816 | } | 817 | } |
817 | } | 818 | } |
818 | 819 | ||
819 | 820 | ||
820 | 821 | ||
821 | 822 | ||
822 | 823 | ||
823 | 824 | ||
824 | 825 | ||
825 | 826 | ||
826 | 827 | ||
827 | 828 | ||
828 | 829 | ||
829 | 830 | ||
830 | 831 | ||
831 | 832 | ||
832 | 833 | ||
833 | 834 | ||
834 | 835 | ||
835 | 836 | ||
836 | 837 | ||
837 | 838 | ||
838 | 839 | ||
839 | 840 | ||
840 | 841 | ||
841 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) | 842 | KServerSocket:: KServerSocket ( QString pw, Q_UINT16 port, int backlog, QObject * parent, const char * name ) : QServerSocket( port, backlog, parent, name ) |
842 | { | 843 | { |
843 | mPassWord = pw; | 844 | mPassWord = pw; |
844 | mSocket = 0; | 845 | mSocket = 0; |
845 | mSyncActionDialog = 0; | 846 | mSyncActionDialog = 0; |
846 | blockRC = false; | 847 | blockRC = false; |
847 | }; | 848 | }; |
848 | 849 | ||
849 | void KServerSocket::newConnection ( int socket ) | 850 | void KServerSocket::newConnection ( int socket ) |
850 | { | 851 | { |
851 | // qDebug("KServerSocket:New connection %d ", socket); | 852 | // qDebug("KServerSocket:New connection %d ", socket); |
852 | if ( mSocket ) { | 853 | if ( mSocket ) { |
853 | qDebug("KServerSocket::newConnection Socket deleted! "); | 854 | qDebug("KServerSocket::newConnection Socket deleted! "); |
854 | delete mSocket; | 855 | delete mSocket; |
855 | mSocket = 0; | 856 | mSocket = 0; |
856 | } | 857 | } |
857 | mSocket = new QSocket( this ); | 858 | mSocket = new QSocket( this ); |
858 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); | 859 | connect( mSocket , SIGNAL(readyRead()), this, SLOT(readClient()) ); |
859 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); | 860 | connect( mSocket , SIGNAL(delayedCloseFinished()), this, SLOT(discardClient()) ); |
860 | mSocket->setSocket( socket ); | 861 | mSocket->setSocket( socket ); |
861 | } | 862 | } |
862 | 863 | ||
863 | void KServerSocket::discardClient() | 864 | void KServerSocket::discardClient() |
864 | { | 865 | { |
865 | //qDebug(" KServerSocket::discardClient()"); | 866 | //qDebug(" KServerSocket::discardClient()"); |
866 | if ( mSocket ) { | 867 | if ( mSocket ) { |
867 | delete mSocket; | 868 | delete mSocket; |
868 | mSocket = 0; | 869 | mSocket = 0; |
869 | } | 870 | } |
870 | //emit endConnect(); | 871 | //emit endConnect(); |
871 | } | 872 | } |
872 | void KServerSocket::readClient() | 873 | void KServerSocket::readClient() |
873 | { | 874 | { |
874 | if ( blockRC ) | 875 | if ( blockRC ) |
875 | return; | 876 | return; |
876 | if ( mSocket == 0 ) { | 877 | if ( mSocket == 0 ) { |
877 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); | 878 | qDebug("ERROR::KServerSocket::readClient(): mSocket == 0 "); |
878 | return; | 879 | return; |
879 | } | 880 | } |
880 | qDebug("KServerSocket readClient()"); | 881 | qDebug("KServerSocket readClient()"); |
881 | if ( mSocket->canReadLine() ) { | 882 | if ( mSocket->canReadLine() ) { |
882 | QString line = mSocket->readLine(); | 883 | QString line = mSocket->readLine(); |
883 | qDebug("KServerSocket readline: %s ", line.latin1()); | 884 | qDebug("KServerSocket readline: %s ", line.latin1()); |
884 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); | 885 | QStringList tokens = QStringList::split( QRegExp("[ \r\n][ \r\n]*"), line ); |
885 | if ( tokens[0] == "GET" ) { | 886 | if ( tokens[0] == "GET" ) { |
886 | if ( tokens[1] == mPassWord ) | 887 | if ( tokens[1] == mPassWord ) |
887 | //emit sendFile( mSocket ); | 888 | //emit sendFile( mSocket ); |
888 | send_file(); | 889 | send_file(); |
889 | else { | 890 | else { |
890 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); | 891 | KMessageBox::information( 0, i18n("ERROR:\nGot send file request\nwith invalid password")); |
891 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 892 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
892 | } | 893 | } |
893 | } | 894 | } |
894 | if ( tokens[0] == "PUT" ) { | 895 | if ( tokens[0] == "PUT" ) { |
895 | if ( tokens[1] == mPassWord ) { | 896 | if ( tokens[1] == mPassWord ) { |
896 | //emit getFile( mSocket ); | 897 | //emit getFile( mSocket ); |
897 | blockRC = true; | 898 | blockRC = true; |
898 | get_file(); | 899 | get_file(); |
899 | } | 900 | } |
900 | else { | 901 | else { |
901 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); | 902 | KMessageBox::information( 0, i18n("ERROR:\nGot receive file request\nwith invalid password")); |
902 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); | 903 | qDebug("password %s, invalid password %s ",mPassWord.latin1(), tokens[1].latin1() ); |
903 | } | 904 | } |
904 | } | 905 | } |
905 | if ( tokens[0] == "STOP" ) { | 906 | if ( tokens[0] == "STOP" ) { |
906 | //emit endConnect(); | 907 | //emit endConnect(); |
907 | end_connect(); | 908 | end_connect(); |
908 | } | 909 | } |
909 | } | 910 | } |
910 | } | 911 | } |
911 | void KServerSocket::end_connect() | 912 | void KServerSocket::end_connect() |
912 | { | 913 | { |
913 | delete mSyncActionDialog; | 914 | delete mSyncActionDialog; |
914 | mSyncActionDialog = 0; | 915 | mSyncActionDialog = 0; |
915 | } | 916 | } |
916 | void KServerSocket::send_file() | 917 | void KServerSocket::send_file() |
917 | { | 918 | { |
918 | //qDebug("MainWindow::sendFile(QSocket* s) "); | 919 | //qDebug("MainWindow::sendFile(QSocket* s) "); |
919 | if ( mSyncActionDialog ) | 920 | if ( mSyncActionDialog ) |
920 | delete mSyncActionDialog; | 921 | delete mSyncActionDialog; |
921 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); | 922 | mSyncActionDialog = new QDialog ( 0, "input-dialog", true ); |
922 | mSyncActionDialog->setCaption(i18n("Received sync request")); | 923 | mSyncActionDialog->setCaption(i18n("Received sync request")); |
923 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); | 924 | QLabel* label = new QLabel( i18n("Synchronizing from remote ...\n\nDo not use this application!\n\nIf syncing fails\nyou can close this dialog."), mSyncActionDialog ); |
924 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); | 925 | QVBoxLayout* lay = new QVBoxLayout( mSyncActionDialog ); |
925 | lay->addWidget( label); | 926 | lay->addWidget( label); |
926 | lay->setMargin(7); | 927 | lay->setMargin(7); |
927 | lay->setSpacing(7); | 928 | lay->setSpacing(7); |
928 | mSyncActionDialog->setFixedSize( 230, 120); | 929 | mSyncActionDialog->setFixedSize( 230, 120); |
929 | mSyncActionDialog->show(); | 930 | mSyncActionDialog->show(); |
930 | qDebug("KSS::saving ... "); | 931 | qDebug("KSS::saving ... "); |
931 | emit saveFile(); | 932 | emit request_file(); |
932 | qApp->processEvents(); | 933 | qApp->processEvents(); |
933 | QString fileName = mFileName; | 934 | QString fileName = mFileName; |
934 | QFile file( fileName ); | 935 | QFile file( fileName ); |
935 | if (!file.open( IO_ReadOnly ) ) { | 936 | if (!file.open( IO_ReadOnly ) ) { |
936 | delete mSyncActionDialog; | 937 | delete mSyncActionDialog; |
937 | mSyncActionDialog = 0; | 938 | mSyncActionDialog = 0; |
938 | qDebug("KSS::error open file "); | 939 | qDebug("KSS::error open file "); |
939 | mSocket->close(); | 940 | mSocket->close(); |
940 | if ( mSocket->state() == QSocket::Idle ) | 941 | if ( mSocket->state() == QSocket::Idle ) |
941 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 942 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
942 | return ; | 943 | return ; |
943 | 944 | ||
944 | } | 945 | } |
945 | mSyncActionDialog->setCaption( i18n("Sending file...") ); | 946 | mSyncActionDialog->setCaption( i18n("Sending file...") ); |
946 | QTextStream ts( &file ); | 947 | QTextStream ts( &file ); |
947 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 948 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
948 | QTextStream os( mSocket ); | 949 | QTextStream os( mSocket ); |
949 | os.setCodec( QTextCodec::codecForName("utf8") ); | 950 | os.setCodec( QTextCodec::codecForName("utf8") ); |
950 | //os.setEncoding( QTextStream::UnicodeUTF8 ); | 951 | //os.setEncoding( QTextStream::UnicodeUTF8 ); |
951 | while ( ! ts.atEnd() ) { | 952 | while ( ! ts.atEnd() ) { |
952 | os << ts.readLine() << "\n"; | 953 | os << ts.readLine() << "\n"; |
953 | } | 954 | } |
954 | //os << ts.read(); | 955 | //os << ts.read(); |
955 | file.close(); | 956 | file.close(); |
956 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); | 957 | mSyncActionDialog->setCaption( i18n("Waiting for synced file...") ); |
957 | mSocket->close(); | 958 | mSocket->close(); |
958 | if ( mSocket->state() == QSocket::Idle ) | 959 | if ( mSocket->state() == QSocket::Idle ) |
959 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 960 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
960 | } | 961 | } |
961 | void KServerSocket::get_file() | 962 | void KServerSocket::get_file() |
962 | { | 963 | { |
963 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); | 964 | mSyncActionDialog->setCaption( i18n("Receiving synced file...") ); |
964 | 965 | ||
965 | piTime.start(); | 966 | piTime.start(); |
966 | piFileString = ""; | 967 | piFileString = ""; |
967 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); | 968 | QTimer::singleShot( 1, this , SLOT (readBackFileFromSocket( ) )); |
968 | } | 969 | } |
969 | 970 | ||
970 | 971 | ||
971 | void KServerSocket::readBackFileFromSocket() | 972 | void KServerSocket::readBackFileFromSocket() |
972 | { | 973 | { |
973 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); | 974 | //qDebug("readBackFileFromSocket() %d ", piTime.elapsed ()); |
974 | while ( mSocket->canReadLine () ) { | 975 | while ( mSocket->canReadLine () ) { |
975 | piTime.restart(); | 976 | piTime.restart(); |
976 | QString line = mSocket->readLine (); | 977 | QString line = mSocket->readLine (); |
977 | piFileString += line; | 978 | piFileString += line; |
978 | //qDebug("readline: %s ", line.latin1()); | 979 | //qDebug("readline: %s ", line.latin1()); |
979 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); | 980 | mSyncActionDialog->setCaption( i18n("Received %1 bytes").arg( piFileString.length() ) ); |
980 | 981 | ||
981 | } | 982 | } |
982 | if ( piTime.elapsed () < 3000 ) { | 983 | if ( piTime.elapsed () < 3000 ) { |
983 | // wait for more | 984 | // wait for more |
984 | //qDebug("waitformore "); | 985 | //qDebug("waitformore "); |
985 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); | 986 | QTimer::singleShot( 100, this , SLOT (readBackFileFromSocket( ) )); |
986 | return; | 987 | return; |
987 | } | 988 | } |
988 | QString fileName = mFileName; | 989 | QString fileName = mFileName; |
989 | QFile file ( fileName ); | 990 | QFile file ( fileName ); |
990 | if (!file.open( IO_WriteOnly ) ) { | 991 | if (!file.open( IO_WriteOnly ) ) { |
991 | delete mSyncActionDialog; | 992 | delete mSyncActionDialog; |
992 | mSyncActionDialog = 0; | 993 | mSyncActionDialog = 0; |
993 | qDebug("error open cal file "); | 994 | qDebug("error open cal file "); |
994 | piFileString = ""; | 995 | piFileString = ""; |
995 | emit file_received( false ); | 996 | emit file_received( false ); |
996 | blockRC = false; | 997 | blockRC = false; |
997 | return ; | 998 | return ; |
998 | 999 | ||
999 | } | 1000 | } |
1000 | 1001 | ||
1001 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); | 1002 | // mView->setLoadedFileVersion(QDateTime::currentDateTime().addSecs( -1)); |
1002 | QTextStream ts ( &file ); | 1003 | QTextStream ts ( &file ); |
1003 | ts.setCodec( QTextCodec::codecForName("utf8") ); | 1004 | ts.setCodec( QTextCodec::codecForName("utf8") ); |
1004 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); | 1005 | mSyncActionDialog->setCaption( i18n("Writing file to disk...") ); |
1005 | ts << piFileString; | 1006 | ts << piFileString; |
1006 | mSocket->close(); | 1007 | mSocket->close(); |
1007 | if ( mSocket->state() == QSocket::Idle ) | 1008 | if ( mSocket->state() == QSocket::Idle ) |
1008 | QTimer::singleShot( 10, this , SLOT ( discardClient())); | 1009 | QTimer::singleShot( 10, this , SLOT ( discardClient())); |
1009 | file.close(); | 1010 | file.close(); |
1010 | delete mSyncActionDialog; | 1011 | delete mSyncActionDialog; |
1011 | mSyncActionDialog = 0; | 1012 | mSyncActionDialog = 0; |
1012 | piFileString = ""; | 1013 | piFileString = ""; |
1013 | blockRC = false; | 1014 | blockRC = false; |
1014 | emit file_received( true ); | 1015 | emit file_received( true ); |
1015 | 1016 | ||
1016 | } | 1017 | } |
1017 | 1018 | ||
1018 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) | 1019 | KCommandSocket::KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent, const char * name ): QObject( parent, name ) |
1019 | { | 1020 | { |
1020 | mPassWord = password; | 1021 | mPassWord = password; |
1021 | mSocket = 0; | 1022 | mSocket = 0; |
1022 | mPort = port; | 1023 | mPort = port; |
1023 | mHost = host; | 1024 | mHost = host; |
1024 | 1025 | ||
1025 | mRetVal = quiet; | 1026 | mRetVal = quiet; |
1026 | mTimerSocket = new QTimer ( this ); | 1027 | mTimerSocket = new QTimer ( this ); |
1027 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); | 1028 | connect( mTimerSocket, SIGNAL ( timeout () ), this, SLOT ( deleteSocket() ) ); |
1028 | } | 1029 | } |
1029 | void KCommandSocket::readFile( QString fn ) | 1030 | void KCommandSocket::readFile( QString fn ) |
1030 | { | 1031 | { |
1031 | if ( !mSocket ) { | 1032 | if ( !mSocket ) { |
1032 | mSocket = new QSocket( this ); | 1033 | mSocket = new QSocket( this ); |
1033 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); | 1034 | connect( mSocket, SIGNAL(readyRead()), this, SLOT(startReadFileFromSocket()) ); |
1034 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1035 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1035 | } | 1036 | } |
1036 | mFileString = ""; | 1037 | mFileString = ""; |
1037 | mFileName = fn; | 1038 | mFileName = fn; |
1038 | mFirst = true; | 1039 | mFirst = true; |
1039 | mSocket->connectToHost( mHost, mPort ); | 1040 | mSocket->connectToHost( mHost, mPort ); |
1040 | QTextStream os( mSocket ); | 1041 | QTextStream os( mSocket ); |
1041 | os.setEncoding( QTextStream::UnicodeUTF8 ); | 1042 | os.setEncoding( QTextStream::UnicodeUTF8 ); |
1042 | os << "GET " << mPassWord << "\r\n"; | 1043 | os << "GET " << mPassWord << "\r\n"; |
1043 | mTimerSocket->start( 10000 ); | 1044 | mTimerSocket->start( 10000 ); |
1044 | } | 1045 | } |
1045 | 1046 | ||
1046 | void KCommandSocket::writeFile( QString fileName ) | 1047 | void KCommandSocket::writeFile( QString fileName ) |
1047 | { | 1048 | { |
1048 | if ( !mSocket ) { | 1049 | if ( !mSocket ) { |
1049 | mSocket = new QSocket( this ); | 1050 | mSocket = new QSocket( this ); |
1050 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1051 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1051 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); | 1052 | connect( mSocket, SIGNAL(connected ()), this, SLOT(writeFileToSocket()) ); |
1052 | } | 1053 | } |
1053 | mFileName = fileName ; | 1054 | mFileName = fileName ; |
1054 | mSocket->connectToHost( mHost, mPort ); | 1055 | mSocket->connectToHost( mHost, mPort ); |
1055 | } | 1056 | } |
1056 | void KCommandSocket::writeFileToSocket() | 1057 | void KCommandSocket::writeFileToSocket() |
1057 | { | 1058 | { |
1058 | QFile file2( mFileName ); | 1059 | QFile file2( mFileName ); |
1059 | if (!file2.open( IO_ReadOnly ) ) { | 1060 | if (!file2.open( IO_ReadOnly ) ) { |
1060 | mRetVal= errorW; | 1061 | mRetVal= errorW; |
1061 | mSocket->close(); | 1062 | mSocket->close(); |
1062 | if ( mSocket->state() == QSocket::Idle ) | 1063 | if ( mSocket->state() == QSocket::Idle ) |
1063 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1064 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1064 | return ; | 1065 | return ; |
1065 | } | 1066 | } |
1066 | QTextStream ts2( &file2 ); | 1067 | QTextStream ts2( &file2 ); |
1067 | ts2.setCodec( QTextCodec::codecForName("utf8") ); | 1068 | ts2.setCodec( QTextCodec::codecForName("utf8") ); |
1068 | QTextStream os2( mSocket ); | 1069 | QTextStream os2( mSocket ); |
1069 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 1070 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
1070 | os2 << "PUT " << mPassWord << "\r\n";; | 1071 | os2 << "PUT " << mPassWord << "\r\n";; |
1071 | while ( ! ts2.atEnd() ) { | 1072 | while ( ! ts2.atEnd() ) { |
1072 | os2 << ts2.readLine() << "\n"; | 1073 | os2 << ts2.readLine() << "\n"; |
1073 | } | 1074 | } |
1074 | mRetVal= successW; | 1075 | mRetVal= successW; |
1075 | file2.close(); | 1076 | file2.close(); |
1076 | mSocket->close(); | 1077 | mSocket->close(); |
1077 | if ( mSocket->state() == QSocket::Idle ) | 1078 | if ( mSocket->state() == QSocket::Idle ) |
1078 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1079 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1079 | } | 1080 | } |
1080 | void KCommandSocket::sendStop() | 1081 | void KCommandSocket::sendStop() |
1081 | { | 1082 | { |
1082 | if ( !mSocket ) { | 1083 | if ( !mSocket ) { |
1083 | mSocket = new QSocket( this ); | 1084 | mSocket = new QSocket( this ); |
1084 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); | 1085 | connect( mSocket, SIGNAL(delayedCloseFinished ()), this, SLOT(deleteSocket()) ); |
1085 | } | 1086 | } |
1086 | mSocket->connectToHost( mHost, mPort ); | 1087 | mSocket->connectToHost( mHost, mPort ); |
1087 | QTextStream os2( mSocket ); | 1088 | QTextStream os2( mSocket ); |
1088 | os2.setCodec( QTextCodec::codecForName("utf8") ); | 1089 | os2.setCodec( QTextCodec::codecForName("utf8") ); |
1089 | os2 << "STOP\r\n"; | 1090 | os2 << "STOP\r\n"; |
1090 | mSocket->close(); | 1091 | mSocket->close(); |
1091 | if ( mSocket->state() == QSocket::Idle ) | 1092 | if ( mSocket->state() == QSocket::Idle ) |
1092 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); | 1093 | QTimer::singleShot( 10, this , SLOT ( deleteSocket())); |
1093 | } | 1094 | } |
1094 | 1095 | ||
1095 | void KCommandSocket::startReadFileFromSocket() | 1096 | void KCommandSocket::startReadFileFromSocket() |
1096 | { | 1097 | { |
1097 | if ( ! mFirst ) | 1098 | if ( ! mFirst ) |
1098 | return; | 1099 | return; |
1099 | mFirst = false; | 1100 | mFirst = false; |
1100 | mTimerSocket->stop(); | 1101 | mTimerSocket->stop(); |
1101 | mFileString = ""; | 1102 | mFileString = ""; |
1102 | mTime.start(); | 1103 | mTime.start(); |
1103 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); | 1104 | QTimer::singleShot( 1, this , SLOT (readFileFromSocket( ) )); |
1104 | 1105 | ||
1105 | } | 1106 | } |
1106 | void KCommandSocket::readFileFromSocket() | 1107 | void KCommandSocket::readFileFromSocket() |
1107 | { | 1108 | { |
1108 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); | 1109 | //qDebug("readBackFileFromSocket() %d ", mTime.elapsed ()); |
1109 | while ( mSocket->canReadLine () ) { | 1110 | while ( mSocket->canReadLine () ) { |
1110 | mTime.restart(); | 1111 | mTime.restart(); |
1111 | QString line = mSocket->readLine (); | 1112 | QString line = mSocket->readLine (); |
1112 | mFileString += line; | 1113 | mFileString += line; |
1113 | //qDebug("readline: %s ", line.latin1()); | 1114 | //qDebug("readline: %s ", line.latin1()); |
1114 | } | 1115 | } |
1115 | if ( mTime.elapsed () < 3000 ) { | 1116 | if ( mTime.elapsed () < 3000 ) { |
1116 | // wait for more | 1117 | // wait for more |
1117 | //qDebug("waitformore "); | 1118 | //qDebug("waitformore "); |
1118 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); | 1119 | QTimer::singleShot( 100, this , SLOT (readFileFromSocket( ) )); |
1119 | return; | 1120 | return; |
1120 | } | 1121 | } |
1121 | QString fileName = mFileName; | 1122 | QString fileName = mFileName; |
1122 | QFile file ( fileName ); | 1123 | QFile file ( fileName ); |
1123 | if (!file.open( IO_WriteOnly ) ) { | 1124 | if (!file.open( IO_WriteOnly ) ) { |
diff --git a/libkdepim/ksyncmanager.h b/libkdepim/ksyncmanager.h index 52e2772..0eb3323 100644 --- a/libkdepim/ksyncmanager.h +++ b/libkdepim/ksyncmanager.h | |||
@@ -1,228 +1,227 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of KDE-Pim/Pi. | 2 | This file is part of KDE-Pim/Pi. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | 19 | ||
20 | $Id$ | 20 | $Id$ |
21 | */ | 21 | */ |
22 | #ifndef _KSYNCMANAGER_H | 22 | #ifndef _KSYNCMANAGER_H |
23 | #define _KSYNCMANAGER_H | 23 | #define _KSYNCMANAGER_H |
24 | 24 | ||
25 | #include <qobject.h> | 25 | #include <qobject.h> |
26 | #include <qstring.h> | 26 | #include <qstring.h> |
27 | #include <qsocket.h> | 27 | #include <qsocket.h> |
28 | #include <qdatetime.h> | 28 | #include <qdatetime.h> |
29 | #include <qserversocket.h> | 29 | #include <qserversocket.h> |
30 | #include <qtextstream.h> | 30 | #include <qtextstream.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | 32 | ||
33 | class QPopupMenu; | 33 | class QPopupMenu; |
34 | class KSyncProfile; | 34 | class KSyncProfile; |
35 | class KPimPrefs; | 35 | class KPimPrefs; |
36 | class QWidget; | 36 | class QWidget; |
37 | class KSyncManager; | 37 | class KSyncManager; |
38 | class KSyncInterface; | 38 | class KSyncInterface; |
39 | class QProgressBar; | 39 | class QProgressBar; |
40 | 40 | ||
41 | 41 | ||
42 | class KServerSocket : public QServerSocket | 42 | class KServerSocket : public QServerSocket |
43 | { | 43 | { |
44 | Q_OBJECT | 44 | Q_OBJECT |
45 | 45 | ||
46 | public: | 46 | public: |
47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); | 47 | KServerSocket ( QString password, Q_UINT16 port, int backlog = 0, QObject * parent=0, const char * name=0 ); |
48 | 48 | ||
49 | void newConnection ( int socket ) ; | 49 | void newConnection ( int socket ) ; |
50 | void setFileName( QString fn ) {mFileName = fn;}; | 50 | void setFileName( QString fn ) {mFileName = fn;}; |
51 | 51 | ||
52 | signals: | 52 | signals: |
53 | //void sendFile(QSocket*); | ||
54 | //void getFile(QSocket*); | ||
55 | void file_received( bool ); | 53 | void file_received( bool ); |
56 | //void file_sent(); | 54 | void request_file(); |
57 | void saveFile(); | 55 | void saveFile(); |
58 | void endConnect(); | 56 | void endConnect(); |
59 | private slots: | 57 | private slots: |
60 | void discardClient(); | 58 | void discardClient(); |
61 | void readClient(); | 59 | void readClient(); |
62 | void readBackFileFromSocket(); | 60 | void readBackFileFromSocket(); |
63 | private : | 61 | private : |
64 | bool blockRC; | 62 | bool blockRC; |
65 | void send_file(); | 63 | void send_file(); |
66 | void get_file(); | 64 | void get_file(); |
67 | void end_connect(); | 65 | void end_connect(); |
68 | QDialog* mSyncActionDialog; | 66 | QDialog* mSyncActionDialog; |
69 | QSocket* mSocket; | 67 | QSocket* mSocket; |
70 | QString mPassWord; | 68 | QString mPassWord; |
71 | QString mFileName; | 69 | QString mFileName; |
72 | QTime piTime; | 70 | QTime piTime; |
73 | QString piFileString; | 71 | QString piFileString; |
74 | }; | 72 | }; |
75 | 73 | ||
76 | class KCommandSocket : public QObject | 74 | class KCommandSocket : public QObject |
77 | { | 75 | { |
78 | Q_OBJECT | 76 | Q_OBJECT |
79 | public: | 77 | public: |
80 | enum state { successR, errorR, successW, errorW, quiet }; | 78 | enum state { successR, errorR, successW, errorW, quiet }; |
81 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); | 79 | KCommandSocket ( QString password, Q_UINT16 port, QString host, QObject * parent=0, const char * name=0 ); |
82 | void readFile( QString ); | 80 | void readFile( QString ); |
83 | void writeFile( QString ); | 81 | void writeFile( QString ); |
84 | void sendStop(); | 82 | void sendStop(); |
85 | 83 | ||
86 | 84 | ||
87 | signals: | 85 | signals: |
88 | void commandFinished( KCommandSocket*, int ); | 86 | void commandFinished( KCommandSocket*, int ); |
89 | private slots: | 87 | private slots: |
90 | void startReadFileFromSocket(); | 88 | void startReadFileFromSocket(); |
91 | void readFileFromSocket(); | 89 | void readFileFromSocket(); |
92 | void deleteSocket(); | 90 | void deleteSocket(); |
93 | void writeFileToSocket(); | 91 | void writeFileToSocket(); |
94 | private : | 92 | private : |
95 | QSocket* mSocket; | 93 | QSocket* mSocket; |
96 | QString mPassWord; | 94 | QString mPassWord; |
97 | Q_UINT16 mPort; | 95 | Q_UINT16 mPort; |
98 | QString mHost; | 96 | QString mHost; |
99 | QString mFileName; | 97 | QString mFileName; |
100 | QTimer* mTimerSocket; | 98 | QTimer* mTimerSocket; |
101 | int mRetVal; | 99 | int mRetVal; |
102 | QTime mTime; | 100 | QTime mTime; |
103 | QString mFileString; | 101 | QString mFileString; |
104 | bool mFirst; | 102 | bool mFirst; |
105 | }; | 103 | }; |
106 | 104 | ||
107 | 105 | ||
108 | class KSyncManager : public QObject | 106 | class KSyncManager : public QObject |
109 | { | 107 | { |
110 | Q_OBJECT | 108 | Q_OBJECT |
111 | 109 | ||
112 | public: | 110 | public: |
113 | enum TargetApp { | 111 | enum TargetApp { |
114 | KOPI = 0, | 112 | KOPI = 0, |
115 | KAPI = 1, | 113 | KAPI = 1, |
116 | PWMPI = 2 }; | 114 | PWMPI = 2 }; |
117 | 115 | ||
118 | 116 | ||
119 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); | 117 | KSyncManager(QWidget* parent, KSyncInterface* implementation, TargetApp ta, KPimPrefs* prefs, QPopupMenu* syncmenu); |
120 | ~KSyncManager() ; | 118 | ~KSyncManager() ; |
121 | 119 | ||
122 | bool blockSave() { return mBlockSaveFlag; } | 120 | bool blockSave() { return mBlockSaveFlag; } |
123 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } | 121 | void setBlockSave(bool sa) { mBlockSaveFlag = sa; } |
124 | void setDefaultFileName( QString s) { mDefFileName = s ;} | 122 | void setDefaultFileName( QString s) { mDefFileName = s ;} |
125 | QString defaultFileName() { return mDefFileName ;} | 123 | QString defaultFileName() { return mDefFileName ;} |
126 | QString syncFileName(); | 124 | QString syncFileName(); |
127 | void fillSyncMenu(); | 125 | void fillSyncMenu(); |
128 | 126 | ||
129 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } | 127 | QString getCurrentSyncDevice() { return mCurrentSyncDevice; } |
130 | QString getCurrentSyncName() { return mCurrentSyncName; } | 128 | QString getCurrentSyncName() { return mCurrentSyncName; } |
131 | 129 | ||
132 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); | 130 | void showProgressBar(int percentage, QString caption = QString::null, int total=100); |
133 | void hideProgressBar(); | 131 | void hideProgressBar(); |
134 | bool isProgressBarCanceled(); | 132 | bool isProgressBarCanceled(); |
135 | 133 | ||
136 | // sync stuff | 134 | // sync stuff |
137 | QString mLocalMachineName; | 135 | QString mLocalMachineName; |
138 | QStringList mExternSyncProfiles; | 136 | QStringList mExternSyncProfiles; |
139 | QStringList mSyncProfileNames; | 137 | QStringList mSyncProfileNames; |
140 | bool mAskForPreferences; | 138 | bool mAskForPreferences; |
141 | bool mShowSyncSummary; | 139 | bool mShowSyncSummary; |
142 | bool mShowSyncEvents; | 140 | bool mShowSyncEvents; |
143 | bool mShowTodoInAgenda; | 141 | bool mShowTodoInAgenda; |
144 | bool mWriteBackExistingOnly; | 142 | bool mWriteBackExistingOnly; |
145 | int mSyncAlgoPrefs; | 143 | int mSyncAlgoPrefs; |
146 | int mRingSyncAlgoPrefs; | 144 | int mRingSyncAlgoPrefs; |
147 | bool mWriteBackFile; | 145 | bool mWriteBackFile; |
148 | int mWriteBackInFuture; | 146 | int mWriteBackInFuture; |
149 | QString mPhoneDevice; | 147 | QString mPhoneDevice; |
150 | QString mPhoneConnection; | 148 | QString mPhoneConnection; |
151 | QString mPhoneModel; | 149 | QString mPhoneModel; |
152 | QString mLastSyncedLocalFile; // save! | 150 | QString mLastSyncedLocalFile; // save! |
153 | QString mPassWordPiSync; | 151 | QString mPassWordPiSync; |
154 | QString mActiveSyncPort; | 152 | QString mActiveSyncPort; |
155 | QString mActiveSyncIP ; | 153 | QString mActiveSyncIP ; |
156 | 154 | ||
157 | signals: | 155 | signals: |
158 | void save(); | 156 | void save(); |
157 | void request_file(); | ||
159 | void getFile( bool ); | 158 | void getFile( bool ); |
160 | 159 | ||
161 | public slots: | 160 | public slots: |
162 | void slotSyncMenu( int ); | 161 | void slotSyncMenu( int ); |
163 | 162 | ||
164 | private: | 163 | private: |
165 | // LR ******************************* | 164 | // LR ******************************* |
166 | // sync stuff! | 165 | // sync stuff! |
167 | void syncPi(); | 166 | void syncPi(); |
168 | void deleteCommandSocket(KCommandSocket*s, int state); | 167 | void deleteCommandSocket(KCommandSocket*s, int state); |
169 | void readFileFromSocket(); | 168 | void readFileFromSocket(); |
170 | KServerSocket * mServerSocket; | 169 | KServerSocket * mServerSocket; |
171 | void enableQuick(); | 170 | void enableQuick(); |
172 | KPimPrefs* mPrefs; | 171 | KPimPrefs* mPrefs; |
173 | QString mDefFileName; | 172 | QString mDefFileName; |
174 | QString mCurrentSyncDevice; | 173 | QString mCurrentSyncDevice; |
175 | QString mCurrentSyncName; | 174 | QString mCurrentSyncName; |
176 | void quickSyncLocalFile(); | 175 | void quickSyncLocalFile(); |
177 | bool syncWithFile( QString fn , bool quick ); | 176 | bool syncWithFile( QString fn , bool quick ); |
178 | void syncLocalFile(); | 177 | void syncLocalFile(); |
179 | void syncPhone(); | 178 | void syncPhone(); |
180 | void syncSharp(); | 179 | void syncSharp(); |
181 | bool syncExternalApplication(QString); | 180 | bool syncExternalApplication(QString); |
182 | void multiSync( bool askforPrefs ); | 181 | void multiSync( bool askforPrefs ); |
183 | int mCurrentSyncProfile ; | 182 | int mCurrentSyncProfile ; |
184 | void syncRemote( KSyncProfile* prof, bool ask = true); | 183 | void syncRemote( KSyncProfile* prof, bool ask = true); |
185 | void edit_sync_options(); | 184 | void edit_sync_options(); |
186 | int ringSync(); | 185 | int ringSync(); |
187 | QString getPassword( ); | 186 | QString getPassword( ); |
188 | 187 | ||
189 | private slots: | 188 | private slots: |
190 | void confSync(); | 189 | void confSync(); |
191 | // ********************* | 190 | // ********************* |
192 | 191 | ||
193 | private: | 192 | private: |
194 | bool mBlockSaveFlag; | 193 | bool mBlockSaveFlag; |
195 | 194 | ||
196 | 195 | ||
197 | QWidget* mParent; | 196 | QWidget* mParent; |
198 | KSyncInterface* mImplementation; | 197 | KSyncInterface* mImplementation; |
199 | TargetApp mTargetApp; | 198 | TargetApp mTargetApp; |
200 | QPopupMenu* mSyncMenu; | 199 | QPopupMenu* mSyncMenu; |
201 | 200 | ||
202 | QProgressBar* bar; | 201 | QProgressBar* bar; |
203 | 202 | ||
204 | 203 | ||
205 | 204 | ||
206 | 205 | ||
207 | 206 | ||
208 | }; | 207 | }; |
209 | 208 | ||
210 | 209 | ||
211 | class KSyncInterface | 210 | class KSyncInterface |
212 | { | 211 | { |
213 | 212 | ||
214 | 213 | ||
215 | public : | 214 | public : |
216 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; | 215 | virtual bool sync(KSyncManager* manager, QString filename, int mode) = 0; |
217 | 216 | ||
218 | virtual bool syncExternal(KSyncManager* manager, QString resource) | 217 | virtual bool syncExternal(KSyncManager* manager, QString resource) |
219 | { | 218 | { |
220 | // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. | 219 | // empty implementation, because some syncable applications do not have an external(sharpdtm) syncmode, like pwmanager. |
221 | return false; | 220 | return false; |
222 | } | 221 | } |
223 | 222 | ||
224 | 223 | ||
225 | }; | 224 | }; |
226 | 225 | ||
227 | 226 | ||
228 | #endif | 227 | #endif |