author | zautrix <zautrix> | 2005-01-26 01:11:54 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2005-01-26 01:11:54 (UTC) |
commit | ab91893abef351f53275248a50032a6d5175132a (patch) (unidiff) | |
tree | 7ecb1aba3741dbffb34ad28787538db942e4d448 | |
parent | c3ec0a5a43fb328f2d190b8adee1ef662746fb41 (diff) | |
download | kdepimpi-ab91893abef351f53275248a50032a6d5175132a.zip kdepimpi-ab91893abef351f53275248a50032a6d5175132a.tar.gz kdepimpi-ab91893abef351f53275248a50032a6d5175132a.tar.bz2 |
fixes
-rw-r--r-- | kabc/addressbook.cpp | 10 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 52 |
3 files changed, 12 insertions, 54 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 9e61261..f3744bc 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp | |||
@@ -1,1266 +1,1266 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> | 3 | Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public | 6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. | 8 | version 2 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. | 13 | Library General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Library General Public License | 15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to | 16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | Boston, MA 02111-1307, USA. | 18 | Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /* | 21 | /* |
22 | Enhanced Version of the file for platform independent KDE tools. | 22 | Enhanced Version of the file for platform independent KDE tools. |
23 | Copyright (c) 2004 Ulf Schenk | 23 | Copyright (c) 2004 Ulf Schenk |
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | /*US | 28 | /*US |
29 | 29 | ||
30 | #include <qfile.h> | 30 | #include <qfile.h> |
31 | #include <qregexp.h> | 31 | #include <qregexp.h> |
32 | #include <qtimer.h> | 32 | #include <qtimer.h> |
33 | 33 | ||
34 | #include <kapplication.h> | 34 | #include <kapplication.h> |
35 | #include <kinstance.h> | 35 | #include <kinstance.h> |
36 | #include <kstandarddirs.h> | 36 | #include <kstandarddirs.h> |
37 | 37 | ||
38 | #include "errorhandler.h" | 38 | #include "errorhandler.h" |
39 | */ | 39 | */ |
40 | #include <qptrlist.h> | 40 | #include <qptrlist.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | #include <qfile.h> | 42 | #include <qfile.h> |
43 | #include <qregexp.h> | 43 | #include <qregexp.h> |
44 | 44 | ||
45 | #include <kglobal.h> | 45 | #include <kglobal.h> |
46 | #include <klocale.h> | 46 | #include <klocale.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | #include <kdebug.h> | 48 | #include <kdebug.h> |
49 | #include <libkcal/syncdefines.h> | 49 | #include <libkcal/syncdefines.h> |
50 | #include <libkdepim/phoneaccess.h> | 50 | #include <libkdepim/phoneaccess.h> |
51 | #include "addressbook.h" | 51 | #include "addressbook.h" |
52 | #include "resource.h" | 52 | #include "resource.h" |
53 | #include "vcardconverter.h" | 53 | #include "vcardconverter.h" |
54 | #include "vcardparser/vcardtool.h" | 54 | #include "vcardparser/vcardtool.h" |
55 | 55 | ||
56 | //US #include "addressbook.moc" | 56 | //US #include "addressbook.moc" |
57 | 57 | ||
58 | using namespace KABC; | 58 | using namespace KABC; |
59 | 59 | ||
60 | struct AddressBook::AddressBookData | 60 | struct AddressBook::AddressBookData |
61 | { | 61 | { |
62 | Addressee::List mAddressees; | 62 | Addressee::List mAddressees; |
63 | Addressee::List mRemovedAddressees; | 63 | Addressee::List mRemovedAddressees; |
64 | Field::List mAllFields; | 64 | Field::List mAllFields; |
65 | KConfig *mConfig; | 65 | KConfig *mConfig; |
66 | KRES::Manager<Resource> *mManager; | 66 | KRES::Manager<Resource> *mManager; |
67 | //US ErrorHandler *mErrorHandler; | 67 | //US ErrorHandler *mErrorHandler; |
68 | }; | 68 | }; |
69 | 69 | ||
70 | struct AddressBook::Iterator::IteratorData | 70 | struct AddressBook::Iterator::IteratorData |
71 | { | 71 | { |
72 | Addressee::List::Iterator mIt; | 72 | Addressee::List::Iterator mIt; |
73 | }; | 73 | }; |
74 | 74 | ||
75 | struct AddressBook::ConstIterator::ConstIteratorData | 75 | struct AddressBook::ConstIterator::ConstIteratorData |
76 | { | 76 | { |
77 | Addressee::List::ConstIterator mIt; | 77 | Addressee::List::ConstIterator mIt; |
78 | }; | 78 | }; |
79 | 79 | ||
80 | AddressBook::Iterator::Iterator() | 80 | AddressBook::Iterator::Iterator() |
81 | { | 81 | { |
82 | d = new IteratorData; | 82 | d = new IteratorData; |
83 | } | 83 | } |
84 | 84 | ||
85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) | 85 | AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) |
86 | { | 86 | { |
87 | d = new IteratorData; | 87 | d = new IteratorData; |
88 | d->mIt = i.d->mIt; | 88 | d->mIt = i.d->mIt; |
89 | } | 89 | } |
90 | 90 | ||
91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) | 91 | AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) |
92 | { | 92 | { |
93 | if( this == &i ) return *this; // guard against self assignment | 93 | if( this == &i ) return *this; // guard against self assignment |
94 | delete d; // delete the old data the Iterator was completely constructed before | 94 | delete d; // delete the old data the Iterator was completely constructed before |
95 | d = new IteratorData; | 95 | d = new IteratorData; |
96 | d->mIt = i.d->mIt; | 96 | d->mIt = i.d->mIt; |
97 | return *this; | 97 | return *this; |
98 | } | 98 | } |
99 | 99 | ||
100 | AddressBook::Iterator::~Iterator() | 100 | AddressBook::Iterator::~Iterator() |
101 | { | 101 | { |
102 | delete d; | 102 | delete d; |
103 | } | 103 | } |
104 | 104 | ||
105 | const Addressee &AddressBook::Iterator::operator*() const | 105 | const Addressee &AddressBook::Iterator::operator*() const |
106 | { | 106 | { |
107 | return *(d->mIt); | 107 | return *(d->mIt); |
108 | } | 108 | } |
109 | 109 | ||
110 | Addressee &AddressBook::Iterator::operator*() | 110 | Addressee &AddressBook::Iterator::operator*() |
111 | { | 111 | { |
112 | return *(d->mIt); | 112 | return *(d->mIt); |
113 | } | 113 | } |
114 | 114 | ||
115 | Addressee *AddressBook::Iterator::operator->() | 115 | Addressee *AddressBook::Iterator::operator->() |
116 | { | 116 | { |
117 | return &(*(d->mIt)); | 117 | return &(*(d->mIt)); |
118 | } | 118 | } |
119 | 119 | ||
120 | AddressBook::Iterator &AddressBook::Iterator::operator++() | 120 | AddressBook::Iterator &AddressBook::Iterator::operator++() |
121 | { | 121 | { |
122 | (d->mIt)++; | 122 | (d->mIt)++; |
123 | return *this; | 123 | return *this; |
124 | } | 124 | } |
125 | 125 | ||
126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) | 126 | AddressBook::Iterator &AddressBook::Iterator::operator++(int) |
127 | { | 127 | { |
128 | (d->mIt)++; | 128 | (d->mIt)++; |
129 | return *this; | 129 | return *this; |
130 | } | 130 | } |
131 | 131 | ||
132 | AddressBook::Iterator &AddressBook::Iterator::operator--() | 132 | AddressBook::Iterator &AddressBook::Iterator::operator--() |
133 | { | 133 | { |
134 | (d->mIt)--; | 134 | (d->mIt)--; |
135 | return *this; | 135 | return *this; |
136 | } | 136 | } |
137 | 137 | ||
138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) | 138 | AddressBook::Iterator &AddressBook::Iterator::operator--(int) |
139 | { | 139 | { |
140 | (d->mIt)--; | 140 | (d->mIt)--; |
141 | return *this; | 141 | return *this; |
142 | } | 142 | } |
143 | 143 | ||
144 | bool AddressBook::Iterator::operator==( const Iterator &it ) | 144 | bool AddressBook::Iterator::operator==( const Iterator &it ) |
145 | { | 145 | { |
146 | return ( d->mIt == it.d->mIt ); | 146 | return ( d->mIt == it.d->mIt ); |
147 | } | 147 | } |
148 | 148 | ||
149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) | 149 | bool AddressBook::Iterator::operator!=( const Iterator &it ) |
150 | { | 150 | { |
151 | return ( d->mIt != it.d->mIt ); | 151 | return ( d->mIt != it.d->mIt ); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | AddressBook::ConstIterator::ConstIterator() | 155 | AddressBook::ConstIterator::ConstIterator() |
156 | { | 156 | { |
157 | d = new ConstIteratorData; | 157 | d = new ConstIteratorData; |
158 | } | 158 | } |
159 | 159 | ||
160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) | 160 | AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) |
161 | { | 161 | { |
162 | d = new ConstIteratorData; | 162 | d = new ConstIteratorData; |
163 | d->mIt = i.d->mIt; | 163 | d->mIt = i.d->mIt; |
164 | } | 164 | } |
165 | 165 | ||
166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) | 166 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) |
167 | { | 167 | { |
168 | if( this == &i ) return *this; // guard for self assignment | 168 | if( this == &i ) return *this; // guard for self assignment |
169 | delete d; // delete the old data because the Iterator was really constructed before | 169 | delete d; // delete the old data because the Iterator was really constructed before |
170 | d = new ConstIteratorData; | 170 | d = new ConstIteratorData; |
171 | d->mIt = i.d->mIt; | 171 | d->mIt = i.d->mIt; |
172 | return *this; | 172 | return *this; |
173 | } | 173 | } |
174 | 174 | ||
175 | AddressBook::ConstIterator::~ConstIterator() | 175 | AddressBook::ConstIterator::~ConstIterator() |
176 | { | 176 | { |
177 | delete d; | 177 | delete d; |
178 | } | 178 | } |
179 | 179 | ||
180 | const Addressee &AddressBook::ConstIterator::operator*() const | 180 | const Addressee &AddressBook::ConstIterator::operator*() const |
181 | { | 181 | { |
182 | return *(d->mIt); | 182 | return *(d->mIt); |
183 | } | 183 | } |
184 | 184 | ||
185 | const Addressee* AddressBook::ConstIterator::operator->() const | 185 | const Addressee* AddressBook::ConstIterator::operator->() const |
186 | { | 186 | { |
187 | return &(*(d->mIt)); | 187 | return &(*(d->mIt)); |
188 | } | 188 | } |
189 | 189 | ||
190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() | 190 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() |
191 | { | 191 | { |
192 | (d->mIt)++; | 192 | (d->mIt)++; |
193 | return *this; | 193 | return *this; |
194 | } | 194 | } |
195 | 195 | ||
196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) | 196 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) |
197 | { | 197 | { |
198 | (d->mIt)++; | 198 | (d->mIt)++; |
199 | return *this; | 199 | return *this; |
200 | } | 200 | } |
201 | 201 | ||
202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() | 202 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() |
203 | { | 203 | { |
204 | (d->mIt)--; | 204 | (d->mIt)--; |
205 | return *this; | 205 | return *this; |
206 | } | 206 | } |
207 | 207 | ||
208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) | 208 | AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) |
209 | { | 209 | { |
210 | (d->mIt)--; | 210 | (d->mIt)--; |
211 | return *this; | 211 | return *this; |
212 | } | 212 | } |
213 | 213 | ||
214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) | 214 | bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) |
215 | { | 215 | { |
216 | return ( d->mIt == it.d->mIt ); | 216 | return ( d->mIt == it.d->mIt ); |
217 | } | 217 | } |
218 | 218 | ||
219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) | 219 | bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) |
220 | { | 220 | { |
221 | return ( d->mIt != it.d->mIt ); | 221 | return ( d->mIt != it.d->mIt ); |
222 | } | 222 | } |
223 | 223 | ||
224 | 224 | ||
225 | AddressBook::AddressBook() | 225 | AddressBook::AddressBook() |
226 | { | 226 | { |
227 | init(0, "contact"); | 227 | init(0, "contact"); |
228 | } | 228 | } |
229 | 229 | ||
230 | AddressBook::AddressBook( const QString &config ) | 230 | AddressBook::AddressBook( const QString &config ) |
231 | { | 231 | { |
232 | init(config, "contact"); | 232 | init(config, "contact"); |
233 | } | 233 | } |
234 | 234 | ||
235 | AddressBook::AddressBook( const QString &config, const QString &family ) | 235 | AddressBook::AddressBook( const QString &config, const QString &family ) |
236 | { | 236 | { |
237 | init(config, family); | 237 | init(config, family); |
238 | 238 | ||
239 | } | 239 | } |
240 | 240 | ||
241 | // the default family is "contact" | 241 | // the default family is "contact" |
242 | void AddressBook::init(const QString &config, const QString &family ) | 242 | void AddressBook::init(const QString &config, const QString &family ) |
243 | { | 243 | { |
244 | blockLSEchange = false; | 244 | blockLSEchange = false; |
245 | d = new AddressBookData; | 245 | d = new AddressBookData; |
246 | QString fami = family; | 246 | QString fami = family; |
247 | if (config != 0) { | 247 | if (config != 0) { |
248 | if ( family == "syncContact" ) { | 248 | if ( family == "syncContact" ) { |
249 | qDebug("creating sync config "); | 249 | qDebug("creating sync config "); |
250 | fami = "contact"; | 250 | fami = "contact"; |
251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); | 251 | KConfig* con = new KConfig( locateLocal("config", "syncContactrc") ); |
252 | con->setGroup( "General" ); | 252 | con->setGroup( "General" ); |
253 | con->writeEntry( "ResourceKeys", QString("sync") ); | 253 | con->writeEntry( "ResourceKeys", QString("sync") ); |
254 | con->writeEntry( "Standard", QString("sync") ); | 254 | con->writeEntry( "Standard", QString("sync") ); |
255 | con->setGroup( "Resource_sync" ); | 255 | con->setGroup( "Resource_sync" ); |
256 | con->writeEntry( "FileName", config ); | 256 | con->writeEntry( "FileName", config ); |
257 | con->writeEntry( "FileFormat", QString("vcard") ); | 257 | con->writeEntry( "FileFormat", QString("vcard") ); |
258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); | 258 | con->writeEntry( "ResourceIdentifier", QString("sync") ); |
259 | con->writeEntry( "ResourceName", QString("sync_res") ); | 259 | con->writeEntry( "ResourceName", QString("sync_res") ); |
260 | if ( config.right(4) == ".xml" ) | 260 | if ( config.right(4) == ".xml" ) |
261 | con->writeEntry( "ResourceType", QString("qtopia") ); | 261 | con->writeEntry( "ResourceType", QString("qtopia") ); |
262 | else if ( config == "sharp" ) { | 262 | else if ( config == "sharp" ) { |
263 | con->writeEntry( "ResourceType", QString("sharp") ); | 263 | con->writeEntry( "ResourceType", QString("sharp") ); |
264 | } else { | 264 | } else { |
265 | con->writeEntry( "ResourceType", QString("file") ); | 265 | con->writeEntry( "ResourceType", QString("file") ); |
266 | } | 266 | } |
267 | //con->sync(); | 267 | //con->sync(); |
268 | d->mConfig = con; | 268 | d->mConfig = con; |
269 | } | 269 | } |
270 | else | 270 | else |
271 | d->mConfig = new KConfig( locateLocal("config", config) ); | 271 | d->mConfig = new KConfig( locateLocal("config", config) ); |
272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); | 272 | // qDebug("AddressBook::init 1 config=%s",config.latin1() ); |
273 | } | 273 | } |
274 | else { | 274 | else { |
275 | d->mConfig = 0; | 275 | d->mConfig = 0; |
276 | // qDebug("AddressBook::init 1 config=0"); | 276 | // qDebug("AddressBook::init 1 config=0"); |
277 | } | 277 | } |
278 | 278 | ||
279 | //US d->mErrorHandler = 0; | 279 | //US d->mErrorHandler = 0; |
280 | d->mManager = new KRES::Manager<Resource>( fami ); | 280 | d->mManager = new KRES::Manager<Resource>( fami ); |
281 | d->mManager->readConfig( d->mConfig ); | 281 | d->mManager->readConfig( d->mConfig ); |
282 | if ( family == "syncContact" ) { | 282 | if ( family == "syncContact" ) { |
283 | KRES::Manager<Resource> *manager = d->mManager; | 283 | KRES::Manager<Resource> *manager = d->mManager; |
284 | KRES::Manager<Resource>::ActiveIterator it; | 284 | KRES::Manager<Resource>::ActiveIterator it; |
285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 285 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
286 | (*it)->setAddressBook( this ); | 286 | (*it)->setAddressBook( this ); |
287 | if ( !(*it)->open() ) | 287 | if ( !(*it)->open() ) |
288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); | 288 | error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); |
289 | } | 289 | } |
290 | Resource *res = standardResource(); | 290 | Resource *res = standardResource(); |
291 | if ( !res ) { | 291 | if ( !res ) { |
292 | qDebug("ERROR: no standard resource"); | 292 | qDebug("ERROR: no standard resource"); |
293 | res = manager->createResource( "file" ); | 293 | res = manager->createResource( "file" ); |
294 | if ( res ) | 294 | if ( res ) |
295 | { | 295 | { |
296 | addResource( res ); | 296 | addResource( res ); |
297 | } | 297 | } |
298 | else | 298 | else |
299 | qDebug(" No resource available!!!"); | 299 | qDebug(" No resource available!!!"); |
300 | } | 300 | } |
301 | setStandardResource( res ); | 301 | setStandardResource( res ); |
302 | manager->writeConfig(); | 302 | manager->writeConfig(); |
303 | } | 303 | } |
304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, | 304 | addCustomField( i18n( "Department" ), KABC::Field::Organization, |
305 | "X-Department", "KADDRESSBOOK" ); | 305 | "X-Department", "KADDRESSBOOK" ); |
306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, | 306 | addCustomField( i18n( "Profession" ), KABC::Field::Organization, |
307 | "X-Profession", "KADDRESSBOOK" ); | 307 | "X-Profession", "KADDRESSBOOK" ); |
308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, | 308 | addCustomField( i18n( "Assistant's Name" ), KABC::Field::Organization, |
309 | "X-AssistantsName", "KADDRESSBOOK" ); | 309 | "X-AssistantsName", "KADDRESSBOOK" ); |
310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, | 310 | addCustomField( i18n( "Manager's Name" ), KABC::Field::Organization, |
311 | "X-ManagersName", "KADDRESSBOOK" ); | 311 | "X-ManagersName", "KADDRESSBOOK" ); |
312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, | 312 | addCustomField( i18n( "Spouse's Name" ), KABC::Field::Personal, |
313 | "X-SpousesName", "KADDRESSBOOK" ); | 313 | "X-SpousesName", "KADDRESSBOOK" ); |
314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, | 314 | addCustomField( i18n( "Office" ), KABC::Field::Personal, |
315 | "X-Office", "KADDRESSBOOK" ); | 315 | "X-Office", "KADDRESSBOOK" ); |
316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, | 316 | addCustomField( i18n( "IM Address" ), KABC::Field::Personal, |
317 | "X-IMAddress", "KADDRESSBOOK" ); | 317 | "X-IMAddress", "KADDRESSBOOK" ); |
318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, | 318 | addCustomField( i18n( "Anniversary" ), KABC::Field::Personal, |
319 | "X-Anniversary", "KADDRESSBOOK" ); | 319 | "X-Anniversary", "KADDRESSBOOK" ); |
320 | 320 | ||
321 | //US added this field to become compatible with Opie/qtopia addressbook | 321 | //US added this field to become compatible with Opie/qtopia addressbook |
322 | // values can be "female" or "male" or "". An empty field represents undefined. | 322 | // values can be "female" or "male" or "". An empty field represents undefined. |
323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, | 323 | addCustomField( i18n( "Gender" ), KABC::Field::Personal, |
324 | "X-Gender", "KADDRESSBOOK" ); | 324 | "X-Gender", "KADDRESSBOOK" ); |
325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, | 325 | addCustomField( i18n( "Children" ), KABC::Field::Personal, |
326 | "X-Children", "KADDRESSBOOK" ); | 326 | "X-Children", "KADDRESSBOOK" ); |
327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, | 327 | addCustomField( i18n( "FreeBusyUrl" ), KABC::Field::Personal, |
328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); | 328 | "X-FreeBusyUrl", "KADDRESSBOOK" ); |
329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, | 329 | addCustomField( i18n( "ExternalID" ), KABC::Field::Personal, |
330 | "X-ExternalID", "KADDRESSBOOK" ); | 330 | "X-ExternalID", "KADDRESSBOOK" ); |
331 | } | 331 | } |
332 | 332 | ||
333 | AddressBook::~AddressBook() | 333 | AddressBook::~AddressBook() |
334 | { | 334 | { |
335 | delete d->mConfig; d->mConfig = 0; | 335 | delete d->mConfig; d->mConfig = 0; |
336 | delete d->mManager; d->mManager = 0; | 336 | delete d->mManager; d->mManager = 0; |
337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; | 337 | //US delete d->mErrorHandler; d->mErrorHandler = 0; |
338 | delete d; d = 0; | 338 | delete d; d = 0; |
339 | } | 339 | } |
340 | 340 | ||
341 | bool AddressBook::load() | 341 | bool AddressBook::load() |
342 | { | 342 | { |
343 | 343 | ||
344 | clear(); | 344 | clear(); |
345 | KRES::Manager<Resource>::ActiveIterator it; | 345 | KRES::Manager<Resource>::ActiveIterator it; |
346 | bool ok = true; | 346 | bool ok = true; |
347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 347 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
348 | if ( !(*it)->load() ) { | 348 | if ( !(*it)->load() ) { |
349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); | 349 | qDebug( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); |
350 | ok = false; | 350 | ok = false; |
351 | } else { | 351 | } else { |
352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); | 352 | qDebug( i18n("Resource loaded: '%1'").arg( (*it)->resourceName() ) ); |
353 | } | 353 | } |
354 | // mark all addressees as unchanged | 354 | // mark all addressees as unchanged |
355 | Addressee::List::Iterator addrIt; | 355 | Addressee::List::Iterator addrIt; |
356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { | 356 | for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) { |
357 | (*addrIt).setChanged( false ); | 357 | (*addrIt).setChanged( false ); |
358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); | 358 | QString id = (*addrIt).custom( "KADDRESSBOOK", "X-ExternalID" ); |
359 | if ( !id.isEmpty() ) { | 359 | if ( !id.isEmpty() ) { |
360 | //qDebug("setId aa %s ", id.latin1()); | 360 | //qDebug("setId aa %s ", id.latin1()); |
361 | (*addrIt).setIDStr(id ); | 361 | (*addrIt).setIDStr(id ); |
362 | } | 362 | } |
363 | } | 363 | } |
364 | blockLSEchange = true; | 364 | blockLSEchange = true; |
365 | return ok; | 365 | return ok; |
366 | } | 366 | } |
367 | 367 | ||
368 | bool AddressBook::save( Ticket *ticket ) | 368 | bool AddressBook::save( Ticket *ticket ) |
369 | { | 369 | { |
370 | kdDebug(5700) << "AddressBook::save()"<< endl; | 370 | kdDebug(5700) << "AddressBook::save()"<< endl; |
371 | 371 | ||
372 | if ( ticket->resource() ) { | 372 | if ( ticket->resource() ) { |
373 | deleteRemovedAddressees(); | 373 | deleteRemovedAddressees(); |
374 | return ticket->resource()->save( ticket ); | 374 | return ticket->resource()->save( ticket ); |
375 | } | 375 | } |
376 | 376 | ||
377 | return false; | 377 | return false; |
378 | } | 378 | } |
379 | // exports all Addressees, which are syncable | 379 | // exports all Addressees, which are syncable |
380 | void AddressBook::export2File( QString fileName ) | 380 | void AddressBook::export2File( QString fileName ) |
381 | { | 381 | { |
382 | 382 | ||
383 | QFile outFile( fileName ); | 383 | QFile outFile( fileName ); |
384 | if ( !outFile.open( IO_WriteOnly ) ) { | 384 | if ( !outFile.open( IO_WriteOnly ) ) { |
385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); | 385 | QString text = i18n( "<qt>Unable to open file <b>%1</b> for export.</qt>" ); |
386 | KMessageBox::error( 0, text.arg( fileName ) ); | 386 | KMessageBox::error( 0, text.arg( fileName ) ); |
387 | return ; | 387 | return ; |
388 | } | 388 | } |
389 | QTextStream t( &outFile ); | 389 | QTextStream t( &outFile ); |
390 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 390 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
391 | Iterator it; | 391 | Iterator it; |
392 | KABC::VCardConverter::Version version; | 392 | KABC::VCardConverter::Version version; |
393 | version = KABC::VCardConverter::v3_0; | 393 | version = KABC::VCardConverter::v3_0; |
394 | for ( it = begin(); it != end(); ++it ) { | 394 | for ( it = begin(); it != end(); ++it ) { |
395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { | 395 | if ( (*it).resource() && (*it).resource()->includeInSync() ) { |
396 | if ( !(*it).IDStr().isEmpty() ) { | 396 | if ( !(*it).IDStr().isEmpty() ) { |
397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); | 397 | (*it).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*it).IDStr() ); |
398 | } | 398 | } |
399 | KABC::VCardConverter converter; | 399 | KABC::VCardConverter converter; |
400 | QString vcard; | 400 | QString vcard; |
401 | //Resource *resource() const; | 401 | //Resource *resource() const; |
402 | converter.addresseeToVCard( *it, vcard, version ); | 402 | converter.addresseeToVCard( *it, vcard, version ); |
403 | t << vcard << "\r\n"; | 403 | t << vcard << "\r\n"; |
404 | } | 404 | } |
405 | } | 405 | } |
406 | t << "\r\n\r\n"; | 406 | t << "\r\n\r\n"; |
407 | outFile.close(); | 407 | outFile.close(); |
408 | } | 408 | } |
409 | // if QStringList uids is empty, all are exported | 409 | // if QStringList uids is empty, all are exported |
410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) | 410 | bool AddressBook::export2PhoneFormat( QStringList uids ,QString fileName ) |
411 | { | 411 | { |
412 | KABC::VCardConverter converter; | 412 | KABC::VCardConverter converter; |
413 | QString datastream; | 413 | QString datastream; |
414 | Iterator it; | 414 | Iterator it; |
415 | bool all = uids.isEmpty(); | 415 | bool all = uids.isEmpty(); |
416 | for ( it = begin(); it != end(); ++it ) { | 416 | for ( it = begin(); it != end(); ++it ) { |
417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { | 417 | // for( QStringList::ConstIterator it = uids.begin(); it != uids.end(); ++it ) { |
418 | if ( ! all ) { | 418 | if ( ! all ) { |
419 | if ( ! ( uids.contains((*it).uid() ) )) | 419 | if ( ! ( uids.contains((*it).uid() ) )) |
420 | continue; | 420 | continue; |
421 | } | 421 | } |
422 | KABC::Addressee a = ( *it ); | 422 | KABC::Addressee a = ( *it ); |
423 | if ( a.isEmpty() ) | 423 | if ( a.isEmpty() ) |
424 | continue; | 424 | continue; |
425 | if ( all && a.resource() && !a.resource()->includeInSync() ) | 425 | if ( all && a.resource() && !a.resource()->includeInSync() ) |
426 | continue; | 426 | continue; |
427 | a.simplifyEmails(); | 427 | a.simplifyEmails(); |
428 | a.simplifyPhoneNumbers(); | 428 | a.simplifyPhoneNumbers(); |
429 | a.simplifyPhoneNumberTypes(); | 429 | a.simplifyPhoneNumberTypes(); |
430 | a.simplifyAddresses(); | 430 | a.simplifyAddresses(); |
431 | 431 | ||
432 | QString vcard; | 432 | QString vcard; |
433 | QString vcardnew; | 433 | QString vcardnew; |
434 | converter.addresseeToVCard( a, vcard ); | 434 | converter.addresseeToVCard( a, vcard ); |
435 | int start = 0; | 435 | int start = 0; |
436 | int next; | 436 | int next; |
437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { | 437 | while ( (next = vcard.find("TYPE=", start) )>= 0 ) { |
438 | int semi = vcard.find(";", next); | 438 | int semi = vcard.find(";", next); |
439 | int dopp = vcard.find(":", next); | 439 | int dopp = vcard.find(":", next); |
440 | int sep; | 440 | int sep; |
441 | if ( semi < dopp && semi >= 0 ) | 441 | if ( semi < dopp && semi >= 0 ) |
442 | sep = semi ; | 442 | sep = semi ; |
443 | else | 443 | else |
444 | sep = dopp; | 444 | sep = dopp; |
445 | vcardnew +=vcard.mid( start, next - start); | 445 | vcardnew +=vcard.mid( start, next - start); |
446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); | 446 | vcardnew +=vcard.mid( next+5,sep -next -5 ).upper(); |
447 | start = sep; | 447 | start = sep; |
448 | } | 448 | } |
449 | vcardnew += vcard.mid( start,vcard.length() ); | 449 | vcardnew += vcard.mid( start,vcard.length() ); |
450 | vcard = ""; | 450 | vcard = ""; |
451 | start = 0; | 451 | start = 0; |
452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { | 452 | while ( (next = vcardnew.find("ADR", start) )>= 0 ) { |
453 | int sep = vcardnew.find(":", next); | 453 | int sep = vcardnew.find(":", next); |
454 | vcard +=vcardnew.mid( start, next - start+3); | 454 | vcard +=vcardnew.mid( start, next - start+3); |
455 | start = sep; | 455 | start = sep; |
456 | } | 456 | } |
457 | vcard += vcardnew.mid( start,vcardnew.length() ); | 457 | vcard += vcardnew.mid( start,vcardnew.length() ); |
458 | vcard.replace ( QRegExp(";;;") , "" ); | 458 | vcard.replace ( QRegExp(";;;") , "" ); |
459 | vcard.replace ( QRegExp(";;") , "" ); | 459 | vcard.replace ( QRegExp(";;") , "" ); |
460 | datastream += vcard; | 460 | datastream += vcard; |
461 | 461 | ||
462 | } | 462 | } |
463 | 463 | ||
464 | QFile outFile(fileName); | 464 | QFile outFile(fileName); |
465 | if ( outFile.open(IO_WriteOnly) ) { | 465 | if ( outFile.open(IO_WriteOnly) ) { |
466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); | 466 | datastream.replace ( QRegExp("VERSION:3.0") , "VERSION:2.1" ); |
467 | QTextStream t( &outFile ); // use a text stream | 467 | QTextStream t( &outFile ); // use a text stream |
468 | t.setEncoding( QTextStream::UnicodeUTF8 ); | 468 | t.setEncoding( QTextStream::UnicodeUTF8 ); |
469 | t <<datastream; | 469 | t <<datastream; |
470 | t << "\r\n\r\n"; | 470 | t << "\r\n\r\n"; |
471 | outFile.close(); | 471 | outFile.close(); |
472 | 472 | ||
473 | } else { | 473 | } else { |
474 | qDebug("Error open temp file "); | 474 | qDebug("Error open temp file "); |
475 | return false; | 475 | return false; |
476 | } | 476 | } |
477 | return true; | 477 | return true; |
478 | 478 | ||
479 | } | 479 | } |
480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) | 480 | int AddressBook::importFromFile( QString fileName, bool replaceLabel, bool removeOld ) |
481 | { | 481 | { |
482 | 482 | ||
483 | if ( removeOld ) | 483 | if ( removeOld ) |
484 | setUntagged( true ); | 484 | setUntagged( true ); |
485 | KABC::Addressee::List list; | 485 | KABC::Addressee::List list; |
486 | QFile file( fileName ); | 486 | QFile file( fileName ); |
487 | file.open( IO_ReadOnly ); | 487 | file.open( IO_ReadOnly ); |
488 | QByteArray rawData = file.readAll(); | 488 | QByteArray rawData = file.readAll(); |
489 | file.close(); | 489 | file.close(); |
490 | QString data; | 490 | QString data; |
491 | if ( replaceLabel ) { | 491 | if ( replaceLabel ) { |
492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); | 492 | data = QString::fromLatin1( rawData.data(), rawData.size() + 1 ); |
493 | data.replace ( QRegExp("LABEL") , "ADR" ); | 493 | data.replace ( QRegExp("LABEL") , "ADR" ); |
494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); | 494 | data.replace ( QRegExp("CHARSET=ISO-8859-1") , "" ); |
495 | } else | 495 | } else |
496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 496 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
497 | KABC::VCardTool tool; | 497 | KABC::VCardTool tool; |
498 | list = tool.parseVCards( data ); | 498 | list = tool.parseVCards( data ); |
499 | KABC::Addressee::List::Iterator it; | 499 | KABC::Addressee::List::Iterator it; |
500 | for ( it = list.begin(); it != list.end(); ++it ) { | 500 | for ( it = list.begin(); it != list.end(); ++it ) { |
501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 501 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
502 | if ( !id.isEmpty() ) | 502 | if ( !id.isEmpty() ) |
503 | (*it).setIDStr(id ); | 503 | (*it).setIDStr(id ); |
504 | (*it).setResource( 0 ); | 504 | (*it).setResource( 0 ); |
505 | if ( replaceLabel ) | 505 | if ( replaceLabel ) |
506 | (*it).removeVoice(); | 506 | (*it).removeVoice(); |
507 | if ( removeOld ) | 507 | if ( removeOld ) |
508 | (*it).setTagged( true ); | 508 | (*it).setTagged( true ); |
509 | insertAddressee( (*it), false, true ); | 509 | insertAddressee( (*it), false, true ); |
510 | } | 510 | } |
511 | if ( removeOld ) | 511 | if ( removeOld ) |
512 | removeUntagged(); | 512 | removeUntagged(); |
513 | return list.count(); | 513 | return list.count(); |
514 | } | 514 | } |
515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) | 515 | void AddressBook::setUntagged(bool setNonSyncTagged) // = false) |
516 | { | 516 | { |
517 | Iterator ait; | 517 | Iterator ait; |
518 | for ( ait = begin(); ait != end(); ++ait ) { | 518 | for ( ait = begin(); ait != end(); ++ait ) { |
519 | if ( setNonSyncTagged ) { | 519 | if ( setNonSyncTagged ) { |
520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { | 520 | if ( (*ait).resource() && ! (*ait).resource()->includeInSync() ) { |
521 | (*ait).setTagged( true ); | 521 | (*ait).setTagged( true ); |
522 | } else | 522 | } else |
523 | (*ait).setTagged( false ); | 523 | (*ait).setTagged( false ); |
524 | } else | 524 | } else |
525 | (*ait).setTagged( false ); | 525 | (*ait).setTagged( false ); |
526 | } | 526 | } |
527 | } | 527 | } |
528 | void AddressBook::removeUntagged() | 528 | void AddressBook::removeUntagged() |
529 | { | 529 | { |
530 | Iterator ait; | 530 | Iterator ait; |
531 | bool todelete = false; | 531 | bool todelete = false; |
532 | Iterator todel; | 532 | Iterator todel; |
533 | for ( ait = begin(); ait != end(); ++ait ) { | 533 | for ( ait = begin(); ait != end(); ++ait ) { |
534 | if ( todelete ) | 534 | if ( todelete ) |
535 | removeAddressee( todel ); | 535 | removeAddressee( todel ); |
536 | if (!(*ait).tagged()) { | 536 | if (!(*ait).tagged()) { |
537 | todelete = true; | 537 | todelete = true; |
538 | todel = ait; | 538 | todel = ait; |
539 | } else | 539 | } else |
540 | todelete = false; | 540 | todelete = false; |
541 | } | 541 | } |
542 | if ( todelete ) | 542 | if ( todelete ) |
543 | removeAddressee( todel ); | 543 | removeAddressee( todel ); |
544 | deleteRemovedAddressees(); | 544 | deleteRemovedAddressees(); |
545 | } | 545 | } |
546 | void AddressBook::smplifyAddressees() | 546 | void AddressBook::smplifyAddressees() |
547 | { | 547 | { |
548 | Iterator ait; | 548 | Iterator ait; |
549 | for ( ait = begin(); ait != end(); ++ait ) { | 549 | for ( ait = begin(); ait != end(); ++ait ) { |
550 | (*ait).simplifyEmails(); | 550 | (*ait).simplifyEmails(); |
551 | (*ait).simplifyPhoneNumbers(); | 551 | (*ait).simplifyPhoneNumbers(); |
552 | (*ait).simplifyPhoneNumberTypes(); | 552 | (*ait).simplifyPhoneNumberTypes(); |
553 | (*ait).simplifyAddresses(); | 553 | (*ait).simplifyAddresses(); |
554 | } | 554 | } |
555 | } | 555 | } |
556 | void AddressBook::removeSyncInfo( QString syncProfile) | 556 | void AddressBook::removeSyncInfo( QString syncProfile) |
557 | { | 557 | { |
558 | Iterator ait; | 558 | Iterator ait; |
559 | for ( ait = begin(); ait != end(); ++ait ) { | 559 | for ( ait = begin(); ait != end(); ++ait ) { |
560 | (*ait).removeID( syncProfile ); | 560 | (*ait).removeID( syncProfile ); |
561 | } | 561 | } |
562 | if ( syncProfile.isEmpty() ) { | 562 | if ( syncProfile.isEmpty() ) { |
563 | Iterator it = begin(); | 563 | Iterator it = begin(); |
564 | Iterator it2 ; | 564 | Iterator it2 ; |
565 | while ( it != end() ) { | 565 | while ( it != end() ) { |
566 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 566 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
567 | it2 = it; | 567 | it2 = it; |
568 | //qDebug("removing %s ",(*it).uid().latin1() ); | 568 | //qDebug("removing %s ",(*it).uid().latin1() ); |
569 | ++it; | 569 | ++it; |
570 | removeAddressee( it2 ); | 570 | removeAddressee( it2 ); |
571 | } else { | 571 | } else { |
572 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 572 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
573 | ++it; | 573 | ++it; |
574 | } | 574 | } |
575 | } | 575 | } |
576 | } else { | 576 | } else { |
577 | Addressee lse; | 577 | Addressee lse; |
578 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); | 578 | lse = findByUid( "last-syncAddressee-"+ syncProfile ); |
579 | if ( ! lse.isEmpty() ) | 579 | if ( ! lse.isEmpty() ) |
580 | removeAddressee( lse ); | 580 | removeAddressee( lse ); |
581 | } | 581 | } |
582 | 582 | ||
583 | } | 583 | } |
584 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) | 584 | void AddressBook::preparePhoneSync( QString currentSyncDevice, bool isPreSync ) |
585 | { | 585 | { |
586 | Iterator ait; | 586 | Iterator ait; |
587 | for ( ait = begin(); ait != end(); ++ait ) { | 587 | for ( ait = begin(); ait != end(); ++ait ) { |
588 | QString id = (*ait).IDStr(); | 588 | QString id = (*ait).IDStr(); |
589 | (*ait).setIDStr( ":"); | 589 | (*ait).setIDStr( ":"); |
590 | (*ait).setExternalUID( id ); | 590 | (*ait).setExternalUID( id ); |
591 | (*ait).setOriginalExternalUID( id ); | 591 | (*ait).setOriginalExternalUID( id ); |
592 | if ( isPreSync ) | 592 | if ( isPreSync ) |
593 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 593 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
594 | else { | 594 | else { |
595 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 595 | (*ait).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
596 | (*ait).setID( currentSyncDevice,id ); | 596 | (*ait).setID( currentSyncDevice,id ); |
597 | 597 | ||
598 | } | 598 | } |
599 | } | 599 | } |
600 | } | 600 | } |
601 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) | 601 | void AddressBook::findNewExtIds( QString fileName, QString currentSyncDevice ) |
602 | { | 602 | { |
603 | 603 | ||
604 | setUntagged(); | 604 | setUntagged(); |
605 | KABC::Addressee::List list; | 605 | KABC::Addressee::List list; |
606 | QFile file( fileName ); | 606 | QFile file( fileName ); |
607 | file.open( IO_ReadOnly ); | 607 | file.open( IO_ReadOnly ); |
608 | QByteArray rawData = file.readAll(); | 608 | QByteArray rawData = file.readAll(); |
609 | file.close(); | 609 | file.close(); |
610 | QString data; | 610 | QString data; |
611 | 611 | ||
612 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); | 612 | data = QString::fromUtf8( rawData.data(), rawData.size() + 1 ); |
613 | KABC::VCardTool tool; | 613 | KABC::VCardTool tool; |
614 | list = tool.parseVCards( data ); | 614 | list = tool.parseVCards( data ); |
615 | KABC::Addressee::List::Iterator it; | 615 | KABC::Addressee::List::Iterator it; |
616 | for ( it = list.begin(); it != list.end(); ++it ) { | 616 | for ( it = list.begin(); it != list.end(); ++it ) { |
617 | Iterator ait; | 617 | Iterator ait; |
618 | for ( ait = begin(); ait != end(); ++ait ) { | 618 | for ( ait = begin(); ait != end(); ++ait ) { |
619 | if ( !(*ait).tagged() ) { | 619 | if ( !(*ait).tagged() ) { |
620 | if ( (*ait).containsAdr(*it)) { | 620 | if ( (*ait).containsAdr(*it)) { |
621 | (*ait).setTagged(true); | 621 | (*ait).setTagged(true); |
622 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); | 622 | QString id = (*it).custom( "KADDRESSBOOK", "X-ExternalID" ); |
623 | (*it).setIDStr( ":"); | 623 | (*it).setIDStr( ":"); |
624 | (*it).setID( currentSyncDevice,id ); | 624 | (*it).setID( currentSyncDevice,id ); |
625 | (*it).setExternalUID( id ); | 625 | (*it).setExternalUID( id ); |
626 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 626 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
627 | (*it).setUid( ( (*ait).uid() )); | 627 | (*it).setUid( ( (*ait).uid() )); |
628 | break; | 628 | break; |
629 | } | 629 | } |
630 | } | 630 | } |
631 | 631 | ||
632 | } | 632 | } |
633 | if ( ait == end() ) | 633 | if ( ait == end() ) |
634 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); | 634 | qDebug("ERROR:: no ext ID found for uid: %s", (*it).uid().latin1()); |
635 | } | 635 | } |
636 | clear(); | 636 | clear(); |
637 | for ( it = list.begin(); it != list.end(); ++it ) { | 637 | for ( it = list.begin(); it != list.end(); ++it ) { |
638 | insertAddressee( (*it) ); | 638 | insertAddressee( (*it) ); |
639 | } | 639 | } |
640 | } | 640 | } |
641 | 641 | ||
642 | bool AddressBook::saveABphone( QString fileName ) | 642 | bool AddressBook::saveABphone( QString fileName ) |
643 | { | 643 | { |
644 | //smplifyAddressees(); | 644 | //smplifyAddressees(); |
645 | qDebug("saveABphone:: saving AB... "); | 645 | qDebug("saveABphone:: saving AB... "); |
646 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) | 646 | if ( ! export2PhoneFormat( QStringList() ,fileName ) ) |
647 | return false; | 647 | return false; |
648 | qDebug("saveABphone:: writing to phone... "); | 648 | qDebug("saveABphone:: writing to phone... "); |
649 | if ( !PhoneAccess::writeToPhone( fileName) ) { | 649 | if ( !PhoneAccess::writeToPhone( fileName) ) { |
650 | return false; | 650 | return false; |
651 | } | 651 | } |
652 | qDebug("saveABphone:: re-reading from phone... "); | 652 | qDebug("saveABphone:: re-reading from phone... "); |
653 | if ( !PhoneAccess::readFromPhone( fileName) ) { | 653 | if ( !PhoneAccess::readFromPhone( fileName) ) { |
654 | return false; | 654 | return false; |
655 | } | 655 | } |
656 | return true; | 656 | return true; |
657 | } | 657 | } |
658 | bool AddressBook::saveAB() | 658 | bool AddressBook::saveAB() |
659 | { | 659 | { |
660 | bool ok = true; | 660 | bool ok = true; |
661 | 661 | ||
662 | deleteRemovedAddressees(); | 662 | deleteRemovedAddressees(); |
663 | Iterator ait; | 663 | Iterator ait; |
664 | for ( ait = begin(); ait != end(); ++ait ) { | 664 | for ( ait = begin(); ait != end(); ++ait ) { |
665 | if ( !(*ait).IDStr().isEmpty() ) { | 665 | if ( !(*ait).IDStr().isEmpty() ) { |
666 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); | 666 | (*ait).insertCustom( "KADDRESSBOOK", "X-ExternalID", (*ait).IDStr() ); |
667 | } | 667 | } |
668 | } | 668 | } |
669 | KRES::Manager<Resource>::ActiveIterator it; | 669 | KRES::Manager<Resource>::ActiveIterator it; |
670 | KRES::Manager<Resource> *manager = d->mManager; | 670 | KRES::Manager<Resource> *manager = d->mManager; |
671 | qDebug("SaveAB::saving..." ); | 671 | qDebug("SaveAB::saving..." ); |
672 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { | 672 | for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { |
673 | qDebug("SaveAB::checking resource..." ); | 673 | qDebug("SaveAB::checking resource..." ); |
674 | if ( (*it)->readOnly() ) | 674 | if ( (*it)->readOnly() ) |
675 | qDebug("resource is readonly." ); | 675 | qDebug("SaveAB::resource is readonly." ); |
676 | if ( (*it)->isOpen() ) | 676 | if ( (*it)->isOpen() ) |
677 | qDebug("resource is open" ); | 677 | qDebug("SaveAB::resource is open" ); |
678 | 678 | ||
679 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { | 679 | if ( !(*it)->readOnly() && (*it)->isOpen() ) { |
680 | Ticket *ticket = requestSaveTicket( *it ); | 680 | Ticket *ticket = requestSaveTicket( *it ); |
681 | qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); | 681 | qDebug("SaveAB::StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); |
682 | if ( !ticket ) { | 682 | if ( !ticket ) { |
683 | qDebug( i18n( "Unable to save to resource '%1'. It is locked." ) | 683 | qDebug( i18n( "SaveAB::Unable to save to resource '%1'. It is locked." ) |
684 | .arg( (*it)->resourceName() ) ); | 684 | .arg( (*it)->resourceName() ) ); |
685 | return false; | 685 | return false; |
686 | } | 686 | } |
687 | 687 | ||
688 | //if ( !save( ticket ) ) | 688 | //if ( !save( ticket ) ) |
689 | if ( ticket->resource() ) { | 689 | if ( ticket->resource() ) { |
690 | QString name = ticket->resource()->resourceName(); | 690 | QString name = ticket->resource()->resourceName(); |
691 | if ( ! ticket->resource()->save( ticket ) ) | 691 | if ( ! ticket->resource()->save( ticket ) ) |
692 | ok = false; | 692 | ok = false; |
693 | else | 693 | else |
694 | qDebug("StdAddressBook::resource saved '%s'", name.latin1() ); | 694 | qDebug("SaveAB::resource saved '%s'", name.latin1() ); |
695 | 695 | ||
696 | } else | 696 | } else |
697 | ok = false; | 697 | ok = false; |
698 | 698 | ||
699 | } | 699 | } |
700 | } | 700 | } |
701 | return ok; | 701 | return ok; |
702 | } | 702 | } |
703 | 703 | ||
704 | AddressBook::Iterator AddressBook::begin() | 704 | AddressBook::Iterator AddressBook::begin() |
705 | { | 705 | { |
706 | Iterator it = Iterator(); | 706 | Iterator it = Iterator(); |
707 | it.d->mIt = d->mAddressees.begin(); | 707 | it.d->mIt = d->mAddressees.begin(); |
708 | return it; | 708 | return it; |
709 | } | 709 | } |
710 | 710 | ||
711 | AddressBook::ConstIterator AddressBook::begin() const | 711 | AddressBook::ConstIterator AddressBook::begin() const |
712 | { | 712 | { |
713 | ConstIterator it = ConstIterator(); | 713 | ConstIterator it = ConstIterator(); |
714 | it.d->mIt = d->mAddressees.begin(); | 714 | it.d->mIt = d->mAddressees.begin(); |
715 | return it; | 715 | return it; |
716 | } | 716 | } |
717 | 717 | ||
718 | AddressBook::Iterator AddressBook::end() | 718 | AddressBook::Iterator AddressBook::end() |
719 | { | 719 | { |
720 | Iterator it = Iterator(); | 720 | Iterator it = Iterator(); |
721 | it.d->mIt = d->mAddressees.end(); | 721 | it.d->mIt = d->mAddressees.end(); |
722 | return it; | 722 | return it; |
723 | } | 723 | } |
724 | 724 | ||
725 | AddressBook::ConstIterator AddressBook::end() const | 725 | AddressBook::ConstIterator AddressBook::end() const |
726 | { | 726 | { |
727 | ConstIterator it = ConstIterator(); | 727 | ConstIterator it = ConstIterator(); |
728 | it.d->mIt = d->mAddressees.end(); | 728 | it.d->mIt = d->mAddressees.end(); |
729 | return it; | 729 | return it; |
730 | } | 730 | } |
731 | 731 | ||
732 | void AddressBook::clear() | 732 | void AddressBook::clear() |
733 | { | 733 | { |
734 | d->mAddressees.clear(); | 734 | d->mAddressees.clear(); |
735 | } | 735 | } |
736 | 736 | ||
737 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) | 737 | Ticket *AddressBook::requestSaveTicket( Resource *resource ) |
738 | { | 738 | { |
739 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; | 739 | kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; |
740 | 740 | ||
741 | if ( !resource ) | 741 | if ( !resource ) |
742 | { | 742 | { |
743 | qDebug("AddressBook::requestSaveTicket no resource" ); | 743 | qDebug("AddressBook::requestSaveTicket no resource" ); |
744 | resource = standardResource(); | 744 | resource = standardResource(); |
745 | } | 745 | } |
746 | 746 | ||
747 | KRES::Manager<Resource>::ActiveIterator it; | 747 | KRES::Manager<Resource>::ActiveIterator it; |
748 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 748 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
749 | if ( (*it) == resource ) { | 749 | if ( (*it) == resource ) { |
750 | if ( (*it)->readOnly() || !(*it)->isOpen() ) | 750 | if ( (*it)->readOnly() || !(*it)->isOpen() ) |
751 | return 0; | 751 | return 0; |
752 | else | 752 | else |
753 | return (*it)->requestSaveTicket(); | 753 | return (*it)->requestSaveTicket(); |
754 | } | 754 | } |
755 | } | 755 | } |
756 | 756 | ||
757 | return 0; | 757 | return 0; |
758 | } | 758 | } |
759 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); | 759 | //void insertAddressee( const Addressee &, bool setRev = true, bool takeResource = false); |
760 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) | 760 | void AddressBook::insertAddressee( const Addressee &a, bool setRev, bool takeResource ) |
761 | { | 761 | { |
762 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { | 762 | if ( blockLSEchange && setRev && a.uid().left( 19 ) == QString("last-syncAddressee-") ) { |
763 | //qDebug("block insert "); | 763 | //qDebug("block insert "); |
764 | return; | 764 | return; |
765 | } | 765 | } |
766 | //qDebug("inserting.... %s ",a.uid().latin1() ); | 766 | //qDebug("inserting.... %s ",a.uid().latin1() ); |
767 | bool found = false; | 767 | bool found = false; |
768 | Addressee::List::Iterator it; | 768 | Addressee::List::Iterator it; |
769 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { | 769 | for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { |
770 | if ( a.uid() == (*it).uid() ) { | 770 | if ( a.uid() == (*it).uid() ) { |
771 | 771 | ||
772 | bool changed = false; | 772 | bool changed = false; |
773 | Addressee addr = a; | 773 | Addressee addr = a; |
774 | if ( addr != (*it) ) | 774 | if ( addr != (*it) ) |
775 | changed = true; | 775 | changed = true; |
776 | 776 | ||
777 | if ( takeResource ) { | 777 | if ( takeResource ) { |
778 | Resource * res = (*it).resource(); | 778 | Resource * res = (*it).resource(); |
779 | (*it) = a; | 779 | (*it) = a; |
780 | (*it).setResource( res ); | 780 | (*it).setResource( res ); |
781 | } else { | 781 | } else { |
782 | (*it) = a; | 782 | (*it) = a; |
783 | if ( (*it).resource() == 0 ) | 783 | if ( (*it).resource() == 0 ) |
784 | (*it).setResource( standardResource() ); | 784 | (*it).setResource( standardResource() ); |
785 | } | 785 | } |
786 | if ( changed ) { | 786 | if ( changed ) { |
787 | if ( setRev ) { | 787 | if ( setRev ) { |
788 | (*it).setRevision( QDateTime::currentDateTime() ); | 788 | (*it).setRevision( QDateTime::currentDateTime() ); |
789 | } | 789 | } |
790 | (*it).setChanged( true ); | 790 | (*it).setChanged( true ); |
791 | } | 791 | } |
792 | 792 | ||
793 | found = true; | 793 | found = true; |
794 | } else { | 794 | } else { |
795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 795 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
796 | QString name = (*it).uid().mid( 19 ); | 796 | QString name = (*it).uid().mid( 19 ); |
797 | Addressee b = a; | 797 | Addressee b = a; |
798 | QString id = b.getID( name ); | 798 | QString id = b.getID( name ); |
799 | if ( ! id.isEmpty() ) { | 799 | if ( ! id.isEmpty() ) { |
800 | QString des = (*it).note(); | 800 | QString des = (*it).note(); |
801 | int startN; | 801 | int startN; |
802 | if( (startN = des.find( id ) ) >= 0 ) { | 802 | if( (startN = des.find( id ) ) >= 0 ) { |
803 | int endN = des.find( ",", startN+1 ); | 803 | int endN = des.find( ",", startN+1 ); |
804 | des = des.left( startN ) + des.mid( endN+1 ); | 804 | des = des.left( startN ) + des.mid( endN+1 ); |
805 | (*it).setNote( des ); | 805 | (*it).setNote( des ); |
806 | } | 806 | } |
807 | } | 807 | } |
808 | } | 808 | } |
809 | } | 809 | } |
810 | } | 810 | } |
811 | if ( found ) | 811 | if ( found ) |
812 | return; | 812 | return; |
813 | 813 | ||
814 | d->mAddressees.append( a ); | 814 | d->mAddressees.append( a ); |
815 | Addressee& addr = d->mAddressees.last(); | 815 | Addressee& addr = d->mAddressees.last(); |
816 | if ( addr.resource() == 0 ) | 816 | if ( addr.resource() == 0 ) |
817 | addr.setResource( standardResource() ); | 817 | addr.setResource( standardResource() ); |
818 | addr.setChanged( true ); | 818 | addr.setChanged( true ); |
819 | } | 819 | } |
820 | 820 | ||
821 | void AddressBook::removeAddressee( const Addressee &a ) | 821 | void AddressBook::removeAddressee( const Addressee &a ) |
822 | { | 822 | { |
823 | Iterator it; | 823 | Iterator it; |
824 | Iterator it2; | 824 | Iterator it2; |
825 | bool found = false; | 825 | bool found = false; |
826 | for ( it = begin(); it != end(); ++it ) { | 826 | for ( it = begin(); it != end(); ++it ) { |
827 | if ( a.uid() == (*it).uid() ) { | 827 | if ( a.uid() == (*it).uid() ) { |
828 | found = true; | 828 | found = true; |
829 | it2 = it; | 829 | it2 = it; |
830 | } else { | 830 | } else { |
831 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { | 831 | if ( (*it).uid().left( 19 ) == QString("last-syncAddressee-") ) { |
832 | QString name = (*it).uid().mid( 19 ); | 832 | QString name = (*it).uid().mid( 19 ); |
833 | Addressee b = a; | 833 | Addressee b = a; |
834 | QString id = b.getID( name ); | 834 | QString id = b.getID( name ); |
835 | if ( ! id.isEmpty() ) { | 835 | if ( ! id.isEmpty() ) { |
836 | QString des = (*it).note(); | 836 | QString des = (*it).note(); |
837 | if( des.find( id ) < 0 ) { | 837 | if( des.find( id ) < 0 ) { |
838 | des += id + ","; | 838 | des += id + ","; |
839 | (*it).setNote( des ); | 839 | (*it).setNote( des ); |
840 | } | 840 | } |
841 | } | 841 | } |
842 | } | 842 | } |
843 | 843 | ||
844 | } | 844 | } |
845 | } | 845 | } |
846 | 846 | ||
847 | if ( found ) | 847 | if ( found ) |
848 | removeAddressee( it2 ); | 848 | removeAddressee( it2 ); |
849 | 849 | ||
850 | } | 850 | } |
851 | 851 | ||
852 | void AddressBook::removeSyncAddressees( bool removeDeleted ) | 852 | void AddressBook::removeSyncAddressees( bool removeDeleted ) |
853 | { | 853 | { |
854 | Iterator it = begin(); | 854 | Iterator it = begin(); |
855 | Iterator it2 ; | 855 | Iterator it2 ; |
856 | QDateTime dt ( QDate( 2003,1,1) ); | 856 | QDateTime dt ( QDate( 2003,1,1) ); |
857 | while ( it != end() ) { | 857 | while ( it != end() ) { |
858 | (*it).setRevision( dt ); | 858 | (*it).setRevision( dt ); |
859 | if (( *it).IDStr() != "changed" ) { | 859 | if (( *it).IDStr() != "changed" ) { |
860 | // "changed" is used for tagging changed addressees when syncing with KDE or OL | 860 | // "changed" is used for tagging changed addressees when syncing with KDE or OL |
861 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); | 861 | (*it).removeCustom( "KADDRESSBOOK", "X-ExternalID" ); |
862 | (*it).setIDStr(":"); | 862 | (*it).setIDStr(":"); |
863 | } | 863 | } |
864 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { | 864 | if ( ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE && removeDeleted )|| (*it).uid().left( 19 ) == QString("last-syncAddressee-")) { |
865 | it2 = it; | 865 | it2 = it; |
866 | //qDebug("removing %s ",(*it).uid().latin1() ); | 866 | //qDebug("removing %s ",(*it).uid().latin1() ); |
867 | ++it; | 867 | ++it; |
868 | removeAddressee( it2 ); | 868 | removeAddressee( it2 ); |
869 | } else { | 869 | } else { |
870 | //qDebug("skipping %s ",(*it).uid().latin1() ); | 870 | //qDebug("skipping %s ",(*it).uid().latin1() ); |
871 | if ( removeDeleted ) { | 871 | if ( removeDeleted ) { |
872 | // we have no postprocessing in the resource, we have to do it here | 872 | // we have no postprocessing in the resource, we have to do it here |
873 | // we have to compute csum for all, because it could be the first sync | 873 | // we have to compute csum for all, because it could be the first sync |
874 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 874 | (*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
875 | } | 875 | } |
876 | ++it; | 876 | ++it; |
877 | } | 877 | } |
878 | } | 878 | } |
879 | deleteRemovedAddressees(); | 879 | deleteRemovedAddressees(); |
880 | } | 880 | } |
881 | 881 | ||
882 | void AddressBook::removeAddressee( const Iterator &it ) | 882 | void AddressBook::removeAddressee( const Iterator &it ) |
883 | { | 883 | { |
884 | d->mRemovedAddressees.append( (*it) ); | 884 | d->mRemovedAddressees.append( (*it) ); |
885 | d->mAddressees.remove( it.d->mIt ); | 885 | d->mAddressees.remove( it.d->mIt ); |
886 | } | 886 | } |
887 | 887 | ||
888 | AddressBook::Iterator AddressBook::find( const Addressee &a ) | 888 | AddressBook::Iterator AddressBook::find( const Addressee &a ) |
889 | { | 889 | { |
890 | Iterator it; | 890 | Iterator it; |
891 | for ( it = begin(); it != end(); ++it ) { | 891 | for ( it = begin(); it != end(); ++it ) { |
892 | if ( a.uid() == (*it).uid() ) { | 892 | if ( a.uid() == (*it).uid() ) { |
893 | return it; | 893 | return it; |
894 | } | 894 | } |
895 | } | 895 | } |
896 | return end(); | 896 | return end(); |
897 | } | 897 | } |
898 | 898 | ||
899 | Addressee AddressBook::findByUid( const QString &uid ) | 899 | Addressee AddressBook::findByUid( const QString &uid ) |
900 | { | 900 | { |
901 | Iterator it; | 901 | Iterator it; |
902 | for ( it = begin(); it != end(); ++it ) { | 902 | for ( it = begin(); it != end(); ++it ) { |
903 | if ( uid == (*it).uid() ) { | 903 | if ( uid == (*it).uid() ) { |
904 | return *it; | 904 | return *it; |
905 | } | 905 | } |
906 | } | 906 | } |
907 | return Addressee(); | 907 | return Addressee(); |
908 | } | 908 | } |
909 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) | 909 | void AddressBook::preExternSync( AddressBook* aBook, const QString& csd , bool isSubset ) |
910 | { | 910 | { |
911 | //qDebug("AddressBook::preExternSync "); | 911 | //qDebug("AddressBook::preExternSync "); |
912 | AddressBook::Iterator it; | 912 | AddressBook::Iterator it; |
913 | for ( it = begin(); it != end(); ++it ) { | 913 | for ( it = begin(); it != end(); ++it ) { |
914 | (*it).setID( csd, (*it).externalUID() ); | 914 | (*it).setID( csd, (*it).externalUID() ); |
915 | (*it).computeCsum( csd ); | 915 | (*it).computeCsum( csd ); |
916 | } | 916 | } |
917 | mergeAB( aBook ,csd, isSubset ); | 917 | mergeAB( aBook ,csd, isSubset ); |
918 | } | 918 | } |
919 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) | 919 | void AddressBook::postExternSync( AddressBook* aBook , const QString& csd, bool setID) |
920 | { | 920 | { |
921 | //qDebug("AddressBook::postExternSync "); | 921 | //qDebug("AddressBook::postExternSync "); |
922 | AddressBook::Iterator it; | 922 | AddressBook::Iterator it; |
923 | int foundEmpty = 0; | 923 | int foundEmpty = 0; |
924 | for ( it = begin(); it != end(); ++it ) { | 924 | for ( it = begin(); it != end(); ++it ) { |
925 | //qDebug("check uid %s ", (*it).uid().latin1() ); | 925 | //qDebug("check uid %s ", (*it).uid().latin1() ); |
926 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || | 926 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID || |
927 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || | 927 | (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_CSUM || |
928 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { | 928 | (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL) { |
929 | Addressee ad = aBook->findByUid( ( (*it).uid() )); | 929 | Addressee ad = aBook->findByUid( ( (*it).uid() )); |
930 | if ( ad.isEmpty() ) { | 930 | if ( ad.isEmpty() ) { |
931 | ++foundEmpty; | 931 | ++foundEmpty; |
932 | //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); | 932 | //qDebug("postExternSync:addressee is empty: %s ", (*it).uid().latin1()); |
933 | //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); | 933 | //qDebug("-- formatted name %s ",(*it).formattedName().latin1() ); |
934 | } else { | 934 | } else { |
935 | (*it).setIDStr(":"); | 935 | (*it).setIDStr(":"); |
936 | if ( setID ) { | 936 | if ( setID ) { |
937 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) | 937 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_NEW_ID ) |
938 | ad.setID( csd, (*it).externalUID() ); | 938 | ad.setID( csd, (*it).externalUID() ); |
939 | } else | 939 | } else |
940 | ad.setID( csd, (*it).uid() ); | 940 | ad.setID( csd, (*it).uid() ); |
941 | (*it).computeCsum( csd ); | 941 | (*it).computeCsum( csd ); |
942 | ad.setCsum( csd, (*it).getCsum( csd ) ); | 942 | ad.setCsum( csd, (*it).getCsum( csd ) ); |
943 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); | 943 | //qDebug("CSUM %s ",(*it).getCsum( csd ).latin1() ); |
944 | aBook->insertAddressee( ad , false); | 944 | aBook->insertAddressee( ad , false); |
945 | } | 945 | } |
946 | } | 946 | } |
947 | } | 947 | } |
948 | if ( foundEmpty ) { | 948 | if ( foundEmpty ) { |
949 | qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); | 949 | qDebug("postExternSync:%d empty addressees found:\n probably filtered out by incoming sync filter.",foundEmpty ); |
950 | } | 950 | } |
951 | 951 | ||
952 | } | 952 | } |
953 | 953 | ||
954 | bool AddressBook::containsExternalUid( const QString& uid ) | 954 | bool AddressBook::containsExternalUid( const QString& uid ) |
955 | { | 955 | { |
956 | Iterator it; | 956 | Iterator it; |
957 | for ( it = begin(); it != end(); ++it ) { | 957 | for ( it = begin(); it != end(); ++it ) { |
958 | if ( uid == (*it).externalUID( ) ) | 958 | if ( uid == (*it).externalUID( ) ) |
959 | return true; | 959 | return true; |
960 | } | 960 | } |
961 | return false; | 961 | return false; |
962 | } | 962 | } |
963 | const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const | 963 | const Addressee AddressBook::findByExternUid( const QString& uid , const QString& profile ) const |
964 | { | 964 | { |
965 | ConstIterator it; | 965 | ConstIterator it; |
966 | for ( it = begin(); it != end(); ++it ) { | 966 | for ( it = begin(); it != end(); ++it ) { |
967 | if ( uid == (*it).getID( profile ) ) | 967 | if ( uid == (*it).getID( profile ) ) |
968 | return (*it); | 968 | return (*it); |
969 | } | 969 | } |
970 | return Addressee(); | 970 | return Addressee(); |
971 | } | 971 | } |
972 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) | 972 | void AddressBook::mergeAB( AddressBook *aBook, const QString& profile , bool isSubset ) |
973 | { | 973 | { |
974 | Iterator it; | 974 | Iterator it; |
975 | Addressee ad; | 975 | Addressee ad; |
976 | for ( it = begin(); it != end(); ++it ) { | 976 | for ( it = begin(); it != end(); ++it ) { |
977 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); | 977 | ad = aBook->findByExternUid( (*it).externalUID(), profile ); |
978 | if ( !ad.isEmpty() ) { | 978 | if ( !ad.isEmpty() ) { |
979 | (*it).mergeContact( ad ,isSubset); | 979 | (*it).mergeContact( ad ,isSubset); |
980 | } | 980 | } |
981 | } | 981 | } |
982 | #if 0 | 982 | #if 0 |
983 | // test only | 983 | // test only |
984 | for ( it = begin(); it != end(); ++it ) { | 984 | for ( it = begin(); it != end(); ++it ) { |
985 | 985 | ||
986 | qDebug("uid %s ", (*it).uid().latin1()); | 986 | qDebug("uid %s ", (*it).uid().latin1()); |
987 | } | 987 | } |
988 | #endif | 988 | #endif |
989 | } | 989 | } |
990 | 990 | ||
991 | #if 0 | 991 | #if 0 |
992 | Addressee::List AddressBook::getExternLastSyncAddressees() | 992 | Addressee::List AddressBook::getExternLastSyncAddressees() |
993 | { | 993 | { |
994 | Addressee::List results; | 994 | Addressee::List results; |
995 | 995 | ||
996 | Iterator it; | 996 | Iterator it; |
997 | for ( it = begin(); it != end(); ++it ) { | 997 | for ( it = begin(); it != end(); ++it ) { |
998 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { | 998 | if ( (*it).uid().left( 19 ) == "last-syncAddressee-" ) { |
999 | if ( (*it).familyName().left(4) == "!E: " ) | 999 | if ( (*it).familyName().left(4) == "!E: " ) |
1000 | results.append( *it ); | 1000 | results.append( *it ); |
1001 | } | 1001 | } |
1002 | } | 1002 | } |
1003 | 1003 | ||
1004 | return results; | 1004 | return results; |
1005 | } | 1005 | } |
1006 | #endif | 1006 | #endif |
1007 | void AddressBook::resetTempSyncStat() | 1007 | void AddressBook::resetTempSyncStat() |
1008 | { | 1008 | { |
1009 | Iterator it; | 1009 | Iterator it; |
1010 | for ( it = begin(); it != end(); ++it ) { | 1010 | for ( it = begin(); it != end(); ++it ) { |
1011 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); | 1011 | (*it).setTempSyncStat ( SYNC_TEMPSTATE_INITIAL ); |
1012 | } | 1012 | } |
1013 | 1013 | ||
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | QStringList AddressBook:: uidList() | 1016 | QStringList AddressBook:: uidList() |
1017 | { | 1017 | { |
1018 | QStringList results; | 1018 | QStringList results; |
1019 | Iterator it; | 1019 | Iterator it; |
1020 | for ( it = begin(); it != end(); ++it ) { | 1020 | for ( it = begin(); it != end(); ++it ) { |
1021 | results.append( (*it).uid() ); | 1021 | results.append( (*it).uid() ); |
1022 | } | 1022 | } |
1023 | return results; | 1023 | return results; |
1024 | } | 1024 | } |
1025 | 1025 | ||
1026 | 1026 | ||
1027 | Addressee::List AddressBook::allAddressees() | 1027 | Addressee::List AddressBook::allAddressees() |
1028 | { | 1028 | { |
1029 | return d->mAddressees; | 1029 | return d->mAddressees; |
1030 | 1030 | ||
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | Addressee::List AddressBook::findByName( const QString &name ) | 1033 | Addressee::List AddressBook::findByName( const QString &name ) |
1034 | { | 1034 | { |
1035 | Addressee::List results; | 1035 | Addressee::List results; |
1036 | 1036 | ||
1037 | Iterator it; | 1037 | Iterator it; |
1038 | for ( it = begin(); it != end(); ++it ) { | 1038 | for ( it = begin(); it != end(); ++it ) { |
1039 | if ( name == (*it).realName() ) { | 1039 | if ( name == (*it).realName() ) { |
1040 | results.append( *it ); | 1040 | results.append( *it ); |
1041 | } | 1041 | } |
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | return results; | 1044 | return results; |
1045 | } | 1045 | } |
1046 | 1046 | ||
1047 | Addressee::List AddressBook::findByEmail( const QString &email ) | 1047 | Addressee::List AddressBook::findByEmail( const QString &email ) |
1048 | { | 1048 | { |
1049 | Addressee::List results; | 1049 | Addressee::List results; |
1050 | QStringList mailList; | 1050 | QStringList mailList; |
1051 | 1051 | ||
1052 | Iterator it; | 1052 | Iterator it; |
1053 | for ( it = begin(); it != end(); ++it ) { | 1053 | for ( it = begin(); it != end(); ++it ) { |
1054 | mailList = (*it).emails(); | 1054 | mailList = (*it).emails(); |
1055 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { | 1055 | for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { |
1056 | if ( email == (*ite) ) { | 1056 | if ( email == (*ite) ) { |
1057 | results.append( *it ); | 1057 | results.append( *it ); |
1058 | } | 1058 | } |
1059 | } | 1059 | } |
1060 | } | 1060 | } |
1061 | 1061 | ||
1062 | return results; | 1062 | return results; |
1063 | } | 1063 | } |
1064 | 1064 | ||
1065 | Addressee::List AddressBook::findByCategory( const QString &category ) | 1065 | Addressee::List AddressBook::findByCategory( const QString &category ) |
1066 | { | 1066 | { |
1067 | Addressee::List results; | 1067 | Addressee::List results; |
1068 | 1068 | ||
1069 | Iterator it; | 1069 | Iterator it; |
1070 | for ( it = begin(); it != end(); ++it ) { | 1070 | for ( it = begin(); it != end(); ++it ) { |
1071 | if ( (*it).hasCategory( category) ) { | 1071 | if ( (*it).hasCategory( category) ) { |
1072 | results.append( *it ); | 1072 | results.append( *it ); |
1073 | } | 1073 | } |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | return results; | 1076 | return results; |
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | void AddressBook::dump() const | 1079 | void AddressBook::dump() const |
1080 | { | 1080 | { |
1081 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; | 1081 | kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; |
1082 | 1082 | ||
1083 | ConstIterator it; | 1083 | ConstIterator it; |
1084 | for( it = begin(); it != end(); ++it ) { | 1084 | for( it = begin(); it != end(); ++it ) { |
1085 | (*it).dump(); | 1085 | (*it).dump(); |
1086 | } | 1086 | } |
1087 | 1087 | ||
1088 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; | 1088 | kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | QString AddressBook::identifier() | 1091 | QString AddressBook::identifier() |
1092 | { | 1092 | { |
1093 | QStringList identifier; | 1093 | QStringList identifier; |
1094 | 1094 | ||
1095 | 1095 | ||
1096 | KRES::Manager<Resource>::ActiveIterator it; | 1096 | KRES::Manager<Resource>::ActiveIterator it; |
1097 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1097 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1098 | if ( !(*it)->identifier().isEmpty() ) | 1098 | if ( !(*it)->identifier().isEmpty() ) |
1099 | identifier.append( (*it)->identifier() ); | 1099 | identifier.append( (*it)->identifier() ); |
1100 | } | 1100 | } |
1101 | 1101 | ||
1102 | return identifier.join( ":" ); | 1102 | return identifier.join( ":" ); |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | Field::List AddressBook::fields( int category ) | 1105 | Field::List AddressBook::fields( int category ) |
1106 | { | 1106 | { |
1107 | if ( d->mAllFields.isEmpty() ) { | 1107 | if ( d->mAllFields.isEmpty() ) { |
1108 | d->mAllFields = Field::allFields(); | 1108 | d->mAllFields = Field::allFields(); |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | if ( category == Field::All ) return d->mAllFields; | 1111 | if ( category == Field::All ) return d->mAllFields; |
1112 | 1112 | ||
1113 | Field::List result; | 1113 | Field::List result; |
1114 | Field::List::ConstIterator it; | 1114 | Field::List::ConstIterator it; |
1115 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { | 1115 | for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { |
1116 | if ( (*it)->category() & category ) result.append( *it ); | 1116 | if ( (*it)->category() & category ) result.append( *it ); |
1117 | } | 1117 | } |
1118 | 1118 | ||
1119 | return result; | 1119 | return result; |
1120 | } | 1120 | } |
1121 | 1121 | ||
1122 | bool AddressBook::addCustomField( const QString &label, int category, | 1122 | bool AddressBook::addCustomField( const QString &label, int category, |
1123 | const QString &key, const QString &app ) | 1123 | const QString &key, const QString &app ) |
1124 | { | 1124 | { |
1125 | if ( d->mAllFields.isEmpty() ) { | 1125 | if ( d->mAllFields.isEmpty() ) { |
1126 | d->mAllFields = Field::allFields(); | 1126 | d->mAllFields = Field::allFields(); |
1127 | } | 1127 | } |
1128 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; | 1128 | //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; |
1129 | QString a = app.isNull() ? KGlobal::getAppName() : app; | 1129 | QString a = app.isNull() ? KGlobal::getAppName() : app; |
1130 | 1130 | ||
1131 | QString k = key.isNull() ? label : key; | 1131 | QString k = key.isNull() ? label : key; |
1132 | 1132 | ||
1133 | Field *field = Field::createCustomField( label, category, k, a ); | 1133 | Field *field = Field::createCustomField( label, category, k, a ); |
1134 | 1134 | ||
1135 | if ( !field ) return false; | 1135 | if ( !field ) return false; |
1136 | 1136 | ||
1137 | d->mAllFields.append( field ); | 1137 | d->mAllFields.append( field ); |
1138 | 1138 | ||
1139 | return true; | 1139 | return true; |
1140 | } | 1140 | } |
1141 | 1141 | ||
1142 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) | 1142 | QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) |
1143 | { | 1143 | { |
1144 | if (!ab.d) return s; | 1144 | if (!ab.d) return s; |
1145 | 1145 | ||
1146 | return s << ab.d->mAddressees; | 1146 | return s << ab.d->mAddressees; |
1147 | } | 1147 | } |
1148 | 1148 | ||
1149 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) | 1149 | QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) |
1150 | { | 1150 | { |
1151 | if (!ab.d) return s; | 1151 | if (!ab.d) return s; |
1152 | 1152 | ||
1153 | s >> ab.d->mAddressees; | 1153 | s >> ab.d->mAddressees; |
1154 | 1154 | ||
1155 | return s; | 1155 | return s; |
1156 | } | 1156 | } |
1157 | 1157 | ||
1158 | bool AddressBook::addResource( Resource *resource ) | 1158 | bool AddressBook::addResource( Resource *resource ) |
1159 | { | 1159 | { |
1160 | if ( !resource->open() ) { | 1160 | if ( !resource->open() ) { |
1161 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; | 1161 | kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; |
1162 | return false; | 1162 | return false; |
1163 | } | 1163 | } |
1164 | 1164 | ||
1165 | resource->setAddressBook( this ); | 1165 | resource->setAddressBook( this ); |
1166 | 1166 | ||
1167 | d->mManager->add( resource ); | 1167 | d->mManager->add( resource ); |
1168 | return true; | 1168 | return true; |
1169 | } | 1169 | } |
1170 | void AddressBook::removeResources() | 1170 | void AddressBook::removeResources() |
1171 | { | 1171 | { |
1172 | //remove all possible resources. This should cleanup the configfile. | 1172 | //remove all possible resources. This should cleanup the configfile. |
1173 | QPtrList<KABC::Resource> mResources = resources(); | 1173 | QPtrList<KABC::Resource> mResources = resources(); |
1174 | 1174 | ||
1175 | QPtrListIterator<KABC::Resource> it(mResources); | 1175 | QPtrListIterator<KABC::Resource> it(mResources); |
1176 | for ( ; it.current(); ++it ) { | 1176 | for ( ; it.current(); ++it ) { |
1177 | KABC::Resource *res = it.current(); | 1177 | KABC::Resource *res = it.current(); |
1178 | removeResource(res); | 1178 | removeResource(res); |
1179 | } | 1179 | } |
1180 | } | 1180 | } |
1181 | 1181 | ||
1182 | bool AddressBook::removeResource( Resource *resource ) | 1182 | bool AddressBook::removeResource( Resource *resource ) |
1183 | { | 1183 | { |
1184 | resource->close(); | 1184 | resource->close(); |
1185 | 1185 | ||
1186 | if ( resource == standardResource() ) | 1186 | if ( resource == standardResource() ) |
1187 | d->mManager->setStandardResource( 0 ); | 1187 | d->mManager->setStandardResource( 0 ); |
1188 | 1188 | ||
1189 | resource->setAddressBook( 0 ); | 1189 | resource->setAddressBook( 0 ); |
1190 | 1190 | ||
1191 | d->mManager->remove( resource ); | 1191 | d->mManager->remove( resource ); |
1192 | return true; | 1192 | return true; |
1193 | } | 1193 | } |
1194 | 1194 | ||
1195 | QPtrList<Resource> AddressBook::resources() | 1195 | QPtrList<Resource> AddressBook::resources() |
1196 | { | 1196 | { |
1197 | QPtrList<Resource> list; | 1197 | QPtrList<Resource> list; |
1198 | 1198 | ||
1199 | // qDebug("AddressBook::resources() 1"); | 1199 | // qDebug("AddressBook::resources() 1"); |
1200 | 1200 | ||
1201 | KRES::Manager<Resource>::ActiveIterator it; | 1201 | KRES::Manager<Resource>::ActiveIterator it; |
1202 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) | 1202 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) |
1203 | list.append( *it ); | 1203 | list.append( *it ); |
1204 | 1204 | ||
1205 | return list; | 1205 | return list; |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | /*US | 1208 | /*US |
1209 | void AddressBook::setErrorHandler( ErrorHandler *handler ) | 1209 | void AddressBook::setErrorHandler( ErrorHandler *handler ) |
1210 | { | 1210 | { |
1211 | delete d->mErrorHandler; | 1211 | delete d->mErrorHandler; |
1212 | d->mErrorHandler = handler; | 1212 | d->mErrorHandler = handler; |
1213 | } | 1213 | } |
1214 | */ | 1214 | */ |
1215 | 1215 | ||
1216 | void AddressBook::error( const QString& msg ) | 1216 | void AddressBook::error( const QString& msg ) |
1217 | { | 1217 | { |
1218 | /*US | 1218 | /*US |
1219 | if ( !d->mErrorHandler ) // create default error handler | 1219 | if ( !d->mErrorHandler ) // create default error handler |
1220 | d->mErrorHandler = new ConsoleErrorHandler; | 1220 | d->mErrorHandler = new ConsoleErrorHandler; |
1221 | 1221 | ||
1222 | if ( d->mErrorHandler ) | 1222 | if ( d->mErrorHandler ) |
1223 | d->mErrorHandler->error( msg ); | 1223 | d->mErrorHandler->error( msg ); |
1224 | else | 1224 | else |
1225 | kdError(5700) << "no error handler defined" << endl; | 1225 | kdError(5700) << "no error handler defined" << endl; |
1226 | */ | 1226 | */ |
1227 | kdDebug(5700) << "msg" << endl; | 1227 | kdDebug(5700) << "msg" << endl; |
1228 | qDebug(msg); | 1228 | qDebug(msg); |
1229 | } | 1229 | } |
1230 | 1230 | ||
1231 | void AddressBook::deleteRemovedAddressees() | 1231 | void AddressBook::deleteRemovedAddressees() |
1232 | { | 1232 | { |
1233 | Addressee::List::Iterator it; | 1233 | Addressee::List::Iterator it; |
1234 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { | 1234 | for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { |
1235 | Resource *resource = (*it).resource(); | 1235 | Resource *resource = (*it).resource(); |
1236 | if ( resource && !resource->readOnly() && resource->isOpen() ) | 1236 | if ( resource && !resource->readOnly() && resource->isOpen() ) |
1237 | resource->removeAddressee( *it ); | 1237 | resource->removeAddressee( *it ); |
1238 | } | 1238 | } |
1239 | 1239 | ||
1240 | d->mRemovedAddressees.clear(); | 1240 | d->mRemovedAddressees.clear(); |
1241 | } | 1241 | } |
1242 | 1242 | ||
1243 | void AddressBook::setStandardResource( Resource *resource ) | 1243 | void AddressBook::setStandardResource( Resource *resource ) |
1244 | { | 1244 | { |
1245 | // qDebug("AddressBook::setStandardResource 1"); | 1245 | // qDebug("AddressBook::setStandardResource 1"); |
1246 | d->mManager->setStandardResource( resource ); | 1246 | d->mManager->setStandardResource( resource ); |
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | Resource *AddressBook::standardResource() | 1249 | Resource *AddressBook::standardResource() |
1250 | { | 1250 | { |
1251 | return d->mManager->standardResource(); | 1251 | return d->mManager->standardResource(); |
1252 | } | 1252 | } |
1253 | 1253 | ||
1254 | KRES::Manager<Resource> *AddressBook::resourceManager() | 1254 | KRES::Manager<Resource> *AddressBook::resourceManager() |
1255 | { | 1255 | { |
1256 | return d->mManager; | 1256 | return d->mManager; |
1257 | } | 1257 | } |
1258 | 1258 | ||
1259 | void AddressBook::cleanUp() | 1259 | void AddressBook::cleanUp() |
1260 | { | 1260 | { |
1261 | KRES::Manager<Resource>::ActiveIterator it; | 1261 | KRES::Manager<Resource>::ActiveIterator it; |
1262 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { | 1262 | for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { |
1263 | if ( !(*it)->readOnly() && (*it)->isOpen() ) | 1263 | if ( !(*it)->readOnly() && (*it)->isOpen() ) |
1264 | (*it)->cleanUp(); | 1264 | (*it)->cleanUp(); |
1265 | } | 1265 | } |
1266 | } | 1266 | } |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 6413b42..e8f8bdd 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -1,303 +1,303 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of libkabc. | 2 | This file is part of libkabc. |
3 | Copyright (c) 2004 Ulf Schenk | 3 | Copyright (c) 2004 Ulf Schenk |
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 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #include <unistd.h> | 30 | #include <unistd.h> |
31 | 31 | ||
32 | #include <qdir.h> | 32 | #include <qdir.h> |
33 | #include <qfile.h> | 33 | #include <qfile.h> |
34 | #include <qfileinfo.h> | 34 | #include <qfileinfo.h> |
35 | #include <qregexp.h> | 35 | #include <qregexp.h> |
36 | //US #include <qtimer.h> | 36 | //US #include <qtimer.h> |
37 | 37 | ||
38 | #include <kapplication.h> | 38 | #include <kapplication.h> |
39 | #include <kconfig.h> | 39 | #include <kconfig.h> |
40 | #include <kdebug.h> | 40 | #include <kdebug.h> |
41 | #include <klocale.h> | 41 | #include <klocale.h> |
42 | //US #include <ksavefile.h> | 42 | //US #include <ksavefile.h> |
43 | #include <kstandarddirs.h> | 43 | #include <kstandarddirs.h> |
44 | #include <kmessagebox.h> | 44 | #include <kmessagebox.h> |
45 | 45 | ||
46 | #include <sl/slzdb.h> | 46 | #include <sl/slzdb.h> |
47 | 47 | ||
48 | #include <libkdepim/ksyncprofile.h> | 48 | #include <libkdepim/ksyncprofile.h> |
49 | 49 | ||
50 | #include "resourcesharpdtmconfig.h" | 50 | #include "resourcesharpdtmconfig.h" |
51 | #include "resourcesharpdtm.h" | 51 | #include "resourcesharpdtm.h" |
52 | 52 | ||
53 | #include "stdaddressbook.h" | 53 | #include "stdaddressbook.h" |
54 | 54 | ||
55 | #include "sharpdtmconverter.h" | 55 | #include "sharpdtmconverter.h" |
56 | //#define ALLOW_LOCKING | 56 | //#define ALLOW_LOCKING |
57 | using namespace KABC; | 57 | using namespace KABC; |
58 | extern "C" | 58 | extern "C" |
59 | { | 59 | { |
60 | void *init_microkabc_sharpdtm() | 60 | void *init_microkabc_sharpdtm() |
61 | { | 61 | { |
62 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); | 62 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); |
63 | } | 63 | } |
64 | } | 64 | } |
65 | 65 | ||
66 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) | 66 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config ) |
67 | : Resource( config ), mConverter (0) | 67 | : Resource( config ), mConverter (0) |
68 | { | 68 | { |
69 | // we can not choose the filename. Therefore use the default to display | 69 | // we can not choose the filename. Therefore use the default to display |
70 | mAccess = 0; | 70 | mAccess = 0; |
71 | QString fileName = SlZDataBase::addressbookFileName(); | 71 | QString fileName = SlZDataBase::addressbookFileName(); |
72 | init( fileName ); | 72 | init( fileName ); |
73 | } | 73 | } |
74 | 74 | ||
75 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) | 75 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName ) |
76 | : Resource( 0 ) | 76 | : Resource( 0 ) |
77 | { | 77 | { |
78 | mAccess = 0; | 78 | mAccess = 0; |
79 | init( fileName ); | 79 | init( fileName ); |
80 | } | 80 | } |
81 | 81 | ||
82 | void ResourceSharpDTM::init( const QString &fileName ) | 82 | void ResourceSharpDTM::init( const QString &fileName ) |
83 | { | 83 | { |
84 | if (mConverter == 0) { | 84 | if (mConverter == 0) { |
85 | mConverter = new SharpDTMConverter(); | 85 | mConverter = new SharpDTMConverter(); |
86 | bool res = mConverter->init(); | 86 | bool res = mConverter->init(); |
87 | if ( !res ) | 87 | if ( !res ) |
88 | { | 88 | { |
89 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 89 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
90 | qDebug(msg); | 90 | qDebug(msg); |
91 | return; | 91 | return; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | setFileName( fileName ); | 94 | setFileName( fileName ); |
95 | } | 95 | } |
96 | 96 | ||
97 | ResourceSharpDTM::~ResourceSharpDTM() | 97 | ResourceSharpDTM::~ResourceSharpDTM() |
98 | { | 98 | { |
99 | if (mConverter != 0) | 99 | if (mConverter != 0) |
100 | delete mConverter; | 100 | delete mConverter; |
101 | 101 | ||
102 | if(mAccess != 0) | 102 | if(mAccess != 0) |
103 | delete mAccess; | 103 | delete mAccess; |
104 | } | 104 | } |
105 | 105 | ||
106 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 106 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
107 | { | 107 | { |
108 | Resource::writeConfig( config ); | 108 | Resource::writeConfig( config ); |
109 | } | 109 | } |
110 | 110 | ||
111 | Ticket *ResourceSharpDTM::requestSaveTicket() | 111 | Ticket *ResourceSharpDTM::requestSaveTicket() |
112 | { | 112 | { |
113 | 113 | ||
114 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 114 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); |
115 | 115 | ||
116 | if ( !addressBook() ) return 0; | 116 | if ( !addressBook() ) return 0; |
117 | return createTicket( this ); | 117 | return createTicket( this ); |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | bool ResourceSharpDTM::doOpen() | 121 | bool ResourceSharpDTM::doOpen() |
122 | { | 122 | { |
123 | if (!mConverter) | 123 | if (!mConverter) |
124 | return false; | 124 | return false; |
125 | return true; | 125 | return true; |
126 | } | 126 | } |
127 | 127 | ||
128 | void ResourceSharpDTM::doClose() | 128 | void ResourceSharpDTM::doClose() |
129 | { | 129 | { |
130 | return; | 130 | return; |
131 | } | 131 | } |
132 | 132 | ||
133 | bool ResourceSharpDTM::load() | 133 | bool ResourceSharpDTM::load() |
134 | { | 134 | { |
135 | if (!mConverter) | 135 | if (!mConverter) |
136 | return false; | 136 | return false; |
137 | QString fileN = SlZDataBase::addressbookFileName(); | 137 | QString fileN = SlZDataBase::addressbookFileName(); |
138 | if ( ! mAccess ) { | 138 | if ( ! mAccess ) { |
139 | mAccess = new SlZDataBase(fileN, | 139 | mAccess = new SlZDataBase(fileN, |
140 | SlZDataBase::addressbookItems(), | 140 | SlZDataBase::addressbookItems(), |
141 | 0, false); | 141 | 0, true); |
142 | } | 142 | } |
143 | if(mAccess == 0) | 143 | if(mAccess == 0) |
144 | return false; | 144 | return false; |
145 | 145 | ||
146 | qDebug("%xResourceSharpDTM::load: %s",this, fileName().latin1()); | 146 | qDebug("ResourceSharpDTM:: %x load: %s",this, fileName().latin1()); |
147 | bool res = false; | 147 | bool res = false; |
148 | CardId id; | 148 | CardId id; |
149 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | 149 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
150 | { | 150 | { |
151 | id = mAccess->cardId(); | 151 | id = mAccess->cardId(); |
152 | KABC::Addressee addressee; | 152 | KABC::Addressee addressee; |
153 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 153 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
154 | if ( !addressee.isEmpty() && res ) | 154 | if ( !addressee.isEmpty() && res ) |
155 | { | 155 | { |
156 | addressee.setResource( this ); | 156 | addressee.setResource( this ); |
157 | addressBook()->insertAddressee( addressee ); | 157 | addressBook()->insertAddressee( addressee ); |
158 | } | 158 | } |
159 | } | 159 | } |
160 | if(mAccess != 0) | 160 | if(mAccess != 0) |
161 | delete mAccess; | 161 | delete mAccess; |
162 | mAccess = 0; | 162 | mAccess = 0; |
163 | 163 | ||
164 | return true; | 164 | return true; |
165 | } | 165 | } |
166 | 166 | ||
167 | bool ResourceSharpDTM::save( Ticket *ticket ) | 167 | bool ResourceSharpDTM::save( Ticket *ticket ) |
168 | { | 168 | { |
169 | if (!mConverter) | 169 | if (!mConverter) |
170 | return false; | 170 | return false; |
171 | QString fileN = SlZDataBase::addressbookFileName(); | 171 | QString fileN = SlZDataBase::addressbookFileName(); |
172 | if ( ! mAccess ) { | 172 | if ( ! mAccess ) { |
173 | mAccess = new SlZDataBase(fileN, | 173 | mAccess = new SlZDataBase(fileN, |
174 | SlZDataBase::addressbookItems(), | 174 | SlZDataBase::addressbookItems(), |
175 | 0, false); | 175 | 0, false); |
176 | } | 176 | } |
177 | if(mAccess == 0) | 177 | if(mAccess == 0) |
178 | return false; | 178 | return false; |
179 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); | 179 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
180 | KABC::AddressBook::Iterator it; | 180 | KABC::AddressBook::Iterator it; |
181 | bool res; | 181 | bool res; |
182 | KABC::Addressee::List changedAddressees; | 182 | KABC::Addressee::List changedAddressees; |
183 | typedef QMap<int,QString> AddresseeMap; | 183 | typedef QMap<int,QString> AddresseeMap; |
184 | AddresseeMap map; | 184 | AddresseeMap map; |
185 | CardId id ; | 185 | CardId id ; |
186 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 186 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
187 | 187 | ||
188 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 188 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
189 | QString uid = (*it).originalExternalUID(); | 189 | QString uid = (*it).originalExternalUID(); |
190 | bool res; | 190 | bool res; |
191 | if ( uid.isEmpty() ) | 191 | if ( uid.isEmpty() ) |
192 | id = 0; | 192 | id = 0; |
193 | else | 193 | else |
194 | id = uid.toUInt(); | 194 | id = uid.toUInt(); |
195 | KABC::Addressee addressee = (*it); | 195 | KABC::Addressee addressee = (*it); |
196 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 196 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
197 | res = mAccess->startEditCard(id); | 197 | res = mAccess->startEditCard(id); |
198 | if (res == true) | 198 | if (res == true) |
199 | { | 199 | { |
200 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 200 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
201 | if (res == true) | 201 | if (res == true) |
202 | { | 202 | { |
203 | res = mAccess->finishEditCard(&id);; | 203 | res = mAccess->finishEditCard(&id);; |
204 | mConverter->setCategories( (*it), mAccess, id ); | 204 | mConverter->setCategories( (*it), mAccess, id ); |
205 | map.insert(id,(*it).uid()); | 205 | map.insert(id,(*it).uid()); |
206 | if (res == false) | 206 | if (res == false) |
207 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 207 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
208 | 208 | ||
209 | } | 209 | } |
210 | else | 210 | else |
211 | { | 211 | { |
212 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 212 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
213 | mAccess->cancelEditCard(); | 213 | mAccess->cancelEditCard(); |
214 | } | 214 | } |
215 | } | 215 | } |
216 | 216 | ||
217 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 217 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
218 | res = mAccess->deleteCard(&id); | 218 | res = mAccess->deleteCard(&id); |
219 | if ( !res ) | 219 | if ( !res ) |
220 | qDebug("delete error "); | 220 | qDebug("delete error "); |
221 | 221 | ||
222 | 222 | ||
223 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 223 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
224 | //changed | 224 | //changed |
225 | res = mAccess->startEditCard(id); | 225 | res = mAccess->startEditCard(id); |
226 | if (res == true) | 226 | if (res == true) |
227 | { | 227 | { |
228 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 228 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
229 | if (res == true) | 229 | if (res == true) |
230 | { | 230 | { |
231 | res = mAccess->finishEditCard(&id); | 231 | res = mAccess->finishEditCard(&id); |
232 | mConverter->setCategories( (*it), mAccess, id ); | 232 | mConverter->setCategories( (*it), mAccess, id ); |
233 | map.insert(id,(*it).uid()); | 233 | map.insert(id,(*it).uid()); |
234 | if (res == false) | 234 | if (res == false) |
235 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 235 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
236 | } | 236 | } |
237 | else | 237 | else |
238 | { | 238 | { |
239 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 239 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
240 | mAccess->cancelEditCard(); | 240 | mAccess->cancelEditCard(); |
241 | } | 241 | } |
242 | } | 242 | } |
243 | } | 243 | } |
244 | } | 244 | } |
245 | 245 | ||
246 | } | 246 | } |
247 | AddresseeMap::Iterator itam; | 247 | AddresseeMap::Iterator itam; |
248 | for ( res=mAccess->first(); res == true; res=mAccess->next()) | 248 | for ( res=mAccess->first(); res == true; res=mAccess->next()) |
249 | { | 249 | { |
250 | id = mAccess->cardId(); | 250 | id = mAccess->cardId(); |
251 | int idint = id; | 251 | int idint = id; |
252 | itam = map.find( idint ); | 252 | itam = map.find( idint ); |
253 | if ( itam != map.end() ) { | 253 | if ( itam != map.end() ) { |
254 | KABC::Addressee addressee; | 254 | KABC::Addressee addressee; |
255 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 255 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
256 | 256 | ||
257 | if ( !addressee.isEmpty() && res ) | 257 | if ( !addressee.isEmpty() && res ) |
258 | { | 258 | { |
259 | addressee.setResource( this ); | 259 | addressee.setResource( this ); |
260 | addressee.setUid( itam.data() ); | 260 | addressee.setUid( itam.data() ); |
261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 261 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
262 | addressBook()->insertAddressee( addressee , false ); | 262 | addressBook()->insertAddressee( addressee , false ); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | } | 265 | } |
266 | delete ticket; | 266 | delete ticket; |
267 | if(mAccess != 0) | 267 | if(mAccess != 0) |
268 | delete mAccess; | 268 | delete mAccess; |
269 | mAccess = 0; | 269 | mAccess = 0; |
270 | return true; | 270 | return true; |
271 | } | 271 | } |
272 | 272 | ||
273 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 273 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
274 | { | 274 | { |
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | 277 | ||
278 | void ResourceSharpDTM::unlock( const QString &fileName ) | 278 | void ResourceSharpDTM::unlock( const QString &fileName ) |
279 | { | 279 | { |
280 | 280 | ||
281 | } | 281 | } |
282 | 282 | ||
283 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 283 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
284 | { | 284 | { |
285 | Resource::setFileName( newFileName ); | 285 | Resource::setFileName( newFileName ); |
286 | } | 286 | } |
287 | 287 | ||
288 | void ResourceSharpDTM::fileChanged() | 288 | void ResourceSharpDTM::fileChanged() |
289 | { | 289 | { |
290 | 290 | ||
291 | } | 291 | } |
292 | 292 | ||
293 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 293 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
294 | { | 294 | { |
295 | } | 295 | } |
296 | 296 | ||
297 | void ResourceSharpDTM::cleanUp() | 297 | void ResourceSharpDTM::cleanUp() |
298 | { | 298 | { |
299 | 299 | ||
300 | } | 300 | } |
301 | 301 | ||
302 | 302 | ||
303 | 303 | ||
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp index 95e16b6..4adcae4 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp | |||
@@ -1,486 +1,444 @@ | |||
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 | #include "kglobal.h" | 28 | #include "kglobal.h" |
29 | #include <qregexp.h> | 29 | #include <qregexp.h> |
30 | 30 | ||
31 | 31 | ||
32 | #include "sharpdtmconverter.h" | 32 | #include "sharpdtmconverter.h" |
33 | 33 | ||
34 | #include <sl/slcategories.h> | 34 | #include <sl/slcategories.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 | using namespace SlCategory; | 40 | using namespace SlCategory; |
41 | 41 | ||
42 | SharpDTMConverter::SharpDTMConverter() : catDB(0) | 42 | SharpDTMConverter::SharpDTMConverter() : catDB(0) |
43 | { | 43 | { |
44 | } | 44 | } |
45 | 45 | ||
46 | SharpDTMConverter::~SharpDTMConverter() | 46 | SharpDTMConverter::~SharpDTMConverter() |
47 | { | 47 | { |
48 | deinit(); | 48 | deinit(); |
49 | } | 49 | } |
50 | 50 | ||
51 | bool SharpDTMConverter::init() | 51 | bool SharpDTMConverter::init() |
52 | { | 52 | { |
53 | catDB = new SlCategory::SlCategories(); | 53 | catDB = new SlCategory::SlCategories(); |
54 | 54 | ||
55 | if (!catDB) | 55 | if (!catDB) |
56 | return false; | 56 | return false; |
57 | 57 | ||
58 | // catDB->load( categoryFileName() ); | 58 | // catDB->load( categoryFileName() ); |
59 | return true; | 59 | return true; |
60 | } | 60 | } |
61 | 61 | ||
62 | void SharpDTMConverter::deinit() | 62 | void SharpDTMConverter::deinit() |
63 | { | 63 | { |
64 | if (catDB) | 64 | if (catDB) |
65 | { | 65 | { |
66 | delete catDB; | 66 | delete catDB; |
67 | catDB = 0; | 67 | catDB = 0; |
68 | } | 68 | } |
69 | } | 69 | } |
70 | 70 | ||
71 | bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr ) | 71 | bool SharpDTMConverter::sharpToAddressee( const CardId &contact, const SlZDataBase* database, Addressee &addr ) |
72 | { | 72 | { |
73 | SlZDataBase* db = (SlZDataBase*)database; | 73 | SlZDataBase* db = (SlZDataBase*)database; |
74 | 74 | ||
75 | // for syncing: we need setting of the two fields | 75 | // for syncing: we need setting of the two fields |
76 | addr.setExternalUID( QString::number( contact ) ); | 76 | addr.setExternalUID( QString::number( contact ) ); |
77 | addr.setOriginalExternalUID( QString::number( contact ) ); | 77 | addr.setOriginalExternalUID( QString::number( contact ) ); |
78 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); | 78 | addr.setTempSyncStat( SYNC_TEMPSTATE_NEW_EXTERNAL ); |
79 | 79 | ||
80 | 80 | ||
81 | // name | 81 | // name |
82 | //qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!"); | 82 | //qDebug("SharpDTMConverter::sharpToAddressee check if the fileAs transformation works!!"); |
83 | addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); | 83 | addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); |
84 | //addr.setName(db->readField(ZdbAdrs::FullName)); | 84 | //addr.setName(db->readField(ZdbAdrs::FullName)); |
85 | 85 | ||
86 | addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); | 86 | addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); |
87 | addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); | 87 | addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); |
88 | addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); | 88 | addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); |
89 | addr.setPrefix( db->readField(ZdbAdrs::Title) ); | 89 | addr.setPrefix( db->readField(ZdbAdrs::Title) ); |
90 | addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); | 90 | addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); |
91 | 91 | ||
92 | 92 | ||
93 | QString emailstr = db->readField(ZdbAdrs::Emails); | 93 | QString emailstr = db->readField(ZdbAdrs::Emails); |
94 | emailstr.replace( QRegExp(","), " " ); | 94 | emailstr.replace( QRegExp(","), " " ); |
95 | emailstr.replace( QRegExp(";"), " " ); | 95 | emailstr.replace( QRegExp(";"), " " ); |
96 | emailstr.replace( QRegExp(":"), " " ); | 96 | emailstr.replace( QRegExp(":"), " " ); |
97 | //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); | 97 | //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); |
98 | QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace()); | 98 | QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace()); |
99 | bool defE = false; | 99 | bool defE = false; |
100 | bool found = false; | 100 | bool found = false; |
101 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 101 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
102 | if (found ) | 102 | if (found ) |
103 | defE = false; | 103 | defE = false; |
104 | else | 104 | else |
105 | found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower()); | 105 | found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower()); |
106 | addr.insertEmail( *it, defE ); | 106 | addr.insertEmail( *it, defE ); |
107 | } | 107 | } |
108 | if ( ! found ) | 108 | if ( ! found ) |
109 | if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) | 109 | if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) |
110 | addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); | 110 | addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); |
111 | 111 | ||
112 | // home | 112 | // home |
113 | if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || | 113 | if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || |
114 | (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || | 114 | (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || |
115 | (!db->readField(ZdbAdrs::HomeState).isEmpty()) || | 115 | (!db->readField(ZdbAdrs::HomeState).isEmpty()) || |
116 | (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || | 116 | (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || |
117 | (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) | 117 | (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) |
118 | { | 118 | { |
119 | Address homeaddress; | 119 | Address homeaddress; |
120 | homeaddress.setType(Address::Home); | 120 | homeaddress.setType(Address::Home); |
121 | //US homeaddress.setPostOfficeBox( "" ); | 121 | //US homeaddress.setPostOfficeBox( "" ); |
122 | //US homeaddress.setExtended( "" ); | 122 | //US homeaddress.setExtended( "" ); |
123 | homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet).replace( QRegExp("\\r"), "")); | 123 | homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet).replace( QRegExp("\\r"), "")); |
124 | homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); | 124 | homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); |
125 | homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); | 125 | homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); |
126 | homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); | 126 | homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); |
127 | homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); | 127 | homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); |
128 | 128 | ||
129 | addr.insertAddress( homeaddress ); | 129 | addr.insertAddress( homeaddress ); |
130 | } | 130 | } |
131 | 131 | ||
132 | if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) | 132 | if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) |
133 | { | 133 | { |
134 | PhoneNumber homephone; | 134 | PhoneNumber homephone; |
135 | homephone.setType( PhoneNumber::Home ); | 135 | homephone.setType( PhoneNumber::Home ); |
136 | homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); | 136 | homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); |
137 | addr.insertPhoneNumber( homephone ); | 137 | addr.insertPhoneNumber( homephone ); |
138 | } | 138 | } |
139 | 139 | ||
140 | if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) | 140 | if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) |
141 | { | 141 | { |
142 | PhoneNumber homefax; | 142 | PhoneNumber homefax; |
143 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | 143 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); |
144 | homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); | 144 | homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); |
145 | addr.insertPhoneNumber( homefax ); | 145 | addr.insertPhoneNumber( homefax ); |
146 | } | 146 | } |
147 | 147 | ||
148 | if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) | 148 | if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) |
149 | { | 149 | { |
150 | PhoneNumber homemobile; | 150 | PhoneNumber homemobile; |
151 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | 151 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); |
152 | homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); | 152 | homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); |
153 | addr.insertPhoneNumber( homemobile ); | 153 | addr.insertPhoneNumber( homemobile ); |
154 | } | 154 | } |
155 | 155 | ||
156 | addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); | 156 | addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); |
157 | 157 | ||
158 | 158 | ||
159 | // business | 159 | // business |
160 | if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || | 160 | if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || |
161 | (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || | 161 | (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || |
162 | (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || | 162 | (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || |
163 | (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || | 163 | (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || |
164 | (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) | 164 | (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) |
165 | { | 165 | { |
166 | Address businessaddress; | 166 | Address businessaddress; |
167 | businessaddress.setType(Address::Work); | 167 | businessaddress.setType(Address::Work); |
168 | //US businessaddress.setPostOfficeBox( "" ); | 168 | //US businessaddress.setPostOfficeBox( "" ); |
169 | //US businessaddress.setExtended( "" ); | 169 | //US businessaddress.setExtended( "" ); |
170 | businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet).replace( QRegExp("\\r"), "") ); | 170 | businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet).replace( QRegExp("\\r"), "") ); |
171 | businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); | 171 | businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); |
172 | businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); | 172 | businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); |
173 | businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); | 173 | businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); |
174 | businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); | 174 | businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); |
175 | 175 | ||
176 | addr.insertAddress( businessaddress ); | 176 | addr.insertAddress( businessaddress ); |
177 | } | 177 | } |
178 | 178 | ||
179 | 179 | ||
180 | if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) | 180 | if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) |
181 | { | 181 | { |
182 | PhoneNumber businessphone; | 182 | PhoneNumber businessphone; |
183 | businessphone.setType( PhoneNumber::Work ); | 183 | businessphone.setType( PhoneNumber::Work ); |
184 | businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); | 184 | businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); |
185 | addr.insertPhoneNumber( businessphone ); | 185 | addr.insertPhoneNumber( businessphone ); |
186 | } | 186 | } |
187 | 187 | ||
188 | if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) | 188 | if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) |
189 | { | 189 | { |
190 | PhoneNumber businessfax; | 190 | PhoneNumber businessfax; |
191 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | 191 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); |
192 | businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); | 192 | businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); |
193 | addr.insertPhoneNumber( businessfax ); | 193 | addr.insertPhoneNumber( businessfax ); |
194 | } | 194 | } |
195 | 195 | ||
196 | if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) | 196 | if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) |
197 | { | 197 | { |
198 | PhoneNumber businessmobile; | 198 | PhoneNumber businessmobile; |
199 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | 199 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); |
200 | businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); | 200 | businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); |
201 | addr.insertPhoneNumber( businessmobile ); | 201 | addr.insertPhoneNumber( businessmobile ); |
202 | } | 202 | } |
203 | 203 | ||
204 | if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) | 204 | if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) |
205 | { | 205 | { |
206 | PhoneNumber businesspager; | 206 | PhoneNumber businesspager; |
207 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | 207 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); |
208 | businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); | 208 | businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); |
209 | addr.insertPhoneNumber( businesspager ); | 209 | addr.insertPhoneNumber( businesspager ); |
210 | } | 210 | } |
211 | 211 | ||
212 | addr.setRole( db->readField(ZdbAdrs::JobTitle) ); | 212 | addr.setRole( db->readField(ZdbAdrs::JobTitle) ); |
213 | addr.setOrganization( db->readField(ZdbAdrs::Company) ); | 213 | addr.setOrganization( db->readField(ZdbAdrs::Company) ); |
214 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); | 214 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); |
215 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); | 215 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); |
216 | addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); | 216 | addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); |
217 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); | 217 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); |
218 | addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); | 218 | addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); |
219 | 219 | ||
220 | //personal | 220 | //personal |
221 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); | 221 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); |
222 | 222 | ||
223 | QString gen = db->readField(ZdbAdrs::Gender); | 223 | QString gen = db->readField(ZdbAdrs::Gender); |
224 | //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); | 224 | //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); |
225 | //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); | 225 | //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); |
226 | if (gen == "1") | 226 | if (gen == "1") |
227 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | 227 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); |
228 | else if (gen == "2") | 228 | else if (gen == "2") |
229 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | 229 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); |
230 | else | 230 | else |
231 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "undef"); | 231 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "undef"); |
232 | 232 | ||
233 | 233 | ||
234 | QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); | 234 | QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); |
235 | if (ann.isValid()) { | 235 | if (ann.isValid()) { |
236 | QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); | 236 | QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); |
237 | //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); | 237 | //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); |
238 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | 238 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); |
239 | } else | 239 | } else |
240 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", " "); | 240 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", " "); |
241 | 241 | ||
242 | 242 | ||
243 | 243 | ||
244 | addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); | 244 | addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); |
245 | 245 | ||
246 | 246 | ||
247 | QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); | 247 | QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); |
248 | //qDebug("birtd %s ", birthd.toString().latin1()); | 248 | //qDebug("birtd %s ", birthd.toString().latin1()); |
249 | if (birthd.isValid()) | 249 | if (birthd.isValid()) |
250 | addr.setBirthday( birthd ); | 250 | addr.setBirthday( birthd ); |
251 | 251 | ||
252 | addr.setNickName( db->readField(ZdbAdrs::Nickname) ); | 252 | addr.setNickName( db->readField(ZdbAdrs::Nickname) ); |
253 | 253 | ||
254 | // others | 254 | // others |
255 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | 255 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. |
256 | //QString notes = db->readField(ZdbAdrs::Notes); | 256 | //QString notes = db->readField(ZdbAdrs::Notes); |
257 | //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; | 257 | //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; |
258 | if ( addr.url().isEmpty() ) | 258 | if ( addr.url().isEmpty() ) |
259 | addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); | 259 | addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); |
260 | addr.setNote( db->readField(ZdbAdrs::Notes).replace( QRegExp("\\r"), "")); | 260 | addr.setNote( db->readField(ZdbAdrs::Notes).replace( QRegExp("\\r"), "")); |
261 | 261 | ||
262 | 262 | ||
263 | 263 | ||
264 | //US QString groups() const { return find( Qtopia::Groups ); } | 264 | //US QString groups() const { return find( Qtopia::Groups ); } |
265 | //US QStringList groupList() const; | 265 | //US QStringList groupList() const; |
266 | 266 | ||
267 | //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); | 267 | //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); |
268 | QArray<int> catArray = db->readCategories(); | 268 | QArray<int> catArray = db->readCategories(); |
269 | QString cat; | 269 | QString cat; |
270 | 270 | ||
271 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | 271 | for ( unsigned int i=0; i < catArray.size(); i++ ) { |
272 | cat = catDB->label(catArray[i]); | 272 | cat = catDB->label(catArray[i]); |
273 | if ( cat.isEmpty() ) | 273 | if ( cat.isEmpty() ) |
274 | addr.insertCategory(QString::number(catArray[i])); | 274 | addr.insertCategory(QString::number(catArray[i])); |
275 | else | 275 | else |
276 | addr.insertCategory( cat ); | 276 | addr.insertCategory( cat ); |
277 | } | 277 | } |
278 | 278 | ||
279 | return true; | 279 | return true; |
280 | } | 280 | } |
281 | 281 | ||
282 | bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) | 282 | bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) |
283 | { | 283 | { |
284 | bool cellHome = false, cellWork = false; | 284 | bool cellHome = false, cellWork = false; |
285 | // name | 285 | // name |
286 | database->writeField(ZdbAdrs::LastName, addr.familyName()); | 286 | database->writeField(ZdbAdrs::LastName, addr.familyName()); |
287 | database->writeField(ZdbAdrs::FirstName, addr.givenName()); | 287 | database->writeField(ZdbAdrs::FirstName, addr.givenName()); |
288 | database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); | 288 | database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); |
289 | database->writeField(ZdbAdrs::Title, addr.prefix()); | 289 | database->writeField(ZdbAdrs::Title, addr.prefix()); |
290 | database->writeField(ZdbAdrs::Suffix, addr.suffix()); | 290 | database->writeField(ZdbAdrs::Suffix, addr.suffix()); |
291 | 291 | ||
292 | //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); | 292 | //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); |
293 | QString formattedName = addr.formattedName(); | 293 | QString formattedName = addr.formattedName(); |
294 | if ( formattedName.isEmpty() ) { | 294 | if ( formattedName.isEmpty() ) { |
295 | if ( !addr.familyName().isEmpty() ) { | 295 | if ( !addr.familyName().isEmpty() ) { |
296 | formattedName = addr.familyName(); | 296 | formattedName = addr.familyName(); |
297 | if ( !addr.givenName().isEmpty() ) { | 297 | if ( !addr.givenName().isEmpty() ) { |
298 | formattedName += ", "; | 298 | formattedName += ", "; |
299 | formattedName += addr.givenName(); | 299 | formattedName += addr.givenName(); |
300 | } | 300 | } |
301 | } else | 301 | } else |
302 | formattedName = addr.givenName(); | 302 | formattedName = addr.givenName(); |
303 | } | 303 | } |
304 | database->writeField(ZdbAdrs::FileAs, formattedName); | 304 | database->writeField(ZdbAdrs::FileAs, formattedName); |
305 | database->writeField(ZdbAdrs::FullName, formattedName); | 305 | database->writeField(ZdbAdrs::FullName, formattedName); |
306 | 306 | ||
307 | 307 | ||
308 | //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); | 308 | //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); |
309 | //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); | 309 | //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); |
310 | QString emails = addr.emails().join(" "); | 310 | QString emails = addr.emails().join(" "); |
311 | database->writeField(ZdbAdrs::Emails, emails ); | 311 | database->writeField(ZdbAdrs::Emails, emails ); |
312 | 312 | ||
313 | database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); | 313 | database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); |
314 | // home | 314 | // home |
315 | const Address homeaddress = addr.address(Address::Home); | 315 | const Address homeaddress = addr.address(Address::Home); |
316 | database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); | 316 | database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); |
317 | database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); | 317 | database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); |
318 | database->writeField(ZdbAdrs::HomeState, homeaddress.region()); | 318 | database->writeField(ZdbAdrs::HomeState, homeaddress.region()); |
319 | database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); | 319 | database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); |
320 | database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); | 320 | database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); |
321 | 321 | ||
322 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 322 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
323 | database->writeField(ZdbAdrs::HomePhone, homephone.number()); | 323 | database->writeField(ZdbAdrs::HomePhone, homephone.number()); |
324 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 324 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
325 | database->writeField(ZdbAdrs::HomeFax, homefax.number()); | 325 | database->writeField(ZdbAdrs::HomeFax, homefax.number()); |
326 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 326 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
327 | database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); | 327 | database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); |
328 | if (!homemobile.number().isEmpty()) { | 328 | if (!homemobile.number().isEmpty()) { |
329 | cellHome = true; | 329 | cellHome = true; |
330 | } | 330 | } |
331 | database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); | 331 | database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); |
332 | // business | 332 | // business |
333 | const Address businessaddress = addr.address(Address::Work); | 333 | const Address businessaddress = addr.address(Address::Work); |
334 | //qDebug("write business address "); | 334 | //qDebug("write business address "); |
335 | database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); | 335 | database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); |
336 | database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); | 336 | database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); |
337 | database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); | 337 | database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); |
338 | database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); | 338 | database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); |
339 | database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); | 339 | database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); |
340 | 340 | ||
341 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 341 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
342 | database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); | 342 | database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); |
343 | 343 | ||
344 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 344 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
345 | database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); | 345 | database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); |
346 | 346 | ||
347 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 347 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
348 | database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); | 348 | database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); |
349 | if (!businessmobile.number().isEmpty()) { | 349 | if (!businessmobile.number().isEmpty()) { |
350 | cellWork = true; | 350 | cellWork = true; |
351 | } | 351 | } |
352 | PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); | 352 | PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); |
353 | if (! mobile.number().isEmpty()) { | 353 | if (! mobile.number().isEmpty()) { |
354 | if ( ! cellHome ) | 354 | if ( ! cellHome ) |
355 | database->writeField(ZdbAdrs::HomeMobile, mobile.number()); | 355 | database->writeField(ZdbAdrs::HomeMobile, mobile.number()); |
356 | else if (! cellWork ) | 356 | else if (! cellWork ) |
357 | database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); | 357 | database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); |
358 | } | 358 | } |
359 | 359 | ||
360 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 360 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
361 | database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); | 361 | database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); |
362 | 362 | ||
363 | database->writeField(ZdbAdrs::JobTitle, addr.role()); | 363 | database->writeField(ZdbAdrs::JobTitle, addr.role()); |
364 | database->writeField(ZdbAdrs::Company, addr.organization()); | 364 | database->writeField(ZdbAdrs::Company, addr.organization()); |
365 | 365 | ||
366 | database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); | 366 | database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); |
367 | database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | 367 | database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); |
368 | database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); | 368 | database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); |
369 | database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | 369 | database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); |
370 | database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); | 370 | database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); |
371 | 371 | ||
372 | //personal | 372 | //personal |
373 | database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); | 373 | database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); |
374 | 374 | ||
375 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | 375 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); |
376 | //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); | 376 | //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); |
377 | //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); | 377 | //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); |
378 | //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); | 378 | //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); |
379 | if (gt == "male") | 379 | if (gt == "male") |
380 | database->writeField(ZdbAdrs::Gender, "1"); | 380 | database->writeField(ZdbAdrs::Gender, "1"); |
381 | else if (gt == "female") | 381 | else if (gt == "female") |
382 | database->writeField(ZdbAdrs::Gender, "2"); | 382 | database->writeField(ZdbAdrs::Gender, "2"); |
383 | else | 383 | else |
384 | database->writeField(ZdbAdrs::Gender, ""); | 384 | database->writeField(ZdbAdrs::Gender, ""); |
385 | 385 | ||
386 | QString dateS ; | 386 | QString dateS ; |
387 | QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | 387 | QDate dt = KGlobal::locale()->readDate(addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
388 | if ( dt.isValid() ) { | 388 | if ( dt.isValid() ) { |
389 | dateS = KGlobal::locale()->formatDate(dt, true ); | 389 | dateS = KGlobal::locale()->formatDate(dt, true ); |
390 | } | 390 | } |
391 | database->writeField(ZdbAdrs::Anniversary, dateS ); | 391 | database->writeField(ZdbAdrs::Anniversary, dateS ); |
392 | database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); | 392 | database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); |
393 | dt = addr.birthday().date(); | 393 | dt = addr.birthday().date(); |
394 | dateS = ""; | 394 | dateS = ""; |
395 | if ( dt.isValid() ) { | 395 | if ( dt.isValid() ) { |
396 | dateS = KGlobal::locale()->formatDate(dt, true ); | 396 | dateS = KGlobal::locale()->formatDate(dt, true ); |
397 | } | 397 | } |
398 | database->writeField(ZdbAdrs::Birthday, dateS); | 398 | database->writeField(ZdbAdrs::Birthday, dateS); |
399 | database->writeField(ZdbAdrs::Nickname, addr.nickName()); | 399 | database->writeField(ZdbAdrs::Nickname, addr.nickName()); |
400 | 400 | ||
401 | // other | 401 | // other |
402 | database->writeField(ZdbAdrs::Notes, addr.note()); | 402 | database->writeField(ZdbAdrs::Notes, addr.note()); |
403 | 403 | ||
404 | //US QString groups() const { return find( Qtopia::Groups ); } | 404 | //US QString groups() const { return find( Qtopia::Groups ); } |
405 | //US QStringList groupList() const; | 405 | //US QStringList groupList() const; |
406 | 406 | ||
407 | 407 | ||
408 | //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); | 408 | //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); |
409 | 409 | ||
410 | return true; | 410 | return true; |
411 | } | 411 | } |
412 | 412 | ||
413 | 413 | ||
414 | bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) | 414 | bool SharpDTMConverter::setCategories( const Addressee &addr, SlZDataBase* database , const CardId &contact ) |
415 | { | 415 | { |
416 | QStringList list = addr.categories(); | 416 | QStringList list = addr.categories(); |
417 | 417 | ||
418 | QArray<int> ids(list.count()); | 418 | QArray<int> ids(list.count()); |
419 | uint index = 0; | 419 | uint index = 0; |
420 | for(uint i=0; i<ids.size(); i++){ | 420 | for(uint i=0; i<ids.size(); i++){ |
421 | if(catDB->exists(list[i])){ | 421 | if(catDB->exists(list[i])){ |
422 | ids[index] = catDB->id(list[i]); | 422 | ids[index] = catDB->id(list[i]); |
423 | qDebug("set ex cat %d %s ",ids[index] , list[i].latin1()); | 423 | //qDebug("set exist cat %d %s ",ids[index] , list[i].latin1()); |
424 | index++; | 424 | index++; |
425 | } else { | 425 | } else { |
426 | ids[index] = catDB->addCategory(list[i]); | 426 | ids[index] = catDB->addCategory(list[i]); |
427 | qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); | 427 | //qDebug("add new cat %d %s ",ids[index] , list[i].latin1()); |
428 | index++; | 428 | index++; |
429 | } | 429 | } |
430 | } | 430 | } |
431 | bool res ; | 431 | bool res ; |
432 | if ( res = database->updateCategories(contact, ids) ) | 432 | |
433 | qDebug("cat updated "); | 433 | if ( !(res = database->updateCategories(contact, ids) )) |
434 | else | 434 | qDebug("SharpDTMConverter::Error updating categories"); |
435 | qDebug("error cat updating "); | ||
436 | 435 | ||
437 | return res; | 436 | return res; |
438 | } | 437 | } |
439 | 438 | ||
440 | #if 0 | ||
441 | m_pCategories = new SlCategories; | ||
442 | catDB | ||
443 | |||
444 | if(categories == QString::null) return true; | ||
445 | QStringList list = CSVParser::parse(categories); | ||
446 | QArray<int> ids(list.count()); | ||
447 | uint index = 0; | ||
448 | for(uint i=0; i<ids.size(); i++){ | ||
449 | #if 0 | ||
450 | bool ok; | ||
451 | ids[index] = list[i].toInt(&ok); | ||
452 | if(ok){ | ||
453 | index++; | ||
454 | } else { | ||
455 | if(m_pCategories->exists(list[i])){ | ||
456 | ids[index] = m_pCategories->id(list[i]); | ||
457 | index++; | ||
458 | } | ||
459 | } | ||
460 | #else | ||
461 | if(m_pCategories->exists(list[i])){ | ||
462 | ids[index] = m_pCategories->id(list[i]); | ||
463 | index++; | ||
464 | } else if(m_addCategory){ | ||
465 | ids[index] = m_pCategories->addCategory(list[i]); | ||
466 | index++; | ||
467 | } | ||
468 | #endif | ||
469 | } | ||
470 | if(ids.size() > 0 && index == 0){ | ||
471 | return true; | ||
472 | } else if(index != ids.size()){ | ||
473 | ids.resize(index); | ||
474 | } | ||
475 | if(!m_pZdb->updateCategories(id, ids)){ | ||
476 | return false; | ||
477 | } | ||
478 | return true; | ||
479 | #endif | ||
480 | |||
481 | QDate SharpDTMConverter::convertDate( QString s) | 439 | QDate SharpDTMConverter::convertDate( QString s) |
482 | { | 440 | { |
483 | QDate dt = KGlobal::locale()->readDate( s ); | 441 | QDate dt = KGlobal::locale()->readDate( s ); |
484 | return dt; | 442 | return dt; |
485 | return QDate (); | 443 | return QDate (); |
486 | } | 444 | } |