-rw-r--r-- | kabc/addressbook.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 20310a0..c61b387 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,646 +1,646 @@ | |||
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 | 41 | ||
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | #include <klocale.h> | 43 | #include <klocale.h> |
44 | #include <kdebug.h> | 44 | #include <kdebug.h> |
45 | #include "addressbook.h" | 45 | #include "addressbook.h" |
46 | #include "resource.h" | 46 | #include "resource.h" |
47 | 47 | ||
48 | //US #include "addressbook.moc" | 48 | //US #include "addressbook.moc" |
49 | 49 | ||
50 | using namespace KABC; | 50 | using namespace KABC; |
51 | 51 | ||
52 | struct AddressBook::AddressBookData | 52 | struct AddressBook::AddressBookData |
53 | { | 53 | { |
54 | Addressee::List mAddressees; | 54 | Addressee::List mAddressees; |
55 | Addressee::List mRemovedAddressees; | 55 | Addressee::List mRemovedAddressees; |
56 | Field::List mAllFields; | 56 | Field::List mAllFields; |
57 | KConfig *mConfig; | 57 | KConfig *mConfig; |
58 | KRES::Manager<Resource> *mManager; | 58 | KRES::Manager<Resource> *mManager; |
59 | //US ErrorHandler *mErrorHandler; | 59 | //US ErrorHandler *mErrorHandler; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | struct AddressBook::Iterator::IteratorData | 62 | struct AddressBook::Iterator::IteratorData |
63 | { | 63 | { |
64 | Addressee::List::Iterator mIt; | 64 | Addressee::List::Iterator mIt; |
65 | }; | 65 | }; |
66 | 66 | ||
67 | struct AddressBook::ConstIterator::ConstIteratorData | 67 | struct AddressBook::ConstIterator::ConstIteratorData |
68 | { | 68 | { |
69 | Addressee::List::ConstIterator mIt; | 69 | Addressee::List::ConstIterator mIt; |
70 | }; | 70 | }; |
71 | 71 | ||
72 | AddressBook::Iterator::Iterator() | 72 | AddressBook::Iterator::Iterator() |
73 | { | 73 | { |
74 | d = new IteratorData; | 74 | d = new IteratorData; |
75 | } | 75 | } |
76 | 76 | ||
77 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 77 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
78 | { | 78 | { |
79 | d = new IteratorData; | 79 | d = new IteratorData; |
80 | d->mIt = i.d->mIt; | 80 | d->mIt = i.d->mIt; |
81 | } | 81 | } |
82 | 82 | ||
83 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 83 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
84 | { | 84 | { |
85 | if( this == &i ) return *this; // guard against self assignment | 85 | if( this == &i ) return *this; // guard against self assignment |
86 | delete d; // delete the old data the Iterator was completely constructed before | 86 | delete d; // delete the old data the Iterator was completely constructed before |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | return *this; | 89 | return *this; |
90 | } | 90 | } |
91 | 91 | ||
92 | AddressBook::Iterator::~Iterator() | 92 | AddressBook::Iterator::~Iterator() |
93 | { | 93 | { |
94 | delete d; | 94 | delete d; |
95 | } | 95 | } |
96 | 96 | ||
97 | const Addressee &AddressBook::Iterator::operator*() const | 97 | const Addressee &AddressBook::Iterator::operator*() const |
98 | { | 98 | { |
99 | return *(d->mIt); | 99 | return *(d->mIt); |
100 | } | 100 | } |
101 | 101 | ||
102 | Addressee &AddressBook::Iterator::operator*() | 102 | Addressee &AddressBook::Iterator::operator*() |
103 | { | 103 | { |
104 | return *(d->mIt); | 104 | return *(d->mIt); |
105 | } | 105 | } |
106 | 106 | ||
107 | Addressee *AddressBook::Iterator::operator->() | 107 | Addressee *AddressBook::Iterator::operator->() |
108 | { | 108 | { |
109 | return &(*(d->mIt)); | 109 | return &(*(d->mIt)); |
110 | } | 110 | } |
111 | 111 | ||
112 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 112 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
113 | { | 113 | { |
114 | (d->mIt)++; | 114 | (d->mIt)++; |
115 | return *this; | 115 | return *this; |
116 | } | 116 | } |
117 | 117 | ||
118 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 118 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
119 | { | 119 | { |
120 | (d->mIt)++; | 120 | (d->mIt)++; |
121 | return *this; | 121 | return *this; |
122 | } | 122 | } |
123 | 123 | ||
124 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 124 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
125 | { | 125 | { |
126 | (d->mIt)--; | 126 | (d->mIt)--; |
127 | return *this; | 127 | return *this; |
128 | } | 128 | } |
129 | 129 | ||
130 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 130 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
131 | { | 131 | { |
132 | (d->mIt)--; | 132 | (d->mIt)--; |
133 | return *this; | 133 | return *this; |
134 | } | 134 | } |
135 | 135 | ||
136 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 136 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
137 | { | 137 | { |
138 | return ( d->mIt == it.d->mIt ); | 138 | return ( d->mIt == it.d->mIt ); |
139 | } | 139 | } |
140 | 140 | ||
141 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 141 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
142 | { | 142 | { |
143 | return ( d->mIt != it.d->mIt ); | 143 | return ( d->mIt != it.d->mIt ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | AddressBook::ConstIterator::ConstIterator() | 147 | AddressBook::ConstIterator::ConstIterator() |
148 | { | 148 | { |
149 | d = new ConstIteratorData; | 149 | d = new ConstIteratorData; |
150 | } | 150 | } |
151 | 151 | ||
152 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 152 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
153 | { | 153 | { |
154 | d = new ConstIteratorData; | 154 | d = new ConstIteratorData; |
155 | d->mIt = i.d->mIt; | 155 | d->mIt = i.d->mIt; |
156 | } | 156 | } |
157 | 157 | ||
158 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 158 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
159 | { | 159 | { |
160 | if( this == &i ) return *this; // guard for self assignment | 160 | if( this == &i ) return *this; // guard for self assignment |
161 | delete d; // delete the old data because the Iterator was really constructed before | 161 | delete d; // delete the old data because the Iterator was really constructed before |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | return *this; | 164 | return *this; |
165 | } | 165 | } |
166 | 166 | ||
167 | AddressBook::ConstIterator::~ConstIterator() | 167 | AddressBook::ConstIterator::~ConstIterator() |
168 | { | 168 | { |
169 | delete d; | 169 | delete d; |
170 | } | 170 | } |
171 | 171 | ||
172 | const Addressee &AddressBook::ConstIterator::operator*() const | 172 | const Addressee &AddressBook::ConstIterator::operator*() const |
173 | { | 173 | { |
174 | return *(d->mIt); | 174 | return *(d->mIt); |
175 | } | 175 | } |
176 | 176 | ||
177 | const Addressee* AddressBook::ConstIterator::operator->() const | 177 | const Addressee* AddressBook::ConstIterator::operator->() const |
178 | { | 178 | { |
179 | return &(*(d->mIt)); | 179 | return &(*(d->mIt)); |
180 | } | 180 | } |
181 | 181 | ||
182 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 182 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
183 | { | 183 | { |
184 | (d->mIt)++; | 184 | (d->mIt)++; |
185 | return *this; | 185 | return *this; |
186 | } | 186 | } |
187 | 187 | ||
188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
189 | { | 189 | { |
190 | (d->mIt)++; | 190 | (d->mIt)++; |
191 | return *this; | 191 | return *this; |
192 | } | 192 | } |
193 | 193 | ||
194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
195 | { | 195 | { |
196 | (d->mIt)--; | 196 | (d->mIt)--; |
197 | return *this; | 197 | return *this; |
198 | } | 198 | } |
199 | 199 | ||
200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
201 | { | 201 | { |
202 | (d->mIt)--; | 202 | (d->mIt)--; |
203 | return *this; | 203 | return *this; |
204 | } | 204 | } |
205 | 205 | ||
206 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 206 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
207 | { | 207 | { |
208 | return ( d->mIt == it.d->mIt ); | 208 | return ( d->mIt == it.d->mIt ); |
209 | } | 209 | } |
210 | 210 | ||
211 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 211 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
212 | { | 212 | { |
213 | return ( d->mIt != it.d->mIt ); | 213 | return ( d->mIt != it.d->mIt ); |
214 | } | 214 | } |
215 | 215 | ||
216 | 216 | ||
217 | AddressBook::AddressBook() | 217 | AddressBook::AddressBook() |
218 | { | 218 | { |
219 | init(0, "contact"); | 219 | init(0, "contact"); |
220 | } | 220 | } |
221 | 221 | ||
222 | AddressBook::AddressBook( const QString &config ) | 222 | AddressBook::AddressBook( const QString &config ) |
223 | { | 223 | { |
224 | init(config, "contact"); | 224 | init(config, "contact"); |
225 | } | 225 | } |
226 | 226 | ||
227 | AddressBook::AddressBook( const QString &config, const QString &family ) | 227 | AddressBook::AddressBook( const QString &config, const QString &family ) |
228 | { | 228 | { |
229 | init(config, family); | 229 | init(config, family); |
230 | 230 | ||
231 | } | 231 | } |
232 | 232 | ||
233 | // the default family is "contact" | 233 | // the default family is "contact" |
234 | void AddressBook::init(const QString &config, const QString &family ) | 234 | void AddressBook::init(const QString &config, const QString &family ) |
235 | { | 235 | { |
236 | d = new AddressBookData; | 236 | d = new AddressBookData; |
237 | if (config != 0) { | 237 | if (config != 0) { |
238 | d->mConfig = new KConfig( config ); | 238 | d->mConfig = new KConfig( locateLocal("config", config) ); |
239 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 239 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
240 | } | 240 | } |
241 | else { | 241 | else { |
242 | d->mConfig = 0; | 242 | d->mConfig = 0; |
243 | // qDebug("AddressBook::init 1 config=0"); | 243 | // qDebug("AddressBook::init 1 config=0"); |
244 | } | 244 | } |
245 | 245 | ||
246 | //US d->mErrorHandler = 0; | 246 | //US d->mErrorHandler = 0; |
247 | d->mManager = new KRES::Manager<Resource>( family, false ); | 247 | d->mManager = new KRES::Manager<Resource>( family, false ); |
248 | d->mManager->readConfig( d->mConfig ); | 248 | d->mManager->readConfig( d->mConfig ); |
249 | } | 249 | } |
250 | 250 | ||
251 | AddressBook::~AddressBook() | 251 | AddressBook::~AddressBook() |
252 | { | 252 | { |
253 | delete d->mConfig; d->mConfig = 0; | 253 | delete d->mConfig; d->mConfig = 0; |
254 | delete d->mManager; d->mManager = 0; | 254 | delete d->mManager; d->mManager = 0; |
255 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 255 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
256 | delete d; d = 0; | 256 | delete d; d = 0; |
257 | } | 257 | } |
258 | 258 | ||
259 | bool AddressBook::load() | 259 | bool AddressBook::load() |
260 | { | 260 | { |
261 | 261 | ||
262 | 262 | ||
263 | clear(); | 263 | clear(); |
264 | 264 | ||
265 | KRES::Manager<Resource>::ActiveIterator it; | 265 | KRES::Manager<Resource>::ActiveIterator it; |
266 | bool ok = true; | 266 | bool ok = true; |
267 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 267 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
268 | if ( !(*it)->load() ) { | 268 | if ( !(*it)->load() ) { |
269 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 269 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
270 | ok = false; | 270 | ok = false; |
271 | } | 271 | } |
272 | 272 | ||
273 | // mark all addressees as unchanged | 273 | // mark all addressees as unchanged |
274 | Addressee::List::Iterator addrIt; | 274 | Addressee::List::Iterator addrIt; |
275 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) | 275 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) |
276 | (*addrIt).setChanged( false ); | 276 | (*addrIt).setChanged( false ); |
277 | 277 | ||
278 | return ok; | 278 | return ok; |
279 | } | 279 | } |
280 | 280 | ||
281 | bool AddressBook::save( Ticket *ticket ) | 281 | bool AddressBook::save( Ticket *ticket ) |
282 | { | 282 | { |
283 | kdDebug(5700) << "AddressBook::save()"<< endl; | 283 | kdDebug(5700) << "AddressBook::save()"<< endl; |
284 | 284 | ||
285 | if ( ticket->resource() ) { | 285 | if ( ticket->resource() ) { |
286 | deleteRemovedAddressees(); | 286 | deleteRemovedAddressees(); |
287 | 287 | ||
288 | return ticket->resource()->save( ticket ); | 288 | return ticket->resource()->save( ticket ); |
289 | } | 289 | } |
290 | 290 | ||
291 | return false; | 291 | return false; |
292 | } | 292 | } |
293 | 293 | ||
294 | AddressBook::Iterator AddressBook::begin() | 294 | AddressBook::Iterator AddressBook::begin() |
295 | { | 295 | { |
296 | Iterator it = Iterator(); | 296 | Iterator it = Iterator(); |
297 | it.d->mIt = d->mAddressees.begin(); | 297 | it.d->mIt = d->mAddressees.begin(); |
298 | return it; | 298 | return it; |
299 | } | 299 | } |
300 | 300 | ||
301 | AddressBook::ConstIterator AddressBook::begin() const | 301 | AddressBook::ConstIterator AddressBook::begin() const |
302 | { | 302 | { |
303 | ConstIterator it = ConstIterator(); | 303 | ConstIterator it = ConstIterator(); |
304 | it.d->mIt = d->mAddressees.begin(); | 304 | it.d->mIt = d->mAddressees.begin(); |
305 | return it; | 305 | return it; |
306 | } | 306 | } |
307 | 307 | ||
308 | AddressBook::Iterator AddressBook::end() | 308 | AddressBook::Iterator AddressBook::end() |
309 | { | 309 | { |
310 | Iterator it = Iterator(); | 310 | Iterator it = Iterator(); |
311 | it.d->mIt = d->mAddressees.end(); | 311 | it.d->mIt = d->mAddressees.end(); |
312 | return it; | 312 | return it; |
313 | } | 313 | } |
314 | 314 | ||
315 | AddressBook::ConstIterator AddressBook::end() const | 315 | AddressBook::ConstIterator AddressBook::end() const |
316 | { | 316 | { |
317 | ConstIterator it = ConstIterator(); | 317 | ConstIterator it = ConstIterator(); |
318 | it.d->mIt = d->mAddressees.end(); | 318 | it.d->mIt = d->mAddressees.end(); |
319 | return it; | 319 | return it; |
320 | } | 320 | } |
321 | 321 | ||
322 | void AddressBook::clear() | 322 | void AddressBook::clear() |
323 | { | 323 | { |
324 | d->mAddressees.clear(); | 324 | d->mAddressees.clear(); |
325 | } | 325 | } |
326 | 326 | ||
327 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 327 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
328 | { | 328 | { |
329 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 329 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
330 | 330 | ||
331 | if ( !resource ) | 331 | if ( !resource ) |
332 | { | 332 | { |
333 | qDebug("AddressBook::requestSaveTicket no resource" ); | 333 | qDebug("AddressBook::requestSaveTicket no resource" ); |
334 | resource = standardResource(); | 334 | resource = standardResource(); |
335 | } | 335 | } |
336 | 336 | ||
337 | KRES::Manager<Resource>::ActiveIterator it; | 337 | KRES::Manager<Resource>::ActiveIterator it; |
338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 338 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
339 | if ( (*it) == resource ) { | 339 | if ( (*it) == resource ) { |
340 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 340 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
341 | return 0; | 341 | return 0; |
342 | else | 342 | else |
343 | return (*it)->requestSaveTicket(); | 343 | return (*it)->requestSaveTicket(); |
344 | } | 344 | } |
345 | } | 345 | } |
346 | 346 | ||
347 | return 0; | 347 | return 0; |
348 | } | 348 | } |
349 | 349 | ||
350 | void AddressBook::insertAddressee( const Addressee &a ) | 350 | void AddressBook::insertAddressee( const Addressee &a ) |
351 | { | 351 | { |
352 | Addressee::List::Iterator it; | 352 | Addressee::List::Iterator it; |
353 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 353 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
354 | if ( a.uid() == (*it).uid() ) { | 354 | if ( a.uid() == (*it).uid() ) { |
355 | bool changed = false; | 355 | bool changed = false; |
356 | Addressee addr = a; | 356 | Addressee addr = a; |
357 | if ( addr != (*it) ) | 357 | if ( addr != (*it) ) |
358 | changed = true; | 358 | changed = true; |
359 | 359 | ||
360 | (*it) = a; | 360 | (*it) = a; |
361 | if ( (*it).resource() == 0 ) | 361 | if ( (*it).resource() == 0 ) |
362 | (*it).setResource( standardResource() ); | 362 | (*it).setResource( standardResource() ); |
363 | 363 | ||
364 | if ( changed ) { | 364 | if ( changed ) { |
365 | (*it).setRevision( QDateTime::currentDateTime() ); | 365 | (*it).setRevision( QDateTime::currentDateTime() ); |
366 | (*it).setChanged( true ); | 366 | (*it).setChanged( true ); |
367 | } | 367 | } |
368 | 368 | ||
369 | return; | 369 | return; |
370 | } | 370 | } |
371 | } | 371 | } |
372 | d->mAddressees.append( a ); | 372 | d->mAddressees.append( a ); |
373 | Addressee& addr = d->mAddressees.last(); | 373 | Addressee& addr = d->mAddressees.last(); |
374 | if ( addr.resource() == 0 ) | 374 | if ( addr.resource() == 0 ) |
375 | addr.setResource( standardResource() ); | 375 | addr.setResource( standardResource() ); |
376 | 376 | ||
377 | addr.setChanged( true ); | 377 | addr.setChanged( true ); |
378 | } | 378 | } |
379 | 379 | ||
380 | void AddressBook::removeAddressee( const Addressee &a ) | 380 | void AddressBook::removeAddressee( const Addressee &a ) |
381 | { | 381 | { |
382 | Iterator it; | 382 | Iterator it; |
383 | for ( it = begin(); it != end(); ++it ) { | 383 | for ( it = begin(); it != end(); ++it ) { |
384 | if ( a.uid() == (*it).uid() ) { | 384 | if ( a.uid() == (*it).uid() ) { |
385 | removeAddressee( it ); | 385 | removeAddressee( it ); |
386 | return; | 386 | return; |
387 | } | 387 | } |
388 | } | 388 | } |
389 | } | 389 | } |
390 | 390 | ||
391 | void AddressBook::removeAddressee( const Iterator &it ) | 391 | void AddressBook::removeAddressee( const Iterator &it ) |
392 | { | 392 | { |
393 | d->mRemovedAddressees.append( (*it) ); | 393 | d->mRemovedAddressees.append( (*it) ); |
394 | d->mAddressees.remove( it.d->mIt ); | 394 | d->mAddressees.remove( it.d->mIt ); |
395 | } | 395 | } |
396 | 396 | ||
397 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 397 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
398 | { | 398 | { |
399 | Iterator it; | 399 | Iterator it; |
400 | for ( it = begin(); it != end(); ++it ) { | 400 | for ( it = begin(); it != end(); ++it ) { |
401 | if ( a.uid() == (*it).uid() ) { | 401 | if ( a.uid() == (*it).uid() ) { |
402 | return it; | 402 | return it; |
403 | } | 403 | } |
404 | } | 404 | } |
405 | return end(); | 405 | return end(); |
406 | } | 406 | } |
407 | 407 | ||
408 | Addressee AddressBook::findByUid( const QString &uid ) | 408 | Addressee AddressBook::findByUid( const QString &uid ) |
409 | { | 409 | { |
410 | Iterator it; | 410 | Iterator it; |
411 | for ( it = begin(); it != end(); ++it ) { | 411 | for ( it = begin(); it != end(); ++it ) { |
412 | if ( uid == (*it).uid() ) { | 412 | if ( uid == (*it).uid() ) { |
413 | return *it; | 413 | return *it; |
414 | } | 414 | } |
415 | } | 415 | } |
416 | return Addressee(); | 416 | return Addressee(); |
417 | } | 417 | } |
418 | 418 | ||
419 | Addressee::List AddressBook::allAddressees() | 419 | Addressee::List AddressBook::allAddressees() |
420 | { | 420 | { |
421 | return d->mAddressees; | 421 | return d->mAddressees; |
422 | } | 422 | } |
423 | 423 | ||
424 | Addressee::List AddressBook::findByName( const QString &name ) | 424 | Addressee::List AddressBook::findByName( const QString &name ) |
425 | { | 425 | { |
426 | Addressee::List results; | 426 | Addressee::List results; |
427 | 427 | ||
428 | Iterator it; | 428 | Iterator it; |
429 | for ( it = begin(); it != end(); ++it ) { | 429 | for ( it = begin(); it != end(); ++it ) { |
430 | if ( name == (*it).name() ) { | 430 | if ( name == (*it).name() ) { |
431 | results.append( *it ); | 431 | results.append( *it ); |
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
435 | return results; | 435 | return results; |
436 | } | 436 | } |
437 | 437 | ||
438 | Addressee::List AddressBook::findByEmail( const QString &email ) | 438 | Addressee::List AddressBook::findByEmail( const QString &email ) |
439 | { | 439 | { |
440 | Addressee::List results; | 440 | Addressee::List results; |
441 | QStringList mailList; | 441 | QStringList mailList; |
442 | 442 | ||
443 | Iterator it; | 443 | Iterator it; |
444 | for ( it = begin(); it != end(); ++it ) { | 444 | for ( it = begin(); it != end(); ++it ) { |
445 | mailList = (*it).emails(); | 445 | mailList = (*it).emails(); |
446 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 446 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
447 | if ( email == (*ite) ) { | 447 | if ( email == (*ite) ) { |
448 | results.append( *it ); | 448 | results.append( *it ); |
449 | } | 449 | } |
450 | } | 450 | } |
451 | } | 451 | } |
452 | 452 | ||
453 | return results; | 453 | return results; |
454 | } | 454 | } |
455 | 455 | ||
456 | Addressee::List AddressBook::findByCategory( const QString &category ) | 456 | Addressee::List AddressBook::findByCategory( const QString &category ) |
457 | { | 457 | { |
458 | Addressee::List results; | 458 | Addressee::List results; |
459 | 459 | ||
460 | Iterator it; | 460 | Iterator it; |
461 | for ( it = begin(); it != end(); ++it ) { | 461 | for ( it = begin(); it != end(); ++it ) { |
462 | if ( (*it).hasCategory( category) ) { | 462 | if ( (*it).hasCategory( category) ) { |
463 | results.append( *it ); | 463 | results.append( *it ); |
464 | } | 464 | } |
465 | } | 465 | } |
466 | 466 | ||
467 | return results; | 467 | return results; |
468 | } | 468 | } |
469 | 469 | ||
470 | void AddressBook::dump() const | 470 | void AddressBook::dump() const |
471 | { | 471 | { |
472 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 472 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
473 | 473 | ||
474 | ConstIterator it; | 474 | ConstIterator it; |
475 | for( it = begin(); it != end(); ++it ) { | 475 | for( it = begin(); it != end(); ++it ) { |
476 | (*it).dump(); | 476 | (*it).dump(); |
477 | } | 477 | } |
478 | 478 | ||
479 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 479 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
480 | } | 480 | } |
481 | 481 | ||
482 | QString AddressBook::identifier() | 482 | QString AddressBook::identifier() |
483 | { | 483 | { |
484 | QStringList identifier; | 484 | QStringList identifier; |
485 | 485 | ||
486 | 486 | ||
487 | KRES::Manager<Resource>::ActiveIterator it; | 487 | KRES::Manager<Resource>::ActiveIterator it; |
488 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 488 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
489 | if ( !(*it)->identifier().isEmpty() ) | 489 | if ( !(*it)->identifier().isEmpty() ) |
490 | identifier.append( (*it)->identifier() ); | 490 | identifier.append( (*it)->identifier() ); |
491 | } | 491 | } |
492 | 492 | ||
493 | return identifier.join( ":" ); | 493 | return identifier.join( ":" ); |
494 | } | 494 | } |
495 | 495 | ||
496 | Field::List AddressBook::fields( int category ) | 496 | Field::List AddressBook::fields( int category ) |
497 | { | 497 | { |
498 | if ( d->mAllFields.isEmpty() ) { | 498 | if ( d->mAllFields.isEmpty() ) { |
499 | d->mAllFields = Field::allFields(); | 499 | d->mAllFields = Field::allFields(); |
500 | } | 500 | } |
501 | 501 | ||
502 | if ( category == Field::All ) return d->mAllFields; | 502 | if ( category == Field::All ) return d->mAllFields; |
503 | 503 | ||
504 | Field::List result; | 504 | Field::List result; |
505 | Field::List::ConstIterator it; | 505 | Field::List::ConstIterator it; |
506 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 506 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
507 | if ( (*it)->category() & category ) result.append( *it ); | 507 | if ( (*it)->category() & category ) result.append( *it ); |
508 | } | 508 | } |
509 | 509 | ||
510 | return result; | 510 | return result; |
511 | } | 511 | } |
512 | 512 | ||
513 | bool AddressBook::addCustomField( const QString &label, int category, | 513 | bool AddressBook::addCustomField( const QString &label, int category, |
514 | const QString &key, const QString &app ) | 514 | const QString &key, const QString &app ) |
515 | { | 515 | { |
516 | if ( d->mAllFields.isEmpty() ) { | 516 | if ( d->mAllFields.isEmpty() ) { |
517 | d->mAllFields = Field::allFields(); | 517 | d->mAllFields = Field::allFields(); |
518 | } | 518 | } |
519 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 519 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
520 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 520 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
521 | 521 | ||
522 | QString k = key.isNull() ? label : key; | 522 | QString k = key.isNull() ? label : key; |
523 | 523 | ||
524 | Field *field = Field::createCustomField( label, category, k, a ); | 524 | Field *field = Field::createCustomField( label, category, k, a ); |
525 | 525 | ||
526 | if ( !field ) return false; | 526 | if ( !field ) return false; |
527 | 527 | ||
528 | d->mAllFields.append( field ); | 528 | d->mAllFields.append( field ); |
529 | 529 | ||
530 | return true; | 530 | return true; |
531 | } | 531 | } |
532 | 532 | ||
533 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 533 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
534 | { | 534 | { |
535 | if (!ab.d) return s; | 535 | if (!ab.d) return s; |
536 | 536 | ||
537 | return s << ab.d->mAddressees; | 537 | return s << ab.d->mAddressees; |
538 | } | 538 | } |
539 | 539 | ||
540 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 540 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
541 | { | 541 | { |
542 | if (!ab.d) return s; | 542 | if (!ab.d) return s; |
543 | 543 | ||
544 | s >> ab.d->mAddressees; | 544 | s >> ab.d->mAddressees; |
545 | 545 | ||
546 | return s; | 546 | return s; |
547 | } | 547 | } |
548 | 548 | ||
549 | bool AddressBook::addResource( Resource *resource ) | 549 | bool AddressBook::addResource( Resource *resource ) |
550 | { | 550 | { |
551 | if ( !resource->open() ) { | 551 | if ( !resource->open() ) { |
552 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 552 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
553 | return false; | 553 | return false; |
554 | } | 554 | } |
555 | 555 | ||
556 | resource->setAddressBook( this ); | 556 | resource->setAddressBook( this ); |
557 | 557 | ||
558 | d->mManager->add( resource ); | 558 | d->mManager->add( resource ); |
559 | return true; | 559 | return true; |
560 | } | 560 | } |
561 | 561 | ||
562 | bool AddressBook::removeResource( Resource *resource ) | 562 | bool AddressBook::removeResource( Resource *resource ) |
563 | { | 563 | { |
564 | resource->close(); | 564 | resource->close(); |
565 | 565 | ||
566 | if ( resource == standardResource() ) | 566 | if ( resource == standardResource() ) |
567 | d->mManager->setStandardResource( 0 ); | 567 | d->mManager->setStandardResource( 0 ); |
568 | 568 | ||
569 | resource->setAddressBook( 0 ); | 569 | resource->setAddressBook( 0 ); |
570 | 570 | ||
571 | d->mManager->remove( resource ); | 571 | d->mManager->remove( resource ); |
572 | return true; | 572 | return true; |
573 | } | 573 | } |
574 | 574 | ||
575 | QPtrList<Resource> AddressBook::resources() | 575 | QPtrList<Resource> AddressBook::resources() |
576 | { | 576 | { |
577 | QPtrList<Resource> list; | 577 | QPtrList<Resource> list; |
578 | 578 | ||
579 | // qDebug("AddressBook::resources() 1"); | 579 | // qDebug("AddressBook::resources() 1"); |
580 | 580 | ||
581 | KRES::Manager<Resource>::ActiveIterator it; | 581 | KRES::Manager<Resource>::ActiveIterator it; |
582 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 582 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
583 | list.append( *it ); | 583 | list.append( *it ); |
584 | 584 | ||
585 | return list; | 585 | return list; |
586 | } | 586 | } |
587 | 587 | ||
588 | /*US | 588 | /*US |
589 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 589 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
590 | { | 590 | { |
591 | delete d->mErrorHandler; | 591 | delete d->mErrorHandler; |
592 | d->mErrorHandler = handler; | 592 | d->mErrorHandler = handler; |
593 | } | 593 | } |
594 | */ | 594 | */ |
595 | 595 | ||
596 | void AddressBook::error( const QString& msg ) | 596 | void AddressBook::error( const QString& msg ) |
597 | { | 597 | { |
598 | /*US | 598 | /*US |
599 | if ( !d->mErrorHandler ) // create default error handler | 599 | if ( !d->mErrorHandler ) // create default error handler |
600 | d->mErrorHandler = new ConsoleErrorHandler; | 600 | d->mErrorHandler = new ConsoleErrorHandler; |
601 | 601 | ||
602 | if ( d->mErrorHandler ) | 602 | if ( d->mErrorHandler ) |
603 | d->mErrorHandler->error( msg ); | 603 | d->mErrorHandler->error( msg ); |
604 | else | 604 | else |
605 | kdError(5700) << "no error handler defined" << endl; | 605 | kdError(5700) << "no error handler defined" << endl; |
606 | */ | 606 | */ |
607 | kdDebug(5700) << "msg" << endl; | 607 | kdDebug(5700) << "msg" << endl; |
608 | qDebug(msg); | 608 | qDebug(msg); |
609 | } | 609 | } |
610 | 610 | ||
611 | void AddressBook::deleteRemovedAddressees() | 611 | void AddressBook::deleteRemovedAddressees() |
612 | { | 612 | { |
613 | Addressee::List::Iterator it; | 613 | Addressee::List::Iterator it; |
614 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 614 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
615 | Resource *resource = (*it).resource(); | 615 | Resource *resource = (*it).resource(); |
616 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 616 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
617 | resource->removeAddressee( *it ); | 617 | resource->removeAddressee( *it ); |
618 | } | 618 | } |
619 | 619 | ||
620 | d->mRemovedAddressees.clear(); | 620 | d->mRemovedAddressees.clear(); |
621 | } | 621 | } |
622 | 622 | ||
623 | void AddressBook::setStandardResource( Resource *resource ) | 623 | void AddressBook::setStandardResource( Resource *resource ) |
624 | { | 624 | { |
625 | // qDebug("AddressBook::setStandardResource 1"); | 625 | // qDebug("AddressBook::setStandardResource 1"); |
626 | d->mManager->setStandardResource( resource ); | 626 | d->mManager->setStandardResource( resource ); |
627 | } | 627 | } |
628 | 628 | ||
629 | Resource *AddressBook::standardResource() | 629 | Resource *AddressBook::standardResource() |
630 | { | 630 | { |
631 | return d->mManager->standardResource(); | 631 | return d->mManager->standardResource(); |
632 | } | 632 | } |
633 | 633 | ||
634 | KRES::Manager<Resource> *AddressBook::resourceManager() | 634 | KRES::Manager<Resource> *AddressBook::resourceManager() |
635 | { | 635 | { |
636 | return d->mManager; | 636 | return d->mManager; |
637 | } | 637 | } |
638 | 638 | ||
639 | void AddressBook::cleanUp() | 639 | void AddressBook::cleanUp() |
640 | { | 640 | { |
641 | KRES::Manager<Resource>::ActiveIterator it; | 641 | KRES::Manager<Resource>::ActiveIterator it; |
642 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 642 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
643 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 643 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
644 | (*it)->cleanUp(); | 644 | (*it)->cleanUp(); |
645 | } | 645 | } |
646 | } | 646 | } |