author | zautrix <zautrix> | 2004-09-20 19:27:24 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-20 19:27:24 (UTC) |
commit | ed49c55dac215ac2ed9286ebfc36e5a19417f0bb (patch) (unidiff) | |
tree | 79f933ed5d4a9a9df524dbd71d41d12dde007401 /kabc | |
parent | 138be6cfa921cd8a07fa0b18046d955e7d2dbd6e (diff) | |
download | kdepimpi-ed49c55dac215ac2ed9286ebfc36e5a19417f0bb.zip kdepimpi-ed49c55dac215ac2ed9286ebfc36e5a19417f0bb.tar.gz kdepimpi-ed49c55dac215ac2ed9286ebfc36e5a19417f0bb.tar.bz2 |
more DTM sync
-rw-r--r-- | kabc/addressbook.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 17b9ba2..adb451f 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,937 +1,940 @@ | |||
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( "FileName", config ); | 251 | con->writeEntry( "FileName", config ); |
252 | con->writeEntry( "FileFormat", QString("vcard") ); | 252 | con->writeEntry( "FileFormat", QString("vcard") ); |
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 | if ( config.right(4) == ".xml" ) | 255 | if ( config.right(4) == ".xml" ) |
256 | con->writeEntry( "ResourceType", QString("qtopia") ); | 256 | con->writeEntry( "ResourceType", QString("qtopia") ); |
257 | else | 257 | else if ( config == "sharp" ) { |
258 | con->writeEntry( "ResourceType", QString("sharp") ); | ||
259 | } else { | ||
258 | con->writeEntry( "ResourceType", QString("file") ); | 260 | con->writeEntry( "ResourceType", QString("file") ); |
261 | } | ||
259 | //con->sync(); | 262 | //con->sync(); |
260 | d->mConfig = con; | 263 | d->mConfig = con; |
261 | } | 264 | } |
262 | else | 265 | else |
263 | d->mConfig = new KConfig( locateLocal("config", config) ); | 266 | d->mConfig = new KConfig( locateLocal("config", config) ); |
264 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 267 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
265 | } | 268 | } |
266 | else { | 269 | else { |
267 | d->mConfig = 0; | 270 | d->mConfig = 0; |
268 | // qDebug("AddressBook::init 1 config=0"); | 271 | // qDebug("AddressBook::init 1 config=0"); |
269 | } | 272 | } |
270 | 273 | ||
271 | //US d->mErrorHandler = 0; | 274 | //US d->mErrorHandler = 0; |
272 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 275 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
273 | d->mManager->readConfig( d->mConfig ); | 276 | d->mManager->readConfig( d->mConfig ); |
274 | if ( family == "syncContact" ) { | 277 | if ( family == "syncContact" ) { |
275 | KRES::Manager<Resource> *manager = d->mManager; | 278 | KRES::Manager<Resource> *manager = d->mManager; |
276 | KRES::Manager<Resource>::ActiveIterator it; | 279 | KRES::Manager<Resource>::ActiveIterator it; |
277 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 280 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
278 | (*it)->setAddressBook( this ); | 281 | (*it)->setAddressBook( this ); |
279 | if ( !(*it)->open() ) | 282 | if ( !(*it)->open() ) |
280 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 283 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
281 | } | 284 | } |
282 | Resource *res = standardResource(); | 285 | Resource *res = standardResource(); |
283 | if ( !res ) { | 286 | if ( !res ) { |
284 | qDebug("ERROR: no standard resource"); | 287 | qDebug("ERROR: no standard resource"); |
285 | res = manager->createResource( "file" ); | 288 | res = manager->createResource( "file" ); |
286 | if ( res ) | 289 | if ( res ) |
287 | { | 290 | { |
288 | addResource( res ); | 291 | addResource( res ); |
289 | } | 292 | } |
290 | else | 293 | else |
291 | qDebug(" No resource available!!!"); | 294 | qDebug(" No resource available!!!"); |
292 | } | 295 | } |
293 | setStandardResource( res ); | 296 | setStandardResource( res ); |
294 | manager->writeConfig(); | 297 | manager->writeConfig(); |
295 | } | 298 | } |
296 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 299 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
297 | "X-Department", "KADDRESSBOOK" ); | 300 | "X-Department", "KADDRESSBOOK" ); |
298 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 301 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
299 | "X-Profession", "KADDRESSBOOK" ); | 302 | "X-Profession", "KADDRESSBOOK" ); |
300 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 303 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
301 | "X-AssistantsName", "KADDRESSBOOK" ); | 304 | "X-AssistantsName", "KADDRESSBOOK" ); |
302 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 305 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
303 | "X-ManagersName", "KADDRESSBOOK" ); | 306 | "X-ManagersName", "KADDRESSBOOK" ); |
304 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 307 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
305 | "X-SpousesName", "KADDRESSBOOK" ); | 308 | "X-SpousesName", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 309 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
307 | "X-Office", "KADDRESSBOOK" ); | 310 | "X-Office", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 311 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
309 | "X-IMAddress", "KADDRESSBOOK" ); | 312 | "X-IMAddress", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 313 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
311 | "X-Anniversary", "KADDRESSBOOK" ); | 314 | "X-Anniversary", "KADDRESSBOOK" ); |
312 | 315 | ||
313 | //US added this field to become compatible with Opie/qtopia addressbook | 316 | //US added this field to become compatible with Opie/qtopia addressbook |
314 | // values can be "female" or "male" or "". An empty field represents undefined. | 317 | // values can be "female" or "male" or "". An empty field represents undefined. |
315 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
316 | "X-Gender", "KADDRESSBOOK" ); | 319 | "X-Gender", "KADDRESSBOOK" ); |
317 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 320 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
318 | "X-Children", "KADDRESSBOOK" ); | 321 | "X-Children", "KADDRESSBOOK" ); |
319 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 322 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
320 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 323 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
321 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 324 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
322 | "X-ExternalID", "KADDRESSBOOK" ); | 325 | "X-ExternalID", "KADDRESSBOOK" ); |
323 | } | 326 | } |
324 | 327 | ||
325 | AddressBook::~AddressBook() | 328 | AddressBook::~AddressBook() |
326 | { | 329 | { |
327 | delete d->mConfig; d->mConfig = 0; | 330 | delete d->mConfig; d->mConfig = 0; |
328 | delete d->mManager; d->mManager = 0; | 331 | delete d->mManager; d->mManager = 0; |
329 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 332 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
330 | delete d; d = 0; | 333 | delete d; d = 0; |
331 | } | 334 | } |
332 | 335 | ||
333 | bool AddressBook::load() | 336 | bool AddressBook::load() |
334 | { | 337 | { |
335 | 338 | ||
336 | 339 | ||
337 | clear(); | 340 | clear(); |
338 | 341 | ||
339 | KRES::Manager<Resource>::ActiveIterator it; | 342 | KRES::Manager<Resource>::ActiveIterator it; |
340 | bool ok = true; | 343 | bool ok = true; |
341 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 344 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
342 | if ( !(*it)->load() ) { | 345 | if ( !(*it)->load() ) { |
343 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 346 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
344 | ok = false; | 347 | ok = false; |
345 | } | 348 | } |
346 | 349 | ||
347 | // mark all addressees as unchanged | 350 | // mark all addressees as unchanged |
348 | Addressee::List::Iterator addrIt; | 351 | Addressee::List::Iterator addrIt; |
349 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 352 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
350 | (*addrIt).setChanged( false ); | 353 | (*addrIt).setChanged( false ); |
351 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 354 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
352 | if ( !id.isEmpty() ) { | 355 | if ( !id.isEmpty() ) { |
353 | //qDebug("setId aa %s ", id.latin1()); | 356 | //qDebug("setId aa %s ", id.latin1()); |
354 | (*addrIt).setIDStr(id ); | 357 | (*addrIt).setIDStr(id ); |
355 | } | 358 | } |
356 | } | 359 | } |
357 | blockLSEchange = true; | 360 | blockLSEchange = true; |
358 | return ok; | 361 | return ok; |
359 | } | 362 | } |
360 | 363 | ||
361 | bool AddressBook::save( Ticket *ticket ) | 364 | bool AddressBook::save( Ticket *ticket ) |
362 | { | 365 | { |
363 | kdDebug(5700) << "AddressBook::save()"<< endl; | 366 | kdDebug(5700) << "AddressBook::save()"<< endl; |
364 | 367 | ||
365 | if ( ticket->resource() ) { | 368 | if ( ticket->resource() ) { |
366 | deleteRemovedAddressees(); | 369 | deleteRemovedAddressees(); |
367 | return ticket->resource()->save( ticket ); | 370 | return ticket->resource()->save( ticket ); |
368 | } | 371 | } |
369 | 372 | ||
370 | return false; | 373 | return false; |
371 | } | 374 | } |
372 | bool AddressBook::saveAB() | 375 | bool AddressBook::saveAB() |
373 | { | 376 | { |
374 | bool ok = true; | 377 | bool ok = true; |
375 | 378 | ||
376 | deleteRemovedAddressees(); | 379 | deleteRemovedAddressees(); |
377 | Iterator ait; | 380 | Iterator ait; |
378 | for ( ait = begin(); ait != end(); ++ait ) { | 381 | for ( ait = begin(); ait != end(); ++ait ) { |
379 | if ( !(*ait).IDStr().isEmpty() ) { | 382 | if ( !(*ait).IDStr().isEmpty() ) { |
380 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 383 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
381 | } | 384 | } |
382 | } | 385 | } |
383 | KRES::Manager<Resource>::ActiveIterator it; | 386 | KRES::Manager<Resource>::ActiveIterator it; |
384 | KRES::Manager<Resource> *manager = d->mManager; | 387 | KRES::Manager<Resource> *manager = d->mManager; |
385 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 388 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
386 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 389 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
387 | Ticket *ticket = requestSaveTicket( *it ); | 390 | Ticket *ticket = requestSaveTicket( *it ); |
388 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 391 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
389 | if ( !ticket ) { | 392 | if ( !ticket ) { |
390 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 393 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
391 | .arg( (*it)->resourceName() ) ); | 394 | .arg( (*it)->resourceName() ) ); |
392 | return false; | 395 | return false; |
393 | } | 396 | } |
394 | 397 | ||
395 | //if ( !save( ticket ) ) | 398 | //if ( !save( ticket ) ) |
396 | if ( ticket->resource() ) { | 399 | if ( ticket->resource() ) { |
397 | if ( ! ticket->resource()->save( ticket ) ) | 400 | if ( ! ticket->resource()->save( ticket ) ) |
398 | ok = false; | 401 | ok = false; |
399 | } else | 402 | } else |
400 | ok = false; | 403 | ok = false; |
401 | 404 | ||
402 | } | 405 | } |
403 | } | 406 | } |
404 | return ok; | 407 | return ok; |
405 | } | 408 | } |
406 | 409 | ||
407 | AddressBook::Iterator AddressBook::begin() | 410 | AddressBook::Iterator AddressBook::begin() |
408 | { | 411 | { |
409 | Iterator it = Iterator(); | 412 | Iterator it = Iterator(); |
410 | it.d->mIt = d->mAddressees.begin(); | 413 | it.d->mIt = d->mAddressees.begin(); |
411 | return it; | 414 | return it; |
412 | } | 415 | } |
413 | 416 | ||
414 | AddressBook::ConstIterator AddressBook::begin() const | 417 | AddressBook::ConstIterator AddressBook::begin() const |
415 | { | 418 | { |
416 | ConstIterator it = ConstIterator(); | 419 | ConstIterator it = ConstIterator(); |
417 | it.d->mIt = d->mAddressees.begin(); | 420 | it.d->mIt = d->mAddressees.begin(); |
418 | return it; | 421 | return it; |
419 | } | 422 | } |
420 | 423 | ||
421 | AddressBook::Iterator AddressBook::end() | 424 | AddressBook::Iterator AddressBook::end() |
422 | { | 425 | { |
423 | Iterator it = Iterator(); | 426 | Iterator it = Iterator(); |
424 | it.d->mIt = d->mAddressees.end(); | 427 | it.d->mIt = d->mAddressees.end(); |
425 | return it; | 428 | return it; |
426 | } | 429 | } |
427 | 430 | ||
428 | AddressBook::ConstIterator AddressBook::end() const | 431 | AddressBook::ConstIterator AddressBook::end() const |
429 | { | 432 | { |
430 | ConstIterator it = ConstIterator(); | 433 | ConstIterator it = ConstIterator(); |
431 | it.d->mIt = d->mAddressees.end(); | 434 | it.d->mIt = d->mAddressees.end(); |
432 | return it; | 435 | return it; |
433 | } | 436 | } |
434 | 437 | ||
435 | void AddressBook::clear() | 438 | void AddressBook::clear() |
436 | { | 439 | { |
437 | d->mAddressees.clear(); | 440 | d->mAddressees.clear(); |
438 | } | 441 | } |
439 | 442 | ||
440 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 443 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
441 | { | 444 | { |
442 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 445 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
443 | 446 | ||
444 | if ( !resource ) | 447 | if ( !resource ) |
445 | { | 448 | { |
446 | qDebug("AddressBook::requestSaveTicket no resource" ); | 449 | qDebug("AddressBook::requestSaveTicket no resource" ); |
447 | resource = standardResource(); | 450 | resource = standardResource(); |
448 | } | 451 | } |
449 | 452 | ||
450 | KRES::Manager<Resource>::ActiveIterator it; | 453 | KRES::Manager<Resource>::ActiveIterator it; |
451 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 454 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
452 | if ( (*it) == resource ) { | 455 | if ( (*it) == resource ) { |
453 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 456 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
454 | return 0; | 457 | return 0; |
455 | else | 458 | else |
456 | return (*it)->requestSaveTicket(); | 459 | return (*it)->requestSaveTicket(); |
457 | } | 460 | } |
458 | } | 461 | } |
459 | 462 | ||
460 | return 0; | 463 | return 0; |
461 | } | 464 | } |
462 | 465 | ||
463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 466 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
464 | { | 467 | { |
465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 468 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
466 | //qDebug("block insert "); | 469 | //qDebug("block insert "); |
467 | return; | 470 | return; |
468 | } | 471 | } |
469 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 472 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
470 | bool found = false; | 473 | bool found = false; |
471 | Addressee::List::Iterator it; | 474 | Addressee::List::Iterator it; |
472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 475 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
473 | if ( a.uid() == (*it).uid() ) { | 476 | if ( a.uid() == (*it).uid() ) { |
474 | 477 | ||
475 | bool changed = false; | 478 | bool changed = false; |
476 | Addressee addr = a; | 479 | Addressee addr = a; |
477 | if ( addr != (*it) ) | 480 | if ( addr != (*it) ) |
478 | changed = true; | 481 | changed = true; |
479 | 482 | ||
480 | (*it) = a; | 483 | (*it) = a; |
481 | if ( (*it).resource() == 0 ) | 484 | if ( (*it).resource() == 0 ) |
482 | (*it).setResource( standardResource() ); | 485 | (*it).setResource( standardResource() ); |
483 | 486 | ||
484 | if ( changed ) { | 487 | if ( changed ) { |
485 | if ( setRev ) { | 488 | if ( setRev ) { |
486 | 489 | ||
487 | // get rid of micro seconds | 490 | // get rid of micro seconds |
488 | QDateTime dt = QDateTime::currentDateTime(); | 491 | QDateTime dt = QDateTime::currentDateTime(); |
489 | QTime t = dt.time(); | 492 | QTime t = dt.time(); |
490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 493 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
491 | (*it).setRevision( dt ); | 494 | (*it).setRevision( dt ); |
492 | } | 495 | } |
493 | (*it).setChanged( true ); | 496 | (*it).setChanged( true ); |
494 | } | 497 | } |
495 | 498 | ||
496 | found = true; | 499 | found = true; |
497 | } else { | 500 | } else { |
498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 501 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
499 | QString name = (*it).uid().mid( 19 ); | 502 | QString name = (*it).uid().mid( 19 ); |
500 | Addressee b = a; | 503 | Addressee b = a; |
501 | QString id = b.getID( name ); | 504 | QString id = b.getID( name ); |
502 | if ( ! id.isEmpty() ) { | 505 | if ( ! id.isEmpty() ) { |
503 | QString des = (*it).note(); | 506 | QString des = (*it).note(); |
504 | int startN; | 507 | int startN; |
505 | if( (startN = des.find( id ) ) >= 0 ) { | 508 | if( (startN = des.find( id ) ) >= 0 ) { |
506 | int endN = des.find( ",", startN+1 ); | 509 | int endN = des.find( ",", startN+1 ); |
507 | des = des.left( startN ) + des.mid( endN+1 ); | 510 | des = des.left( startN ) + des.mid( endN+1 ); |
508 | (*it).setNote( des ); | 511 | (*it).setNote( des ); |
509 | } | 512 | } |
510 | } | 513 | } |
511 | } | 514 | } |
512 | } | 515 | } |
513 | } | 516 | } |
514 | if ( found ) | 517 | if ( found ) |
515 | return; | 518 | return; |
516 | d->mAddressees.append( a ); | 519 | d->mAddressees.append( a ); |
517 | Addressee& addr = d->mAddressees.last(); | 520 | Addressee& addr = d->mAddressees.last(); |
518 | if ( addr.resource() == 0 ) | 521 | if ( addr.resource() == 0 ) |
519 | addr.setResource( standardResource() ); | 522 | addr.setResource( standardResource() ); |
520 | 523 | ||
521 | addr.setChanged( true ); | 524 | addr.setChanged( true ); |
522 | } | 525 | } |
523 | 526 | ||
524 | void AddressBook::removeAddressee( const Addressee &a ) | 527 | void AddressBook::removeAddressee( const Addressee &a ) |
525 | { | 528 | { |
526 | Iterator it; | 529 | Iterator it; |
527 | Iterator it2; | 530 | Iterator it2; |
528 | bool found = false; | 531 | bool found = false; |
529 | for ( it = begin(); it != end(); ++it ) { | 532 | for ( it = begin(); it != end(); ++it ) { |
530 | if ( a.uid() == (*it).uid() ) { | 533 | if ( a.uid() == (*it).uid() ) { |
531 | found = true; | 534 | found = true; |
532 | it2 = it; | 535 | it2 = it; |
533 | } else { | 536 | } else { |
534 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 537 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
535 | QString name = (*it).uid().mid( 19 ); | 538 | QString name = (*it).uid().mid( 19 ); |
536 | Addressee b = a; | 539 | Addressee b = a; |
537 | QString id = b.getID( name ); | 540 | QString id = b.getID( name ); |
538 | if ( ! id.isEmpty() ) { | 541 | if ( ! id.isEmpty() ) { |
539 | QString des = (*it).note(); | 542 | QString des = (*it).note(); |
540 | if( des.find( id ) < 0 ) { | 543 | if( des.find( id ) < 0 ) { |
541 | des += id + ","; | 544 | des += id + ","; |
542 | (*it).setNote( des ); | 545 | (*it).setNote( des ); |
543 | } | 546 | } |
544 | } | 547 | } |
545 | } | 548 | } |
546 | 549 | ||
547 | } | 550 | } |
548 | } | 551 | } |
549 | 552 | ||
550 | if ( found ) | 553 | if ( found ) |
551 | removeAddressee( it2 ); | 554 | removeAddressee( it2 ); |
552 | 555 | ||
553 | } | 556 | } |
554 | 557 | ||
555 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 558 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
556 | { | 559 | { |
557 | Iterator it = begin(); | 560 | Iterator it = begin(); |
558 | Iterator it2 ; | 561 | Iterator it2 ; |
559 | QDateTime dt ( QDate( 2004,1,1) ); | 562 | QDateTime dt ( QDate( 2004,1,1) ); |
560 | while ( it != end() ) { | 563 | while ( it != end() ) { |
561 | (*it).setRevision( dt ); | 564 | (*it).setRevision( dt ); |
562 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 565 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
563 | (*it).setIDStr(""); | 566 | (*it).setIDStr(""); |
564 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 567 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
565 | it2 = it; | 568 | it2 = it; |
566 | //qDebug("removing %s ",(*it).uid().latin1() ); | 569 | //qDebug("removing %s ",(*it).uid().latin1() ); |
567 | ++it; | 570 | ++it; |
568 | removeAddressee( it2 ); | 571 | removeAddressee( it2 ); |
569 | } else { | 572 | } else { |
570 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 573 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
571 | ++it; | 574 | ++it; |
572 | } | 575 | } |
573 | } | 576 | } |
574 | deleteRemovedAddressees(); | 577 | deleteRemovedAddressees(); |
575 | } | 578 | } |
576 | 579 | ||
577 | void AddressBook::removeAddressee( const Iterator &it ) | 580 | void AddressBook::removeAddressee( const Iterator &it ) |
578 | { | 581 | { |
579 | d->mRemovedAddressees.append( (*it) ); | 582 | d->mRemovedAddressees.append( (*it) ); |
580 | d->mAddressees.remove( it.d->mIt ); | 583 | d->mAddressees.remove( it.d->mIt ); |
581 | } | 584 | } |
582 | 585 | ||
583 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 586 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
584 | { | 587 | { |
585 | Iterator it; | 588 | Iterator it; |
586 | for ( it = begin(); it != end(); ++it ) { | 589 | for ( it = begin(); it != end(); ++it ) { |
587 | if ( a.uid() == (*it).uid() ) { | 590 | if ( a.uid() == (*it).uid() ) { |
588 | return it; | 591 | return it; |
589 | } | 592 | } |
590 | } | 593 | } |
591 | return end(); | 594 | return end(); |
592 | } | 595 | } |
593 | 596 | ||
594 | Addressee AddressBook::findByUid( const QString &uid ) | 597 | Addressee AddressBook::findByUid( const QString &uid ) |
595 | { | 598 | { |
596 | Iterator it; | 599 | Iterator it; |
597 | for ( it = begin(); it != end(); ++it ) { | 600 | for ( it = begin(); it != end(); ++it ) { |
598 | if ( uid == (*it).uid() ) { | 601 | if ( uid == (*it).uid() ) { |
599 | return *it; | 602 | return *it; |
600 | } | 603 | } |
601 | } | 604 | } |
602 | return Addressee(); | 605 | return Addressee(); |
603 | } | 606 | } |
604 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 607 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
605 | { | 608 | { |
606 | qDebug("AddressBook::preExternSync "); | 609 | qDebug("AddressBook::preExternSync "); |
607 | AddressBook::Iterator it; | 610 | AddressBook::Iterator it; |
608 | for ( it = begin(); it != end(); ++it ) { | 611 | for ( it = begin(); it != end(); ++it ) { |
609 | (*it).setID( csd, (*it).externalUID() ); | 612 | (*it).setID( csd, (*it).externalUID() ); |
610 | (*it).computeCsum( csd ); | 613 | (*it).computeCsum( csd ); |
611 | } | 614 | } |
612 | mergeAB( aBook ,csd ); | 615 | mergeAB( aBook ,csd ); |
613 | } | 616 | } |
614 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 617 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
615 | { | 618 | { |
616 | qDebug("AddressBook::postExternSync "); | 619 | qDebug("AddressBook::postExternSync "); |
617 | AddressBook::Iterator it; | 620 | AddressBook::Iterator it; |
618 | for ( it = begin(); it != end(); ++it ) { | 621 | for ( it = begin(); it != end(); ++it ) { |
619 | qDebug("check uid %s ", (*it).uid().latin1() ); | 622 | qDebug("check uid %s ", (*it).uid().latin1() ); |
620 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 623 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
621 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 624 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
622 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 625 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
623 | if ( ad.isEmpty() ) { | 626 | if ( ad.isEmpty() ) { |
624 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 627 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
625 | } else { | 628 | } else { |
626 | (*it).computeCsum( csd ); | 629 | (*it).computeCsum( csd ); |
627 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 630 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
628 | ad.setID( csd, (*it).externalUID() ); | 631 | ad.setID( csd, (*it).externalUID() ); |
629 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 632 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
630 | aBook->insertAddressee( ad ); | 633 | aBook->insertAddressee( ad ); |
631 | } | 634 | } |
632 | } | 635 | } |
633 | } | 636 | } |
634 | } | 637 | } |
635 | 638 | ||
636 | bool AddressBook::containsExternalUid( const QString& uid ) | 639 | bool AddressBook::containsExternalUid( const QString& uid ) |
637 | { | 640 | { |
638 | Iterator it; | 641 | Iterator it; |
639 | for ( it = begin(); it != end(); ++it ) { | 642 | for ( it = begin(); it != end(); ++it ) { |
640 | if ( uid == (*it).externalUID( ) ) | 643 | if ( uid == (*it).externalUID( ) ) |
641 | return true; | 644 | return true; |
642 | } | 645 | } |
643 | return false; | 646 | return false; |
644 | } | 647 | } |
645 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 648 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
646 | { | 649 | { |
647 | Iterator it; | 650 | Iterator it; |
648 | for ( it = begin(); it != end(); ++it ) { | 651 | for ( it = begin(); it != end(); ++it ) { |
649 | if ( uid == (*it).getID( profile ) ) | 652 | if ( uid == (*it).getID( profile ) ) |
650 | return (*it); | 653 | return (*it); |
651 | } | 654 | } |
652 | return Addressee(); | 655 | return Addressee(); |
653 | } | 656 | } |
654 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 657 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
655 | { | 658 | { |
656 | Iterator it; | 659 | Iterator it; |
657 | Addressee ad; | 660 | Addressee ad; |
658 | for ( it = begin(); it != end(); ++it ) { | 661 | for ( it = begin(); it != end(); ++it ) { |
659 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 662 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
660 | if ( !ad.isEmpty() ) { | 663 | if ( !ad.isEmpty() ) { |
661 | (*it).mergeContact( ad ); | 664 | (*it).mergeContact( ad ); |
662 | } | 665 | } |
663 | } | 666 | } |
664 | #if 0 | 667 | #if 0 |
665 | // test only | 668 | // test only |
666 | for ( it = begin(); it != end(); ++it ) { | 669 | for ( it = begin(); it != end(); ++it ) { |
667 | 670 | ||
668 | qDebug("uid %s ", (*it).uid().latin1()); | 671 | qDebug("uid %s ", (*it).uid().latin1()); |
669 | } | 672 | } |
670 | #endif | 673 | #endif |
671 | } | 674 | } |
672 | 675 | ||
673 | #if 0 | 676 | #if 0 |
674 | Addressee::List AddressBook::getExternLastSyncAddressees() | 677 | Addressee::List AddressBook::getExternLastSyncAddressees() |
675 | { | 678 | { |
676 | Addressee::List results; | 679 | Addressee::List results; |
677 | 680 | ||
678 | Iterator it; | 681 | Iterator it; |
679 | for ( it = begin(); it != end(); ++it ) { | 682 | for ( it = begin(); it != end(); ++it ) { |
680 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 683 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
681 | if ( (*it).familyName().left(4) == "!E: " ) | 684 | if ( (*it).familyName().left(4) == "!E: " ) |
682 | results.append( *it ); | 685 | results.append( *it ); |
683 | } | 686 | } |
684 | } | 687 | } |
685 | 688 | ||
686 | return results; | 689 | return results; |
687 | } | 690 | } |
688 | #endif | 691 | #endif |
689 | void AddressBook::resetTempSyncStat() | 692 | void AddressBook::resetTempSyncStat() |
690 | { | 693 | { |
691 | Iterator it; | 694 | Iterator it; |
692 | for ( it = begin(); it != end(); ++it ) { | 695 | for ( it = begin(); it != end(); ++it ) { |
693 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 696 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
694 | } | 697 | } |
695 | 698 | ||
696 | } | 699 | } |
697 | 700 | ||
698 | QStringList AddressBook:: uidList() | 701 | QStringList AddressBook:: uidList() |
699 | { | 702 | { |
700 | QStringList results; | 703 | QStringList results; |
701 | Iterator it; | 704 | Iterator it; |
702 | for ( it = begin(); it != end(); ++it ) { | 705 | for ( it = begin(); it != end(); ++it ) { |
703 | results.append( (*it).uid() ); | 706 | results.append( (*it).uid() ); |
704 | } | 707 | } |
705 | return results; | 708 | return results; |
706 | } | 709 | } |
707 | 710 | ||
708 | 711 | ||
709 | Addressee::List AddressBook::allAddressees() | 712 | Addressee::List AddressBook::allAddressees() |
710 | { | 713 | { |
711 | return d->mAddressees; | 714 | return d->mAddressees; |
712 | 715 | ||
713 | } | 716 | } |
714 | 717 | ||
715 | Addressee::List AddressBook::findByName( const QString &name ) | 718 | Addressee::List AddressBook::findByName( const QString &name ) |
716 | { | 719 | { |
717 | Addressee::List results; | 720 | Addressee::List results; |
718 | 721 | ||
719 | Iterator it; | 722 | Iterator it; |
720 | for ( it = begin(); it != end(); ++it ) { | 723 | for ( it = begin(); it != end(); ++it ) { |
721 | if ( name == (*it).realName() ) { | 724 | if ( name == (*it).realName() ) { |
722 | results.append( *it ); | 725 | results.append( *it ); |
723 | } | 726 | } |
724 | } | 727 | } |
725 | 728 | ||
726 | return results; | 729 | return results; |
727 | } | 730 | } |
728 | 731 | ||
729 | Addressee::List AddressBook::findByEmail( const QString &email ) | 732 | Addressee::List AddressBook::findByEmail( const QString &email ) |
730 | { | 733 | { |
731 | Addressee::List results; | 734 | Addressee::List results; |
732 | QStringList mailList; | 735 | QStringList mailList; |
733 | 736 | ||
734 | Iterator it; | 737 | Iterator it; |
735 | for ( it = begin(); it != end(); ++it ) { | 738 | for ( it = begin(); it != end(); ++it ) { |
736 | mailList = (*it).emails(); | 739 | mailList = (*it).emails(); |
737 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 740 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
738 | if ( email == (*ite) ) { | 741 | if ( email == (*ite) ) { |
739 | results.append( *it ); | 742 | results.append( *it ); |
740 | } | 743 | } |
741 | } | 744 | } |
742 | } | 745 | } |
743 | 746 | ||
744 | return results; | 747 | return results; |
745 | } | 748 | } |
746 | 749 | ||
747 | Addressee::List AddressBook::findByCategory( const QString &category ) | 750 | Addressee::List AddressBook::findByCategory( const QString &category ) |
748 | { | 751 | { |
749 | Addressee::List results; | 752 | Addressee::List results; |
750 | 753 | ||
751 | Iterator it; | 754 | Iterator it; |
752 | for ( it = begin(); it != end(); ++it ) { | 755 | for ( it = begin(); it != end(); ++it ) { |
753 | if ( (*it).hasCategory( category) ) { | 756 | if ( (*it).hasCategory( category) ) { |
754 | results.append( *it ); | 757 | results.append( *it ); |
755 | } | 758 | } |
756 | } | 759 | } |
757 | 760 | ||
758 | return results; | 761 | return results; |
759 | } | 762 | } |
760 | 763 | ||
761 | void AddressBook::dump() const | 764 | void AddressBook::dump() const |
762 | { | 765 | { |
763 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 766 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
764 | 767 | ||
765 | ConstIterator it; | 768 | ConstIterator it; |
766 | for( it = begin(); it != end(); ++it ) { | 769 | for( it = begin(); it != end(); ++it ) { |
767 | (*it).dump(); | 770 | (*it).dump(); |
768 | } | 771 | } |
769 | 772 | ||
770 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 773 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
771 | } | 774 | } |
772 | 775 | ||
773 | QString AddressBook::identifier() | 776 | QString AddressBook::identifier() |
774 | { | 777 | { |
775 | QStringList identifier; | 778 | QStringList identifier; |
776 | 779 | ||
777 | 780 | ||
778 | KRES::Manager<Resource>::ActiveIterator it; | 781 | KRES::Manager<Resource>::ActiveIterator it; |
779 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 782 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
780 | if ( !(*it)->identifier().isEmpty() ) | 783 | if ( !(*it)->identifier().isEmpty() ) |
781 | identifier.append( (*it)->identifier() ); | 784 | identifier.append( (*it)->identifier() ); |
782 | } | 785 | } |
783 | 786 | ||
784 | return identifier.join( ":" ); | 787 | return identifier.join( ":" ); |
785 | } | 788 | } |
786 | 789 | ||
787 | Field::List AddressBook::fields( int category ) | 790 | Field::List AddressBook::fields( int category ) |
788 | { | 791 | { |
789 | if ( d->mAllFields.isEmpty() ) { | 792 | if ( d->mAllFields.isEmpty() ) { |
790 | d->mAllFields = Field::allFields(); | 793 | d->mAllFields = Field::allFields(); |
791 | } | 794 | } |
792 | 795 | ||
793 | if ( category == Field::All ) return d->mAllFields; | 796 | if ( category == Field::All ) return d->mAllFields; |
794 | 797 | ||
795 | Field::List result; | 798 | Field::List result; |
796 | Field::List::ConstIterator it; | 799 | Field::List::ConstIterator it; |
797 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 800 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
798 | if ( (*it)->category() & category ) result.append( *it ); | 801 | if ( (*it)->category() & category ) result.append( *it ); |
799 | } | 802 | } |
800 | 803 | ||
801 | return result; | 804 | return result; |
802 | } | 805 | } |
803 | 806 | ||
804 | bool AddressBook::addCustomField( const QString &label, int category, | 807 | bool AddressBook::addCustomField( const QString &label, int category, |
805 | const QString &key, const QString &app ) | 808 | const QString &key, const QString &app ) |
806 | { | 809 | { |
807 | if ( d->mAllFields.isEmpty() ) { | 810 | if ( d->mAllFields.isEmpty() ) { |
808 | d->mAllFields = Field::allFields(); | 811 | d->mAllFields = Field::allFields(); |
809 | } | 812 | } |
810 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 813 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
811 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 814 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
812 | 815 | ||
813 | QString k = key.isNull() ? label : key; | 816 | QString k = key.isNull() ? label : key; |
814 | 817 | ||
815 | Field *field = Field::createCustomField( label, category, k, a ); | 818 | Field *field = Field::createCustomField( label, category, k, a ); |
816 | 819 | ||
817 | if ( !field ) return false; | 820 | if ( !field ) return false; |
818 | 821 | ||
819 | d->mAllFields.append( field ); | 822 | d->mAllFields.append( field ); |
820 | 823 | ||
821 | return true; | 824 | return true; |
822 | } | 825 | } |
823 | 826 | ||
824 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 827 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
825 | { | 828 | { |
826 | if (!ab.d) return s; | 829 | if (!ab.d) return s; |
827 | 830 | ||
828 | return s << ab.d->mAddressees; | 831 | return s << ab.d->mAddressees; |
829 | } | 832 | } |
830 | 833 | ||
831 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 834 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
832 | { | 835 | { |
833 | if (!ab.d) return s; | 836 | if (!ab.d) return s; |
834 | 837 | ||
835 | s >> ab.d->mAddressees; | 838 | s >> ab.d->mAddressees; |
836 | 839 | ||
837 | return s; | 840 | return s; |
838 | } | 841 | } |
839 | 842 | ||
840 | bool AddressBook::addResource( Resource *resource ) | 843 | bool AddressBook::addResource( Resource *resource ) |
841 | { | 844 | { |
842 | if ( !resource->open() ) { | 845 | if ( !resource->open() ) { |
843 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 846 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
844 | return false; | 847 | return false; |
845 | } | 848 | } |
846 | 849 | ||
847 | resource->setAddressBook( this ); | 850 | resource->setAddressBook( this ); |
848 | 851 | ||
849 | d->mManager->add( resource ); | 852 | d->mManager->add( resource ); |
850 | return true; | 853 | return true; |
851 | } | 854 | } |
852 | 855 | ||
853 | bool AddressBook::removeResource( Resource *resource ) | 856 | bool AddressBook::removeResource( Resource *resource ) |
854 | { | 857 | { |
855 | resource->close(); | 858 | resource->close(); |
856 | 859 | ||
857 | if ( resource == standardResource() ) | 860 | if ( resource == standardResource() ) |
858 | d->mManager->setStandardResource( 0 ); | 861 | d->mManager->setStandardResource( 0 ); |
859 | 862 | ||
860 | resource->setAddressBook( 0 ); | 863 | resource->setAddressBook( 0 ); |
861 | 864 | ||
862 | d->mManager->remove( resource ); | 865 | d->mManager->remove( resource ); |
863 | return true; | 866 | return true; |
864 | } | 867 | } |
865 | 868 | ||
866 | QPtrList<Resource> AddressBook::resources() | 869 | QPtrList<Resource> AddressBook::resources() |
867 | { | 870 | { |
868 | QPtrList<Resource> list; | 871 | QPtrList<Resource> list; |
869 | 872 | ||
870 | // qDebug("AddressBook::resources() 1"); | 873 | // qDebug("AddressBook::resources() 1"); |
871 | 874 | ||
872 | KRES::Manager<Resource>::ActiveIterator it; | 875 | KRES::Manager<Resource>::ActiveIterator it; |
873 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 876 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
874 | list.append( *it ); | 877 | list.append( *it ); |
875 | 878 | ||
876 | return list; | 879 | return list; |
877 | } | 880 | } |
878 | 881 | ||
879 | /*US | 882 | /*US |
880 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 883 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
881 | { | 884 | { |
882 | delete d->mErrorHandler; | 885 | delete d->mErrorHandler; |
883 | d->mErrorHandler = handler; | 886 | d->mErrorHandler = handler; |
884 | } | 887 | } |
885 | */ | 888 | */ |
886 | 889 | ||
887 | void AddressBook::error( const QString& msg ) | 890 | void AddressBook::error( const QString& msg ) |
888 | { | 891 | { |
889 | /*US | 892 | /*US |
890 | if ( !d->mErrorHandler ) // create default error handler | 893 | if ( !d->mErrorHandler ) // create default error handler |
891 | d->mErrorHandler = new ConsoleErrorHandler; | 894 | d->mErrorHandler = new ConsoleErrorHandler; |
892 | 895 | ||
893 | if ( d->mErrorHandler ) | 896 | if ( d->mErrorHandler ) |
894 | d->mErrorHandler->error( msg ); | 897 | d->mErrorHandler->error( msg ); |
895 | else | 898 | else |
896 | kdError(5700) << "no error handler defined" << endl; | 899 | kdError(5700) << "no error handler defined" << endl; |
897 | */ | 900 | */ |
898 | kdDebug(5700) << "msg" << endl; | 901 | kdDebug(5700) << "msg" << endl; |
899 | qDebug(msg); | 902 | qDebug(msg); |
900 | } | 903 | } |
901 | 904 | ||
902 | void AddressBook::deleteRemovedAddressees() | 905 | void AddressBook::deleteRemovedAddressees() |
903 | { | 906 | { |
904 | Addressee::List::Iterator it; | 907 | Addressee::List::Iterator it; |
905 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 908 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
906 | Resource *resource = (*it).resource(); | 909 | Resource *resource = (*it).resource(); |
907 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 910 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
908 | resource->removeAddressee( *it ); | 911 | resource->removeAddressee( *it ); |
909 | } | 912 | } |
910 | 913 | ||
911 | d->mRemovedAddressees.clear(); | 914 | d->mRemovedAddressees.clear(); |
912 | } | 915 | } |
913 | 916 | ||
914 | void AddressBook::setStandardResource( Resource *resource ) | 917 | void AddressBook::setStandardResource( Resource *resource ) |
915 | { | 918 | { |
916 | // qDebug("AddressBook::setStandardResource 1"); | 919 | // qDebug("AddressBook::setStandardResource 1"); |
917 | d->mManager->setStandardResource( resource ); | 920 | d->mManager->setStandardResource( resource ); |
918 | } | 921 | } |
919 | 922 | ||
920 | Resource *AddressBook::standardResource() | 923 | Resource *AddressBook::standardResource() |
921 | { | 924 | { |
922 | return d->mManager->standardResource(); | 925 | return d->mManager->standardResource(); |
923 | } | 926 | } |
924 | 927 | ||
925 | KRES::Manager<Resource> *AddressBook::resourceManager() | 928 | KRES::Manager<Resource> *AddressBook::resourceManager() |
926 | { | 929 | { |
927 | return d->mManager; | 930 | return d->mManager; |
928 | } | 931 | } |
929 | 932 | ||
930 | void AddressBook::cleanUp() | 933 | void AddressBook::cleanUp() |
931 | { | 934 | { |
932 | KRES::Manager<Resource>::ActiveIterator it; | 935 | KRES::Manager<Resource>::ActiveIterator it; |
933 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 936 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
934 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 937 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
935 | (*it)->cleanUp(); | 938 | (*it)->cleanUp(); |
936 | } | 939 | } |
937 | } | 940 | } |