-rw-r--r-- | kabc/addressbook.cpp | 1 | ||||
-rw-r--r-- | kaddressbook/kabcore.cpp | 3 | ||||
-rw-r--r-- | libkdepim/phoneaccess.cpp | 6 |
3 files changed, 8 insertions, 2 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 1a06956..1050f55 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,810 +1,811 @@ | |||
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> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | #include <qregexp.h> | ||
43 | 44 | ||
44 | #include <kglobal.h> | 45 | #include <kglobal.h> |
45 | #include <klocale.h> | 46 | #include <klocale.h> |
46 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
47 | #include <kdebug.h> | 48 | #include <kdebug.h> |
48 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
49 | #include "addressbook.h" | 50 | #include "addressbook.h" |
50 | #include "resource.h" | 51 | #include "resource.h" |
51 | #include "vcardconverter.h" | 52 | #include "vcardconverter.h" |
52 | #include "vcardparser/vcardtool.h" | 53 | #include "vcardparser/vcardtool.h" |
53 | 54 | ||
54 | //US #include "addressbook.moc" | 55 | //US #include "addressbook.moc" |
55 | 56 | ||
56 | using namespace KABC; | 57 | using namespace KABC; |
57 | 58 | ||
58 | struct AddressBook::AddressBookData | 59 | struct AddressBook::AddressBookData |
59 | { | 60 | { |
60 | Addressee::List mAddressees; | 61 | Addressee::List mAddressees; |
61 | Addressee::List mRemovedAddressees; | 62 | Addressee::List mRemovedAddressees; |
62 | Field::List mAllFields; | 63 | Field::List mAllFields; |
63 | KConfig *mConfig; | 64 | KConfig *mConfig; |
64 | KRES::Manager<Resource> *mManager; | 65 | KRES::Manager<Resource> *mManager; |
65 | //US ErrorHandler *mErrorHandler; | 66 | //US ErrorHandler *mErrorHandler; |
66 | }; | 67 | }; |
67 | 68 | ||
68 | struct AddressBook::Iterator::IteratorData | 69 | struct AddressBook::Iterator::IteratorData |
69 | { | 70 | { |
70 | Addressee::List::Iterator mIt; | 71 | Addressee::List::Iterator mIt; |
71 | }; | 72 | }; |
72 | 73 | ||
73 | struct AddressBook::ConstIterator::ConstIteratorData | 74 | struct AddressBook::ConstIterator::ConstIteratorData |
74 | { | 75 | { |
75 | Addressee::List::ConstIterator mIt; | 76 | Addressee::List::ConstIterator mIt; |
76 | }; | 77 | }; |
77 | 78 | ||
78 | AddressBook::Iterator::Iterator() | 79 | AddressBook::Iterator::Iterator() |
79 | { | 80 | { |
80 | d = new IteratorData; | 81 | d = new IteratorData; |
81 | } | 82 | } |
82 | 83 | ||
83 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 84 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
84 | { | 85 | { |
85 | d = new IteratorData; | 86 | d = new IteratorData; |
86 | d->mIt = i.d->mIt; | 87 | d->mIt = i.d->mIt; |
87 | } | 88 | } |
88 | 89 | ||
89 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 90 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
90 | { | 91 | { |
91 | if( this == &i ) return *this; // guard against self assignment | 92 | if( this == &i ) return *this; // guard against self assignment |
92 | delete d; // delete the old data the Iterator was completely constructed before | 93 | delete d; // delete the old data the Iterator was completely constructed before |
93 | d = new IteratorData; | 94 | d = new IteratorData; |
94 | d->mIt = i.d->mIt; | 95 | d->mIt = i.d->mIt; |
95 | return *this; | 96 | return *this; |
96 | } | 97 | } |
97 | 98 | ||
98 | AddressBook::Iterator::~Iterator() | 99 | AddressBook::Iterator::~Iterator() |
99 | { | 100 | { |
100 | delete d; | 101 | delete d; |
101 | } | 102 | } |
102 | 103 | ||
103 | const Addressee &AddressBook::Iterator::operator*() const | 104 | const Addressee &AddressBook::Iterator::operator*() const |
104 | { | 105 | { |
105 | return *(d->mIt); | 106 | return *(d->mIt); |
106 | } | 107 | } |
107 | 108 | ||
108 | Addressee &AddressBook::Iterator::operator*() | 109 | Addressee &AddressBook::Iterator::operator*() |
109 | { | 110 | { |
110 | return *(d->mIt); | 111 | return *(d->mIt); |
111 | } | 112 | } |
112 | 113 | ||
113 | Addressee *AddressBook::Iterator::operator->() | 114 | Addressee *AddressBook::Iterator::operator->() |
114 | { | 115 | { |
115 | return &(*(d->mIt)); | 116 | return &(*(d->mIt)); |
116 | } | 117 | } |
117 | 118 | ||
118 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 119 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
119 | { | 120 | { |
120 | (d->mIt)++; | 121 | (d->mIt)++; |
121 | return *this; | 122 | return *this; |
122 | } | 123 | } |
123 | 124 | ||
124 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 125 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
125 | { | 126 | { |
126 | (d->mIt)++; | 127 | (d->mIt)++; |
127 | return *this; | 128 | return *this; |
128 | } | 129 | } |
129 | 130 | ||
130 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 131 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
131 | { | 132 | { |
132 | (d->mIt)--; | 133 | (d->mIt)--; |
133 | return *this; | 134 | return *this; |
134 | } | 135 | } |
135 | 136 | ||
136 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 137 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
137 | { | 138 | { |
138 | (d->mIt)--; | 139 | (d->mIt)--; |
139 | return *this; | 140 | return *this; |
140 | } | 141 | } |
141 | 142 | ||
142 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 143 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
143 | { | 144 | { |
144 | return ( d->mIt == it.d->mIt ); | 145 | return ( d->mIt == it.d->mIt ); |
145 | } | 146 | } |
146 | 147 | ||
147 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 148 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
148 | { | 149 | { |
149 | return ( d->mIt != it.d->mIt ); | 150 | return ( d->mIt != it.d->mIt ); |
150 | } | 151 | } |
151 | 152 | ||
152 | 153 | ||
153 | AddressBook::ConstIterator::ConstIterator() | 154 | AddressBook::ConstIterator::ConstIterator() |
154 | { | 155 | { |
155 | d = new ConstIteratorData; | 156 | d = new ConstIteratorData; |
156 | } | 157 | } |
157 | 158 | ||
158 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 159 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
159 | { | 160 | { |
160 | d = new ConstIteratorData; | 161 | d = new ConstIteratorData; |
161 | d->mIt = i.d->mIt; | 162 | d->mIt = i.d->mIt; |
162 | } | 163 | } |
163 | 164 | ||
164 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 165 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
165 | { | 166 | { |
166 | if( this == &i ) return *this; // guard for self assignment | 167 | if( this == &i ) return *this; // guard for self assignment |
167 | delete d; // delete the old data because the Iterator was really constructed before | 168 | delete d; // delete the old data because the Iterator was really constructed before |
168 | d = new ConstIteratorData; | 169 | d = new ConstIteratorData; |
169 | d->mIt = i.d->mIt; | 170 | d->mIt = i.d->mIt; |
170 | return *this; | 171 | return *this; |
171 | } | 172 | } |
172 | 173 | ||
173 | AddressBook::ConstIterator::~ConstIterator() | 174 | AddressBook::ConstIterator::~ConstIterator() |
174 | { | 175 | { |
175 | delete d; | 176 | delete d; |
176 | } | 177 | } |
177 | 178 | ||
178 | const Addressee &AddressBook::ConstIterator::operator*() const | 179 | const Addressee &AddressBook::ConstIterator::operator*() const |
179 | { | 180 | { |
180 | return *(d->mIt); | 181 | return *(d->mIt); |
181 | } | 182 | } |
182 | 183 | ||
183 | const Addressee* AddressBook::ConstIterator::operator->() const | 184 | const Addressee* AddressBook::ConstIterator::operator->() const |
184 | { | 185 | { |
185 | return &(*(d->mIt)); | 186 | return &(*(d->mIt)); |
186 | } | 187 | } |
187 | 188 | ||
188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
189 | { | 190 | { |
190 | (d->mIt)++; | 191 | (d->mIt)++; |
191 | return *this; | 192 | return *this; |
192 | } | 193 | } |
193 | 194 | ||
194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
195 | { | 196 | { |
196 | (d->mIt)++; | 197 | (d->mIt)++; |
197 | return *this; | 198 | return *this; |
198 | } | 199 | } |
199 | 200 | ||
200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
201 | { | 202 | { |
202 | (d->mIt)--; | 203 | (d->mIt)--; |
203 | return *this; | 204 | return *this; |
204 | } | 205 | } |
205 | 206 | ||
206 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 207 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
207 | { | 208 | { |
208 | (d->mIt)--; | 209 | (d->mIt)--; |
209 | return *this; | 210 | return *this; |
210 | } | 211 | } |
211 | 212 | ||
212 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 213 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
213 | { | 214 | { |
214 | return ( d->mIt == it.d->mIt ); | 215 | return ( d->mIt == it.d->mIt ); |
215 | } | 216 | } |
216 | 217 | ||
217 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 218 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
218 | { | 219 | { |
219 | return ( d->mIt != it.d->mIt ); | 220 | return ( d->mIt != it.d->mIt ); |
220 | } | 221 | } |
221 | 222 | ||
222 | 223 | ||
223 | AddressBook::AddressBook() | 224 | AddressBook::AddressBook() |
224 | { | 225 | { |
225 | init(0, "contact"); | 226 | init(0, "contact"); |
226 | } | 227 | } |
227 | 228 | ||
228 | AddressBook::AddressBook( const QString &config ) | 229 | AddressBook::AddressBook( const QString &config ) |
229 | { | 230 | { |
230 | init(config, "contact"); | 231 | init(config, "contact"); |
231 | } | 232 | } |
232 | 233 | ||
233 | AddressBook::AddressBook( const QString &config, const QString &family ) | 234 | AddressBook::AddressBook( const QString &config, const QString &family ) |
234 | { | 235 | { |
235 | init(config, family); | 236 | init(config, family); |
236 | 237 | ||
237 | } | 238 | } |
238 | 239 | ||
239 | // the default family is "contact" | 240 | // the default family is "contact" |
240 | void AddressBook::init(const QString &config, const QString &family ) | 241 | void AddressBook::init(const QString &config, const QString &family ) |
241 | { | 242 | { |
242 | blockLSEchange = false; | 243 | blockLSEchange = false; |
243 | d = new AddressBookData; | 244 | d = new AddressBookData; |
244 | QString fami = family; | 245 | QString fami = family; |
245 | if (config != 0) { | 246 | if (config != 0) { |
246 | if ( family == "syncContact" ) { | 247 | if ( family == "syncContact" ) { |
247 | qDebug("creating sync config "); | 248 | qDebug("creating sync config "); |
248 | fami = "contact"; | 249 | fami = "contact"; |
249 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 250 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
250 | con->setGroup( "General" ); | 251 | con->setGroup( "General" ); |
251 | con->writeEntry( "ResourceKeys", QString("sync") ); | 252 | con->writeEntry( "ResourceKeys", QString("sync") ); |
252 | con->writeEntry( "Standard", QString("sync") ); | 253 | con->writeEntry( "Standard", QString("sync") ); |
253 | con->setGroup( "Resource_sync" ); | 254 | con->setGroup( "Resource_sync" ); |
254 | con->writeEntry( "FileName", config ); | 255 | con->writeEntry( "FileName", config ); |
255 | con->writeEntry( "FileFormat", QString("vcard") ); | 256 | con->writeEntry( "FileFormat", QString("vcard") ); |
256 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 257 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
257 | con->writeEntry( "ResourceName", QString("sync_res") ); | 258 | con->writeEntry( "ResourceName", QString("sync_res") ); |
258 | if ( config.right(4) == ".xml" ) | 259 | if ( config.right(4) == ".xml" ) |
259 | con->writeEntry( "ResourceType", QString("qtopia") ); | 260 | con->writeEntry( "ResourceType", QString("qtopia") ); |
260 | else if ( config == "sharp" ) { | 261 | else if ( config == "sharp" ) { |
261 | con->writeEntry( "ResourceType", QString("sharp") ); | 262 | con->writeEntry( "ResourceType", QString("sharp") ); |
262 | } else { | 263 | } else { |
263 | con->writeEntry( "ResourceType", QString("file") ); | 264 | con->writeEntry( "ResourceType", QString("file") ); |
264 | } | 265 | } |
265 | //con->sync(); | 266 | //con->sync(); |
266 | d->mConfig = con; | 267 | d->mConfig = con; |
267 | } | 268 | } |
268 | else | 269 | else |
269 | d->mConfig = new KConfig( locateLocal("config", config) ); | 270 | d->mConfig = new KConfig( locateLocal("config", config) ); |
270 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 271 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
271 | } | 272 | } |
272 | else { | 273 | else { |
273 | d->mConfig = 0; | 274 | d->mConfig = 0; |
274 | // qDebug("AddressBook::init 1 config=0"); | 275 | // qDebug("AddressBook::init 1 config=0"); |
275 | } | 276 | } |
276 | 277 | ||
277 | //US d->mErrorHandler = 0; | 278 | //US d->mErrorHandler = 0; |
278 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 279 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
279 | d->mManager->readConfig( d->mConfig ); | 280 | d->mManager->readConfig( d->mConfig ); |
280 | if ( family == "syncContact" ) { | 281 | if ( family == "syncContact" ) { |
281 | KRES::Manager<Resource> *manager = d->mManager; | 282 | KRES::Manager<Resource> *manager = d->mManager; |
282 | KRES::Manager<Resource>::ActiveIterator it; | 283 | KRES::Manager<Resource>::ActiveIterator it; |
283 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 284 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
284 | (*it)->setAddressBook( this ); | 285 | (*it)->setAddressBook( this ); |
285 | if ( !(*it)->open() ) | 286 | if ( !(*it)->open() ) |
286 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 287 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
287 | } | 288 | } |
288 | Resource *res = standardResource(); | 289 | Resource *res = standardResource(); |
289 | if ( !res ) { | 290 | if ( !res ) { |
290 | qDebug("ERROR: no standard resource"); | 291 | qDebug("ERROR: no standard resource"); |
291 | res = manager->createResource( "file" ); | 292 | res = manager->createResource( "file" ); |
292 | if ( res ) | 293 | if ( res ) |
293 | { | 294 | { |
294 | addResource( res ); | 295 | addResource( res ); |
295 | } | 296 | } |
296 | else | 297 | else |
297 | qDebug(" No resource available!!!"); | 298 | qDebug(" No resource available!!!"); |
298 | } | 299 | } |
299 | setStandardResource( res ); | 300 | setStandardResource( res ); |
300 | manager->writeConfig(); | 301 | manager->writeConfig(); |
301 | } | 302 | } |
302 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 303 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
303 | "X-Department", "KADDRESSBOOK" ); | 304 | "X-Department", "KADDRESSBOOK" ); |
304 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 305 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
305 | "X-Profession", "KADDRESSBOOK" ); | 306 | "X-Profession", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 307 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
307 | "X-AssistantsName", "KADDRESSBOOK" ); | 308 | "X-AssistantsName", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 309 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
309 | "X-ManagersName", "KADDRESSBOOK" ); | 310 | "X-ManagersName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 311 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
311 | "X-SpousesName", "KADDRESSBOOK" ); | 312 | "X-SpousesName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 313 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
313 | "X-Office", "KADDRESSBOOK" ); | 314 | "X-Office", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 315 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
315 | "X-IMAddress", "KADDRESSBOOK" ); | 316 | "X-IMAddress", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 317 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
317 | "X-Anniversary", "KADDRESSBOOK" ); | 318 | "X-Anniversary", "KADDRESSBOOK" ); |
318 | 319 | ||
319 | //US added this field to become compatible with Opie/qtopia addressbook | 320 | //US added this field to become compatible with Opie/qtopia addressbook |
320 | // values can be "female" or "male" or "". An empty field represents undefined. | 321 | // values can be "female" or "male" or "". An empty field represents undefined. |
321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 322 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
322 | "X-Gender", "KADDRESSBOOK" ); | 323 | "X-Gender", "KADDRESSBOOK" ); |
323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 324 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
324 | "X-Children", "KADDRESSBOOK" ); | 325 | "X-Children", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 326 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 327 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 328 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
328 | "X-ExternalID", "KADDRESSBOOK" ); | 329 | "X-ExternalID", "KADDRESSBOOK" ); |
329 | } | 330 | } |
330 | 331 | ||
331 | AddressBook::~AddressBook() | 332 | AddressBook::~AddressBook() |
332 | { | 333 | { |
333 | delete d->mConfig; d->mConfig = 0; | 334 | delete d->mConfig; d->mConfig = 0; |
334 | delete d->mManager; d->mManager = 0; | 335 | delete d->mManager; d->mManager = 0; |
335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 336 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
336 | delete d; d = 0; | 337 | delete d; d = 0; |
337 | } | 338 | } |
338 | 339 | ||
339 | bool AddressBook::load() | 340 | bool AddressBook::load() |
340 | { | 341 | { |
341 | 342 | ||
342 | 343 | ||
343 | clear(); | 344 | clear(); |
344 | 345 | ||
345 | KRES::Manager<Resource>::ActiveIterator it; | 346 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 347 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 348 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 349 | if ( !(*it)->load() ) { |
349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 350 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 351 | ok = false; |
351 | } | 352 | } |
352 | 353 | ||
353 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
354 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
356 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
358 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
359 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
360 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
361 | } | 362 | } |
362 | } | 363 | } |
363 | blockLSEchange = true; | 364 | blockLSEchange = true; |
364 | return ok; | 365 | return ok; |
365 | } | 366 | } |
366 | 367 | ||
367 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
368 | { | 369 | { |
369 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
370 | 371 | ||
371 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
372 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
373 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
374 | } | 375 | } |
375 | 376 | ||
376 | return false; | 377 | return false; |
377 | } | 378 | } |
378 | void AddressBook::export2File( QString fileName ) | 379 | void AddressBook::export2File( QString fileName ) |
379 | { | 380 | { |
380 | 381 | ||
381 | QFile outFile( fileName ); | 382 | QFile outFile( fileName ); |
382 | if ( !outFile.open( IO_WriteOnly ) ) { | 383 | if ( !outFile.open( IO_WriteOnly ) ) { |
383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 384 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
384 | KMessageBox::error( 0, text.arg( fileName ) ); | 385 | KMessageBox::error( 0, text.arg( fileName ) ); |
385 | return ; | 386 | return ; |
386 | } | 387 | } |
387 | QTextStream t( &outFile ); | 388 | QTextStream t( &outFile ); |
388 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 389 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
389 | Iterator it; | 390 | Iterator it; |
390 | KABC::VCardConverter::Version version; | 391 | KABC::VCardConverter::Version version; |
391 | version = KABC::VCardConverter::v3_0; | 392 | version = KABC::VCardConverter::v3_0; |
392 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
393 | if ( !(*it).IDStr().isEmpty() ) { | 394 | if ( !(*it).IDStr().isEmpty() ) { |
394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
395 | } | 396 | } |
396 | KABC::VCardConverter converter; | 397 | KABC::VCardConverter converter; |
397 | QString vcard; | 398 | QString vcard; |
398 | //Resource *resource() const; | 399 | //Resource *resource() const; |
399 | converter.addresseeToVCard( *it, vcard, version ); | 400 | converter.addresseeToVCard( *it, vcard, version ); |
400 | t << vcard << "\r\n"; | 401 | t << vcard << "\r\n"; |
401 | } | 402 | } |
402 | t << "\r\n\r\n"; | 403 | t << "\r\n\r\n"; |
403 | outFile.close(); | 404 | outFile.close(); |
404 | } | 405 | } |
405 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) | 406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel ) |
406 | { | 407 | { |
407 | 408 | ||
408 | KABC::Addressee::List list; | 409 | KABC::Addressee::List list; |
409 | QFile file( fileName ); | 410 | QFile file( fileName ); |
410 | 411 | ||
411 | file.open( IO_ReadOnly ); | 412 | file.open( IO_ReadOnly ); |
412 | QByteArray rawData = file.readAll(); | 413 | QByteArray rawData = file.readAll(); |
413 | file.close(); | 414 | file.close(); |
414 | QString data; | 415 | QString data; |
415 | if ( replaceLabel ) { | 416 | if ( replaceLabel ) { |
416 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 417 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
417 | data.replace ( QRegExp("LABEL") , "ADR" ); | 418 | data.replace ( QRegExp("LABEL") , "ADR" ); |
418 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 419 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
419 | } else | 420 | } else |
420 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 421 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
421 | KABC::VCardTool tool; | 422 | KABC::VCardTool tool; |
422 | list = tool.parseVCards( data ); | 423 | list = tool.parseVCards( data ); |
423 | KABC::Addressee::List::Iterator it; | 424 | KABC::Addressee::List::Iterator it; |
424 | for ( it = list.begin(); it != list.end(); ++it ) { | 425 | for ( it = list.begin(); it != list.end(); ++it ) { |
425 | (*it).setResource( 0 ); | 426 | (*it).setResource( 0 ); |
426 | if ( replaceLabel ) | 427 | if ( replaceLabel ) |
427 | (*it).removeVoice(); | 428 | (*it).removeVoice(); |
428 | insertAddressee( (*it), false, true ); | 429 | insertAddressee( (*it), false, true ); |
429 | } | 430 | } |
430 | 431 | ||
431 | } | 432 | } |
432 | 433 | ||
433 | bool AddressBook::saveAB() | 434 | bool AddressBook::saveAB() |
434 | { | 435 | { |
435 | bool ok = true; | 436 | bool ok = true; |
436 | 437 | ||
437 | deleteRemovedAddressees(); | 438 | deleteRemovedAddressees(); |
438 | Iterator ait; | 439 | Iterator ait; |
439 | for ( ait = begin(); ait != end(); ++ait ) { | 440 | for ( ait = begin(); ait != end(); ++ait ) { |
440 | if ( !(*ait).IDStr().isEmpty() ) { | 441 | if ( !(*ait).IDStr().isEmpty() ) { |
441 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 442 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
442 | } | 443 | } |
443 | } | 444 | } |
444 | KRES::Manager<Resource>::ActiveIterator it; | 445 | KRES::Manager<Resource>::ActiveIterator it; |
445 | KRES::Manager<Resource> *manager = d->mManager; | 446 | KRES::Manager<Resource> *manager = d->mManager; |
446 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 447 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
447 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 448 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
448 | Ticket *ticket = requestSaveTicket( *it ); | 449 | Ticket *ticket = requestSaveTicket( *it ); |
449 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 450 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
450 | if ( !ticket ) { | 451 | if ( !ticket ) { |
451 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 452 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
452 | .arg( (*it)->resourceName() ) ); | 453 | .arg( (*it)->resourceName() ) ); |
453 | return false; | 454 | return false; |
454 | } | 455 | } |
455 | 456 | ||
456 | //if ( !save( ticket ) ) | 457 | //if ( !save( ticket ) ) |
457 | if ( ticket->resource() ) { | 458 | if ( ticket->resource() ) { |
458 | if ( ! ticket->resource()->save( ticket ) ) | 459 | if ( ! ticket->resource()->save( ticket ) ) |
459 | ok = false; | 460 | ok = false; |
460 | } else | 461 | } else |
461 | ok = false; | 462 | ok = false; |
462 | 463 | ||
463 | } | 464 | } |
464 | } | 465 | } |
465 | return ok; | 466 | return ok; |
466 | } | 467 | } |
467 | 468 | ||
468 | AddressBook::Iterator AddressBook::begin() | 469 | AddressBook::Iterator AddressBook::begin() |
469 | { | 470 | { |
470 | Iterator it = Iterator(); | 471 | Iterator it = Iterator(); |
471 | it.d->mIt = d->mAddressees.begin(); | 472 | it.d->mIt = d->mAddressees.begin(); |
472 | return it; | 473 | return it; |
473 | } | 474 | } |
474 | 475 | ||
475 | AddressBook::ConstIterator AddressBook::begin() const | 476 | AddressBook::ConstIterator AddressBook::begin() const |
476 | { | 477 | { |
477 | ConstIterator it = ConstIterator(); | 478 | ConstIterator it = ConstIterator(); |
478 | it.d->mIt = d->mAddressees.begin(); | 479 | it.d->mIt = d->mAddressees.begin(); |
479 | return it; | 480 | return it; |
480 | } | 481 | } |
481 | 482 | ||
482 | AddressBook::Iterator AddressBook::end() | 483 | AddressBook::Iterator AddressBook::end() |
483 | { | 484 | { |
484 | Iterator it = Iterator(); | 485 | Iterator it = Iterator(); |
485 | it.d->mIt = d->mAddressees.end(); | 486 | it.d->mIt = d->mAddressees.end(); |
486 | return it; | 487 | return it; |
487 | } | 488 | } |
488 | 489 | ||
489 | AddressBook::ConstIterator AddressBook::end() const | 490 | AddressBook::ConstIterator AddressBook::end() const |
490 | { | 491 | { |
491 | ConstIterator it = ConstIterator(); | 492 | ConstIterator it = ConstIterator(); |
492 | it.d->mIt = d->mAddressees.end(); | 493 | it.d->mIt = d->mAddressees.end(); |
493 | return it; | 494 | return it; |
494 | } | 495 | } |
495 | 496 | ||
496 | void AddressBook::clear() | 497 | void AddressBook::clear() |
497 | { | 498 | { |
498 | d->mAddressees.clear(); | 499 | d->mAddressees.clear(); |
499 | } | 500 | } |
500 | 501 | ||
501 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 502 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
502 | { | 503 | { |
503 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 504 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
504 | 505 | ||
505 | if ( !resource ) | 506 | if ( !resource ) |
506 | { | 507 | { |
507 | qDebug("AddressBook::requestSaveTicket no resource" ); | 508 | qDebug("AddressBook::requestSaveTicket no resource" ); |
508 | resource = standardResource(); | 509 | resource = standardResource(); |
509 | } | 510 | } |
510 | 511 | ||
511 | KRES::Manager<Resource>::ActiveIterator it; | 512 | KRES::Manager<Resource>::ActiveIterator it; |
512 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 513 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
513 | if ( (*it) == resource ) { | 514 | if ( (*it) == resource ) { |
514 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 515 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
515 | return 0; | 516 | return 0; |
516 | else | 517 | else |
517 | return (*it)->requestSaveTicket(); | 518 | return (*it)->requestSaveTicket(); |
518 | } | 519 | } |
519 | } | 520 | } |
520 | 521 | ||
521 | return 0; | 522 | return 0; |
522 | } | 523 | } |
523 | 524 | ||
524 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 525 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
525 | { | 526 | { |
526 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 527 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
527 | //qDebug("block insert "); | 528 | //qDebug("block insert "); |
528 | return; | 529 | return; |
529 | } | 530 | } |
530 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 531 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
531 | bool found = false; | 532 | bool found = false; |
532 | Addressee::List::Iterator it; | 533 | Addressee::List::Iterator it; |
533 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 534 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
534 | if ( a.uid() == (*it).uid() ) { | 535 | if ( a.uid() == (*it).uid() ) { |
535 | 536 | ||
536 | bool changed = false; | 537 | bool changed = false; |
537 | Addressee addr = a; | 538 | Addressee addr = a; |
538 | if ( addr != (*it) ) | 539 | if ( addr != (*it) ) |
539 | changed = true; | 540 | changed = true; |
540 | 541 | ||
541 | if ( takeResource ) { | 542 | if ( takeResource ) { |
542 | Resource * res = (*it).resource(); | 543 | Resource * res = (*it).resource(); |
543 | (*it) = a; | 544 | (*it) = a; |
544 | (*it).setResource( res ); | 545 | (*it).setResource( res ); |
545 | } else { | 546 | } else { |
546 | (*it) = a; | 547 | (*it) = a; |
547 | if ( (*it).resource() == 0 ) | 548 | if ( (*it).resource() == 0 ) |
548 | (*it).setResource( standardResource() ); | 549 | (*it).setResource( standardResource() ); |
549 | } | 550 | } |
550 | if ( changed ) { | 551 | if ( changed ) { |
551 | if ( setRev ) { | 552 | if ( setRev ) { |
552 | 553 | ||
553 | // get rid of micro seconds | 554 | // get rid of micro seconds |
554 | QDateTime dt = QDateTime::currentDateTime(); | 555 | QDateTime dt = QDateTime::currentDateTime(); |
555 | QTime t = dt.time(); | 556 | QTime t = dt.time(); |
556 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 557 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
557 | (*it).setRevision( dt ); | 558 | (*it).setRevision( dt ); |
558 | } | 559 | } |
559 | (*it).setChanged( true ); | 560 | (*it).setChanged( true ); |
560 | } | 561 | } |
561 | 562 | ||
562 | found = true; | 563 | found = true; |
563 | } else { | 564 | } else { |
564 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 565 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
565 | QString name = (*it).uid().mid( 19 ); | 566 | QString name = (*it).uid().mid( 19 ); |
566 | Addressee b = a; | 567 | Addressee b = a; |
567 | QString id = b.getID( name ); | 568 | QString id = b.getID( name ); |
568 | if ( ! id.isEmpty() ) { | 569 | if ( ! id.isEmpty() ) { |
569 | QString des = (*it).note(); | 570 | QString des = (*it).note(); |
570 | int startN; | 571 | int startN; |
571 | if( (startN = des.find( id ) ) >= 0 ) { | 572 | if( (startN = des.find( id ) ) >= 0 ) { |
572 | int endN = des.find( ",", startN+1 ); | 573 | int endN = des.find( ",", startN+1 ); |
573 | des = des.left( startN ) + des.mid( endN+1 ); | 574 | des = des.left( startN ) + des.mid( endN+1 ); |
574 | (*it).setNote( des ); | 575 | (*it).setNote( des ); |
575 | } | 576 | } |
576 | } | 577 | } |
577 | } | 578 | } |
578 | } | 579 | } |
579 | } | 580 | } |
580 | if ( found ) | 581 | if ( found ) |
581 | return; | 582 | return; |
582 | d->mAddressees.append( a ); | 583 | d->mAddressees.append( a ); |
583 | Addressee& addr = d->mAddressees.last(); | 584 | Addressee& addr = d->mAddressees.last(); |
584 | if ( addr.resource() == 0 ) | 585 | if ( addr.resource() == 0 ) |
585 | addr.setResource( standardResource() ); | 586 | addr.setResource( standardResource() ); |
586 | 587 | ||
587 | addr.setChanged( true ); | 588 | addr.setChanged( true ); |
588 | } | 589 | } |
589 | 590 | ||
590 | void AddressBook::removeAddressee( const Addressee &a ) | 591 | void AddressBook::removeAddressee( const Addressee &a ) |
591 | { | 592 | { |
592 | Iterator it; | 593 | Iterator it; |
593 | Iterator it2; | 594 | Iterator it2; |
594 | bool found = false; | 595 | bool found = false; |
595 | for ( it = begin(); it != end(); ++it ) { | 596 | for ( it = begin(); it != end(); ++it ) { |
596 | if ( a.uid() == (*it).uid() ) { | 597 | if ( a.uid() == (*it).uid() ) { |
597 | found = true; | 598 | found = true; |
598 | it2 = it; | 599 | it2 = it; |
599 | } else { | 600 | } else { |
600 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 601 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
601 | QString name = (*it).uid().mid( 19 ); | 602 | QString name = (*it).uid().mid( 19 ); |
602 | Addressee b = a; | 603 | Addressee b = a; |
603 | QString id = b.getID( name ); | 604 | QString id = b.getID( name ); |
604 | if ( ! id.isEmpty() ) { | 605 | if ( ! id.isEmpty() ) { |
605 | QString des = (*it).note(); | 606 | QString des = (*it).note(); |
606 | if( des.find( id ) < 0 ) { | 607 | if( des.find( id ) < 0 ) { |
607 | des += id + ","; | 608 | des += id + ","; |
608 | (*it).setNote( des ); | 609 | (*it).setNote( des ); |
609 | } | 610 | } |
610 | } | 611 | } |
611 | } | 612 | } |
612 | 613 | ||
613 | } | 614 | } |
614 | } | 615 | } |
615 | 616 | ||
616 | if ( found ) | 617 | if ( found ) |
617 | removeAddressee( it2 ); | 618 | removeAddressee( it2 ); |
618 | 619 | ||
619 | } | 620 | } |
620 | 621 | ||
621 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 622 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
622 | { | 623 | { |
623 | Iterator it = begin(); | 624 | Iterator it = begin(); |
624 | Iterator it2 ; | 625 | Iterator it2 ; |
625 | QDateTime dt ( QDate( 2004,1,1) ); | 626 | QDateTime dt ( QDate( 2004,1,1) ); |
626 | while ( it != end() ) { | 627 | while ( it != end() ) { |
627 | (*it).setRevision( dt ); | 628 | (*it).setRevision( dt ); |
628 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 629 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
629 | (*it).setIDStr(""); | 630 | (*it).setIDStr(""); |
630 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 631 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
631 | it2 = it; | 632 | it2 = it; |
632 | //qDebug("removing %s ",(*it).uid().latin1() ); | 633 | //qDebug("removing %s ",(*it).uid().latin1() ); |
633 | ++it; | 634 | ++it; |
634 | removeAddressee( it2 ); | 635 | removeAddressee( it2 ); |
635 | } else { | 636 | } else { |
636 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 637 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
637 | ++it; | 638 | ++it; |
638 | } | 639 | } |
639 | } | 640 | } |
640 | deleteRemovedAddressees(); | 641 | deleteRemovedAddressees(); |
641 | } | 642 | } |
642 | 643 | ||
643 | void AddressBook::removeAddressee( const Iterator &it ) | 644 | void AddressBook::removeAddressee( const Iterator &it ) |
644 | { | 645 | { |
645 | d->mRemovedAddressees.append( (*it) ); | 646 | d->mRemovedAddressees.append( (*it) ); |
646 | d->mAddressees.remove( it.d->mIt ); | 647 | d->mAddressees.remove( it.d->mIt ); |
647 | } | 648 | } |
648 | 649 | ||
649 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 650 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
650 | { | 651 | { |
651 | Iterator it; | 652 | Iterator it; |
652 | for ( it = begin(); it != end(); ++it ) { | 653 | for ( it = begin(); it != end(); ++it ) { |
653 | if ( a.uid() == (*it).uid() ) { | 654 | if ( a.uid() == (*it).uid() ) { |
654 | return it; | 655 | return it; |
655 | } | 656 | } |
656 | } | 657 | } |
657 | return end(); | 658 | return end(); |
658 | } | 659 | } |
659 | 660 | ||
660 | Addressee AddressBook::findByUid( const QString &uid ) | 661 | Addressee AddressBook::findByUid( const QString &uid ) |
661 | { | 662 | { |
662 | Iterator it; | 663 | Iterator it; |
663 | for ( it = begin(); it != end(); ++it ) { | 664 | for ( it = begin(); it != end(); ++it ) { |
664 | if ( uid == (*it).uid() ) { | 665 | if ( uid == (*it).uid() ) { |
665 | return *it; | 666 | return *it; |
666 | } | 667 | } |
667 | } | 668 | } |
668 | return Addressee(); | 669 | return Addressee(); |
669 | } | 670 | } |
670 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 671 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
671 | { | 672 | { |
672 | //qDebug("AddressBook::preExternSync "); | 673 | //qDebug("AddressBook::preExternSync "); |
673 | AddressBook::Iterator it; | 674 | AddressBook::Iterator it; |
674 | for ( it = begin(); it != end(); ++it ) { | 675 | for ( it = begin(); it != end(); ++it ) { |
675 | (*it).setID( csd, (*it).externalUID() ); | 676 | (*it).setID( csd, (*it).externalUID() ); |
676 | (*it).computeCsum( csd ); | 677 | (*it).computeCsum( csd ); |
677 | } | 678 | } |
678 | mergeAB( aBook ,csd ); | 679 | mergeAB( aBook ,csd ); |
679 | } | 680 | } |
680 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 681 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
681 | { | 682 | { |
682 | //qDebug("AddressBook::postExternSync "); | 683 | //qDebug("AddressBook::postExternSync "); |
683 | AddressBook::Iterator it; | 684 | AddressBook::Iterator it; |
684 | for ( it = begin(); it != end(); ++it ) { | 685 | for ( it = begin(); it != end(); ++it ) { |
685 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 686 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
686 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 687 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
687 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 688 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
688 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 689 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
689 | if ( ad.isEmpty() ) { | 690 | if ( ad.isEmpty() ) { |
690 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 691 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
691 | } else { | 692 | } else { |
692 | (*it).computeCsum( csd ); | 693 | (*it).computeCsum( csd ); |
693 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 694 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
694 | ad.setID( csd, (*it).externalUID() ); | 695 | ad.setID( csd, (*it).externalUID() ); |
695 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 696 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
696 | aBook->insertAddressee( ad ); | 697 | aBook->insertAddressee( ad ); |
697 | } | 698 | } |
698 | } | 699 | } |
699 | } | 700 | } |
700 | } | 701 | } |
701 | 702 | ||
702 | bool AddressBook::containsExternalUid( const QString& uid ) | 703 | bool AddressBook::containsExternalUid( const QString& uid ) |
703 | { | 704 | { |
704 | Iterator it; | 705 | Iterator it; |
705 | for ( it = begin(); it != end(); ++it ) { | 706 | for ( it = begin(); it != end(); ++it ) { |
706 | if ( uid == (*it).externalUID( ) ) | 707 | if ( uid == (*it).externalUID( ) ) |
707 | return true; | 708 | return true; |
708 | } | 709 | } |
709 | return false; | 710 | return false; |
710 | } | 711 | } |
711 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 712 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
712 | { | 713 | { |
713 | Iterator it; | 714 | Iterator it; |
714 | for ( it = begin(); it != end(); ++it ) { | 715 | for ( it = begin(); it != end(); ++it ) { |
715 | if ( uid == (*it).getID( profile ) ) | 716 | if ( uid == (*it).getID( profile ) ) |
716 | return (*it); | 717 | return (*it); |
717 | } | 718 | } |
718 | return Addressee(); | 719 | return Addressee(); |
719 | } | 720 | } |
720 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 721 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
721 | { | 722 | { |
722 | Iterator it; | 723 | Iterator it; |
723 | Addressee ad; | 724 | Addressee ad; |
724 | for ( it = begin(); it != end(); ++it ) { | 725 | for ( it = begin(); it != end(); ++it ) { |
725 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 726 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
726 | if ( !ad.isEmpty() ) { | 727 | if ( !ad.isEmpty() ) { |
727 | (*it).mergeContact( ad ); | 728 | (*it).mergeContact( ad ); |
728 | } | 729 | } |
729 | } | 730 | } |
730 | #if 0 | 731 | #if 0 |
731 | // test only | 732 | // test only |
732 | for ( it = begin(); it != end(); ++it ) { | 733 | for ( it = begin(); it != end(); ++it ) { |
733 | 734 | ||
734 | qDebug("uid %s ", (*it).uid().latin1()); | 735 | qDebug("uid %s ", (*it).uid().latin1()); |
735 | } | 736 | } |
736 | #endif | 737 | #endif |
737 | } | 738 | } |
738 | 739 | ||
739 | #if 0 | 740 | #if 0 |
740 | Addressee::List AddressBook::getExternLastSyncAddressees() | 741 | Addressee::List AddressBook::getExternLastSyncAddressees() |
741 | { | 742 | { |
742 | Addressee::List results; | 743 | Addressee::List results; |
743 | 744 | ||
744 | Iterator it; | 745 | Iterator it; |
745 | for ( it = begin(); it != end(); ++it ) { | 746 | for ( it = begin(); it != end(); ++it ) { |
746 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 747 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
747 | if ( (*it).familyName().left(4) == "!E: " ) | 748 | if ( (*it).familyName().left(4) == "!E: " ) |
748 | results.append( *it ); | 749 | results.append( *it ); |
749 | } | 750 | } |
750 | } | 751 | } |
751 | 752 | ||
752 | return results; | 753 | return results; |
753 | } | 754 | } |
754 | #endif | 755 | #endif |
755 | void AddressBook::resetTempSyncStat() | 756 | void AddressBook::resetTempSyncStat() |
756 | { | 757 | { |
757 | Iterator it; | 758 | Iterator it; |
758 | for ( it = begin(); it != end(); ++it ) { | 759 | for ( it = begin(); it != end(); ++it ) { |
759 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 760 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
760 | } | 761 | } |
761 | 762 | ||
762 | } | 763 | } |
763 | 764 | ||
764 | QStringList AddressBook:: uidList() | 765 | QStringList AddressBook:: uidList() |
765 | { | 766 | { |
766 | QStringList results; | 767 | QStringList results; |
767 | Iterator it; | 768 | Iterator it; |
768 | for ( it = begin(); it != end(); ++it ) { | 769 | for ( it = begin(); it != end(); ++it ) { |
769 | results.append( (*it).uid() ); | 770 | results.append( (*it).uid() ); |
770 | } | 771 | } |
771 | return results; | 772 | return results; |
772 | } | 773 | } |
773 | 774 | ||
774 | 775 | ||
775 | Addressee::List AddressBook::allAddressees() | 776 | Addressee::List AddressBook::allAddressees() |
776 | { | 777 | { |
777 | return d->mAddressees; | 778 | return d->mAddressees; |
778 | 779 | ||
779 | } | 780 | } |
780 | 781 | ||
781 | Addressee::List AddressBook::findByName( const QString &name ) | 782 | Addressee::List AddressBook::findByName( const QString &name ) |
782 | { | 783 | { |
783 | Addressee::List results; | 784 | Addressee::List results; |
784 | 785 | ||
785 | Iterator it; | 786 | Iterator it; |
786 | for ( it = begin(); it != end(); ++it ) { | 787 | for ( it = begin(); it != end(); ++it ) { |
787 | if ( name == (*it).realName() ) { | 788 | if ( name == (*it).realName() ) { |
788 | results.append( *it ); | 789 | results.append( *it ); |
789 | } | 790 | } |
790 | } | 791 | } |
791 | 792 | ||
792 | return results; | 793 | return results; |
793 | } | 794 | } |
794 | 795 | ||
795 | Addressee::List AddressBook::findByEmail( const QString &email ) | 796 | Addressee::List AddressBook::findByEmail( const QString &email ) |
796 | { | 797 | { |
797 | Addressee::List results; | 798 | Addressee::List results; |
798 | QStringList mailList; | 799 | QStringList mailList; |
799 | 800 | ||
800 | Iterator it; | 801 | Iterator it; |
801 | for ( it = begin(); it != end(); ++it ) { | 802 | for ( it = begin(); it != end(); ++it ) { |
802 | mailList = (*it).emails(); | 803 | mailList = (*it).emails(); |
803 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 804 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
804 | if ( email == (*ite) ) { | 805 | if ( email == (*ite) ) { |
805 | results.append( *it ); | 806 | results.append( *it ); |
806 | } | 807 | } |
807 | } | 808 | } |
808 | } | 809 | } |
809 | 810 | ||
810 | return results; | 811 | return results; |
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp index efcd492..7ec3fca 100644 --- a/kaddressbook/kabcore.cpp +++ b/kaddressbook/kabcore.cpp | |||
@@ -2044,855 +2044,856 @@ void KABCore::addActionsManually() | |||
2044 | mActionCategories->plug( settingsMenu ); | 2044 | mActionCategories->plug( settingsMenu ); |
2045 | 2045 | ||
2046 | mActionLicence->plug( helpMenu ); | 2046 | mActionLicence->plug( helpMenu ); |
2047 | mActionFaq->plug( helpMenu ); | 2047 | mActionFaq->plug( helpMenu ); |
2048 | mActionAboutKAddressbook->plug( helpMenu ); | 2048 | mActionAboutKAddressbook->plug( helpMenu ); |
2049 | 2049 | ||
2050 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { | 2050 | if (KGlobal::getDesktopSize() > KGlobal::Small ) { |
2051 | 2051 | ||
2052 | mActionSave->plug( tb ); | 2052 | mActionSave->plug( tb ); |
2053 | mViewManager->getFilterAction()->plug ( tb); | 2053 | mViewManager->getFilterAction()->plug ( tb); |
2054 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { | 2054 | if (KGlobal::getDesktopSize() == KGlobal::Desktop ) { |
2055 | mActionUndo->plug( tb ); | 2055 | mActionUndo->plug( tb ); |
2056 | mActionDelete->plug( tb ); | 2056 | mActionDelete->plug( tb ); |
2057 | mActionRedo->plug( tb ); | 2057 | mActionRedo->plug( tb ); |
2058 | } | 2058 | } |
2059 | } | 2059 | } |
2060 | //mActionQuit->plug ( tb ); | 2060 | //mActionQuit->plug ( tb ); |
2061 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); | 2061 | // tb->insertWidget(-1, 0, mIncSearchWidget, 6); |
2062 | 2062 | ||
2063 | //US link the searchwidget first to this. | 2063 | //US link the searchwidget first to this. |
2064 | // The real linkage to the toolbar happens later. | 2064 | // The real linkage to the toolbar happens later. |
2065 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); | 2065 | //US mIncSearchWidget->reparent(tb, 0, QPoint(50,0), TRUE); |
2066 | //US tb->insertItem( mIncSearchWidget ); | 2066 | //US tb->insertItem( mIncSearchWidget ); |
2067 | /*US | 2067 | /*US |
2068 | mIncSearchWidget = new IncSearchWidget( tb ); | 2068 | mIncSearchWidget = new IncSearchWidget( tb ); |
2069 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), | 2069 | connect( mIncSearchWidget, SIGNAL( doSearch( const QString& ) ), |
2070 | SLOT( incrementalSearch( const QString& ) ) ); | 2070 | SLOT( incrementalSearch( const QString& ) ) ); |
2071 | 2071 | ||
2072 | mJumpButtonBar = new JumpButtonBar( this, this ); | 2072 | mJumpButtonBar = new JumpButtonBar( this, this ); |
2073 | 2073 | ||
2074 | //US topLayout->addWidget( mJumpButtonBar ); | 2074 | //US topLayout->addWidget( mJumpButtonBar ); |
2075 | this->layout()->add( mJumpButtonBar ); | 2075 | this->layout()->add( mJumpButtonBar ); |
2076 | */ | 2076 | */ |
2077 | 2077 | ||
2078 | #endif //KAB_EMBEDDED | 2078 | #endif //KAB_EMBEDDED |
2079 | 2079 | ||
2080 | mActionExport2phone->plug( ExportMenu ); | 2080 | mActionExport2phone->plug( ExportMenu ); |
2081 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); | 2081 | connect ( syncMenu, SIGNAL( activated ( int ) ), syncManager, SLOT (slotSyncMenu( int ) ) ); |
2082 | syncManager->fillSyncMenu(); | 2082 | syncManager->fillSyncMenu(); |
2083 | 2083 | ||
2084 | } | 2084 | } |
2085 | void KABCore::showLicence() | 2085 | void KABCore::showLicence() |
2086 | { | 2086 | { |
2087 | KApplication::showLicence(); | 2087 | KApplication::showLicence(); |
2088 | } | 2088 | } |
2089 | void KABCore::removeVoice() | 2089 | void KABCore::removeVoice() |
2090 | { | 2090 | { |
2091 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) | 2091 | if ( KMessageBox::questionYesNo( this, i18n("After importing, phone numbers\nmay have two or more types.\n(E.g. work+voice)\nThese numbers are shown as \"other\".\nClick Yes to remove the voice type\nfrom numbers with more than one type.\n\nRemove voice type?") ) == KMessageBox::No ) |
2092 | return; | 2092 | return; |
2093 | KABC::Addressee::List list = mViewManager->selectedAddressees(); | 2093 | KABC::Addressee::List list = mViewManager->selectedAddressees(); |
2094 | KABC::Addressee::List::Iterator it; | 2094 | KABC::Addressee::List::Iterator it; |
2095 | for ( it = list.begin(); it != list.end(); ++it ) { | 2095 | for ( it = list.begin(); it != list.end(); ++it ) { |
2096 | 2096 | ||
2097 | if ( (*it).removeVoice() ) | 2097 | if ( (*it).removeVoice() ) |
2098 | contactModified((*it) ); | 2098 | contactModified((*it) ); |
2099 | } | 2099 | } |
2100 | } | 2100 | } |
2101 | 2101 | ||
2102 | 2102 | ||
2103 | 2103 | ||
2104 | void KABCore::clipboardDataChanged() | 2104 | void KABCore::clipboardDataChanged() |
2105 | { | 2105 | { |
2106 | 2106 | ||
2107 | if ( mReadWrite ) | 2107 | if ( mReadWrite ) |
2108 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); | 2108 | mActionPaste->setEnabled( !QApplication::clipboard()->text().isEmpty() ); |
2109 | 2109 | ||
2110 | } | 2110 | } |
2111 | 2111 | ||
2112 | void KABCore::updateActionMenu() | 2112 | void KABCore::updateActionMenu() |
2113 | { | 2113 | { |
2114 | UndoStack *undo = UndoStack::instance(); | 2114 | UndoStack *undo = UndoStack::instance(); |
2115 | RedoStack *redo = RedoStack::instance(); | 2115 | RedoStack *redo = RedoStack::instance(); |
2116 | 2116 | ||
2117 | if ( undo->isEmpty() ) | 2117 | if ( undo->isEmpty() ) |
2118 | mActionUndo->setText( i18n( "Undo" ) ); | 2118 | mActionUndo->setText( i18n( "Undo" ) ); |
2119 | else | 2119 | else |
2120 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); | 2120 | mActionUndo->setText( i18n( "Undo %1" ).arg( undo->top()->name() ) ); |
2121 | 2121 | ||
2122 | mActionUndo->setEnabled( !undo->isEmpty() ); | 2122 | mActionUndo->setEnabled( !undo->isEmpty() ); |
2123 | 2123 | ||
2124 | if ( !redo->top() ) | 2124 | if ( !redo->top() ) |
2125 | mActionRedo->setText( i18n( "Redo" ) ); | 2125 | mActionRedo->setText( i18n( "Redo" ) ); |
2126 | else | 2126 | else |
2127 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); | 2127 | mActionRedo->setText( i18n( "Redo %1" ).arg( redo->top()->name() ) ); |
2128 | 2128 | ||
2129 | mActionRedo->setEnabled( !redo->isEmpty() ); | 2129 | mActionRedo->setEnabled( !redo->isEmpty() ); |
2130 | } | 2130 | } |
2131 | 2131 | ||
2132 | void KABCore::configureKeyBindings() | 2132 | void KABCore::configureKeyBindings() |
2133 | { | 2133 | { |
2134 | #ifndef KAB_EMBEDDED | 2134 | #ifndef KAB_EMBEDDED |
2135 | KKeyDialog::configure( actionCollection(), true ); | 2135 | KKeyDialog::configure( actionCollection(), true ); |
2136 | #else //KAB_EMBEDDED | 2136 | #else //KAB_EMBEDDED |
2137 | qDebug("KABCore::configureKeyBindings() not implemented"); | 2137 | qDebug("KABCore::configureKeyBindings() not implemented"); |
2138 | #endif //KAB_EMBEDDED | 2138 | #endif //KAB_EMBEDDED |
2139 | } | 2139 | } |
2140 | 2140 | ||
2141 | #ifdef KAB_EMBEDDED | 2141 | #ifdef KAB_EMBEDDED |
2142 | void KABCore::configureResources() | 2142 | void KABCore::configureResources() |
2143 | { | 2143 | { |
2144 | KRES::KCMKResources dlg( this, "" , 0 ); | 2144 | KRES::KCMKResources dlg( this, "" , 0 ); |
2145 | 2145 | ||
2146 | if ( !dlg.exec() ) | 2146 | if ( !dlg.exec() ) |
2147 | return; | 2147 | return; |
2148 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); | 2148 | KMessageBox::information( this, i18n("Please restart to get the \nchanged resources (re)loaded!\n") ); |
2149 | } | 2149 | } |
2150 | #endif //KAB_EMBEDDED | 2150 | #endif //KAB_EMBEDDED |
2151 | 2151 | ||
2152 | 2152 | ||
2153 | /* this method will be called through the QCop interface from Ko/Pi to select addresses | 2153 | /* this method will be called through the QCop interface from Ko/Pi to select addresses |
2154 | * for the attendees list of an event. | 2154 | * for the attendees list of an event. |
2155 | */ | 2155 | */ |
2156 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) | 2156 | void KABCore::requestForNameEmailUidList(const QString& sourceChannel, const QString& uid) |
2157 | { | 2157 | { |
2158 | QStringList nameList; | 2158 | QStringList nameList; |
2159 | QStringList emailList; | 2159 | QStringList emailList; |
2160 | QStringList uidList; | 2160 | QStringList uidList; |
2161 | 2161 | ||
2162 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 2162 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
2163 | uint i=0; | 2163 | uint i=0; |
2164 | for (i=0; i < list.count(); i++) | 2164 | for (i=0; i < list.count(); i++) |
2165 | { | 2165 | { |
2166 | nameList.append(list[i].realName()); | 2166 | nameList.append(list[i].realName()); |
2167 | emailList.append(list[i].preferredEmail()); | 2167 | emailList.append(list[i].preferredEmail()); |
2168 | uidList.append(list[i].uid()); | 2168 | uidList.append(list[i].uid()); |
2169 | } | 2169 | } |
2170 | 2170 | ||
2171 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); | 2171 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI(sourceChannel, uid, nameList, emailList, uidList); |
2172 | 2172 | ||
2173 | } | 2173 | } |
2174 | 2174 | ||
2175 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays | 2175 | /* this method will be called through the QCop interface from Ko/Pi to select birthdays |
2176 | * to put them into the calendar. | 2176 | * to put them into the calendar. |
2177 | */ | 2177 | */ |
2178 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) | 2178 | void KABCore::requestForBirthdayList(const QString& sourceChannel, const QString& uid) |
2179 | { | 2179 | { |
2180 | // qDebug("KABCore::requestForBirthdayList"); | 2180 | // qDebug("KABCore::requestForBirthdayList"); |
2181 | QStringList birthdayList; | 2181 | QStringList birthdayList; |
2182 | QStringList anniversaryList; | 2182 | QStringList anniversaryList; |
2183 | QStringList realNameList; | 2183 | QStringList realNameList; |
2184 | QStringList preferredEmailList; | 2184 | QStringList preferredEmailList; |
2185 | QStringList assembledNameList; | 2185 | QStringList assembledNameList; |
2186 | QStringList uidList; | 2186 | QStringList uidList; |
2187 | 2187 | ||
2188 | KABC::AddressBook::Iterator it; | 2188 | KABC::AddressBook::Iterator it; |
2189 | 2189 | ||
2190 | int count = 0; | 2190 | int count = 0; |
2191 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { | 2191 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) { |
2192 | ++count; | 2192 | ++count; |
2193 | } | 2193 | } |
2194 | QProgressBar bar(count,0 ); | 2194 | QProgressBar bar(count,0 ); |
2195 | int w = 300; | 2195 | int w = 300; |
2196 | if ( QApplication::desktop()->width() < 320 ) | 2196 | if ( QApplication::desktop()->width() < 320 ) |
2197 | w = 220; | 2197 | w = 220; |
2198 | int h = bar.sizeHint().height() ; | 2198 | int h = bar.sizeHint().height() ; |
2199 | int dw = QApplication::desktop()->width(); | 2199 | int dw = QApplication::desktop()->width(); |
2200 | int dh = QApplication::desktop()->height(); | 2200 | int dh = QApplication::desktop()->height(); |
2201 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); | 2201 | bar.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); |
2202 | bar.show(); | 2202 | bar.show(); |
2203 | bar.setCaption (i18n("collecting birthdays - close to abort!") ); | 2203 | bar.setCaption (i18n("collecting birthdays - close to abort!") ); |
2204 | qApp->processEvents(); | 2204 | qApp->processEvents(); |
2205 | 2205 | ||
2206 | QDate bday; | 2206 | QDate bday; |
2207 | QString anni; | 2207 | QString anni; |
2208 | QString formattedbday; | 2208 | QString formattedbday; |
2209 | 2209 | ||
2210 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) | 2210 | for( it = mAddressBook->begin(); it != mAddressBook->end(); ++it ) |
2211 | { | 2211 | { |
2212 | if ( ! bar.isVisible() ) | 2212 | if ( ! bar.isVisible() ) |
2213 | return; | 2213 | return; |
2214 | bar.setProgress( count++ ); | 2214 | bar.setProgress( count++ ); |
2215 | qApp->processEvents(); | 2215 | qApp->processEvents(); |
2216 | bday = (*it).birthday().date(); | 2216 | bday = (*it).birthday().date(); |
2217 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); | 2217 | anni = (*it).custom("KADDRESSBOOK", "X-Anniversary" ); |
2218 | 2218 | ||
2219 | if ( bday.isValid() || !anni.isEmpty()) | 2219 | if ( bday.isValid() || !anni.isEmpty()) |
2220 | { | 2220 | { |
2221 | if (bday.isValid()) | 2221 | if (bday.isValid()) |
2222 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); | 2222 | formattedbday = KGlobal::locale()->formatDate(bday, true, KLocale::ISODate); |
2223 | else | 2223 | else |
2224 | formattedbday = "NOTVALID"; | 2224 | formattedbday = "NOTVALID"; |
2225 | if (anni.isEmpty()) | 2225 | if (anni.isEmpty()) |
2226 | anni = "INVALID"; | 2226 | anni = "INVALID"; |
2227 | 2227 | ||
2228 | birthdayList.append(formattedbday); | 2228 | birthdayList.append(formattedbday); |
2229 | anniversaryList.append(anni); //should be ISODate | 2229 | anniversaryList.append(anni); //should be ISODate |
2230 | realNameList.append((*it).realName()); | 2230 | realNameList.append((*it).realName()); |
2231 | preferredEmailList.append((*it).preferredEmail()); | 2231 | preferredEmailList.append((*it).preferredEmail()); |
2232 | assembledNameList.append((*it).assembledName()); | 2232 | assembledNameList.append((*it).assembledName()); |
2233 | uidList.append((*it).uid()); | 2233 | uidList.append((*it).uid()); |
2234 | 2234 | ||
2235 | qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); | 2235 | qDebug("found birthday in KA/Pi: %s,%s,%s,%s: %s, %s", (*it).realName().latin1(), (*it).preferredEmail().latin1(), (*it).assembledName().latin1(), (*it).uid().latin1(), formattedbday.latin1(), anni.latin1() ); |
2236 | } | 2236 | } |
2237 | } | 2237 | } |
2238 | 2238 | ||
2239 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); | 2239 | bool res = ExternalAppHandler::instance()->returnBirthdayListFromKAPI(sourceChannel, uid, birthdayList, anniversaryList, realNameList, preferredEmailList, assembledNameList, uidList); |
2240 | 2240 | ||
2241 | } | 2241 | } |
2242 | 2242 | ||
2243 | /* this method will be called through the QCop interface from other apps to show details of a contact. | 2243 | /* this method will be called through the QCop interface from other apps to show details of a contact. |
2244 | */ | 2244 | */ |
2245 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) | 2245 | void KABCore::requestForDetails(const QString& sourceChannel, const QString& sessionuid, const QString& name, const QString& email, const QString& uid) |
2246 | { | 2246 | { |
2247 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); | 2247 | qDebug("KABCore::requestForDetails %s %s %s %s %s", sourceChannel.latin1(), sessionuid.latin1(), name.latin1(), email.latin1(), uid.latin1()); |
2248 | 2248 | ||
2249 | QString foundUid = QString::null; | 2249 | QString foundUid = QString::null; |
2250 | if ( ! uid.isEmpty() ) { | 2250 | if ( ! uid.isEmpty() ) { |
2251 | Addressee adrr = mAddressBook->findByUid( uid ); | 2251 | Addressee adrr = mAddressBook->findByUid( uid ); |
2252 | if ( !adrr.isEmpty() ) { | 2252 | if ( !adrr.isEmpty() ) { |
2253 | foundUid = uid; | 2253 | foundUid = uid; |
2254 | } | 2254 | } |
2255 | if ( email == "sendbacklist" ) { | 2255 | if ( email == "sendbacklist" ) { |
2256 | //qDebug("ssssssssssssssssssssssend "); | 2256 | //qDebug("ssssssssssssssssssssssend "); |
2257 | QStringList nameList; | 2257 | QStringList nameList; |
2258 | QStringList emailList; | 2258 | QStringList emailList; |
2259 | QStringList uidList; | 2259 | QStringList uidList; |
2260 | nameList.append(adrr.realName()); | 2260 | nameList.append(adrr.realName()); |
2261 | emailList = adrr.emails(); | 2261 | emailList = adrr.emails(); |
2262 | uidList.append( adrr.preferredEmail()); | 2262 | uidList.append( adrr.preferredEmail()); |
2263 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); | 2263 | bool res = ExternalAppHandler::instance()->returnNameEmailUidListFromKAPI("QPE/Application/ompi", uid, nameList, emailList, uidList); |
2264 | return; | 2264 | return; |
2265 | } | 2265 | } |
2266 | 2266 | ||
2267 | } | 2267 | } |
2268 | 2268 | ||
2269 | if ( email == "sendbacklist" ) | 2269 | if ( email == "sendbacklist" ) |
2270 | return; | 2270 | return; |
2271 | if (foundUid.isEmpty()) | 2271 | if (foundUid.isEmpty()) |
2272 | { | 2272 | { |
2273 | //find the uid of the person first | 2273 | //find the uid of the person first |
2274 | Addressee::List namelist; | 2274 | Addressee::List namelist; |
2275 | Addressee::List emaillist; | 2275 | Addressee::List emaillist; |
2276 | 2276 | ||
2277 | if (!name.isEmpty()) | 2277 | if (!name.isEmpty()) |
2278 | namelist = mAddressBook->findByName( name ); | 2278 | namelist = mAddressBook->findByName( name ); |
2279 | 2279 | ||
2280 | if (!email.isEmpty()) | 2280 | if (!email.isEmpty()) |
2281 | emaillist = mAddressBook->findByEmail( email ); | 2281 | emaillist = mAddressBook->findByEmail( email ); |
2282 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); | 2282 | qDebug("count %d %d ", namelist.count(),emaillist.count() ); |
2283 | //check if we have a match in Namelist and Emaillist | 2283 | //check if we have a match in Namelist and Emaillist |
2284 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { | 2284 | if ((namelist.count() == 0) && (emaillist.count() > 0)) { |
2285 | foundUid = emaillist[0].uid(); | 2285 | foundUid = emaillist[0].uid(); |
2286 | } | 2286 | } |
2287 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) | 2287 | else if ((namelist.count() > 0) && (emaillist.count() == 0)) |
2288 | foundUid = namelist[0].uid(); | 2288 | foundUid = namelist[0].uid(); |
2289 | else | 2289 | else |
2290 | { | 2290 | { |
2291 | for (int i = 0; i < namelist.count(); i++) | 2291 | for (int i = 0; i < namelist.count(); i++) |
2292 | { | 2292 | { |
2293 | for (int j = 0; j < emaillist.count(); j++) | 2293 | for (int j = 0; j < emaillist.count(); j++) |
2294 | { | 2294 | { |
2295 | if (namelist[i] == emaillist[j]) | 2295 | if (namelist[i] == emaillist[j]) |
2296 | { | 2296 | { |
2297 | foundUid = namelist[i].uid(); | 2297 | foundUid = namelist[i].uid(); |
2298 | } | 2298 | } |
2299 | } | 2299 | } |
2300 | } | 2300 | } |
2301 | } | 2301 | } |
2302 | } | 2302 | } |
2303 | else | 2303 | else |
2304 | { | 2304 | { |
2305 | foundUid = uid; | 2305 | foundUid = uid; |
2306 | } | 2306 | } |
2307 | 2307 | ||
2308 | if (!foundUid.isEmpty()) | 2308 | if (!foundUid.isEmpty()) |
2309 | { | 2309 | { |
2310 | 2310 | ||
2311 | // raise Ka/Pi if it is in the background | 2311 | // raise Ka/Pi if it is in the background |
2312 | #ifndef DESKTOP_VERSION | 2312 | #ifndef DESKTOP_VERSION |
2313 | #ifndef KORG_NODCOP | 2313 | #ifndef KORG_NODCOP |
2314 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); | 2314 | //QCopEnvelope e("QPE/Application/kapi", "raise()"); |
2315 | #endif | 2315 | #endif |
2316 | #endif | 2316 | #endif |
2317 | 2317 | ||
2318 | mMainWindow->showMaximized(); | 2318 | mMainWindow->showMaximized(); |
2319 | mMainWindow-> raise(); | 2319 | mMainWindow-> raise(); |
2320 | 2320 | ||
2321 | mViewManager->setSelected( "", false); | 2321 | mViewManager->setSelected( "", false); |
2322 | mViewManager->refreshView( "" ); | 2322 | mViewManager->refreshView( "" ); |
2323 | mViewManager->setSelected( foundUid, true ); | 2323 | mViewManager->setSelected( foundUid, true ); |
2324 | mViewManager->refreshView( foundUid ); | 2324 | mViewManager->refreshView( foundUid ); |
2325 | 2325 | ||
2326 | if ( !mMultipleViewsAtOnce ) | 2326 | if ( !mMultipleViewsAtOnce ) |
2327 | { | 2327 | { |
2328 | setDetailsVisible( true ); | 2328 | setDetailsVisible( true ); |
2329 | mActionDetails->setChecked(true); | 2329 | mActionDetails->setChecked(true); |
2330 | } | 2330 | } |
2331 | } | 2331 | } |
2332 | } | 2332 | } |
2333 | 2333 | ||
2334 | 2334 | ||
2335 | void KABCore::faq() | 2335 | void KABCore::faq() |
2336 | { | 2336 | { |
2337 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); | 2337 | KApplication::showFile( "KA/Pi FAQ", "kdepim/kaddressbook/kapiFAQ.txt" ); |
2338 | } | 2338 | } |
2339 | 2339 | ||
2340 | #include <libkcal/syncdefines.h> | 2340 | #include <libkcal/syncdefines.h> |
2341 | 2341 | ||
2342 | KABC::Addressee KABCore::getLastSyncAddressee() | 2342 | KABC::Addressee KABCore::getLastSyncAddressee() |
2343 | { | 2343 | { |
2344 | Addressee lse; | 2344 | Addressee lse; |
2345 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2345 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2346 | 2346 | ||
2347 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); | 2347 | //qDebug("CurrentSyncDevice %s ",mCurrentSyncDevice .latin1() ); |
2348 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2348 | lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2349 | if (lse.isEmpty()) { | 2349 | if (lse.isEmpty()) { |
2350 | qDebug("Creating new last-syncAddressee "); | 2350 | qDebug("Creating new last-syncAddressee "); |
2351 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2351 | lse.setUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2352 | QString sum = ""; | 2352 | QString sum = ""; |
2353 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) | 2353 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) |
2354 | sum = "E: "; | 2354 | sum = "E: "; |
2355 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); | 2355 | lse.setFamilyName("!"+sum+mCurrentSyncDevice + i18n(" - sync event")); |
2356 | lse.setRevision( mLastAddressbookSync ); | 2356 | lse.setRevision( mLastAddressbookSync ); |
2357 | lse.setCategories( i18n("SyncEvent") ); | 2357 | lse.setCategories( i18n("SyncEvent") ); |
2358 | mAddressBook->insertAddressee( lse ); | 2358 | mAddressBook->insertAddressee( lse ); |
2359 | } | 2359 | } |
2360 | return lse; | 2360 | return lse; |
2361 | } | 2361 | } |
2362 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) | 2362 | int KABCore::takeAddressee( KABC::Addressee* local, KABC::Addressee* remote, int mode , bool full ) |
2363 | { | 2363 | { |
2364 | 2364 | ||
2365 | //void setZaurusId(int id); | 2365 | //void setZaurusId(int id); |
2366 | // int zaurusId() const; | 2366 | // int zaurusId() const; |
2367 | // void setZaurusUid(int id); | 2367 | // void setZaurusUid(int id); |
2368 | // int zaurusUid() const; | 2368 | // int zaurusUid() const; |
2369 | // void setZaurusStat(int id); | 2369 | // void setZaurusStat(int id); |
2370 | // int zaurusStat() const; | 2370 | // int zaurusStat() const; |
2371 | // 0 equal | 2371 | // 0 equal |
2372 | // 1 take local | 2372 | // 1 take local |
2373 | // 2 take remote | 2373 | // 2 take remote |
2374 | // 3 cancel | 2374 | // 3 cancel |
2375 | QDateTime lastSync = mLastAddressbookSync; | 2375 | QDateTime lastSync = mLastAddressbookSync; |
2376 | QDateTime localMod = local->revision(); | 2376 | QDateTime localMod = local->revision(); |
2377 | QDateTime remoteMod = remote->revision(); | 2377 | QDateTime remoteMod = remote->revision(); |
2378 | 2378 | ||
2379 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2379 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2380 | 2380 | ||
2381 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2381 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2382 | bool remCh, locCh; | 2382 | bool remCh, locCh; |
2383 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); | 2383 | remCh = ( remote->getCsum(mCurrentSyncDevice) != local->getCsum(mCurrentSyncDevice) ); |
2384 | 2384 | ||
2385 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); | 2385 | //qDebug("loc %s rem %s", local->getCsum(mCurrentSyncDevice).latin1(), remote->getCsum(mCurrentSyncDevice).latin1() ); |
2386 | locCh = ( localMod > mLastAddressbookSync ); | 2386 | locCh = ( localMod > mLastAddressbookSync ); |
2387 | if ( !remCh && ! locCh ) { | 2387 | if ( !remCh && ! locCh ) { |
2388 | //qDebug("both not changed "); | 2388 | //qDebug("both not changed "); |
2389 | lastSync = localMod.addDays(1); | 2389 | lastSync = localMod.addDays(1); |
2390 | if ( mode <= SYNC_PREF_ASK ) | 2390 | if ( mode <= SYNC_PREF_ASK ) |
2391 | return 0; | 2391 | return 0; |
2392 | } else { | 2392 | } else { |
2393 | if ( locCh ) { | 2393 | if ( locCh ) { |
2394 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); | 2394 | //qDebug("loc changed %s %s", localMod.toString().latin1(), mLastAddressbookSync.toString().latin1()); |
2395 | lastSync = localMod.addDays( -1 ); | 2395 | lastSync = localMod.addDays( -1 ); |
2396 | if ( !remCh ) | 2396 | if ( !remCh ) |
2397 | remoteMod =( lastSync.addDays( -1 ) ); | 2397 | remoteMod =( lastSync.addDays( -1 ) ); |
2398 | } else { | 2398 | } else { |
2399 | //qDebug(" not loc changed "); | 2399 | //qDebug(" not loc changed "); |
2400 | lastSync = localMod.addDays( 1 ); | 2400 | lastSync = localMod.addDays( 1 ); |
2401 | if ( remCh ) | 2401 | if ( remCh ) |
2402 | remoteMod =( lastSync.addDays( 1 ) ); | 2402 | remoteMod =( lastSync.addDays( 1 ) ); |
2403 | 2403 | ||
2404 | } | 2404 | } |
2405 | } | 2405 | } |
2406 | full = true; | 2406 | full = true; |
2407 | if ( mode < SYNC_PREF_ASK ) | 2407 | if ( mode < SYNC_PREF_ASK ) |
2408 | mode = SYNC_PREF_ASK; | 2408 | mode = SYNC_PREF_ASK; |
2409 | } else { | 2409 | } else { |
2410 | if ( localMod == remoteMod ) | 2410 | if ( localMod == remoteMod ) |
2411 | return 0; | 2411 | return 0; |
2412 | 2412 | ||
2413 | } | 2413 | } |
2414 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); | 2414 | // qDebug(" %d %d conflict on %s %s ", mode, full, local->summary().latin1(), remote->summary().latin1() ); |
2415 | 2415 | ||
2416 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); | 2416 | //qDebug("%s %d %s %d", local->lastModified().toString().latin1() , localMod, remote->lastModified().toString().latin1(), remoteMod); |
2417 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); | 2417 | //qDebug("%d %d %d %d ", local->lastModified().time().second(), local->lastModified().time().msec(), remote->lastModified().time().second(), remote->lastModified().time().msec() ); |
2418 | //full = true; //debug only | 2418 | //full = true; //debug only |
2419 | if ( full ) { | 2419 | if ( full ) { |
2420 | bool equ = ( (*local) == (*remote) ); | 2420 | bool equ = ( (*local) == (*remote) ); |
2421 | if ( equ ) { | 2421 | if ( equ ) { |
2422 | //qDebug("equal "); | 2422 | //qDebug("equal "); |
2423 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2423 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2424 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); | 2424 | local->setCsum( mCurrentSyncDevice, remote->getCsum(mCurrentSyncDevice) ); |
2425 | } | 2425 | } |
2426 | if ( mode < SYNC_PREF_FORCE_LOCAL ) | 2426 | if ( mode < SYNC_PREF_FORCE_LOCAL ) |
2427 | return 0; | 2427 | return 0; |
2428 | 2428 | ||
2429 | }//else //debug only | 2429 | }//else //debug only |
2430 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); | 2430 | //qDebug("not equal %s %s ", local->summary().latin1(), remote->summary().latin1()); |
2431 | } | 2431 | } |
2432 | int result; | 2432 | int result; |
2433 | bool localIsNew; | 2433 | bool localIsNew; |
2434 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); | 2434 | //qDebug("%s -- %s mLastCalendarSync %s lastsync %s --- local %s remote %s ",local->summary().latin1(), remote->summary().latin1(),mLastCalendarSync.toString().latin1() ,lastSync.toString().latin1() , local->lastModified().toString().latin1() , remote->lastModified().toString().latin1() ); |
2435 | 2435 | ||
2436 | if ( full && mode < SYNC_PREF_NEWEST ) | 2436 | if ( full && mode < SYNC_PREF_NEWEST ) |
2437 | mode = SYNC_PREF_ASK; | 2437 | mode = SYNC_PREF_ASK; |
2438 | 2438 | ||
2439 | switch( mode ) { | 2439 | switch( mode ) { |
2440 | case SYNC_PREF_LOCAL: | 2440 | case SYNC_PREF_LOCAL: |
2441 | if ( lastSync > remoteMod ) | 2441 | if ( lastSync > remoteMod ) |
2442 | return 1; | 2442 | return 1; |
2443 | if ( lastSync > localMod ) | 2443 | if ( lastSync > localMod ) |
2444 | return 2; | 2444 | return 2; |
2445 | return 1; | 2445 | return 1; |
2446 | break; | 2446 | break; |
2447 | case SYNC_PREF_REMOTE: | 2447 | case SYNC_PREF_REMOTE: |
2448 | if ( lastSync > remoteMod ) | 2448 | if ( lastSync > remoteMod ) |
2449 | return 1; | 2449 | return 1; |
2450 | if ( lastSync > localMod ) | 2450 | if ( lastSync > localMod ) |
2451 | return 2; | 2451 | return 2; |
2452 | return 2; | 2452 | return 2; |
2453 | break; | 2453 | break; |
2454 | case SYNC_PREF_NEWEST: | 2454 | case SYNC_PREF_NEWEST: |
2455 | if ( localMod > remoteMod ) | 2455 | if ( localMod > remoteMod ) |
2456 | return 1; | 2456 | return 1; |
2457 | else | 2457 | else |
2458 | return 2; | 2458 | return 2; |
2459 | break; | 2459 | break; |
2460 | case SYNC_PREF_ASK: | 2460 | case SYNC_PREF_ASK: |
2461 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); | 2461 | //qDebug("lsy %s --- lo %s --- re %s ", lastSync.toString().latin1(), localMod.toString().latin1(), remoteMod.toString().latin1() ); |
2462 | if ( lastSync > remoteMod ) | 2462 | if ( lastSync > remoteMod ) |
2463 | return 1; | 2463 | return 1; |
2464 | if ( lastSync > localMod ) | 2464 | if ( lastSync > localMod ) |
2465 | return 2; | 2465 | return 2; |
2466 | localIsNew = localMod >= remoteMod; | 2466 | localIsNew = localMod >= remoteMod; |
2467 | //qDebug("conflict! ************************************** "); | 2467 | //qDebug("conflict! ************************************** "); |
2468 | { | 2468 | { |
2469 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); | 2469 | KPIM::AddresseeChooser acd ( *local,*remote, localIsNew , this ); |
2470 | result = acd.executeD(localIsNew); | 2470 | result = acd.executeD(localIsNew); |
2471 | return result; | 2471 | return result; |
2472 | } | 2472 | } |
2473 | break; | 2473 | break; |
2474 | case SYNC_PREF_FORCE_LOCAL: | 2474 | case SYNC_PREF_FORCE_LOCAL: |
2475 | return 1; | 2475 | return 1; |
2476 | break; | 2476 | break; |
2477 | case SYNC_PREF_FORCE_REMOTE: | 2477 | case SYNC_PREF_FORCE_REMOTE: |
2478 | return 2; | 2478 | return 2; |
2479 | break; | 2479 | break; |
2480 | 2480 | ||
2481 | default: | 2481 | default: |
2482 | // SYNC_PREF_TAKE_BOTH not implemented | 2482 | // SYNC_PREF_TAKE_BOTH not implemented |
2483 | break; | 2483 | break; |
2484 | } | 2484 | } |
2485 | return 0; | 2485 | return 0; |
2486 | } | 2486 | } |
2487 | 2487 | ||
2488 | 2488 | ||
2489 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) | 2489 | bool KABCore::synchronizeAddressbooks( KABC::AddressBook* local, KABC::AddressBook* remote,int mode) |
2490 | { | 2490 | { |
2491 | bool syncOK = true; | 2491 | bool syncOK = true; |
2492 | int addedAddressee = 0; | 2492 | int addedAddressee = 0; |
2493 | int addedAddresseeR = 0; | 2493 | int addedAddresseeR = 0; |
2494 | int deletedAddresseeR = 0; | 2494 | int deletedAddresseeR = 0; |
2495 | int deletedAddresseeL = 0; | 2495 | int deletedAddresseeL = 0; |
2496 | int changedLocal = 0; | 2496 | int changedLocal = 0; |
2497 | int changedRemote = 0; | 2497 | int changedRemote = 0; |
2498 | 2498 | ||
2499 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); | 2499 | QString mCurrentSyncName = syncManager->getCurrentSyncName(); |
2500 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); | 2500 | QString mCurrentSyncDevice = syncManager->getCurrentSyncDevice(); |
2501 | 2501 | ||
2502 | //QPtrList<Addressee> el = local->rawAddressees(); | 2502 | //QPtrList<Addressee> el = local->rawAddressees(); |
2503 | Addressee addresseeR; | 2503 | Addressee addresseeR; |
2504 | QString uid; | 2504 | QString uid; |
2505 | int take; | 2505 | int take; |
2506 | Addressee addresseeL; | 2506 | Addressee addresseeL; |
2507 | Addressee addresseeRSync; | 2507 | Addressee addresseeRSync; |
2508 | Addressee addresseeLSync; | 2508 | Addressee addresseeLSync; |
2509 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); | 2509 | // KABC::Addressee::List addresseeRSyncSharp = remote->getExternLastSyncAddressees(); |
2510 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); | 2510 | //KABC::Addressee::List addresseeLSyncSharp = local->getExternLastSyncAddressees(); |
2511 | bool fullDateRange = false; | 2511 | bool fullDateRange = false; |
2512 | local->resetTempSyncStat(); | 2512 | local->resetTempSyncStat(); |
2513 | mLastAddressbookSync = QDateTime::currentDateTime(); | 2513 | mLastAddressbookSync = QDateTime::currentDateTime(); |
2514 | QDateTime modifiedCalendar = mLastAddressbookSync;; | 2514 | QDateTime modifiedCalendar = mLastAddressbookSync;; |
2515 | addresseeLSync = getLastSyncAddressee(); | 2515 | addresseeLSync = getLastSyncAddressee(); |
2516 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); | 2516 | qDebug("Last Sync %s ", addresseeLSync.revision().toString().latin1()); |
2517 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); | 2517 | addresseeR = remote->findByUid("last-syncAddressee-"+mCurrentSyncName ); |
2518 | if ( !addresseeR.isEmpty() ) { | 2518 | if ( !addresseeR.isEmpty() ) { |
2519 | addresseeRSync = addresseeR; | 2519 | addresseeRSync = addresseeR; |
2520 | remote->removeAddressee(addresseeR ); | 2520 | remote->removeAddressee(addresseeR ); |
2521 | 2521 | ||
2522 | } else { | 2522 | } else { |
2523 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2523 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2524 | addresseeRSync = addresseeLSync ; | 2524 | addresseeRSync = addresseeLSync ; |
2525 | } else { | 2525 | } else { |
2526 | qDebug("FULLDATE 1"); | 2526 | qDebug("FULLDATE 1"); |
2527 | fullDateRange = true; | 2527 | fullDateRange = true; |
2528 | Addressee newAdd; | 2528 | Addressee newAdd; |
2529 | addresseeRSync = newAdd; | 2529 | addresseeRSync = newAdd; |
2530 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); | 2530 | addresseeRSync.setFamilyName(mCurrentSyncName + i18n(" - sync addressee")); |
2531 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); | 2531 | addresseeRSync.setUid("last-syncAddressee-"+mCurrentSyncName ); |
2532 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2532 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2533 | addresseeRSync.setCategories( i18n("SyncAddressee") ); | 2533 | addresseeRSync.setCategories( i18n("SyncAddressee") ); |
2534 | } | 2534 | } |
2535 | } | 2535 | } |
2536 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { | 2536 | if ( addresseeLSync.revision() == mLastAddressbookSync ) { |
2537 | qDebug("FULLDATE 2"); | 2537 | qDebug("FULLDATE 2"); |
2538 | fullDateRange = true; | 2538 | fullDateRange = true; |
2539 | } | 2539 | } |
2540 | if ( ! fullDateRange ) { | 2540 | if ( ! fullDateRange ) { |
2541 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { | 2541 | if ( addresseeLSync.revision() != addresseeRSync.revision() ) { |
2542 | 2542 | ||
2543 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); | 2543 | // qDebug("set fulldate to true %s %s" ,addresseeLSync->dtStart().toString().latin1(), addresseeRSync->dtStart().toString().latin1() ); |
2544 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); | 2544 | //qDebug("%d %d %d %d ", addresseeLSync->dtStart().time().second(), addresseeLSync->dtStart().time().msec() , addresseeRSync->dtStart().time().second(), addresseeRSync->dtStart().time().msec()); |
2545 | fullDateRange = true; | 2545 | fullDateRange = true; |
2546 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); | 2546 | qDebug("FULLDATE 3 %s %s", addresseeLSync.revision().toString().latin1() , addresseeRSync.revision().toString().latin1() ); |
2547 | } | 2547 | } |
2548 | } | 2548 | } |
2549 | // fullDateRange = true; // debug only! | 2549 | // fullDateRange = true; // debug only! |
2550 | if ( fullDateRange ) | 2550 | if ( fullDateRange ) |
2551 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); | 2551 | mLastAddressbookSync = QDateTime::currentDateTime().addDays( -100*365); |
2552 | else | 2552 | else |
2553 | mLastAddressbookSync = addresseeLSync.revision(); | 2553 | mLastAddressbookSync = addresseeLSync.revision(); |
2554 | // for resyncing if own file has changed | 2554 | // for resyncing if own file has changed |
2555 | // PENDING fixme later when implemented | 2555 | // PENDING fixme later when implemented |
2556 | #if 0 | 2556 | #if 0 |
2557 | if ( mCurrentSyncDevice == "deleteaftersync" ) { | 2557 | if ( mCurrentSyncDevice == "deleteaftersync" ) { |
2558 | mLastAddressbookSync = loadedFileVersion; | 2558 | mLastAddressbookSync = loadedFileVersion; |
2559 | qDebug("setting mLastAddressbookSync "); | 2559 | qDebug("setting mLastAddressbookSync "); |
2560 | } | 2560 | } |
2561 | #endif | 2561 | #endif |
2562 | 2562 | ||
2563 | //qDebug("*************************** "); | 2563 | //qDebug("*************************** "); |
2564 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); | 2564 | // qDebug("mLastAddressbookSync %s ",mLastAddressbookSync.toString().latin1() ); |
2565 | QStringList er = remote->uidList(); | 2565 | QStringList er = remote->uidList(); |
2566 | Addressee inR ;//= er.first(); | 2566 | Addressee inR ;//= er.first(); |
2567 | Addressee inL; | 2567 | Addressee inL; |
2568 | 2568 | ||
2569 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); | 2569 | syncManager->showProgressBar(0, i18n("Syncing - close to abort!"), er.count()); |
2570 | 2570 | ||
2571 | int modulo = (er.count()/10)+1; | 2571 | int modulo = (er.count()/10)+1; |
2572 | int incCounter = 0; | 2572 | int incCounter = 0; |
2573 | while ( incCounter < er.count()) { | 2573 | while ( incCounter < er.count()) { |
2574 | if (syncManager->isProgressBarCanceled()) | 2574 | if (syncManager->isProgressBarCanceled()) |
2575 | return false; | 2575 | return false; |
2576 | if ( incCounter % modulo == 0 ) | 2576 | if ( incCounter % modulo == 0 ) |
2577 | syncManager->showProgressBar(incCounter); | 2577 | syncManager->showProgressBar(incCounter); |
2578 | 2578 | ||
2579 | uid = er[ incCounter ]; | 2579 | uid = er[ incCounter ]; |
2580 | bool skipIncidence = false; | 2580 | bool skipIncidence = false; |
2581 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2581 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2582 | skipIncidence = true; | 2582 | skipIncidence = true; |
2583 | QString idS,OidS; | 2583 | QString idS,OidS; |
2584 | qApp->processEvents(); | 2584 | qApp->processEvents(); |
2585 | if ( !skipIncidence ) { | 2585 | if ( !skipIncidence ) { |
2586 | inL = local->findByUid( uid ); | 2586 | inL = local->findByUid( uid ); |
2587 | inR = remote->findByUid( uid ); | 2587 | inR = remote->findByUid( uid ); |
2588 | //inL.setResource( 0 ); | 2588 | //inL.setResource( 0 ); |
2589 | //inR.setResource( 0 ); | 2589 | //inR.setResource( 0 ); |
2590 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars | 2590 | if ( !inL.isEmpty() ) { // maybe conflict - same uid in both calendars |
2591 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { | 2591 | if ( take = takeAddressee( &inL, &inR, mode, fullDateRange ) ) { |
2592 | //qDebug("take %d %s ", take, inL.summary().latin1()); | 2592 | //qDebug("take %d %s ", take, inL.summary().latin1()); |
2593 | if ( take == 3 ) | 2593 | if ( take == 3 ) |
2594 | return false; | 2594 | return false; |
2595 | if ( take == 1 ) {// take local | 2595 | if ( take == 1 ) {// take local |
2596 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2596 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2597 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2597 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2598 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2598 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2599 | local->insertAddressee( inL, false ); | 2599 | local->insertAddressee( inL, false ); |
2600 | idS = inR.externalUID(); | 2600 | idS = inR.externalUID(); |
2601 | OidS = inR.originalExternalUID(); | 2601 | OidS = inR.originalExternalUID(); |
2602 | } | 2602 | } |
2603 | else | 2603 | else |
2604 | idS = inR.IDStr(); | 2604 | idS = inR.IDStr(); |
2605 | remote->removeAddressee( inR ); | 2605 | remote->removeAddressee( inR ); |
2606 | inR = inL; | 2606 | inR = inL; |
2607 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); | 2607 | inR.setTempSyncStat( SYNC_TEMPSTATE_INITIAL ); |
2608 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2608 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2609 | inR.setOriginalExternalUID( OidS ); | 2609 | inR.setOriginalExternalUID( OidS ); |
2610 | inR.setExternalUID( idS ); | 2610 | inR.setExternalUID( idS ); |
2611 | } else { | 2611 | } else { |
2612 | inR.setIDStr( idS ); | 2612 | inR.setIDStr( idS ); |
2613 | } | 2613 | } |
2614 | inR.setResource( 0 ); | 2614 | inR.setResource( 0 ); |
2615 | remote->insertAddressee( inR , false); | 2615 | remote->insertAddressee( inR , false); |
2616 | ++changedRemote; | 2616 | ++changedRemote; |
2617 | } else { // take == 2 take remote | 2617 | } else { // take == 2 take remote |
2618 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2618 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2619 | if ( inR.revision().date().year() < 2004 ) | 2619 | if ( inR.revision().date().year() < 2004 ) |
2620 | inR.setRevision( modifiedCalendar ); | 2620 | inR.setRevision( modifiedCalendar ); |
2621 | } | 2621 | } |
2622 | idS = inL.IDStr(); | 2622 | idS = inL.IDStr(); |
2623 | local->removeAddressee( inL ); | 2623 | local->removeAddressee( inL ); |
2624 | inL = inR; | 2624 | inL = inR; |
2625 | inL.setIDStr( idS ); | 2625 | inL.setIDStr( idS ); |
2626 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2626 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2627 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); | 2627 | inL.setCsum( mCurrentSyncDevice, inR.getCsum(mCurrentSyncDevice) ); |
2628 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); | 2628 | inL.setID( mCurrentSyncDevice, inR.getID(mCurrentSyncDevice) ); |
2629 | } | 2629 | } |
2630 | inL.setResource( 0 ); | 2630 | inL.setResource( 0 ); |
2631 | local->insertAddressee( inL , false ); | 2631 | local->insertAddressee( inL , false ); |
2632 | ++changedLocal; | 2632 | ++changedLocal; |
2633 | } | 2633 | } |
2634 | } | 2634 | } |
2635 | } else { // no conflict | 2635 | } else { // no conflict |
2636 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2636 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2637 | QString des = addresseeLSync.note(); | 2637 | QString des = addresseeLSync.note(); |
2638 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it | 2638 | if ( des.find( inR.getID(mCurrentSyncDevice) +"," ) >= 0 && mode != 5) { // delete it |
2639 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); | 2639 | inR.setTempSyncStat( SYNC_TEMPSTATE_DELETE ); |
2640 | remote->insertAddressee( inR, false ); | 2640 | remote->insertAddressee( inR, false ); |
2641 | ++deletedAddresseeR; | 2641 | ++deletedAddresseeR; |
2642 | } else { | 2642 | } else { |
2643 | inR.setRevision( modifiedCalendar ); | 2643 | inR.setRevision( modifiedCalendar ); |
2644 | remote->insertAddressee( inR, false ); | 2644 | remote->insertAddressee( inR, false ); |
2645 | inL = inR; | 2645 | inL = inR; |
2646 | inL.setResource( 0 ); | 2646 | inL.setResource( 0 ); |
2647 | local->insertAddressee( inL , false); | 2647 | local->insertAddressee( inL , false); |
2648 | ++addedAddressee; | 2648 | ++addedAddressee; |
2649 | } | 2649 | } |
2650 | } else { | 2650 | } else { |
2651 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { | 2651 | if ( inR.revision() > mLastAddressbookSync || mode == 5 ) { |
2652 | inR.setRevision( modifiedCalendar ); | 2652 | inR.setRevision( modifiedCalendar ); |
2653 | remote->insertAddressee( inR, false ); | 2653 | remote->insertAddressee( inR, false ); |
2654 | inR.setResource( 0 ); | 2654 | inR.setResource( 0 ); |
2655 | local->insertAddressee( inR, false ); | 2655 | local->insertAddressee( inR, false ); |
2656 | ++addedAddressee; | 2656 | ++addedAddressee; |
2657 | } else { | 2657 | } else { |
2658 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); | 2658 | // pending checkExternSyncAddressee(addresseeRSyncSharp, inR); |
2659 | remote->removeAddressee( inR ); | 2659 | remote->removeAddressee( inR ); |
2660 | ++deletedAddresseeR; | 2660 | ++deletedAddresseeR; |
2661 | } | 2661 | } |
2662 | } | 2662 | } |
2663 | } | 2663 | } |
2664 | } | 2664 | } |
2665 | ++incCounter; | 2665 | ++incCounter; |
2666 | } | 2666 | } |
2667 | er.clear(); | 2667 | er.clear(); |
2668 | QStringList el = local->uidList(); | 2668 | QStringList el = local->uidList(); |
2669 | modulo = (el.count()/10)+1; | 2669 | modulo = (el.count()/10)+1; |
2670 | 2670 | ||
2671 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); | 2671 | syncManager->showProgressBar(0, i18n("Add / remove addressees"), el.count()); |
2672 | incCounter = 0; | 2672 | incCounter = 0; |
2673 | while ( incCounter < el.count()) { | 2673 | while ( incCounter < el.count()) { |
2674 | qApp->processEvents(); | 2674 | qApp->processEvents(); |
2675 | if (syncManager->isProgressBarCanceled()) | 2675 | if (syncManager->isProgressBarCanceled()) |
2676 | return false; | 2676 | return false; |
2677 | if ( incCounter % modulo == 0 ) | 2677 | if ( incCounter % modulo == 0 ) |
2678 | syncManager->showProgressBar(incCounter); | 2678 | syncManager->showProgressBar(incCounter); |
2679 | uid = el[ incCounter ]; | 2679 | uid = el[ incCounter ]; |
2680 | bool skipIncidence = false; | 2680 | bool skipIncidence = false; |
2681 | if ( uid.left(19) == QString("last-syncAddressee-") ) | 2681 | if ( uid.left(19) == QString("last-syncAddressee-") ) |
2682 | skipIncidence = true; | 2682 | skipIncidence = true; |
2683 | if ( !skipIncidence ) { | 2683 | if ( !skipIncidence ) { |
2684 | inL = local->findByUid( uid ); | 2684 | inL = local->findByUid( uid ); |
2685 | inR = remote->findByUid( uid ); | 2685 | inR = remote->findByUid( uid ); |
2686 | if ( inR.isEmpty() ) { | 2686 | if ( inR.isEmpty() ) { |
2687 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { | 2687 | if ( mGlobalSyncMode == SYNC_MODE_EXTERNAL ) { |
2688 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { | 2688 | if ( !inL.getID(mCurrentSyncDevice).isEmpty() && mode != 4 ) { |
2689 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2689 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2690 | local->removeAddressee( inL ); | 2690 | local->removeAddressee( inL ); |
2691 | ++deletedAddresseeL; | 2691 | ++deletedAddresseeL; |
2692 | } else { | 2692 | } else { |
2693 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2693 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2694 | inL.removeID(mCurrentSyncDevice ); | 2694 | inL.removeID(mCurrentSyncDevice ); |
2695 | ++addedAddresseeR; | 2695 | ++addedAddresseeR; |
2696 | inL.setRevision( modifiedCalendar ); | 2696 | inL.setRevision( modifiedCalendar ); |
2697 | local->insertAddressee( inL, false ); | 2697 | local->insertAddressee( inL, false ); |
2698 | inR = inL; | 2698 | inR = inL; |
2699 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); | 2699 | inR.setTempSyncStat( SYNC_TEMPSTATE_ADDED_EXTERNAL ); |
2700 | inR.setResource( 0 ); | 2700 | inR.setResource( 0 ); |
2701 | remote->insertAddressee( inR, false ); | 2701 | remote->insertAddressee( inR, false ); |
2702 | } | 2702 | } |
2703 | } | 2703 | } |
2704 | } else { | 2704 | } else { |
2705 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { | 2705 | if ( inL.revision() < mLastAddressbookSync && mode != 4 ) { |
2706 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); | 2706 | // pending checkExternSyncAddressee(addresseeLSyncSharp, inL); |
2707 | local->removeAddressee( inL ); | 2707 | local->removeAddressee( inL ); |
2708 | ++deletedAddresseeL; | 2708 | ++deletedAddresseeL; |
2709 | } else { | 2709 | } else { |
2710 | if ( ! syncManager->mWriteBackExistingOnly ) { | 2710 | if ( ! syncManager->mWriteBackExistingOnly ) { |
2711 | ++addedAddresseeR; | 2711 | ++addedAddresseeR; |
2712 | inL.setRevision( modifiedCalendar ); | 2712 | inL.setRevision( modifiedCalendar ); |
2713 | local->insertAddressee( inL, false ); | 2713 | local->insertAddressee( inL, false ); |
2714 | inR = inL; | 2714 | inR = inL; |
2715 | inR.setResource( 0 ); | 2715 | inR.setResource( 0 ); |
2716 | remote->insertAddressee( inR, false ); | 2716 | remote->insertAddressee( inR, false ); |
2717 | } | 2717 | } |
2718 | } | 2718 | } |
2719 | } | 2719 | } |
2720 | } | 2720 | } |
2721 | } | 2721 | } |
2722 | ++incCounter; | 2722 | ++incCounter; |
2723 | } | 2723 | } |
2724 | el.clear(); | 2724 | el.clear(); |
2725 | syncManager->hideProgressBar(); | 2725 | syncManager->hideProgressBar(); |
2726 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); | 2726 | mLastAddressbookSync = QDateTime::currentDateTime().addSecs( 1 ); |
2727 | // get rid of micro seconds | 2727 | // get rid of micro seconds |
2728 | QTime t = mLastAddressbookSync.time(); | 2728 | QTime t = mLastAddressbookSync.time(); |
2729 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 2729 | mLastAddressbookSync.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
2730 | addresseeLSync.setRevision( mLastAddressbookSync ); | 2730 | addresseeLSync.setRevision( mLastAddressbookSync ); |
2731 | addresseeRSync.setRevision( mLastAddressbookSync ); | 2731 | addresseeRSync.setRevision( mLastAddressbookSync ); |
2732 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; | 2732 | addresseeRSync.setRole( i18n("!Remote from: ")+mCurrentSyncName ) ; |
2733 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); | 2733 | addresseeLSync.setRole(i18n("!Local from: ") + mCurrentSyncName ); |
2734 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; | 2734 | addresseeRSync.setGivenName( i18n("!DO NOT EDIT!") ) ; |
2735 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); | 2735 | addresseeLSync.setGivenName(i18n("!DO NOT EDIT!") ); |
2736 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; | 2736 | addresseeRSync.setOrganization( "!"+mLastAddressbookSync.toString() ) ; |
2737 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); | 2737 | addresseeLSync.setOrganization("!"+ mLastAddressbookSync.toString() ); |
2738 | addresseeRSync.setNote( "" ) ; | 2738 | addresseeRSync.setNote( "" ) ; |
2739 | addresseeLSync.setNote( "" ); | 2739 | addresseeLSync.setNote( "" ); |
2740 | 2740 | ||
2741 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) | 2741 | if ( mGlobalSyncMode == SYNC_MODE_NORMAL) |
2742 | remote->insertAddressee( addresseeRSync, false ); | 2742 | remote->insertAddressee( addresseeRSync, false ); |
2743 | local->insertAddressee( addresseeLSync, false ); | 2743 | local->insertAddressee( addresseeLSync, false ); |
2744 | QString mes; | 2744 | QString mes; |
2745 | 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 ); | 2745 | 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 ); |
2746 | if ( syncManager->mShowSyncSummary ) { | 2746 | if ( syncManager->mShowSyncSummary ) { |
2747 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); | 2747 | KMessageBox::information(this, mes, i18n("KA/Pi Synchronization") ); |
2748 | } | 2748 | } |
2749 | qDebug( mes ); | 2749 | qDebug( mes ); |
2750 | return syncOK; | 2750 | return syncOK; |
2751 | } | 2751 | } |
2752 | 2752 | ||
2753 | 2753 | ||
2754 | //this is a overwritten callbackmethods from the syncinterface | 2754 | //this is a overwritten callbackmethods from the syncinterface |
2755 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) | 2755 | bool KABCore::sync(KSyncManager* manager, QString filename, int mode) |
2756 | { | 2756 | { |
2757 | 2757 | ||
2758 | //pending prepare addresseeview for output | 2758 | //pending prepare addresseeview for output |
2759 | //pending detect, if remote file has REV field. if not switch to external sync | 2759 | //pending detect, if remote file has REV field. if not switch to external sync |
2760 | mGlobalSyncMode = SYNC_MODE_NORMAL; | 2760 | mGlobalSyncMode = SYNC_MODE_NORMAL; |
2761 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2761 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2762 | 2762 | ||
2763 | AddressBook abLocal(filename,"syncContact"); | 2763 | AddressBook abLocal(filename,"syncContact"); |
2764 | bool syncOK = false; | 2764 | bool syncOK = false; |
2765 | if ( abLocal.load() ) { | 2765 | if ( abLocal.load() ) { |
2766 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); | 2766 | qDebug("AB loaded %s,sync mode %d",filename.latin1(), mode ); |
2767 | bool external = false; | 2767 | bool external = false; |
2768 | bool isXML = false; | 2768 | bool isXML = false; |
2769 | if ( filename.right(4) == ".xml") { | 2769 | if ( filename.right(4) == ".xml") { |
2770 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2770 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2771 | isXML = true; | 2771 | isXML = true; |
2772 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2772 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2773 | } else { | 2773 | } else { |
2774 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); | 2774 | Addressee lse = mAddressBook->findByUid( "last-syncAddressee-"+mCurrentSyncDevice ); |
2775 | if ( ! lse.isEmpty() ) { | 2775 | if ( ! lse.isEmpty() ) { |
2776 | if ( lse.familyName().left(4) == "!E: " ) | 2776 | if ( lse.familyName().left(4) == "!E: " ) |
2777 | external = true; | 2777 | external = true; |
2778 | } else { | 2778 | } else { |
2779 | bool found = false; | 2779 | bool found = false; |
2780 | AddressBook::Iterator it; | 2780 | AddressBook::Iterator it; |
2781 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2781 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2782 | if ( (*it).revision().date().year() > 2003 ) { | 2782 | if ( (*it).revision().date().year() > 2003 ) { |
2783 | found = true; | 2783 | found = true; |
2784 | break; | 2784 | break; |
2785 | } | 2785 | } |
2786 | } | 2786 | } |
2787 | external = ! found; | 2787 | external = ! found; |
2788 | } | 2788 | } |
2789 | 2789 | ||
2790 | if ( external ) { | 2790 | if ( external ) { |
2791 | qDebug("Setting vcf mode to external "); | 2791 | qDebug("Setting vcf mode to external "); |
2792 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2792 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2793 | AddressBook::Iterator it; | 2793 | AddressBook::Iterator it; |
2794 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2794 | for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2795 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); | 2795 | (*it).setID( mCurrentSyncDevice, (*it).uid() ); |
2796 | (*it).computeCsum( mCurrentSyncDevice ); | 2796 | (*it).computeCsum( mCurrentSyncDevice ); |
2797 | } | 2797 | } |
2798 | } | 2798 | } |
2799 | } | 2799 | } |
2800 | //AddressBook::Iterator it; | 2800 | //AddressBook::Iterator it; |
2801 | //QStringList vcards; | 2801 | //QStringList vcards; |
2802 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { | 2802 | //for ( it = abLocal.begin(); it != abLocal.end(); ++it ) { |
2803 | // qDebug("Name %s ", (*it).familyName().latin1()); | 2803 | // qDebug("Name %s ", (*it).familyName().latin1()); |
2804 | //} | 2804 | //} |
2805 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); | 2805 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, mode ); |
2806 | if ( syncOK ) { | 2806 | if ( syncOK ) { |
2807 | if ( syncManager->mWriteBackFile ) | 2807 | if ( syncManager->mWriteBackFile ) |
2808 | { | 2808 | { |
2809 | if ( external ) | 2809 | if ( external ) |
2810 | abLocal.removeSyncAddressees( !isXML); | 2810 | abLocal.removeSyncAddressees( !isXML); |
2811 | qDebug("Saving remote AB "); | 2811 | qDebug("Saving remote AB "); |
2812 | abLocal.saveAB(); | 2812 | if ( ! abLocal.saveAB()) |
2813 | qDebug("Error writing back AB to file "); | ||
2813 | if ( isXML ) { | 2814 | if ( isXML ) { |
2814 | // afterwrite processing | 2815 | // afterwrite processing |
2815 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2816 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2816 | } | 2817 | } |
2817 | } | 2818 | } |
2818 | } | 2819 | } |
2819 | setModified(); | 2820 | setModified(); |
2820 | 2821 | ||
2821 | } | 2822 | } |
2822 | if ( syncOK ) | 2823 | if ( syncOK ) |
2823 | mViewManager->refreshView(); | 2824 | mViewManager->refreshView(); |
2824 | return syncOK; | 2825 | return syncOK; |
2825 | #if 0 | 2826 | #if 0 |
2826 | 2827 | ||
2827 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { | 2828 | if ( storage->load(KOPrefs::instance()->mUseQuicksave) ) { |
2828 | getEventViewerDialog()->setSyncMode( true ); | 2829 | getEventViewerDialog()->setSyncMode( true ); |
2829 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); | 2830 | syncOK = synchronizeCalendar( mCalendar, calendar, mode ); |
2830 | getEventViewerDialog()->setSyncMode( false ); | 2831 | getEventViewerDialog()->setSyncMode( false ); |
2831 | if ( syncOK ) { | 2832 | if ( syncOK ) { |
2832 | if ( KOPrefs::instance()->mWriteBackFile ) | 2833 | if ( KOPrefs::instance()->mWriteBackFile ) |
2833 | { | 2834 | { |
2834 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); | 2835 | storage->setSaveFormat( new ICalFormat( KOPrefs::instance()->mUseQuicksave) ); |
2835 | storage->save(); | 2836 | storage->save(); |
2836 | } | 2837 | } |
2837 | } | 2838 | } |
2838 | setModified(); | 2839 | setModified(); |
2839 | } | 2840 | } |
2840 | 2841 | ||
2841 | #endif | 2842 | #endif |
2842 | } | 2843 | } |
2843 | 2844 | ||
2844 | 2845 | ||
2845 | //this is a overwritten callbackmethods from the syncinterface | 2846 | //this is a overwritten callbackmethods from the syncinterface |
2846 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) | 2847 | bool KABCore::syncExternal(KSyncManager* manager, QString resource) |
2847 | { | 2848 | { |
2848 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); | 2849 | QString mCurrentSyncDevice = manager->getCurrentSyncDevice(); |
2849 | 2850 | ||
2850 | AddressBook abLocal( resource,"syncContact"); | 2851 | AddressBook abLocal( resource,"syncContact"); |
2851 | bool syncOK = false; | 2852 | bool syncOK = false; |
2852 | if ( abLocal.load() ) { | 2853 | if ( abLocal.load() ) { |
2853 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); | 2854 | qDebug("AB sharp loaded ,sync device %s",mCurrentSyncDevice.latin1()); |
2854 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; | 2855 | mGlobalSyncMode = SYNC_MODE_EXTERNAL; |
2855 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); | 2856 | abLocal.preExternSync( mAddressBook ,mCurrentSyncDevice ); |
2856 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); | 2857 | syncOK = synchronizeAddressbooks( mAddressBook, &abLocal, syncManager->mSyncAlgoPrefs ); |
2857 | if ( syncOK ) { | 2858 | if ( syncOK ) { |
2858 | if ( syncManager->mWriteBackFile ) { | 2859 | if ( syncManager->mWriteBackFile ) { |
2859 | abLocal.saveAB(); | 2860 | abLocal.saveAB(); |
2860 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); | 2861 | abLocal.postExternSync( mAddressBook,mCurrentSyncDevice ); |
2861 | } | 2862 | } |
2862 | } | 2863 | } |
2863 | setModified(); | 2864 | setModified(); |
2864 | } | 2865 | } |
2865 | if ( syncOK ) | 2866 | if ( syncOK ) |
2866 | mViewManager->refreshView(); | 2867 | mViewManager->refreshView(); |
2867 | return syncOK; | 2868 | return syncOK; |
2868 | 2869 | ||
2869 | } | 2870 | } |
2870 | 2871 | ||
2871 | void KABCore::getFile( bool success ) | 2872 | void KABCore::getFile( bool success ) |
2872 | { | 2873 | { |
2873 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); | 2874 | QTimer::singleShot( 15000, this , SLOT ( setCaptionBack())); |
2874 | if ( ! success ) { | 2875 | if ( ! success ) { |
2875 | setCaption( i18n("Error receiving file. Nothing changed!") ); | 2876 | setCaption( i18n("Error receiving file. Nothing changed!") ); |
2876 | return; | 2877 | return; |
2877 | } | 2878 | } |
2878 | mAddressBook->importFromFile( sentSyncFile() ); | 2879 | mAddressBook->importFromFile( sentSyncFile() ); |
2879 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); | 2880 | topLevelWidget()->setCaption( i18n("Pi-Sync successful!") ); |
2880 | mViewManager->refreshView(); | 2881 | mViewManager->refreshView(); |
2881 | } | 2882 | } |
2882 | void KABCore::syncFileRequest() | 2883 | void KABCore::syncFileRequest() |
2883 | { | 2884 | { |
2884 | mAddressBook->export2File( sentSyncFile() ); | 2885 | mAddressBook->export2File( sentSyncFile() ); |
2885 | } | 2886 | } |
2886 | QString KABCore::sentSyncFile() | 2887 | QString KABCore::sentSyncFile() |
2887 | { | 2888 | { |
2888 | #ifdef _WIN32_ | 2889 | #ifdef _WIN32_ |
2889 | return locateLocal( "tmp", "copysyncab.vcf" ); | 2890 | return locateLocal( "tmp", "copysyncab.vcf" ); |
2890 | #else | 2891 | #else |
2891 | return QString( "/tmp/copysyncab.vcf" ); | 2892 | return QString( "/tmp/copysyncab.vcf" ); |
2892 | #endif | 2893 | #endif |
2893 | } | 2894 | } |
2894 | 2895 | ||
2895 | void KABCore::setCaptionBack() | 2896 | void KABCore::setCaptionBack() |
2896 | { | 2897 | { |
2897 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); | 2898 | topLevelWidget()->setCaption( i18n("KAddressbook/Pi") ); |
2898 | } | 2899 | } |
diff --git a/libkdepim/phoneaccess.cpp b/libkdepim/phoneaccess.cpp index 357cd39..fe914dd 100644 --- a/libkdepim/phoneaccess.cpp +++ b/libkdepim/phoneaccess.cpp | |||
@@ -1,147 +1,151 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkdepim. | 2 | This file is part of libkdepim. |
3 | 3 | ||
4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> | 4 | Copyright (c) 2004 Lutz Rogowski <rogowski@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | 22 | ||
23 | #include <qstring.h> | 23 | #include <qstring.h> |
24 | #include <qapplication.h> | 24 | #include <qapplication.h> |
25 | #include <qptrlist.h> | 25 | #include <qptrlist.h> |
26 | #include <qregexp.h> | 26 | #include <qregexp.h> |
27 | #include <qfile.h> | 27 | #include <qfile.h> |
28 | #include <qtextstream.h> | 28 | #include <qtextstream.h> |
29 | #include <qtextcodec.h> | 29 | #include <qtextcodec.h> |
30 | #include <qdir.h> | 30 | #include <qdir.h> |
31 | #include <kmessagebox.h> | 31 | #include <kmessagebox.h> |
32 | #include <stdlib.h> | 32 | #include <stdlib.h> |
33 | #include "phoneaccess.h" | 33 | #include "phoneaccess.h" |
34 | 34 | ||
35 | void PhoneAccess::writeConfig( QString device, QString connection, QString model ) | 35 | void PhoneAccess::writeConfig( QString device, QString connection, QString model ) |
36 | { | 36 | { |
37 | #ifdef _WIN32_ | 37 | #ifdef _WIN32_ |
38 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; | 38 | QString fileName = qApp->applicationDirPath () +"\\gammurc"; |
39 | #else | 39 | #else |
40 | QString fileName = QDir::homeDirPath() +"/.gammurc"; | 40 | QString fileName = QDir::homeDirPath() +"/.gammurc"; |
41 | #endif | 41 | #endif |
42 | //qDebug("save %d ", load ); | 42 | //qDebug("save %d ", load ); |
43 | QString content = "[gammu]\n";; | 43 | QString content = "[gammu]\n";; |
44 | bool write = false; | 44 | bool write = false; |
45 | bool addPort = true, addConnection = true, addModel = true; | 45 | bool addPort = true, addConnection = true, addModel = true; |
46 | QFile file( fileName ); | 46 | QFile file( fileName ); |
47 | if ( QFile::exists( fileName) ) { | 47 | if ( QFile::exists( fileName) ) { |
48 | if (!file.open( IO_ReadOnly ) ) { | 48 | if (!file.open( IO_ReadOnly ) ) { |
49 | qDebug("Error: cannot open %s ", fileName.latin1() ); | 49 | qDebug("Error: cannot open %s ", fileName.latin1() ); |
50 | return; | 50 | return; |
51 | } | 51 | } |
52 | QString line; | 52 | QString line; |
53 | while ( file.readLine( line, 1024 ) > 0 ) { | 53 | while ( file.readLine( line, 1024 ) > 0 ) { |
54 | //qDebug("*%s* ", line.latin1() ); | 54 | //qDebug("*%s* ", line.latin1() ); |
55 | if ( line.left(7 ) == "[gammu]" ) { | 55 | if ( line.left(7 ) == "[gammu]" ) { |
56 | ; | 56 | ; |
57 | } else | 57 | } else |
58 | if ( line.left(4 ) == "port" ) { | 58 | if ( line.left(4 ) == "port" ) { |
59 | if ( line == "port = " + device+"\n" ) { | 59 | if ( line == "port = " + device+"\n" ) { |
60 | content += line ; | 60 | content += line ; |
61 | addPort = false; | 61 | addPort = false; |
62 | //qDebug("port found" ); | 62 | //qDebug("port found" ); |
63 | } | 63 | } |
64 | 64 | ||
65 | } else if ( line.left(5 ) == "model" ) { | 65 | } else if ( line.left(5 ) == "model" ) { |
66 | if ( line == "model = " + model +"\n") { | 66 | if ( line == "model = " + model +"\n") { |
67 | content += line ; | 67 | content += line ; |
68 | addModel = false; | 68 | addModel = false; |
69 | //qDebug("model found" ); | 69 | //qDebug("model found" ); |
70 | } | 70 | } |
71 | 71 | ||
72 | } else if ( line.left( 10 ) == "connection" ) { | 72 | } else if ( line.left( 10 ) == "connection" ) { |
73 | if ( line == "connection = " + connection +"\n") { | 73 | if ( line == "connection = " + connection +"\n") { |
74 | addConnection = false; | 74 | addConnection = false; |
75 | content += line ; | 75 | content += line ; |
76 | //qDebug("con found" ); | 76 | //qDebug("con found" ); |
77 | } | 77 | } |
78 | 78 | ||
79 | } else { | 79 | } else { |
80 | content += line ; | 80 | content += line ; |
81 | } | 81 | } |
82 | } | 82 | } |
83 | file.close(); | 83 | file.close(); |
84 | } else { | 84 | } else { |
85 | if ( ! connection.isEmpty() ) { | 85 | if ( ! connection.isEmpty() ) { |
86 | addConnection = true; | 86 | addConnection = true; |
87 | } | 87 | } |
88 | if ( ! device.isEmpty() ) { | 88 | if ( ! device.isEmpty() ) { |
89 | addPort = true; | 89 | addPort = true; |
90 | 90 | ||
91 | } | 91 | } |
92 | if ( ! model.isEmpty() ) { | 92 | if ( ! model.isEmpty() ) { |
93 | addModel = true; | 93 | addModel = true; |
94 | } | 94 | } |
95 | } | 95 | } |
96 | 96 | ||
97 | if ( addConnection ) { | 97 | if ( addConnection ) { |
98 | write = true; | 98 | write = true; |
99 | content += "connection = "; | 99 | content += "connection = "; |
100 | content += connection; | 100 | content += connection; |
101 | content += "\n"; | 101 | content += "\n"; |
102 | } | 102 | } |
103 | if ( addPort ) { | 103 | if ( addPort ) { |
104 | write = true; | 104 | write = true; |
105 | content += "port = "; | 105 | content += "port = "; |
106 | content += device; | 106 | content += device; |
107 | content += "\n"; | 107 | content += "\n"; |
108 | 108 | ||
109 | } | 109 | } |
110 | if ( addModel ) { | 110 | if ( addModel ) { |
111 | write = true; | 111 | write = true; |
112 | content += "model = "; | 112 | content += "model = "; |
113 | content += model; | 113 | content += model; |
114 | content += "\n"; | 114 | content += "\n"; |
115 | } | 115 | } |
116 | if ( write ) { | 116 | if ( write ) { |
117 | if (!file.open( IO_WriteOnly ) ) { | 117 | if (!file.open( IO_WriteOnly ) ) { |
118 | qDebug("Error: cannot write file %s ", fileName.latin1() ); | 118 | qDebug("Error: cannot write file %s ", fileName.latin1() ); |
119 | return; | 119 | return; |
120 | } | 120 | } |
121 | qDebug("Writing file %s ", fileName.latin1() ); | 121 | qDebug("Writing file %s ", fileName.latin1() ); |
122 | QTextStream ts( &file ); | 122 | QTextStream ts( &file ); |
123 | ts << content ; | 123 | ts << content ; |
124 | file.close(); | 124 | file.close(); |
125 | } | 125 | } |
126 | 126 | ||
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | bool PhoneAccess::writeToPhone( QString fileName) | 130 | bool PhoneAccess::writeToPhone( QString fileName) |
131 | { | 131 | { |
132 | 132 | ||
133 | #ifdef DESKTOP_VERSION | 133 | #ifdef DESKTOP_VERSION |
134 | #ifdef _WIN32_ | ||
135 | QString command ="kammu --restore " + fileName ; | ||
136 | #else | ||
134 | QString command ="./kammu --restore " + fileName ; | 137 | QString command ="./kammu --restore " + fileName ; |
138 | #endif | ||
135 | #else | 139 | #else |
136 | QString command ="kammu --restore " + fileName ; | 140 | QString command ="kammu --restore " + fileName ; |
137 | #endif | 141 | #endif |
138 | int ret; | 142 | int ret; |
139 | while ( (ret = system ( command.latin1())) != 0 ) { | 143 | while ( (ret = system ( command.latin1())) != 0 ) { |
140 | qDebug("Error S::command returned %d. asking users", ret); | 144 | qDebug("Error S::command returned %d.", ret); |
141 | int retval = KMessageBox::warningContinueCancel(0, | 145 | int retval = KMessageBox::warningContinueCancel(0, |
142 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); | 146 | i18n("Error accessing device!\nPlease turn on connection\nand retry!"),i18n("KO/Pi phone access"),i18n("Retry"),i18n("Cancel")); |
143 | if ( retval != KMessageBox::Continue ) | 147 | if ( retval != KMessageBox::Continue ) |
144 | return false; | 148 | return false; |
145 | } | 149 | } |
146 | return true; | 150 | return true; |
147 | } | 151 | } |