author | zautrix <zautrix> | 2004-09-20 00:12:42 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-20 00:12:42 (UTC) |
commit | b01b669d88fa195261d29ecf73b1c69e608a5ebc (patch) (unidiff) | |
tree | c0e79d45242a764b49470d07a9c95be156c121cc /kabc | |
parent | 3da2cfeab2edbe64a17251662e56668fe143f7a3 (diff) | |
download | kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.zip kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.gz kdepimpi-b01b669d88fa195261d29ecf73b1c69e608a5ebc.tar.bz2 |
more AB sync
-rw-r--r-- | kabc/addressbook.cpp | 27 | ||||
-rw-r--r-- | kabc/addressbook.h | 3 | ||||
-rw-r--r-- | kabc/addressee.cpp | 6 | ||||
-rw-r--r-- | kabc/plugins/qtopia/qtopiaconverter.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 79 |
5 files changed, 98 insertions, 19 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 86dc7c2..17b9ba2 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,922 +1,937 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /*US | 28 | /*US |
29 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | 41 | ||
42 | #include <kglobal.h> | 42 | #include <kglobal.h> |
43 | #include <klocale.h> | 43 | #include <klocale.h> |
44 | #include <kdebug.h> | 44 | #include <kdebug.h> |
45 | #include <libkcal/syncdefines.h> | 45 | #include <libkcal/syncdefines.h> |
46 | #include "addressbook.h" | 46 | #include "addressbook.h" |
47 | #include "resource.h" | 47 | #include "resource.h" |
48 | 48 | ||
49 | //US #include "addressbook.moc" | 49 | //US #include "addressbook.moc" |
50 | 50 | ||
51 | using namespace KABC; | 51 | using namespace KABC; |
52 | 52 | ||
53 | struct AddressBook::AddressBookData | 53 | struct AddressBook::AddressBookData |
54 | { | 54 | { |
55 | Addressee::List mAddressees; | 55 | Addressee::List mAddressees; |
56 | Addressee::List mRemovedAddressees; | 56 | Addressee::List mRemovedAddressees; |
57 | Field::List mAllFields; | 57 | Field::List mAllFields; |
58 | KConfig *mConfig; | 58 | KConfig *mConfig; |
59 | KRES::Manager<Resource> *mManager; | 59 | KRES::Manager<Resource> *mManager; |
60 | //US ErrorHandler *mErrorHandler; | 60 | //US ErrorHandler *mErrorHandler; |
61 | }; | 61 | }; |
62 | 62 | ||
63 | struct AddressBook::Iterator::IteratorData | 63 | struct AddressBook::Iterator::IteratorData |
64 | { | 64 | { |
65 | Addressee::List::Iterator mIt; | 65 | Addressee::List::Iterator mIt; |
66 | }; | 66 | }; |
67 | 67 | ||
68 | struct AddressBook::ConstIterator::ConstIteratorData | 68 | struct AddressBook::ConstIterator::ConstIteratorData |
69 | { | 69 | { |
70 | Addressee::List::ConstIterator mIt; | 70 | Addressee::List::ConstIterator mIt; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | AddressBook::Iterator::Iterator() | 73 | AddressBook::Iterator::Iterator() |
74 | { | 74 | { |
75 | d = new IteratorData; | 75 | d = new IteratorData; |
76 | } | 76 | } |
77 | 77 | ||
78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 78 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
79 | { | 79 | { |
80 | d = new IteratorData; | 80 | d = new IteratorData; |
81 | d->mIt = i.d->mIt; | 81 | d->mIt = i.d->mIt; |
82 | } | 82 | } |
83 | 83 | ||
84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 84 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
85 | { | 85 | { |
86 | if( this == &i ) return *this; // guard against self assignment | 86 | if( this == &i ) return *this; // guard against self assignment |
87 | delete d; // delete the old data the Iterator was completely constructed before | 87 | delete d; // delete the old data the Iterator was completely constructed before |
88 | d = new IteratorData; | 88 | d = new IteratorData; |
89 | d->mIt = i.d->mIt; | 89 | d->mIt = i.d->mIt; |
90 | return *this; | 90 | return *this; |
91 | } | 91 | } |
92 | 92 | ||
93 | AddressBook::Iterator::~Iterator() | 93 | AddressBook::Iterator::~Iterator() |
94 | { | 94 | { |
95 | delete d; | 95 | delete d; |
96 | } | 96 | } |
97 | 97 | ||
98 | const Addressee &AddressBook::Iterator::operator*() const | 98 | const Addressee &AddressBook::Iterator::operator*() const |
99 | { | 99 | { |
100 | return *(d->mIt); | 100 | return *(d->mIt); |
101 | } | 101 | } |
102 | 102 | ||
103 | Addressee &AddressBook::Iterator::operator*() | 103 | Addressee &AddressBook::Iterator::operator*() |
104 | { | 104 | { |
105 | return *(d->mIt); | 105 | return *(d->mIt); |
106 | } | 106 | } |
107 | 107 | ||
108 | Addressee *AddressBook::Iterator::operator->() | 108 | Addressee *AddressBook::Iterator::operator->() |
109 | { | 109 | { |
110 | return &(*(d->mIt)); | 110 | return &(*(d->mIt)); |
111 | } | 111 | } |
112 | 112 | ||
113 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 113 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
114 | { | 114 | { |
115 | (d->mIt)++; | 115 | (d->mIt)++; |
116 | return *this; | 116 | return *this; |
117 | } | 117 | } |
118 | 118 | ||
119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 119 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
120 | { | 120 | { |
121 | (d->mIt)++; | 121 | (d->mIt)++; |
122 | return *this; | 122 | return *this; |
123 | } | 123 | } |
124 | 124 | ||
125 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 125 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
126 | { | 126 | { |
127 | (d->mIt)--; | 127 | (d->mIt)--; |
128 | return *this; | 128 | return *this; |
129 | } | 129 | } |
130 | 130 | ||
131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 131 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
132 | { | 132 | { |
133 | (d->mIt)--; | 133 | (d->mIt)--; |
134 | return *this; | 134 | return *this; |
135 | } | 135 | } |
136 | 136 | ||
137 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 137 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
138 | { | 138 | { |
139 | return ( d->mIt == it.d->mIt ); | 139 | return ( d->mIt == it.d->mIt ); |
140 | } | 140 | } |
141 | 141 | ||
142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 142 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
143 | { | 143 | { |
144 | return ( d->mIt != it.d->mIt ); | 144 | return ( d->mIt != it.d->mIt ); |
145 | } | 145 | } |
146 | 146 | ||
147 | 147 | ||
148 | AddressBook::ConstIterator::ConstIterator() | 148 | AddressBook::ConstIterator::ConstIterator() |
149 | { | 149 | { |
150 | d = new ConstIteratorData; | 150 | d = new ConstIteratorData; |
151 | } | 151 | } |
152 | 152 | ||
153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 153 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
154 | { | 154 | { |
155 | d = new ConstIteratorData; | 155 | d = new ConstIteratorData; |
156 | d->mIt = i.d->mIt; | 156 | d->mIt = i.d->mIt; |
157 | } | 157 | } |
158 | 158 | ||
159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 159 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
160 | { | 160 | { |
161 | if( this == &i ) return *this; // guard for self assignment | 161 | if( this == &i ) return *this; // guard for self assignment |
162 | delete d; // delete the old data because the Iterator was really constructed before | 162 | delete d; // delete the old data because the Iterator was really constructed before |
163 | d = new ConstIteratorData; | 163 | d = new ConstIteratorData; |
164 | d->mIt = i.d->mIt; | 164 | d->mIt = i.d->mIt; |
165 | return *this; | 165 | return *this; |
166 | } | 166 | } |
167 | 167 | ||
168 | AddressBook::ConstIterator::~ConstIterator() | 168 | AddressBook::ConstIterator::~ConstIterator() |
169 | { | 169 | { |
170 | delete d; | 170 | delete d; |
171 | } | 171 | } |
172 | 172 | ||
173 | const Addressee &AddressBook::ConstIterator::operator*() const | 173 | const Addressee &AddressBook::ConstIterator::operator*() const |
174 | { | 174 | { |
175 | return *(d->mIt); | 175 | return *(d->mIt); |
176 | } | 176 | } |
177 | 177 | ||
178 | const Addressee* AddressBook::ConstIterator::operator->() const | 178 | const Addressee* AddressBook::ConstIterator::operator->() const |
179 | { | 179 | { |
180 | return &(*(d->mIt)); | 180 | return &(*(d->mIt)); |
181 | } | 181 | } |
182 | 182 | ||
183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 183 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
184 | { | 184 | { |
185 | (d->mIt)++; | 185 | (d->mIt)++; |
186 | return *this; | 186 | return *this; |
187 | } | 187 | } |
188 | 188 | ||
189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 189 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
190 | { | 190 | { |
191 | (d->mIt)++; | 191 | (d->mIt)++; |
192 | return *this; | 192 | return *this; |
193 | } | 193 | } |
194 | 194 | ||
195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 195 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
196 | { | 196 | { |
197 | (d->mIt)--; | 197 | (d->mIt)--; |
198 | return *this; | 198 | return *this; |
199 | } | 199 | } |
200 | 200 | ||
201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 201 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
202 | { | 202 | { |
203 | (d->mIt)--; | 203 | (d->mIt)--; |
204 | return *this; | 204 | return *this; |
205 | } | 205 | } |
206 | 206 | ||
207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 207 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
208 | { | 208 | { |
209 | return ( d->mIt == it.d->mIt ); | 209 | return ( d->mIt == it.d->mIt ); |
210 | } | 210 | } |
211 | 211 | ||
212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 212 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
213 | { | 213 | { |
214 | return ( d->mIt != it.d->mIt ); | 214 | return ( d->mIt != it.d->mIt ); |
215 | } | 215 | } |
216 | 216 | ||
217 | 217 | ||
218 | AddressBook::AddressBook() | 218 | AddressBook::AddressBook() |
219 | { | 219 | { |
220 | init(0, "contact"); | 220 | init(0, "contact"); |
221 | } | 221 | } |
222 | 222 | ||
223 | AddressBook::AddressBook( const QString &config ) | 223 | AddressBook::AddressBook( const QString &config ) |
224 | { | 224 | { |
225 | init(config, "contact"); | 225 | init(config, "contact"); |
226 | } | 226 | } |
227 | 227 | ||
228 | AddressBook::AddressBook( const QString &config, const QString &family ) | 228 | AddressBook::AddressBook( const QString &config, const QString &family ) |
229 | { | 229 | { |
230 | init(config, family); | 230 | init(config, family); |
231 | 231 | ||
232 | } | 232 | } |
233 | 233 | ||
234 | // the default family is "contact" | 234 | // the default family is "contact" |
235 | void AddressBook::init(const QString &config, const QString &family ) | 235 | void AddressBook::init(const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | blockLSEchange = false; | 237 | blockLSEchange = false; |
238 | d = new AddressBookData; | 238 | d = new AddressBookData; |
239 | QString fami = family; | 239 | QString fami = family; |
240 | qDebug("new ab "); | 240 | qDebug("new ab "); |
241 | if (config != 0) { | 241 | if (config != 0) { |
242 | qDebug("config != 0 "); | 242 | qDebug("config != 0 "); |
243 | if ( family == "syncContact" ) { | 243 | if ( family == "syncContact" ) { |
244 | qDebug("creating sync config "); | 244 | qDebug("creating sync config "); |
245 | fami = "contact"; | 245 | fami = "contact"; |
246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 246 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
247 | con->setGroup( "General" ); | 247 | con->setGroup( "General" ); |
248 | con->writeEntry( "ResourceKeys", QString("sync") ); | 248 | con->writeEntry( "ResourceKeys", QString("sync") ); |
249 | con->writeEntry( "Standard", QString("sync") ); | 249 | con->writeEntry( "Standard", QString("sync") ); |
250 | con->setGroup( "Resource_sync" ); | 250 | con->setGroup( "Resource_sync" ); |
251 | con->writeEntry( "FileName", config ); | 251 | con->writeEntry( "FileName", config ); |
252 | con->writeEntry( "FileFormat", QString("vcard") ); | 252 | con->writeEntry( "FileFormat", QString("vcard") ); |
253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 253 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
254 | con->writeEntry( "ResourceName", QString("sync_res") ); | 254 | con->writeEntry( "ResourceName", QString("sync_res") ); |
255 | if ( config.right(4) == ".xml" ) | 255 | if ( config.right(4) == ".xml" ) |
256 | con->writeEntry( "ResourceType", QString("qtopia") ); | 256 | con->writeEntry( "ResourceType", QString("qtopia") ); |
257 | else | 257 | else |
258 | con->writeEntry( "ResourceType", QString("file") ); | 258 | con->writeEntry( "ResourceType", QString("file") ); |
259 | //con->sync(); | 259 | //con->sync(); |
260 | d->mConfig = con; | 260 | d->mConfig = con; |
261 | } | 261 | } |
262 | else | 262 | else |
263 | d->mConfig = new KConfig( locateLocal("config", config) ); | 263 | d->mConfig = new KConfig( locateLocal("config", config) ); |
264 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 264 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
265 | } | 265 | } |
266 | else { | 266 | else { |
267 | d->mConfig = 0; | 267 | d->mConfig = 0; |
268 | // qDebug("AddressBook::init 1 config=0"); | 268 | // qDebug("AddressBook::init 1 config=0"); |
269 | } | 269 | } |
270 | 270 | ||
271 | //US d->mErrorHandler = 0; | 271 | //US d->mErrorHandler = 0; |
272 | d->mManager = new KRES::Manager<Resource>( fami, false ); | 272 | d->mManager = new KRES::Manager<Resource>( fami, false ); |
273 | d->mManager->readConfig( d->mConfig ); | 273 | d->mManager->readConfig( d->mConfig ); |
274 | if ( family == "syncContact" ) { | 274 | if ( family == "syncContact" ) { |
275 | KRES::Manager<Resource> *manager = d->mManager; | 275 | KRES::Manager<Resource> *manager = d->mManager; |
276 | KRES::Manager<Resource>::ActiveIterator it; | 276 | KRES::Manager<Resource>::ActiveIterator it; |
277 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 277 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
278 | (*it)->setAddressBook( this ); | 278 | (*it)->setAddressBook( this ); |
279 | if ( !(*it)->open() ) | 279 | if ( !(*it)->open() ) |
280 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 280 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
281 | } | 281 | } |
282 | Resource *res = standardResource(); | 282 | Resource *res = standardResource(); |
283 | if ( !res ) { | 283 | if ( !res ) { |
284 | qDebug("ERROR: no standard resource"); | 284 | qDebug("ERROR: no standard resource"); |
285 | res = manager->createResource( "file" ); | 285 | res = manager->createResource( "file" ); |
286 | if ( res ) | 286 | if ( res ) |
287 | { | 287 | { |
288 | addResource( res ); | 288 | addResource( res ); |
289 | } | 289 | } |
290 | else | 290 | else |
291 | qDebug(" No resource available!!!"); | 291 | qDebug(" No resource available!!!"); |
292 | } | 292 | } |
293 | setStandardResource( res ); | 293 | setStandardResource( res ); |
294 | manager->writeConfig(); | 294 | manager->writeConfig(); |
295 | } | 295 | } |
296 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 296 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
297 | "X-Department", "KADDRESSBOOK" ); | 297 | "X-Department", "KADDRESSBOOK" ); |
298 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 298 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
299 | "X-Profession", "KADDRESSBOOK" ); | 299 | "X-Profession", "KADDRESSBOOK" ); |
300 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 300 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
301 | "X-AssistantsName", "KADDRESSBOOK" ); | 301 | "X-AssistantsName", "KADDRESSBOOK" ); |
302 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 302 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
303 | "X-ManagersName", "KADDRESSBOOK" ); | 303 | "X-ManagersName", "KADDRESSBOOK" ); |
304 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 304 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
305 | "X-SpousesName", "KADDRESSBOOK" ); | 305 | "X-SpousesName", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 306 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
307 | "X-Office", "KADDRESSBOOK" ); | 307 | "X-Office", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 308 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
309 | "X-IMAddress", "KADDRESSBOOK" ); | 309 | "X-IMAddress", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 310 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
311 | "X-Anniversary", "KADDRESSBOOK" ); | 311 | "X-Anniversary", "KADDRESSBOOK" ); |
312 | 312 | ||
313 | //US added this field to become compatible with Opie/qtopia addressbook | 313 | //US added this field to become compatible with Opie/qtopia addressbook |
314 | // values can be "female" or "male" or "". An empty field represents undefined. | 314 | // values can be "female" or "male" or "". An empty field represents undefined. |
315 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 315 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
316 | "X-Gender", "KADDRESSBOOK" ); | 316 | "X-Gender", "KADDRESSBOOK" ); |
317 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 317 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
318 | "X-Children", "KADDRESSBOOK" ); | 318 | "X-Children", "KADDRESSBOOK" ); |
319 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 319 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
320 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 320 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
321 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 321 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
322 | "X-ExternalID", "KADDRESSBOOK" ); | 322 | "X-ExternalID", "KADDRESSBOOK" ); |
323 | } | 323 | } |
324 | 324 | ||
325 | AddressBook::~AddressBook() | 325 | AddressBook::~AddressBook() |
326 | { | 326 | { |
327 | delete d->mConfig; d->mConfig = 0; | 327 | delete d->mConfig; d->mConfig = 0; |
328 | delete d->mManager; d->mManager = 0; | 328 | delete d->mManager; d->mManager = 0; |
329 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 329 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
330 | delete d; d = 0; | 330 | delete d; d = 0; |
331 | } | 331 | } |
332 | 332 | ||
333 | bool AddressBook::load() | 333 | bool AddressBook::load() |
334 | { | 334 | { |
335 | 335 | ||
336 | 336 | ||
337 | clear(); | 337 | clear(); |
338 | 338 | ||
339 | KRES::Manager<Resource>::ActiveIterator it; | 339 | KRES::Manager<Resource>::ActiveIterator it; |
340 | bool ok = true; | 340 | bool ok = true; |
341 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 341 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
342 | if ( !(*it)->load() ) { | 342 | if ( !(*it)->load() ) { |
343 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 343 | error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
344 | ok = false; | 344 | ok = false; |
345 | } | 345 | } |
346 | 346 | ||
347 | // mark all addressees as unchanged | 347 | // mark all addressees as unchanged |
348 | Addressee::List::Iterator addrIt; | 348 | Addressee::List::Iterator addrIt; |
349 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 349 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
350 | (*addrIt).setChanged( false ); | 350 | (*addrIt).setChanged( false ); |
351 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 351 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
352 | if ( !id.isEmpty() ) { | 352 | if ( !id.isEmpty() ) { |
353 | //qDebug("setId aa %s ", id.latin1()); | 353 | //qDebug("setId aa %s ", id.latin1()); |
354 | (*addrIt).setIDStr(id ); | 354 | (*addrIt).setIDStr(id ); |
355 | } | 355 | } |
356 | } | 356 | } |
357 | blockLSEchange = true; | 357 | blockLSEchange = true; |
358 | return ok; | 358 | return ok; |
359 | } | 359 | } |
360 | 360 | ||
361 | bool AddressBook::save( Ticket *ticket ) | 361 | bool AddressBook::save( Ticket *ticket ) |
362 | { | 362 | { |
363 | kdDebug(5700) << "AddressBook::save()"<< endl; | 363 | kdDebug(5700) << "AddressBook::save()"<< endl; |
364 | 364 | ||
365 | if ( ticket->resource() ) { | 365 | if ( ticket->resource() ) { |
366 | deleteRemovedAddressees(); | 366 | deleteRemovedAddressees(); |
367 | return ticket->resource()->save( ticket ); | 367 | return ticket->resource()->save( ticket ); |
368 | } | 368 | } |
369 | 369 | ||
370 | return false; | 370 | return false; |
371 | } | 371 | } |
372 | bool AddressBook::saveAB() | 372 | bool AddressBook::saveAB() |
373 | { | 373 | { |
374 | bool ok = true; | 374 | bool ok = true; |
375 | 375 | ||
376 | deleteRemovedAddressees(); | 376 | deleteRemovedAddressees(); |
377 | Iterator ait; | 377 | Iterator ait; |
378 | for ( ait = begin(); ait != end(); ++ait ) { | 378 | for ( ait = begin(); ait != end(); ++ait ) { |
379 | if ( !(*ait).IDStr().isEmpty() ) { | 379 | if ( !(*ait).IDStr().isEmpty() ) { |
380 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 380 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
381 | } | 381 | } |
382 | } | 382 | } |
383 | KRES::Manager<Resource>::ActiveIterator it; | 383 | KRES::Manager<Resource>::ActiveIterator it; |
384 | KRES::Manager<Resource> *manager = d->mManager; | 384 | KRES::Manager<Resource> *manager = d->mManager; |
385 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 385 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
386 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 386 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
387 | Ticket *ticket = requestSaveTicket( *it ); | 387 | Ticket *ticket = requestSaveTicket( *it ); |
388 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 388 | // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
389 | if ( !ticket ) { | 389 | if ( !ticket ) { |
390 | error( i18n( "Unable to save to resource '%1'. It is locked." ) | 390 | error( i18n( "Unable to save to resource '%1'. It is locked." ) |
391 | .arg( (*it)->resourceName() ) ); | 391 | .arg( (*it)->resourceName() ) ); |
392 | return false; | 392 | return false; |
393 | } | 393 | } |
394 | 394 | ||
395 | //if ( !save( ticket ) ) | 395 | //if ( !save( ticket ) ) |
396 | if ( ticket->resource() ) { | 396 | if ( ticket->resource() ) { |
397 | if ( ! ticket->resource()->save( ticket ) ) | 397 | if ( ! ticket->resource()->save( ticket ) ) |
398 | ok = false; | 398 | ok = false; |
399 | } else | 399 | } else |
400 | ok = false; | 400 | ok = false; |
401 | 401 | ||
402 | } | 402 | } |
403 | } | 403 | } |
404 | return ok; | 404 | return ok; |
405 | } | 405 | } |
406 | 406 | ||
407 | AddressBook::Iterator AddressBook::begin() | 407 | AddressBook::Iterator AddressBook::begin() |
408 | { | 408 | { |
409 | Iterator it = Iterator(); | 409 | Iterator it = Iterator(); |
410 | it.d->mIt = d->mAddressees.begin(); | 410 | it.d->mIt = d->mAddressees.begin(); |
411 | return it; | 411 | return it; |
412 | } | 412 | } |
413 | 413 | ||
414 | AddressBook::ConstIterator AddressBook::begin() const | 414 | AddressBook::ConstIterator AddressBook::begin() const |
415 | { | 415 | { |
416 | ConstIterator it = ConstIterator(); | 416 | ConstIterator it = ConstIterator(); |
417 | it.d->mIt = d->mAddressees.begin(); | 417 | it.d->mIt = d->mAddressees.begin(); |
418 | return it; | 418 | return it; |
419 | } | 419 | } |
420 | 420 | ||
421 | AddressBook::Iterator AddressBook::end() | 421 | AddressBook::Iterator AddressBook::end() |
422 | { | 422 | { |
423 | Iterator it = Iterator(); | 423 | Iterator it = Iterator(); |
424 | it.d->mIt = d->mAddressees.end(); | 424 | it.d->mIt = d->mAddressees.end(); |
425 | return it; | 425 | return it; |
426 | } | 426 | } |
427 | 427 | ||
428 | AddressBook::ConstIterator AddressBook::end() const | 428 | AddressBook::ConstIterator AddressBook::end() const |
429 | { | 429 | { |
430 | ConstIterator it = ConstIterator(); | 430 | ConstIterator it = ConstIterator(); |
431 | it.d->mIt = d->mAddressees.end(); | 431 | it.d->mIt = d->mAddressees.end(); |
432 | return it; | 432 | return it; |
433 | } | 433 | } |
434 | 434 | ||
435 | void AddressBook::clear() | 435 | void AddressBook::clear() |
436 | { | 436 | { |
437 | d->mAddressees.clear(); | 437 | d->mAddressees.clear(); |
438 | } | 438 | } |
439 | 439 | ||
440 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 440 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
441 | { | 441 | { |
442 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 442 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
443 | 443 | ||
444 | if ( !resource ) | 444 | if ( !resource ) |
445 | { | 445 | { |
446 | qDebug("AddressBook::requestSaveTicket no resource" ); | 446 | qDebug("AddressBook::requestSaveTicket no resource" ); |
447 | resource = standardResource(); | 447 | resource = standardResource(); |
448 | } | 448 | } |
449 | 449 | ||
450 | KRES::Manager<Resource>::ActiveIterator it; | 450 | KRES::Manager<Resource>::ActiveIterator it; |
451 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 451 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
452 | if ( (*it) == resource ) { | 452 | if ( (*it) == resource ) { |
453 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 453 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
454 | return 0; | 454 | return 0; |
455 | else | 455 | else |
456 | return (*it)->requestSaveTicket(); | 456 | return (*it)->requestSaveTicket(); |
457 | } | 457 | } |
458 | } | 458 | } |
459 | 459 | ||
460 | return 0; | 460 | return 0; |
461 | } | 461 | } |
462 | 462 | ||
463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) | 463 | void AddressBook::insertAddressee( const Addressee &a, bool setRev ) |
464 | { | 464 | { |
465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 465 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
466 | //qDebug("block insert "); | 466 | //qDebug("block insert "); |
467 | return; | 467 | return; |
468 | } | 468 | } |
469 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 469 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
470 | bool found = false; | 470 | bool found = false; |
471 | Addressee::List::Iterator it; | 471 | Addressee::List::Iterator it; |
472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 472 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
473 | if ( a.uid() == (*it).uid() ) { | 473 | if ( a.uid() == (*it).uid() ) { |
474 | 474 | ||
475 | bool changed = false; | 475 | bool changed = false; |
476 | Addressee addr = a; | 476 | Addressee addr = a; |
477 | if ( addr != (*it) ) | 477 | if ( addr != (*it) ) |
478 | changed = true; | 478 | changed = true; |
479 | 479 | ||
480 | (*it) = a; | 480 | (*it) = a; |
481 | if ( (*it).resource() == 0 ) | 481 | if ( (*it).resource() == 0 ) |
482 | (*it).setResource( standardResource() ); | 482 | (*it).setResource( standardResource() ); |
483 | 483 | ||
484 | if ( changed ) { | 484 | if ( changed ) { |
485 | if ( setRev ) { | 485 | if ( setRev ) { |
486 | 486 | ||
487 | // get rid of micro seconds | 487 | // get rid of micro seconds |
488 | QDateTime dt = QDateTime::currentDateTime(); | 488 | QDateTime dt = QDateTime::currentDateTime(); |
489 | QTime t = dt.time(); | 489 | QTime t = dt.time(); |
490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); | 490 | dt.setTime( QTime (t.hour (), t.minute (), t.second () ) ); |
491 | (*it).setRevision( dt ); | 491 | (*it).setRevision( dt ); |
492 | } | 492 | } |
493 | (*it).setChanged( true ); | 493 | (*it).setChanged( true ); |
494 | } | 494 | } |
495 | 495 | ||
496 | found = true; | 496 | found = true; |
497 | } else { | 497 | } else { |
498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 498 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
499 | QString name = (*it).uid().mid( 19 ); | 499 | QString name = (*it).uid().mid( 19 ); |
500 | Addressee b = a; | 500 | Addressee b = a; |
501 | QString id = b.getID( name ); | 501 | QString id = b.getID( name ); |
502 | if ( ! id.isEmpty() ) { | 502 | if ( ! id.isEmpty() ) { |
503 | QString des = (*it).note(); | 503 | QString des = (*it).note(); |
504 | int startN; | 504 | int startN; |
505 | if( (startN = des.find( id ) ) >= 0 ) { | 505 | if( (startN = des.find( id ) ) >= 0 ) { |
506 | int endN = des.find( ",", startN+1 ); | 506 | int endN = des.find( ",", startN+1 ); |
507 | des = des.left( startN ) + des.mid( endN+1 ); | 507 | des = des.left( startN ) + des.mid( endN+1 ); |
508 | (*it).setNote( des ); | 508 | (*it).setNote( des ); |
509 | } | 509 | } |
510 | } | 510 | } |
511 | } | 511 | } |
512 | } | 512 | } |
513 | } | 513 | } |
514 | if ( found ) | 514 | if ( found ) |
515 | return; | 515 | return; |
516 | d->mAddressees.append( a ); | 516 | d->mAddressees.append( a ); |
517 | Addressee& addr = d->mAddressees.last(); | 517 | Addressee& addr = d->mAddressees.last(); |
518 | if ( addr.resource() == 0 ) | 518 | if ( addr.resource() == 0 ) |
519 | addr.setResource( standardResource() ); | 519 | addr.setResource( standardResource() ); |
520 | 520 | ||
521 | addr.setChanged( true ); | 521 | addr.setChanged( true ); |
522 | } | 522 | } |
523 | 523 | ||
524 | void AddressBook::removeAddressee( const Addressee &a ) | 524 | void AddressBook::removeAddressee( const Addressee &a ) |
525 | { | 525 | { |
526 | Iterator it; | 526 | Iterator it; |
527 | Iterator it2; | 527 | Iterator it2; |
528 | bool found = false; | 528 | bool found = false; |
529 | for ( it = begin(); it != end(); ++it ) { | 529 | for ( it = begin(); it != end(); ++it ) { |
530 | if ( a.uid() == (*it).uid() ) { | 530 | if ( a.uid() == (*it).uid() ) { |
531 | found = true; | 531 | found = true; |
532 | it2 = it; | 532 | it2 = it; |
533 | } else { | 533 | } else { |
534 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 534 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
535 | QString name = (*it).uid().mid( 19 ); | 535 | QString name = (*it).uid().mid( 19 ); |
536 | Addressee b = a; | 536 | Addressee b = a; |
537 | QString id = b.getID( name ); | 537 | QString id = b.getID( name ); |
538 | if ( ! id.isEmpty() ) { | 538 | if ( ! id.isEmpty() ) { |
539 | QString des = (*it).note(); | 539 | QString des = (*it).note(); |
540 | if( des.find( id ) < 0 ) { | 540 | if( des.find( id ) < 0 ) { |
541 | des += id + ","; | 541 | des += id + ","; |
542 | (*it).setNote( des ); | 542 | (*it).setNote( des ); |
543 | } | 543 | } |
544 | } | 544 | } |
545 | } | 545 | } |
546 | 546 | ||
547 | } | 547 | } |
548 | } | 548 | } |
549 | 549 | ||
550 | if ( found ) | 550 | if ( found ) |
551 | removeAddressee( it2 ); | 551 | removeAddressee( it2 ); |
552 | 552 | ||
553 | } | 553 | } |
554 | 554 | ||
555 | void AddressBook::removeDeletedAddressees() | 555 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
556 | { | 556 | { |
557 | deleteRemovedAddressees(); | ||
558 | Iterator it = begin(); | 557 | Iterator it = begin(); |
559 | Iterator it2 ; | 558 | Iterator it2 ; |
560 | QDateTime dt ( QDate( 2004,1,1) ); | 559 | QDateTime dt ( QDate( 2004,1,1) ); |
561 | while ( it != end() ) { | 560 | while ( it != end() ) { |
562 | (*it).setRevision( dt ); | 561 | (*it).setRevision( dt ); |
563 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 562 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
564 | (*it).setIDStr(""); | 563 | (*it).setIDStr(""); |
565 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE || (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 564 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
566 | it2 = it; | 565 | it2 = it; |
567 | //qDebug("removing %s ",(*it).uid().latin1() ); | 566 | //qDebug("removing %s ",(*it).uid().latin1() ); |
568 | ++it; | 567 | ++it; |
569 | removeAddressee( it2 ); | 568 | removeAddressee( it2 ); |
570 | } else { | 569 | } else { |
571 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 570 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
572 | ++it; | 571 | ++it; |
573 | } | 572 | } |
574 | } | 573 | } |
575 | deleteRemovedAddressees(); | 574 | deleteRemovedAddressees(); |
576 | } | 575 | } |
577 | 576 | ||
578 | void AddressBook::removeAddressee( const Iterator &it ) | 577 | void AddressBook::removeAddressee( const Iterator &it ) |
579 | { | 578 | { |
580 | d->mRemovedAddressees.append( (*it) ); | 579 | d->mRemovedAddressees.append( (*it) ); |
581 | d->mAddressees.remove( it.d->mIt ); | 580 | d->mAddressees.remove( it.d->mIt ); |
582 | } | 581 | } |
583 | 582 | ||
584 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 583 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
585 | { | 584 | { |
586 | Iterator it; | 585 | Iterator it; |
587 | for ( it = begin(); it != end(); ++it ) { | 586 | for ( it = begin(); it != end(); ++it ) { |
588 | if ( a.uid() == (*it).uid() ) { | 587 | if ( a.uid() == (*it).uid() ) { |
589 | return it; | 588 | return it; |
590 | } | 589 | } |
591 | } | 590 | } |
592 | return end(); | 591 | return end(); |
593 | } | 592 | } |
594 | 593 | ||
595 | Addressee AddressBook::findByUid( const QString &uid ) | 594 | Addressee AddressBook::findByUid( const QString &uid ) |
596 | { | 595 | { |
597 | Iterator it; | 596 | Iterator it; |
598 | for ( it = begin(); it != end(); ++it ) { | 597 | for ( it = begin(); it != end(); ++it ) { |
599 | if ( uid == (*it).uid() ) { | 598 | if ( uid == (*it).uid() ) { |
600 | return *it; | 599 | return *it; |
601 | } | 600 | } |
602 | } | 601 | } |
603 | return Addressee(); | 602 | return Addressee(); |
604 | } | 603 | } |
605 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) | 604 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd ) |
606 | { | 605 | { |
607 | qDebug("AddressBook::preExternSync "); | 606 | qDebug("AddressBook::preExternSync "); |
608 | AddressBook::Iterator it; | 607 | AddressBook::Iterator it; |
609 | for ( it = begin(); it != end(); ++it ) { | 608 | for ( it = begin(); it != end(); ++it ) { |
610 | (*it).setID( csd, (*it).externalUID() ); | 609 | (*it).setID( csd, (*it).externalUID() ); |
611 | (*it).computeCsum( csd ); | 610 | (*it).computeCsum( csd ); |
612 | } | 611 | } |
613 | mergeAB( aBook ,csd ); | 612 | mergeAB( aBook ,csd ); |
614 | } | 613 | } |
615 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) | 614 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd) |
616 | { | 615 | { |
617 | qDebug("AddressBook::postExternSync "); | 616 | qDebug("AddressBook::postExternSync "); |
618 | AddressBook::Iterator it; | 617 | AddressBook::Iterator it; |
619 | for ( it = begin(); it != end(); ++it ) { | 618 | for ( it = begin(); it != end(); ++it ) { |
619 | qDebug("check uid %s ", (*it).uid().latin1() ); | ||
620 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 620 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
621 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { | 621 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM ) { |
622 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 622 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
623 | if ( ad.isEmpty() ) { | 623 | if ( ad.isEmpty() ) { |
624 | qDebug("ERROR ad empty "); | 624 | qDebug("postExternSync:ERROR addressee is empty: %s ", (*it).uid().latin1()); |
625 | } else { | 625 | } else { |
626 | (*it).computeCsum( csd ); | 626 | (*it).computeCsum( csd ); |
627 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 627 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
628 | ad.setID( csd, (*it).externalUID() ); | 628 | ad.setID( csd, (*it).externalUID() ); |
629 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 629 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
630 | aBook->insertAddressee( ad ); | 630 | aBook->insertAddressee( ad ); |
631 | } | 631 | } |
632 | } | 632 | } |
633 | } | 633 | } |
634 | } | 634 | } |
635 | 635 | ||
636 | 636 | bool AddressBook::containsExternalUid( const QString& uid ) | |
637 | { | ||
638 | Iterator it; | ||
639 | for ( it = begin(); it != end(); ++it ) { | ||
640 | if ( uid == (*it).externalUID( ) ) | ||
641 | return true; | ||
642 | } | ||
643 | return false; | ||
644 | } | ||
637 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) | 645 | Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) |
638 | { | 646 | { |
639 | Iterator it; | 647 | Iterator it; |
640 | for ( it = begin(); it != end(); ++it ) { | 648 | for ( it = begin(); it != end(); ++it ) { |
641 | if ( uid == (*it).getID( profile ) ) | 649 | if ( uid == (*it).getID( profile ) ) |
642 | return (*it); | 650 | return (*it); |
643 | } | 651 | } |
644 | return Addressee(); | 652 | return Addressee(); |
645 | } | 653 | } |
646 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) | 654 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile ) |
647 | { | 655 | { |
648 | Iterator it; | 656 | Iterator it; |
649 | Addressee ad; | 657 | Addressee ad; |
650 | for ( it = begin(); it != end(); ++it ) { | 658 | for ( it = begin(); it != end(); ++it ) { |
651 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 659 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
652 | if ( !ad.isEmpty() ) { | 660 | if ( !ad.isEmpty() ) { |
653 | (*it).mergeContact( ad ); | 661 | (*it).mergeContact( ad ); |
654 | } | 662 | } |
655 | } | 663 | } |
664 | #if 0 | ||
665 | // test only | ||
666 | for ( it = begin(); it != end(); ++it ) { | ||
667 | |||
668 | qDebug("uid %s ", (*it).uid().latin1()); | ||
669 | } | ||
670 | #endif | ||
656 | } | 671 | } |
657 | 672 | ||
658 | #if 0 | 673 | #if 0 |
659 | Addressee::List AddressBook::getExternLastSyncAddressees() | 674 | Addressee::List AddressBook::getExternLastSyncAddressees() |
660 | { | 675 | { |
661 | Addressee::List results; | 676 | Addressee::List results; |
662 | 677 | ||
663 | Iterator it; | 678 | Iterator it; |
664 | for ( it = begin(); it != end(); ++it ) { | 679 | for ( it = begin(); it != end(); ++it ) { |
665 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 680 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
666 | if ( (*it).familyName().left(4) == "!E: " ) | 681 | if ( (*it).familyName().left(4) == "!E: " ) |
667 | results.append( *it ); | 682 | results.append( *it ); |
668 | } | 683 | } |
669 | } | 684 | } |
670 | 685 | ||
671 | return results; | 686 | return results; |
672 | } | 687 | } |
673 | #endif | 688 | #endif |
674 | void AddressBook::resetTempSyncStat() | 689 | void AddressBook::resetTempSyncStat() |
675 | { | 690 | { |
676 | Iterator it; | 691 | Iterator it; |
677 | for ( it = begin(); it != end(); ++it ) { | 692 | for ( it = begin(); it != end(); ++it ) { |
678 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 693 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
679 | } | 694 | } |
680 | 695 | ||
681 | } | 696 | } |
682 | 697 | ||
683 | QStringList AddressBook:: uidList() | 698 | QStringList AddressBook:: uidList() |
684 | { | 699 | { |
685 | QStringList results; | 700 | QStringList results; |
686 | Iterator it; | 701 | Iterator it; |
687 | for ( it = begin(); it != end(); ++it ) { | 702 | for ( it = begin(); it != end(); ++it ) { |
688 | results.append( (*it).uid() ); | 703 | results.append( (*it).uid() ); |
689 | } | 704 | } |
690 | return results; | 705 | return results; |
691 | } | 706 | } |
692 | 707 | ||
693 | 708 | ||
694 | Addressee::List AddressBook::allAddressees() | 709 | Addressee::List AddressBook::allAddressees() |
695 | { | 710 | { |
696 | return d->mAddressees; | 711 | return d->mAddressees; |
697 | 712 | ||
698 | } | 713 | } |
699 | 714 | ||
700 | Addressee::List AddressBook::findByName( const QString &name ) | 715 | Addressee::List AddressBook::findByName( const QString &name ) |
701 | { | 716 | { |
702 | Addressee::List results; | 717 | Addressee::List results; |
703 | 718 | ||
704 | Iterator it; | 719 | Iterator it; |
705 | for ( it = begin(); it != end(); ++it ) { | 720 | for ( it = begin(); it != end(); ++it ) { |
706 | if ( name == (*it).realName() ) { | 721 | if ( name == (*it).realName() ) { |
707 | results.append( *it ); | 722 | results.append( *it ); |
708 | } | 723 | } |
709 | } | 724 | } |
710 | 725 | ||
711 | return results; | 726 | return results; |
712 | } | 727 | } |
713 | 728 | ||
714 | Addressee::List AddressBook::findByEmail( const QString &email ) | 729 | Addressee::List AddressBook::findByEmail( const QString &email ) |
715 | { | 730 | { |
716 | Addressee::List results; | 731 | Addressee::List results; |
717 | QStringList mailList; | 732 | QStringList mailList; |
718 | 733 | ||
719 | Iterator it; | 734 | Iterator it; |
720 | for ( it = begin(); it != end(); ++it ) { | 735 | for ( it = begin(); it != end(); ++it ) { |
721 | mailList = (*it).emails(); | 736 | mailList = (*it).emails(); |
722 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 737 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
723 | if ( email == (*ite) ) { | 738 | if ( email == (*ite) ) { |
724 | results.append( *it ); | 739 | results.append( *it ); |
725 | } | 740 | } |
726 | } | 741 | } |
727 | } | 742 | } |
728 | 743 | ||
729 | return results; | 744 | return results; |
730 | } | 745 | } |
731 | 746 | ||
732 | Addressee::List AddressBook::findByCategory( const QString &category ) | 747 | Addressee::List AddressBook::findByCategory( const QString &category ) |
733 | { | 748 | { |
734 | Addressee::List results; | 749 | Addressee::List results; |
735 | 750 | ||
736 | Iterator it; | 751 | Iterator it; |
737 | for ( it = begin(); it != end(); ++it ) { | 752 | for ( it = begin(); it != end(); ++it ) { |
738 | if ( (*it).hasCategory( category) ) { | 753 | if ( (*it).hasCategory( category) ) { |
739 | results.append( *it ); | 754 | results.append( *it ); |
740 | } | 755 | } |
741 | } | 756 | } |
742 | 757 | ||
743 | return results; | 758 | return results; |
744 | } | 759 | } |
745 | 760 | ||
746 | void AddressBook::dump() const | 761 | void AddressBook::dump() const |
747 | { | 762 | { |
748 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 763 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
749 | 764 | ||
750 | ConstIterator it; | 765 | ConstIterator it; |
751 | for( it = begin(); it != end(); ++it ) { | 766 | for( it = begin(); it != end(); ++it ) { |
752 | (*it).dump(); | 767 | (*it).dump(); |
753 | } | 768 | } |
754 | 769 | ||
755 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 770 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
756 | } | 771 | } |
757 | 772 | ||
758 | QString AddressBook::identifier() | 773 | QString AddressBook::identifier() |
759 | { | 774 | { |
760 | QStringList identifier; | 775 | QStringList identifier; |
761 | 776 | ||
762 | 777 | ||
763 | KRES::Manager<Resource>::ActiveIterator it; | 778 | KRES::Manager<Resource>::ActiveIterator it; |
764 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 779 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
765 | if ( !(*it)->identifier().isEmpty() ) | 780 | if ( !(*it)->identifier().isEmpty() ) |
766 | identifier.append( (*it)->identifier() ); | 781 | identifier.append( (*it)->identifier() ); |
767 | } | 782 | } |
768 | 783 | ||
769 | return identifier.join( ":" ); | 784 | return identifier.join( ":" ); |
770 | } | 785 | } |
771 | 786 | ||
772 | Field::List AddressBook::fields( int category ) | 787 | Field::List AddressBook::fields( int category ) |
773 | { | 788 | { |
774 | if ( d->mAllFields.isEmpty() ) { | 789 | if ( d->mAllFields.isEmpty() ) { |
775 | d->mAllFields = Field::allFields(); | 790 | d->mAllFields = Field::allFields(); |
776 | } | 791 | } |
777 | 792 | ||
778 | if ( category == Field::All ) return d->mAllFields; | 793 | if ( category == Field::All ) return d->mAllFields; |
779 | 794 | ||
780 | Field::List result; | 795 | Field::List result; |
781 | Field::List::ConstIterator it; | 796 | Field::List::ConstIterator it; |
782 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 797 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
783 | if ( (*it)->category() & category ) result.append( *it ); | 798 | if ( (*it)->category() & category ) result.append( *it ); |
784 | } | 799 | } |
785 | 800 | ||
786 | return result; | 801 | return result; |
787 | } | 802 | } |
788 | 803 | ||
789 | bool AddressBook::addCustomField( const QString &label, int category, | 804 | bool AddressBook::addCustomField( const QString &label, int category, |
790 | const QString &key, const QString &app ) | 805 | const QString &key, const QString &app ) |
791 | { | 806 | { |
792 | if ( d->mAllFields.isEmpty() ) { | 807 | if ( d->mAllFields.isEmpty() ) { |
793 | d->mAllFields = Field::allFields(); | 808 | d->mAllFields = Field::allFields(); |
794 | } | 809 | } |
795 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 810 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
796 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 811 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
797 | 812 | ||
798 | QString k = key.isNull() ? label : key; | 813 | QString k = key.isNull() ? label : key; |
799 | 814 | ||
800 | Field *field = Field::createCustomField( label, category, k, a ); | 815 | Field *field = Field::createCustomField( label, category, k, a ); |
801 | 816 | ||
802 | if ( !field ) return false; | 817 | if ( !field ) return false; |
803 | 818 | ||
804 | d->mAllFields.append( field ); | 819 | d->mAllFields.append( field ); |
805 | 820 | ||
806 | return true; | 821 | return true; |
807 | } | 822 | } |
808 | 823 | ||
809 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 824 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
810 | { | 825 | { |
811 | if (!ab.d) return s; | 826 | if (!ab.d) return s; |
812 | 827 | ||
813 | return s << ab.d->mAddressees; | 828 | return s << ab.d->mAddressees; |
814 | } | 829 | } |
815 | 830 | ||
816 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 831 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
817 | { | 832 | { |
818 | if (!ab.d) return s; | 833 | if (!ab.d) return s; |
819 | 834 | ||
820 | s >> ab.d->mAddressees; | 835 | s >> ab.d->mAddressees; |
821 | 836 | ||
822 | return s; | 837 | return s; |
823 | } | 838 | } |
824 | 839 | ||
825 | bool AddressBook::addResource( Resource *resource ) | 840 | bool AddressBook::addResource( Resource *resource ) |
826 | { | 841 | { |
827 | if ( !resource->open() ) { | 842 | if ( !resource->open() ) { |
828 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 843 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
829 | return false; | 844 | return false; |
830 | } | 845 | } |
831 | 846 | ||
832 | resource->setAddressBook( this ); | 847 | resource->setAddressBook( this ); |
833 | 848 | ||
834 | d->mManager->add( resource ); | 849 | d->mManager->add( resource ); |
835 | return true; | 850 | return true; |
836 | } | 851 | } |
837 | 852 | ||
838 | bool AddressBook::removeResource( Resource *resource ) | 853 | bool AddressBook::removeResource( Resource *resource ) |
839 | { | 854 | { |
840 | resource->close(); | 855 | resource->close(); |
841 | 856 | ||
842 | if ( resource == standardResource() ) | 857 | if ( resource == standardResource() ) |
843 | d->mManager->setStandardResource( 0 ); | 858 | d->mManager->setStandardResource( 0 ); |
844 | 859 | ||
845 | resource->setAddressBook( 0 ); | 860 | resource->setAddressBook( 0 ); |
846 | 861 | ||
847 | d->mManager->remove( resource ); | 862 | d->mManager->remove( resource ); |
848 | return true; | 863 | return true; |
849 | } | 864 | } |
850 | 865 | ||
851 | QPtrList<Resource> AddressBook::resources() | 866 | QPtrList<Resource> AddressBook::resources() |
852 | { | 867 | { |
853 | QPtrList<Resource> list; | 868 | QPtrList<Resource> list; |
854 | 869 | ||
855 | // qDebug("AddressBook::resources() 1"); | 870 | // qDebug("AddressBook::resources() 1"); |
856 | 871 | ||
857 | KRES::Manager<Resource>::ActiveIterator it; | 872 | KRES::Manager<Resource>::ActiveIterator it; |
858 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 873 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
859 | list.append( *it ); | 874 | list.append( *it ); |
860 | 875 | ||
861 | return list; | 876 | return list; |
862 | } | 877 | } |
863 | 878 | ||
864 | /*US | 879 | /*US |
865 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 880 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
866 | { | 881 | { |
867 | delete d->mErrorHandler; | 882 | delete d->mErrorHandler; |
868 | d->mErrorHandler = handler; | 883 | d->mErrorHandler = handler; |
869 | } | 884 | } |
870 | */ | 885 | */ |
871 | 886 | ||
872 | void AddressBook::error( const QString& msg ) | 887 | void AddressBook::error( const QString& msg ) |
873 | { | 888 | { |
874 | /*US | 889 | /*US |
875 | if ( !d->mErrorHandler ) // create default error handler | 890 | if ( !d->mErrorHandler ) // create default error handler |
876 | d->mErrorHandler = new ConsoleErrorHandler; | 891 | d->mErrorHandler = new ConsoleErrorHandler; |
877 | 892 | ||
878 | if ( d->mErrorHandler ) | 893 | if ( d->mErrorHandler ) |
879 | d->mErrorHandler->error( msg ); | 894 | d->mErrorHandler->error( msg ); |
880 | else | 895 | else |
881 | kdError(5700) << "no error handler defined" << endl; | 896 | kdError(5700) << "no error handler defined" << endl; |
882 | */ | 897 | */ |
883 | kdDebug(5700) << "msg" << endl; | 898 | kdDebug(5700) << "msg" << endl; |
884 | qDebug(msg); | 899 | qDebug(msg); |
885 | } | 900 | } |
886 | 901 | ||
887 | void AddressBook::deleteRemovedAddressees() | 902 | void AddressBook::deleteRemovedAddressees() |
888 | { | 903 | { |
889 | Addressee::List::Iterator it; | 904 | Addressee::List::Iterator it; |
890 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 905 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
891 | Resource *resource = (*it).resource(); | 906 | Resource *resource = (*it).resource(); |
892 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 907 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
893 | resource->removeAddressee( *it ); | 908 | resource->removeAddressee( *it ); |
894 | } | 909 | } |
895 | 910 | ||
896 | d->mRemovedAddressees.clear(); | 911 | d->mRemovedAddressees.clear(); |
897 | } | 912 | } |
898 | 913 | ||
899 | void AddressBook::setStandardResource( Resource *resource ) | 914 | void AddressBook::setStandardResource( Resource *resource ) |
900 | { | 915 | { |
901 | // qDebug("AddressBook::setStandardResource 1"); | 916 | // qDebug("AddressBook::setStandardResource 1"); |
902 | d->mManager->setStandardResource( resource ); | 917 | d->mManager->setStandardResource( resource ); |
903 | } | 918 | } |
904 | 919 | ||
905 | Resource *AddressBook::standardResource() | 920 | Resource *AddressBook::standardResource() |
906 | { | 921 | { |
907 | return d->mManager->standardResource(); | 922 | return d->mManager->standardResource(); |
908 | } | 923 | } |
909 | 924 | ||
910 | KRES::Manager<Resource> *AddressBook::resourceManager() | 925 | KRES::Manager<Resource> *AddressBook::resourceManager() |
911 | { | 926 | { |
912 | return d->mManager; | 927 | return d->mManager; |
913 | } | 928 | } |
914 | 929 | ||
915 | void AddressBook::cleanUp() | 930 | void AddressBook::cleanUp() |
916 | { | 931 | { |
917 | KRES::Manager<Resource>::ActiveIterator it; | 932 | KRES::Manager<Resource>::ActiveIterator it; |
918 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 933 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
919 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 934 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
920 | (*it)->cleanUp(); | 935 | (*it)->cleanUp(); |
921 | } | 936 | } |
922 | } | 937 | } |
diff --git a/kabc/addressbook.h b/kabc/addressbook.h index 157dc56..8f62f0d 100644 --- a/kabc/addressbook.h +++ b/kabc/addressbook.h | |||
@@ -1,339 +1,340 @@ | |||
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 | ||
146 | /** | 146 | /** |
147 | Returns a iterator for first entry of address book. | 147 | Returns a iterator for first entry of address book. |
148 | */ | 148 | */ |
149 | Iterator begin(); | 149 | Iterator begin(); |
150 | 150 | ||
151 | /** | 151 | /** |
152 | Returns a const iterator for first entry of address book. | 152 | Returns a const iterator for first entry of address book. |
153 | */ | 153 | */ |
154 | ConstIterator begin() const; | 154 | ConstIterator begin() const; |
155 | 155 | ||
156 | /** | 156 | /** |
157 | Returns a iterator for first entry of address book. | 157 | Returns a iterator for first entry of address book. |
158 | */ | 158 | */ |
159 | Iterator end(); | 159 | Iterator end(); |
160 | 160 | ||
161 | /** | 161 | /** |
162 | Returns a const iterator for first entry of address book. | 162 | Returns a const iterator for first entry of address book. |
163 | */ | 163 | */ |
164 | ConstIterator end() const; | 164 | ConstIterator end() const; |
165 | 165 | ||
166 | /** | 166 | /** |
167 | Removes all entries from address book. | 167 | Removes all entries from address book. |
168 | */ | 168 | */ |
169 | void clear(); | 169 | void clear(); |
170 | 170 | ||
171 | /** | 171 | /** |
172 | Insert an Addressee object into address book. If an object with the same | 172 | 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 | 173 | 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. | 174 | one. If not the new object is appended to the address book. |
175 | */ | 175 | */ |
176 | void insertAddressee( const Addressee &, bool setRev = true ); | 176 | void insertAddressee( const Addressee &, bool setRev = true ); |
177 | 177 | ||
178 | /** | 178 | /** |
179 | Removes entry from the address book. | 179 | Removes entry from the address book. |
180 | */ | 180 | */ |
181 | void removeAddressee( const Addressee & ); | 181 | void removeAddressee( const Addressee & ); |
182 | 182 | ||
183 | /** | 183 | /** |
184 | This is like @ref removeAddressee() just above, with the difference that | 184 | This is like @ref removeAddressee() just above, with the difference that |
185 | the first element is a iterator, returned by @ref begin(). | 185 | the first element is a iterator, returned by @ref begin(). |
186 | */ | 186 | */ |
187 | void removeAddressee( const Iterator & ); | 187 | void removeAddressee( const Iterator & ); |
188 | 188 | ||
189 | /** | 189 | /** |
190 | Find the specified entry in address book. Returns end(), if the entry | 190 | Find the specified entry in address book. Returns end(), if the entry |
191 | couldn't be found. | 191 | couldn't be found. |
192 | */ | 192 | */ |
193 | Iterator find( const Addressee & ); | 193 | Iterator find( const Addressee & ); |
194 | 194 | ||
195 | /** | 195 | /** |
196 | Find the entry specified by an unique id. Returns an empty Addressee | 196 | 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. | 197 | object, if the address book does not contain an entry with this id. |
198 | */ | 198 | */ |
199 | Addressee findByUid( const QString & ); | 199 | Addressee findByUid( const QString & ); |
200 | 200 | ||
201 | 201 | ||
202 | /** | 202 | /** |
203 | Returns a list of all addressees in the address book. This list can | 203 | Returns a list of all addressees in the address book. This list can |
204 | be sorted with @ref KABC::AddresseeList for example. | 204 | be sorted with @ref KABC::AddresseeList for example. |
205 | */ | 205 | */ |
206 | Addressee::List allAddressees(); | 206 | Addressee::List allAddressees(); |
207 | 207 | ||
208 | /** | 208 | /** |
209 | Find all entries with the specified name in the address book. Returns | 209 | Find all entries with the specified name in the address book. Returns |
210 | an empty list, if no entries could be found. | 210 | an empty list, if no entries could be found. |
211 | */ | 211 | */ |
212 | Addressee::List findByName( const QString & ); | 212 | Addressee::List findByName( const QString & ); |
213 | 213 | ||
214 | /** | 214 | /** |
215 | Find all entries with the specified email address in the address book. | 215 | Find all entries with the specified email address in the address book. |
216 | Returns an empty list, if no entries could be found. | 216 | Returns an empty list, if no entries could be found. |
217 | */ | 217 | */ |
218 | Addressee::List findByEmail( const QString & ); | 218 | Addressee::List findByEmail( const QString & ); |
219 | 219 | ||
220 | /** | 220 | /** |
221 | Find all entries wich have the specified category in the address book. | 221 | Find all entries wich have the specified category in the address book. |
222 | Returns an empty list, if no entries could be found. | 222 | Returns an empty list, if no entries could be found. |
223 | */ | 223 | */ |
224 | Addressee::List findByCategory( const QString & ); | 224 | Addressee::List findByCategory( const QString & ); |
225 | 225 | ||
226 | /** | 226 | /** |
227 | Return a string identifying this addressbook. | 227 | Return a string identifying this addressbook. |
228 | */ | 228 | */ |
229 | virtual QString identifier(); | 229 | virtual QString identifier(); |
230 | 230 | ||
231 | /** | 231 | /** |
232 | Used for debug output. | 232 | Used for debug output. |
233 | */ | 233 | */ |
234 | void dump() const; | 234 | void dump() const; |
235 | 235 | ||
236 | void emitAddressBookLocked() { emit addressBookLocked( this ); } | 236 | void emitAddressBookLocked() { emit addressBookLocked( this ); } |
237 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } | 237 | void emitAddressBookUnlocked() { emit addressBookUnlocked( this ); } |
238 | void emitAddressBookChanged() { emit addressBookChanged( this ); } | 238 | void emitAddressBookChanged() { emit addressBookChanged( this ); } |
239 | 239 | ||
240 | /** | 240 | /** |
241 | Return list of all Fields known to the address book which are associated | 241 | Return list of all Fields known to the address book which are associated |
242 | with the given field category. | 242 | with the given field category. |
243 | */ | 243 | */ |
244 | Field::List fields( int category = Field::All ); | 244 | Field::List fields( int category = Field::All ); |
245 | 245 | ||
246 | /** | 246 | /** |
247 | Add custom field to address book. | 247 | Add custom field to address book. |
248 | 248 | ||
249 | @param label User visible label of the field. | 249 | @param label User visible label of the field. |
250 | @param category Ored list of field categories. | 250 | @param category Ored list of field categories. |
251 | @param key Identifier used as key for reading and writing the field. | 251 | @param key Identifier used as key for reading and writing the field. |
252 | @param app String used as application key for reading and writing | 252 | @param app String used as application key for reading and writing |
253 | the field. | 253 | the field. |
254 | */ | 254 | */ |
255 | bool addCustomField( const QString &label, int category = Field::All, | 255 | bool addCustomField( const QString &label, int category = Field::All, |
256 | const QString &key = QString::null, | 256 | const QString &key = QString::null, |
257 | const QString &app = QString::null ); | 257 | const QString &app = QString::null ); |
258 | 258 | ||
259 | 259 | ||
260 | /** | 260 | /** |
261 | Add address book resource. | 261 | Add address book resource. |
262 | */ | 262 | */ |
263 | bool addResource( Resource * ); | 263 | bool addResource( Resource * ); |
264 | 264 | ||
265 | /** | 265 | /** |
266 | Remove address book resource. | 266 | Remove address book resource. |
267 | */ | 267 | */ |
268 | bool removeResource( Resource * ); | 268 | bool removeResource( Resource * ); |
269 | 269 | ||
270 | /** | 270 | /** |
271 | Return pointer list of all resources. | 271 | Return pointer list of all resources. |
272 | */ | 272 | */ |
273 | QPtrList<Resource> resources(); | 273 | QPtrList<Resource> resources(); |
274 | 274 | ||
275 | /** | 275 | /** |
276 | Set the @p ErrorHandler, that is used by @ref error() to | 276 | Set the @p ErrorHandler, that is used by @ref error() to |
277 | provide gui-independend error messages. | 277 | provide gui-independend error messages. |
278 | */ | 278 | */ |
279 | void setErrorHandler( ErrorHandler * ); | 279 | void setErrorHandler( ErrorHandler * ); |
280 | 280 | ||
281 | /** | 281 | /** |
282 | Shows gui independend error messages. | 282 | Shows gui independend error messages. |
283 | */ | 283 | */ |
284 | void error( const QString& ); | 284 | void error( const QString& ); |
285 | 285 | ||
286 | /** | 286 | /** |
287 | Query all resources to clean up their lock files | 287 | Query all resources to clean up their lock files |
288 | */ | 288 | */ |
289 | void cleanUp(); | 289 | void cleanUp(); |
290 | 290 | ||
291 | // sync stuff | 291 | // sync stuff |
292 | //Addressee::List getExternLastSyncAddressees(); | 292 | //Addressee::List getExternLastSyncAddressees(); |
293 | void resetTempSyncStat(); | 293 | void resetTempSyncStat(); |
294 | QStringList uidList(); | 294 | QStringList uidList(); |
295 | void removeDeletedAddressees(); | 295 | void removeSyncAddressees( bool removeDeleted = false ); |
296 | void mergeAB( AddressBook *aBook, const QString& profile ); | 296 | void mergeAB( AddressBook *aBook, const QString& profile ); |
297 | Addressee findByExternUid( const QString& uid , const QString& profile ); | 297 | Addressee findByExternUid( const QString& uid , const QString& profile ); |
298 | bool containsExternalUid( const QString& uid ); | ||
298 | 299 | ||
299 | void preExternSync( AddressBook* aBook, const QString& csd ); | 300 | void preExternSync( AddressBook* aBook, const QString& csd ); |
300 | void postExternSync( AddressBook* aBook, const QString& csd ); | 301 | void postExternSync( AddressBook* aBook, const QString& csd ); |
301 | signals: | 302 | signals: |
302 | /** | 303 | /** |
303 | Emitted, when the address book has changed on disk. | 304 | Emitted, when the address book has changed on disk. |
304 | */ | 305 | */ |
305 | void addressBookChanged( AddressBook * ); | 306 | void addressBookChanged( AddressBook * ); |
306 | 307 | ||
307 | /** | 308 | /** |
308 | Emitted, when the address book has been locked for writing. | 309 | Emitted, when the address book has been locked for writing. |
309 | */ | 310 | */ |
310 | void addressBookLocked( AddressBook * ); | 311 | void addressBookLocked( AddressBook * ); |
311 | 312 | ||
312 | /** | 313 | /** |
313 | Emitted, when the address book has been unlocked. | 314 | Emitted, when the address book has been unlocked. |
314 | */ | 315 | */ |
315 | void addressBookUnlocked( AddressBook * ); | 316 | void addressBookUnlocked( AddressBook * ); |
316 | 317 | ||
317 | protected: | 318 | protected: |
318 | void deleteRemovedAddressees(); | 319 | void deleteRemovedAddressees(); |
319 | void setStandardResource( Resource * ); | 320 | void setStandardResource( Resource * ); |
320 | Resource *standardResource(); | 321 | Resource *standardResource(); |
321 | KRES::Manager<Resource> *resourceManager(); | 322 | KRES::Manager<Resource> *resourceManager(); |
322 | 323 | ||
323 | void init(const QString &config, const QString &family); | 324 | void init(const QString &config, const QString &family); |
324 | 325 | ||
325 | private: | 326 | private: |
326 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 | 327 | //US QPtrList<Resource> mDummy; // Remove in KDE 4 |
327 | 328 | ||
328 | 329 | ||
329 | struct AddressBookData; | 330 | struct AddressBookData; |
330 | AddressBookData *d; | 331 | AddressBookData *d; |
331 | bool blockLSEchange; | 332 | bool blockLSEchange; |
332 | }; | 333 | }; |
333 | 334 | ||
334 | QDataStream &operator<<( QDataStream &, const AddressBook & ); | 335 | QDataStream &operator<<( QDataStream &, const AddressBook & ); |
335 | QDataStream &operator>>( QDataStream &, AddressBook & ); | 336 | QDataStream &operator>>( QDataStream &, AddressBook & ); |
336 | 337 | ||
337 | } | 338 | } |
338 | 339 | ||
339 | #endif | 340 | #endif |
diff --git a/kabc/addressee.cpp b/kabc/addressee.cpp index fda62f1..e241281 100644 --- a/kabc/addressee.cpp +++ b/kabc/addressee.cpp | |||
@@ -1,1161 +1,1165 @@ | |||
1 | /*** Warning! This file has been generated by the script makeaddressee ***/ | 1 | /*** Warning! This file has been generated by the script makeaddressee ***/ |
2 | /* | 2 | /* |
3 | This file is part of libkabc. | 3 | This file is part of libkabc. |
4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 4 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
5 | 5 | ||
6 | This library is free software; you can redistribute it and/or | 6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public | 7 | modify it under the terms of the GNU Library General Public |
8 | License as published by the Free Software Foundation; either | 8 | License as published by the Free Software Foundation; either |
9 | version 2 of the License, or (at your option) any later version. | 9 | version 2 of the License, or (at your option) any later version. |
10 | 10 | ||
11 | This library is distributed in the hope that it will be useful, | 11 | This library is distributed in the hope that it will be useful, |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 | Library General Public License for more details. | 14 | Library General Public License for more details. |
15 | 15 | ||
16 | You should have received a copy of the GNU Library General Public License | 16 | You should have received a copy of the GNU Library General Public License |
17 | along with this library; see the file COPYING.LIB. If not, write to | 17 | along with this library; see the file COPYING.LIB. If not, write to |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. | 19 | Boston, MA 02111-1307, USA. |
20 | */ | 20 | */ |
21 | 21 | ||
22 | /* | 22 | /* |
23 | Enhanced Version of the file for platform independent KDE tools. | 23 | Enhanced Version of the file for platform independent KDE tools. |
24 | Copyright (c) 2004 Ulf Schenk | 24 | Copyright (c) 2004 Ulf Schenk |
25 | 25 | ||
26 | $Id$ | 26 | $Id$ |
27 | */ | 27 | */ |
28 | 28 | ||
29 | #include <kconfig.h> | 29 | #include <kconfig.h> |
30 | 30 | ||
31 | #include <ksharedptr.h> | 31 | #include <ksharedptr.h> |
32 | #include <kdebug.h> | 32 | #include <kdebug.h> |
33 | #include <kapplication.h> | 33 | #include <kapplication.h> |
34 | #include <klocale.h> | 34 | #include <klocale.h> |
35 | #include <kidmanager.h> | 35 | #include <kidmanager.h> |
36 | //US | 36 | //US |
37 | #include <kstandarddirs.h> | 37 | #include <kstandarddirs.h> |
38 | #include <libkcal/syncdefines.h> | 38 | #include <libkcal/syncdefines.h> |
39 | 39 | ||
40 | //US #include "resource.h" | 40 | //US #include "resource.h" |
41 | #include "addressee.h" | 41 | #include "addressee.h" |
42 | 42 | ||
43 | using namespace KABC; | 43 | using namespace KABC; |
44 | 44 | ||
45 | static bool matchBinaryPattern( int value, int pattern ); | 45 | static bool matchBinaryPattern( int value, int pattern ); |
46 | 46 | ||
47 | struct Addressee::AddresseeData : public KShared | 47 | struct Addressee::AddresseeData : public KShared |
48 | { | 48 | { |
49 | QString uid; | 49 | QString uid; |
50 | QString name; | 50 | QString name; |
51 | QString formattedName; | 51 | QString formattedName; |
52 | QString familyName; | 52 | QString familyName; |
53 | QString givenName; | 53 | QString givenName; |
54 | QString additionalName; | 54 | QString additionalName; |
55 | QString prefix; | 55 | QString prefix; |
56 | QString suffix; | 56 | QString suffix; |
57 | QString nickName; | 57 | QString nickName; |
58 | QDateTime birthday; | 58 | QDateTime birthday; |
59 | QString mailer; | 59 | QString mailer; |
60 | TimeZone timeZone; | 60 | TimeZone timeZone; |
61 | Geo geo; | 61 | Geo geo; |
62 | QString title; | 62 | QString title; |
63 | QString role; | 63 | QString role; |
64 | QString organization; | 64 | QString organization; |
65 | QString note; | 65 | QString note; |
66 | QString productId; | 66 | QString productId; |
67 | QDateTime revision; | 67 | QDateTime revision; |
68 | QString sortString; | 68 | QString sortString; |
69 | QString externalUID; | 69 | QString externalUID; |
70 | QString originalExternalUID; | 70 | QString originalExternalUID; |
71 | KURL url; | 71 | KURL url; |
72 | Secrecy secrecy; | 72 | Secrecy secrecy; |
73 | Picture logo; | 73 | Picture logo; |
74 | Picture photo; | 74 | Picture photo; |
75 | Sound sound; | 75 | Sound sound; |
76 | Agent agent; | 76 | Agent agent; |
77 | QString mExternalId; | 77 | QString mExternalId; |
78 | PhoneNumber::List phoneNumbers; | 78 | PhoneNumber::List phoneNumbers; |
79 | Address::List addresses; | 79 | Address::List addresses; |
80 | Key::List keys; | 80 | Key::List keys; |
81 | QStringList emails; | 81 | QStringList emails; |
82 | QStringList categories; | 82 | QStringList categories; |
83 | QStringList custom; | 83 | QStringList custom; |
84 | int mTempSyncStat; | 84 | int mTempSyncStat; |
85 | Resource *resource; | 85 | Resource *resource; |
86 | 86 | ||
87 | bool empty :1; | 87 | bool empty :1; |
88 | bool changed :1; | 88 | bool changed :1; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | Addressee::Addressee() | 91 | Addressee::Addressee() |
92 | { | 92 | { |
93 | mData = new AddresseeData; | 93 | mData = new AddresseeData; |
94 | mData->empty = true; | 94 | mData->empty = true; |
95 | mData->changed = false; | 95 | mData->changed = false; |
96 | mData->resource = 0; | 96 | mData->resource = 0; |
97 | mData->mExternalId = ":"; | 97 | mData->mExternalId = ":"; |
98 | mData->revision = QDateTime ( QDate( 2004,1,1)); | 98 | mData->revision = QDateTime ( QDate( 2003,1,1)); |
99 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; | 99 | mData->mTempSyncStat = SYNC_TEMPSTATE_INITIAL; |
100 | } | 100 | } |
101 | 101 | ||
102 | Addressee::~Addressee() | 102 | Addressee::~Addressee() |
103 | { | 103 | { |
104 | } | 104 | } |
105 | 105 | ||
106 | Addressee::Addressee( const Addressee &a ) | 106 | Addressee::Addressee( const Addressee &a ) |
107 | { | 107 | { |
108 | mData = a.mData; | 108 | mData = a.mData; |
109 | } | 109 | } |
110 | 110 | ||
111 | Addressee &Addressee::operator=( const Addressee &a ) | 111 | Addressee &Addressee::operator=( const Addressee &a ) |
112 | { | 112 | { |
113 | mData = a.mData; | 113 | mData = a.mData; |
114 | return (*this); | 114 | return (*this); |
115 | } | 115 | } |
116 | 116 | ||
117 | Addressee Addressee::copy() | 117 | Addressee Addressee::copy() |
118 | { | 118 | { |
119 | Addressee a; | 119 | Addressee a; |
120 | *(a.mData) = *mData; | 120 | *(a.mData) = *mData; |
121 | return a; | 121 | return a; |
122 | } | 122 | } |
123 | 123 | ||
124 | void Addressee::detach() | 124 | void Addressee::detach() |
125 | { | 125 | { |
126 | if ( mData.count() == 1 ) return; | 126 | if ( mData.count() == 1 ) return; |
127 | *this = copy(); | 127 | *this = copy(); |
128 | } | 128 | } |
129 | 129 | ||
130 | bool Addressee::operator==( const Addressee &a ) const | 130 | bool Addressee::operator==( const Addressee &a ) const |
131 | { | 131 | { |
132 | if ( uid() != a.uid() ) return false; | 132 | if ( uid() != a.uid() ) return false; |
133 | if ( mData->name != a.mData->name ) return false; | 133 | if ( mData->name != a.mData->name ) return false; |
134 | if ( mData->formattedName != a.mData->formattedName ) return false; | 134 | if ( mData->formattedName != a.mData->formattedName ) return false; |
135 | if ( mData->familyName != a.mData->familyName ) return false; | 135 | if ( mData->familyName != a.mData->familyName ) return false; |
136 | if ( mData->givenName != a.mData->givenName ) return false; | 136 | if ( mData->givenName != a.mData->givenName ) return false; |
137 | if ( mData->additionalName != a.mData->additionalName ) return false; | 137 | if ( mData->additionalName != a.mData->additionalName ) return false; |
138 | if ( mData->prefix != a.mData->prefix ) return false; | 138 | if ( mData->prefix != a.mData->prefix ) return false; |
139 | if ( mData->suffix != a.mData->suffix ) return false; | 139 | if ( mData->suffix != a.mData->suffix ) return false; |
140 | if ( mData->nickName != a.mData->nickName ) return false; | 140 | if ( mData->nickName != a.mData->nickName ) return false; |
141 | if ( mData->birthday != a.mData->birthday ) return false; | 141 | if ( mData->birthday != a.mData->birthday ) return false; |
142 | if ( mData->mailer != a.mData->mailer ) return false; | 142 | if ( mData->mailer != a.mData->mailer ) return false; |
143 | if ( mData->timeZone != a.mData->timeZone ) return false; | 143 | if ( mData->timeZone != a.mData->timeZone ) return false; |
144 | if ( mData->geo != a.mData->geo ) return false; | 144 | if ( mData->geo != a.mData->geo ) return false; |
145 | if ( mData->title != a.mData->title ) return false; | 145 | if ( mData->title != a.mData->title ) return false; |
146 | if ( mData->role != a.mData->role ) return false; | 146 | if ( mData->role != a.mData->role ) return false; |
147 | if ( mData->organization != a.mData->organization ) return false; | 147 | if ( mData->organization != a.mData->organization ) return false; |
148 | if ( mData->note != a.mData->note ) return false; | 148 | if ( mData->note != a.mData->note ) return false; |
149 | if ( mData->productId != a.mData->productId ) return false; | 149 | if ( mData->productId != a.mData->productId ) return false; |
150 | //if ( mData->revision != a.mData->revision ) return false; | 150 | //if ( mData->revision != a.mData->revision ) return false; |
151 | if ( mData->sortString != a.mData->sortString ) return false; | 151 | if ( mData->sortString != a.mData->sortString ) return false; |
152 | if ( mData->secrecy != a.mData->secrecy ) return false; | 152 | if ( mData->secrecy != a.mData->secrecy ) return false; |
153 | if ( mData->logo != a.mData->logo ) return false; | 153 | if ( mData->logo != a.mData->logo ) return false; |
154 | if ( mData->photo != a.mData->photo ) return false; | 154 | if ( mData->photo != a.mData->photo ) return false; |
155 | if ( mData->sound != a.mData->sound ) return false; | 155 | if ( mData->sound != a.mData->sound ) return false; |
156 | if ( mData->agent != a.mData->agent ) return false; | 156 | if ( mData->agent != a.mData->agent ) return false; |
157 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && | 157 | if ( ( mData->url.isValid() || a.mData->url.isValid() ) && |
158 | ( mData->url != a.mData->url ) ) return false; | 158 | ( mData->url != a.mData->url ) ) return false; |
159 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; | 159 | if ( mData->phoneNumbers != a.mData->phoneNumbers ) return false; |
160 | if ( mData->addresses != a.mData->addresses ) return false; | 160 | if ( mData->addresses != a.mData->addresses ) return false; |
161 | if ( mData->keys != a.mData->keys ) return false; | 161 | if ( mData->keys != a.mData->keys ) return false; |
162 | if ( mData->emails != a.mData->emails ) return false; | 162 | if ( mData->emails != a.mData->emails ) return false; |
163 | if ( mData->categories != a.mData->categories ) return false; | 163 | if ( mData->categories != a.mData->categories ) return false; |
164 | if ( mData->custom != a.mData->custom ) return false; | 164 | if ( mData->custom != a.mData->custom ) return false; |
165 | 165 | ||
166 | return true; | 166 | return true; |
167 | } | 167 | } |
168 | 168 | ||
169 | bool Addressee::operator!=( const Addressee &a ) const | 169 | bool Addressee::operator!=( const Addressee &a ) const |
170 | { | 170 | { |
171 | return !( a == *this ); | 171 | return !( a == *this ); |
172 | } | 172 | } |
173 | 173 | ||
174 | bool Addressee::isEmpty() const | 174 | bool Addressee::isEmpty() const |
175 | { | 175 | { |
176 | return mData->empty; | 176 | return mData->empty; |
177 | } | 177 | } |
178 | ulong Addressee::getCsum4List( const QStringList & attList) | 178 | ulong Addressee::getCsum4List( const QStringList & attList) |
179 | { | 179 | { |
180 | int max = attList.count(); | 180 | int max = attList.count(); |
181 | ulong cSum = 0; | 181 | ulong cSum = 0; |
182 | int j,k,i; | 182 | int j,k,i; |
183 | int add; | 183 | int add; |
184 | for ( i = 0; i < max ; ++i ) { | 184 | for ( i = 0; i < max ; ++i ) { |
185 | QString s = attList[i]; | 185 | QString s = attList[i]; |
186 | if ( ! s.isEmpty() ){ | 186 | if ( ! s.isEmpty() ){ |
187 | j = s.length(); | 187 | j = s.length(); |
188 | for ( k = 0; k < j; ++k ) { | 188 | for ( k = 0; k < j; ++k ) { |
189 | int mul = k +1; | 189 | int mul = k +1; |
190 | add = s[k].unicode (); | 190 | add = s[k].unicode (); |
191 | if ( k < 16 ) | 191 | if ( k < 16 ) |
192 | mul = mul * mul; | 192 | mul = mul * mul; |
193 | int ii = i+1; | 193 | int ii = i+1; |
194 | add = add * mul *ii*ii*ii; | 194 | add = add * mul *ii*ii*ii; |
195 | cSum += add; | 195 | cSum += add; |
196 | } | 196 | } |
197 | } | 197 | } |
198 | 198 | ||
199 | } | 199 | } |
200 | //QString dump = attList.join(","); | 200 | //QString dump = attList.join(","); |
201 | //qDebug("csum: %d %s", cSum,dump.latin1()); | 201 | //qDebug("csum: %d %s", cSum,dump.latin1()); |
202 | 202 | ||
203 | return cSum; | 203 | return cSum; |
204 | 204 | ||
205 | } | 205 | } |
206 | void Addressee::computeCsum(const QString &dev) | 206 | void Addressee::computeCsum(const QString &dev) |
207 | { | 207 | { |
208 | QStringList l; | 208 | QStringList l; |
209 | if ( !mData->name.isEmpty() ) l.append(mData->name); | 209 | if ( !mData->name.isEmpty() ) l.append(mData->name); |
210 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); | 210 | if ( !mData->formattedName.isEmpty() ) l.append(mData->formattedName ); |
211 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); | 211 | if ( !mData->familyName.isEmpty() ) l.append( mData->familyName ); |
212 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); | 212 | if ( !mData->givenName.isEmpty() ) l.append(mData->givenName ); |
213 | if ( !mData->additionalName ) l.append( mData->additionalName ); | 213 | if ( !mData->additionalName ) l.append( mData->additionalName ); |
214 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); | 214 | if ( !mData->prefix.isEmpty() ) l.append( mData->prefix ); |
215 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); | 215 | if ( !mData->suffix.isEmpty() ) l.append( mData->suffix ); |
216 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); | 216 | if ( !mData->nickName.isEmpty() ) l.append( mData->nickName ); |
217 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); | 217 | if ( mData->birthday.isValid() ) l.append( mData->birthday.toString() ); |
218 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); | 218 | if ( !mData->mailer.isEmpty() ) l.append( mData->mailer ); |
219 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); | 219 | if ( mData->timeZone.isValid() ) l.append( mData->timeZone.asString() ); |
220 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); | 220 | if ( mData->geo.isValid() ) l.append( mData->geo.asString() ); |
221 | if ( !mData->title .isEmpty() ) l.append( mData->title ); | 221 | if ( !mData->title .isEmpty() ) l.append( mData->title ); |
222 | if ( !mData->role.isEmpty() ) l.append( mData->role ); | 222 | if ( !mData->role.isEmpty() ) l.append( mData->role ); |
223 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); | 223 | if ( !mData->organization.isEmpty() ) l.append( mData->organization ); |
224 | if ( !mData->note.isEmpty() ) l.append( mData->note ); | 224 | if ( !mData->note.isEmpty() ) l.append( mData->note ); |
225 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); | 225 | if ( !mData->productId.isEmpty() ) l.append(mData->productId ); |
226 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); | 226 | if ( !mData->sortString.isEmpty() ) l.append( mData->sortString ); |
227 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); | 227 | if ( mData->secrecy.isValid() ) l.append( mData->secrecy.asString()); |
228 | // if ( !mData->logo.isEmpty() ) l.append( ); | 228 | // if ( !mData->logo.isEmpty() ) l.append( ); |
229 | //if ( !mData->photo.isEmpty() ) l.append( ); | 229 | //if ( !mData->photo.isEmpty() ) l.append( ); |
230 | //if ( !mData->sound.isEmpty() ) l.append( ); | 230 | //if ( !mData->sound.isEmpty() ) l.append( ); |
231 | //if ( !mData->agent.isEmpty() ) l.append( ); | 231 | //if ( !mData->agent.isEmpty() ) l.append( ); |
232 | //if ( mData->url.isValid() ) l.append( ); | 232 | //if ( mData->url.isValid() ) l.append( ); |
233 | #if 0 | 233 | #if 0 |
234 | if ( !mData->phoneNumbers.isEmpty() ) l.append( ); | 234 | if ( !mData->phoneNumbers.isEmpty() ) l.append( ); |
235 | if ( !mData->addresses.isEmpty() ) l.append( ); | 235 | if ( !mData->addresses.isEmpty() ) l.append( ); |
236 | //if ( !mData->keys.isEmpty() ) l.append( ); | 236 | //if ( !mData->keys.isEmpty() ) l.append( ); |
237 | if ( !mData->emails.isEmpty() ) l.append( ); | 237 | if ( !mData->emails.isEmpty() ) l.append( ); |
238 | if ( !mData->categories .isEmpty() ) l.append( ); | 238 | if ( !mData->categories .isEmpty() ) l.append( ); |
239 | if ( !mData->custom.isEmpty() ) l.append( ); | 239 | if ( !mData->custom.isEmpty() ) l.append( ); |
240 | #endif | 240 | #endif |
241 | KABC::PhoneNumber::List phoneNumbers; | 241 | KABC::PhoneNumber::List phoneNumbers; |
242 | KABC::PhoneNumber::List::Iterator phoneIter; | 242 | KABC::PhoneNumber::List::Iterator phoneIter; |
243 | 243 | ||
244 | QStringList t; | 244 | QStringList t; |
245 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); | 245 | for ( phoneIter = mData->phoneNumbers.begin(); phoneIter != mData->phoneNumbers.end(); |
246 | ++phoneIter ) | 246 | ++phoneIter ) |
247 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); | 247 | t.append( ( *phoneIter ).number()+QString::number( ( *phoneIter ).type() ) ); |
248 | t.sort(); | 248 | t.sort(); |
249 | uint iii; | 249 | uint iii; |
250 | for ( iii = 0; iii < t.count(); ++iii) | 250 | for ( iii = 0; iii < t.count(); ++iii) |
251 | l.append( t[iii] ); | 251 | l.append( t[iii] ); |
252 | t = mData->emails; | 252 | t = mData->emails; |
253 | t.sort(); | 253 | t.sort(); |
254 | for ( iii = 0; iii < t.count(); ++iii) | 254 | for ( iii = 0; iii < t.count(); ++iii) |
255 | l.append( t[iii] ); | 255 | l.append( t[iii] ); |
256 | t = mData->categories; | 256 | t = mData->categories; |
257 | t.sort(); | 257 | t.sort(); |
258 | for ( iii = 0; iii < t.count(); ++iii) | 258 | for ( iii = 0; iii < t.count(); ++iii) |
259 | l.append( t[iii] ); | 259 | l.append( t[iii] ); |
260 | t = mData->custom; | 260 | t = mData->custom; |
261 | t.sort(); | 261 | t.sort(); |
262 | for ( iii = 0; iii < t.count(); ++iii) | 262 | for ( iii = 0; iii < t.count(); ++iii) |
263 | l.append( t[iii] ); | 263 | l.append( t[iii] ); |
264 | KABC::Address::List::Iterator addressIter; | 264 | KABC::Address::List::Iterator addressIter; |
265 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); | 265 | for ( addressIter = mData->addresses.begin(); addressIter != mData->addresses.end(); |
266 | ++addressIter ) { | 266 | ++addressIter ) { |
267 | t = (*addressIter).asList(); | 267 | t = (*addressIter).asList(); |
268 | t.sort(); | 268 | t.sort(); |
269 | for ( iii = 0; iii < t.count(); ++iii) | 269 | for ( iii = 0; iii < t.count(); ++iii) |
270 | l.append( t[iii] ); | 270 | l.append( t[iii] ); |
271 | } | 271 | } |
272 | uint cs = getCsum4List(l); | 272 | uint cs = getCsum4List(l); |
273 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); | 273 | // qDebug("CSUM computed %d %s %s", cs,QString::number (cs ).latin1(), uid().latin1() ); |
274 | setCsum( dev, QString::number (cs )); | 274 | setCsum( dev, QString::number (cs )); |
275 | } | 275 | } |
276 | 276 | ||
277 | void Addressee::mergeContact( const Addressee& ad ) | 277 | void Addressee::mergeContact( const Addressee& ad ) |
278 | { | 278 | { |
279 | 279 | ||
280 | detach(); | 280 | detach(); |
281 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; | 281 | if ( mData->name.isEmpty() ) mData->name = ad.mData->name; |
282 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; | 282 | if ( mData->formattedName.isEmpty() ) mData->formattedName = ad.mData->formattedName; |
283 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; | 283 | if ( mData->familyName.isEmpty() ) mData->familyName = ad.mData->familyName; |
284 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; | 284 | if ( mData->givenName.isEmpty() ) mData->givenName = ad.mData->givenName ; |
285 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; | 285 | if ( mData->additionalName ) mData->additionalName = ad.mData->additionalName; |
286 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; | 286 | if ( mData->prefix.isEmpty() ) mData->prefix = ad.mData->prefix; |
287 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; | 287 | if ( mData->suffix.isEmpty() ) mData->suffix = ad.mData->suffix; |
288 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; | 288 | if ( mData->nickName.isEmpty() ) mData->nickName = ad.mData->nickName; |
289 | if ( !mData->birthday.isValid() ) | 289 | if ( !mData->birthday.isValid() ) |
290 | if ( ad.mData->birthday.isValid()) | 290 | if ( ad.mData->birthday.isValid()) |
291 | mData->birthday = ad.mData->birthday; | 291 | mData->birthday = ad.mData->birthday; |
292 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; | 292 | if ( mData->mailer.isEmpty() ) mData->mailer = ad.mData->mailer; |
293 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; | 293 | if ( !mData->timeZone.isValid() ) mData->timeZone = ad.mData->timeZone; |
294 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; | 294 | if ( !mData->geo.isValid() ) mData->geo = ad.mData->geo; |
295 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; | 295 | if ( mData->title .isEmpty() ) mData->title = ad.mData->title ; |
296 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; | 296 | if ( mData->role.isEmpty() ) mData->role = ad.mData->role ; |
297 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; | 297 | if ( mData->organization.isEmpty() ) mData->organization = ad.mData->organization ; |
298 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; | 298 | if ( mData->note.isEmpty() ) mData->note = ad.mData->note ; |
299 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; | 299 | if ( mData->productId.isEmpty() ) mData->productId = ad.mData->productId; |
300 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; | 300 | if ( mData->sortString.isEmpty() ) mData->sortString = ad.mData->sortString; |
301 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; | 301 | if ( !mData->secrecy.isValid() ) mData->secrecy = ad.mData->secrecy; |
302 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; | 302 | if ( ( !mData->url.isValid() && ad.mData->url.isValid() ) ) mData->url = ad.mData->url ; |
303 | 303 | ||
304 | // pending: | 304 | // pending: |
305 | // merging phonenumbers | 305 | // merging phonenumbers |
306 | // merging addresses | 306 | // merging addresses |
307 | // merging emails; | 307 | // merging emails; |
308 | // merging categories; | 308 | // merging categories; |
309 | // merging custom; | 309 | // merging custom; |
310 | // merging keys | 310 | // merging keys |
311 | qDebug("merge contact %s ", ad.uid().latin1()); | ||
312 | setUid( ad.uid() ); | ||
311 | } | 313 | } |
312 | 314 | ||
313 | void Addressee::removeID(const QString &prof) | 315 | void Addressee::removeID(const QString &prof) |
314 | { | 316 | { |
315 | detach(); | 317 | detach(); |
316 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); | 318 | mData->mExternalId = KIdManager::removeId ( mData->mExternalId, prof); |
317 | 319 | ||
318 | } | 320 | } |
319 | void Addressee::setID( const QString & prof , const QString & id ) | 321 | void Addressee::setID( const QString & prof , const QString & id ) |
320 | { | 322 | { |
321 | detach(); | 323 | detach(); |
322 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); | 324 | mData->mExternalId = KIdManager::setId ( mData->mExternalId, prof, id ); |
323 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 325 | //qDebug("setID2 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
324 | } | 326 | } |
325 | void Addressee::setTempSyncStat( int id ) | 327 | void Addressee::setTempSyncStat( int id ) |
326 | { | 328 | { |
327 | if ( mData->mTempSyncStat == id ) return; | 329 | if ( mData->mTempSyncStat == id ) return; |
328 | detach(); | 330 | detach(); |
329 | mData->mTempSyncStat = id; | 331 | mData->mTempSyncStat = id; |
330 | } | 332 | } |
331 | int Addressee::tempSyncStat() const | 333 | int Addressee::tempSyncStat() const |
332 | { | 334 | { |
333 | return mData->mTempSyncStat; | 335 | return mData->mTempSyncStat; |
334 | } | 336 | } |
335 | 337 | ||
336 | QString Addressee::getID( const QString & prof) | 338 | QString Addressee::getID( const QString & prof) |
337 | { | 339 | { |
338 | return KIdManager::getId ( mData->mExternalId, prof ); | 340 | return KIdManager::getId ( mData->mExternalId, prof ); |
339 | } | 341 | } |
340 | 342 | ||
341 | void Addressee::setCsum( const QString & prof , const QString & id ) | 343 | void Addressee::setCsum( const QString & prof , const QString & id ) |
342 | { | 344 | { |
343 | detach(); | 345 | detach(); |
344 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); | 346 | //qDebug("setcsum1 %s %s %s",mData->mExternalId.latin1(), prof.latin1(), id.latin1() ); |
345 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); | 347 | mData->mExternalId = KIdManager::setCsum ( mData->mExternalId, prof, id ); |
346 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); | 348 | //qDebug("setcsum2 %s ",mData->mExternalId.latin1() ); |
347 | } | 349 | } |
348 | 350 | ||
349 | QString Addressee::getCsum( const QString & prof) | 351 | QString Addressee::getCsum( const QString & prof) |
350 | { | 352 | { |
351 | return KIdManager::getCsum ( mData->mExternalId, prof ); | 353 | return KIdManager::getCsum ( mData->mExternalId, prof ); |
352 | } | 354 | } |
353 | 355 | ||
354 | void Addressee::setIDStr( const QString & s ) | 356 | void Addressee::setIDStr( const QString & s ) |
355 | { | 357 | { |
356 | detach(); | 358 | detach(); |
357 | mData->mExternalId = s; | 359 | mData->mExternalId = s; |
358 | } | 360 | } |
359 | 361 | ||
360 | QString Addressee::IDStr() const | 362 | QString Addressee::IDStr() const |
361 | { | 363 | { |
362 | return mData->mExternalId; | 364 | return mData->mExternalId; |
363 | } | 365 | } |
364 | 366 | ||
365 | void Addressee::setExternalUID( const QString &id ) | 367 | void Addressee::setExternalUID( const QString &id ) |
366 | { | 368 | { |
367 | if ( id == mData->externalUID ) return; | 369 | if ( id == mData->externalUID ) return; |
368 | detach(); | 370 | detach(); |
369 | mData->empty = false; | 371 | mData->empty = false; |
370 | mData->externalUID = id; | 372 | mData->externalUID = id; |
371 | } | 373 | } |
372 | 374 | ||
373 | QString Addressee::externalUID() const | 375 | QString Addressee::externalUID() const |
374 | { | 376 | { |
375 | return mData->externalUID; | 377 | return mData->externalUID; |
376 | } | 378 | } |
377 | void Addressee::setOriginalExternalUID( const QString &id ) | 379 | void Addressee::setOriginalExternalUID( const QString &id ) |
378 | { | 380 | { |
379 | if ( id == mData->originalExternalUID ) return; | 381 | if ( id == mData->originalExternalUID ) return; |
380 | detach(); | 382 | detach(); |
381 | mData->empty = false; | 383 | mData->empty = false; |
384 | qDebug("*******Set orig uid %s ", id.latin1()); | ||
382 | mData->originalExternalUID = id; | 385 | mData->originalExternalUID = id; |
383 | } | 386 | } |
384 | 387 | ||
385 | QString Addressee::originalExternalUID() const | 388 | QString Addressee::originalExternalUID() const |
386 | { | 389 | { |
387 | return mData->originalExternalUID; | 390 | return mData->originalExternalUID; |
388 | } | 391 | } |
389 | 392 | ||
390 | void Addressee::setUid( const QString &id ) | 393 | void Addressee::setUid( const QString &id ) |
391 | { | 394 | { |
392 | if ( id == mData->uid ) return; | 395 | if ( id == mData->uid ) return; |
393 | detach(); | 396 | detach(); |
397 | qDebug("****setuid %s ", id.latin1()); | ||
394 | mData->empty = false; | 398 | mData->empty = false; |
395 | mData->uid = id; | 399 | mData->uid = id; |
396 | } | 400 | } |
397 | 401 | ||
398 | QString Addressee::uid() const | 402 | QString Addressee::uid() const |
399 | { | 403 | { |
400 | if ( mData->uid.isEmpty() ) | 404 | if ( mData->uid.isEmpty() ) |
401 | mData->uid = KApplication::randomString( 10 ); | 405 | mData->uid = KApplication::randomString( 10 ); |
402 | 406 | ||
403 | return mData->uid; | 407 | return mData->uid; |
404 | } | 408 | } |
405 | 409 | ||
406 | QString Addressee::uidLabel() | 410 | QString Addressee::uidLabel() |
407 | { | 411 | { |
408 | return i18n("Unique Identifier"); | 412 | return i18n("Unique Identifier"); |
409 | } | 413 | } |
410 | 414 | ||
411 | void Addressee::setName( const QString &name ) | 415 | void Addressee::setName( const QString &name ) |
412 | { | 416 | { |
413 | if ( name == mData->name ) return; | 417 | if ( name == mData->name ) return; |
414 | detach(); | 418 | detach(); |
415 | mData->empty = false; | 419 | mData->empty = false; |
416 | mData->name = name; | 420 | mData->name = name; |
417 | } | 421 | } |
418 | 422 | ||
419 | QString Addressee::name() const | 423 | QString Addressee::name() const |
420 | { | 424 | { |
421 | return mData->name; | 425 | return mData->name; |
422 | } | 426 | } |
423 | 427 | ||
424 | QString Addressee::nameLabel() | 428 | QString Addressee::nameLabel() |
425 | { | 429 | { |
426 | return i18n("Name"); | 430 | return i18n("Name"); |
427 | } | 431 | } |
428 | 432 | ||
429 | 433 | ||
430 | void Addressee::setFormattedName( const QString &formattedName ) | 434 | void Addressee::setFormattedName( const QString &formattedName ) |
431 | { | 435 | { |
432 | if ( formattedName == mData->formattedName ) return; | 436 | if ( formattedName == mData->formattedName ) return; |
433 | detach(); | 437 | detach(); |
434 | mData->empty = false; | 438 | mData->empty = false; |
435 | mData->formattedName = formattedName; | 439 | mData->formattedName = formattedName; |
436 | } | 440 | } |
437 | 441 | ||
438 | QString Addressee::formattedName() const | 442 | QString Addressee::formattedName() const |
439 | { | 443 | { |
440 | return mData->formattedName; | 444 | return mData->formattedName; |
441 | } | 445 | } |
442 | 446 | ||
443 | QString Addressee::formattedNameLabel() | 447 | QString Addressee::formattedNameLabel() |
444 | { | 448 | { |
445 | return i18n("Formatted Name"); | 449 | return i18n("Formatted Name"); |
446 | } | 450 | } |
447 | 451 | ||
448 | 452 | ||
449 | void Addressee::setFamilyName( const QString &familyName ) | 453 | void Addressee::setFamilyName( const QString &familyName ) |
450 | { | 454 | { |
451 | if ( familyName == mData->familyName ) return; | 455 | if ( familyName == mData->familyName ) return; |
452 | detach(); | 456 | detach(); |
453 | mData->empty = false; | 457 | mData->empty = false; |
454 | mData->familyName = familyName; | 458 | mData->familyName = familyName; |
455 | } | 459 | } |
456 | 460 | ||
457 | QString Addressee::familyName() const | 461 | QString Addressee::familyName() const |
458 | { | 462 | { |
459 | return mData->familyName; | 463 | return mData->familyName; |
460 | } | 464 | } |
461 | 465 | ||
462 | QString Addressee::familyNameLabel() | 466 | QString Addressee::familyNameLabel() |
463 | { | 467 | { |
464 | return i18n("Family Name"); | 468 | return i18n("Family Name"); |
465 | } | 469 | } |
466 | 470 | ||
467 | 471 | ||
468 | void Addressee::setGivenName( const QString &givenName ) | 472 | void Addressee::setGivenName( const QString &givenName ) |
469 | { | 473 | { |
470 | if ( givenName == mData->givenName ) return; | 474 | if ( givenName == mData->givenName ) return; |
471 | detach(); | 475 | detach(); |
472 | mData->empty = false; | 476 | mData->empty = false; |
473 | mData->givenName = givenName; | 477 | mData->givenName = givenName; |
474 | } | 478 | } |
475 | 479 | ||
476 | QString Addressee::givenName() const | 480 | QString Addressee::givenName() const |
477 | { | 481 | { |
478 | return mData->givenName; | 482 | return mData->givenName; |
479 | } | 483 | } |
480 | 484 | ||
481 | QString Addressee::givenNameLabel() | 485 | QString Addressee::givenNameLabel() |
482 | { | 486 | { |
483 | return i18n("Given Name"); | 487 | return i18n("Given Name"); |
484 | } | 488 | } |
485 | 489 | ||
486 | 490 | ||
487 | void Addressee::setAdditionalName( const QString &additionalName ) | 491 | void Addressee::setAdditionalName( const QString &additionalName ) |
488 | { | 492 | { |
489 | if ( additionalName == mData->additionalName ) return; | 493 | if ( additionalName == mData->additionalName ) return; |
490 | detach(); | 494 | detach(); |
491 | mData->empty = false; | 495 | mData->empty = false; |
492 | mData->additionalName = additionalName; | 496 | mData->additionalName = additionalName; |
493 | } | 497 | } |
494 | 498 | ||
495 | QString Addressee::additionalName() const | 499 | QString Addressee::additionalName() const |
496 | { | 500 | { |
497 | return mData->additionalName; | 501 | return mData->additionalName; |
498 | } | 502 | } |
499 | 503 | ||
500 | QString Addressee::additionalNameLabel() | 504 | QString Addressee::additionalNameLabel() |
501 | { | 505 | { |
502 | return i18n("Additional Names"); | 506 | return i18n("Additional Names"); |
503 | } | 507 | } |
504 | 508 | ||
505 | 509 | ||
506 | void Addressee::setPrefix( const QString &prefix ) | 510 | void Addressee::setPrefix( const QString &prefix ) |
507 | { | 511 | { |
508 | if ( prefix == mData->prefix ) return; | 512 | if ( prefix == mData->prefix ) return; |
509 | detach(); | 513 | detach(); |
510 | mData->empty = false; | 514 | mData->empty = false; |
511 | mData->prefix = prefix; | 515 | mData->prefix = prefix; |
512 | } | 516 | } |
513 | 517 | ||
514 | QString Addressee::prefix() const | 518 | QString Addressee::prefix() const |
515 | { | 519 | { |
516 | return mData->prefix; | 520 | return mData->prefix; |
517 | } | 521 | } |
518 | 522 | ||
519 | QString Addressee::prefixLabel() | 523 | QString Addressee::prefixLabel() |
520 | { | 524 | { |
521 | return i18n("Honorific Prefixes"); | 525 | return i18n("Honorific Prefixes"); |
522 | } | 526 | } |
523 | 527 | ||
524 | 528 | ||
525 | void Addressee::setSuffix( const QString &suffix ) | 529 | void Addressee::setSuffix( const QString &suffix ) |
526 | { | 530 | { |
527 | if ( suffix == mData->suffix ) return; | 531 | if ( suffix == mData->suffix ) return; |
528 | detach(); | 532 | detach(); |
529 | mData->empty = false; | 533 | mData->empty = false; |
530 | mData->suffix = suffix; | 534 | mData->suffix = suffix; |
531 | } | 535 | } |
532 | 536 | ||
533 | QString Addressee::suffix() const | 537 | QString Addressee::suffix() const |
534 | { | 538 | { |
535 | return mData->suffix; | 539 | return mData->suffix; |
536 | } | 540 | } |
537 | 541 | ||
538 | QString Addressee::suffixLabel() | 542 | QString Addressee::suffixLabel() |
539 | { | 543 | { |
540 | return i18n("Honorific Suffixes"); | 544 | return i18n("Honorific Suffixes"); |
541 | } | 545 | } |
542 | 546 | ||
543 | 547 | ||
544 | void Addressee::setNickName( const QString &nickName ) | 548 | void Addressee::setNickName( const QString &nickName ) |
545 | { | 549 | { |
546 | if ( nickName == mData->nickName ) return; | 550 | if ( nickName == mData->nickName ) return; |
547 | detach(); | 551 | detach(); |
548 | mData->empty = false; | 552 | mData->empty = false; |
549 | mData->nickName = nickName; | 553 | mData->nickName = nickName; |
550 | } | 554 | } |
551 | 555 | ||
552 | QString Addressee::nickName() const | 556 | QString Addressee::nickName() const |
553 | { | 557 | { |
554 | return mData->nickName; | 558 | return mData->nickName; |
555 | } | 559 | } |
556 | 560 | ||
557 | QString Addressee::nickNameLabel() | 561 | QString Addressee::nickNameLabel() |
558 | { | 562 | { |
559 | return i18n("Nick Name"); | 563 | return i18n("Nick Name"); |
560 | } | 564 | } |
561 | 565 | ||
562 | 566 | ||
563 | void Addressee::setBirthday( const QDateTime &birthday ) | 567 | void Addressee::setBirthday( const QDateTime &birthday ) |
564 | { | 568 | { |
565 | if ( birthday == mData->birthday ) return; | 569 | if ( birthday == mData->birthday ) return; |
566 | detach(); | 570 | detach(); |
567 | mData->empty = false; | 571 | mData->empty = false; |
568 | mData->birthday = birthday; | 572 | mData->birthday = birthday; |
569 | } | 573 | } |
570 | 574 | ||
571 | QDateTime Addressee::birthday() const | 575 | QDateTime Addressee::birthday() const |
572 | { | 576 | { |
573 | return mData->birthday; | 577 | return mData->birthday; |
574 | } | 578 | } |
575 | 579 | ||
576 | QString Addressee::birthdayLabel() | 580 | QString Addressee::birthdayLabel() |
577 | { | 581 | { |
578 | return i18n("Birthday"); | 582 | return i18n("Birthday"); |
579 | } | 583 | } |
580 | 584 | ||
581 | 585 | ||
582 | QString Addressee::homeAddressStreetLabel() | 586 | QString Addressee::homeAddressStreetLabel() |
583 | { | 587 | { |
584 | return i18n("Home Address Street"); | 588 | return i18n("Home Address Street"); |
585 | } | 589 | } |
586 | 590 | ||
587 | 591 | ||
588 | QString Addressee::homeAddressLocalityLabel() | 592 | QString Addressee::homeAddressLocalityLabel() |
589 | { | 593 | { |
590 | return i18n("Home Address Locality"); | 594 | return i18n("Home Address Locality"); |
591 | } | 595 | } |
592 | 596 | ||
593 | 597 | ||
594 | QString Addressee::homeAddressRegionLabel() | 598 | QString Addressee::homeAddressRegionLabel() |
595 | { | 599 | { |
596 | return i18n("Home Address Region"); | 600 | return i18n("Home Address Region"); |
597 | } | 601 | } |
598 | 602 | ||
599 | 603 | ||
600 | QString Addressee::homeAddressPostalCodeLabel() | 604 | QString Addressee::homeAddressPostalCodeLabel() |
601 | { | 605 | { |
602 | return i18n("Home Address Postal Code"); | 606 | return i18n("Home Address Postal Code"); |
603 | } | 607 | } |
604 | 608 | ||
605 | 609 | ||
606 | QString Addressee::homeAddressCountryLabel() | 610 | QString Addressee::homeAddressCountryLabel() |
607 | { | 611 | { |
608 | return i18n("Home Address Country"); | 612 | return i18n("Home Address Country"); |
609 | } | 613 | } |
610 | 614 | ||
611 | 615 | ||
612 | QString Addressee::homeAddressLabelLabel() | 616 | QString Addressee::homeAddressLabelLabel() |
613 | { | 617 | { |
614 | return i18n("Home Address Label"); | 618 | return i18n("Home Address Label"); |
615 | } | 619 | } |
616 | 620 | ||
617 | 621 | ||
618 | QString Addressee::businessAddressStreetLabel() | 622 | QString Addressee::businessAddressStreetLabel() |
619 | { | 623 | { |
620 | return i18n("Business Address Street"); | 624 | return i18n("Business Address Street"); |
621 | } | 625 | } |
622 | 626 | ||
623 | 627 | ||
624 | QString Addressee::businessAddressLocalityLabel() | 628 | QString Addressee::businessAddressLocalityLabel() |
625 | { | 629 | { |
626 | return i18n("Business Address Locality"); | 630 | return i18n("Business Address Locality"); |
627 | } | 631 | } |
628 | 632 | ||
629 | 633 | ||
630 | QString Addressee::businessAddressRegionLabel() | 634 | QString Addressee::businessAddressRegionLabel() |
631 | { | 635 | { |
632 | return i18n("Business Address Region"); | 636 | return i18n("Business Address Region"); |
633 | } | 637 | } |
634 | 638 | ||
635 | 639 | ||
636 | QString Addressee::businessAddressPostalCodeLabel() | 640 | QString Addressee::businessAddressPostalCodeLabel() |
637 | { | 641 | { |
638 | return i18n("Business Address Postal Code"); | 642 | return i18n("Business Address Postal Code"); |
639 | } | 643 | } |
640 | 644 | ||
641 | 645 | ||
642 | QString Addressee::businessAddressCountryLabel() | 646 | QString Addressee::businessAddressCountryLabel() |
643 | { | 647 | { |
644 | return i18n("Business Address Country"); | 648 | return i18n("Business Address Country"); |
645 | } | 649 | } |
646 | 650 | ||
647 | 651 | ||
648 | QString Addressee::businessAddressLabelLabel() | 652 | QString Addressee::businessAddressLabelLabel() |
649 | { | 653 | { |
650 | return i18n("Business Address Label"); | 654 | return i18n("Business Address Label"); |
651 | } | 655 | } |
652 | 656 | ||
653 | 657 | ||
654 | QString Addressee::homePhoneLabel() | 658 | QString Addressee::homePhoneLabel() |
655 | { | 659 | { |
656 | return i18n("Home Phone"); | 660 | return i18n("Home Phone"); |
657 | } | 661 | } |
658 | 662 | ||
659 | 663 | ||
660 | QString Addressee::businessPhoneLabel() | 664 | QString Addressee::businessPhoneLabel() |
661 | { | 665 | { |
662 | return i18n("Business Phone"); | 666 | return i18n("Business Phone"); |
663 | } | 667 | } |
664 | 668 | ||
665 | 669 | ||
666 | QString Addressee::mobilePhoneLabel() | 670 | QString Addressee::mobilePhoneLabel() |
667 | { | 671 | { |
668 | return i18n("Mobile Phone"); | 672 | return i18n("Mobile Phone"); |
669 | } | 673 | } |
670 | 674 | ||
671 | 675 | ||
672 | QString Addressee::homeFaxLabel() | 676 | QString Addressee::homeFaxLabel() |
673 | { | 677 | { |
674 | return i18n("Home Fax"); | 678 | return i18n("Home Fax"); |
675 | } | 679 | } |
676 | 680 | ||
677 | 681 | ||
678 | QString Addressee::businessFaxLabel() | 682 | QString Addressee::businessFaxLabel() |
679 | { | 683 | { |
680 | return i18n("Business Fax"); | 684 | return i18n("Business Fax"); |
681 | } | 685 | } |
682 | 686 | ||
683 | 687 | ||
684 | QString Addressee::carPhoneLabel() | 688 | QString Addressee::carPhoneLabel() |
685 | { | 689 | { |
686 | return i18n("Car Phone"); | 690 | return i18n("Car Phone"); |
687 | } | 691 | } |
688 | 692 | ||
689 | 693 | ||
690 | QString Addressee::isdnLabel() | 694 | QString Addressee::isdnLabel() |
691 | { | 695 | { |
692 | return i18n("ISDN"); | 696 | return i18n("ISDN"); |
693 | } | 697 | } |
694 | 698 | ||
695 | 699 | ||
696 | QString Addressee::pagerLabel() | 700 | QString Addressee::pagerLabel() |
697 | { | 701 | { |
698 | return i18n("Pager"); | 702 | return i18n("Pager"); |
699 | } | 703 | } |
700 | 704 | ||
701 | QString Addressee::sipLabel() | 705 | QString Addressee::sipLabel() |
702 | { | 706 | { |
703 | return i18n("SIP"); | 707 | return i18n("SIP"); |
704 | } | 708 | } |
705 | 709 | ||
706 | QString Addressee::emailLabel() | 710 | QString Addressee::emailLabel() |
707 | { | 711 | { |
708 | return i18n("Email Address"); | 712 | return i18n("Email Address"); |
709 | } | 713 | } |
710 | 714 | ||
711 | 715 | ||
712 | void Addressee::setMailer( const QString &mailer ) | 716 | void Addressee::setMailer( const QString &mailer ) |
713 | { | 717 | { |
714 | if ( mailer == mData->mailer ) return; | 718 | if ( mailer == mData->mailer ) return; |
715 | detach(); | 719 | detach(); |
716 | mData->empty = false; | 720 | mData->empty = false; |
717 | mData->mailer = mailer; | 721 | mData->mailer = mailer; |
718 | } | 722 | } |
719 | 723 | ||
720 | QString Addressee::mailer() const | 724 | QString Addressee::mailer() const |
721 | { | 725 | { |
722 | return mData->mailer; | 726 | return mData->mailer; |
723 | } | 727 | } |
724 | 728 | ||
725 | QString Addressee::mailerLabel() | 729 | QString Addressee::mailerLabel() |
726 | { | 730 | { |
727 | return i18n("Mail Client"); | 731 | return i18n("Mail Client"); |
728 | } | 732 | } |
729 | 733 | ||
730 | 734 | ||
731 | void Addressee::setTimeZone( const TimeZone &timeZone ) | 735 | void Addressee::setTimeZone( const TimeZone &timeZone ) |
732 | { | 736 | { |
733 | if ( timeZone == mData->timeZone ) return; | 737 | if ( timeZone == mData->timeZone ) return; |
734 | detach(); | 738 | detach(); |
735 | mData->empty = false; | 739 | mData->empty = false; |
736 | mData->timeZone = timeZone; | 740 | mData->timeZone = timeZone; |
737 | } | 741 | } |
738 | 742 | ||
739 | TimeZone Addressee::timeZone() const | 743 | TimeZone Addressee::timeZone() const |
740 | { | 744 | { |
741 | return mData->timeZone; | 745 | return mData->timeZone; |
742 | } | 746 | } |
743 | 747 | ||
744 | QString Addressee::timeZoneLabel() | 748 | QString Addressee::timeZoneLabel() |
745 | { | 749 | { |
746 | return i18n("Time Zone"); | 750 | return i18n("Time Zone"); |
747 | } | 751 | } |
748 | 752 | ||
749 | 753 | ||
750 | void Addressee::setGeo( const Geo &geo ) | 754 | void Addressee::setGeo( const Geo &geo ) |
751 | { | 755 | { |
752 | if ( geo == mData->geo ) return; | 756 | if ( geo == mData->geo ) return; |
753 | detach(); | 757 | detach(); |
754 | mData->empty = false; | 758 | mData->empty = false; |
755 | mData->geo = geo; | 759 | mData->geo = geo; |
756 | } | 760 | } |
757 | 761 | ||
758 | Geo Addressee::geo() const | 762 | Geo Addressee::geo() const |
759 | { | 763 | { |
760 | return mData->geo; | 764 | return mData->geo; |
761 | } | 765 | } |
762 | 766 | ||
763 | QString Addressee::geoLabel() | 767 | QString Addressee::geoLabel() |
764 | { | 768 | { |
765 | return i18n("Geographic Position"); | 769 | return i18n("Geographic Position"); |
766 | } | 770 | } |
767 | 771 | ||
768 | 772 | ||
769 | void Addressee::setTitle( const QString &title ) | 773 | void Addressee::setTitle( const QString &title ) |
770 | { | 774 | { |
771 | if ( title == mData->title ) return; | 775 | if ( title == mData->title ) return; |
772 | detach(); | 776 | detach(); |
773 | mData->empty = false; | 777 | mData->empty = false; |
774 | mData->title = title; | 778 | mData->title = title; |
775 | } | 779 | } |
776 | 780 | ||
777 | QString Addressee::title() const | 781 | QString Addressee::title() const |
778 | { | 782 | { |
779 | return mData->title; | 783 | return mData->title; |
780 | } | 784 | } |
781 | 785 | ||
782 | QString Addressee::titleLabel() | 786 | QString Addressee::titleLabel() |
783 | { | 787 | { |
784 | return i18n("Title"); | 788 | return i18n("Title"); |
785 | } | 789 | } |
786 | 790 | ||
787 | 791 | ||
788 | void Addressee::setRole( const QString &role ) | 792 | void Addressee::setRole( const QString &role ) |
789 | { | 793 | { |
790 | if ( role == mData->role ) return; | 794 | if ( role == mData->role ) return; |
791 | detach(); | 795 | detach(); |
792 | mData->empty = false; | 796 | mData->empty = false; |
793 | mData->role = role; | 797 | mData->role = role; |
794 | } | 798 | } |
795 | 799 | ||
796 | QString Addressee::role() const | 800 | QString Addressee::role() const |
797 | { | 801 | { |
798 | return mData->role; | 802 | return mData->role; |
799 | } | 803 | } |
800 | 804 | ||
801 | QString Addressee::roleLabel() | 805 | QString Addressee::roleLabel() |
802 | { | 806 | { |
803 | return i18n("Role"); | 807 | return i18n("Role"); |
804 | } | 808 | } |
805 | 809 | ||
806 | 810 | ||
807 | void Addressee::setOrganization( const QString &organization ) | 811 | void Addressee::setOrganization( const QString &organization ) |
808 | { | 812 | { |
809 | if ( organization == mData->organization ) return; | 813 | if ( organization == mData->organization ) return; |
810 | detach(); | 814 | detach(); |
811 | mData->empty = false; | 815 | mData->empty = false; |
812 | mData->organization = organization; | 816 | mData->organization = organization; |
813 | } | 817 | } |
814 | 818 | ||
815 | QString Addressee::organization() const | 819 | QString Addressee::organization() const |
816 | { | 820 | { |
817 | return mData->organization; | 821 | return mData->organization; |
818 | } | 822 | } |
819 | 823 | ||
820 | QString Addressee::organizationLabel() | 824 | QString Addressee::organizationLabel() |
821 | { | 825 | { |
822 | return i18n("Organization"); | 826 | return i18n("Organization"); |
823 | } | 827 | } |
824 | 828 | ||
825 | 829 | ||
826 | void Addressee::setNote( const QString ¬e ) | 830 | void Addressee::setNote( const QString ¬e ) |
827 | { | 831 | { |
828 | if ( note == mData->note ) return; | 832 | if ( note == mData->note ) return; |
829 | detach(); | 833 | detach(); |
830 | mData->empty = false; | 834 | mData->empty = false; |
831 | mData->note = note; | 835 | mData->note = note; |
832 | } | 836 | } |
833 | 837 | ||
834 | QString Addressee::note() const | 838 | QString Addressee::note() const |
835 | { | 839 | { |
836 | return mData->note; | 840 | return mData->note; |
837 | } | 841 | } |
838 | 842 | ||
839 | QString Addressee::noteLabel() | 843 | QString Addressee::noteLabel() |
840 | { | 844 | { |
841 | return i18n("Note"); | 845 | return i18n("Note"); |
842 | } | 846 | } |
843 | 847 | ||
844 | 848 | ||
845 | void Addressee::setProductId( const QString &productId ) | 849 | void Addressee::setProductId( const QString &productId ) |
846 | { | 850 | { |
847 | if ( productId == mData->productId ) return; | 851 | if ( productId == mData->productId ) return; |
848 | detach(); | 852 | detach(); |
849 | mData->empty = false; | 853 | mData->empty = false; |
850 | mData->productId = productId; | 854 | mData->productId = productId; |
851 | } | 855 | } |
852 | 856 | ||
853 | QString Addressee::productId() const | 857 | QString Addressee::productId() const |
854 | { | 858 | { |
855 | return mData->productId; | 859 | return mData->productId; |
856 | } | 860 | } |
857 | 861 | ||
858 | QString Addressee::productIdLabel() | 862 | QString Addressee::productIdLabel() |
859 | { | 863 | { |
860 | return i18n("Product Identifier"); | 864 | return i18n("Product Identifier"); |
861 | } | 865 | } |
862 | 866 | ||
863 | 867 | ||
864 | void Addressee::setRevision( const QDateTime &revision ) | 868 | void Addressee::setRevision( const QDateTime &revision ) |
865 | { | 869 | { |
866 | if ( revision == mData->revision ) return; | 870 | if ( revision == mData->revision ) return; |
867 | detach(); | 871 | detach(); |
868 | mData->empty = false; | 872 | mData->empty = false; |
869 | mData->revision = revision; | 873 | mData->revision = revision; |
870 | } | 874 | } |
871 | 875 | ||
872 | QDateTime Addressee::revision() const | 876 | QDateTime Addressee::revision() const |
873 | { | 877 | { |
874 | return mData->revision; | 878 | return mData->revision; |
875 | } | 879 | } |
876 | 880 | ||
877 | QString Addressee::revisionLabel() | 881 | QString Addressee::revisionLabel() |
878 | { | 882 | { |
879 | return i18n("Revision Date"); | 883 | return i18n("Revision Date"); |
880 | } | 884 | } |
881 | 885 | ||
882 | 886 | ||
883 | void Addressee::setSortString( const QString &sortString ) | 887 | void Addressee::setSortString( const QString &sortString ) |
884 | { | 888 | { |
885 | if ( sortString == mData->sortString ) return; | 889 | if ( sortString == mData->sortString ) return; |
886 | detach(); | 890 | detach(); |
887 | mData->empty = false; | 891 | mData->empty = false; |
888 | mData->sortString = sortString; | 892 | mData->sortString = sortString; |
889 | } | 893 | } |
890 | 894 | ||
891 | QString Addressee::sortString() const | 895 | QString Addressee::sortString() const |
892 | { | 896 | { |
893 | return mData->sortString; | 897 | return mData->sortString; |
894 | } | 898 | } |
895 | 899 | ||
896 | QString Addressee::sortStringLabel() | 900 | QString Addressee::sortStringLabel() |
897 | { | 901 | { |
898 | return i18n("Sort String"); | 902 | return i18n("Sort String"); |
899 | } | 903 | } |
900 | 904 | ||
901 | 905 | ||
902 | void Addressee::setUrl( const KURL &url ) | 906 | void Addressee::setUrl( const KURL &url ) |
903 | { | 907 | { |
904 | if ( url == mData->url ) return; | 908 | if ( url == mData->url ) return; |
905 | detach(); | 909 | detach(); |
906 | mData->empty = false; | 910 | mData->empty = false; |
907 | mData->url = url; | 911 | mData->url = url; |
908 | } | 912 | } |
909 | 913 | ||
910 | KURL Addressee::url() const | 914 | KURL Addressee::url() const |
911 | { | 915 | { |
912 | return mData->url; | 916 | return mData->url; |
913 | } | 917 | } |
914 | 918 | ||
915 | QString Addressee::urlLabel() | 919 | QString Addressee::urlLabel() |
916 | { | 920 | { |
917 | return i18n("URL"); | 921 | return i18n("URL"); |
918 | } | 922 | } |
919 | 923 | ||
920 | 924 | ||
921 | void Addressee::setSecrecy( const Secrecy &secrecy ) | 925 | void Addressee::setSecrecy( const Secrecy &secrecy ) |
922 | { | 926 | { |
923 | if ( secrecy == mData->secrecy ) return; | 927 | if ( secrecy == mData->secrecy ) return; |
924 | detach(); | 928 | detach(); |
925 | mData->empty = false; | 929 | mData->empty = false; |
926 | mData->secrecy = secrecy; | 930 | mData->secrecy = secrecy; |
927 | } | 931 | } |
928 | 932 | ||
929 | Secrecy Addressee::secrecy() const | 933 | Secrecy Addressee::secrecy() const |
930 | { | 934 | { |
931 | return mData->secrecy; | 935 | return mData->secrecy; |
932 | } | 936 | } |
933 | 937 | ||
934 | QString Addressee::secrecyLabel() | 938 | QString Addressee::secrecyLabel() |
935 | { | 939 | { |
936 | return i18n("Security Class"); | 940 | return i18n("Security Class"); |
937 | } | 941 | } |
938 | 942 | ||
939 | 943 | ||
940 | void Addressee::setLogo( const Picture &logo ) | 944 | void Addressee::setLogo( const Picture &logo ) |
941 | { | 945 | { |
942 | if ( logo == mData->logo ) return; | 946 | if ( logo == mData->logo ) return; |
943 | detach(); | 947 | detach(); |
944 | mData->empty = false; | 948 | mData->empty = false; |
945 | mData->logo = logo; | 949 | mData->logo = logo; |
946 | } | 950 | } |
947 | 951 | ||
948 | Picture Addressee::logo() const | 952 | Picture Addressee::logo() const |
949 | { | 953 | { |
950 | return mData->logo; | 954 | return mData->logo; |
951 | } | 955 | } |
952 | 956 | ||
953 | QString Addressee::logoLabel() | 957 | QString Addressee::logoLabel() |
954 | { | 958 | { |
955 | return i18n("Logo"); | 959 | return i18n("Logo"); |
956 | } | 960 | } |
957 | 961 | ||
958 | 962 | ||
959 | void Addressee::setPhoto( const Picture &photo ) | 963 | void Addressee::setPhoto( const Picture &photo ) |
960 | { | 964 | { |
961 | if ( photo == mData->photo ) return; | 965 | if ( photo == mData->photo ) return; |
962 | detach(); | 966 | detach(); |
963 | mData->empty = false; | 967 | mData->empty = false; |
964 | mData->photo = photo; | 968 | mData->photo = photo; |
965 | } | 969 | } |
966 | 970 | ||
967 | Picture Addressee::photo() const | 971 | Picture Addressee::photo() const |
968 | { | 972 | { |
969 | return mData->photo; | 973 | return mData->photo; |
970 | } | 974 | } |
971 | 975 | ||
972 | QString Addressee::photoLabel() | 976 | QString Addressee::photoLabel() |
973 | { | 977 | { |
974 | return i18n("Photo"); | 978 | return i18n("Photo"); |
975 | } | 979 | } |
976 | 980 | ||
977 | 981 | ||
978 | void Addressee::setSound( const Sound &sound ) | 982 | void Addressee::setSound( const Sound &sound ) |
979 | { | 983 | { |
980 | if ( sound == mData->sound ) return; | 984 | if ( sound == mData->sound ) return; |
981 | detach(); | 985 | detach(); |
982 | mData->empty = false; | 986 | mData->empty = false; |
983 | mData->sound = sound; | 987 | mData->sound = sound; |
984 | } | 988 | } |
985 | 989 | ||
986 | Sound Addressee::sound() const | 990 | Sound Addressee::sound() const |
987 | { | 991 | { |
988 | return mData->sound; | 992 | return mData->sound; |
989 | } | 993 | } |
990 | 994 | ||
991 | QString Addressee::soundLabel() | 995 | QString Addressee::soundLabel() |
992 | { | 996 | { |
993 | return i18n("Sound"); | 997 | return i18n("Sound"); |
994 | } | 998 | } |
995 | 999 | ||
996 | 1000 | ||
997 | void Addressee::setAgent( const Agent &agent ) | 1001 | void Addressee::setAgent( const Agent &agent ) |
998 | { | 1002 | { |
999 | if ( agent == mData->agent ) return; | 1003 | if ( agent == mData->agent ) return; |
1000 | detach(); | 1004 | detach(); |
1001 | mData->empty = false; | 1005 | mData->empty = false; |
1002 | mData->agent = agent; | 1006 | mData->agent = agent; |
1003 | } | 1007 | } |
1004 | 1008 | ||
1005 | Agent Addressee::agent() const | 1009 | Agent Addressee::agent() const |
1006 | { | 1010 | { |
1007 | return mData->agent; | 1011 | return mData->agent; |
1008 | } | 1012 | } |
1009 | 1013 | ||
1010 | QString Addressee::agentLabel() | 1014 | QString Addressee::agentLabel() |
1011 | { | 1015 | { |
1012 | return i18n("Agent"); | 1016 | return i18n("Agent"); |
1013 | } | 1017 | } |
1014 | 1018 | ||
1015 | 1019 | ||
1016 | 1020 | ||
1017 | void Addressee::setNameFromString( const QString &str ) | 1021 | void Addressee::setNameFromString( const QString &str ) |
1018 | { | 1022 | { |
1019 | setFormattedName( str ); | 1023 | setFormattedName( str ); |
1020 | setName( str ); | 1024 | setName( str ); |
1021 | 1025 | ||
1022 | static bool first = true; | 1026 | static bool first = true; |
1023 | static QStringList titles; | 1027 | static QStringList titles; |
1024 | static QStringList suffixes; | 1028 | static QStringList suffixes; |
1025 | static QStringList prefixes; | 1029 | static QStringList prefixes; |
1026 | 1030 | ||
1027 | if ( first ) { | 1031 | if ( first ) { |
1028 | first = false; | 1032 | first = false; |
1029 | titles += i18n( "Dr." ); | 1033 | titles += i18n( "Dr." ); |
1030 | titles += i18n( "Miss" ); | 1034 | titles += i18n( "Miss" ); |
1031 | titles += i18n( "Mr." ); | 1035 | titles += i18n( "Mr." ); |
1032 | titles += i18n( "Mrs." ); | 1036 | titles += i18n( "Mrs." ); |
1033 | titles += i18n( "Ms." ); | 1037 | titles += i18n( "Ms." ); |
1034 | titles += i18n( "Prof." ); | 1038 | titles += i18n( "Prof." ); |
1035 | 1039 | ||
1036 | suffixes += i18n( "I" ); | 1040 | suffixes += i18n( "I" ); |
1037 | suffixes += i18n( "II" ); | 1041 | suffixes += i18n( "II" ); |
1038 | suffixes += i18n( "III" ); | 1042 | suffixes += i18n( "III" ); |
1039 | suffixes += i18n( "Jr." ); | 1043 | suffixes += i18n( "Jr." ); |
1040 | suffixes += i18n( "Sr." ); | 1044 | suffixes += i18n( "Sr." ); |
1041 | 1045 | ||
1042 | prefixes += "van"; | 1046 | prefixes += "van"; |
1043 | prefixes += "von"; | 1047 | prefixes += "von"; |
1044 | prefixes += "de"; | 1048 | prefixes += "de"; |
1045 | 1049 | ||
1046 | KConfig config( locateLocal( "config", "kabcrc") ); | 1050 | KConfig config( locateLocal( "config", "kabcrc") ); |
1047 | config.setGroup( "General" ); | 1051 | config.setGroup( "General" ); |
1048 | titles += config.readListEntry( "Prefixes" ); | 1052 | titles += config.readListEntry( "Prefixes" ); |
1049 | titles.remove( "" ); | 1053 | titles.remove( "" ); |
1050 | prefixes += config.readListEntry( "Inclusions" ); | 1054 | prefixes += config.readListEntry( "Inclusions" ); |
1051 | prefixes.remove( "" ); | 1055 | prefixes.remove( "" ); |
1052 | suffixes += config.readListEntry( "Suffixes" ); | 1056 | suffixes += config.readListEntry( "Suffixes" ); |
1053 | suffixes.remove( "" ); | 1057 | suffixes.remove( "" ); |
1054 | } | 1058 | } |
1055 | 1059 | ||
1056 | // clear all name parts | 1060 | // clear all name parts |
1057 | setPrefix( "" ); | 1061 | setPrefix( "" ); |
1058 | setGivenName( "" ); | 1062 | setGivenName( "" ); |
1059 | setAdditionalName( "" ); | 1063 | setAdditionalName( "" ); |
1060 | setFamilyName( "" ); | 1064 | setFamilyName( "" ); |
1061 | setSuffix( "" ); | 1065 | setSuffix( "" ); |
1062 | 1066 | ||
1063 | if ( str.isEmpty() ) | 1067 | if ( str.isEmpty() ) |
1064 | return; | 1068 | return; |
1065 | 1069 | ||
1066 | int i = str.find(','); | 1070 | int i = str.find(','); |
1067 | if( i < 0 ) { | 1071 | if( i < 0 ) { |
1068 | QStringList parts = QStringList::split( " ", str ); | 1072 | QStringList parts = QStringList::split( " ", str ); |
1069 | int leftOffset = 0; | 1073 | int leftOffset = 0; |
1070 | int rightOffset = parts.count() - 1; | 1074 | int rightOffset = parts.count() - 1; |
1071 | 1075 | ||
1072 | QString suffix; | 1076 | QString suffix; |
1073 | while ( rightOffset >= 0 ) { | 1077 | while ( rightOffset >= 0 ) { |
1074 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1078 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1075 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1079 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1076 | rightOffset--; | 1080 | rightOffset--; |
1077 | } else | 1081 | } else |
1078 | break; | 1082 | break; |
1079 | } | 1083 | } |
1080 | setSuffix( suffix ); | 1084 | setSuffix( suffix ); |
1081 | 1085 | ||
1082 | if ( rightOffset < 0 ) | 1086 | if ( rightOffset < 0 ) |
1083 | return; | 1087 | return; |
1084 | 1088 | ||
1085 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1089 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1086 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1090 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1087 | rightOffset--; | 1091 | rightOffset--; |
1088 | } else | 1092 | } else |
1089 | setFamilyName( parts[ rightOffset ] ); | 1093 | setFamilyName( parts[ rightOffset ] ); |
1090 | 1094 | ||
1091 | QString prefix; | 1095 | QString prefix; |
1092 | while ( leftOffset < rightOffset ) { | 1096 | while ( leftOffset < rightOffset ) { |
1093 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1097 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1094 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1098 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1095 | leftOffset++; | 1099 | leftOffset++; |
1096 | } else | 1100 | } else |
1097 | break; | 1101 | break; |
1098 | } | 1102 | } |
1099 | setPrefix( prefix ); | 1103 | setPrefix( prefix ); |
1100 | 1104 | ||
1101 | if ( leftOffset < rightOffset ) { | 1105 | if ( leftOffset < rightOffset ) { |
1102 | setGivenName( parts[ leftOffset ] ); | 1106 | setGivenName( parts[ leftOffset ] ); |
1103 | leftOffset++; | 1107 | leftOffset++; |
1104 | } | 1108 | } |
1105 | 1109 | ||
1106 | QString additionalName; | 1110 | QString additionalName; |
1107 | while ( leftOffset < rightOffset ) { | 1111 | while ( leftOffset < rightOffset ) { |
1108 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1112 | additionalName.append( ( additionalName.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1109 | leftOffset++; | 1113 | leftOffset++; |
1110 | } | 1114 | } |
1111 | setAdditionalName( additionalName ); | 1115 | setAdditionalName( additionalName ); |
1112 | } else { | 1116 | } else { |
1113 | QString part1 = str.left( i ); | 1117 | QString part1 = str.left( i ); |
1114 | QString part2 = str.mid( i + 1 ); | 1118 | QString part2 = str.mid( i + 1 ); |
1115 | 1119 | ||
1116 | QStringList parts = QStringList::split( " ", part1 ); | 1120 | QStringList parts = QStringList::split( " ", part1 ); |
1117 | int leftOffset = 0; | 1121 | int leftOffset = 0; |
1118 | int rightOffset = parts.count() - 1; | 1122 | int rightOffset = parts.count() - 1; |
1119 | 1123 | ||
1120 | QString suffix; | 1124 | QString suffix; |
1121 | while ( rightOffset >= 0 ) { | 1125 | while ( rightOffset >= 0 ) { |
1122 | if ( suffixes.contains( parts[ rightOffset ] ) ) { | 1126 | if ( suffixes.contains( parts[ rightOffset ] ) ) { |
1123 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); | 1127 | suffix.prepend(parts[ rightOffset ] + (suffix.isEmpty() ? "" : " ")); |
1124 | rightOffset--; | 1128 | rightOffset--; |
1125 | } else | 1129 | } else |
1126 | break; | 1130 | break; |
1127 | } | 1131 | } |
1128 | setSuffix( suffix ); | 1132 | setSuffix( suffix ); |
1129 | 1133 | ||
1130 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { | 1134 | if ( rightOffset - 1 >= 0 && prefixes.contains( parts[ rightOffset - 1 ].lower() ) ) { |
1131 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); | 1135 | setFamilyName( parts[ rightOffset - 1 ] + " " + parts[ rightOffset ] ); |
1132 | rightOffset--; | 1136 | rightOffset--; |
1133 | } else | 1137 | } else |
1134 | setFamilyName( parts[ rightOffset ] ); | 1138 | setFamilyName( parts[ rightOffset ] ); |
1135 | 1139 | ||
1136 | QString prefix; | 1140 | QString prefix; |
1137 | while ( leftOffset < rightOffset ) { | 1141 | while ( leftOffset < rightOffset ) { |
1138 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1142 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1139 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1143 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1140 | leftOffset++; | 1144 | leftOffset++; |
1141 | } else | 1145 | } else |
1142 | break; | 1146 | break; |
1143 | } | 1147 | } |
1144 | 1148 | ||
1145 | parts = QStringList::split( " ", part2 ); | 1149 | parts = QStringList::split( " ", part2 ); |
1146 | 1150 | ||
1147 | leftOffset = 0; | 1151 | leftOffset = 0; |
1148 | rightOffset = parts.count(); | 1152 | rightOffset = parts.count(); |
1149 | 1153 | ||
1150 | while ( leftOffset < rightOffset ) { | 1154 | while ( leftOffset < rightOffset ) { |
1151 | if ( titles.contains( parts[ leftOffset ] ) ) { | 1155 | if ( titles.contains( parts[ leftOffset ] ) ) { |
1152 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); | 1156 | prefix.append( ( prefix.isEmpty() ? "" : " ") + parts[ leftOffset ] ); |
1153 | leftOffset++; | 1157 | leftOffset++; |
1154 | } else | 1158 | } else |
1155 | break; | 1159 | break; |
1156 | } | 1160 | } |
1157 | setPrefix( prefix ); | 1161 | setPrefix( prefix ); |
1158 | 1162 | ||
1159 | if ( leftOffset < rightOffset ) { | 1163 | if ( leftOffset < rightOffset ) { |
1160 | setGivenName( parts[ leftOffset ] ); | 1164 | setGivenName( parts[ leftOffset ] ); |
1161 | leftOffset++; | 1165 | leftOffset++; |
diff --git a/kabc/plugins/qtopia/qtopiaconverter.cpp b/kabc/plugins/qtopia/qtopiaconverter.cpp index de45e63..430c7b3 100644 --- a/kabc/plugins/qtopia/qtopiaconverter.cpp +++ b/kabc/plugins/qtopia/qtopiaconverter.cpp | |||
@@ -1,376 +1,376 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> | 3 | Copyright (c) 2002 Tobias Koenig <tokoe@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 | #include "kglobal.h" | 29 | #include "kglobal.h" |
30 | 30 | ||
31 | 31 | ||
32 | #include "qtopiaconverter.h" | 32 | #include "qtopiaconverter.h" |
33 | 33 | ||
34 | #include <qpe/categories.h> | 34 | #include <qpe/categories.h> |
35 | #include <libkdepim/ksyncprofile.h> | 35 | #include <libkdepim/ksyncprofile.h> |
36 | //US #include <qpe/categoryselect.h> | 36 | //US #include <qpe/categoryselect.h> |
37 | 37 | ||
38 | 38 | ||
39 | using namespace KABC; | 39 | using namespace KABC; |
40 | 40 | ||
41 | QtopiaConverter::QtopiaConverter() : catDB(0) | 41 | QtopiaConverter::QtopiaConverter() : catDB(0) |
42 | { | 42 | { |
43 | } | 43 | } |
44 | 44 | ||
45 | QtopiaConverter::~QtopiaConverter() | 45 | QtopiaConverter::~QtopiaConverter() |
46 | { | 46 | { |
47 | deinit(); | 47 | deinit(); |
48 | } | 48 | } |
49 | 49 | ||
50 | bool QtopiaConverter::init() | 50 | bool QtopiaConverter::init() |
51 | { | 51 | { |
52 | catDB = new Categories(); | 52 | catDB = new Categories(); |
53 | 53 | ||
54 | if (!catDB) | 54 | if (!catDB) |
55 | return false; | 55 | return false; |
56 | 56 | ||
57 | catDB->load( categoryFileName() ); | 57 | catDB->load( categoryFileName() ); |
58 | return true; | 58 | return true; |
59 | } | 59 | } |
60 | 60 | ||
61 | void QtopiaConverter::deinit() | 61 | void QtopiaConverter::deinit() |
62 | { | 62 | { |
63 | if (catDB) | 63 | if (catDB) |
64 | { | 64 | { |
65 | delete catDB; | 65 | delete catDB; |
66 | catDB = 0; | 66 | catDB = 0; |
67 | } | 67 | } |
68 | } | 68 | } |
69 | 69 | ||
70 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) | 70 | bool QtopiaConverter::qtopiaToAddressee( const PimContact &contact, Addressee &addr ) |
71 | { | 71 | { |
72 | // name | 72 | // name |
73 | addr.setFormattedName(contact.fileAs()); | 73 | addr.setFormattedName(contact.fileAs()); |
74 | addr.setFamilyName( contact.lastName() ); | 74 | addr.setFamilyName( contact.lastName() ); |
75 | addr.setGivenName( contact.firstName() ); | 75 | addr.setGivenName( contact.firstName() ); |
76 | addr.setAdditionalName( contact.middleName() ); | 76 | addr.setAdditionalName( contact.middleName() ); |
77 | addr.setPrefix( contact.nameTitle() ); | 77 | addr.setPrefix( contact.nameTitle() ); |
78 | addr.setSuffix( contact.suffix() ); | 78 | addr.setSuffix( contact.suffix() ); |
79 | 79 | ||
80 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 80 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
81 | QString exuid = contact.uid().toString(); | 81 | QString exuid = contact.uid().toString(); |
82 | addr.setOriginalExternalUID( exuid ); | 82 | addr.setOriginalExternalUID( exuid ); |
83 | int ente = exuid.find( "-0000"); | 83 | int ente = exuid.find( "-0000"); |
84 | if ( exuid.left(1) == "{" ) | 84 | if ( exuid.left(1) == "{" ) |
85 | exuid = exuid.mid(1); | 85 | exuid = exuid.mid(1); |
86 | if ( ente > -1 ) | 86 | if ( ente > -1 ) |
87 | exuid = exuid.left( ente-1 ); | 87 | exuid = exuid.left( ente-1 ); |
88 | addr.setExternalUID( exuid ); | 88 | addr.setExternalUID( exuid ); |
89 | //qDebug("QtopiaConverter:set uid %s ",addr.externalUID().latin1() ); | 89 | qDebug("QtopiaConverter:set %s uid %s ",addr.originalExternalUID().latin1(),addr.externalUID().latin1() ); |
90 | 90 | ||
91 | 91 | ||
92 | QStringList emails = contact.emailList(); | 92 | QStringList emails = contact.emailList(); |
93 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 93 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
94 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); | 94 | addr.insertEmail( *it, ((*it) == contact.defaultEmail()) ); |
95 | } | 95 | } |
96 | 96 | ||
97 | if (!contact.defaultEmail().isEmpty()) | 97 | if (!contact.defaultEmail().isEmpty()) |
98 | addr.insertEmail(contact.defaultEmail(), true); | 98 | addr.insertEmail(contact.defaultEmail(), true); |
99 | 99 | ||
100 | // home | 100 | // home |
101 | if ((!contact.homeStreet().isEmpty()) || | 101 | if ((!contact.homeStreet().isEmpty()) || |
102 | (!contact.homeCity().isEmpty()) || | 102 | (!contact.homeCity().isEmpty()) || |
103 | (!contact.homeState().isEmpty()) || | 103 | (!contact.homeState().isEmpty()) || |
104 | (!contact.homeZip().isEmpty()) || | 104 | (!contact.homeZip().isEmpty()) || |
105 | (!contact.homeCountry().isEmpty())) | 105 | (!contact.homeCountry().isEmpty())) |
106 | { | 106 | { |
107 | Address homeaddress; | 107 | Address homeaddress; |
108 | homeaddress.setType(Address::Home); | 108 | homeaddress.setType(Address::Home); |
109 | //US homeaddress.setPostOfficeBox( "" ); | 109 | //US homeaddress.setPostOfficeBox( "" ); |
110 | //US homeaddress.setExtended( "" ); | 110 | //US homeaddress.setExtended( "" ); |
111 | homeaddress.setStreet( contact.homeStreet() ); | 111 | homeaddress.setStreet( contact.homeStreet() ); |
112 | homeaddress.setLocality( contact.homeCity() ); | 112 | homeaddress.setLocality( contact.homeCity() ); |
113 | homeaddress.setRegion( contact.homeState() ); | 113 | homeaddress.setRegion( contact.homeState() ); |
114 | homeaddress.setPostalCode( contact.homeZip() ); | 114 | homeaddress.setPostalCode( contact.homeZip() ); |
115 | homeaddress.setCountry( contact.homeCountry() ); | 115 | homeaddress.setCountry( contact.homeCountry() ); |
116 | 116 | ||
117 | addr.insertAddress( homeaddress ); | 117 | addr.insertAddress( homeaddress ); |
118 | } | 118 | } |
119 | 119 | ||
120 | if (!contact.homePhone().isEmpty()) | 120 | if (!contact.homePhone().isEmpty()) |
121 | { | 121 | { |
122 | PhoneNumber homephone; | 122 | PhoneNumber homephone; |
123 | homephone.setType( PhoneNumber::Home ); | 123 | homephone.setType( PhoneNumber::Home ); |
124 | homephone.setNumber( contact.homePhone() ); | 124 | homephone.setNumber( contact.homePhone() ); |
125 | addr.insertPhoneNumber( homephone ); | 125 | addr.insertPhoneNumber( homephone ); |
126 | } | 126 | } |
127 | 127 | ||
128 | if (!contact.homeFax().isEmpty()) | 128 | if (!contact.homeFax().isEmpty()) |
129 | { | 129 | { |
130 | PhoneNumber homefax; | 130 | PhoneNumber homefax; |
131 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | 131 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); |
132 | homefax.setNumber( contact.homeFax() ); | 132 | homefax.setNumber( contact.homeFax() ); |
133 | addr.insertPhoneNumber( homefax ); | 133 | addr.insertPhoneNumber( homefax ); |
134 | } | 134 | } |
135 | 135 | ||
136 | if (!contact.homeMobile().isEmpty()) | 136 | if (!contact.homeMobile().isEmpty()) |
137 | { | 137 | { |
138 | PhoneNumber homemobile; | 138 | PhoneNumber homemobile; |
139 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | 139 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); |
140 | homemobile.setNumber( contact.homeMobile() ); | 140 | homemobile.setNumber( contact.homeMobile() ); |
141 | addr.insertPhoneNumber( homemobile ); | 141 | addr.insertPhoneNumber( homemobile ); |
142 | } | 142 | } |
143 | 143 | ||
144 | addr.setUrl( contact.homeWebpage() ); | 144 | addr.setUrl( contact.homeWebpage() ); |
145 | 145 | ||
146 | 146 | ||
147 | // business | 147 | // business |
148 | if ((!contact.businessStreet().isEmpty()) || | 148 | if ((!contact.businessStreet().isEmpty()) || |
149 | (!contact.businessCity().isEmpty()) || | 149 | (!contact.businessCity().isEmpty()) || |
150 | (!contact.businessState().isEmpty()) || | 150 | (!contact.businessState().isEmpty()) || |
151 | (!contact.businessZip().isEmpty()) || | 151 | (!contact.businessZip().isEmpty()) || |
152 | (!contact.businessCountry().isEmpty())) | 152 | (!contact.businessCountry().isEmpty())) |
153 | { | 153 | { |
154 | Address businessaddress; | 154 | Address businessaddress; |
155 | businessaddress.setType(Address::Work); | 155 | businessaddress.setType(Address::Work); |
156 | //US businessaddress.setPostOfficeBox( "" ); | 156 | //US businessaddress.setPostOfficeBox( "" ); |
157 | //US businessaddress.setExtended( "" ); | 157 | //US businessaddress.setExtended( "" ); |
158 | businessaddress.setStreet( contact.businessStreet() ); | 158 | businessaddress.setStreet( contact.businessStreet() ); |
159 | businessaddress.setLocality( contact.businessCity() ); | 159 | businessaddress.setLocality( contact.businessCity() ); |
160 | businessaddress.setRegion( contact.businessState() ); | 160 | businessaddress.setRegion( contact.businessState() ); |
161 | businessaddress.setPostalCode( contact.businessZip() ); | 161 | businessaddress.setPostalCode( contact.businessZip() ); |
162 | businessaddress.setCountry( contact.businessCountry() ); | 162 | businessaddress.setCountry( contact.businessCountry() ); |
163 | 163 | ||
164 | addr.insertAddress( businessaddress ); | 164 | addr.insertAddress( businessaddress ); |
165 | } | 165 | } |
166 | 166 | ||
167 | 167 | ||
168 | if (!contact.businessPhone().isEmpty()) | 168 | if (!contact.businessPhone().isEmpty()) |
169 | { | 169 | { |
170 | PhoneNumber businessphone; | 170 | PhoneNumber businessphone; |
171 | businessphone.setType( PhoneNumber::Work ); | 171 | businessphone.setType( PhoneNumber::Work ); |
172 | businessphone.setNumber( contact.businessPhone() ); | 172 | businessphone.setNumber( contact.businessPhone() ); |
173 | addr.insertPhoneNumber( businessphone ); | 173 | addr.insertPhoneNumber( businessphone ); |
174 | } | 174 | } |
175 | 175 | ||
176 | if (!contact.businessFax().isEmpty()) | 176 | if (!contact.businessFax().isEmpty()) |
177 | { | 177 | { |
178 | PhoneNumber businessfax; | 178 | PhoneNumber businessfax; |
179 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | 179 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); |
180 | businessfax.setNumber( contact.businessFax() ); | 180 | businessfax.setNumber( contact.businessFax() ); |
181 | addr.insertPhoneNumber( businessfax ); | 181 | addr.insertPhoneNumber( businessfax ); |
182 | } | 182 | } |
183 | 183 | ||
184 | if (!contact.businessMobile().isEmpty()) | 184 | if (!contact.businessMobile().isEmpty()) |
185 | { | 185 | { |
186 | PhoneNumber businessmobile; | 186 | PhoneNumber businessmobile; |
187 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | 187 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); |
188 | businessmobile.setNumber( contact.businessMobile() ); | 188 | businessmobile.setNumber( contact.businessMobile() ); |
189 | addr.insertPhoneNumber( businessmobile ); | 189 | addr.insertPhoneNumber( businessmobile ); |
190 | } | 190 | } |
191 | 191 | ||
192 | if (!contact.businessPager().isEmpty()) | 192 | if (!contact.businessPager().isEmpty()) |
193 | { | 193 | { |
194 | PhoneNumber businesspager; | 194 | PhoneNumber businesspager; |
195 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | 195 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); |
196 | businesspager.setNumber( contact.businessPager() ); | 196 | businesspager.setNumber( contact.businessPager() ); |
197 | addr.insertPhoneNumber( businesspager ); | 197 | addr.insertPhoneNumber( businesspager ); |
198 | } | 198 | } |
199 | 199 | ||
200 | addr.setRole( contact.jobTitle() ); //? | 200 | addr.setRole( contact.jobTitle() ); //? |
201 | addr.setOrganization( contact.company() ); | 201 | addr.setOrganization( contact.company() ); |
202 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); | 202 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", contact.profession() ); |
203 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); | 203 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", contact.assistant() ); |
204 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); | 204 | addr.insertCustom( "KADDRESSBOOK", "X-Department", contact.department() ); |
205 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); | 205 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", contact.manager() ); |
206 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); | 206 | addr.insertCustom( "KADDRESSBOOK", "X-Office", contact.office() ); |
207 | 207 | ||
208 | //personal | 208 | //personal |
209 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); | 209 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", contact.spouse() ); |
210 | // qtopia uses this categorization: | 210 | // qtopia uses this categorization: |
211 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 211 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
212 | if (contact.gender() == PimContact::Male) | 212 | if (contact.gender() == PimContact::Male) |
213 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | 213 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); |
214 | else if (contact.gender() == PimContact::Female) | 214 | else if (contact.gender() == PimContact::Female) |
215 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | 215 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); |
216 | 216 | ||
217 | if (contact.anniversary().isValid()) { | 217 | if (contact.anniversary().isValid()) { |
218 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); | 218 | QString dt = KGlobal::locale()->formatDate(contact.anniversary(), true, KLocale::ISODate); |
219 | //US | 219 | //US |
220 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); | 220 | // qDebug("QtopiaConverter::qtopiaToAddressee found:%s", dt.latin1()); |
221 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | 221 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); |
222 | } | 222 | } |
223 | 223 | ||
224 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); | 224 | addr.insertCustom( "KADDRESSBOOK", "X-Children", contact.children() ); |
225 | if (contact.birthday().isValid()) | 225 | if (contact.birthday().isValid()) |
226 | addr.setBirthday( contact.birthday() ); | 226 | addr.setBirthday( contact.birthday() ); |
227 | 227 | ||
228 | addr.setNickName( contact.nickname() ); | 228 | addr.setNickName( contact.nickname() ); |
229 | 229 | ||
230 | // others | 230 | // others |
231 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | 231 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. |
232 | QString notes = contact.notes(); | 232 | QString notes = contact.notes(); |
233 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; | 233 | notes += "\nBusinessWebPage: " + contact.businessWebpage() + "\n"; |
234 | 234 | ||
235 | addr.setNote( contact.notes() ); | 235 | addr.setNote( contact.notes() ); |
236 | 236 | ||
237 | 237 | ||
238 | 238 | ||
239 | //US QString groups() const { return find( Qtopia::Groups ); } | 239 | //US QString groups() const { return find( Qtopia::Groups ); } |
240 | //US QStringList groupList() const; | 240 | //US QStringList groupList() const; |
241 | 241 | ||
242 | QArray<int> catArray = contact.categories(); | 242 | QArray<int> catArray = contact.categories(); |
243 | QString cat; | 243 | QString cat; |
244 | 244 | ||
245 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | 245 | for ( unsigned int i=0; i < catArray.size(); i++ ) { |
246 | cat = catDB->label("contact", catArray[i]); | 246 | cat = catDB->label("contact", catArray[i]); |
247 | if ( cat.isEmpty() ) | 247 | if ( cat.isEmpty() ) |
248 | addr.insertCategory(QString::number(catArray[i])); | 248 | addr.insertCategory(QString::number(catArray[i])); |
249 | else | 249 | else |
250 | addr.insertCategory( cat ); | 250 | addr.insertCategory( cat ); |
251 | } | 251 | } |
252 | 252 | ||
253 | return true; | 253 | return true; |
254 | } | 254 | } |
255 | 255 | ||
256 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) | 256 | bool QtopiaConverter::addresseeToQtopia( const Addressee &addr, PimContact &contact ) |
257 | { | 257 | { |
258 | 258 | ||
259 | 259 | ||
260 | 260 | ||
261 | // name | 261 | // name |
262 | contact.setLastName(addr.familyName()); | 262 | contact.setLastName(addr.familyName()); |
263 | contact.setFirstName(addr.givenName()); | 263 | contact.setFirstName(addr.givenName()); |
264 | contact.setMiddleName(addr.additionalName()); | 264 | contact.setMiddleName(addr.additionalName()); |
265 | contact.setNameTitle(addr.prefix()); | 265 | contact.setNameTitle(addr.prefix()); |
266 | contact.setSuffix(addr.suffix()); | 266 | contact.setSuffix(addr.suffix()); |
267 | contact.setFileAs(); | 267 | contact.setFileAs(); |
268 | 268 | ||
269 | 269 | ||
270 | 270 | ||
271 | QStringList emails = addr.emails(); | 271 | QStringList emails = addr.emails(); |
272 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 272 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
273 | contact.insertEmail(*it); | 273 | contact.insertEmail(*it); |
274 | } | 274 | } |
275 | contact.setDefaultEmail( addr.preferredEmail() ); | 275 | contact.setDefaultEmail( addr.preferredEmail() ); |
276 | 276 | ||
277 | 277 | ||
278 | // home | 278 | // home |
279 | const Address homeaddress = addr.address(Address::Home); | 279 | const Address homeaddress = addr.address(Address::Home); |
280 | if (!homeaddress.isEmpty()) { | 280 | if (!homeaddress.isEmpty()) { |
281 | contact.setHomeStreet(homeaddress.street()); | 281 | contact.setHomeStreet(homeaddress.street()); |
282 | contact.setHomeCity(homeaddress.locality()); | 282 | contact.setHomeCity(homeaddress.locality()); |
283 | contact.setHomeState(homeaddress.region()); | 283 | contact.setHomeState(homeaddress.region()); |
284 | contact.setHomeZip(homeaddress.postalCode()); | 284 | contact.setHomeZip(homeaddress.postalCode()); |
285 | contact.setHomeCountry(homeaddress.country()); | 285 | contact.setHomeCountry(homeaddress.country()); |
286 | } | 286 | } |
287 | 287 | ||
288 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 288 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
289 | if (!homephone.number().isEmpty()) | 289 | if (!homephone.number().isEmpty()) |
290 | contact.setHomePhone(homephone.number()); | 290 | contact.setHomePhone(homephone.number()); |
291 | 291 | ||
292 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 292 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
293 | if (!homefax.number().isEmpty()) | 293 | if (!homefax.number().isEmpty()) |
294 | contact.setHomeFax(homefax.number()); | 294 | contact.setHomeFax(homefax.number()); |
295 | 295 | ||
296 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 296 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
297 | if (!homemobile.number().isEmpty()) | 297 | if (!homemobile.number().isEmpty()) |
298 | contact.setHomeMobile(homemobile.number()); | 298 | contact.setHomeMobile(homemobile.number()); |
299 | 299 | ||
300 | contact.setHomeWebpage(addr.url().url()); | 300 | contact.setHomeWebpage(addr.url().url()); |
301 | 301 | ||
302 | 302 | ||
303 | // business | 303 | // business |
304 | const Address businessaddress = addr.address(Address::Work); | 304 | const Address businessaddress = addr.address(Address::Work); |
305 | if (!businessaddress.isEmpty()) { | 305 | if (!businessaddress.isEmpty()) { |
306 | contact.setBusinessStreet(businessaddress.street()); | 306 | contact.setBusinessStreet(businessaddress.street()); |
307 | contact.setBusinessCity(businessaddress.locality()); | 307 | contact.setBusinessCity(businessaddress.locality()); |
308 | contact.setBusinessState(businessaddress.region()); | 308 | contact.setBusinessState(businessaddress.region()); |
309 | contact.setBusinessZip(businessaddress.postalCode()); | 309 | contact.setBusinessZip(businessaddress.postalCode()); |
310 | contact.setBusinessCountry(businessaddress.country()); | 310 | contact.setBusinessCountry(businessaddress.country()); |
311 | } | 311 | } |
312 | 312 | ||
313 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 313 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
314 | if (!businessphone.number().isEmpty()) | 314 | if (!businessphone.number().isEmpty()) |
315 | contact.setBusinessPhone(businessphone.number()); | 315 | contact.setBusinessPhone(businessphone.number()); |
316 | 316 | ||
317 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 317 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
318 | if (!businessfax.number().isEmpty()) | 318 | if (!businessfax.number().isEmpty()) |
319 | contact.setBusinessFax(businessfax.number()); | 319 | contact.setBusinessFax(businessfax.number()); |
320 | 320 | ||
321 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 321 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
322 | if (!businessmobile.number().isEmpty()) | 322 | if (!businessmobile.number().isEmpty()) |
323 | contact.setBusinessMobile(businessmobile.number()); | 323 | contact.setBusinessMobile(businessmobile.number()); |
324 | 324 | ||
325 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 325 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
326 | if (!businesspager.number().isEmpty()) | 326 | if (!businesspager.number().isEmpty()) |
327 | contact.setBusinessPager(businesspager.number()); | 327 | contact.setBusinessPager(businesspager.number()); |
328 | 328 | ||
329 | contact.setJobTitle(addr.role()); | 329 | contact.setJobTitle(addr.role()); |
330 | contact.setCompany(addr.organization()); | 330 | contact.setCompany(addr.organization()); |
331 | 331 | ||
332 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); | 332 | contact.setProfession(addr.custom( "KADDRESSBOOK", "X-Profession" )); |
333 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | 333 | contact.setAssistant(addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); |
334 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); | 334 | contact.setDepartment(addr.custom( "KADDRESSBOOK", "X-Department" )); |
335 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | 335 | contact.setManager(addr.custom( "KADDRESSBOOK", "X-ManagersName" )); |
336 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); | 336 | contact.setOffice(addr.custom( "KADDRESSBOOK", "X-Office" )); |
337 | 337 | ||
338 | //personal | 338 | //personal |
339 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); | 339 | contact.setSpouse(addr.custom( "KADDRESSBOOK", "X-Spouse" )); |
340 | // qtopia uses this categorization: | 340 | // qtopia uses this categorization: |
341 | // enum GenderType { UnspecifiedGender=0, Male, Female }; | 341 | // enum GenderType { UnspecifiedGender=0, Male, Female }; |
342 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | 342 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); |
343 | if (gt = "male") | 343 | if (gt = "male") |
344 | contact.setGender(PimContact::Male); | 344 | contact.setGender(PimContact::Male); |
345 | else if (gt = "female") | 345 | else if (gt = "female") |
346 | contact.setGender(PimContact::Female); | 346 | contact.setGender(PimContact::Female); |
347 | else | 347 | else |
348 | contact.setGender(PimContact::UnspecifiedGender); | 348 | contact.setGender(PimContact::UnspecifiedGender); |
349 | 349 | ||
350 | 350 | ||
351 | QDate dt = KGlobal::locale()->readDate( | 351 | QDate dt = KGlobal::locale()->readDate( |
352 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | 352 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
353 | contact.setAnniversary( dt ); | 353 | contact.setAnniversary( dt ); |
354 | 354 | ||
355 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); | 355 | contact.setChildren(addr.custom( "KADDRESSBOOK", "X-Children" )); |
356 | 356 | ||
357 | contact.setBirthday(addr.birthday().date()); | 357 | contact.setBirthday(addr.birthday().date()); |
358 | contact.setNickname(addr.nickName()); | 358 | contact.setNickname(addr.nickName()); |
359 | 359 | ||
360 | // other | 360 | // other |
361 | contact.setNotes(addr.note()); | 361 | contact.setNotes(addr.note()); |
362 | 362 | ||
363 | //US QString groups() const { return find( Qtopia::Groups ); } | 363 | //US QString groups() const { return find( Qtopia::Groups ); } |
364 | //US QStringList groupList() const; | 364 | //US QStringList groupList() const; |
365 | 365 | ||
366 | 366 | ||
367 | QStringList cats = addr.categories(); | 367 | QStringList cats = addr.categories(); |
368 | 368 | ||
369 | QArray<int> iar; | 369 | QArray<int> iar; |
370 | if ( !cats.isEmpty() ) { | 370 | if ( !cats.isEmpty() ) { |
371 | QArray<int> iar = catDB->ids("contact", cats); | 371 | QArray<int> iar = catDB->ids("contact", cats); |
372 | contact.setCategories(iar); | 372 | contact.setCategories(iar); |
373 | } | 373 | } |
374 | 374 | ||
375 | return true; | 375 | return true; |
376 | } | 376 | } |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 935a1cf..1f90fcb 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -1,346 +1,405 @@ | |||
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 | #include <sys/types.h> | 27 | #include <sys/types.h> |
28 | #include <sys/stat.h> | 28 | #include <sys/stat.h> |
29 | #include <unistd.h> | 29 | #include <unistd.h> |
30 | 30 | ||
31 | #include <qdir.h> | 31 | #include <qdir.h> |
32 | #include <qfile.h> | 32 | #include <qfile.h> |
33 | #include <qfileinfo.h> | 33 | #include <qfileinfo.h> |
34 | #include <qregexp.h> | 34 | #include <qregexp.h> |
35 | //US #include <qtimer.h> | 35 | //US #include <qtimer.h> |
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | #include <qpe/pim/addressbookaccess.h> | 45 | #include <qpe/pim/addressbookaccess.h> |
46 | 46 | ||
47 | 47 | ||
48 | #include "resourceqtopiaconfig.h" | 48 | #include "resourceqtopiaconfig.h" |
49 | #include "stdaddressbook.h" | 49 | #include "stdaddressbook.h" |
50 | 50 | ||
51 | #include "qtopiaconverter.h" | 51 | #include "qtopiaconverter.h" |
52 | #include "syncprefwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
55 | #include <libkdepim/ksyncprofile.h> | 55 | #include <libkdepim/ksyncprofile.h> |
56 | #include <qpe/quuid.h> | 56 | #include <qpe/quuid.h> |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | extern "C" | 59 | extern "C" |
60 | { | 60 | { |
61 | void *init_microkabc_qtopia() | 61 | void *init_microkabc_qtopia() |
62 | { | 62 | { |
63 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); | 63 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); |
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | 67 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
68 | : Resource( config, syncable ), mConverter (0) | 68 | : Resource( config, syncable ), mConverter (0) |
69 | { | 69 | { |
70 | // we can not choose the filename. Therefore use the default to display | 70 | // we can not choose the filename. Therefore use the default to display |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | init( fileName ); | 72 | init( fileName ); |
73 | } | 73 | } |
74 | 74 | ||
75 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) | 75 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
76 | : Resource( 0, syncable ) | 76 | : Resource( 0, syncable ) |
77 | { | 77 | { |
78 | init( fileName ); | 78 | init( fileName ); |
79 | } | 79 | } |
80 | 80 | ||
81 | void ResourceQtopia::init( const QString &fileName ) | 81 | void ResourceQtopia::init( const QString &fileName ) |
82 | { | 82 | { |
83 | 83 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 87 | ||
88 | setFileName( fileName ); | 88 | setFileName( fileName ); |
89 | } | 89 | } |
90 | 90 | ||
91 | ResourceQtopia::~ResourceQtopia() | 91 | ResourceQtopia::~ResourceQtopia() |
92 | { | 92 | { |
93 | if (mConverter != 0) | 93 | if (mConverter != 0) |
94 | delete mConverter; | 94 | delete mConverter; |
95 | 95 | ||
96 | if(mAccess != 0) | 96 | if(mAccess != 0) |
97 | delete mAccess; | 97 | delete mAccess; |
98 | } | 98 | } |
99 | 99 | ||
100 | void ResourceQtopia::writeConfig( KConfig *config ) | 100 | void ResourceQtopia::writeConfig( KConfig *config ) |
101 | { | 101 | { |
102 | Resource::writeConfig( config ); | 102 | Resource::writeConfig( config ); |
103 | } | 103 | } |
104 | 104 | ||
105 | Ticket *ResourceQtopia::requestSaveTicket() | 105 | Ticket *ResourceQtopia::requestSaveTicket() |
106 | { | 106 | { |
107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
108 | 108 | ||
109 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | 109 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); |
110 | 110 | ||
111 | if ( !addressBook() ) return 0; | 111 | if ( !addressBook() ) return 0; |
112 | 112 | ||
113 | if ( !lock( fileName() ) ) { | 113 | if ( !lock( fileName() ) ) { |
114 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 114 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
115 | << fileName() << "'" << endl; | 115 | << fileName() << "'" << endl; |
116 | return 0; | 116 | return 0; |
117 | } | 117 | } |
118 | return createTicket( this ); | 118 | return createTicket( this ); |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | bool ResourceQtopia::doOpen() | 122 | bool ResourceQtopia::doOpen() |
123 | { | 123 | { |
124 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 124 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
125 | 125 | ||
126 | mAccess = new AddressBookAccess(); | 126 | mAccess = new AddressBookAccess(); |
127 | 127 | ||
128 | if ( !mAccess ) { | 128 | if ( !mAccess ) { |
129 | qDebug("Unable to load file() %s", fileName().latin1()); | 129 | qDebug("Unable to load file() %s", fileName().latin1()); |
130 | return false; | 130 | return false; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | if (mConverter == 0) | 134 | if (mConverter == 0) |
135 | { | 135 | { |
136 | mConverter = new QtopiaConverter(); | 136 | mConverter = new QtopiaConverter(); |
137 | bool res = mConverter->init(); | 137 | bool res = mConverter->init(); |
138 | if ( !res ) | 138 | if ( !res ) |
139 | { | 139 | { |
140 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 140 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
141 | qDebug(msg); | 141 | qDebug(msg); |
142 | delete mAccess; | 142 | delete mAccess; |
143 | mAccess = 0; | 143 | mAccess = 0; |
144 | return false; | 144 | return false; |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | return true; | 148 | return true; |
149 | } | 149 | } |
150 | 150 | ||
151 | void ResourceQtopia::doClose() | 151 | void ResourceQtopia::doClose() |
152 | { | 152 | { |
153 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 153 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
154 | 154 | ||
155 | if(mAccess) | 155 | if(mAccess) |
156 | { | 156 | { |
157 | delete mAccess; | 157 | delete mAccess; |
158 | mAccess = 0; | 158 | mAccess = 0; |
159 | } | 159 | } |
160 | // it seems so, that deletion of access deletes backend as well | 160 | // it seems so, that deletion of access deletes backend as well |
161 | //delete backend; | 161 | //delete backend; |
162 | 162 | ||
163 | return; | 163 | return; |
164 | } | 164 | } |
165 | 165 | ||
166 | bool ResourceQtopia::load() | 166 | bool ResourceQtopia::load() |
167 | { | 167 | { |
168 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | 168 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); |
169 | 169 | ||
170 | AddressBookIterator it(*mAccess); | 170 | AddressBookIterator it(*mAccess); |
171 | const PimContact* contact; | 171 | const PimContact* contact; |
172 | bool res; | 172 | bool res; |
173 | 173 | ||
174 | for (contact=it.toFirst(); it.current(); ++it) | 174 | for (contact=it.toFirst(); it.current(); ++it) |
175 | { | 175 | { |
176 | contact = it.current(); | 176 | contact = it.current(); |
177 | 177 | ||
178 | KABC::Addressee addressee; | 178 | KABC::Addressee addressee; |
179 | 179 | ||
180 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 180 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
181 | 181 | ||
182 | if ( !addressee.isEmpty() && res ) | 182 | if ( !addressee.isEmpty() && res ) |
183 | { | 183 | { |
184 | addressee.setResource( this ); | 184 | addressee.setResource( this ); |
185 | addressBook()->insertAddressee( addressee ); | 185 | addressBook()->insertAddressee( addressee ); |
186 | } | 186 | } |
187 | } | 187 | } |
188 | 188 | ||
189 | return true; | 189 | return true; |
190 | } | 190 | } |
191 | 191 | ||
192 | bool ResourceQtopia::save( Ticket *ticket ) | 192 | bool ResourceQtopia::save( Ticket *ticket ) |
193 | { | 193 | { |
194 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); | 194 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
195 | 195 | ||
196 | mDirWatch.stopScan(); | 196 | mDirWatch.stopScan(); |
197 | 197 | ||
198 | KABC::AddressBook::Iterator it; | 198 | KABC::AddressBook::Iterator it; |
199 | bool res; | 199 | bool res; |
200 | 200 | KABC::Addressee::List changedAddressees; | |
201 | QStringList addedUID; | ||
201 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 202 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
202 | //KABC::Addressee addressee = (*it); | 203 | //KABC::Addressee addressee = (*it); |
204 | // qDebug("AAAfor uid %s ", (*it).originalExternalUID().latin1() ); | ||
203 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 205 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
204 | QUuid uid( (*it).originalExternalUID() ); | 206 | QUuid uid( (*it).originalExternalUID() ); |
205 | bool ok; | 207 | bool ok; |
206 | PimContact c = mAccess->contactForId( uid, &ok ); | 208 | PimContact c = mAccess->contactForId( uid, &ok ); |
209 | qDebug("ResourceQtopia::save:Found %d for uid %s ", ok,(*it).originalExternalUID().latin1() ); | ||
207 | res = mConverter->addresseeToQtopia( *it, c ); | 210 | res = mConverter->addresseeToQtopia( *it, c ); |
208 | if (res == true) { | 211 | if (res == true) { |
209 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 212 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
210 | mAccess->addContact(c); | 213 | qDebug("skipping adding of contact "); |
211 | KABC::Addressee addressee; | 214 | continue; |
212 | mConverter->qtopiaToAddressee( c, addressee ); | 215 | PimContact e; |
213 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 216 | AddressBookAccess Access2; |
214 | addressBook()->insertAddressee( addressee ); | 217 | Access2.addContact(e); |
218 | const PimContact* contact; | ||
219 | bool res; | ||
220 | QString uid2, Ouid; | ||
221 | AddressBookIterator itt(Access2); | ||
222 | for (contact=itt.toFirst(); itt.current(); ++itt) | ||
223 | { | ||
224 | contact = itt.current(); | ||
225 | QString exuid = contact->uid().toString(); | ||
226 | Ouid =exuid; | ||
227 | int ente = exuid.find( "-0000"); | ||
228 | if ( exuid.left(1) == "{" ) | ||
229 | exuid = exuid.mid(1); | ||
230 | if ( ente > -1 ) | ||
231 | exuid = exuid.left( ente-1 ); | ||
232 | uid2 = exuid; | ||
233 | qDebug("trying find uid "); | ||
234 | if ( !addressBook()->containsExternalUid( uid2 ) ) { | ||
235 | qDebug("ab not contains "); | ||
236 | if ( !addedUID.contains( uid2 )) { | ||
237 | qDebug("list not contains "); | ||
238 | break; | ||
239 | } | ||
240 | } | ||
241 | |||
242 | } | ||
243 | if ( !itt.current()) { | ||
244 | qDebug("ERROR uid "); | ||
245 | continue; | ||
246 | } | ||
247 | else | ||
248 | qDebug("ADD uid detected "); | ||
249 | |||
250 | |||
251 | QUuid uid3( Ouid); | ||
252 | PimContact d = Access2.contactForId( uid3, &ok ); | ||
253 | if ( ! ok ) { | ||
254 | qDebug("ADD: Error getting new uid "); | ||
255 | } else { | ||
256 | qDebug("NEW UID found "); | ||
257 | PimContact g = mAccess->contactForId( c.uid(), &ok ); | ||
258 | KABC::Addressee addressee; | ||
259 | mConverter->qtopiaToAddressee( g, addressee ); | ||
260 | addressee.setUid((*it).uid() ); | ||
261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
262 | changedAddressees.append( addressee ); | ||
263 | addedUID.append( uid2 ); | ||
264 | } | ||
265 | |||
215 | 266 | ||
216 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 267 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
268 | qDebug("Remove contact "); | ||
217 | if ( ok ) | 269 | if ( ok ) |
218 | mAccess->removeContact(c); | 270 | mAccess->removeContact(c); |
219 | else | 271 | else |
220 | qDebug("Error revoe contact from qtopia "); | 272 | qDebug("Error remove contact from qtopia "); |
221 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 273 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
222 | if ( ok ) { | 274 | if ( ok ) { |
275 | qDebug("Update contact "); | ||
223 | mAccess->updateContact(c); | 276 | mAccess->updateContact(c); |
277 | PimContact g = mAccess->contactForId( c.uid(), &ok ); | ||
224 | KABC::Addressee addressee; | 278 | KABC::Addressee addressee; |
225 | mConverter->qtopiaToAddressee( c, addressee ); | 279 | mConverter->qtopiaToAddressee( g, addressee ); |
280 | addressee.setUid((*it).uid() ); | ||
226 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | 281 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); |
227 | addressBook()->insertAddressee( addressee ); | 282 | changedAddressees.append( addressee ); |
228 | } | 283 | } |
229 | else | 284 | else |
230 | qDebug("Error update contact from qtopia "); | 285 | qDebug("Error update contact from qtopia "); |
231 | 286 | ||
232 | } | 287 | } |
233 | 288 | ||
234 | } else { | 289 | } else { |
235 | qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); | 290 | qDebug("Unable to convert Addressee %s", (*it).formattedName().latin1()); |
236 | } | 291 | } |
237 | } | 292 | } |
238 | } | 293 | } |
239 | 294 | ||
240 | // mAccess->addressBookUpdated(); | 295 | KABC::Addressee::List::Iterator it2; |
296 | for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) | ||
297 | addressBook()->insertAddressee((*it2)); | ||
298 | |||
299 | |||
241 | 300 | ||
242 | mDirWatch.startScan(); | 301 | mDirWatch.startScan(); |
243 | 302 | ||
244 | delete ticket; | 303 | delete ticket; |
245 | unlock( fileName() ); | 304 | unlock( fileName() ); |
246 | 305 | ||
247 | return true; | 306 | return true; |
248 | } | 307 | } |
249 | 308 | ||
250 | bool ResourceQtopia::lock( const QString &lockfileName ) | 309 | bool ResourceQtopia::lock( const QString &lockfileName ) |
251 | { | 310 | { |
252 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); | 311 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
253 | 312 | ||
254 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | 313 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; |
255 | 314 | ||
256 | QString fn = lockfileName; | 315 | QString fn = lockfileName; |
257 | 316 | ||
258 | KURL url(fn); | 317 | KURL url(fn); |
259 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 318 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
260 | 319 | ||
261 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 320 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
262 | 321 | ||
263 | if (QFile::exists( lockName )) | 322 | if (QFile::exists( lockName )) |
264 | { | 323 | { |
265 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); | 324 | qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); |
266 | return false; | 325 | return false; |
267 | } | 326 | } |
268 | 327 | ||
269 | QString lockUniqueName; | 328 | QString lockUniqueName; |
270 | lockUniqueName = fn + KApplication::randomString( 8 ); | 329 | lockUniqueName = fn + KApplication::randomString( 8 ); |
271 | 330 | ||
272 | url = lockUniqueName; | 331 | url = lockUniqueName; |
273 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 332 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
274 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 333 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
275 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 334 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
276 | 335 | ||
277 | // Create unique file | 336 | // Create unique file |
278 | QFile file( mLockUniqueName ); | 337 | QFile file( mLockUniqueName ); |
279 | file.open( IO_WriteOnly ); | 338 | file.open( IO_WriteOnly ); |
280 | file.close(); | 339 | file.close(); |
281 | 340 | ||
282 | // Create lock file | 341 | // Create lock file |
283 | int result = 0; | 342 | int result = 0; |
284 | #ifndef _WIN32_ | 343 | #ifndef _WIN32_ |
285 | result = ::link( QFile::encodeName( mLockUniqueName ), | 344 | result = ::link( QFile::encodeName( mLockUniqueName ), |
286 | QFile::encodeName( lockName ) ); | 345 | QFile::encodeName( lockName ) ); |
287 | #endif | 346 | #endif |
288 | if ( result == 0 ) { | 347 | if ( result == 0 ) { |
289 | addressBook()->emitAddressBookLocked(); | 348 | addressBook()->emitAddressBookLocked(); |
290 | return true; | 349 | return true; |
291 | } | 350 | } |
292 | 351 | ||
293 | // TODO: check stat | 352 | // TODO: check stat |
294 | 353 | ||
295 | return false; | 354 | return false; |
296 | } | 355 | } |
297 | 356 | ||
298 | void ResourceQtopia::unlock( const QString &fileName ) | 357 | void ResourceQtopia::unlock( const QString &fileName ) |
299 | { | 358 | { |
300 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | 359 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); |
301 | 360 | ||
302 | QString fn = fileName; | 361 | QString fn = fileName; |
303 | KURL url(fn); | 362 | KURL url(fn); |
304 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 363 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
305 | 364 | ||
306 | QFile::remove( lockName ); | 365 | QFile::remove( lockName ); |
307 | QFile::remove( mLockUniqueName ); | 366 | QFile::remove( mLockUniqueName ); |
308 | addressBook()->emitAddressBookUnlocked(); | 367 | addressBook()->emitAddressBookUnlocked(); |
309 | } | 368 | } |
310 | 369 | ||
311 | void ResourceQtopia::setFileName( const QString &newFileName ) | 370 | void ResourceQtopia::setFileName( const QString &newFileName ) |
312 | { | 371 | { |
313 | mDirWatch.stopScan(); | 372 | mDirWatch.stopScan(); |
314 | mDirWatch.removeFile( fileName() ); | 373 | mDirWatch.removeFile( fileName() ); |
315 | 374 | ||
316 | Resource::setFileName( newFileName ); | 375 | Resource::setFileName( newFileName ); |
317 | 376 | ||
318 | mDirWatch.addFile( fileName() ); | 377 | mDirWatch.addFile( fileName() ); |
319 | mDirWatch.startScan(); | 378 | mDirWatch.startScan(); |
320 | } | 379 | } |
321 | 380 | ||
322 | 381 | ||
323 | void ResourceQtopia::fileChanged() | 382 | void ResourceQtopia::fileChanged() |
324 | { | 383 | { |
325 | // There is a small theoretical chance that KDirWatch calls us before | 384 | // There is a small theoretical chance that KDirWatch calls us before |
326 | // we are fully constructed | 385 | // we are fully constructed |
327 | if (!addressBook()) | 386 | if (!addressBook()) |
328 | return; | 387 | return; |
329 | 388 | ||
330 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 389 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
331 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
332 | load(); | 391 | load(); |
333 | addressBook()->emitAddressBookChanged(); | 392 | addressBook()->emitAddressBookChanged(); |
334 | } | 393 | } |
335 | } | 394 | } |
336 | 395 | ||
337 | void ResourceQtopia::removeAddressee( const Addressee &addr ) | 396 | void ResourceQtopia::removeAddressee( const Addressee &addr ) |
338 | { | 397 | { |
339 | } | 398 | } |
340 | 399 | ||
341 | void ResourceQtopia::cleanUp() | 400 | void ResourceQtopia::cleanUp() |
342 | { | 401 | { |
343 | unlock( fileName() ); | 402 | unlock( fileName() ); |
344 | } | 403 | } |
345 | 404 | ||
346 | //US #include "resourceqtopia.moc" | 405 | //US #include "resourceqtopia.moc" |