-rw-r--r-- | kabc/addressbook.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index ec9f893..46a9cf4 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,849 +1,866 @@ | |||
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 <libkcal/syncdefines.h> | 45 | #include <libkcal/syncdefines.h> |
46 | #include "addressbook.h" | 46 | #include "addressbook.h" |
47 | #include "resource.h" | 47 | #include "resource.h" |
48 | 48 | ||
49 | //US #include "addressbook.moc" | 49 | //US #include "addressbook.moc" |
50 | 50 | ||
51 | using namespace KABC; | 51 | using namespace KABC; |
52 | 52 | ||
53 | struct AddressBook::AddressBookData | 53 | struct AddressBook::AddressBookData |
54 | { | 54 | { |
55 | Addressee::List mAddressees; | 55 | Addressee::List mAddressees; |
56 | Addressee::List mRemovedAddressees; | 56 | Addressee::List mRemovedAddressees; |
57 | Field::List mAllFields; | 57 | Field::List mAllFields; |
58 | KConfig *mConfig; | 58 | KConfig *mConfig; |
59 | KRES::Manager<Resource> *mManager; | 59 | KRES::Manager<Resource> *mManager; |
60 | //US ErrorHandler *mErrorHandler; | 60 | //US ErrorHandler *mErrorHandler; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | struct AddressBook::Iterator::IteratorData | 63 | struct AddressBook::Iterator::IteratorData |
64 | { | 64 | { |
65 | Addressee::List::Iterator mIt; | 65 | Addressee::List::Iterator mIt; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct AddressBook::ConstIterator::ConstIteratorData | 68 | struct AddressBook::ConstIterator::ConstIteratorData |
69 | { | 69 | { |
70 | Addressee::List::ConstIterator mIt; | 70 | Addressee::List::ConstIterator mIt; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | AddressBook::Iterator::Iterator() | 73 | AddressBook::Iterator::Iterator() |
74 | { | 74 | { |
75 | d = new IteratorData; | 75 | d = new IteratorData; |
76 | } | 76 | } |
77 | 77 | ||
78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
79 | { | 79 | { |
80 | d = new IteratorData; | 80 | d = new IteratorData; |
81 | d->mIt = i.d->mIt; | 81 | d->mIt = i.d->mIt; |
82 | } | 82 | } |
83 | 83 | ||
84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
85 | { | 85 | { |
86 | if( this == &i ) return *this; // guard against self assignment | 86 | if( this == &i ) return *this; // guard against self assignment |
87 | delete d; // delete the old data the Iterator was completely constructed before | 87 | delete d; // delete the old data the Iterator was completely constructed before |
88 | d = new IteratorData; | 88 | d = new IteratorData; |
89 | d->mIt = i.d->mIt; | 89 | d->mIt = i.d->mIt; |
90 | return *this; | 90 | return *this; |
91 | } | 91 | } |
92 | 92 | ||
93 | AddressBook::Iterator::~Iterator() | 93 | AddressBook::Iterator::~Iterator() |
94 | { | 94 | { |
95 | delete d; | 95 | delete d; |
96 | } | 96 | } |
97 | 97 | ||
98 | const Addressee &AddressBook::Iterator::operator*() const | 98 | const Addressee &AddressBook::Iterator::operator*() const |
99 | { | 99 | { |
100 | return *(d->mIt); | 100 | return *(d->mIt); |
101 | } | 101 | } |
102 | 102 | ||
103 | Addressee &AddressBook::Iterator::operator*() | 103 | Addressee &AddressBook::Iterator::operator*() |
104 | { | 104 | { |
105 | return *(d->mIt); | 105 | return *(d->mIt); |
106 | } | 106 | } |
107 | 107 | ||
108 | Addressee *AddressBook::Iterator::operator->() | 108 | Addressee *AddressBook::Iterator::operator->() |
109 | { | 109 | { |
110 | return &(*(d->mIt)); | 110 | return &(*(d->mIt)); |
111 | } | 111 | } |
112 | 112 | ||
113 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 113 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
114 | { | 114 | { |
115 | (d->mIt)++; | 115 | (d->mIt)++; |
116 | return *this; | 116 | return *this; |
117 | } | 117 | } |
118 | 118 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
120 | { | 120 | { |
121 | (d->mIt)++; | 121 | (d->mIt)++; |
122 | return *this; | 122 | return *this; |
123 | } | 123 | } |
124 | 124 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 125 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
126 | { | 126 | { |
127 | (d->mIt)--; | 127 | (d->mIt)--; |
128 | return *this; | 128 | return *this; |
129 | } | 129 | } |
130 | 130 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
132 | { | 132 | { |
133 | (d->mIt)--; | 133 | (d->mIt)--; |
134 | return *this; | 134 | return *this; |
135 | } | 135 | } |
136 | 136 | ||
137 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 137 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
138 | { | 138 | { |
139 | return ( d->mIt == it.d->mIt ); | 139 | return ( d->mIt == it.d->mIt ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
143 | { | 143 | { |
144 | return ( d->mIt != it.d->mIt ); | 144 | return ( d->mIt != it.d->mIt ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | AddressBook::ConstIterator::ConstIterator() | 148 | AddressBook::ConstIterator::ConstIterator() |
149 | { | 149 | { |
150 | d = new ConstIteratorData; | 150 | d = new ConstIteratorData; |
151 | } | 151 | } |
152 | 152 | ||
153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
154 | { | 154 | { |
155 | d = new ConstIteratorData; | 155 | d = new ConstIteratorData; |
156 | d->mIt = i.d->mIt; | 156 | d->mIt = i.d->mIt; |
157 | } | 157 | } |
158 | 158 | ||
159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
160 | { | 160 | { |
161 | if( this == &i ) return *this; // guard for self assignment | 161 | if( this == &i ) return *this; // guard for self assignment |
162 | delete d; // delete the old data because the Iterator was really constructed before | 162 | delete d; // delete the old data because the Iterator was really constructed before |
163 | d = new ConstIteratorData; | 163 | d = new ConstIteratorData; |
164 | d->mIt = i.d->mIt; | 164 | d->mIt = i.d->mIt; |
165 | return *this; | 165 | return *this; |
166 | } | 166 | } |
167 | 167 | ||
168 | AddressBook::ConstIterator::~ConstIterator() | 168 | AddressBook::ConstIterator::~ConstIterator() |
169 | { | 169 | { |
170 | delete d; | 170 | delete d; |
171 | } | 171 | } |
172 | 172 | ||
173 | const Addressee &AddressBook::ConstIterator::operator*() const | 173 | const Addressee &AddressBook::ConstIterator::operator*() const |
174 | { | 174 | { |
175 | return *(d->mIt); | 175 | return *(d->mIt); |
176 | } | 176 | } |
177 | 177 | ||
178 | const Addressee* AddressBook::ConstIterator::operator->() const | 178 | const Addressee* AddressBook::ConstIterator::operator->() const |
179 | { | 179 | { |
180 | return &(*(d->mIt)); | 180 | return &(*(d->mIt)); |
181 | } | 181 | } |
182 | 182 | ||
183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
184 | { | 184 | { |
185 | (d->mIt)++; | 185 | (d->mIt)++; |
186 | return *this; | 186 | return *this; |
187 | } | 187 | } |
188 | 188 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
190 | { | 190 | { |
191 | (d->mIt)++; | 191 | (d->mIt)++; |
192 | return *this; | 192 | return *this; |
193 | } | 193 | } |
194 | 194 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
196 | { | 196 | { |
197 | (d->mIt)--; | 197 | (d->mIt)--; |
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
202 | { | 202 | { |
203 | (d->mIt)--; | 203 | (d->mIt)--; |
204 | return *this; | 204 | return *this; |
205 | } | 205 | } |
206 | 206 | ||
207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
208 | { | 208 | { |
209 | return ( d->mIt == it.d->mIt ); | 209 | return ( d->mIt == it.d->mIt ); |
210 | } | 210 | } |
211 | 211 | ||
212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
213 | { | 213 | { |
214 | return ( d->mIt != it.d->mIt ); | 214 | return ( d->mIt != it.d->mIt ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | AddressBook::AddressBook() | 218 | AddressBook::AddressBook() |
219 | { | 219 | { |
220 | init(0, "contact"); | 220 | init(0, "contact"); |
221 | } | 221 | } |
222 | 222 | ||
223 | AddressBook::AddressBook( const QString &config ) | 223 | AddressBook::AddressBook( const QString &config ) |
224 | { | 224 | { |
225 | init(config, "contact"); | 225 | init(config, "contact"); |
226 | } | 226 | } |
227 | 227 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 228 | AddressBook::AddressBook( const QString &config, const QString &family ) |
229 | { | 229 | { |
230 | init(config, family); | 230 | init(config, family); |
231 | 231 | ||
232 | } | 232 | } |
233 | 233 | ||
234 | // the default family is "contact" | 234 | // the default family is "contact" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 235 | void AddressBook::init(const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | blockLSEchange = false; | 237 | blockLSEchange = false; |
238 | d = new AddressBookData; | 238 | d = new AddressBookData; |
239 | QString fami = family; | 239 | QString fami = family; |
240 | qDebug("new ab "); | 240 | qDebug("new ab "); |
241 | if (config != 0) { | 241 | if (config != 0) { |
242 | qDebug("config != 0 "); | 242 | qDebug("config != 0 "); |
243 | if ( family == "syncContact" ) { | 243 | if ( family == "syncContact" ) { |
244 | qDebug("creating sync config "); | 244 | qDebug("creating sync config "); |
245 | fami = "contact"; | 245 | fami = "contact"; |
246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
247 | con->setGroup( "General" ); | 247 | con->setGroup( "General" ); |
248 | con->writeEntry( "ResourceKeys", QString("sync") ); | 248 | con->writeEntry( "ResourceKeys", QString("sync") ); |
249 | con->writeEntry( "Standard", QString("sync") ); | 249 | con->writeEntry( "Standard", QString("sync") ); |
250 | con->setGroup( "Resource_sync" ); | 250 | con->setGroup( "Resource_sync" ); |
251 | con->writeEntry( "FileFormat", QString("vcard") ); | 251 | con->writeEntry( "FileFormat", QString("vcard") ); |
252 | con->writeEntry( "FileName", config ); | 252 | con->writeEntry( "FileName", config ); |
253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
254 | con->writeEntry( "ResourceName", QString("sync_res") ); | 254 | con->writeEntry( "ResourceName", QString("sync_res") ); |
255 | con->writeEntry( "ResourceType", QString("file") ); | 255 | con->writeEntry( "ResourceType", QString("file") ); |
256 | //con->sync(); | 256 | //con->sync(); |
257 | d->mConfig = con; | 257 | d->mConfig = con; |
258 | } | 258 | } |
259 | else | 259 | else |
260 | d->mConfig = new KConfig( locateLocal("config", config) ); | 260 | d->mConfig = new KConfig( locateLocal("config", config) ); |
261 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 261 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
262 | } | 262 | } |
263 | else { | 263 | else { |
264 | d->mConfig = 0; | 264 | d->mConfig = 0; |
265 | // qDebug("AddressBook::init 1 config=0"); | 265 | // qDebug("AddressBook::init 1 config=0"); |
266 | } | 266 | } |
267 | 267 | ||
268 | //US d->mErrorHandler = 0; | 268 | //US d->mErrorHandler = 0; |
269 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 269 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
270 | d->mManager->readConfig( d->mConfig ); | 270 | d->mManager->readConfig( d->mConfig ); |
271 | if ( family == "syncContact" ) { | 271 | if ( family == "syncContact" ) { |
272 | KRES::Manager<Resource> *manager = d->mManager; | 272 | KRES::Manager<Resource> *manager = d->mManager; |
273 | KRES::Manager<Resource>::ActiveIterator it; | 273 | KRES::Manager<Resource>::ActiveIterator it; |
274 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 274 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
275 | (*it)->setAddressBook( this ); | 275 | (*it)->setAddressBook( this ); |
276 | if ( !(*it)->open() ) | 276 | if ( !(*it)->open() ) |
277 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 277 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
278 | } | 278 | } |
279 | Resource *res = standardResource(); | 279 | Resource *res = standardResource(); |
280 | if ( !res ) { | 280 | if ( !res ) { |
281 | qDebug("ERROR: no standard resource"); | 281 | qDebug("ERROR: no standard resource"); |
282 | res = manager->createResource( "file" ); | 282 | res = manager->createResource( "file" ); |
283 | if ( res ) | 283 | if ( res ) |
284 | { | 284 | { |
285 | addResource( res ); | 285 | addResource( res ); |
286 | } | 286 | } |
287 | else | 287 | else |
288 | qDebug(" No resource available!!!"); | 288 | qDebug(" No resource available!!!"); |
289 | } | 289 | } |
290 | setStandardResource( res ); | 290 | setStandardResource( res ); |
291 | manager->writeConfig(); | 291 | manager->writeConfig(); |
292 | } | 292 | } |
293 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 293 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
294 | "X-Department", "KADDRESSBOOK" ); | 294 | "X-Department", "KADDRESSBOOK" ); |
295 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 295 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
296 | "X-Profession", "KADDRESSBOOK" ); | 296 | "X-Profession", "KADDRESSBOOK" ); |
297 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 297 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
298 | "X-AssistantsName", "KADDRESSBOOK" ); | 298 | "X-AssistantsName", "KADDRESSBOOK" ); |
299 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 299 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
300 | "X-ManagersName", "KADDRESSBOOK" ); | 300 | "X-ManagersName", "KADDRESSBOOK" ); |
301 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 301 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
302 | "X-SpousesName", "KADDRESSBOOK" ); | 302 | "X-SpousesName", "KADDRESSBOOK" ); |
303 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 303 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
304 | "X-Office", "KADDRESSBOOK" ); | 304 | "X-Office", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 305 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
306 | "X-IMAddress", "KADDRESSBOOK" ); | 306 | "X-IMAddress", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 307 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
308 | "X-Anniversary", "KADDRESSBOOK" ); | 308 | "X-Anniversary", "KADDRESSBOOK" ); |
309 | 309 | ||
310 | //US added this field to become compatible with Opie/qtopia addressbook | 310 | //US added this field to become compatible with Opie/qtopia addressbook |
311 | // values can be "female" or "male" or "". An empty field represents undefined. | 311 | // values can be "female" or "male" or "". An empty field represents undefined. |
312 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
313 | "X-Gender", "KADDRESSBOOK" ); | 313 | "X-Gender", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
315 | "X-Children", "KADDRESSBOOK" ); | 315 | "X-Children", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
317 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 317 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
319 | "X-ExternalID", "KADDRESSBOOK" ); | 319 | "X-ExternalID", "KADDRESSBOOK" ); |
320 | } | 320 | } |
321 | 321 | ||
322 | AddressBook::~AddressBook() | 322 | AddressBook::~AddressBook() |
323 | { | 323 | { |
324 | delete d->mConfig; d->mConfig = 0; | 324 | delete d->mConfig; d->mConfig = 0; |
325 | delete d->mManager; d->mManager = 0; | 325 | delete d->mManager; d->mManager = 0; |
326 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 326 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
327 | delete d; d = 0; | 327 | delete d; d = 0; |
328 | } | 328 | } |
329 | 329 | ||
330 | bool AddressBook::load() | 330 | bool AddressBook::load() |
331 | { | 331 | { |
332 | 332 | ||
333 | 333 | ||
334 | clear(); | 334 | clear(); |
335 | 335 | ||
336 | KRES::Manager<Resource>::ActiveIterator it; | 336 | KRES::Manager<Resource>::ActiveIterator it; |
337 | bool ok = true; | 337 | bool ok = true; |
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)->load() ) { | 339 | if ( !(*it)->load() ) { |
340 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 340 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
341 | ok = false; | 341 | ok = false; |
342 | } | 342 | } |
343 | 343 | ||
344 | // mark all addressees as unchanged | 344 | // mark all addressees as unchanged |
345 | Addressee::List::Iterator addrIt; | 345 | Addressee::List::Iterator addrIt; |
346 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) | 346 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
347 | (*addrIt).setChanged( false ); | 347 | (*addrIt).setChanged( false ); |
348 | 348 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | |
349 | if ( !id.isEmpty() ) { | ||
350 | //qDebug("setId aa %s ", id.latin1()); | ||
351 | (*addrIt).setIDStr(id ); | ||
352 | } | ||
353 | } | ||
349 | blockLSEchange = true; | 354 | blockLSEchange = true; |
350 | return ok; | 355 | return ok; |
351 | } | 356 | } |
352 | 357 | ||
353 | bool AddressBook::save( Ticket *ticket ) | 358 | bool AddressBook::save( Ticket *ticket ) |
354 | { | 359 | { |
355 | kdDebug(5700) << "AddressBook::save()"<< endl; | 360 | kdDebug(5700) << "AddressBook::save()"<< endl; |
356 | 361 | ||
357 | if ( ticket->resource() ) { | 362 | if ( ticket->resource() ) { |
358 | deleteRemovedAddressees(); | 363 | deleteRemovedAddressees(); |
359 | return ticket->resource()->save( ticket ); | 364 | return ticket->resource()->save( ticket ); |
360 | } | 365 | } |
361 | 366 | ||
362 | return false; | 367 | return false; |
363 | } | 368 | } |
364 | bool AddressBook::saveAB() | 369 | bool AddressBook::saveAB() |
365 | { | 370 | { |
366 | bool ok = true; | 371 | bool ok = true; |
367 | 372 | ||
368 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
369 | 374 | Iterator ait; | |
375 | for ( ait = begin(); ait != end(); ++ait ) { | ||
376 | if ( !(*ait).IDStr().isEmpty() ) { | ||
377 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | ||
378 | } | ||
379 | } | ||
370 | KRES::Manager<Resource>::ActiveIterator it; | 380 | KRES::Manager<Resource>::ActiveIterator it; |
371 | KRES::Manager<Resource> *manager = d->mManager; | 381 | KRES::Manager<Resource> *manager = d->mManager; |
372 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 382 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
373 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 383 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
374 | Ticket *ticket = requestSaveTicket( *it ); | 384 | Ticket *ticket = requestSaveTicket( *it ); |
375 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 385 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
376 | if ( !ticket ) { | 386 | if ( !ticket ) { |
377 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 387 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
378 | .arg( (*it)->resourceName() ) ); | 388 | .arg( (*it)->resourceName() ) ); |
379 | return false; | 389 | return false; |
380 | } | 390 | } |
381 | 391 | ||
382 | //if ( !save( ticket ) ) | 392 | //if ( !save( ticket ) ) |
383 | if ( ticket->resource() ) { | 393 | if ( ticket->resource() ) { |
384 | if ( ! ticket->resource()->save( ticket ) ) | 394 | if ( ! ticket->resource()->save( ticket ) ) |
385 | ok = false; | 395 | ok = false; |
386 | } else | 396 | } else |
387 | ok = false; | 397 | ok = false; |
388 | 398 | ||
389 | } | 399 | } |
390 | } | 400 | } |
391 | return ok; | 401 | return ok; |
392 | } | 402 | } |
393 | 403 | ||
394 | AddressBook::Iterator AddressBook::begin() | 404 | AddressBook::Iterator AddressBook::begin() |
395 | { | 405 | { |
396 | Iterator it = Iterator(); | 406 | Iterator it = Iterator(); |
397 | it.d->mIt = d->mAddressees.begin(); | 407 | it.d->mIt = d->mAddressees.begin(); |
398 | return it; | 408 | return it; |
399 | } | 409 | } |
400 | 410 | ||
401 | AddressBook::ConstIterator AddressBook::begin() const | 411 | AddressBook::ConstIterator AddressBook::begin() const |
402 | { | 412 | { |
403 | ConstIterator it = ConstIterator(); | 413 | ConstIterator it = ConstIterator(); |
404 | it.d->mIt = d->mAddressees.begin(); | 414 | it.d->mIt = d->mAddressees.begin(); |
405 | return it; | 415 | return it; |
406 | } | 416 | } |
407 | 417 | ||
408 | AddressBook::Iterator AddressBook::end() | 418 | AddressBook::Iterator AddressBook::end() |
409 | { | 419 | { |
410 | Iterator it = Iterator(); | 420 | Iterator it = Iterator(); |
411 | it.d->mIt = d->mAddressees.end(); | 421 | it.d->mIt = d->mAddressees.end(); |
412 | return it; | 422 | return it; |
413 | } | 423 | } |
414 | 424 | ||
415 | AddressBook::ConstIterator AddressBook::end() const | 425 | AddressBook::ConstIterator AddressBook::end() const |
416 | { | 426 | { |
417 | ConstIterator it = ConstIterator(); | 427 | ConstIterator it = ConstIterator(); |
418 | it.d->mIt = d->mAddressees.end(); | 428 | it.d->mIt = d->mAddressees.end(); |
419 | return it; | 429 | return it; |
420 | } | 430 | } |
421 | 431 | ||
422 | void AddressBook::clear() | 432 | void AddressBook::clear() |
423 | { | 433 | { |
424 | d->mAddressees.clear(); | 434 | d->mAddressees.clear(); |
425 | } | 435 | } |
426 | 436 | ||
427 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 437 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
428 | { | 438 | { |
429 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 439 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
430 | 440 | ||
431 | if ( !resource ) | 441 | if ( !resource ) |
432 | { | 442 | { |
433 | qDebug("AddressBook::requestSaveTicket no resource" ); | 443 | qDebug("AddressBook::requestSaveTicket no resource" ); |
434 | resource = standardResource(); | 444 | resource = standardResource(); |
435 | } | 445 | } |
436 | 446 | ||
437 | KRES::Manager<Resource>::ActiveIterator it; | 447 | KRES::Manager<Resource>::ActiveIterator it; |
438 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 448 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
439 | if ( (*it) == resource ) { | 449 | if ( (*it) == resource ) { |
440 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 450 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
441 | return 0; | 451 | return 0; |
442 | else | 452 | else |
443 | return (*it)->requestSaveTicket(); | 453 | return (*it)->requestSaveTicket(); |
444 | } | 454 | } |
445 | } | 455 | } |
446 | 456 | ||
447 | return 0; | 457 | return 0; |
448 | } | 458 | } |
449 | 459 | ||
450 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 460 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
451 | { | 461 | { |
452 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 462 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
463 | //qDebug("block insert "); | ||
453 | return; | 464 | return; |
454 | } | 465 | } |
466 | //qDebug("inserting.... %s ",a.uid().latin1() ); | ||
455 | bool found = false; | 467 | bool found = false; |
456 | Addressee::List::Iterator it; | 468 | Addressee::List::Iterator it; |
457 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 469 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
458 | if ( a.uid() == (*it).uid() ) { | 470 | if ( a.uid() == (*it).uid() ) { |
459 | 471 | ||
460 | bool changed = false; | 472 | bool changed = false; |
461 | Addressee addr = a; | 473 | Addressee addr = a; |
462 | if ( addr != (*it) ) | 474 | if ( addr != (*it) ) |
463 | changed = true; | 475 | changed = true; |
464 | 476 | ||
465 | (*it) = a; | 477 | (*it) = a; |
466 | if ( (*it).resource() == 0 ) | 478 | if ( (*it).resource() == 0 ) |
467 | (*it).setResource( standardResource() ); | 479 | (*it).setResource( standardResource() ); |
468 | 480 | ||
469 | if ( changed ) { | 481 | if ( changed ) { |
470 | if ( setRev ) { | 482 | if ( setRev ) { |
471 | 483 | ||
472 | // get rid of micro seconds | 484 | // get rid of micro seconds |
473 | QDateTime dt = QDateTime::currentDateTime(); | 485 | QDateTime dt = QDateTime::currentDateTime(); |
474 | QTime t = dt.time(); | 486 | QTime t = dt.time(); |
475 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 487 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
476 | (*it).setRevision( dt ); | 488 | (*it).setRevision( dt ); |
477 | } | 489 | } |
478 | (*it).setChanged( true ); | 490 | (*it).setChanged( true ); |
479 | } | 491 | } |
480 | 492 | ||
481 | found = true; | 493 | found = true; |
482 | } else { | 494 | } else { |
483 | if ( (*it).uid() == QString("last-syncAddressee-") ) { | 495 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
484 | QString name = (*it).uid().mid( 19 ); | 496 | QString name = (*it).uid().mid( 19 ); |
485 | Addressee b = a; | 497 | Addressee b = a; |
486 | QString id = b.getID( name ); | 498 | QString id = b.getID( name ); |
487 | if ( ! id.isEmpty() ) { | 499 | if ( ! id.isEmpty() ) { |
488 | QString des = (*it).note(); | 500 | QString des = (*it).note(); |
489 | int startN; | 501 | int startN; |
490 | if( (startN = des.find( id ) ) >= 0 ) { | 502 | if( (startN = des.find( id ) ) >= 0 ) { |
491 | int endN = des.find( ",", startN+1 ); | 503 | int endN = des.find( ",", startN+1 ); |
492 | des = des.left( startN ) + des.mid( endN+1 ); | 504 | des = des.left( startN ) + des.mid( endN+1 ); |
493 | (*it).setNote( des ); | 505 | (*it).setNote( des ); |
494 | } | 506 | } |
495 | } | 507 | } |
496 | } | 508 | } |
497 | } | 509 | } |
498 | } | 510 | } |
499 | if ( found ) | 511 | if ( found ) |
500 | return; | 512 | return; |
501 | d->mAddressees.append( a ); | 513 | d->mAddressees.append( a ); |
502 | Addressee& addr = d->mAddressees.last(); | 514 | Addressee& addr = d->mAddressees.last(); |
503 | if ( addr.resource() == 0 ) | 515 | if ( addr.resource() == 0 ) |
504 | addr.setResource( standardResource() ); | 516 | addr.setResource( standardResource() ); |
505 | 517 | ||
506 | addr.setChanged( true ); | 518 | addr.setChanged( true ); |
507 | } | 519 | } |
508 | 520 | ||
509 | void AddressBook::removeAddressee( const Addressee &a ) | 521 | void AddressBook::removeAddressee( const Addressee &a ) |
510 | { | 522 | { |
511 | Iterator it; | 523 | Iterator it; |
512 | Iterator it2; | 524 | Iterator it2; |
513 | bool found = false; | 525 | bool found = false; |
514 | for ( it = begin(); it != end(); ++it ) { | 526 | for ( it = begin(); it != end(); ++it ) { |
515 | if ( a.uid() == (*it).uid() ) { | 527 | if ( a.uid() == (*it).uid() ) { |
516 | found = true; | 528 | found = true; |
517 | it2 = it; | 529 | it2 = it; |
518 | } else { | 530 | } else { |
519 | if ( (*it).uid() == QString("last-syncAddressee-") ) { | 531 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
520 | QString name = (*it).uid().mid( 19 ); | 532 | QString name = (*it).uid().mid( 19 ); |
521 | Addressee b = a; | 533 | Addressee b = a; |
522 | QString id = b.getID( name ); | 534 | QString id = b.getID( name ); |
523 | if ( ! id.isEmpty() ) { | 535 | if ( ! id.isEmpty() ) { |
524 | QString des = (*it).note(); | 536 | QString des = (*it).note(); |
525 | if( des.find( id ) < 0 ) { | 537 | if( des.find( id ) < 0 ) { |
526 | des += id + ","; | 538 | des += id + ","; |
527 | (*it).setNote( des ); | 539 | (*it).setNote( des ); |
528 | } | 540 | } |
529 | } | 541 | } |
530 | } | 542 | } |
531 | 543 | ||
532 | } | 544 | } |
533 | } | 545 | } |
534 | 546 | ||
535 | if ( found ) | 547 | if ( found ) |
536 | removeAddressee( it2 ); | 548 | removeAddressee( it2 ); |
537 | 549 | ||
538 | } | 550 | } |
539 | 551 | ||
540 | void AddressBook::removeDeletedAddressees() | 552 | void AddressBook::removeDeletedAddressees() |
541 | { | 553 | { |
542 | deleteRemovedAddressees(); | 554 | deleteRemovedAddressees(); |
543 | Iterator it = begin(); | 555 | Iterator it = begin(); |
544 | Iterator it2 ; | 556 | Iterator it2 ; |
545 | QDateTime dt ( QDate( 2004,1,1) ); | 557 | QDateTime dt ( QDate( 2004,1,1) ); |
546 | while ( it != end() ) { | 558 | while ( it != end() ) { |
547 | (*it).setRevision( dt ); | 559 | (*it).setRevision( dt ); |
548 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 560 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
561 | (*it).setIDStr(""); | ||
562 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | ||
549 | it2 = it; | 563 | it2 = it; |
564 | //qDebug("removing %s ",(*it).uid().latin1() ); | ||
550 | ++it; | 565 | ++it; |
551 | removeAddressee( it2 ); | 566 | removeAddressee( it2 ); |
552 | } else | 567 | } else { |
568 | //qDebug("skipping %s ",(*it).uid().latin1() ); | ||
553 | ++it; | 569 | ++it; |
570 | } | ||
554 | } | 571 | } |
555 | deleteRemovedAddressees(); | 572 | deleteRemovedAddressees(); |
556 | } | 573 | } |
557 | 574 | ||
558 | void AddressBook::removeAddressee( const Iterator &it ) | 575 | void AddressBook::removeAddressee( const Iterator &it ) |
559 | { | 576 | { |
560 | d->mRemovedAddressees.append( (*it) ); | 577 | d->mRemovedAddressees.append( (*it) ); |
561 | d->mAddressees.remove( it.d->mIt ); | 578 | d->mAddressees.remove( it.d->mIt ); |
562 | } | 579 | } |
563 | 580 | ||
564 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 581 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
565 | { | 582 | { |
566 | Iterator it; | 583 | Iterator it; |
567 | for ( it = begin(); it != end(); ++it ) { | 584 | for ( it = begin(); it != end(); ++it ) { |
568 | if ( a.uid() == (*it).uid() ) { | 585 | if ( a.uid() == (*it).uid() ) { |
569 | return it; | 586 | return it; |
570 | } | 587 | } |
571 | } | 588 | } |
572 | return end(); | 589 | return end(); |
573 | } | 590 | } |
574 | 591 | ||
575 | Addressee AddressBook::findByUid( const QString &uid ) | 592 | Addressee AddressBook::findByUid( const QString &uid ) |
576 | { | 593 | { |
577 | Iterator it; | 594 | Iterator it; |
578 | for ( it = begin(); it != end(); ++it ) { | 595 | for ( it = begin(); it != end(); ++it ) { |
579 | if ( uid == (*it).uid() ) { | 596 | if ( uid == (*it).uid() ) { |
580 | return *it; | 597 | return *it; |
581 | } | 598 | } |
582 | } | 599 | } |
583 | return Addressee(); | 600 | return Addressee(); |
584 | } | 601 | } |
585 | #if 0 | 602 | #if 0 |
586 | Addressee::List AddressBook::getExternLastSyncAddressees() | 603 | Addressee::List AddressBook::getExternLastSyncAddressees() |
587 | { | 604 | { |
588 | Addressee::List results; | 605 | Addressee::List results; |
589 | 606 | ||
590 | Iterator it; | 607 | Iterator it; |
591 | for ( it = begin(); it != end(); ++it ) { | 608 | for ( it = begin(); it != end(); ++it ) { |
592 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 609 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
593 | if ( (*it).familyName().left(4) == "!E: " ) | 610 | if ( (*it).familyName().left(4) == "!E: " ) |
594 | results.append( *it ); | 611 | results.append( *it ); |
595 | } | 612 | } |
596 | } | 613 | } |
597 | 614 | ||
598 | return results; | 615 | return results; |
599 | } | 616 | } |
600 | #endif | 617 | #endif |
601 | void AddressBook::resetTempSyncStat() | 618 | void AddressBook::resetTempSyncStat() |
602 | { | 619 | { |
603 | Iterator it; | 620 | Iterator it; |
604 | for ( it = begin(); it != end(); ++it ) { | 621 | for ( it = begin(); it != end(); ++it ) { |
605 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 622 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
606 | } | 623 | } |
607 | 624 | ||
608 | } | 625 | } |
609 | 626 | ||
610 | QStringList AddressBook:: uidList() | 627 | QStringList AddressBook:: uidList() |
611 | { | 628 | { |
612 | QStringList results; | 629 | QStringList results; |
613 | Iterator it; | 630 | Iterator it; |
614 | for ( it = begin(); it != end(); ++it ) { | 631 | for ( it = begin(); it != end(); ++it ) { |
615 | results.append( (*it).uid() ); | 632 | results.append( (*it).uid() ); |
616 | } | 633 | } |
617 | return results; | 634 | return results; |
618 | } | 635 | } |
619 | 636 | ||
620 | 637 | ||
621 | Addressee::List AddressBook::allAddressees() | 638 | Addressee::List AddressBook::allAddressees() |
622 | { | 639 | { |
623 | return d->mAddressees; | 640 | return d->mAddressees; |
624 | 641 | ||
625 | } | 642 | } |
626 | 643 | ||
627 | Addressee::List AddressBook::findByName( const QString &name ) | 644 | Addressee::List AddressBook::findByName( const QString &name ) |
628 | { | 645 | { |
629 | Addressee::List results; | 646 | Addressee::List results; |
630 | 647 | ||
631 | Iterator it; | 648 | Iterator it; |
632 | for ( it = begin(); it != end(); ++it ) { | 649 | for ( it = begin(); it != end(); ++it ) { |
633 | if ( name == (*it).realName() ) { | 650 | if ( name == (*it).realName() ) { |
634 | results.append( *it ); | 651 | results.append( *it ); |
635 | } | 652 | } |
636 | } | 653 | } |
637 | 654 | ||
638 | return results; | 655 | return results; |
639 | } | 656 | } |
640 | 657 | ||
641 | Addressee::List AddressBook::findByEmail( const QString &email ) | 658 | Addressee::List AddressBook::findByEmail( const QString &email ) |
642 | { | 659 | { |
643 | Addressee::List results; | 660 | Addressee::List results; |
644 | QStringList mailList; | 661 | QStringList mailList; |
645 | 662 | ||
646 | Iterator it; | 663 | Iterator it; |
647 | for ( it = begin(); it != end(); ++it ) { | 664 | for ( it = begin(); it != end(); ++it ) { |
648 | mailList = (*it).emails(); | 665 | mailList = (*it).emails(); |
649 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 666 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
650 | if ( email == (*ite) ) { | 667 | if ( email == (*ite) ) { |
651 | results.append( *it ); | 668 | results.append( *it ); |
652 | } | 669 | } |
653 | } | 670 | } |
654 | } | 671 | } |
655 | 672 | ||
656 | return results; | 673 | return results; |
657 | } | 674 | } |
658 | 675 | ||
659 | Addressee::List AddressBook::findByCategory( const QString &category ) | 676 | Addressee::List AddressBook::findByCategory( const QString &category ) |
660 | { | 677 | { |
661 | Addressee::List results; | 678 | Addressee::List results; |
662 | 679 | ||
663 | Iterator it; | 680 | Iterator it; |
664 | for ( it = begin(); it != end(); ++it ) { | 681 | for ( it = begin(); it != end(); ++it ) { |
665 | if ( (*it).hasCategory( category) ) { | 682 | if ( (*it).hasCategory( category) ) { |
666 | results.append( *it ); | 683 | results.append( *it ); |
667 | } | 684 | } |
668 | } | 685 | } |
669 | 686 | ||
670 | return results; | 687 | return results; |
671 | } | 688 | } |
672 | 689 | ||
673 | void AddressBook::dump() const | 690 | void AddressBook::dump() const |
674 | { | 691 | { |
675 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 692 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
676 | 693 | ||
677 | ConstIterator it; | 694 | ConstIterator it; |
678 | for( it = begin(); it != end(); ++it ) { | 695 | for( it = begin(); it != end(); ++it ) { |
679 | (*it).dump(); | 696 | (*it).dump(); |
680 | } | 697 | } |
681 | 698 | ||
682 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 699 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
683 | } | 700 | } |
684 | 701 | ||
685 | QString AddressBook::identifier() | 702 | QString AddressBook::identifier() |
686 | { | 703 | { |
687 | QStringList identifier; | 704 | QStringList identifier; |
688 | 705 | ||
689 | 706 | ||
690 | KRES::Manager<Resource>::ActiveIterator it; | 707 | KRES::Manager<Resource>::ActiveIterator it; |
691 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 708 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
692 | if ( !(*it)->identifier().isEmpty() ) | 709 | if ( !(*it)->identifier().isEmpty() ) |
693 | identifier.append( (*it)->identifier() ); | 710 | identifier.append( (*it)->identifier() ); |
694 | } | 711 | } |
695 | 712 | ||
696 | return identifier.join( ":" ); | 713 | return identifier.join( ":" ); |
697 | } | 714 | } |
698 | 715 | ||
699 | Field::List AddressBook::fields( int category ) | 716 | Field::List AddressBook::fields( int category ) |
700 | { | 717 | { |
701 | if ( d->mAllFields.isEmpty() ) { | 718 | if ( d->mAllFields.isEmpty() ) { |
702 | d->mAllFields = Field::allFields(); | 719 | d->mAllFields = Field::allFields(); |
703 | } | 720 | } |
704 | 721 | ||
705 | if ( category == Field::All ) return d->mAllFields; | 722 | if ( category == Field::All ) return d->mAllFields; |
706 | 723 | ||
707 | Field::List result; | 724 | Field::List result; |
708 | Field::List::ConstIterator it; | 725 | Field::List::ConstIterator it; |
709 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 726 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
710 | if ( (*it)->category() & category ) result.append( *it ); | 727 | if ( (*it)->category() & category ) result.append( *it ); |
711 | } | 728 | } |
712 | 729 | ||
713 | return result; | 730 | return result; |
714 | } | 731 | } |
715 | 732 | ||
716 | bool AddressBook::addCustomField( const QString &label, int category, | 733 | bool AddressBook::addCustomField( const QString &label, int category, |
717 | const QString &key, const QString &app ) | 734 | const QString &key, const QString &app ) |
718 | { | 735 | { |
719 | if ( d->mAllFields.isEmpty() ) { | 736 | if ( d->mAllFields.isEmpty() ) { |
720 | d->mAllFields = Field::allFields(); | 737 | d->mAllFields = Field::allFields(); |
721 | } | 738 | } |
722 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 739 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
723 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 740 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
724 | 741 | ||
725 | QString k = key.isNull() ? label : key; | 742 | QString k = key.isNull() ? label : key; |
726 | 743 | ||
727 | Field *field = Field::createCustomField( label, category, k, a ); | 744 | Field *field = Field::createCustomField( label, category, k, a ); |
728 | 745 | ||
729 | if ( !field ) return false; | 746 | if ( !field ) return false; |
730 | 747 | ||
731 | d->mAllFields.append( field ); | 748 | d->mAllFields.append( field ); |
732 | 749 | ||
733 | return true; | 750 | return true; |
734 | } | 751 | } |
735 | 752 | ||
736 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 753 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
737 | { | 754 | { |
738 | if (!ab.d) return s; | 755 | if (!ab.d) return s; |
739 | 756 | ||
740 | return s << ab.d->mAddressees; | 757 | return s << ab.d->mAddressees; |
741 | } | 758 | } |
742 | 759 | ||
743 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 760 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
744 | { | 761 | { |
745 | if (!ab.d) return s; | 762 | if (!ab.d) return s; |
746 | 763 | ||
747 | s >> ab.d->mAddressees; | 764 | s >> ab.d->mAddressees; |
748 | 765 | ||
749 | return s; | 766 | return s; |
750 | } | 767 | } |
751 | 768 | ||
752 | bool AddressBook::addResource( Resource *resource ) | 769 | bool AddressBook::addResource( Resource *resource ) |
753 | { | 770 | { |
754 | if ( !resource->open() ) { | 771 | if ( !resource->open() ) { |
755 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 772 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
756 | return false; | 773 | return false; |
757 | } | 774 | } |
758 | 775 | ||
759 | resource->setAddressBook( this ); | 776 | resource->setAddressBook( this ); |
760 | 777 | ||
761 | d->mManager->add( resource ); | 778 | d->mManager->add( resource ); |
762 | return true; | 779 | return true; |
763 | } | 780 | } |
764 | 781 | ||
765 | bool AddressBook::removeResource( Resource *resource ) | 782 | bool AddressBook::removeResource( Resource *resource ) |
766 | { | 783 | { |
767 | resource->close(); | 784 | resource->close(); |
768 | 785 | ||
769 | if ( resource == standardResource() ) | 786 | if ( resource == standardResource() ) |
770 | d->mManager->setStandardResource( 0 ); | 787 | d->mManager->setStandardResource( 0 ); |
771 | 788 | ||
772 | resource->setAddressBook( 0 ); | 789 | resource->setAddressBook( 0 ); |
773 | 790 | ||
774 | d->mManager->remove( resource ); | 791 | d->mManager->remove( resource ); |
775 | return true; | 792 | return true; |
776 | } | 793 | } |
777 | 794 | ||
778 | QPtrList<Resource> AddressBook::resources() | 795 | QPtrList<Resource> AddressBook::resources() |
779 | { | 796 | { |
780 | QPtrList<Resource> list; | 797 | QPtrList<Resource> list; |
781 | 798 | ||
782 | // qDebug("AddressBook::resources() 1"); | 799 | // qDebug("AddressBook::resources() 1"); |
783 | 800 | ||
784 | KRES::Manager<Resource>::ActiveIterator it; | 801 | KRES::Manager<Resource>::ActiveIterator it; |
785 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 802 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
786 | list.append( *it ); | 803 | list.append( *it ); |
787 | 804 | ||
788 | return list; | 805 | return list; |
789 | } | 806 | } |
790 | 807 | ||
791 | /*US | 808 | /*US |
792 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 809 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
793 | { | 810 | { |
794 | delete d->mErrorHandler; | 811 | delete d->mErrorHandler; |
795 | d->mErrorHandler = handler; | 812 | d->mErrorHandler = handler; |
796 | } | 813 | } |
797 | */ | 814 | */ |
798 | 815 | ||
799 | void AddressBook::error( const QString& msg ) | 816 | void AddressBook::error( const QString& msg ) |
800 | { | 817 | { |
801 | /*US | 818 | /*US |
802 | if ( !d->mErrorHandler ) // create default error handler | 819 | if ( !d->mErrorHandler ) // create default error handler |
803 | d->mErrorHandler = new ConsoleErrorHandler; | 820 | d->mErrorHandler = new ConsoleErrorHandler; |
804 | 821 | ||
805 | if ( d->mErrorHandler ) | 822 | if ( d->mErrorHandler ) |
806 | d->mErrorHandler->error( msg ); | 823 | d->mErrorHandler->error( msg ); |
807 | else | 824 | else |
808 | kdError(5700) << "no error handler defined" << endl; | 825 | kdError(5700) << "no error handler defined" << endl; |
809 | */ | 826 | */ |
810 | kdDebug(5700) << "msg" << endl; | 827 | kdDebug(5700) << "msg" << endl; |
811 | qDebug(msg); | 828 | qDebug(msg); |
812 | } | 829 | } |
813 | 830 | ||
814 | void AddressBook::deleteRemovedAddressees() | 831 | void AddressBook::deleteRemovedAddressees() |
815 | { | 832 | { |
816 | Addressee::List::Iterator it; | 833 | Addressee::List::Iterator it; |
817 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 834 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
818 | Resource *resource = (*it).resource(); | 835 | Resource *resource = (*it).resource(); |
819 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 836 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
820 | resource->removeAddressee( *it ); | 837 | resource->removeAddressee( *it ); |
821 | } | 838 | } |
822 | 839 | ||
823 | d->mRemovedAddressees.clear(); | 840 | d->mRemovedAddressees.clear(); |
824 | } | 841 | } |
825 | 842 | ||
826 | void AddressBook::setStandardResource( Resource *resource ) | 843 | void AddressBook::setStandardResource( Resource *resource ) |
827 | { | 844 | { |
828 | // qDebug("AddressBook::setStandardResource 1"); | 845 | // qDebug("AddressBook::setStandardResource 1"); |
829 | d->mManager->setStandardResource( resource ); | 846 | d->mManager->setStandardResource( resource ); |
830 | } | 847 | } |
831 | 848 | ||
832 | Resource *AddressBook::standardResource() | 849 | Resource *AddressBook::standardResource() |
833 | { | 850 | { |
834 | return d->mManager->standardResource(); | 851 | return d->mManager->standardResource(); |
835 | } | 852 | } |
836 | 853 | ||
837 | KRES::Manager<Resource> *AddressBook::resourceManager() | 854 | KRES::Manager<Resource> *AddressBook::resourceManager() |
838 | { | 855 | { |
839 | return d->mManager; | 856 | return d->mManager; |
840 | } | 857 | } |
841 | 858 | ||
842 | void AddressBook::cleanUp() | 859 | void AddressBook::cleanUp() |
843 | { | 860 | { |
844 | KRES::Manager<Resource>::ActiveIterator it; | 861 | KRES::Manager<Resource>::ActiveIterator it; |
845 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 862 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
846 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 863 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
847 | (*it)->cleanUp(); | 864 | (*it)->cleanUp(); |
848 | } | 865 | } |
849 | } | 866 | } |