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