author | zautrix <zautrix> | 2004-10-11 10:09:39 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-11 10:09:39 (UTC) |
commit | d3759373291c08d2cde93d85a76d190dc8a33830 (patch) (unidiff) | |
tree | ccc808fbdcd2ef0f38747fa459b2c605948f49a5 /kabc/addressbook.cpp | |
parent | 504f6b2a8732d980a88234cdef0a80c201b9c4da (diff) | |
download | kdepimpi-d3759373291c08d2cde93d85a76d190dc8a33830.zip kdepimpi-d3759373291c08d2cde93d85a76d190dc8a33830.tar.gz kdepimpi-d3759373291c08d2cde93d85a76d190dc8a33830.tar.bz2 |
crash fix in saveAB
-rw-r--r-- | kabc/addressbook.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ad0f702..19c26eb 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,1198 +1,1199 @@ | |||
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 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <klocale.h> | 46 | #include <klocale.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
50 | #include <libkdepim/phoneaccess.h> | 50 | #include <libkdepim/phoneaccess.h> |
51 | #include "addressbook.h" | 51 | #include "addressbook.h" |
52 | #include "resource.h" | 52 | #include "resource.h" |
53 | #include "vcardconverter.h" | 53 | #include "vcardconverter.h" |
54 | #include "vcardparser/vcardtool.h" | 54 | #include "vcardparser/vcardtool.h" |
55 | 55 | ||
56 | //US #include "addressbook.moc" | 56 | //US #include "addressbook.moc" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | 59 | ||
60 | struct AddressBook::AddressBookData | 60 | struct AddressBook::AddressBookData |
61 | { | 61 | { |
62 | Addressee::List mAddressees; | 62 | Addressee::List mAddressees; |
63 | Addressee::List mRemovedAddressees; | 63 | Addressee::List mRemovedAddressees; |
64 | Field::List mAllFields; | 64 | Field::List mAllFields; |
65 | KConfig *mConfig; | 65 | KConfig *mConfig; |
66 | KRES::Manager<Resource> *mManager; | 66 | KRES::Manager<Resource> *mManager; |
67 | //US ErrorHandler *mErrorHandler; | 67 | //US ErrorHandler *mErrorHandler; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | struct AddressBook::Iterator::IteratorData | 70 | struct AddressBook::Iterator::IteratorData |
71 | { | 71 | { |
72 | Addressee::List::Iterator mIt; | 72 | Addressee::List::Iterator mIt; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct AddressBook::ConstIterator::ConstIteratorData | 75 | struct AddressBook::ConstIterator::ConstIteratorData |
76 | { | 76 | { |
77 | Addressee::List::ConstIterator mIt; | 77 | Addressee::List::ConstIterator mIt; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | AddressBook::Iterator::Iterator() | 80 | AddressBook::Iterator::Iterator() |
81 | { | 81 | { |
82 | d = new IteratorData; | 82 | d = new IteratorData; |
83 | } | 83 | } |
84 | 84 | ||
85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
86 | { | 86 | { |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | } | 89 | } |
90 | 90 | ||
91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
92 | { | 92 | { |
93 | if( this == &i ) return *this; // guard against self assignment | 93 | if( this == &i ) return *this; // guard against self assignment |
94 | delete d; // delete the old data the Iterator was completely constructed before | 94 | delete d; // delete the old data the Iterator was completely constructed before |
95 | d = new IteratorData; | 95 | d = new IteratorData; |
96 | d->mIt = i.d->mIt; | 96 | d->mIt = i.d->mIt; |
97 | return *this; | 97 | return *this; |
98 | } | 98 | } |
99 | 99 | ||
100 | AddressBook::Iterator::~Iterator() | 100 | AddressBook::Iterator::~Iterator() |
101 | { | 101 | { |
102 | delete d; | 102 | delete d; |
103 | } | 103 | } |
104 | 104 | ||
105 | const Addressee &AddressBook::Iterator::operator*() const | 105 | const Addressee &AddressBook::Iterator::operator*() const |
106 | { | 106 | { |
107 | return *(d->mIt); | 107 | return *(d->mIt); |
108 | } | 108 | } |
109 | 109 | ||
110 | Addressee &AddressBook::Iterator::operator*() | 110 | Addressee &AddressBook::Iterator::operator*() |
111 | { | 111 | { |
112 | return *(d->mIt); | 112 | return *(d->mIt); |
113 | } | 113 | } |
114 | 114 | ||
115 | Addressee *AddressBook::Iterator::operator->() | 115 | Addressee *AddressBook::Iterator::operator->() |
116 | { | 116 | { |
117 | return &(*(d->mIt)); | 117 | return &(*(d->mIt)); |
118 | } | 118 | } |
119 | 119 | ||
120 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 120 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
121 | { | 121 | { |
122 | (d->mIt)++; | 122 | (d->mIt)++; |
123 | return *this; | 123 | return *this; |
124 | } | 124 | } |
125 | 125 | ||
126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
127 | { | 127 | { |
128 | (d->mIt)++; | 128 | (d->mIt)++; |
129 | return *this; | 129 | return *this; |
130 | } | 130 | } |
131 | 131 | ||
132 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 132 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
133 | { | 133 | { |
134 | (d->mIt)--; | 134 | (d->mIt)--; |
135 | return *this; | 135 | return *this; |
136 | } | 136 | } |
137 | 137 | ||
138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
139 | { | 139 | { |
140 | (d->mIt)--; | 140 | (d->mIt)--; |
141 | return *this; | 141 | return *this; |
142 | } | 142 | } |
143 | 143 | ||
144 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 144 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
145 | { | 145 | { |
146 | return ( d->mIt == it.d->mIt ); | 146 | return ( d->mIt == it.d->mIt ); |
147 | } | 147 | } |
148 | 148 | ||
149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
150 | { | 150 | { |
151 | return ( d->mIt != it.d->mIt ); | 151 | return ( d->mIt != it.d->mIt ); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | AddressBook::ConstIterator::ConstIterator() | 155 | AddressBook::ConstIterator::ConstIterator() |
156 | { | 156 | { |
157 | d = new ConstIteratorData; | 157 | d = new ConstIteratorData; |
158 | } | 158 | } |
159 | 159 | ||
160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
161 | { | 161 | { |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | } | 164 | } |
165 | 165 | ||
166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
167 | { | 167 | { |
168 | if( this == &i ) return *this; // guard for self assignment | 168 | if( this == &i ) return *this; // guard for self assignment |
169 | delete d; // delete the old data because the Iterator was really constructed before | 169 | delete d; // delete the old data because the Iterator was really constructed before |
170 | d = new ConstIteratorData; | 170 | d = new ConstIteratorData; |
171 | d->mIt = i.d->mIt; | 171 | d->mIt = i.d->mIt; |
172 | return *this; | 172 | return *this; |
173 | } | 173 | } |
174 | 174 | ||
175 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
176 | { | 176 | { |
177 | delete d; | 177 | delete d; |
178 | } | 178 | } |
179 | 179 | ||
180 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
181 | { | 181 | { |
182 | return *(d->mIt); | 182 | return *(d->mIt); |
183 | } | 183 | } |
184 | 184 | ||
185 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
186 | { | 186 | { |
187 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
188 | } | 188 | } |
189 | 189 | ||
190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
191 | { | 191 | { |
192 | (d->mIt)++; | 192 | (d->mIt)++; |
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
197 | { | 197 | { |
198 | (d->mIt)++; | 198 | (d->mIt)++; |
199 | return *this; | 199 | return *this; |
200 | } | 200 | } |
201 | 201 | ||
202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
203 | { | 203 | { |
204 | (d->mIt)--; | 204 | (d->mIt)--; |
205 | return *this; | 205 | return *this; |
206 | } | 206 | } |
207 | 207 | ||
208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
209 | { | 209 | { |
210 | (d->mIt)--; | 210 | (d->mIt)--; |
211 | return *this; | 211 | return *this; |
212 | } | 212 | } |
213 | 213 | ||
214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
215 | { | 215 | { |
216 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
220 | { | 220 | { |
221 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
226 | { | 226 | { |
227 | init(0, "contact"); | 227 | init(0, "contact"); |
228 | } | 228 | } |
229 | 229 | ||
230 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
231 | { | 231 | { |
232 | init(config, "contact"); | 232 | init(config, "contact"); |
233 | } | 233 | } |
234 | 234 | ||
235 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | init(config, family); | 237 | init(config, family); |
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | // the default family is "contact" | 241 | // the default family is "contact" |
242 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
243 | { | 243 | { |
244 | blockLSEchange = false; | 244 | blockLSEchange = false; |
245 | d = new AddressBookData; | 245 | d = new AddressBookData; |
246 | QString fami = family; | 246 | QString fami = family; |
247 | if (config != 0) { | 247 | if (config != 0) { |
248 | if ( family == "syncContact" ) { | 248 | if ( family == "syncContact" ) { |
249 | qDebug("creating sync config "); | 249 | qDebug("creating sync config "); |
250 | fami = "contact"; | 250 | fami = "contact"; |
251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
252 | con->setGroup( "General" ); | 252 | con->setGroup( "General" ); |
253 | con->writeEntry( "ResourceKeys", QString("sync") ); | 253 | con->writeEntry( "ResourceKeys", QString("sync") ); |
254 | con->writeEntry( "Standard", QString("sync") ); | 254 | con->writeEntry( "Standard", QString("sync") ); |
255 | con->setGroup( "Resource_sync" ); | 255 | con->setGroup( "Resource_sync" ); |
256 | con->writeEntry( "FileName", config ); | 256 | con->writeEntry( "FileName", config ); |
257 | con->writeEntry( "FileFormat", QString("vcard") ); | 257 | con->writeEntry( "FileFormat", QString("vcard") ); |
258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
259 | con->writeEntry( "ResourceName", QString("sync_res") ); | 259 | con->writeEntry( "ResourceName", QString("sync_res") ); |
260 | if ( config.right(4) == ".xml" ) | 260 | if ( config.right(4) == ".xml" ) |
261 | con->writeEntry( "ResourceType", QString("qtopia") ); | 261 | con->writeEntry( "ResourceType", QString("qtopia") ); |
262 | else if ( config == "sharp" ) { | 262 | else if ( config == "sharp" ) { |
263 | con->writeEntry( "ResourceType", QString("sharp") ); | 263 | con->writeEntry( "ResourceType", QString("sharp") ); |
264 | } else { | 264 | } else { |
265 | con->writeEntry( "ResourceType", QString("file") ); | 265 | con->writeEntry( "ResourceType", QString("file") ); |
266 | } | 266 | } |
267 | //con->sync(); | 267 | //con->sync(); |
268 | d->mConfig = con; | 268 | d->mConfig = con; |
269 | } | 269 | } |
270 | else | 270 | else |
271 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | d->mConfig = 0; | 275 | d->mConfig = 0; |
276 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
277 | } | 277 | } |
278 | 278 | ||
279 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
280 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 280 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
281 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
282 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
283 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
284 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
286 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
287 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
289 | } | 289 | } |
290 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
291 | if ( !res ) { | 291 | if ( !res ) { |
292 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
293 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | void AddressBook::export2File( QString fileName ) | 379 | void AddressBook::export2File( QString fileName ) |
380 | { | 380 | { |
381 | 381 | ||
382 | QFile outFile( fileName ); | 382 | QFile outFile( fileName ); |
383 | if ( !outFile.open( IO_WriteOnly ) ) { | 383 | if ( !outFile.open( IO_WriteOnly ) ) { |
384 | 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>" ); |
385 | KMessageBox::error( 0, text.arg( fileName ) ); | 385 | KMessageBox::error( 0, text.arg( fileName ) ); |
386 | return ; | 386 | return ; |
387 | } | 387 | } |
388 | QTextStream t( &outFile ); | 388 | QTextStream t( &outFile ); |
389 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 389 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
390 | Iterator it; | 390 | Iterator it; |
391 | KABC::VCardConverter::Version version; | 391 | KABC::VCardConverter::Version version; |
392 | version = KABC::VCardConverter::v3_0; | 392 | version = KABC::VCardConverter::v3_0; |
393 | for ( it = begin(); it != end(); ++it ) { | 393 | for ( it = begin(); it != end(); ++it ) { |
394 | if ( !(*it).IDStr().isEmpty() ) { | 394 | if ( !(*it).IDStr().isEmpty() ) { |
395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 395 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
396 | } | 396 | } |
397 | KABC::VCardConverter converter; | 397 | KABC::VCardConverter converter; |
398 | QString vcard; | 398 | QString vcard; |
399 | //Resource *resource() const; | 399 | //Resource *resource() const; |
400 | converter.addresseeToVCard( *it, vcard, version ); | 400 | converter.addresseeToVCard( *it, vcard, version ); |
401 | t << vcard << "\r\n"; | 401 | t << vcard << "\r\n"; |
402 | } | 402 | } |
403 | t << "\r\n\r\n"; | 403 | t << "\r\n\r\n"; |
404 | outFile.close(); | 404 | outFile.close(); |
405 | } | 405 | } |
406 | // if QStringList uids is empty, all are exported | 406 | // if QStringList uids is empty, all are exported |
407 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 407 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
408 | { | 408 | { |
409 | KABC::VCardConverter converter; | 409 | KABC::VCardConverter converter; |
410 | QString datastream; | 410 | QString datastream; |
411 | Iterator it; | 411 | Iterator it; |
412 | bool all = uids.isEmpty(); | 412 | bool all = uids.isEmpty(); |
413 | for ( it = begin(); it != end(); ++it ) { | 413 | for ( it = begin(); it != end(); ++it ) { |
414 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 414 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
415 | if ( ! all ) { | 415 | if ( ! all ) { |
416 | if ( ! ( uids.contains((*it).uid() ) )) | 416 | if ( ! ( uids.contains((*it).uid() ) )) |
417 | continue; | 417 | continue; |
418 | } | 418 | } |
419 | KABC::Addressee a = ( *it ); | 419 | KABC::Addressee a = ( *it ); |
420 | if ( a.isEmpty() ) | 420 | if ( a.isEmpty() ) |
421 | continue; | 421 | continue; |
422 | a.simplifyEmails(); | 422 | a.simplifyEmails(); |
423 | a.simplifyPhoneNumbers(); | 423 | a.simplifyPhoneNumbers(); |
424 | a.simplifyPhoneNumberTypes(); | 424 | a.simplifyPhoneNumberTypes(); |
425 | a.simplifyAddresses(); | 425 | a.simplifyAddresses(); |
426 | 426 | ||
427 | QString vcard; | 427 | QString vcard; |
428 | QString vcardnew; | 428 | QString vcardnew; |
429 | converter.addresseeToVCard( a, vcard ); | 429 | converter.addresseeToVCard( a, vcard ); |
430 | int start = 0; | 430 | int start = 0; |
431 | int next; | 431 | int next; |
432 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 432 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
433 | int semi = vcard.find(";", next); | 433 | int semi = vcard.find(";", next); |
434 | int dopp = vcard.find(":", next); | 434 | int dopp = vcard.find(":", next); |
435 | int sep; | 435 | int sep; |
436 | if ( semi < dopp && semi >= 0 ) | 436 | if ( semi < dopp && semi >= 0 ) |
437 | sep = semi ; | 437 | sep = semi ; |
438 | else | 438 | else |
439 | sep = dopp; | 439 | sep = dopp; |
440 | vcardnew +=vcard.mid( start, next - start); | 440 | vcardnew +=vcard.mid( start, next - start); |
441 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 441 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
442 | start = sep; | 442 | start = sep; |
443 | } | 443 | } |
444 | vcardnew += vcard.mid( start,vcard.length() ); | 444 | vcardnew += vcard.mid( start,vcard.length() ); |
445 | vcard = ""; | 445 | vcard = ""; |
446 | start = 0; | 446 | start = 0; |
447 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 447 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
448 | int sep = vcardnew.find(":", next); | 448 | int sep = vcardnew.find(":", next); |
449 | vcard +=vcardnew.mid( start, next - start+3); | 449 | vcard +=vcardnew.mid( start, next - start+3); |
450 | start = sep; | 450 | start = sep; |
451 | } | 451 | } |
452 | vcard += vcardnew.mid( start,vcardnew.length() ); | 452 | vcard += vcardnew.mid( start,vcardnew.length() ); |
453 | vcard.replace ( QRegExp(";;;") , "" ); | 453 | vcard.replace ( QRegExp(";;;") , "" ); |
454 | vcard.replace ( QRegExp(";;") , "" ); | 454 | vcard.replace ( QRegExp(";;") , "" ); |
455 | datastream += vcard; | 455 | datastream += vcard; |
456 | 456 | ||
457 | } | 457 | } |
458 | 458 | ||
459 | QFile outFile(fileName); | 459 | QFile outFile(fileName); |
460 | if ( outFile.open(IO_WriteOnly) ) { | 460 | if ( outFile.open(IO_WriteOnly) ) { |
461 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 461 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
462 | QTextStream t( &outFile ); // use a text stream | 462 | QTextStream t( &outFile ); // use a text stream |
463 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 463 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
464 | t <<datastream; | 464 | t <<datastream; |
465 | t << "\r\n\r\n"; | 465 | t << "\r\n\r\n"; |
466 | outFile.close(); | 466 | outFile.close(); |
467 | 467 | ||
468 | } else { | 468 | } else { |
469 | qDebug("Error open temp file "); | 469 | qDebug("Error open temp file "); |
470 | return false; | 470 | return false; |
471 | } | 471 | } |
472 | return true; | 472 | return true; |
473 | 473 | ||
474 | } | 474 | } |
475 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 475 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
476 | { | 476 | { |
477 | 477 | ||
478 | if ( removeOld ) | 478 | if ( removeOld ) |
479 | setUntagged(); | 479 | setUntagged(); |
480 | KABC::Addressee::List list; | 480 | KABC::Addressee::List list; |
481 | QFile file( fileName ); | 481 | QFile file( fileName ); |
482 | file.open( IO_ReadOnly ); | 482 | file.open( IO_ReadOnly ); |
483 | QByteArray rawData = file.readAll(); | 483 | QByteArray rawData = file.readAll(); |
484 | file.close(); | 484 | file.close(); |
485 | QString data; | 485 | QString data; |
486 | if ( replaceLabel ) { | 486 | if ( replaceLabel ) { |
487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 487 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
488 | data.replace ( QRegExp("LABEL") , "ADR" ); | 488 | data.replace ( QRegExp("LABEL") , "ADR" ); |
489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 489 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
490 | } else | 490 | } else |
491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 491 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
492 | KABC::VCardTool tool; | 492 | KABC::VCardTool tool; |
493 | list = tool.parseVCards( data ); | 493 | list = tool.parseVCards( data ); |
494 | KABC::Addressee::List::Iterator it; | 494 | KABC::Addressee::List::Iterator it; |
495 | for ( it = list.begin(); it != list.end(); ++it ) { | 495 | for ( it = list.begin(); it != list.end(); ++it ) { |
496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 496 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
497 | if ( !id.isEmpty() ) | 497 | if ( !id.isEmpty() ) |
498 | (*it).setIDStr(id ); | 498 | (*it).setIDStr(id ); |
499 | (*it).setResource( 0 ); | 499 | (*it).setResource( 0 ); |
500 | if ( replaceLabel ) | 500 | if ( replaceLabel ) |
501 | (*it).removeVoice(); | 501 | (*it).removeVoice(); |
502 | if ( removeOld ) | 502 | if ( removeOld ) |
503 | (*it).setTagged( true ); | 503 | (*it).setTagged( true ); |
504 | insertAddressee( (*it), false, true ); | 504 | insertAddressee( (*it), false, true ); |
505 | } | 505 | } |
506 | if ( removeOld ) | 506 | if ( removeOld ) |
507 | removeUntagged(); | 507 | removeUntagged(); |
508 | } | 508 | } |
509 | void AddressBook::setUntagged() | 509 | void AddressBook::setUntagged() |
510 | { | 510 | { |
511 | Iterator ait; | 511 | Iterator ait; |
512 | for ( ait = begin(); ait != end(); ++ait ) { | 512 | for ( ait = begin(); ait != end(); ++ait ) { |
513 | (*ait).setTagged( false ); | 513 | (*ait).setTagged( false ); |
514 | } | 514 | } |
515 | } | 515 | } |
516 | void AddressBook::removeUntagged() | 516 | void AddressBook::removeUntagged() |
517 | { | 517 | { |
518 | Iterator ait; | 518 | Iterator ait; |
519 | bool todelete = false; | 519 | bool todelete = false; |
520 | Iterator todel; | 520 | Iterator todel; |
521 | for ( ait = begin(); ait != end(); ++ait ) { | 521 | for ( ait = begin(); ait != end(); ++ait ) { |
522 | if ( todelete ) | 522 | if ( todelete ) |
523 | removeAddressee( todel ); | 523 | removeAddressee( todel ); |
524 | if (!(*ait).tagged()) { | 524 | if (!(*ait).tagged()) { |
525 | todelete = true; | 525 | todelete = true; |
526 | todel = ait; | 526 | todel = ait; |
527 | } else | 527 | } else |
528 | todelete = false; | 528 | todelete = false; |
529 | } | 529 | } |
530 | if ( todelete ) | 530 | if ( todelete ) |
531 | removeAddressee( todel ); | 531 | removeAddressee( todel ); |
532 | deleteRemovedAddressees(); | 532 | deleteRemovedAddressees(); |
533 | } | 533 | } |
534 | void AddressBook::smplifyAddressees() | 534 | void AddressBook::smplifyAddressees() |
535 | { | 535 | { |
536 | Iterator ait; | 536 | Iterator ait; |
537 | for ( ait = begin(); ait != end(); ++ait ) { | 537 | for ( ait = begin(); ait != end(); ++ait ) { |
538 | (*ait).simplifyEmails(); | 538 | (*ait).simplifyEmails(); |
539 | (*ait).simplifyPhoneNumbers(); | 539 | (*ait).simplifyPhoneNumbers(); |
540 | (*ait).simplifyPhoneNumberTypes(); | 540 | (*ait).simplifyPhoneNumberTypes(); |
541 | (*ait).simplifyAddresses(); | 541 | (*ait).simplifyAddresses(); |
542 | } | 542 | } |
543 | } | 543 | } |
544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 544 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
545 | { | 545 | { |
546 | Iterator ait; | 546 | Iterator ait; |
547 | for ( ait = begin(); ait != end(); ++ait ) { | 547 | for ( ait = begin(); ait != end(); ++ait ) { |
548 | QString id = (*ait).IDStr(); | 548 | QString id = (*ait).IDStr(); |
549 | (*ait).setIDStr( ":"); | 549 | (*ait).setIDStr( ":"); |
550 | (*ait).setExternalUID( id ); | 550 | (*ait).setExternalUID( id ); |
551 | (*ait).setOriginalExternalUID( id ); | 551 | (*ait).setOriginalExternalUID( id ); |
552 | if ( isPreSync ) | 552 | if ( isPreSync ) |
553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 553 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
554 | else { | 554 | else { |
555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 555 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
556 | (*ait).setID( currentSyncDevice,id ); | 556 | (*ait).setID( currentSyncDevice,id ); |
557 | 557 | ||
558 | } | 558 | } |
559 | } | 559 | } |
560 | } | 560 | } |
561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 561 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
562 | { | 562 | { |
563 | 563 | ||
564 | setUntagged(); | 564 | setUntagged(); |
565 | KABC::Addressee::List list; | 565 | KABC::Addressee::List list; |
566 | QFile file( fileName ); | 566 | QFile file( fileName ); |
567 | file.open( IO_ReadOnly ); | 567 | file.open( IO_ReadOnly ); |
568 | QByteArray rawData = file.readAll(); | 568 | QByteArray rawData = file.readAll(); |
569 | file.close(); | 569 | file.close(); |
570 | QString data; | 570 | QString data; |
571 | 571 | ||
572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 572 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
573 | KABC::VCardTool tool; | 573 | KABC::VCardTool tool; |
574 | list = tool.parseVCards( data ); | 574 | list = tool.parseVCards( data ); |
575 | KABC::Addressee::List::Iterator it; | 575 | KABC::Addressee::List::Iterator it; |
576 | for ( it = list.begin(); it != list.end(); ++it ) { | 576 | for ( it = list.begin(); it != list.end(); ++it ) { |
577 | Iterator ait; | 577 | Iterator ait; |
578 | for ( ait = begin(); ait != end(); ++ait ) { | 578 | for ( ait = begin(); ait != end(); ++ait ) { |
579 | if ( !(*ait).tagged() ) { | 579 | if ( !(*ait).tagged() ) { |
580 | if ( (*ait).containsAdr(*it)) { | 580 | if ( (*ait).containsAdr(*it)) { |
581 | (*ait).setTagged(true); | 581 | (*ait).setTagged(true); |
582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 582 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
583 | (*it).setIDStr( ":"); | 583 | (*it).setIDStr( ":"); |
584 | (*it).setID( currentSyncDevice,id ); | 584 | (*it).setID( currentSyncDevice,id ); |
585 | (*it).setExternalUID( id ); | 585 | (*it).setExternalUID( id ); |
586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 586 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
587 | (*it).setUid( ( (*ait).uid() )); | 587 | (*it).setUid( ( (*ait).uid() )); |
588 | break; | 588 | break; |
589 | } | 589 | } |
590 | } | 590 | } |
591 | 591 | ||
592 | } | 592 | } |
593 | if ( ait == end() ) | 593 | if ( ait == end() ) |
594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 594 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
595 | } | 595 | } |
596 | clear(); | 596 | clear(); |
597 | for ( it = list.begin(); it != list.end(); ++it ) { | 597 | for ( it = list.begin(); it != list.end(); ++it ) { |
598 | insertAddressee( (*it) ); | 598 | insertAddressee( (*it) ); |
599 | } | 599 | } |
600 | } | 600 | } |
601 | 601 | ||
602 | bool AddressBook::saveABphone( QString fileName ) | 602 | bool AddressBook::saveABphone( QString fileName ) |
603 | { | 603 | { |
604 | //smplifyAddressees(); | 604 | //smplifyAddressees(); |
605 | qDebug("saveABphone:: saving AB... "); | 605 | qDebug("saveABphone:: saving AB... "); |
606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 606 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
607 | return false; | 607 | return false; |
608 | qDebug("saveABphone:: writing to phone... "); | 608 | qDebug("saveABphone:: writing to phone... "); |
609 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 609 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
610 | return false; | 610 | return false; |
611 | } | 611 | } |
612 | qDebug("saveABphone:: re-reading from phone... "); | 612 | qDebug("saveABphone:: re-reading from phone... "); |
613 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 613 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
614 | return false; | 614 | return false; |
615 | } | 615 | } |
616 | return true; | 616 | return true; |
617 | } | 617 | } |
618 | bool AddressBook::saveAB() | 618 | bool AddressBook::saveAB() |
619 | { | 619 | { |
620 | bool ok = true; | 620 | bool ok = true; |
621 | 621 | ||
622 | deleteRemovedAddressees(); | 622 | deleteRemovedAddressees(); |
623 | Iterator ait; | 623 | Iterator ait; |
624 | for ( ait = begin(); ait != end(); ++ait ) { | 624 | for ( ait = begin(); ait != end(); ++ait ) { |
625 | if ( !(*ait).IDStr().isEmpty() ) { | 625 | if ( !(*ait).IDStr().isEmpty() ) { |
626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 626 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
627 | } | 627 | } |
628 | } | 628 | } |
629 | KRES::Manager<Resource>::ActiveIterator it; | 629 | KRES::Manager<Resource>::ActiveIterator it; |
630 | KRES::Manager<Resource> *manager = d->mManager; | 630 | KRES::Manager<Resource> *manager = d->mManager; |
631 | qDebug("SaveAB::saving..." ); | 631 | qDebug("SaveAB::saving..." ); |
632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 632 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
633 | qDebug("SaveAB::checking resource..." ); | 633 | qDebug("SaveAB::checking resource..." ); |
634 | if ( (*it)->readOnly() ) | 634 | if ( (*it)->readOnly() ) |
635 | qDebug("readonly." ); | 635 | qDebug("resource is readonly." ); |
636 | if ( (*it)->isOpen() ) | 636 | if ( (*it)->isOpen() ) |
637 | qDebug("open" ); | 637 | qDebug("resource is open" ); |
638 | 638 | ||
639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 639 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
640 | Ticket *ticket = requestSaveTicket( *it ); | 640 | Ticket *ticket = requestSaveTicket( *it ); |
641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 641 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
642 | if ( !ticket ) { | 642 | if ( !ticket ) { |
643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 643 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) |
644 | .arg( (*it)->resourceName() ) ); | 644 | .arg( (*it)->resourceName() ) ); |
645 | return false; | 645 | return false; |
646 | } | 646 | } |
647 | 647 | ||
648 | //if ( !save( ticket ) ) | 648 | //if ( !save( ticket ) ) |
649 | if ( ticket->resource() ) { | 649 | if ( ticket->resource() ) { |
650 | QString name = ticket->resource()->resourceName(); | ||
650 | if ( ! ticket->resource()->save( ticket ) ) | 651 | if ( ! ticket->resource()->save( ticket ) ) |
651 | ok = false; | 652 | ok = false; |
652 | else | 653 | else |
653 | qDebug("StdAddressBook::saved '%s'", ticket->resource()->resourceName().latin1() ); | 654 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); |
654 | 655 | ||
655 | } else | 656 | } else |
656 | ok = false; | 657 | ok = false; |
657 | 658 | ||
658 | } | 659 | } |
659 | } | 660 | } |
660 | return ok; | 661 | return ok; |
661 | } | 662 | } |
662 | 663 | ||
663 | AddressBook::Iterator AddressBook::begin() | 664 | AddressBook::Iterator AddressBook::begin() |
664 | { | 665 | { |
665 | Iterator it = Iterator(); | 666 | Iterator it = Iterator(); |
666 | it.d->mIt = d->mAddressees.begin(); | 667 | it.d->mIt = d->mAddressees.begin(); |
667 | return it; | 668 | return it; |
668 | } | 669 | } |
669 | 670 | ||
670 | AddressBook::ConstIterator AddressBook::begin() const | 671 | AddressBook::ConstIterator AddressBook::begin() const |
671 | { | 672 | { |
672 | ConstIterator it = ConstIterator(); | 673 | ConstIterator it = ConstIterator(); |
673 | it.d->mIt = d->mAddressees.begin(); | 674 | it.d->mIt = d->mAddressees.begin(); |
674 | return it; | 675 | return it; |
675 | } | 676 | } |
676 | 677 | ||
677 | AddressBook::Iterator AddressBook::end() | 678 | AddressBook::Iterator AddressBook::end() |
678 | { | 679 | { |
679 | Iterator it = Iterator(); | 680 | Iterator it = Iterator(); |
680 | it.d->mIt = d->mAddressees.end(); | 681 | it.d->mIt = d->mAddressees.end(); |
681 | return it; | 682 | return it; |
682 | } | 683 | } |
683 | 684 | ||
684 | AddressBook::ConstIterator AddressBook::end() const | 685 | AddressBook::ConstIterator AddressBook::end() const |
685 | { | 686 | { |
686 | ConstIterator it = ConstIterator(); | 687 | ConstIterator it = ConstIterator(); |
687 | it.d->mIt = d->mAddressees.end(); | 688 | it.d->mIt = d->mAddressees.end(); |
688 | return it; | 689 | return it; |
689 | } | 690 | } |
690 | 691 | ||
691 | void AddressBook::clear() | 692 | void AddressBook::clear() |
692 | { | 693 | { |
693 | d->mAddressees.clear(); | 694 | d->mAddressees.clear(); |
694 | } | 695 | } |
695 | 696 | ||
696 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 697 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
697 | { | 698 | { |
698 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 699 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
699 | 700 | ||
700 | if ( !resource ) | 701 | if ( !resource ) |
701 | { | 702 | { |
702 | qDebug("AddressBook::requestSaveTicket no resource" ); | 703 | qDebug("AddressBook::requestSaveTicket no resource" ); |
703 | resource = standardResource(); | 704 | resource = standardResource(); |
704 | } | 705 | } |
705 | 706 | ||
706 | KRES::Manager<Resource>::ActiveIterator it; | 707 | KRES::Manager<Resource>::ActiveIterator it; |
707 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
708 | if ( (*it) == resource ) { | 709 | if ( (*it) == resource ) { |
709 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 710 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
710 | return 0; | 711 | return 0; |
711 | else | 712 | else |
712 | return (*it)->requestSaveTicket(); | 713 | return (*it)->requestSaveTicket(); |
713 | } | 714 | } |
714 | } | 715 | } |
715 | 716 | ||
716 | return 0; | 717 | return 0; |
717 | } | 718 | } |
718 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 719 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
719 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 720 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
720 | { | 721 | { |
721 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 722 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
722 | //qDebug("block insert "); | 723 | //qDebug("block insert "); |
723 | return; | 724 | return; |
724 | } | 725 | } |
725 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 726 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
726 | bool found = false; | 727 | bool found = false; |
727 | Addressee::List::Iterator it; | 728 | Addressee::List::Iterator it; |
728 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 729 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
729 | if ( a.uid() == (*it).uid() ) { | 730 | if ( a.uid() == (*it).uid() ) { |
730 | 731 | ||
731 | bool changed = false; | 732 | bool changed = false; |
732 | Addressee addr = a; | 733 | Addressee addr = a; |
733 | if ( addr != (*it) ) | 734 | if ( addr != (*it) ) |
734 | changed = true; | 735 | changed = true; |
735 | 736 | ||
736 | if ( takeResource ) { | 737 | if ( takeResource ) { |
737 | Resource * res = (*it).resource(); | 738 | Resource * res = (*it).resource(); |
738 | (*it) = a; | 739 | (*it) = a; |
739 | (*it).setResource( res ); | 740 | (*it).setResource( res ); |
740 | } else { | 741 | } else { |
741 | (*it) = a; | 742 | (*it) = a; |
742 | if ( (*it).resource() == 0 ) | 743 | if ( (*it).resource() == 0 ) |
743 | (*it).setResource( standardResource() ); | 744 | (*it).setResource( standardResource() ); |
744 | } | 745 | } |
745 | if ( changed ) { | 746 | if ( changed ) { |
746 | if ( setRev ) { | 747 | if ( setRev ) { |
747 | 748 | ||
748 | // get rid of micro seconds | 749 | // get rid of micro seconds |
749 | QDateTime dt = QDateTime::currentDateTime(); | 750 | QDateTime dt = QDateTime::currentDateTime(); |
750 | QTime t = dt.time(); | 751 | QTime t = dt.time(); |
751 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 752 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
752 | (*it).setRevision( dt ); | 753 | (*it).setRevision( dt ); |
753 | } | 754 | } |
754 | (*it).setChanged( true ); | 755 | (*it).setChanged( true ); |
755 | } | 756 | } |
756 | 757 | ||
757 | found = true; | 758 | found = true; |
758 | } else { | 759 | } else { |
759 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 760 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
760 | QString name = (*it).uid().mid( 19 ); | 761 | QString name = (*it).uid().mid( 19 ); |
761 | Addressee b = a; | 762 | Addressee b = a; |
762 | QString id = b.getID( name ); | 763 | QString id = b.getID( name ); |
763 | if ( ! id.isEmpty() ) { | 764 | if ( ! id.isEmpty() ) { |
764 | QString des = (*it).note(); | 765 | QString des = (*it).note(); |
765 | int startN; | 766 | int startN; |
766 | if( (startN = des.find( id ) ) >= 0 ) { | 767 | if( (startN = des.find( id ) ) >= 0 ) { |
767 | int endN = des.find( ",", startN+1 ); | 768 | int endN = des.find( ",", startN+1 ); |
768 | des = des.left( startN ) + des.mid( endN+1 ); | 769 | des = des.left( startN ) + des.mid( endN+1 ); |
769 | (*it).setNote( des ); | 770 | (*it).setNote( des ); |
770 | } | 771 | } |
771 | } | 772 | } |
772 | } | 773 | } |
773 | } | 774 | } |
774 | } | 775 | } |
775 | if ( found ) | 776 | if ( found ) |
776 | return; | 777 | return; |
777 | d->mAddressees.append( a ); | 778 | d->mAddressees.append( a ); |
778 | Addressee& addr = d->mAddressees.last(); | 779 | Addressee& addr = d->mAddressees.last(); |
779 | if ( addr.resource() == 0 ) | 780 | if ( addr.resource() == 0 ) |
780 | addr.setResource( standardResource() ); | 781 | addr.setResource( standardResource() ); |
781 | 782 | ||
782 | addr.setChanged( true ); | 783 | addr.setChanged( true ); |
783 | } | 784 | } |
784 | 785 | ||
785 | void AddressBook::removeAddressee( const Addressee &a ) | 786 | void AddressBook::removeAddressee( const Addressee &a ) |
786 | { | 787 | { |
787 | Iterator it; | 788 | Iterator it; |
788 | Iterator it2; | 789 | Iterator it2; |
789 | bool found = false; | 790 | bool found = false; |
790 | for ( it = begin(); it != end(); ++it ) { | 791 | for ( it = begin(); it != end(); ++it ) { |
791 | if ( a.uid() == (*it).uid() ) { | 792 | if ( a.uid() == (*it).uid() ) { |
792 | found = true; | 793 | found = true; |
793 | it2 = it; | 794 | it2 = it; |
794 | } else { | 795 | } else { |
795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 796 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
796 | QString name = (*it).uid().mid( 19 ); | 797 | QString name = (*it).uid().mid( 19 ); |
797 | Addressee b = a; | 798 | Addressee b = a; |
798 | QString id = b.getID( name ); | 799 | QString id = b.getID( name ); |
799 | if ( ! id.isEmpty() ) { | 800 | if ( ! id.isEmpty() ) { |
800 | QString des = (*it).note(); | 801 | QString des = (*it).note(); |
801 | if( des.find( id ) < 0 ) { | 802 | if( des.find( id ) < 0 ) { |
802 | des += id + ","; | 803 | des += id + ","; |
803 | (*it).setNote( des ); | 804 | (*it).setNote( des ); |
804 | } | 805 | } |
805 | } | 806 | } |
806 | } | 807 | } |
807 | 808 | ||
808 | } | 809 | } |
809 | } | 810 | } |
810 | 811 | ||
811 | if ( found ) | 812 | if ( found ) |
812 | removeAddressee( it2 ); | 813 | removeAddressee( it2 ); |
813 | 814 | ||
814 | } | 815 | } |
815 | 816 | ||
816 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 817 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
817 | { | 818 | { |
818 | Iterator it = begin(); | 819 | Iterator it = begin(); |
819 | Iterator it2 ; | 820 | Iterator it2 ; |
820 | QDateTime dt ( QDate( 2004,1,1) ); | 821 | QDateTime dt ( QDate( 2004,1,1) ); |
821 | while ( it != end() ) { | 822 | while ( it != end() ) { |
822 | (*it).setRevision( dt ); | 823 | (*it).setRevision( dt ); |
823 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 824 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
824 | (*it).setIDStr(""); | 825 | (*it).setIDStr(""); |
825 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 826 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
826 | it2 = it; | 827 | it2 = it; |
827 | //qDebug("removing %s ",(*it).uid().latin1() ); | 828 | //qDebug("removing %s ",(*it).uid().latin1() ); |
828 | ++it; | 829 | ++it; |
829 | removeAddressee( it2 ); | 830 | removeAddressee( it2 ); |
830 | } else { | 831 | } else { |
831 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 832 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
832 | ++it; | 833 | ++it; |
833 | } | 834 | } |
834 | } | 835 | } |
835 | deleteRemovedAddressees(); | 836 | deleteRemovedAddressees(); |
836 | } | 837 | } |
837 | 838 | ||
838 | void AddressBook::removeAddressee( const Iterator &it ) | 839 | void AddressBook::removeAddressee( const Iterator &it ) |
839 | { | 840 | { |
840 | d->mRemovedAddressees.append( (*it) ); | 841 | d->mRemovedAddressees.append( (*it) ); |
841 | d->mAddressees.remove( it.d->mIt ); | 842 | d->mAddressees.remove( it.d->mIt ); |
842 | } | 843 | } |
843 | 844 | ||
844 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 845 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
845 | { | 846 | { |
846 | Iterator it; | 847 | Iterator it; |
847 | for ( it = begin(); it != end(); ++it ) { | 848 | for ( it = begin(); it != end(); ++it ) { |
848 | if ( a.uid() == (*it).uid() ) { | 849 | if ( a.uid() == (*it).uid() ) { |
849 | return it; | 850 | return it; |
850 | } | 851 | } |
851 | } | 852 | } |
852 | return end(); | 853 | return end(); |
853 | } | 854 | } |
854 | 855 | ||
855 | Addressee AddressBook::findByUid( const QString &uid ) | 856 | Addressee AddressBook::findByUid( const QString &uid ) |
856 | { | 857 | { |
857 | Iterator it; | 858 | Iterator it; |
858 | for ( it = begin(); it != end(); ++it ) { | 859 | for ( it = begin(); it != end(); ++it ) { |
859 | if ( uid == (*it).uid() ) { | 860 | if ( uid == (*it).uid() ) { |
860 | return *it; | 861 | return *it; |
861 | } | 862 | } |
862 | } | 863 | } |
863 | return Addressee(); | 864 | return Addressee(); |
864 | } | 865 | } |
865 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 866 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
866 | { | 867 | { |
867 | //qDebug("AddressBook::preExternSync "); | 868 | //qDebug("AddressBook::preExternSync "); |
868 | AddressBook::Iterator it; | 869 | AddressBook::Iterator it; |
869 | for ( it = begin(); it != end(); ++it ) { | 870 | for ( it = begin(); it != end(); ++it ) { |
870 | (*it).setID( csd, (*it).externalUID() ); | 871 | (*it).setID( csd, (*it).externalUID() ); |
871 | (*it).computeCsum( csd ); | 872 | (*it).computeCsum( csd ); |
872 | } | 873 | } |
873 | mergeAB( aBook ,csd ); | 874 | mergeAB( aBook ,csd ); |
874 | } | 875 | } |
875 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 876 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
876 | { | 877 | { |
877 | //qDebug("AddressBook::postExternSync "); | 878 | //qDebug("AddressBook::postExternSync "); |
878 | AddressBook::Iterator it; | 879 | AddressBook::Iterator it; |
879 | for ( it = begin(); it != end(); ++it ) { | 880 | for ( it = begin(); it != end(); ++it ) { |
880 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 881 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
881 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 882 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
882 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 883 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
883 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 884 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
884 | if ( ad.isEmpty() ) { | 885 | if ( ad.isEmpty() ) { |
885 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 886 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
886 | } else { | 887 | } else { |
887 | (*it).computeCsum( csd ); | 888 | (*it).computeCsum( csd ); |
888 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 889 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
889 | ad.setID( csd, (*it).externalUID() ); | 890 | ad.setID( csd, (*it).externalUID() ); |
890 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 891 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
891 | aBook->insertAddressee( ad ); | 892 | aBook->insertAddressee( ad ); |
892 | } | 893 | } |
893 | } | 894 | } |
894 | } | 895 | } |
895 | } | 896 | } |
896 | 897 | ||
897 | bool AddressBook::containsExternalUid( const QString& uid ) | 898 | bool AddressBook::containsExternalUid( const QString& uid ) |
898 | { | 899 | { |
899 | Iterator it; | 900 | Iterator it; |
900 | for ( it = begin(); it != end(); ++it ) { | 901 | for ( it = begin(); it != end(); ++it ) { |
901 | if ( uid == (*it).externalUID( ) ) | 902 | if ( uid == (*it).externalUID( ) ) |
902 | return true; | 903 | return true; |
903 | } | 904 | } |
904 | return false; | 905 | return false; |
905 | } | 906 | } |
906 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 907 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
907 | { | 908 | { |
908 | Iterator it; | 909 | Iterator it; |
909 | for ( it = begin(); it != end(); ++it ) { | 910 | for ( it = begin(); it != end(); ++it ) { |
910 | if ( uid == (*it).getID( profile ) ) | 911 | if ( uid == (*it).getID( profile ) ) |
911 | return (*it); | 912 | return (*it); |
912 | } | 913 | } |
913 | return Addressee(); | 914 | return Addressee(); |
914 | } | 915 | } |
915 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 916 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
916 | { | 917 | { |
917 | Iterator it; | 918 | Iterator it; |
918 | Addressee ad; | 919 | Addressee ad; |
919 | for ( it = begin(); it != end(); ++it ) { | 920 | for ( it = begin(); it != end(); ++it ) { |
920 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 921 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
921 | if ( !ad.isEmpty() ) { | 922 | if ( !ad.isEmpty() ) { |
922 | (*it).mergeContact( ad ); | 923 | (*it).mergeContact( ad ); |
923 | } | 924 | } |
924 | } | 925 | } |
925 | #if 0 | 926 | #if 0 |
926 | // test only | 927 | // test only |
927 | for ( it = begin(); it != end(); ++it ) { | 928 | for ( it = begin(); it != end(); ++it ) { |
928 | 929 | ||
929 | qDebug("uid %s ", (*it).uid().latin1()); | 930 | qDebug("uid %s ", (*it).uid().latin1()); |
930 | } | 931 | } |
931 | #endif | 932 | #endif |
932 | } | 933 | } |
933 | 934 | ||
934 | #if 0 | 935 | #if 0 |
935 | Addressee::List AddressBook::getExternLastSyncAddressees() | 936 | Addressee::List AddressBook::getExternLastSyncAddressees() |
936 | { | 937 | { |
937 | Addressee::List results; | 938 | Addressee::List results; |
938 | 939 | ||
939 | Iterator it; | 940 | Iterator it; |
940 | for ( it = begin(); it != end(); ++it ) { | 941 | for ( it = begin(); it != end(); ++it ) { |
941 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 942 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
942 | if ( (*it).familyName().left(4) == "!E: " ) | 943 | if ( (*it).familyName().left(4) == "!E: " ) |
943 | results.append( *it ); | 944 | results.append( *it ); |
944 | } | 945 | } |
945 | } | 946 | } |
946 | 947 | ||
947 | return results; | 948 | return results; |
948 | } | 949 | } |
949 | #endif | 950 | #endif |
950 | void AddressBook::resetTempSyncStat() | 951 | void AddressBook::resetTempSyncStat() |
951 | { | 952 | { |
952 | Iterator it; | 953 | Iterator it; |
953 | for ( it = begin(); it != end(); ++it ) { | 954 | for ( it = begin(); it != end(); ++it ) { |
954 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 955 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
955 | } | 956 | } |
956 | 957 | ||
957 | } | 958 | } |
958 | 959 | ||
959 | QStringList AddressBook:: uidList() | 960 | QStringList AddressBook:: uidList() |
960 | { | 961 | { |
961 | QStringList results; | 962 | QStringList results; |
962 | Iterator it; | 963 | Iterator it; |
963 | for ( it = begin(); it != end(); ++it ) { | 964 | for ( it = begin(); it != end(); ++it ) { |
964 | results.append( (*it).uid() ); | 965 | results.append( (*it).uid() ); |
965 | } | 966 | } |
966 | return results; | 967 | return results; |
967 | } | 968 | } |
968 | 969 | ||
969 | 970 | ||
970 | Addressee::List AddressBook::allAddressees() | 971 | Addressee::List AddressBook::allAddressees() |
971 | { | 972 | { |
972 | return d->mAddressees; | 973 | return d->mAddressees; |
973 | 974 | ||
974 | } | 975 | } |
975 | 976 | ||
976 | Addressee::List AddressBook::findByName( const QString &name ) | 977 | Addressee::List AddressBook::findByName( const QString &name ) |
977 | { | 978 | { |
978 | Addressee::List results; | 979 | Addressee::List results; |
979 | 980 | ||
980 | Iterator it; | 981 | Iterator it; |
981 | for ( it = begin(); it != end(); ++it ) { | 982 | for ( it = begin(); it != end(); ++it ) { |
982 | if ( name == (*it).realName() ) { | 983 | if ( name == (*it).realName() ) { |
983 | results.append( *it ); | 984 | results.append( *it ); |
984 | } | 985 | } |
985 | } | 986 | } |
986 | 987 | ||
987 | return results; | 988 | return results; |
988 | } | 989 | } |
989 | 990 | ||
990 | Addressee::List AddressBook::findByEmail( const QString &email ) | 991 | Addressee::List AddressBook::findByEmail( const QString &email ) |
991 | { | 992 | { |
992 | Addressee::List results; | 993 | Addressee::List results; |
993 | QStringList mailList; | 994 | QStringList mailList; |
994 | 995 | ||
995 | Iterator it; | 996 | Iterator it; |
996 | for ( it = begin(); it != end(); ++it ) { | 997 | for ( it = begin(); it != end(); ++it ) { |
997 | mailList = (*it).emails(); | 998 | mailList = (*it).emails(); |
998 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 999 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
999 | if ( email == (*ite) ) { | 1000 | if ( email == (*ite) ) { |
1000 | results.append( *it ); | 1001 | results.append( *it ); |
1001 | } | 1002 | } |
1002 | } | 1003 | } |
1003 | } | 1004 | } |
1004 | 1005 | ||
1005 | return results; | 1006 | return results; |
1006 | } | 1007 | } |
1007 | 1008 | ||
1008 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1009 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1009 | { | 1010 | { |
1010 | Addressee::List results; | 1011 | Addressee::List results; |
1011 | 1012 | ||
1012 | Iterator it; | 1013 | Iterator it; |
1013 | for ( it = begin(); it != end(); ++it ) { | 1014 | for ( it = begin(); it != end(); ++it ) { |
1014 | if ( (*it).hasCategory( category) ) { | 1015 | if ( (*it).hasCategory( category) ) { |
1015 | results.append( *it ); | 1016 | results.append( *it ); |
1016 | } | 1017 | } |
1017 | } | 1018 | } |
1018 | 1019 | ||
1019 | return results; | 1020 | return results; |
1020 | } | 1021 | } |
1021 | 1022 | ||
1022 | void AddressBook::dump() const | 1023 | void AddressBook::dump() const |
1023 | { | 1024 | { |
1024 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1025 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1025 | 1026 | ||
1026 | ConstIterator it; | 1027 | ConstIterator it; |
1027 | for( it = begin(); it != end(); ++it ) { | 1028 | for( it = begin(); it != end(); ++it ) { |
1028 | (*it).dump(); | 1029 | (*it).dump(); |
1029 | } | 1030 | } |
1030 | 1031 | ||
1031 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1032 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1032 | } | 1033 | } |
1033 | 1034 | ||
1034 | QString AddressBook::identifier() | 1035 | QString AddressBook::identifier() |
1035 | { | 1036 | { |
1036 | QStringList identifier; | 1037 | QStringList identifier; |
1037 | 1038 | ||
1038 | 1039 | ||
1039 | KRES::Manager<Resource>::ActiveIterator it; | 1040 | KRES::Manager<Resource>::ActiveIterator it; |
1040 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1041 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1041 | if ( !(*it)->identifier().isEmpty() ) | 1042 | if ( !(*it)->identifier().isEmpty() ) |
1042 | identifier.append( (*it)->identifier() ); | 1043 | identifier.append( (*it)->identifier() ); |
1043 | } | 1044 | } |
1044 | 1045 | ||
1045 | return identifier.join( ":" ); | 1046 | return identifier.join( ":" ); |
1046 | } | 1047 | } |
1047 | 1048 | ||
1048 | Field::List AddressBook::fields( int category ) | 1049 | Field::List AddressBook::fields( int category ) |
1049 | { | 1050 | { |
1050 | if ( d->mAllFields.isEmpty() ) { | 1051 | if ( d->mAllFields.isEmpty() ) { |
1051 | d->mAllFields = Field::allFields(); | 1052 | d->mAllFields = Field::allFields(); |
1052 | } | 1053 | } |
1053 | 1054 | ||
1054 | if ( category == Field::All ) return d->mAllFields; | 1055 | if ( category == Field::All ) return d->mAllFields; |
1055 | 1056 | ||
1056 | Field::List result; | 1057 | Field::List result; |
1057 | Field::List::ConstIterator it; | 1058 | Field::List::ConstIterator it; |
1058 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1059 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1059 | if ( (*it)->category() & category ) result.append( *it ); | 1060 | if ( (*it)->category() & category ) result.append( *it ); |
1060 | } | 1061 | } |
1061 | 1062 | ||
1062 | return result; | 1063 | return result; |
1063 | } | 1064 | } |
1064 | 1065 | ||
1065 | bool AddressBook::addCustomField( const QString &label, int category, | 1066 | bool AddressBook::addCustomField( const QString &label, int category, |
1066 | const QString &key, const QString &app ) | 1067 | const QString &key, const QString &app ) |
1067 | { | 1068 | { |
1068 | if ( d->mAllFields.isEmpty() ) { | 1069 | if ( d->mAllFields.isEmpty() ) { |
1069 | d->mAllFields = Field::allFields(); | 1070 | d->mAllFields = Field::allFields(); |
1070 | } | 1071 | } |
1071 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1072 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1072 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1073 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1073 | 1074 | ||
1074 | QString k = key.isNull() ? label : key; | 1075 | QString k = key.isNull() ? label : key; |
1075 | 1076 | ||
1076 | Field *field = Field::createCustomField( label, category, k, a ); | 1077 | Field *field = Field::createCustomField( label, category, k, a ); |
1077 | 1078 | ||
1078 | if ( !field ) return false; | 1079 | if ( !field ) return false; |
1079 | 1080 | ||
1080 | d->mAllFields.append( field ); | 1081 | d->mAllFields.append( field ); |
1081 | 1082 | ||
1082 | return true; | 1083 | return true; |
1083 | } | 1084 | } |
1084 | 1085 | ||
1085 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1086 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1086 | { | 1087 | { |
1087 | if (!ab.d) return s; | 1088 | if (!ab.d) return s; |
1088 | 1089 | ||
1089 | return s << ab.d->mAddressees; | 1090 | return s << ab.d->mAddressees; |
1090 | } | 1091 | } |
1091 | 1092 | ||
1092 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1093 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1093 | { | 1094 | { |
1094 | if (!ab.d) return s; | 1095 | if (!ab.d) return s; |
1095 | 1096 | ||
1096 | s >> ab.d->mAddressees; | 1097 | s >> ab.d->mAddressees; |
1097 | 1098 | ||
1098 | return s; | 1099 | return s; |
1099 | } | 1100 | } |
1100 | 1101 | ||
1101 | bool AddressBook::addResource( Resource *resource ) | 1102 | bool AddressBook::addResource( Resource *resource ) |
1102 | { | 1103 | { |
1103 | if ( !resource->open() ) { | 1104 | if ( !resource->open() ) { |
1104 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1105 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1105 | return false; | 1106 | return false; |
1106 | } | 1107 | } |
1107 | 1108 | ||
1108 | resource->setAddressBook( this ); | 1109 | resource->setAddressBook( this ); |
1109 | 1110 | ||
1110 | d->mManager->add( resource ); | 1111 | d->mManager->add( resource ); |
1111 | return true; | 1112 | return true; |
1112 | } | 1113 | } |
1113 | 1114 | ||
1114 | bool AddressBook::removeResource( Resource *resource ) | 1115 | bool AddressBook::removeResource( Resource *resource ) |
1115 | { | 1116 | { |
1116 | resource->close(); | 1117 | resource->close(); |
1117 | 1118 | ||
1118 | if ( resource == standardResource() ) | 1119 | if ( resource == standardResource() ) |
1119 | d->mManager->setStandardResource( 0 ); | 1120 | d->mManager->setStandardResource( 0 ); |
1120 | 1121 | ||
1121 | resource->setAddressBook( 0 ); | 1122 | resource->setAddressBook( 0 ); |
1122 | 1123 | ||
1123 | d->mManager->remove( resource ); | 1124 | d->mManager->remove( resource ); |
1124 | return true; | 1125 | return true; |
1125 | } | 1126 | } |
1126 | 1127 | ||
1127 | QPtrList<Resource> AddressBook::resources() | 1128 | QPtrList<Resource> AddressBook::resources() |
1128 | { | 1129 | { |
1129 | QPtrList<Resource> list; | 1130 | QPtrList<Resource> list; |
1130 | 1131 | ||
1131 | // qDebug("AddressBook::resources() 1"); | 1132 | // qDebug("AddressBook::resources() 1"); |
1132 | 1133 | ||
1133 | KRES::Manager<Resource>::ActiveIterator it; | 1134 | KRES::Manager<Resource>::ActiveIterator it; |
1134 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1135 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1135 | list.append( *it ); | 1136 | list.append( *it ); |
1136 | 1137 | ||
1137 | return list; | 1138 | return list; |
1138 | } | 1139 | } |
1139 | 1140 | ||
1140 | /*US | 1141 | /*US |
1141 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1142 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1142 | { | 1143 | { |
1143 | delete d->mErrorHandler; | 1144 | delete d->mErrorHandler; |
1144 | d->mErrorHandler = handler; | 1145 | d->mErrorHandler = handler; |
1145 | } | 1146 | } |
1146 | */ | 1147 | */ |
1147 | 1148 | ||
1148 | void AddressBook::error( const QString& msg ) | 1149 | void AddressBook::error( const QString& msg ) |
1149 | { | 1150 | { |
1150 | /*US | 1151 | /*US |
1151 | if ( !d->mErrorHandler ) // create default error handler | 1152 | if ( !d->mErrorHandler ) // create default error handler |
1152 | d->mErrorHandler = new ConsoleErrorHandler; | 1153 | d->mErrorHandler = new ConsoleErrorHandler; |
1153 | 1154 | ||
1154 | if ( d->mErrorHandler ) | 1155 | if ( d->mErrorHandler ) |
1155 | d->mErrorHandler->error( msg ); | 1156 | d->mErrorHandler->error( msg ); |
1156 | else | 1157 | else |
1157 | kdError(5700) << "no error handler defined" << endl; | 1158 | kdError(5700) << "no error handler defined" << endl; |
1158 | */ | 1159 | */ |
1159 | kdDebug(5700) << "msg" << endl; | 1160 | kdDebug(5700) << "msg" << endl; |
1160 | qDebug(msg); | 1161 | qDebug(msg); |
1161 | } | 1162 | } |
1162 | 1163 | ||
1163 | void AddressBook::deleteRemovedAddressees() | 1164 | void AddressBook::deleteRemovedAddressees() |
1164 | { | 1165 | { |
1165 | Addressee::List::Iterator it; | 1166 | Addressee::List::Iterator it; |
1166 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1167 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1167 | Resource *resource = (*it).resource(); | 1168 | Resource *resource = (*it).resource(); |
1168 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1169 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1169 | resource->removeAddressee( *it ); | 1170 | resource->removeAddressee( *it ); |
1170 | } | 1171 | } |
1171 | 1172 | ||
1172 | d->mRemovedAddressees.clear(); | 1173 | d->mRemovedAddressees.clear(); |
1173 | } | 1174 | } |
1174 | 1175 | ||
1175 | void AddressBook::setStandardResource( Resource *resource ) | 1176 | void AddressBook::setStandardResource( Resource *resource ) |
1176 | { | 1177 | { |
1177 | // qDebug("AddressBook::setStandardResource 1"); | 1178 | // qDebug("AddressBook::setStandardResource 1"); |
1178 | d->mManager->setStandardResource( resource ); | 1179 | d->mManager->setStandardResource( resource ); |
1179 | } | 1180 | } |
1180 | 1181 | ||
1181 | Resource *AddressBook::standardResource() | 1182 | Resource *AddressBook::standardResource() |
1182 | { | 1183 | { |
1183 | return d->mManager->standardResource(); | 1184 | return d->mManager->standardResource(); |
1184 | } | 1185 | } |
1185 | 1186 | ||
1186 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1187 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1187 | { | 1188 | { |
1188 | return d->mManager; | 1189 | return d->mManager; |
1189 | } | 1190 | } |
1190 | 1191 | ||
1191 | void AddressBook::cleanUp() | 1192 | void AddressBook::cleanUp() |
1192 | { | 1193 | { |
1193 | KRES::Manager<Resource>::ActiveIterator it; | 1194 | KRES::Manager<Resource>::ActiveIterator it; |
1194 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1195 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1195 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1196 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1196 | (*it)->cleanUp(); | 1197 | (*it)->cleanUp(); |
1197 | } | 1198 | } |
1198 | } | 1199 | } |