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,514 +1,517 @@ | |||
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 ) |