-rw-r--r-- | kabc/addressbook.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ff05f7e..16927e2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,1024 +1,1032 @@ | |||
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 "addressbook.h" | 50 | #include "addressbook.h" |
51 | #include "resource.h" | 51 | #include "resource.h" |
52 | #include "vcardconverter.h" | 52 | #include "vcardconverter.h" |
53 | #include "vcardparser/vcardtool.h" | 53 | #include "vcardparser/vcardtool.h" |
54 | 54 | ||
55 | //US #include "addressbook.moc" | 55 | //US #include "addressbook.moc" |
56 | 56 | ||
57 | using namespace KABC; | 57 | using namespace KABC; |
58 | 58 | ||
59 | struct AddressBook::AddressBookData | 59 | struct AddressBook::AddressBookData |
60 | { | 60 | { |
61 | Addressee::List mAddressees; | 61 | Addressee::List mAddressees; |
62 | Addressee::List mRemovedAddressees; | 62 | Addressee::List mRemovedAddressees; |
63 | Field::List mAllFields; | 63 | Field::List mAllFields; |
64 | KConfig *mConfig; | 64 | KConfig *mConfig; |
65 | KRES::Manager<Resource> *mManager; | 65 | KRES::Manager<Resource> *mManager; |
66 | //US ErrorHandler *mErrorHandler; | 66 | //US ErrorHandler *mErrorHandler; |
67 | }; | 67 | }; |
68 | 68 | ||
69 | struct AddressBook::Iterator::IteratorData | 69 | struct AddressBook::Iterator::IteratorData |
70 | { | 70 | { |
71 | Addressee::List::Iterator mIt; | 71 | Addressee::List::Iterator mIt; |
72 | }; | 72 | }; |
73 | 73 | ||
74 | struct AddressBook::ConstIterator::ConstIteratorData | 74 | struct AddressBook::ConstIterator::ConstIteratorData |
75 | { | 75 | { |
76 | Addressee::List::ConstIterator mIt; | 76 | Addressee::List::ConstIterator mIt; |
77 | }; | 77 | }; |
78 | 78 | ||
79 | AddressBook::Iterator::Iterator() | 79 | AddressBook::Iterator::Iterator() |
80 | { | 80 | { |
81 | d = new IteratorData; | 81 | d = new IteratorData; |
82 | } | 82 | } |
83 | 83 | ||
84 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 84 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
85 | { | 85 | { |
86 | d = new IteratorData; | 86 | d = new IteratorData; |
87 | d->mIt = i.d->mIt; | 87 | d->mIt = i.d->mIt; |
88 | } | 88 | } |
89 | 89 | ||
90 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 90 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
91 | { | 91 | { |
92 | if( this == &i ) return *this; // guard against self assignment | 92 | if( this == &i ) return *this; // guard against self assignment |
93 | 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 |
94 | d = new IteratorData; | 94 | d = new IteratorData; |
95 | d->mIt = i.d->mIt; | 95 | d->mIt = i.d->mIt; |
96 | return *this; | 96 | return *this; |
97 | } | 97 | } |
98 | 98 | ||
99 | AddressBook::Iterator::~Iterator() | 99 | AddressBook::Iterator::~Iterator() |
100 | { | 100 | { |
101 | delete d; | 101 | delete d; |
102 | } | 102 | } |
103 | 103 | ||
104 | const Addressee &AddressBook::Iterator::operator*() const | 104 | const Addressee &AddressBook::Iterator::operator*() const |
105 | { | 105 | { |
106 | return *(d->mIt); | 106 | return *(d->mIt); |
107 | } | 107 | } |
108 | 108 | ||
109 | Addressee &AddressBook::Iterator::operator*() | 109 | Addressee &AddressBook::Iterator::operator*() |
110 | { | 110 | { |
111 | return *(d->mIt); | 111 | return *(d->mIt); |
112 | } | 112 | } |
113 | 113 | ||
114 | Addressee *AddressBook::Iterator::operator->() | 114 | Addressee *AddressBook::Iterator::operator->() |
115 | { | 115 | { |
116 | return &(*(d->mIt)); | 116 | return &(*(d->mIt)); |
117 | } | 117 | } |
118 | 118 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 119 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
120 | { | 120 | { |
121 | (d->mIt)++; | 121 | (d->mIt)++; |
122 | return *this; | 122 | return *this; |
123 | } | 123 | } |
124 | 124 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 125 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
126 | { | 126 | { |
127 | (d->mIt)++; | 127 | (d->mIt)++; |
128 | return *this; | 128 | return *this; |
129 | } | 129 | } |
130 | 130 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 131 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
132 | { | 132 | { |
133 | (d->mIt)--; | 133 | (d->mIt)--; |
134 | return *this; | 134 | return *this; |
135 | } | 135 | } |
136 | 136 | ||
137 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 137 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
138 | { | 138 | { |
139 | (d->mIt)--; | 139 | (d->mIt)--; |
140 | return *this; | 140 | return *this; |
141 | } | 141 | } |
142 | 142 | ||
143 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 143 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
144 | { | 144 | { |
145 | return ( d->mIt == it.d->mIt ); | 145 | return ( d->mIt == it.d->mIt ); |
146 | } | 146 | } |
147 | 147 | ||
148 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 148 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
149 | { | 149 | { |
150 | return ( d->mIt != it.d->mIt ); | 150 | return ( d->mIt != it.d->mIt ); |
151 | } | 151 | } |
152 | 152 | ||
153 | 153 | ||
154 | AddressBook::ConstIterator::ConstIterator() | 154 | AddressBook::ConstIterator::ConstIterator() |
155 | { | 155 | { |
156 | d = new ConstIteratorData; | 156 | d = new ConstIteratorData; |
157 | } | 157 | } |
158 | 158 | ||
159 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 159 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
160 | { | 160 | { |
161 | d = new ConstIteratorData; | 161 | d = new ConstIteratorData; |
162 | d->mIt = i.d->mIt; | 162 | d->mIt = i.d->mIt; |
163 | } | 163 | } |
164 | 164 | ||
165 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 165 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
166 | { | 166 | { |
167 | if( this == &i ) return *this; // guard for self assignment | 167 | if( this == &i ) return *this; // guard for self assignment |
168 | 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 |
169 | d = new ConstIteratorData; | 169 | d = new ConstIteratorData; |
170 | d->mIt = i.d->mIt; | 170 | d->mIt = i.d->mIt; |
171 | return *this; | 171 | return *this; |
172 | } | 172 | } |
173 | 173 | ||
174 | AddressBook::ConstIterator::~ConstIterator() | 174 | AddressBook::ConstIterator::~ConstIterator() |
175 | { | 175 | { |
176 | delete d; | 176 | delete d; |
177 | } | 177 | } |
178 | 178 | ||
179 | const Addressee &AddressBook::ConstIterator::operator*() const | 179 | const Addressee &AddressBook::ConstIterator::operator*() const |
180 | { | 180 | { |
181 | return *(d->mIt); | 181 | return *(d->mIt); |
182 | } | 182 | } |
183 | 183 | ||
184 | const Addressee* AddressBook::ConstIterator::operator->() const | 184 | const Addressee* AddressBook::ConstIterator::operator->() const |
185 | { | 185 | { |
186 | return &(*(d->mIt)); | 186 | return &(*(d->mIt)); |
187 | } | 187 | } |
188 | 188 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
190 | { | 190 | { |
191 | (d->mIt)++; | 191 | (d->mIt)++; |
192 | return *this; | 192 | return *this; |
193 | } | 193 | } |
194 | 194 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
196 | { | 196 | { |
197 | (d->mIt)++; | 197 | (d->mIt)++; |
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
202 | { | 202 | { |
203 | (d->mIt)--; | 203 | (d->mIt)--; |
204 | return *this; | 204 | return *this; |
205 | } | 205 | } |
206 | 206 | ||
207 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 207 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
208 | { | 208 | { |
209 | (d->mIt)--; | 209 | (d->mIt)--; |
210 | return *this; | 210 | return *this; |
211 | } | 211 | } |
212 | 212 | ||
213 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 213 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
214 | { | 214 | { |
215 | return ( d->mIt == it.d->mIt ); | 215 | return ( d->mIt == it.d->mIt ); |
216 | } | 216 | } |
217 | 217 | ||
218 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 218 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
219 | { | 219 | { |
220 | return ( d->mIt != it.d->mIt ); | 220 | return ( d->mIt != it.d->mIt ); |
221 | } | 221 | } |
222 | 222 | ||
223 | 223 | ||
224 | AddressBook::AddressBook() | 224 | AddressBook::AddressBook() |
225 | { | 225 | { |
226 | init(0, "contact"); | 226 | init(0, "contact"); |
227 | } | 227 | } |
228 | 228 | ||
229 | AddressBook::AddressBook( const QString &config ) | 229 | AddressBook::AddressBook( const QString &config ) |
230 | { | 230 | { |
231 | init(config, "contact"); | 231 | init(config, "contact"); |
232 | } | 232 | } |
233 | 233 | ||
234 | AddressBook::AddressBook( const QString &config, const QString &family ) | 234 | AddressBook::AddressBook( const QString &config, const QString &family ) |
235 | { | 235 | { |
236 | init(config, family); | 236 | init(config, family); |
237 | 237 | ||
238 | } | 238 | } |
239 | 239 | ||
240 | // the default family is "contact" | 240 | // the default family is "contact" |
241 | void AddressBook::init(const QString &config, const QString &family ) | 241 | void AddressBook::init(const QString &config, const QString &family ) |
242 | { | 242 | { |
243 | blockLSEchange = false; | 243 | blockLSEchange = false; |
244 | d = new AddressBookData; | 244 | d = new AddressBookData; |
245 | QString fami = family; | 245 | QString fami = family; |
246 | if (config != 0) { | 246 | if (config != 0) { |
247 | if ( family == "syncContact" ) { | 247 | if ( family == "syncContact" ) { |
248 | qDebug("creating sync config "); | 248 | qDebug("creating sync config "); |
249 | fami = "contact"; | 249 | fami = "contact"; |
250 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 250 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
251 | con->setGroup( "General" ); | 251 | con->setGroup( "General" ); |
252 | con->writeEntry( "ResourceKeys", QString("sync") ); | 252 | con->writeEntry( "ResourceKeys", QString("sync") ); |
253 | con->writeEntry( "Standard", QString("sync") ); | 253 | con->writeEntry( "Standard", QString("sync") ); |
254 | con->setGroup( "Resource_sync" ); | 254 | con->setGroup( "Resource_sync" ); |
255 | con->writeEntry( "FileName", config ); | 255 | con->writeEntry( "FileName", config ); |
256 | con->writeEntry( "FileFormat", QString("vcard") ); | 256 | con->writeEntry( "FileFormat", QString("vcard") ); |
257 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 257 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
258 | con->writeEntry( "ResourceName", QString("sync_res") ); | 258 | con->writeEntry( "ResourceName", QString("sync_res") ); |
259 | if ( config.right(4) == ".xml" ) | 259 | if ( config.right(4) == ".xml" ) |
260 | con->writeEntry( "ResourceType", QString("qtopia") ); | 260 | con->writeEntry( "ResourceType", QString("qtopia") ); |
261 | else if ( config == "sharp" ) { | 261 | else if ( config == "sharp" ) { |
262 | con->writeEntry( "ResourceType", QString("sharp") ); | 262 | con->writeEntry( "ResourceType", QString("sharp") ); |
263 | } else { | 263 | } else { |
264 | con->writeEntry( "ResourceType", QString("file") ); | 264 | con->writeEntry( "ResourceType", QString("file") ); |
265 | } | 265 | } |
266 | //con->sync(); | 266 | //con->sync(); |
267 | d->mConfig = con; | 267 | d->mConfig = con; |
268 | } | 268 | } |
269 | else | 269 | else |
270 | d->mConfig = new KConfig( locateLocal("config", config) ); | 270 | d->mConfig = new KConfig( locateLocal("config", config) ); |
271 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 271 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
272 | } | 272 | } |
273 | else { | 273 | else { |
274 | d->mConfig = 0; | 274 | d->mConfig = 0; |
275 | // qDebug("AddressBook::init 1 config=0"); | 275 | // qDebug("AddressBook::init 1 config=0"); |
276 | } | 276 | } |
277 | 277 | ||
278 | //US d->mErrorHandler = 0; | 278 | //US d->mErrorHandler = 0; |
279 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 279 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
280 | d->mManager->readConfig( d->mConfig ); | 280 | d->mManager->readConfig( d->mConfig ); |
281 | if ( family == "syncContact" ) { | 281 | if ( family == "syncContact" ) { |
282 | KRES::Manager<Resource> *manager = d->mManager; | 282 | KRES::Manager<Resource> *manager = d->mManager; |
283 | KRES::Manager<Resource>::ActiveIterator it; | 283 | KRES::Manager<Resource>::ActiveIterator it; |
284 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 284 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
285 | (*it)->setAddressBook( this ); | 285 | (*it)->setAddressBook( this ); |
286 | if ( !(*it)->open() ) | 286 | if ( !(*it)->open() ) |
287 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 287 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
288 | } | 288 | } |
289 | Resource *res = standardResource(); | 289 | Resource *res = standardResource(); |
290 | if ( !res ) { | 290 | if ( !res ) { |
291 | qDebug("ERROR: no standard resource"); | 291 | qDebug("ERROR: no standard resource"); |
292 | res = manager->createResource( "file" ); | 292 | res = manager->createResource( "file" ); |
293 | if ( res ) | 293 | if ( res ) |
294 | { | 294 | { |
295 | addResource( res ); | 295 | addResource( res ); |
296 | } | 296 | } |
297 | else | 297 | else |
298 | qDebug(" No resource available!!!"); | 298 | qDebug(" No resource available!!!"); |
299 | } | 299 | } |
300 | setStandardResource( res ); | 300 | setStandardResource( res ); |
301 | manager->writeConfig(); | 301 | manager->writeConfig(); |
302 | } | 302 | } |
303 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 303 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
304 | "X-Department", "KADDRESSBOOK" ); | 304 | "X-Department", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 305 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
306 | "X-Profession", "KADDRESSBOOK" ); | 306 | "X-Profession", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 307 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
308 | "X-AssistantsName", "KADDRESSBOOK" ); | 308 | "X-AssistantsName", "KADDRESSBOOK" ); |
309 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 309 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
310 | "X-ManagersName", "KADDRESSBOOK" ); | 310 | "X-ManagersName", "KADDRESSBOOK" ); |
311 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 311 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
312 | "X-SpousesName", "KADDRESSBOOK" ); | 312 | "X-SpousesName", "KADDRESSBOOK" ); |
313 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 313 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
314 | "X-Office", "KADDRESSBOOK" ); | 314 | "X-Office", "KADDRESSBOOK" ); |
315 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 315 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
316 | "X-IMAddress", "KADDRESSBOOK" ); | 316 | "X-IMAddress", "KADDRESSBOOK" ); |
317 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 317 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
318 | "X-Anniversary", "KADDRESSBOOK" ); | 318 | "X-Anniversary", "KADDRESSBOOK" ); |
319 | 319 | ||
320 | //US added this field to become compatible with Opie/qtopia addressbook | 320 | //US added this field to become compatible with Opie/qtopia addressbook |
321 | // 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. |
322 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 322 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
323 | "X-Gender", "KADDRESSBOOK" ); | 323 | "X-Gender", "KADDRESSBOOK" ); |
324 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 324 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
325 | "X-Children", "KADDRESSBOOK" ); | 325 | "X-Children", "KADDRESSBOOK" ); |
326 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 326 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
327 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 327 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
328 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 328 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
329 | "X-ExternalID", "KADDRESSBOOK" ); | 329 | "X-ExternalID", "KADDRESSBOOK" ); |
330 | } | 330 | } |
331 | 331 | ||
332 | AddressBook::~AddressBook() | 332 | AddressBook::~AddressBook() |
333 | { | 333 | { |
334 | delete d->mConfig; d->mConfig = 0; | 334 | delete d->mConfig; d->mConfig = 0; |
335 | delete d->mManager; d->mManager = 0; | 335 | delete d->mManager; d->mManager = 0; |
336 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 336 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
337 | delete d; d = 0; | 337 | delete d; d = 0; |
338 | } | 338 | } |
339 | 339 | ||
340 | bool AddressBook::load() | 340 | bool AddressBook::load() |
341 | { | 341 | { |
342 | 342 | ||
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | 345 | ||
346 | KRES::Manager<Resource>::ActiveIterator it; | 346 | KRES::Manager<Resource>::ActiveIterator it; |
347 | bool ok = true; | 347 | bool ok = true; |
348 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 348 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
349 | if ( !(*it)->load() ) { | 349 | if ( !(*it)->load() ) { |
350 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 350 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
351 | ok = false; | 351 | ok = false; |
352 | } | 352 | } |
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 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 406 | void AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
407 | { | 407 | { |
408 | 408 | ||
409 | if ( removeOld ) | 409 | if ( removeOld ) |
410 | setUntagged(); | 410 | setUntagged(); |
411 | KABC::Addressee::List list; | 411 | KABC::Addressee::List list; |
412 | QFile file( fileName ); | 412 | QFile file( fileName ); |
413 | file.open( IO_ReadOnly ); | 413 | file.open( IO_ReadOnly ); |
414 | QByteArray rawData = file.readAll(); | 414 | QByteArray rawData = file.readAll(); |
415 | file.close(); | 415 | file.close(); |
416 | QString data; | 416 | QString data; |
417 | if ( replaceLabel ) { | 417 | if ( replaceLabel ) { |
418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 418 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
419 | data.replace ( QRegExp("LABEL") , "ADR" ); | 419 | data.replace ( QRegExp("LABEL") , "ADR" ); |
420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 420 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
421 | } else | 421 | } else |
422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 422 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
423 | KABC::VCardTool tool; | 423 | KABC::VCardTool tool; |
424 | list = tool.parseVCards( data ); | 424 | list = tool.parseVCards( data ); |
425 | KABC::Addressee::List::Iterator it; | 425 | KABC::Addressee::List::Iterator it; |
426 | for ( it = list.begin(); it != list.end(); ++it ) { | 426 | for ( it = list.begin(); it != list.end(); ++it ) { |
427 | (*it).setResource( 0 ); | 427 | (*it).setResource( 0 ); |
428 | if ( replaceLabel ) | 428 | if ( replaceLabel ) |
429 | (*it).removeVoice(); | 429 | (*it).removeVoice(); |
430 | if ( removeOld ) | 430 | if ( removeOld ) |
431 | (*it).setTagged( true ); | 431 | (*it).setTagged( true ); |
432 | insertAddressee( (*it), false, true ); | 432 | insertAddressee( (*it), false, true ); |
433 | } | 433 | } |
434 | if ( removeOld ) | 434 | if ( removeOld ) |
435 | removeUntagged(); | 435 | removeUntagged(); |
436 | } | 436 | } |
437 | void AddressBook::setUntagged() | 437 | void AddressBook::setUntagged() |
438 | { | 438 | { |
439 | Iterator ait; | 439 | Iterator ait; |
440 | for ( ait = begin(); ait != end(); ++ait ) { | 440 | for ( ait = begin(); ait != end(); ++ait ) { |
441 | (*ait).setTagged( false ); | 441 | (*ait).setTagged( false ); |
442 | } | 442 | } |
443 | } | 443 | } |
444 | void AddressBook::removeUntagged() | 444 | void AddressBook::removeUntagged() |
445 | { | 445 | { |
446 | Iterator ait; | 446 | Iterator ait; |
447 | bool todelete = false; | ||
448 | Iterator todel; | ||
447 | for ( ait = begin(); ait != end(); ++ait ) { | 449 | for ( ait = begin(); ait != end(); ++ait ) { |
448 | if (!(*ait).tagged()) | 450 | if ( todelete ) |
449 | removeAddressee( ait ); | 451 | removeAddressee( todel ); |
450 | } | 452 | if (!(*ait).tagged()) { |
451 | 453 | todelete = true; | |
454 | todel = ait; | ||
455 | } else | ||
456 | todelete = false; | ||
457 | } | ||
458 | if ( todelete ) | ||
459 | removeAddressee( todel ); | ||
452 | deleteRemovedAddressees(); | 460 | deleteRemovedAddressees(); |
453 | } | 461 | } |
454 | bool AddressBook::saveAB() | 462 | bool AddressBook::saveAB() |
455 | { | 463 | { |
456 | bool ok = true; | 464 | bool ok = true; |
457 | 465 | ||
458 | deleteRemovedAddressees(); | 466 | deleteRemovedAddressees(); |
459 | Iterator ait; | 467 | Iterator ait; |
460 | for ( ait = begin(); ait != end(); ++ait ) { | 468 | for ( ait = begin(); ait != end(); ++ait ) { |
461 | if ( !(*ait).IDStr().isEmpty() ) { | 469 | if ( !(*ait).IDStr().isEmpty() ) { |
462 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 470 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
463 | } | 471 | } |
464 | } | 472 | } |
465 | KRES::Manager<Resource>::ActiveIterator it; | 473 | KRES::Manager<Resource>::ActiveIterator it; |
466 | KRES::Manager<Resource> *manager = d->mManager; | 474 | KRES::Manager<Resource> *manager = d->mManager; |
467 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 475 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
468 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 476 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
469 | Ticket *ticket = requestSaveTicket( *it ); | 477 | Ticket *ticket = requestSaveTicket( *it ); |
470 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 478 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
471 | if ( !ticket ) { | 479 | if ( !ticket ) { |
472 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 480 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
473 | .arg( (*it)->resourceName() ) ); | 481 | .arg( (*it)->resourceName() ) ); |
474 | return false; | 482 | return false; |
475 | } | 483 | } |
476 | 484 | ||
477 | //if ( !save( ticket ) ) | 485 | //if ( !save( ticket ) ) |
478 | if ( ticket->resource() ) { | 486 | if ( ticket->resource() ) { |
479 | if ( ! ticket->resource()->save( ticket ) ) | 487 | if ( ! ticket->resource()->save( ticket ) ) |
480 | ok = false; | 488 | ok = false; |
481 | } else | 489 | } else |
482 | ok = false; | 490 | ok = false; |
483 | 491 | ||
484 | } | 492 | } |
485 | } | 493 | } |
486 | return ok; | 494 | return ok; |
487 | } | 495 | } |
488 | 496 | ||
489 | AddressBook::Iterator AddressBook::begin() | 497 | AddressBook::Iterator AddressBook::begin() |
490 | { | 498 | { |
491 | Iterator it = Iterator(); | 499 | Iterator it = Iterator(); |
492 | it.d->mIt = d->mAddressees.begin(); | 500 | it.d->mIt = d->mAddressees.begin(); |
493 | return it; | 501 | return it; |
494 | } | 502 | } |
495 | 503 | ||
496 | AddressBook::ConstIterator AddressBook::begin() const | 504 | AddressBook::ConstIterator AddressBook::begin() const |
497 | { | 505 | { |
498 | ConstIterator it = ConstIterator(); | 506 | ConstIterator it = ConstIterator(); |
499 | it.d->mIt = d->mAddressees.begin(); | 507 | it.d->mIt = d->mAddressees.begin(); |
500 | return it; | 508 | return it; |
501 | } | 509 | } |
502 | 510 | ||
503 | AddressBook::Iterator AddressBook::end() | 511 | AddressBook::Iterator AddressBook::end() |
504 | { | 512 | { |
505 | Iterator it = Iterator(); | 513 | Iterator it = Iterator(); |
506 | it.d->mIt = d->mAddressees.end(); | 514 | it.d->mIt = d->mAddressees.end(); |
507 | return it; | 515 | return it; |
508 | } | 516 | } |
509 | 517 | ||
510 | AddressBook::ConstIterator AddressBook::end() const | 518 | AddressBook::ConstIterator AddressBook::end() const |
511 | { | 519 | { |
512 | ConstIterator it = ConstIterator(); | 520 | ConstIterator it = ConstIterator(); |
513 | it.d->mIt = d->mAddressees.end(); | 521 | it.d->mIt = d->mAddressees.end(); |
514 | return it; | 522 | return it; |
515 | } | 523 | } |
516 | 524 | ||
517 | void AddressBook::clear() | 525 | void AddressBook::clear() |
518 | { | 526 | { |
519 | d->mAddressees.clear(); | 527 | d->mAddressees.clear(); |
520 | } | 528 | } |
521 | 529 | ||
522 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 530 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
523 | { | 531 | { |
524 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 532 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
525 | 533 | ||
526 | if ( !resource ) | 534 | if ( !resource ) |
527 | { | 535 | { |
528 | qDebug("AddressBook::requestSaveTicket no resource" ); | 536 | qDebug("AddressBook::requestSaveTicket no resource" ); |
529 | resource = standardResource(); | 537 | resource = standardResource(); |
530 | } | 538 | } |
531 | 539 | ||
532 | KRES::Manager<Resource>::ActiveIterator it; | 540 | KRES::Manager<Resource>::ActiveIterator it; |
533 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 541 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
534 | if ( (*it) == resource ) { | 542 | if ( (*it) == resource ) { |
535 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 543 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
536 | return 0; | 544 | return 0; |
537 | else | 545 | else |
538 | return (*it)->requestSaveTicket(); | 546 | return (*it)->requestSaveTicket(); |
539 | } | 547 | } |
540 | } | 548 | } |
541 | 549 | ||
542 | return 0; | 550 | return 0; |
543 | } | 551 | } |
544 | 552 | ||
545 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 553 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
546 | { | 554 | { |
547 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 555 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
548 | //qDebug("block insert "); | 556 | //qDebug("block insert "); |
549 | return; | 557 | return; |
550 | } | 558 | } |
551 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 559 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
552 | bool found = false; | 560 | bool found = false; |
553 | Addressee::List::Iterator it; | 561 | Addressee::List::Iterator it; |
554 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 562 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
555 | if ( a.uid() == (*it).uid() ) { | 563 | if ( a.uid() == (*it).uid() ) { |
556 | 564 | ||
557 | bool changed = false; | 565 | bool changed = false; |
558 | Addressee addr = a; | 566 | Addressee addr = a; |
559 | if ( addr != (*it) ) | 567 | if ( addr != (*it) ) |
560 | changed = true; | 568 | changed = true; |
561 | 569 | ||
562 | if ( takeResource ) { | 570 | if ( takeResource ) { |
563 | Resource * res = (*it).resource(); | 571 | Resource * res = (*it).resource(); |
564 | (*it) = a; | 572 | (*it) = a; |
565 | (*it).setResource( res ); | 573 | (*it).setResource( res ); |
566 | } else { | 574 | } else { |
567 | (*it) = a; | 575 | (*it) = a; |
568 | if ( (*it).resource() == 0 ) | 576 | if ( (*it).resource() == 0 ) |
569 | (*it).setResource( standardResource() ); | 577 | (*it).setResource( standardResource() ); |
570 | } | 578 | } |
571 | if ( changed ) { | 579 | if ( changed ) { |
572 | if ( setRev ) { | 580 | if ( setRev ) { |
573 | 581 | ||
574 | // get rid of micro seconds | 582 | // get rid of micro seconds |
575 | QDateTime dt = QDateTime::currentDateTime(); | 583 | QDateTime dt = QDateTime::currentDateTime(); |
576 | QTime t = dt.time(); | 584 | QTime t = dt.time(); |
577 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 585 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
578 | (*it).setRevision( dt ); | 586 | (*it).setRevision( dt ); |
579 | } | 587 | } |
580 | (*it).setChanged( true ); | 588 | (*it).setChanged( true ); |
581 | } | 589 | } |
582 | 590 | ||
583 | found = true; | 591 | found = true; |
584 | } else { | 592 | } else { |
585 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 593 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
586 | QString name = (*it).uid().mid( 19 ); | 594 | QString name = (*it).uid().mid( 19 ); |
587 | Addressee b = a; | 595 | Addressee b = a; |
588 | QString id = b.getID( name ); | 596 | QString id = b.getID( name ); |
589 | if ( ! id.isEmpty() ) { | 597 | if ( ! id.isEmpty() ) { |
590 | QString des = (*it).note(); | 598 | QString des = (*it).note(); |
591 | int startN; | 599 | int startN; |
592 | if( (startN = des.find( id ) ) >= 0 ) { | 600 | if( (startN = des.find( id ) ) >= 0 ) { |
593 | int endN = des.find( ",", startN+1 ); | 601 | int endN = des.find( ",", startN+1 ); |
594 | des = des.left( startN ) + des.mid( endN+1 ); | 602 | des = des.left( startN ) + des.mid( endN+1 ); |
595 | (*it).setNote( des ); | 603 | (*it).setNote( des ); |
596 | } | 604 | } |
597 | } | 605 | } |
598 | } | 606 | } |
599 | } | 607 | } |
600 | } | 608 | } |
601 | if ( found ) | 609 | if ( found ) |
602 | return; | 610 | return; |
603 | d->mAddressees.append( a ); | 611 | d->mAddressees.append( a ); |
604 | Addressee& addr = d->mAddressees.last(); | 612 | Addressee& addr = d->mAddressees.last(); |
605 | if ( addr.resource() == 0 ) | 613 | if ( addr.resource() == 0 ) |
606 | addr.setResource( standardResource() ); | 614 | addr.setResource( standardResource() ); |
607 | 615 | ||
608 | addr.setChanged( true ); | 616 | addr.setChanged( true ); |
609 | } | 617 | } |
610 | 618 | ||
611 | void AddressBook::removeAddressee( const Addressee &a ) | 619 | void AddressBook::removeAddressee( const Addressee &a ) |
612 | { | 620 | { |
613 | Iterator it; | 621 | Iterator it; |
614 | Iterator it2; | 622 | Iterator it2; |
615 | bool found = false; | 623 | bool found = false; |
616 | for ( it = begin(); it != end(); ++it ) { | 624 | for ( it = begin(); it != end(); ++it ) { |
617 | if ( a.uid() == (*it).uid() ) { | 625 | if ( a.uid() == (*it).uid() ) { |
618 | found = true; | 626 | found = true; |
619 | it2 = it; | 627 | it2 = it; |
620 | } else { | 628 | } else { |
621 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 629 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
622 | QString name = (*it).uid().mid( 19 ); | 630 | QString name = (*it).uid().mid( 19 ); |
623 | Addressee b = a; | 631 | Addressee b = a; |
624 | QString id = b.getID( name ); | 632 | QString id = b.getID( name ); |
625 | if ( ! id.isEmpty() ) { | 633 | if ( ! id.isEmpty() ) { |
626 | QString des = (*it).note(); | 634 | QString des = (*it).note(); |
627 | if( des.find( id ) < 0 ) { | 635 | if( des.find( id ) < 0 ) { |
628 | des += id + ","; | 636 | des += id + ","; |
629 | (*it).setNote( des ); | 637 | (*it).setNote( des ); |
630 | } | 638 | } |
631 | } | 639 | } |
632 | } | 640 | } |
633 | 641 | ||
634 | } | 642 | } |
635 | } | 643 | } |
636 | 644 | ||
637 | if ( found ) | 645 | if ( found ) |
638 | removeAddressee( it2 ); | 646 | removeAddressee( it2 ); |
639 | 647 | ||
640 | } | 648 | } |
641 | 649 | ||
642 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 650 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
643 | { | 651 | { |
644 | Iterator it = begin(); | 652 | Iterator it = begin(); |
645 | Iterator it2 ; | 653 | Iterator it2 ; |
646 | QDateTime dt ( QDate( 2004,1,1) ); | 654 | QDateTime dt ( QDate( 2004,1,1) ); |
647 | while ( it != end() ) { | 655 | while ( it != end() ) { |
648 | (*it).setRevision( dt ); | 656 | (*it).setRevision( dt ); |
649 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 657 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
650 | (*it).setIDStr(""); | 658 | (*it).setIDStr(""); |
651 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 659 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
652 | it2 = it; | 660 | it2 = it; |
653 | //qDebug("removing %s ",(*it).uid().latin1() ); | 661 | //qDebug("removing %s ",(*it).uid().latin1() ); |
654 | ++it; | 662 | ++it; |
655 | removeAddressee( it2 ); | 663 | removeAddressee( it2 ); |
656 | } else { | 664 | } else { |
657 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 665 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
658 | ++it; | 666 | ++it; |
659 | } | 667 | } |
660 | } | 668 | } |
661 | deleteRemovedAddressees(); | 669 | deleteRemovedAddressees(); |
662 | } | 670 | } |
663 | 671 | ||
664 | void AddressBook::removeAddressee( const Iterator &it ) | 672 | void AddressBook::removeAddressee( const Iterator &it ) |
665 | { | 673 | { |
666 | d->mRemovedAddressees.append( (*it) ); | 674 | d->mRemovedAddressees.append( (*it) ); |
667 | d->mAddressees.remove( it.d->mIt ); | 675 | d->mAddressees.remove( it.d->mIt ); |
668 | } | 676 | } |
669 | 677 | ||
670 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 678 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
671 | { | 679 | { |
672 | Iterator it; | 680 | Iterator it; |
673 | for ( it = begin(); it != end(); ++it ) { | 681 | for ( it = begin(); it != end(); ++it ) { |
674 | if ( a.uid() == (*it).uid() ) { | 682 | if ( a.uid() == (*it).uid() ) { |
675 | return it; | 683 | return it; |
676 | } | 684 | } |
677 | } | 685 | } |
678 | return end(); | 686 | return end(); |
679 | } | 687 | } |
680 | 688 | ||
681 | Addressee AddressBook::findByUid( const QString &uid ) | 689 | Addressee AddressBook::findByUid( const QString &uid ) |
682 | { | 690 | { |
683 | Iterator it; | 691 | Iterator it; |
684 | for ( it = begin(); it != end(); ++it ) { | 692 | for ( it = begin(); it != end(); ++it ) { |
685 | if ( uid == (*it).uid() ) { | 693 | if ( uid == (*it).uid() ) { |
686 | return *it; | 694 | return *it; |
687 | } | 695 | } |
688 | } | 696 | } |
689 | return Addressee(); | 697 | return Addressee(); |
690 | } | 698 | } |
691 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 699 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
692 | { | 700 | { |
693 | //qDebug("AddressBook::preExternSync "); | 701 | //qDebug("AddressBook::preExternSync "); |
694 | AddressBook::Iterator it; | 702 | AddressBook::Iterator it; |
695 | for ( it = begin(); it != end(); ++it ) { | 703 | for ( it = begin(); it != end(); ++it ) { |
696 | (*it).setID( csd, (*it).externalUID() ); | 704 | (*it).setID( csd, (*it).externalUID() ); |
697 | (*it).computeCsum( csd ); | 705 | (*it).computeCsum( csd ); |
698 | } | 706 | } |
699 | mergeAB( aBook ,csd ); | 707 | mergeAB( aBook ,csd ); |
700 | } | 708 | } |
701 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 709 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
702 | { | 710 | { |
703 | //qDebug("AddressBook::postExternSync "); | 711 | //qDebug("AddressBook::postExternSync "); |
704 | AddressBook::Iterator it; | 712 | AddressBook::Iterator it; |
705 | for ( it = begin(); it != end(); ++it ) { | 713 | for ( it = begin(); it != end(); ++it ) { |
706 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 714 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
707 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 715 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
708 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 716 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
709 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 717 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
710 | if ( ad.isEmpty() ) { | 718 | if ( ad.isEmpty() ) { |
711 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 719 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
712 | } else { | 720 | } else { |
713 | (*it).computeCsum( csd ); | 721 | (*it).computeCsum( csd ); |
714 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 722 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
715 | ad.setID( csd, (*it).externalUID() ); | 723 | ad.setID( csd, (*it).externalUID() ); |
716 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 724 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
717 | aBook->insertAddressee( ad ); | 725 | aBook->insertAddressee( ad ); |
718 | } | 726 | } |
719 | } | 727 | } |
720 | } | 728 | } |
721 | } | 729 | } |
722 | 730 | ||
723 | bool AddressBook::containsExternalUid( const QString& uid ) | 731 | bool AddressBook::containsExternalUid( const QString& uid ) |
724 | { | 732 | { |
725 | Iterator it; | 733 | Iterator it; |
726 | for ( it = begin(); it != end(); ++it ) { | 734 | for ( it = begin(); it != end(); ++it ) { |
727 | if ( uid == (*it).externalUID( ) ) | 735 | if ( uid == (*it).externalUID( ) ) |
728 | return true; | 736 | return true; |
729 | } | 737 | } |
730 | return false; | 738 | return false; |
731 | } | 739 | } |
732 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 740 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
733 | { | 741 | { |
734 | Iterator it; | 742 | Iterator it; |
735 | for ( it = begin(); it != end(); ++it ) { | 743 | for ( it = begin(); it != end(); ++it ) { |
736 | if ( uid == (*it).getID( profile ) ) | 744 | if ( uid == (*it).getID( profile ) ) |
737 | return (*it); | 745 | return (*it); |
738 | } | 746 | } |
739 | return Addressee(); | 747 | return Addressee(); |
740 | } | 748 | } |
741 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 749 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
742 | { | 750 | { |
743 | Iterator it; | 751 | Iterator it; |
744 | Addressee ad; | 752 | Addressee ad; |
745 | for ( it = begin(); it != end(); ++it ) { | 753 | for ( it = begin(); it != end(); ++it ) { |
746 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 754 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
747 | if ( !ad.isEmpty() ) { | 755 | if ( !ad.isEmpty() ) { |
748 | (*it).mergeContact( ad ); | 756 | (*it).mergeContact( ad ); |
749 | } | 757 | } |
750 | } | 758 | } |
751 | #if 0 | 759 | #if 0 |
752 | // test only | 760 | // test only |
753 | for ( it = begin(); it != end(); ++it ) { | 761 | for ( it = begin(); it != end(); ++it ) { |
754 | 762 | ||
755 | qDebug("uid %s ", (*it).uid().latin1()); | 763 | qDebug("uid %s ", (*it).uid().latin1()); |
756 | } | 764 | } |
757 | #endif | 765 | #endif |
758 | } | 766 | } |
759 | 767 | ||
760 | #if 0 | 768 | #if 0 |
761 | Addressee::List AddressBook::getExternLastSyncAddressees() | 769 | Addressee::List AddressBook::getExternLastSyncAddressees() |
762 | { | 770 | { |
763 | Addressee::List results; | 771 | Addressee::List results; |
764 | 772 | ||
765 | Iterator it; | 773 | Iterator it; |
766 | for ( it = begin(); it != end(); ++it ) { | 774 | for ( it = begin(); it != end(); ++it ) { |
767 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 775 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
768 | if ( (*it).familyName().left(4) == "!E: " ) | 776 | if ( (*it).familyName().left(4) == "!E: " ) |
769 | results.append( *it ); | 777 | results.append( *it ); |
770 | } | 778 | } |
771 | } | 779 | } |
772 | 780 | ||
773 | return results; | 781 | return results; |
774 | } | 782 | } |
775 | #endif | 783 | #endif |
776 | void AddressBook::resetTempSyncStat() | 784 | void AddressBook::resetTempSyncStat() |
777 | { | 785 | { |
778 | Iterator it; | 786 | Iterator it; |
779 | for ( it = begin(); it != end(); ++it ) { | 787 | for ( it = begin(); it != end(); ++it ) { |
780 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 788 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
781 | } | 789 | } |
782 | 790 | ||
783 | } | 791 | } |
784 | 792 | ||
785 | QStringList AddressBook:: uidList() | 793 | QStringList AddressBook:: uidList() |
786 | { | 794 | { |
787 | QStringList results; | 795 | QStringList results; |
788 | Iterator it; | 796 | Iterator it; |
789 | for ( it = begin(); it != end(); ++it ) { | 797 | for ( it = begin(); it != end(); ++it ) { |
790 | results.append( (*it).uid() ); | 798 | results.append( (*it).uid() ); |
791 | } | 799 | } |
792 | return results; | 800 | return results; |
793 | } | 801 | } |
794 | 802 | ||
795 | 803 | ||
796 | Addressee::List AddressBook::allAddressees() | 804 | Addressee::List AddressBook::allAddressees() |
797 | { | 805 | { |
798 | return d->mAddressees; | 806 | return d->mAddressees; |
799 | 807 | ||
800 | } | 808 | } |
801 | 809 | ||
802 | Addressee::List AddressBook::findByName( const QString &name ) | 810 | Addressee::List AddressBook::findByName( const QString &name ) |
803 | { | 811 | { |
804 | Addressee::List results; | 812 | Addressee::List results; |
805 | 813 | ||
806 | Iterator it; | 814 | Iterator it; |
807 | for ( it = begin(); it != end(); ++it ) { | 815 | for ( it = begin(); it != end(); ++it ) { |
808 | if ( name == (*it).realName() ) { | 816 | if ( name == (*it).realName() ) { |
809 | results.append( *it ); | 817 | results.append( *it ); |
810 | } | 818 | } |
811 | } | 819 | } |
812 | 820 | ||
813 | return results; | 821 | return results; |
814 | } | 822 | } |
815 | 823 | ||
816 | Addressee::List AddressBook::findByEmail( const QString &email ) | 824 | Addressee::List AddressBook::findByEmail( const QString &email ) |
817 | { | 825 | { |
818 | Addressee::List results; | 826 | Addressee::List results; |
819 | QStringList mailList; | 827 | QStringList mailList; |
820 | 828 | ||
821 | Iterator it; | 829 | Iterator it; |
822 | for ( it = begin(); it != end(); ++it ) { | 830 | for ( it = begin(); it != end(); ++it ) { |
823 | mailList = (*it).emails(); | 831 | mailList = (*it).emails(); |
824 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 832 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
825 | if ( email == (*ite) ) { | 833 | if ( email == (*ite) ) { |
826 | results.append( *it ); | 834 | results.append( *it ); |
827 | } | 835 | } |
828 | } | 836 | } |
829 | } | 837 | } |
830 | 838 | ||
831 | return results; | 839 | return results; |
832 | } | 840 | } |
833 | 841 | ||
834 | Addressee::List AddressBook::findByCategory( const QString &category ) | 842 | Addressee::List AddressBook::findByCategory( const QString &category ) |
835 | { | 843 | { |
836 | Addressee::List results; | 844 | Addressee::List results; |
837 | 845 | ||
838 | Iterator it; | 846 | Iterator it; |
839 | for ( it = begin(); it != end(); ++it ) { | 847 | for ( it = begin(); it != end(); ++it ) { |
840 | if ( (*it).hasCategory( category) ) { | 848 | if ( (*it).hasCategory( category) ) { |
841 | results.append( *it ); | 849 | results.append( *it ); |
842 | } | 850 | } |
843 | } | 851 | } |
844 | 852 | ||
845 | return results; | 853 | return results; |
846 | } | 854 | } |
847 | 855 | ||
848 | void AddressBook::dump() const | 856 | void AddressBook::dump() const |
849 | { | 857 | { |
850 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 858 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
851 | 859 | ||
852 | ConstIterator it; | 860 | ConstIterator it; |
853 | for( it = begin(); it != end(); ++it ) { | 861 | for( it = begin(); it != end(); ++it ) { |
854 | (*it).dump(); | 862 | (*it).dump(); |
855 | } | 863 | } |
856 | 864 | ||
857 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 865 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
858 | } | 866 | } |
859 | 867 | ||
860 | QString AddressBook::identifier() | 868 | QString AddressBook::identifier() |
861 | { | 869 | { |
862 | QStringList identifier; | 870 | QStringList identifier; |
863 | 871 | ||
864 | 872 | ||
865 | KRES::Manager<Resource>::ActiveIterator it; | 873 | KRES::Manager<Resource>::ActiveIterator it; |
866 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 874 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
867 | if ( !(*it)->identifier().isEmpty() ) | 875 | if ( !(*it)->identifier().isEmpty() ) |
868 | identifier.append( (*it)->identifier() ); | 876 | identifier.append( (*it)->identifier() ); |
869 | } | 877 | } |
870 | 878 | ||
871 | return identifier.join( ":" ); | 879 | return identifier.join( ":" ); |
872 | } | 880 | } |
873 | 881 | ||
874 | Field::List AddressBook::fields( int category ) | 882 | Field::List AddressBook::fields( int category ) |
875 | { | 883 | { |
876 | if ( d->mAllFields.isEmpty() ) { | 884 | if ( d->mAllFields.isEmpty() ) { |
877 | d->mAllFields = Field::allFields(); | 885 | d->mAllFields = Field::allFields(); |
878 | } | 886 | } |
879 | 887 | ||
880 | if ( category == Field::All ) return d->mAllFields; | 888 | if ( category == Field::All ) return d->mAllFields; |
881 | 889 | ||
882 | Field::List result; | 890 | Field::List result; |
883 | Field::List::ConstIterator it; | 891 | Field::List::ConstIterator it; |
884 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 892 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
885 | if ( (*it)->category() & category ) result.append( *it ); | 893 | if ( (*it)->category() & category ) result.append( *it ); |
886 | } | 894 | } |
887 | 895 | ||
888 | return result; | 896 | return result; |
889 | } | 897 | } |
890 | 898 | ||
891 | bool AddressBook::addCustomField( const QString &label, int category, | 899 | bool AddressBook::addCustomField( const QString &label, int category, |
892 | const QString &key, const QString &app ) | 900 | const QString &key, const QString &app ) |
893 | { | 901 | { |
894 | if ( d->mAllFields.isEmpty() ) { | 902 | if ( d->mAllFields.isEmpty() ) { |
895 | d->mAllFields = Field::allFields(); | 903 | d->mAllFields = Field::allFields(); |
896 | } | 904 | } |
897 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 905 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
898 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 906 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
899 | 907 | ||
900 | QString k = key.isNull() ? label : key; | 908 | QString k = key.isNull() ? label : key; |
901 | 909 | ||
902 | Field *field = Field::createCustomField( label, category, k, a ); | 910 | Field *field = Field::createCustomField( label, category, k, a ); |
903 | 911 | ||
904 | if ( !field ) return false; | 912 | if ( !field ) return false; |
905 | 913 | ||
906 | d->mAllFields.append( field ); | 914 | d->mAllFields.append( field ); |
907 | 915 | ||
908 | return true; | 916 | return true; |
909 | } | 917 | } |
910 | 918 | ||
911 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 919 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
912 | { | 920 | { |
913 | if (!ab.d) return s; | 921 | if (!ab.d) return s; |
914 | 922 | ||
915 | return s << ab.d->mAddressees; | 923 | return s << ab.d->mAddressees; |
916 | } | 924 | } |
917 | 925 | ||
918 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 926 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
919 | { | 927 | { |
920 | if (!ab.d) return s; | 928 | if (!ab.d) return s; |
921 | 929 | ||
922 | s >> ab.d->mAddressees; | 930 | s >> ab.d->mAddressees; |
923 | 931 | ||
924 | return s; | 932 | return s; |
925 | } | 933 | } |
926 | 934 | ||
927 | bool AddressBook::addResource( Resource *resource ) | 935 | bool AddressBook::addResource( Resource *resource ) |
928 | { | 936 | { |
929 | if ( !resource->open() ) { | 937 | if ( !resource->open() ) { |
930 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 938 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
931 | return false; | 939 | return false; |
932 | } | 940 | } |
933 | 941 | ||
934 | resource->setAddressBook( this ); | 942 | resource->setAddressBook( this ); |
935 | 943 | ||
936 | d->mManager->add( resource ); | 944 | d->mManager->add( resource ); |
937 | return true; | 945 | return true; |
938 | } | 946 | } |
939 | 947 | ||
940 | bool AddressBook::removeResource( Resource *resource ) | 948 | bool AddressBook::removeResource( Resource *resource ) |
941 | { | 949 | { |
942 | resource->close(); | 950 | resource->close(); |
943 | 951 | ||
944 | if ( resource == standardResource() ) | 952 | if ( resource == standardResource() ) |
945 | d->mManager->setStandardResource( 0 ); | 953 | d->mManager->setStandardResource( 0 ); |
946 | 954 | ||
947 | resource->setAddressBook( 0 ); | 955 | resource->setAddressBook( 0 ); |
948 | 956 | ||
949 | d->mManager->remove( resource ); | 957 | d->mManager->remove( resource ); |
950 | return true; | 958 | return true; |
951 | } | 959 | } |
952 | 960 | ||
953 | QPtrList<Resource> AddressBook::resources() | 961 | QPtrList<Resource> AddressBook::resources() |
954 | { | 962 | { |
955 | QPtrList<Resource> list; | 963 | QPtrList<Resource> list; |
956 | 964 | ||
957 | // qDebug("AddressBook::resources() 1"); | 965 | // qDebug("AddressBook::resources() 1"); |
958 | 966 | ||
959 | KRES::Manager<Resource>::ActiveIterator it; | 967 | KRES::Manager<Resource>::ActiveIterator it; |
960 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 968 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
961 | list.append( *it ); | 969 | list.append( *it ); |
962 | 970 | ||
963 | return list; | 971 | return list; |
964 | } | 972 | } |
965 | 973 | ||
966 | /*US | 974 | /*US |
967 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 975 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
968 | { | 976 | { |
969 | delete d->mErrorHandler; | 977 | delete d->mErrorHandler; |
970 | d->mErrorHandler = handler; | 978 | d->mErrorHandler = handler; |
971 | } | 979 | } |
972 | */ | 980 | */ |
973 | 981 | ||
974 | void AddressBook::error( const QString& msg ) | 982 | void AddressBook::error( const QString& msg ) |
975 | { | 983 | { |
976 | /*US | 984 | /*US |
977 | if ( !d->mErrorHandler ) // create default error handler | 985 | if ( !d->mErrorHandler ) // create default error handler |
978 | d->mErrorHandler = new ConsoleErrorHandler; | 986 | d->mErrorHandler = new ConsoleErrorHandler; |
979 | 987 | ||
980 | if ( d->mErrorHandler ) | 988 | if ( d->mErrorHandler ) |
981 | d->mErrorHandler->error( msg ); | 989 | d->mErrorHandler->error( msg ); |
982 | else | 990 | else |
983 | kdError(5700) << "no error handler defined" << endl; | 991 | kdError(5700) << "no error handler defined" << endl; |
984 | */ | 992 | */ |
985 | kdDebug(5700) << "msg" << endl; | 993 | kdDebug(5700) << "msg" << endl; |
986 | qDebug(msg); | 994 | qDebug(msg); |
987 | } | 995 | } |
988 | 996 | ||
989 | void AddressBook::deleteRemovedAddressees() | 997 | void AddressBook::deleteRemovedAddressees() |
990 | { | 998 | { |
991 | Addressee::List::Iterator it; | 999 | Addressee::List::Iterator it; |
992 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1000 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
993 | Resource *resource = (*it).resource(); | 1001 | Resource *resource = (*it).resource(); |
994 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1002 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
995 | resource->removeAddressee( *it ); | 1003 | resource->removeAddressee( *it ); |
996 | } | 1004 | } |
997 | 1005 | ||
998 | d->mRemovedAddressees.clear(); | 1006 | d->mRemovedAddressees.clear(); |
999 | } | 1007 | } |
1000 | 1008 | ||
1001 | void AddressBook::setStandardResource( Resource *resource ) | 1009 | void AddressBook::setStandardResource( Resource *resource ) |
1002 | { | 1010 | { |
1003 | // qDebug("AddressBook::setStandardResource 1"); | 1011 | // qDebug("AddressBook::setStandardResource 1"); |
1004 | d->mManager->setStandardResource( resource ); | 1012 | d->mManager->setStandardResource( resource ); |
1005 | } | 1013 | } |
1006 | 1014 | ||
1007 | Resource *AddressBook::standardResource() | 1015 | Resource *AddressBook::standardResource() |
1008 | { | 1016 | { |
1009 | return d->mManager->standardResource(); | 1017 | return d->mManager->standardResource(); |
1010 | } | 1018 | } |
1011 | 1019 | ||
1012 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1020 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1013 | { | 1021 | { |
1014 | return d->mManager; | 1022 | return d->mManager; |
1015 | } | 1023 | } |
1016 | 1024 | ||
1017 | void AddressBook::cleanUp() | 1025 | void AddressBook::cleanUp() |
1018 | { | 1026 | { |
1019 | KRES::Manager<Resource>::ActiveIterator it; | 1027 | KRES::Manager<Resource>::ActiveIterator it; |
1020 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1028 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1021 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1029 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1022 | (*it)->cleanUp(); | 1030 | (*it)->cleanUp(); |
1023 | } | 1031 | } |
1024 | } | 1032 | } |