author | zautrix <zautrix> | 2004-10-07 09:56:31 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-07 09:56:31 (UTC) |
commit | edd36b813763c304b104f276437c2c60ee9bd1f1 (patch) (unidiff) | |
tree | da3a9f6fbd905fe876131af5025690806ce60704 /kabc | |
parent | 9345818e9c291130691288e4b065190259eb4e01 (diff) | |
download | kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.zip kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.tar.gz kdepimpi-edd36b813763c304b104f276437c2c60ee9bd1f1.tar.bz2 |
sync fixes
-rw-r--r-- | kabc/addressbook.cpp | 70 | ||||
-rw-r--r-- | kabc/addressbook.h | 5 |
2 files changed, 67 insertions, 8 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 5fb49eb..295cf03 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,938 +1,996 @@ | |||
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 | #include <qtextstream.h> | ||
42 | #include <qfile.h> | ||
41 | 43 | ||
42 | #include <kglobal.h> | 44 | #include <kglobal.h> |
43 | #include <klocale.h> | 45 | #include <klocale.h>> |
46 | #include <kmessagebox.h> | ||
44 | #include <kdebug.h> | 47 | #include <kdebug.h> |
45 | #include <libkcal/syncdefines.h> | 48 | #include <libkcal/syncdefines.h> |
46 | #include "addressbook.h" | 49 | #include "addressbook.h" |
47 | #include "resource.h" | 50 | #include "resource.h" |
51 | #include "vcardconverter.h" | ||
52 | #include "vcardparser/vcardtool.h" | ||
48 | 53 | ||
49 | //US #include "addressbook.moc" | 54 | //US #include "addressbook.moc" |
50 | 55 | ||
51 | using namespace KABC; | 56 | using namespace KABC; |
52 | 57 | ||
53 | struct AddressBook::AddressBookData | 58 | struct AddressBook::AddressBookData |
54 | { | 59 | { |
55 | Addressee::List mAddressees; | 60 | Addressee::List mAddressees; |
56 | Addressee::List mRemovedAddressees; | 61 | Addressee::List mRemovedAddressees; |
57 | Field::List mAllFields; | 62 | Field::List mAllFields; |
58 | KConfig *mConfig; | 63 | KConfig *mConfig; |
59 | KRES::Manager<Resource> *mManager; | 64 | KRES::Manager<Resource> *mManager; |
60 | //US ErrorHandler *mErrorHandler; | 65 | //US ErrorHandler *mErrorHandler; |
61 | }; | 66 | }; |
62 | 67 | ||
63 | struct AddressBook::Iterator::IteratorData | 68 | struct AddressBook::Iterator::IteratorData |
64 | { | 69 | { |
65 | Addressee::List::Iterator mIt; | 70 | Addressee::List::Iterator mIt; |
66 | }; | 71 | }; |
67 | 72 | ||
68 | struct AddressBook::ConstIterator::ConstIteratorData | 73 | struct AddressBook::ConstIterator::ConstIteratorData |
69 | { | 74 | { |
70 | Addressee::List::ConstIterator mIt; | 75 | Addressee::List::ConstIterator mIt; |
71 | }; | 76 | }; |
72 | 77 | ||
73 | AddressBook::Iterator::Iterator() | 78 | AddressBook::Iterator::Iterator() |
74 | { | 79 | { |
75 | d = new IteratorData; | 80 | d = new IteratorData; |
76 | } | 81 | } |
77 | 82 | ||
78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 83 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
79 | { | 84 | { |
80 | d = new IteratorData; | 85 | d = new IteratorData; |
81 | d->mIt = i.d->mIt; | 86 | d->mIt = i.d->mIt; |
82 | } | 87 | } |
83 | 88 | ||
84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 89 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
85 | { | 90 | { |
86 | if( this == &i ) return *this; // guard against self assignment | 91 | if( this == &i ) return *this; // guard against self assignment |
87 | delete d; // delete the old data the Iterator was completely constructed before | 92 | delete d; // delete the old data the Iterator was completely constructed before |
88 | d = new IteratorData; | 93 | d = new IteratorData; |
89 | d->mIt = i.d->mIt; | 94 | d->mIt = i.d->mIt; |
90 | return *this; | 95 | return *this; |
91 | } | 96 | } |
92 | 97 | ||
93 | AddressBook::Iterator::~Iterator() | 98 | AddressBook::Iterator::~Iterator() |
94 | { | 99 | { |
95 | delete d; | 100 | delete d; |
96 | } | 101 | } |
97 | 102 | ||
98 | const Addressee &AddressBook::Iterator::operator*() const | 103 | const Addressee &AddressBook::Iterator::operator*() const |
99 | { | 104 | { |
100 | return *(d->mIt); | 105 | return *(d->mIt); |
101 | } | 106 | } |
102 | 107 | ||
103 | Addressee &AddressBook::Iterator::operator*() | 108 | Addressee &AddressBook::Iterator::operator*() |
104 | { | 109 | { |
105 | return *(d->mIt); | 110 | return *(d->mIt); |
106 | } | 111 | } |
107 | 112 | ||
108 | Addressee *AddressBook::Iterator::operator->() | 113 | Addressee *AddressBook::Iterator::operator->() |
109 | { | 114 | { |
110 | return &(*(d->mIt)); | 115 | return &(*(d->mIt)); |
111 | } | 116 | } |
112 | 117 | ||
113 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 118 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
114 | { | 119 | { |
115 | (d->mIt)++; | 120 | (d->mIt)++; |
116 | return *this; | 121 | return *this; |
117 | } | 122 | } |
118 | 123 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 124 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
120 | { | 125 | { |
121 | (d->mIt)++; | 126 | (d->mIt)++; |
122 | return *this; | 127 | return *this; |
123 | } | 128 | } |
124 | 129 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 130 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
126 | { | 131 | { |
127 | (d->mIt)--; | 132 | (d->mIt)--; |
128 | return *this; | 133 | return *this; |
129 | } | 134 | } |
130 | 135 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 136 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
132 | { | 137 | { |
133 | (d->mIt)--; | 138 | (d->mIt)--; |
134 | return *this; | 139 | return *this; |
135 | } | 140 | } |
136 | 141 | ||
137 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 142 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
138 | { | 143 | { |
139 | return ( d->mIt == it.d->mIt ); | 144 | return ( d->mIt == it.d->mIt ); |
140 | } | 145 | } |
141 | 146 | ||
142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 147 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
143 | { | 148 | { |
144 | return ( d->mIt != it.d->mIt ); | 149 | return ( d->mIt != it.d->mIt ); |
145 | } | 150 | } |
146 | 151 | ||
147 | 152 | ||
148 | AddressBook::ConstIterator::ConstIterator() | 153 | AddressBook::ConstIterator::ConstIterator() |
149 | { | 154 | { |
150 | d = new ConstIteratorData; | 155 | d = new ConstIteratorData; |
151 | } | 156 | } |
152 | 157 | ||
153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 158 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
154 | { | 159 | { |
155 | d = new ConstIteratorData; | 160 | d = new ConstIteratorData; |
156 | d->mIt = i.d->mIt; | 161 | d->mIt = i.d->mIt; |
157 | } | 162 | } |
158 | 163 | ||
159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 164 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
160 | { | 165 | { |
161 | if( this == &i ) return *this; // guard for self assignment | 166 | if( this == &i ) return *this; // guard for self assignment |
162 | delete d; // delete the old data because the Iterator was really constructed before | 167 | delete d; // delete the old data because the Iterator was really constructed before |
163 | d = new ConstIteratorData; | 168 | d = new ConstIteratorData; |
164 | d->mIt = i.d->mIt; | 169 | d->mIt = i.d->mIt; |
165 | return *this; | 170 | return *this; |
166 | } | 171 | } |
167 | 172 | ||
168 | AddressBook::ConstIterator::~ConstIterator() | 173 | AddressBook::ConstIterator::~ConstIterator() |
169 | { | 174 | { |
170 | delete d; | 175 | delete d; |
171 | } | 176 | } |
172 | 177 | ||
173 | const Addressee &AddressBook::ConstIterator::operator*() const | 178 | const Addressee &AddressBook::ConstIterator::operator*() const |
174 | { | 179 | { |
175 | return *(d->mIt); | 180 | return *(d->mIt); |
176 | } | 181 | } |
177 | 182 | ||
178 | const Addressee* AddressBook::ConstIterator::operator->() const | 183 | const Addressee* AddressBook::ConstIterator::operator->() const |
179 | { | 184 | { |
180 | return &(*(d->mIt)); | 185 | return &(*(d->mIt)); |
181 | } | 186 | } |
182 | 187 | ||
183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 188 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
184 | { | 189 | { |
185 | (d->mIt)++; | 190 | (d->mIt)++; |
186 | return *this; | 191 | return *this; |
187 | } | 192 | } |
188 | 193 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 194 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
190 | { | 195 | { |
191 | (d->mIt)++; | 196 | (d->mIt)++; |
192 | return *this; | 197 | return *this; |
193 | } | 198 | } |
194 | 199 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 200 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
196 | { | 201 | { |
197 | (d->mIt)--; | 202 | (d->mIt)--; |
198 | return *this; | 203 | return *this; |
199 | } | 204 | } |
200 | 205 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 206 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
202 | { | 207 | { |
203 | (d->mIt)--; | 208 | (d->mIt)--; |
204 | return *this; | 209 | return *this; |
205 | } | 210 | } |
206 | 211 | ||
207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
208 | { | 213 | { |
209 | return ( d->mIt == it.d->mIt ); | 214 | return ( d->mIt == it.d->mIt ); |
210 | } | 215 | } |
211 | 216 | ||
212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 217 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
213 | { | 218 | { |
214 | return ( d->mIt != it.d->mIt ); | 219 | return ( d->mIt != it.d->mIt ); |
215 | } | 220 | } |
216 | 221 | ||
217 | 222 | ||
218 | AddressBook::AddressBook() | 223 | AddressBook::AddressBook() |
219 | { | 224 | { |
220 | init(0, "contact"); | 225 | init(0, "contact"); |
221 | } | 226 | } |
222 | 227 | ||
223 | AddressBook::AddressBook( const QString &config ) | 228 | AddressBook::AddressBook( const QString &config ) |
224 | { | 229 | { |
225 | init(config, "contact"); | 230 | init(config, "contact"); |
226 | } | 231 | } |
227 | 232 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 233 | AddressBook::AddressBook( const QString &config, const QString &family ) |
229 | { | 234 | { |
230 | init(config, family); | 235 | init(config, family); |
231 | 236 | ||
232 | } | 237 | } |
233 | 238 | ||
234 | // the default family is "contact" | 239 | // the default family is "contact" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 240 | void AddressBook::init(const QString &config, const QString &family ) |
236 | { | 241 | { |
237 | blockLSEchange = false; | 242 | blockLSEchange = false; |
238 | d = new AddressBookData; | 243 | d = new AddressBookData; |
239 | QString fami = family; | 244 | QString fami = family; |
240 | if (config != 0) { | 245 | if (config != 0) { |
241 | if ( family == "syncContact" ) { | 246 | if ( family == "syncContact" ) { |
242 | qDebug("creating sync config "); | 247 | qDebug("creating sync config "); |
243 | fami = "contact"; | 248 | fami = "contact"; |
244 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 249 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
245 | con->setGroup( "General" ); | 250 | con->setGroup( "General" ); |
246 | con->writeEntry( "ResourceKeys", QString("sync") ); | 251 | con->writeEntry( "ResourceKeys", QString("sync") ); |
247 | con->writeEntry( "Standard", QString("sync") ); | 252 | con->writeEntry( "Standard", QString("sync") ); |
248 | con->setGroup( "Resource_sync" ); | 253 | con->setGroup( "Resource_sync" ); |
249 | con->writeEntry( "FileName", config ); | 254 | con->writeEntry( "FileName", config ); |
250 | con->writeEntry( "FileFormat", QString("vcard") ); | 255 | con->writeEntry( "FileFormat", QString("vcard") ); |
251 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 256 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
252 | con->writeEntry( "ResourceName", QString("sync_res") ); | 257 | con->writeEntry( "ResourceName", QString("sync_res") ); |
253 | if ( config.right(4) == ".xml" ) | 258 | if ( config.right(4) == ".xml" ) |
254 | con->writeEntry( "ResourceType", QString("qtopia") ); | 259 | con->writeEntry( "ResourceType", QString("qtopia") ); |
255 | else if ( config == "sharp" ) { | 260 | else if ( config == "sharp" ) { |
256 | con->writeEntry( "ResourceType", QString("sharp") ); | 261 | con->writeEntry( "ResourceType", QString("sharp") ); |
257 | } else { | 262 | } else { |
258 | con->writeEntry( "ResourceType", QString("file") ); | 263 | con->writeEntry( "ResourceType", QString("file") ); |
259 | } | 264 | } |
260 | //con->sync(); | 265 | //con->sync(); |
261 | d->mConfig = con; | 266 | d->mConfig = con; |
262 | } | 267 | } |
263 | else | 268 | else |
264 | d->mConfig = new KConfig( locateLocal("config", config) ); | 269 | d->mConfig = new KConfig( locateLocal("config", config) ); |
265 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 270 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
266 | } | 271 | } |
267 | else { | 272 | else { |
268 | d->mConfig = 0; | 273 | d->mConfig = 0; |
269 | // qDebug("AddressBook::init 1 config=0"); | 274 | // qDebug("AddressBook::init 1 config=0"); |
270 | } | 275 | } |
271 | 276 | ||
272 | //US d->mErrorHandler = 0; | 277 | //US d->mErrorHandler = 0; |
273 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 278 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
274 | d->mManager->readConfig( d->mConfig ); | 279 | d->mManager->readConfig( d->mConfig ); |
275 | if ( family == "syncContact" ) { | 280 | if ( family == "syncContact" ) { |
276 | KRES::Manager<Resource> *manager = d->mManager; | 281 | KRES::Manager<Resource> *manager = d->mManager; |
277 | KRES::Manager<Resource>::ActiveIterator it; | 282 | KRES::Manager<Resource>::ActiveIterator it; |
278 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 283 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
279 | (*it)->setAddressBook( this ); | 284 | (*it)->setAddressBook( this ); |
280 | if ( !(*it)->open() ) | 285 | if ( !(*it)->open() ) |
281 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 286 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
282 | } | 287 | } |
283 | Resource *res = standardResource(); | 288 | Resource *res = standardResource(); |
284 | if ( !res ) { | 289 | if ( !res ) { |
285 | qDebug("ERROR: no standard resource"); | 290 | qDebug("ERROR: no standard resource"); |
286 | res = manager->createResource( "file" ); | 291 | res = manager->createResource( "file" ); |
287 | if ( res ) | 292 | if ( res ) |
288 | { | 293 | { |
289 | addResource( res ); | 294 | addResource( res ); |
290 | } | 295 | } |
291 | else | 296 | else |
292 | qDebug(" No resource available!!!"); | 297 | qDebug(" No resource available!!!"); |
293 | } | 298 | } |
294 | setStandardResource( res ); | 299 | setStandardResource( res ); |
295 | manager->writeConfig(); | 300 | manager->writeConfig(); |
296 | } | 301 | } |
297 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 302 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
298 | "X-Department", "KADDRESSBOOK" ); | 303 | "X-Department", "KADDRESSBOOK" ); |
299 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
300 | "X-Profession", "KADDRESSBOOK" ); | 305 | "X-Profession", "KADDRESSBOOK" ); |
301 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
302 | "X-AssistantsName", "KADDRESSBOOK" ); | 307 | "X-AssistantsName", "KADDRESSBOOK" ); |
303 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
304 | "X-ManagersName", "KADDRESSBOOK" ); | 309 | "X-ManagersName", "KADDRESSBOOK" ); |
305 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 310 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
306 | "X-SpousesName", "KADDRESSBOOK" ); | 311 | "X-SpousesName", "KADDRESSBOOK" ); |
307 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
308 | "X-Office", "KADDRESSBOOK" ); | 313 | "X-Office", "KADDRESSBOOK" ); |
309 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
310 | "X-IMAddress", "KADDRESSBOOK" ); | 315 | "X-IMAddress", "KADDRESSBOOK" ); |
311 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
312 | "X-Anniversary", "KADDRESSBOOK" ); | 317 | "X-Anniversary", "KADDRESSBOOK" ); |
313 | 318 | ||
314 | //US added this field to become compatible with Opie/qtopia addressbook | 319 | //US added this field to become compatible with Opie/qtopia addressbook |
315 | // values can be "female" or "male" or "". An empty field represents undefined. | 320 | // values can be "female" or "male" or "". An empty field represents undefined. |
316 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
317 | "X-Gender", "KADDRESSBOOK" ); | 322 | "X-Gender", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
319 | "X-Children", "KADDRESSBOOK" ); | 324 | "X-Children", "KADDRESSBOOK" ); |
320 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
321 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 326 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
322 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
323 | "X-ExternalID", "KADDRESSBOOK" ); | 328 | "X-ExternalID", "KADDRESSBOOK" ); |
324 | } | 329 | } |
325 | 330 | ||
326 | AddressBook::~AddressBook() | 331 | AddressBook::~AddressBook() |
327 | { | 332 | { |
328 | delete d->mConfig; d->mConfig = 0; | 333 | delete d->mConfig; d->mConfig = 0; |
329 | delete d->mManager; d->mManager = 0; | 334 | delete d->mManager; d->mManager = 0; |
330 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 335 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
331 | delete d; d = 0; | 336 | delete d; d = 0; |
332 | } | 337 | } |
333 | 338 | ||
334 | bool AddressBook::load() | 339 | bool AddressBook::load() |
335 | { | 340 | { |
336 | 341 | ||
337 | 342 | ||
338 | clear(); | 343 | clear(); |
339 | 344 | ||
340 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
341 | bool ok = true; | 346 | bool ok = true; |
342 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
343 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
344 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
345 | ok = false; | 350 | ok = false; |
346 | } | 351 | } |
347 | 352 | ||
348 | // mark all addressees as unchanged | 353 | // mark all addressees as unchanged |
349 | Addressee::List::Iterator addrIt; | 354 | Addressee::List::Iterator addrIt; |
350 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 355 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
351 | (*addrIt).setChanged( false ); | 356 | (*addrIt).setChanged( false ); |
352 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 357 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
353 | if ( !id.isEmpty() ) { | 358 | if ( !id.isEmpty() ) { |
354 | //qDebug("setId aa %s ", id.latin1()); | 359 | //qDebug("setId aa %s ", id.latin1()); |
355 | (*addrIt).setIDStr(id ); | 360 | (*addrIt).setIDStr(id ); |
356 | } | 361 | } |
357 | } | 362 | } |
358 | blockLSEchange = true; | 363 | blockLSEchange = true; |
359 | return ok; | 364 | return ok; |
360 | } | 365 | } |
361 | 366 | ||
362 | bool AddressBook::save( Ticket *ticket ) | 367 | bool AddressBook::save( Ticket *ticket ) |
363 | { | 368 | { |
364 | kdDebug(5700) << "AddressBook::save()"<< endl; | 369 | kdDebug(5700) << "AddressBook::save()"<< endl; |
365 | 370 | ||
366 | if ( ticket->resource() ) { | 371 | if ( ticket->resource() ) { |
367 | deleteRemovedAddressees(); | 372 | deleteRemovedAddressees(); |
368 | return ticket->resource()->save( ticket ); | 373 | return ticket->resource()->save( ticket ); |
369 | } | 374 | } |
370 | 375 | ||
371 | return false; | 376 | return false; |
372 | } | 377 | } |
378 | void AddressBook::export2File( QString fileName ) | ||
379 | { | ||
380 | |||
381 | QFile outFile( fileName ); | ||
382 | if ( !outFile.open( IO_WriteOnly ) ) { | ||
383 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | ||
384 | KMessageBox::error( 0, text.arg( fileName ) ); | ||
385 | return ; | ||
386 | } | ||
387 | QTextStream t( &outFile ); | ||
388 | t.setEncoding( QTextStream::UnicodeUTF8 ); | ||
389 | Iterator it; | ||
390 | KABC::VCardConverter::Version version; | ||
391 | version = KABC::VCardConverter::v3_0; | ||
392 | for ( it = begin(); it != end(); ++it ) { | ||
393 | if ( !(*it).IDStr().isEmpty() ) { | ||
394 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | ||
395 | } | ||
396 | KABC::VCardConverter converter; | ||
397 | QString vcard; | ||
398 | //Resource *resource() const; | ||
399 | converter.addresseeToVCard( *it, vcard, version ); | ||
400 | t << vcard << "\r\n"; | ||
401 | } | ||
402 | outFile.close(); | ||
403 | } | ||
404 | void AddressBook::importFromFile( QString fileName ) | ||
405 | { | ||
406 | |||
407 | KABC::Addressee::List list; | ||
408 | QFile file( fileName ); | ||
409 | |||
410 | file.open( IO_ReadOnly ); | ||
411 | QByteArray rawData = file.readAll(); | ||
412 | file.close(); | ||
413 | |||
414 | QString data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | ||
415 | KABC::VCardTool tool; | ||
416 | list = tool.parseVCards( data ); | ||
417 | |||
418 | KABC::Addressee::List::Iterator it; | ||
419 | for ( it = list.begin(); it != list.end(); ++it ) { | ||
420 | (*it).setResource( 0 ); | ||
421 | insertAddressee( (*it), false, true ); | ||
422 | } | ||
423 | |||
424 | } | ||
425 | |||
373 | bool AddressBook::saveAB() | 426 | bool AddressBook::saveAB() |
374 | { | 427 | { |
375 | bool ok = true; | 428 | bool ok = true; |
376 | 429 | ||
377 | deleteRemovedAddressees(); | 430 | deleteRemovedAddressees(); |
378 | Iterator ait; | 431 | Iterator ait; |
379 | for ( ait = begin(); ait != end(); ++ait ) { | 432 | for ( ait = begin(); ait != end(); ++ait ) { |
380 | if ( !(*ait).IDStr().isEmpty() ) { | 433 | if ( !(*ait).IDStr().isEmpty() ) { |
381 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 434 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
382 | } | 435 | } |
383 | } | 436 | } |
384 | KRES::Manager<Resource>::ActiveIterator it; | 437 | KRES::Manager<Resource>::ActiveIterator it; |
385 | KRES::Manager<Resource> *manager = d->mManager; | 438 | KRES::Manager<Resource> *manager = d->mManager; |
386 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 439 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
387 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 440 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
388 | Ticket *ticket = requestSaveTicket( *it ); | 441 | Ticket *ticket = requestSaveTicket( *it ); |
389 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 442 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
390 | if ( !ticket ) { | 443 | if ( !ticket ) { |
391 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 444 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
392 | .arg( (*it)->resourceName() ) ); | 445 | .arg( (*it)->resourceName() ) ); |
393 | return false; | 446 | return false; |
394 | } | 447 | } |
395 | 448 | ||
396 | //if ( !save( ticket ) ) | 449 | //if ( !save( ticket ) ) |
397 | if ( ticket->resource() ) { | 450 | if ( ticket->resource() ) { |
398 | if ( ! ticket->resource()->save( ticket ) ) | 451 | if ( ! ticket->resource()->save( ticket ) ) |
399 | ok = false; | 452 | ok = false; |
400 | } else | 453 | } else |
401 | ok = false; | 454 | ok = false; |
402 | 455 | ||
403 | } | 456 | } |
404 | } | 457 | } |
405 | return ok; | 458 | return ok; |
406 | } | 459 | } |
407 | 460 | ||
408 | AddressBook::Iterator AddressBook::begin() | 461 | AddressBook::Iterator AddressBook::begin() |
409 | { | 462 | { |
410 | Iterator it = Iterator(); | 463 | Iterator it = Iterator(); |
411 | it.d->mIt = d->mAddressees.begin(); | 464 | it.d->mIt = d->mAddressees.begin(); |
412 | return it; | 465 | return it; |
413 | } | 466 | } |
414 | 467 | ||
415 | AddressBook::ConstIterator AddressBook::begin() const | 468 | AddressBook::ConstIterator AddressBook::begin() const |
416 | { | 469 | { |
417 | ConstIterator it = ConstIterator(); | 470 | ConstIterator it = ConstIterator(); |
418 | it.d->mIt = d->mAddressees.begin(); | 471 | it.d->mIt = d->mAddressees.begin(); |
419 | return it; | 472 | return it; |
420 | } | 473 | } |
421 | 474 | ||
422 | AddressBook::Iterator AddressBook::end() | 475 | AddressBook::Iterator AddressBook::end() |
423 | { | 476 | { |
424 | Iterator it = Iterator(); | 477 | Iterator it = Iterator(); |
425 | it.d->mIt = d->mAddressees.end(); | 478 | it.d->mIt = d->mAddressees.end(); |
426 | return it; | 479 | return it; |
427 | } | 480 | } |
428 | 481 | ||
429 | AddressBook::ConstIterator AddressBook::end() const | 482 | AddressBook::ConstIterator AddressBook::end() const |
430 | { | 483 | { |
431 | ConstIterator it = ConstIterator(); | 484 | ConstIterator it = ConstIterator(); |
432 | it.d->mIt = d->mAddressees.end(); | 485 | it.d->mIt = d->mAddressees.end(); |
433 | return it; | 486 | return it; |
434 | } | 487 | } |
435 | 488 | ||
436 | void AddressBook::clear() | 489 | void AddressBook::clear() |
437 | { | 490 | { |
438 | d->mAddressees.clear(); | 491 | d->mAddressees.clear(); |
439 | } | 492 | } |
440 | 493 | ||
441 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 494 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
442 | { | 495 | { |
443 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 496 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
444 | 497 | ||
445 | if ( !resource ) | 498 | if ( !resource ) |
446 | { | 499 | { |
447 | qDebug("AddressBook::requestSaveTicket no resource" ); | 500 | qDebug("AddressBook::requestSaveTicket no resource" ); |
448 | resource = standardResource(); | 501 | resource = standardResource(); |
449 | } | 502 | } |
450 | 503 | ||
451 | KRES::Manager<Resource>::ActiveIterator it; | 504 | KRES::Manager<Resource>::ActiveIterator it; |
452 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 505 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
453 | if ( (*it) == resource ) { | 506 | if ( (*it) == resource ) { |
454 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 507 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
455 | return 0; | 508 | return 0; |
456 | else | 509 | else |
457 | return (*it)->requestSaveTicket(); | 510 | return (*it)->requestSaveTicket(); |
458 | } | 511 | } |
459 | } | 512 | } |
460 | 513 | ||
461 | return 0; | 514 | return 0; |
462 | } | 515 | } |
463 | 516 | ||
464 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 517 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
465 | { | 518 | { |
466 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 519 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
467 | //qDebug("block insert "); | 520 | //qDebug("block insert "); |
468 | return; | 521 | return; |
469 | } | 522 | } |
470 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 523 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
471 | bool found = false; | 524 | bool found = false; |
472 | Addressee::List::Iterator it; | 525 | Addressee::List::Iterator it; |
473 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 526 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
474 | if ( a.uid() == (*it).uid() ) { | 527 | if ( a.uid() == (*it).uid() ) { |
475 | 528 | ||
476 | bool changed = false; | 529 | bool changed = false; |
477 | Addressee addr = a; | 530 | Addressee addr = a; |
478 | if ( addr != (*it) ) | 531 | if ( addr != (*it) ) |
479 | changed = true; | 532 | changed = true; |
480 | 533 | ||
481 | (*it) = a; | 534 | if ( takeResource ) { |
482 | if ( (*it).resource() == 0 ) | 535 | Resource * res = (*it).resource(); |
483 | (*it).setResource( standardResource() ); | 536 | (*it) = a; |
484 | 537 | (*it).setResource( res ); | |
538 | } else { | ||
539 | (*it) = a; | ||
540 | if ( (*it).resource() == 0 ) | ||
541 | (*it).setResource( standardResource() ); | ||
542 | } | ||
485 | if ( changed ) { | 543 | if ( changed ) { |
486 | if ( setRev ) { | 544 | if ( setRev ) { |
487 | 545 | ||
488 | // get rid of micro seconds | 546 | // get rid of micro seconds |
489 | QDateTime dt = QDateTime::currentDateTime(); | 547 | QDateTime dt = QDateTime::currentDateTime(); |
490 | QTime t = dt.time(); | 548 | QTime t = dt.time(); |
491 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 549 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
492 | (*it).setRevision( dt ); | 550 | (*it).setRevision( dt ); |
493 | } | 551 | } |
494 | (*it).setChanged( true ); | 552 | (*it).setChanged( true ); |
495 | } | 553 | } |
496 | 554 | ||
497 | found = true; | 555 | found = true; |
498 | } else { | 556 | } else { |
499 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 557 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
500 | QString name = (*it).uid().mid( 19 ); | 558 | QString name = (*it).uid().mid( 19 ); |
501 | Addressee b = a; | 559 | Addressee b = a; |
502 | QString id = b.getID( name ); | 560 | QString id = b.getID( name ); |
503 | if ( ! id.isEmpty() ) { | 561 | if ( ! id.isEmpty() ) { |
504 | QString des = (*it).note(); | 562 | QString des = (*it).note(); |
505 | int startN; | 563 | int startN; |
506 | if( (startN = des.find( id ) ) >= 0 ) { | 564 | if( (startN = des.find( id ) ) >= 0 ) { |
507 | int endN = des.find( ",", startN+1 ); | 565 | int endN = des.find( ",", startN+1 ); |
508 | des = des.left( startN ) + des.mid( endN+1 ); | 566 | des = des.left( startN ) + des.mid( endN+1 ); |
509 | (*it).setNote( des ); | 567 | (*it).setNote( des ); |
510 | } | 568 | } |
511 | } | 569 | } |
512 | } | 570 | } |
513 | } | 571 | } |
514 | } | 572 | } |
515 | if ( found ) | 573 | if ( found ) |
516 | return; | 574 | return; |
517 | d->mAddressees.append( a ); | 575 | d->mAddressees.append( a ); |
518 | Addressee& addr = d->mAddressees.last(); | 576 | Addressee& addr = d->mAddressees.last(); |
519 | if ( addr.resource() == 0 ) | 577 | if ( addr.resource() == 0 ) |
520 | addr.setResource( standardResource() ); | 578 | addr.setResource( standardResource() ); |
521 | 579 | ||
522 | addr.setChanged( true ); | 580 | addr.setChanged( true ); |
523 | } | 581 | } |
524 | 582 | ||
525 | void AddressBook::removeAddressee( const Addressee &a ) | 583 | void AddressBook::removeAddressee( const Addressee &a ) |
526 | { | 584 | { |
527 | Iterator it; | 585 | Iterator it; |
528 | Iterator it2; | 586 | Iterator it2; |
529 | bool found = false; | 587 | bool found = false; |
530 | for ( it = begin(); it != end(); ++it ) { | 588 | for ( it = begin(); it != end(); ++it ) { |
531 | if ( a.uid() == (*it).uid() ) { | 589 | if ( a.uid() == (*it).uid() ) { |
532 | found = true; | 590 | found = true; |
533 | it2 = it; | 591 | it2 = it; |
534 | } else { | 592 | } else { |
535 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 593 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
536 | QString name = (*it).uid().mid( 19 ); | 594 | QString name = (*it).uid().mid( 19 ); |
537 | Addressee b = a; | 595 | Addressee b = a; |
538 | QString id = b.getID( name ); | 596 | QString id = b.getID( name ); |
539 | if ( ! id.isEmpty() ) { | 597 | if ( ! id.isEmpty() ) { |
540 | QString des = (*it).note(); | 598 | QString des = (*it).note(); |
541 | if( des.find( id ) < 0 ) { | 599 | if( des.find( id ) < 0 ) { |
542 | des += id + ","; | 600 | des += id + ","; |
543 | (*it).setNote( des ); | 601 | (*it).setNote( des ); |
544 | } | 602 | } |
545 | } | 603 | } |
546 | } | 604 | } |
547 | 605 | ||
548 | } | 606 | } |
549 | } | 607 | } |
550 | 608 | ||
551 | if ( found ) | 609 | if ( found ) |
552 | removeAddressee( it2 ); | 610 | removeAddressee( it2 ); |
553 | 611 | ||
554 | } | 612 | } |
555 | 613 | ||
556 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 614 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
557 | { | 615 | { |
558 | Iterator it = begin(); | 616 | Iterator it = begin(); |
559 | Iterator it2 ; | 617 | Iterator it2 ; |
560 | QDateTime dt ( QDate( 2004,1,1) ); | 618 | QDateTime dt ( QDate( 2004,1,1) ); |
561 | while ( it != end() ) { | 619 | while ( it != end() ) { |
562 | (*it).setRevision( dt ); | 620 | (*it).setRevision( dt ); |
563 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 621 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
564 | (*it).setIDStr(""); | 622 | (*it).setIDStr(""); |
565 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 623 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
566 | it2 = it; | 624 | it2 = it; |
567 | //qDebug("removing %s ",(*it).uid().latin1() ); | 625 | //qDebug("removing %s ",(*it).uid().latin1() ); |
568 | ++it; | 626 | ++it; |
569 | removeAddressee( it2 ); | 627 | removeAddressee( it2 ); |
570 | } else { | 628 | } else { |
571 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 629 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
572 | ++it; | 630 | ++it; |
573 | } | 631 | } |
574 | } | 632 | } |
575 | deleteRemovedAddressees(); | 633 | deleteRemovedAddressees(); |
576 | } | 634 | } |
577 | 635 | ||
578 | void AddressBook::removeAddressee( const Iterator &it ) | 636 | void AddressBook::removeAddressee( const Iterator &it ) |
579 | { | 637 | { |
580 | d->mRemovedAddressees.append( (*it) ); | 638 | d->mRemovedAddressees.append( (*it) ); |
581 | d->mAddressees.remove( it.d->mIt ); | 639 | d->mAddressees.remove( it.d->mIt ); |
582 | } | 640 | } |
583 | 641 | ||
584 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 642 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
585 | { | 643 | { |
586 | Iterator it; | 644 | Iterator it; |
587 | for ( it = begin(); it != end(); ++it ) { | 645 | for ( it = begin(); it != end(); ++it ) { |
588 | if ( a.uid() == (*it).uid() ) { | 646 | if ( a.uid() == (*it).uid() ) { |
589 | return it; | 647 | return it; |
590 | } | 648 | } |
591 | } | 649 | } |
592 | return end(); | 650 | return end(); |
593 | } | 651 | } |
594 | 652 | ||
595 | Addressee AddressBook::findByUid( const QString &uid ) | 653 | Addressee AddressBook::findByUid( const QString &uid ) |
596 | { | 654 | { |
597 | Iterator it; | 655 | Iterator it; |
598 | for ( it = begin(); it != end(); ++it ) { | 656 | for ( it = begin(); it != end(); ++it ) { |
599 | if ( uid == (*it).uid() ) { | 657 | if ( uid == (*it).uid() ) { |
600 | return *it; | 658 | return *it; |
601 | } | 659 | } |
602 | } | 660 | } |
603 | return Addressee(); | 661 | return Addressee(); |
604 | } | 662 | } |
605 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 663 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
606 | { | 664 | { |
607 | //qDebug("AddressBook::preExternSync "); | 665 | //qDebug("AddressBook::preExternSync "); |
608 | AddressBook::Iterator it; | 666 | AddressBook::Iterator it; |
609 | for ( it = begin(); it != end(); ++it ) { | 667 | for ( it = begin(); it != end(); ++it ) { |
610 | (*it).setID( csd, (*it).externalUID() ); | 668 | (*it).setID( csd, (*it).externalUID() ); |
611 | (*it).computeCsum( csd ); | 669 | (*it).computeCsum( csd ); |
612 | } | 670 | } |
613 | mergeAB( aBook ,csd ); | 671 | mergeAB( aBook ,csd ); |
614 | } | 672 | } |
615 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 673 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
616 | { | 674 | { |
617 | //qDebug("AddressBook::postExternSync "); | 675 | //qDebug("AddressBook::postExternSync "); |
618 | AddressBook::Iterator it; | 676 | AddressBook::Iterator it; |
619 | for ( it = begin(); it != end(); ++it ) { | 677 | for ( it = begin(); it != end(); ++it ) { |
620 | // qDebug("check uid %s ", (*it).uid().latin1() ); | 678 | // qDebug("check uid %s ", (*it).uid().latin1() ); |
621 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 679 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
622 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 680 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
623 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 681 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
624 | if ( ad.isEmpty() ) { | 682 | if ( ad.isEmpty() ) { |
625 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); | 683 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
626 | } else { | 684 | } else { |
627 | (*it).computeCsum( csd ); | 685 | (*it).computeCsum( csd ); |
628 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 686 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
629 | ad.setID( csd, (*it).externalUID() ); | 687 | ad.setID( csd, (*it).externalUID() ); |
630 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 688 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
631 | aBook->insertAddressee( ad ); | 689 | aBook->insertAddressee( ad ); |
632 | } | 690 | } |
633 | } | 691 | } |
634 | } | 692 | } |
635 | } | 693 | } |
636 | 694 | ||
637 | bool AddressBook::containsExternalUid( const QString& uid ) | 695 | bool AddressBook::containsExternalUid( const QString& uid ) |
638 | { | 696 | { |
639 | Iterator it; | 697 | Iterator it; |
640 | for ( it = begin(); it != end(); ++it ) { | 698 | for ( it = begin(); it != end(); ++it ) { |
641 | if ( uid == (*it).externalUID( ) ) | 699 | if ( uid == (*it).externalUID( ) ) |
642 | return true; | 700 | return true; |
643 | } | 701 | } |
644 | return false; | 702 | return false; |
645 | } | 703 | } |
646 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 704 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
647 | { | 705 | { |
648 | Iterator it; | 706 | Iterator it; |
649 | for ( it = begin(); it != end(); ++it ) { | 707 | for ( it = begin(); it != end(); ++it ) { |
650 | if ( uid == (*it).getID( profile ) ) | 708 | if ( uid == (*it).getID( profile ) ) |
651 | return (*it); | 709 | return (*it); |
652 | } | 710 | } |
653 | return Addressee(); | 711 | return Addressee(); |
654 | } | 712 | } |
655 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 713 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
656 | { | 714 | { |
657 | Iterator it; | 715 | Iterator it; |
658 | Addressee ad; | 716 | Addressee ad; |
659 | for ( it = begin(); it != end(); ++it ) { | 717 | for ( it = begin(); it != end(); ++it ) { |
660 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 718 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
661 | if ( !ad.isEmpty() ) { | 719 | if ( !ad.isEmpty() ) { |
662 | (*it).mergeContact( ad ); | 720 | (*it).mergeContact( ad ); |
663 | } | 721 | } |
664 | } | 722 | } |
665 | #if 0 | 723 | #if 0 |
666 | // test only | 724 | // test only |
667 | for ( it = begin(); it != end(); ++it ) { | 725 | for ( it = begin(); it != end(); ++it ) { |
668 | 726 | ||
669 | qDebug("uid %s ", (*it).uid().latin1()); | 727 | qDebug("uid %s ", (*it).uid().latin1()); |
670 | } | 728 | } |
671 | #endif | 729 | #endif |
672 | } | 730 | } |
673 | 731 | ||
674 | #if 0 | 732 | #if 0 |
675 | Addressee::List AddressBook::getExternLastSyncAddressees() | 733 | Addressee::List AddressBook::getExternLastSyncAddressees() |
676 | { | 734 | { |
677 | Addressee::List results; | 735 | Addressee::List results; |
678 | 736 | ||
679 | Iterator it; | 737 | Iterator it; |
680 | for ( it = begin(); it != end(); ++it ) { | 738 | for ( it = begin(); it != end(); ++it ) { |
681 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 739 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
682 | if ( (*it).familyName().left(4) == "!E: " ) | 740 | if ( (*it).familyName().left(4) == "!E: " ) |
683 | results.append( *it ); | 741 | results.append( *it ); |
684 | } | 742 | } |
685 | } | 743 | } |
686 | 744 | ||
687 | return results; | 745 | return results; |
688 | } | 746 | } |
689 | #endif | 747 | #endif |
690 | void AddressBook::resetTempSyncStat() | 748 | void AddressBook::resetTempSyncStat() |
691 | { | 749 | { |
692 | Iterator it; | 750 | Iterator it; |
693 | for ( it = begin(); it != end(); ++it ) { | 751 | for ( it = begin(); it != end(); ++it ) { |
694 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 752 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
695 | } | 753 | } |
696 | 754 | ||
697 | } | 755 | } |
698 | 756 | ||
699 | QStringList AddressBook:: uidList() | 757 | QStringList AddressBook:: uidList() |
700 | { | 758 | { |
701 | QStringList results; | 759 | QStringList results; |
702 | Iterator it; | 760 | Iterator it; |
703 | for ( it = begin(); it != end(); ++it ) { | 761 | for ( it = begin(); it != end(); ++it ) { |
704 | results.append( (*it).uid() ); | 762 | results.append( (*it).uid() ); |
705 | } | 763 | } |
706 | return results; | 764 | return results; |
707 | } | 765 | } |
708 | 766 | ||
709 | 767 | ||
710 | Addressee::List AddressBook::allAddressees() | 768 | Addressee::List AddressBook::allAddressees() |
711 | { | 769 | { |
712 | return d->mAddressees; | 770 | return d->mAddressees; |
713 | 771 | ||
714 | } | 772 | } |
715 | 773 | ||
716 | Addressee::List AddressBook::findByName( const QString &name ) | 774 | Addressee::List AddressBook::findByName( const QString &name ) |
717 | { | 775 | { |
718 | Addressee::List results; | 776 | Addressee::List results; |
719 | 777 | ||
720 | Iterator it; | 778 | Iterator it; |
721 | for ( it = begin(); it != end(); ++it ) { | 779 | for ( it = begin(); it != end(); ++it ) { |
722 | if ( name == (*it).realName() ) { | 780 | if ( name == (*it).realName() ) { |
723 | results.append( *it ); | 781 | results.append( *it ); |
724 | } | 782 | } |
725 | } | 783 | } |
726 | 784 | ||
727 | return results; | 785 | return results; |
728 | } | 786 | } |
729 | 787 | ||
730 | Addressee::List AddressBook::findByEmail( const QString &email ) | 788 | Addressee::List AddressBook::findByEmail( const QString &email ) |
731 | { | 789 | { |
732 | Addressee::List results; | 790 | Addressee::List results; |
733 | QStringList mailList; | 791 | QStringList mailList; |
734 | 792 | ||
735 | Iterator it; | 793 | Iterator it; |
736 | for ( it = begin(); it != end(); ++it ) { | 794 | for ( it = begin(); it != end(); ++it ) { |
737 | mailList = (*it).emails(); | 795 | mailList = (*it).emails(); |
738 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 796 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
739 | if ( email == (*ite) ) { | 797 | if ( email == (*ite) ) { |
740 | results.append( *it ); | 798 | results.append( *it ); |
741 | } | 799 | } |
742 | } | 800 | } |
743 | } | 801 | } |
744 | 802 | ||
745 | return results; | 803 | return results; |
746 | } | 804 | } |
747 | 805 | ||
748 | Addressee::List AddressBook::findByCategory( const QString &category ) | 806 | Addressee::List AddressBook::findByCategory( const QString &category ) |
749 | { | 807 | { |
750 | Addressee::List results; | 808 | Addressee::List results; |
751 | 809 | ||
752 | Iterator it; | 810 | Iterator it; |
753 | for ( it = begin(); it != end(); ++it ) { | 811 | for ( it = begin(); it != end(); ++it ) { |
754 | if ( (*it).hasCategory( category) ) { | 812 | if ( (*it).hasCategory( category) ) { |
755 | results.append( *it ); | 813 | results.append( *it ); |
756 | } | 814 | } |
757 | } | 815 | } |
758 | 816 | ||
759 | return results; | 817 | return results; |
760 | } | 818 | } |
761 | 819 | ||
762 | void AddressBook::dump() const | 820 | void AddressBook::dump() const |
763 | { | 821 | { |
764 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 822 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
765 | 823 | ||
766 | ConstIterator it; | 824 | ConstIterator it; |
767 | for( it = begin(); it != end(); ++it ) { | 825 | for( it = begin(); it != end(); ++it ) { |
768 | (*it).dump(); | 826 | (*it).dump(); |
769 | } | 827 | } |
770 | 828 | ||
771 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 829 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
772 | } | 830 | } |
773 | 831 | ||
774 | QString AddressBook::identifier() | 832 | QString AddressBook::identifier() |
775 | { | 833 | { |
776 | QStringList identifier; | 834 | QStringList identifier; |
777 | 835 | ||
778 | 836 | ||
779 | KRES::Manager<Resource>::ActiveIterator it; | 837 | KRES::Manager<Resource>::ActiveIterator it; |
780 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 838 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
781 | if ( !(*it)->identifier().isEmpty() ) | 839 | if ( !(*it)->identifier().isEmpty() ) |
782 | identifier.append( (*it)->identifier() ); | 840 | identifier.append( (*it)->identifier() ); |
783 | } | 841 | } |
784 | 842 | ||
785 | return identifier.join( ":" ); | 843 | return identifier.join( ":" ); |
786 | } | 844 | } |
787 | 845 | ||
788 | Field::List AddressBook::fields( int category ) | 846 | Field::List AddressBook::fields( int category ) |
789 | { | 847 | { |
790 | if ( d->mAllFields.isEmpty() ) { | 848 | if ( d->mAllFields.isEmpty() ) { |
791 | d->mAllFields = Field::allFields(); | 849 | d->mAllFields = Field::allFields(); |
792 | } | 850 | } |
793 | 851 | ||
794 | if ( category == Field::All ) return d->mAllFields; | 852 | if ( category == Field::All ) return d->mAllFields; |
795 | 853 | ||
796 | Field::List result; | 854 | Field::List result; |
797 | Field::List::ConstIterator it; | 855 | Field::List::ConstIterator it; |
798 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 856 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
799 | if ( (*it)->category() & category ) result.append( *it ); | 857 | if ( (*it)->category() & category ) result.append( *it ); |
800 | } | 858 | } |
801 | 859 | ||
802 | return result; | 860 | return result; |
803 | } | 861 | } |
804 | 862 | ||
805 | bool AddressBook::addCustomField( const QString &label, int category, | 863 | bool AddressBook::addCustomField( const QString &label, int category, |
806 | const QString &key, const QString &app ) | 864 | const QString &key, const QString &app ) |
807 | { | 865 | { |
808 | if ( d->mAllFields.isEmpty() ) { | 866 | if ( d->mAllFields.isEmpty() ) { |
809 | d->mAllFields = Field::allFields(); | 867 | d->mAllFields = Field::allFields(); |
810 | } | 868 | } |
811 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 869 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
812 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 870 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
813 | 871 | ||
814 | QString k = key.isNull() ? label : key; | 872 | QString k = key.isNull() ? label : key; |
815 | 873 | ||
816 | Field *field = Field::createCustomField( label, category, k, a ); | 874 | Field *field = Field::createCustomField( label, category, k, a ); |
817 | 875 | ||
818 | if ( !field ) return false; | 876 | if ( !field ) return false; |
819 | 877 | ||
820 | d->mAllFields.append( field ); | 878 | d->mAllFields.append( field ); |
821 | 879 | ||
822 | return true; | 880 | return true; |
823 | } | 881 | } |
824 | 882 | ||
825 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 883 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
826 | { | 884 | { |
827 | if (!ab.d) return s; | 885 | if (!ab.d) return s; |
828 | 886 | ||
829 | return s << ab.d->mAddressees; | 887 | return s << ab.d->mAddressees; |
830 | } | 888 | } |
831 | 889 | ||
832 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 890 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
833 | { | 891 | { |
834 | if (!ab.d) return s; | 892 | if (!ab.d) return s; |
835 | 893 | ||
836 | s >> ab.d->mAddressees; | 894 | s >> ab.d->mAddressees; |
837 | 895 | ||
838 | return s; | 896 | return s; |
839 | } | 897 | } |
840 | 898 | ||
841 | bool AddressBook::addResource( Resource *resource ) | 899 | bool AddressBook::addResource( Resource *resource ) |
842 | { | 900 | { |
843 | if ( !resource->open() ) { | 901 | if ( !resource->open() ) { |
844 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 902 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
845 | return false; | 903 | return false; |
846 | } | 904 | } |
847 | 905 | ||
848 | resource->setAddressBook( this ); | 906 | resource->setAddressBook( this ); |
849 | 907 | ||
850 | d->mManager->add( resource ); | 908 | d->mManager->add( resource ); |
851 | return true; | 909 | return true; |
852 | } | 910 | } |
853 | 911 | ||
854 | bool AddressBook::removeResource( Resource *resource ) | 912 | bool AddressBook::removeResource( Resource *resource ) |
855 | { | 913 | { |
856 | resource->close(); | 914 | resource->close(); |
857 | 915 | ||
858 | if ( resource == standardResource() ) | 916 | if ( resource == standardResource() ) |
859 | d->mManager->setStandardResource( 0 ); | 917 | d->mManager->setStandardResource( 0 ); |
860 | 918 | ||
861 | resource->setAddressBook( 0 ); | 919 | resource->setAddressBook( 0 ); |
862 | 920 | ||
863 | d->mManager->remove( resource ); | 921 | d->mManager->remove( resource ); |
864 | return true; | 922 | return true; |
865 | } | 923 | } |
866 | 924 | ||
867 | QPtrList<Resource> AddressBook::resources() | 925 | QPtrList<Resource> AddressBook::resources() |
868 | { | 926 | { |
869 | QPtrList<Resource> list; | 927 | QPtrList<Resource> list; |
870 | 928 | ||
871 | // qDebug("AddressBook::resources() 1"); | 929 | // qDebug("AddressBook::resources() 1"); |
872 | 930 | ||
873 | KRES::Manager<Resource>::ActiveIterator it; | 931 | KRES::Manager<Resource>::ActiveIterator it; |
874 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 932 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
875 | list.append( *it ); | 933 | list.append( *it ); |
876 | 934 | ||
877 | return list; | 935 | return list; |
878 | } | 936 | } |
879 | 937 | ||
880 | /*US | 938 | /*US |
881 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 939 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
882 | { | 940 | { |
883 | delete d->mErrorHandler; | 941 | delete d->mErrorHandler; |
884 | d->mErrorHandler = handler; | 942 | d->mErrorHandler = handler; |
885 | } | 943 | } |
886 | */ | 944 | */ |
887 | 945 | ||
888 | void AddressBook::error( const QString& msg ) | 946 | void AddressBook::error( const QString& msg ) |
889 | { | 947 | { |
890 | /*US | 948 | /*US |
891 | if ( !d->mErrorHandler ) // create default error handler | 949 | if ( !d->mErrorHandler ) // create default error handler |
892 | d->mErrorHandler = new ConsoleErrorHandler; | 950 | d->mErrorHandler = new ConsoleErrorHandler; |
893 | 951 | ||
894 | if ( d->mErrorHandler ) | 952 | if ( d->mErrorHandler ) |
895 | d->mErrorHandler->error( msg ); | 953 | d->mErrorHandler->error( msg ); |
896 | else | 954 | else |
897 | kdError(5700) << "no error handler defined" << endl; | 955 | kdError(5700) << "no error handler defined" << endl; |
898 | */ | 956 | */ |
899 | kdDebug(5700) << "msg" << endl; | 957 | kdDebug(5700) << "msg" << endl; |
900 | qDebug(msg); | 958 | qDebug(msg); |
901 | } | 959 | } |
902 | 960 | ||
903 | void AddressBook::deleteRemovedAddressees() | 961 | void AddressBook::deleteRemovedAddressees() |
904 | { | 962 | { |
905 | Addressee::List::Iterator it; | 963 | Addressee::List::Iterator it; |
906 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 964 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
907 | Resource *resource = (*it).resource(); | 965 | Resource *resource = (*it).resource(); |
908 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 966 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
909 | resource->removeAddressee( *it ); | 967 | resource->removeAddressee( *it ); |
910 | } | 968 | } |
911 | 969 | ||
912 | d->mRemovedAddressees.clear(); | 970 | d->mRemovedAddressees.clear(); |
913 | } | 971 | } |
914 | 972 | ||
915 | void AddressBook::setStandardResource( Resource *resource ) | 973 | void AddressBook::setStandardResource( Resource *resource ) |
916 | { | 974 | { |
917 | // qDebug("AddressBook::setStandardResource 1"); | 975 | // qDebug("AddressBook::setStandardResource 1"); |
918 | d->mManager->setStandardResource( resource ); | 976 | d->mManager->setStandardResource( resource ); |
919 | } | 977 | } |
920 | 978 | ||
921 | Resource *AddressBook::standardResource() | 979 | Resource *AddressBook::standardResource() |
922 | { | 980 | { |
923 | return d->mManager->standardResource(); | 981 | return d->mManager->standardResource(); |
924 | } | 982 | } |
925 | 983 | ||
926 | KRES::Manager<Resource> *AddressBook::resourceManager() | 984 | KRES::Manager<Resource> *AddressBook::resourceManager() |
927 | { | 985 | { |
928 | return d->mManager; | 986 | return d->mManager; |
929 | } | 987 | } |
930 | 988 | ||
931 | void AddressBook::cleanUp() | 989 | void AddressBook::cleanUp() |
932 | { | 990 | { |
933 | KRES::Manager<Resource>::ActiveIterator it; | 991 | KRES::Manager<Resource>::ActiveIterator it; |
934 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 992 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
935 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 993 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
936 | (*it)->cleanUp(); | 994 | (*it)->cleanUp(); |
937 | } | 995 | } |
938 | } | 996 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 8f62f0d..3603ec1 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,340 +1,341 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef KABC_ADDRESSBOOK_H | 28 | #ifndef KABC_ADDRESSBOOK_H |
29 | #define KABC_ADDRESSBOOK_H | 29 | #define KABC_ADDRESSBOOK_H |
30 | 30 | ||
31 | #include <qobject.h> | 31 | #include <qobject.h> |
32 | 32 | ||
33 | #include <kresources/manager.h> | 33 | #include <kresources/manager.h> |
34 | #include <qptrlist.h> | 34 | #include <qptrlist.h> |
35 | 35 | ||
36 | #include "addressee.h" | 36 | #include "addressee.h" |
37 | #include "field.h" | 37 | #include "field.h" |
38 | 38 | ||
39 | namespace KABC { | 39 | namespace KABC { |
40 | 40 | ||
41 | class ErrorHandler; | 41 | class ErrorHandler; |
42 | class Resource; | 42 | class Resource; |
43 | class Ticket; | 43 | class Ticket; |
44 | 44 | ||
45 | /** | 45 | /** |
46 | @short Address Book | 46 | @short Address Book |
47 | 47 | ||
48 | This class provides access to a collection of address book entries. | 48 | This class provides access to a collection of address book entries. |
49 | */ | 49 | */ |
50 | class AddressBook : public QObject | 50 | class AddressBook : public QObject |
51 | { | 51 | { |
52 | Q_OBJECT | 52 | Q_OBJECT |
53 | 53 | ||
54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); | 54 | friend QDataStream &operator<<( QDataStream &, const AddressBook & ); |
55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); | 55 | friend QDataStream &operator>>( QDataStream &, AddressBook & ); |
56 | friend class StdAddressBook; | 56 | friend class StdAddressBook; |
57 | 57 | ||
58 | public: | 58 | public: |
59 | /** | 59 | /** |
60 | @short Address Book Iterator | 60 | @short Address Book Iterator |
61 | 61 | ||
62 | This class provides an iterator for address book entries. | 62 | This class provides an iterator for address book entries. |
63 | */ | 63 | */ |
64 | class Iterator | 64 | class Iterator |
65 | { | 65 | { |
66 | public: | 66 | public: |
67 | Iterator(); | 67 | Iterator(); |
68 | Iterator( const Iterator & ); | 68 | Iterator( const Iterator & ); |
69 | ~Iterator(); | 69 | ~Iterator(); |
70 | 70 | ||
71 | Iterator &operator=( const Iterator & ); | 71 | Iterator &operator=( const Iterator & ); |
72 | const Addressee &operator*() const; | 72 | const Addressee &operator*() const; |
73 | Addressee &operator*(); | 73 | Addressee &operator*(); |
74 | Addressee* operator->(); | 74 | Addressee* operator->(); |
75 | Iterator &operator++(); | 75 | Iterator &operator++(); |
76 | Iterator &operator++(int); | 76 | Iterator &operator++(int); |
77 | Iterator &operator--(); | 77 | Iterator &operator--(); |
78 | Iterator &operator--(int); | 78 | Iterator &operator--(int); |
79 | bool operator==( const Iterator &it ); | 79 | bool operator==( const Iterator &it ); |
80 | bool operator!=( const Iterator &it ); | 80 | bool operator!=( const Iterator &it ); |
81 | 81 | ||
82 | struct IteratorData; | 82 | struct IteratorData; |
83 | IteratorData *d; | 83 | IteratorData *d; |
84 | }; | 84 | }; |
85 | 85 | ||
86 | /** | 86 | /** |
87 | @short Address Book Const Iterator | 87 | @short Address Book Const Iterator |
88 | 88 | ||
89 | This class provides a const iterator for address book entries. | 89 | This class provides a const iterator for address book entries. |
90 | */ | 90 | */ |
91 | class ConstIterator | 91 | class ConstIterator |
92 | { | 92 | { |
93 | public: | 93 | public: |
94 | ConstIterator(); | 94 | ConstIterator(); |
95 | ConstIterator( const ConstIterator & ); | 95 | ConstIterator( const ConstIterator & ); |
96 | ~ConstIterator(); | 96 | ~ConstIterator(); |
97 | 97 | ||
98 | ConstIterator &operator=( const ConstIterator & ); | 98 | ConstIterator &operator=( const ConstIterator & ); |
99 | const Addressee &operator*() const; | 99 | const Addressee &operator*() const; |
100 | const Addressee* operator->() const; | 100 | const Addressee* operator->() const; |
101 | ConstIterator &operator++(); | 101 | ConstIterator &operator++(); |
102 | ConstIterator &operator++(int); | 102 | ConstIterator &operator++(int); |
103 | ConstIterator &operator--(); | 103 | ConstIterator &operator--(); |
104 | ConstIterator &operator--(int); | 104 | ConstIterator &operator--(int); |
105 | bool operator==( const ConstIterator &it ); | 105 | bool operator==( const ConstIterator &it ); |
106 | bool operator!=( const ConstIterator &it ); | 106 | bool operator!=( const ConstIterator &it ); |
107 | 107 | ||
108 | struct ConstIteratorData; | 108 | struct ConstIteratorData; |
109 | ConstIteratorData *d; | 109 | ConstIteratorData *d; |
110 | }; | 110 | }; |
111 | 111 | ||
112 | /** | 112 | /** |
113 | Constructs a address book object. | 113 | Constructs a address book object. |
114 | 114 | ||
115 | @param format File format class. | 115 | @param format File format class. |
116 | */ | 116 | */ |
117 | AddressBook(); | 117 | AddressBook(); |
118 | AddressBook( const QString &config ); | 118 | AddressBook( const QString &config ); |
119 | AddressBook( const QString &config, const QString &family ); | 119 | AddressBook( const QString &config, const QString &family ); |
120 | virtual ~AddressBook(); | 120 | virtual ~AddressBook(); |
121 | 121 | ||
122 | /** | 122 | /** |
123 | Requests a ticket for saving the addressbook. Calling this function locks | 123 | Requests a ticket for saving the addressbook. Calling this function locks |
124 | the addressbook for all other processes. If the address book is already | 124 | the addressbook for all other processes. If the address book is already |
125 | locked the function returns 0. You need the returned @ref Ticket object | 125 | locked the function returns 0. You need the returned @ref Ticket object |
126 | for calling the @ref save() function. | 126 | for calling the @ref save() function. |
127 | 127 | ||
128 | @see save() | 128 | @see save() |
129 | */ | 129 | */ |
130 | Ticket *requestSaveTicket( Resource *resource=0 ); | 130 | Ticket *requestSaveTicket( Resource *resource=0 ); |
131 | 131 | ||
132 | /** | 132 | /** |
133 | Load address book from file. | 133 | Load address book from file. |
134 | */ | 134 | */ |
135 | bool load(); | 135 | bool load(); |
136 | 136 | ||
137 | /** | 137 | /** |
138 | Save address book. The address book is saved to the file, the Ticket | 138 | Save address book. The address book is saved to the file, the Ticket |
139 | object has been requested for by @ref requestSaveTicket(). | 139 | object has been requested for by @ref requestSaveTicket(). |
140 | 140 | ||
141 | @param ticket a ticket object returned by @ref requestSaveTicket() | 141 | @param ticket a ticket object returned by @ref requestSaveTicket() |
142 | */ | 142 | */ |
143 | bool save( Ticket *ticket ); | 143 | bool save( Ticket *ticket ); |
144 | bool saveAB( ); | 144 | bool saveAB( ); |
145 | 145 | void export2File( QString fileName ); | |
146 | void importFromFile( QString fileName ); | ||
146 | /** | 147 | /** |
147 | Returns a iterator for first entry of address book. | 148 | Returns a iterator for first entry of address book. |
148 | */ | 149 | */ |
149 | Iterator begin(); | 150 | Iterator begin(); |
150 | 151 | ||
151 | /** | 152 | /** |
152 | Returns a const iterator for first entry of address book. | 153 | Returns a const iterator for first entry of address book. |
153 | */ | 154 | */ |
154 | ConstIterator begin() const; | 155 | ConstIterator begin() const; |
155 | 156 | ||
156 | /** | 157 | /** |
157 | Returns a iterator for first entry of address book. | 158 | Returns a iterator for first entry of address book. |
158 | */ | 159 | */ |
159 | Iterator end(); | 160 | Iterator end(); |
160 | 161 | ||
161 | /** | 162 | /** |
162 | Returns a const iterator for first entry of address book. | 163 | Returns a const iterator for first entry of address book. |
163 | */ | 164 | */ |
164 | ConstIterator end() const; | 165 | ConstIterator end() const; |
165 | 166 | ||
166 | /** | 167 | /** |
167 | Removes all entries from address book. | 168 | Removes all entries from address book. |
168 | */ | 169 | */ |
169 | void clear(); | 170 | void clear(); |
170 | 171 | ||
171 | /** | 172 | /** |
172 | Insert an Addressee object into address book. If an object with the same | 173 | Insert an Addressee object into address book. If an object with the same |
173 | unique id already exists in the address book it it replaced by the new | 174 | unique id already exists in the address book it it replaced by the new |
174 | one. If not the new object is appended to the address book. | 175 | one. If not the new object is appended to the address book. |
175 | */ | 176 | */ |
176 | void insertAddressee( const Addressee &, bool setRev = true ); | 177 | void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
177 | 178 | ||
178 | /** | 179 | /** |
179 | Removes entry from the address book. | 180 | Removes entry from the address book. |
180 | */ | 181 | */ |
181 | void removeAddressee( const Addressee & ); | 182 | void removeAddressee( const Addressee & ); |
182 | 183 | ||
183 | /** | 184 | /** |
184 | This is like @ref removeAddressee() just above, with the difference that | 185 | This is like @ref removeAddressee() just above, with the difference that |
185 | the first element is a iterator, returned by @ref begin(). | 186 | the first element is a iterator, returned by @ref begin(). |
186 | */ | 187 | */ |
187 | void removeAddressee( const Iterator & ); | 188 | void removeAddressee( const Iterator & ); |
188 | 189 | ||
189 | /** | 190 | /** |
190 | Find the specified entry in address book. Returns end(), if the entry | 191 | Find the specified entry in address book. Returns end(), if the entry |
191 | couldn't be found. | 192 | couldn't be found. |
192 | */ | 193 | */ |
193 | Iterator find( const Addressee & ); | 194 | Iterator find( const Addressee & ); |
194 | 195 | ||
195 | /** | 196 | /** |
196 | Find the entry specified by an unique id. Returns an empty Addressee | 197 | Find the entry specified by an unique id. Returns an empty Addressee |
197 | object, if the address book does not contain an entry with this id. | 198 | object, if the address book does not contain an entry with this id. |
198 | */ | 199 | */ |
199 | Addressee findByUid( const QString & ); | 200 | Addressee findByUid( const QString & ); |
200 | 201 | ||
201 | 202 | ||
202 | /** | 203 | /** |
203 | Returns a list of all addressees in the address book. This list can | 204 | Returns a list of all addressees in the address book. This list can |
204 | be sorted with @ref KABC::AddresseeList for example. | 205 | be sorted with @ref KABC::AddresseeList for example. |
205 | */ | 206 | */ |
206 | Addressee::List allAddressees(); | 207 | Addressee::List allAddressees(); |
207 | 208 | ||
208 | /** | 209 | /** |
209 | Find all entries with the specified name in the address book. Returns | 210 | Find all entries with the specified name in the address book. Returns |
210 | an empty list, if no entries could be found. | 211 | an empty list, if no entries could be found. |
211 | */ | 212 | */ |
212 | Addressee::List findByName( const QString & ); | 213 | Addressee::List findByName( const QString & ); |
213 | 214 | ||
214 | /** | 215 | /** |
215 | Find all entries with the specified email address in the address book. | 216 | Find all entries with the specified email address in the address book. |
216 | Returns an empty list, if no entries could be found. | 217 | Returns an empty list, if no entries could be found. |
217 | */ | 218 | */ |
218 | Addressee::List findByEmail( const QString & ); | 219 | Addressee::List findByEmail( const QString & ); |
219 | 220 | ||
220 | /** | 221 | /** |
221 | Find all entries wich have the specified category in the address book. | 222 | Find all entries wich have the specified category in the address book. |
222 | Returns an empty list, if no entries could be found. | 223 | Returns an empty list, if no entries could be found. |
223 | */ | 224 | */ |
224 | Addressee::List findByCategory( const QString & ); | 225 | Addressee::List findByCategory( const QString & ); |
225 | 226 | ||
226 | /** | 227 | /** |
227 | Return a string identifying this addressbook. | 228 | Return a string identifying this addressbook. |
228 | */ | 229 | */ |
229 | virtual QString identifier(); | 230 | virtual QString identifier(); |
230 | 231 | ||
231 | /** | 232 | /** |
232 | Used for debug output. | 233 | Used for debug output. |
233 | */ | 234 | */ |
234 | void dump() const; | 235 | void dump() const; |
235 | 236 | ||
236 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 237 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
237 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 238 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
238 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 239 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
239 | 240 | ||
240 | /** | 241 | /** |
241 | Return list of all Fields known to the address book which are associated | 242 | Return list of all Fields known to the address book which are associated |
242 | with the given field category. | 243 | with the given field category. |
243 | */ | 244 | */ |
244 | Field::List fields( int category = Field::All ); | 245 | Field::List fields( int category = Field::All ); |
245 | 246 | ||
246 | /** | 247 | /** |
247 | Add custom field to address book. | 248 | Add custom field to address book. |
248 | 249 | ||
249 | @param label User visible label of the field. | 250 | @param label User visible label of the field. |
250 | @param category Ored list of field categories. | 251 | @param category Ored list of field categories. |
251 | @param key Identifier used as key for reading and writing the field. | 252 | @param key Identifier used as key for reading and writing the field. |
252 | @param app String used as application key for reading and writing | 253 | @param app String used as application key for reading and writing |
253 | the field. | 254 | the field. |
254 | */ | 255 | */ |
255 | bool addCustomField( const QString &label, int category = Field::All, | 256 | bool addCustomField( const QString &label, int category = Field::All, |
256 | const QString &key = QString::null, | 257 | const QString &key = QString::null, |
257 | const QString &app = QString::null ); | 258 | const QString &app = QString::null ); |
258 | 259 | ||
259 | 260 | ||
260 | /** | 261 | /** |
261 | Add address book resource. | 262 | Add address book resource. |
262 | */ | 263 | */ |
263 | bool addResource( Resource * ); | 264 | bool addResource( Resource * ); |
264 | 265 | ||
265 | /** | 266 | /** |
266 | Remove address book resource. | 267 | Remove address book resource. |
267 | */ | 268 | */ |
268 | bool removeResource( Resource * ); | 269 | bool removeResource( Resource * ); |
269 | 270 | ||
270 | /** | 271 | /** |
271 | Return pointer list of all resources. | 272 | Return pointer list of all resources. |
272 | */ | 273 | */ |
273 | QPtrList<Resource> resources(); | 274 | QPtrList<Resource> resources(); |
274 | 275 | ||
275 | /** | 276 | /** |
276 | Set the @p ErrorHandler, that is used by @ref error() to | 277 | Set the @p ErrorHandler, that is used by @ref error() to |
277 | provide gui-independend error messages. | 278 | provide gui-independend error messages. |
278 | */ | 279 | */ |
279 | void setErrorHandler( ErrorHandler * ); | 280 | void setErrorHandler( ErrorHandler * ); |
280 | 281 | ||
281 | /** | 282 | /** |
282 | Shows gui independend error messages. | 283 | Shows gui independend error messages. |
283 | */ | 284 | */ |
284 | void error( const QString& ); | 285 | void error( const QString& ); |
285 | 286 | ||
286 | /** | 287 | /** |
287 | Query all resources to clean up their lock files | 288 | Query all resources to clean up their lock files |
288 | */ | 289 | */ |
289 | void cleanUp(); | 290 | void cleanUp(); |
290 | 291 | ||
291 | // sync stuff | 292 | // sync stuff |
292 | //Addressee::List getExternLastSyncAddressees(); | 293 | //Addressee::List getExternLastSyncAddressees(); |
293 | void resetTempSyncStat(); | 294 | void resetTempSyncStat(); |
294 | QStringList uidList(); | 295 | QStringList uidList(); |
295 | void removeSyncAddressees( bool removeDeleted = false ); | 296 | void removeSyncAddressees( bool removeDeleted = false ); |
296 | void mergeAB( AddressBook *aBook, const QString& profile ); | 297 | void mergeAB( AddressBook *aBook, const QString& profile ); |
297 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 298 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
298 | bool containsExternalUid( const QString& uid ); | 299 | bool containsExternalUid( const QString& uid ); |
299 | 300 | ||
300 | void preExternSync( AddressBook* aBook, const QString& csd ); | 301 | void preExternSync( AddressBook* aBook, const QString& csd ); |
301 | void postExternSync( AddressBook* aBook, const QString& csd ); | 302 | void postExternSync( AddressBook* aBook, const QString& csd ); |
302 | signals: | 303 | signals: |
303 | /** | 304 | /** |
304 | Emitted, when the address book has changed on disk. | 305 | Emitted, when the address book has changed on disk. |
305 | */ | 306 | */ |
306 | void addressBookChanged( AddressBook * ); | 307 | void addressBookChanged( AddressBook * ); |
307 | 308 | ||
308 | /** | 309 | /** |
309 | Emitted, when the address book has been locked for writing. | 310 | Emitted, when the address book has been locked for writing. |
310 | */ | 311 | */ |
311 | void addressBookLocked( AddressBook * ); | 312 | void addressBookLocked( AddressBook * ); |
312 | 313 | ||
313 | /** | 314 | /** |
314 | Emitted, when the address book has been unlocked. | 315 | Emitted, when the address book has been unlocked. |
315 | */ | 316 | */ |
316 | void addressBookUnlocked( AddressBook * ); | 317 | void addressBookUnlocked( AddressBook * ); |
317 | 318 | ||
318 | protected: | 319 | protected: |
319 | void deleteRemovedAddressees(); | 320 | void deleteRemovedAddressees(); |
320 | void setStandardResource( Resource * ); | 321 | void setStandardResource( Resource * ); |
321 | Resource *standardResource(); | 322 | Resource *standardResource(); |
322 | KRES::Manager<Resource> *resourceManager(); | 323 | KRES::Manager<Resource> *resourceManager(); |
323 | 324 | ||
324 | void init(const QString &config, const QString &family); | 325 | void init(const QString &config, const QString &family); |
325 | 326 | ||
326 | private: | 327 | private: |
327 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 328 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
328 | 329 | ||
329 | 330 | ||
330 | struct AddressBookData; | 331 | struct AddressBookData; |
331 | AddressBookData *d; | 332 | AddressBookData *d; |
332 | bool blockLSEchange; | 333 | bool blockLSEchange; |
333 | }; | 334 | }; |
334 | 335 | ||
335 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 336 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
336 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 337 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
337 | 338 | ||
338 | } | 339 | } |
339 | 340 | ||
340 | #endif | 341 | #endif |