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