author | zautrix <zautrix> | 2004-09-21 10:08:57 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-09-21 10:08:57 (UTC) |
commit | 19f445f0b6e7d4591db46b89e877ed9f4332ecd4 (patch) (unidiff) | |
tree | fd21a5dc32332060197d792552ef1eb469e92175 /kabc | |
parent | 1cf4cc6e7bf25ee309852c7c97155de86917289f (diff) | |
download | kdepimpi-19f445f0b6e7d4591db46b89e877ed9f4332ecd4.zip kdepimpi-19f445f0b6e7d4591db46b89e877ed9f4332ecd4.tar.gz kdepimpi-19f445f0b6e7d4591db46b89e877ed9f4332ecd4.tar.bz2 |
more sync fixes
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 3 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 48 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/sharpdtmconverter.cpp | 17 |
3 files changed, 61 insertions, 7 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index b8c32d5..6cd63fd 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -1,408 +1,409 @@ | |||
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 | #include <sys/types.h> | 28 | #include <sys/types.h> |
29 | #include <sys/stat.h> | 29 | #include <sys/stat.h> |
30 | #ifndef _WIN32_ | 30 | #ifndef _WIN32_ |
31 | #include <unistd.h> | 31 | #include <unistd.h> |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | #include <qfile.h> | 34 | #include <qfile.h> |
35 | #include <qfileinfo.h> | 35 | #include <qfileinfo.h> |
36 | #include <qregexp.h> | 36 | #include <qregexp.h> |
37 | #include <qtimer.h> | 37 | #include <qtimer.h> |
38 | 38 | ||
39 | #include <kapplication.h> | 39 | #include <kapplication.h> |
40 | #include <kconfig.h> | 40 | #include <kconfig.h> |
41 | #include <kdebug.h> | 41 | #include <kdebug.h> |
42 | #include <klocale.h> | 42 | #include <klocale.h> |
43 | //US #include <ksavefile.h> | 43 | //US #include <ksavefile.h> |
44 | #include <kstandarddirs.h> | 44 | #include <kstandarddirs.h> |
45 | #include <kmessagebox.h> | 45 | #include <kmessagebox.h> |
46 | 46 | ||
47 | #include "formatfactory.h" | 47 | #include "formatfactory.h" |
48 | 48 | ||
49 | #include "resource.h" | 49 | #include "resource.h" |
50 | #include "resourcefileconfig.h" | 50 | #include "resourcefileconfig.h" |
51 | #include "stdaddressbook.h" | 51 | #include "stdaddressbook.h" |
52 | #define NO_DIRWATCH | 52 | #define NO_DIRWATCH |
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncprefwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | //#define ALLOW_LOCKING | 56 | //#define ALLOW_LOCKING |
57 | 57 | ||
58 | 58 | ||
59 | 59 | ||
60 | using namespace KABC; | 60 | using namespace KABC; |
61 | 61 | ||
62 | extern "C" | 62 | extern "C" |
63 | #ifdef _WIN32_ | 63 | #ifdef _WIN32_ |
64 | __declspec(dllexport) | 64 | __declspec(dllexport) |
65 | #else | 65 | #else |
66 | { | 66 | { |
67 | #endif | 67 | #endif |
68 | 68 | ||
69 | //US void *init_kabc_file() | 69 | //US void *init_kabc_file() |
70 | void *init_microkabc_file() | 70 | void *init_microkabc_file() |
71 | { | 71 | { |
72 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); | 72 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); |
73 | } | 73 | } |
74 | #ifndef _WIN32_ | 74 | #ifndef _WIN32_ |
75 | } | 75 | } |
76 | #endif | 76 | #endif |
77 | 77 | ||
78 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) | 78 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) |
79 | : Resource( config, syncable ) , mFormat( 0 ) | 79 | : Resource( config, syncable ) , mFormat( 0 ) |
80 | { | 80 | { |
81 | QString fileName, formatName, default_fileName; | 81 | QString fileName, formatName, default_fileName; |
82 | 82 | ||
83 | if (syncable == true) | 83 | if (syncable == true) |
84 | default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; | 84 | default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; |
85 | else | 85 | else |
86 | default_fileName = StdAddressBook::fileName(); | 86 | default_fileName = StdAddressBook::fileName(); |
87 | 87 | ||
88 | KConfig *cfg = (KConfig *)config; | 88 | KConfig *cfg = (KConfig *)config; |
89 | if ( cfg ) { | 89 | if ( cfg ) { |
90 | fileName = cfg->readEntry( "FileName", default_fileName ); | 90 | fileName = cfg->readEntry( "FileName", default_fileName ); |
91 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 91 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
92 | } else { | 92 | } else { |
93 | fileName = default_fileName; | 93 | fileName = default_fileName; |
94 | formatName = "vcard"; | 94 | formatName = "vcard"; |
95 | } | 95 | } |
96 | 96 | ||
97 | init( fileName, formatName ); | 97 | init( fileName, formatName ); |
98 | } | 98 | } |
99 | 99 | ||
100 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , | 100 | ResourceFile::ResourceFile( const QString &fileName, bool syncable , |
101 | const QString &formatName ) | 101 | const QString &formatName ) |
102 | : Resource( 0, syncable ) | 102 | : Resource( 0, syncable ) |
103 | { | 103 | { |
104 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 104 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
105 | init( fileName, formatName ); | 105 | init( fileName, formatName ); |
106 | } | 106 | } |
107 | 107 | ||
108 | void ResourceFile::init( const QString &fileName, const QString &formatName ) | 108 | void ResourceFile::init( const QString &fileName, const QString &formatName ) |
109 | { | 109 | { |
110 | mFormatName = formatName; | 110 | mFormatName = formatName; |
111 | 111 | ||
112 | FormatFactory *factory = FormatFactory::self(); | 112 | FormatFactory *factory = FormatFactory::self(); |
113 | mFormat = factory->format( mFormatName ); | 113 | mFormat = factory->format( mFormatName ); |
114 | 114 | ||
115 | if ( !mFormat ) { | 115 | if ( !mFormat ) { |
116 | mFormatName = "vcard"; | 116 | mFormatName = "vcard"; |
117 | mFormat = factory->format( mFormatName ); | 117 | mFormat = factory->format( mFormatName ); |
118 | } | 118 | } |
119 | 119 | ||
120 | #ifndef NO_DIRWATCH | 120 | #ifndef NO_DIRWATCH |
121 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 121 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
122 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 122 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
123 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 123 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
124 | #endif | 124 | #endif |
125 | setFileName( fileName ); | 125 | setFileName( fileName ); |
126 | } | 126 | } |
127 | 127 | ||
128 | ResourceFile::~ResourceFile() | 128 | ResourceFile::~ResourceFile() |
129 | { | 129 | { |
130 | delete mFormat; | 130 | delete mFormat; |
131 | mFormat = 0; | 131 | mFormat = 0; |
132 | } | 132 | } |
133 | 133 | ||
134 | void ResourceFile::writeConfig( KConfig *config ) | 134 | void ResourceFile::writeConfig( KConfig *config ) |
135 | { | 135 | { |
136 | 136 | ||
137 | config->setGroup( "Resource_" + identifier() ); | 137 | config->setGroup( "Resource_" + identifier() ); |
138 | Resource::writeConfig( config ); | 138 | Resource::writeConfig( config ); |
139 | 139 | ||
140 | config->writeEntry( "FileName", mFileName ); | 140 | config->writeEntry( "FileName", mFileName ); |
141 | config->writeEntry( "FileFormat", mFormatName ); | 141 | config->writeEntry( "FileFormat", mFormatName ); |
142 | 142 | ||
143 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 143 | // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
144 | 144 | ||
145 | } | 145 | } |
146 | 146 | ||
147 | Ticket *ResourceFile::requestSaveTicket() | 147 | Ticket *ResourceFile::requestSaveTicket() |
148 | { | 148 | { |
149 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; | 149 | kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; |
150 | 150 | ||
151 | if ( !addressBook() ) return 0; | 151 | if ( !addressBook() ) return 0; |
152 | 152 | ||
153 | #ifdef ALLOW_LOCKING | 153 | #ifdef ALLOW_LOCKING |
154 | if ( !lock( mFileName ) ) { | 154 | if ( !lock( mFileName ) ) { |
155 | qDebug("unablt to lock file "); | 155 | qDebug("unablt to lock file "); |
156 | return 0; | 156 | return 0; |
157 | } | 157 | } |
158 | #endif | 158 | #endif |
159 | return createTicket( this ); | 159 | return createTicket( this ); |
160 | } | 160 | } |
161 | 161 | ||
162 | 162 | ||
163 | bool ResourceFile::doOpen() | 163 | bool ResourceFile::doOpen() |
164 | { | 164 | { |
165 | QFile file( mFileName ); | 165 | QFile file( mFileName ); |
166 | qDebug("ResourceFile::openfile %s ", mFileName.latin1()); | ||
166 | 167 | ||
167 | if ( !file.exists() ) { | 168 | if ( !file.exists() ) { |
168 | // try to create the file | 169 | // try to create the file |
169 | bool ok = file.open( IO_WriteOnly ); | 170 | bool ok = file.open( IO_WriteOnly ); |
170 | if ( ok ) | 171 | if ( ok ) |
171 | file.close(); | 172 | file.close(); |
172 | 173 | ||
173 | return ok; | 174 | return ok; |
174 | } else { | 175 | } else { |
175 | if ( !file.open( IO_ReadWrite ) ) | 176 | if ( !file.open( IO_ReadWrite ) ) |
176 | return false; | 177 | return false; |
177 | 178 | ||
178 | if ( file.size() == 0 ) { | 179 | if ( file.size() == 0 ) { |
179 | file.close(); | 180 | file.close(); |
180 | return true; | 181 | return true; |
181 | } | 182 | } |
182 | 183 | ||
183 | bool ok = mFormat->checkFormat( &file ); | 184 | bool ok = mFormat->checkFormat( &file ); |
184 | file.close(); | 185 | file.close(); |
185 | 186 | ||
186 | return ok; | 187 | return ok; |
187 | } | 188 | } |
188 | } | 189 | } |
189 | 190 | ||
190 | void ResourceFile::doClose() | 191 | void ResourceFile::doClose() |
191 | { | 192 | { |
192 | } | 193 | } |
193 | 194 | ||
194 | bool ResourceFile::load() | 195 | bool ResourceFile::load() |
195 | { | 196 | { |
196 | 197 | ||
197 | 198 | qDebug("ResourceFile::loadfile %s ", mFileName.latin1()); | |
198 | QFile file( mFileName ); | 199 | QFile file( mFileName ); |
199 | if ( !file.open( IO_ReadOnly ) ) { | 200 | if ( !file.open( IO_ReadOnly ) ) { |
200 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); | 201 | addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); |
201 | return false; | 202 | return false; |
202 | } | 203 | } |
203 | 204 | ||
204 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 205 | // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
205 | 206 | ||
206 | return mFormat->loadAll( addressBook(), this, &file ); | 207 | return mFormat->loadAll( addressBook(), this, &file ); |
207 | } | 208 | } |
208 | 209 | ||
209 | bool ResourceFile::save( Ticket *ticket ) | 210 | bool ResourceFile::save( Ticket *ticket ) |
210 | { | 211 | { |
211 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | 212 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); |
212 | 213 | ||
213 | 214 | ||
214 | // create backup file | 215 | // create backup file |
215 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | 216 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); |
216 | 217 | ||
217 | /*US we use a simpler method to create a backupfile | 218 | /*US we use a simpler method to create a backupfile |
218 | 219 | ||
219 | (void) KSaveFile::backupFile( mFileName, QString::null | 220 | (void) KSaveFile::backupFile( mFileName, QString::null |
220 | ,extension ); | 221 | ,extension ); |
221 | 222 | ||
222 | KSaveFile saveFile( mFileName ); | 223 | KSaveFile saveFile( mFileName ); |
223 | bool ok = false; | 224 | bool ok = false; |
224 | if ( saveFile.status() == 0 && saveFile.file() ) | 225 | if ( saveFile.status() == 0 && saveFile.file() ) |
225 | { | 226 | { |
226 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 227 | mFormat->saveAll( addressBook(), this, saveFile.file() ); |
227 | ok = saveFile.close(); | 228 | ok = saveFile.close(); |
228 | } | 229 | } |
229 | */ | 230 | */ |
230 | 231 | ||
231 | //US ToDo: write backupfile | 232 | //US ToDo: write backupfile |
232 | #ifndef NO_DIRWATCH | 233 | #ifndef NO_DIRWATCH |
233 | mDirWatch.stopScan(); | 234 | mDirWatch.stopScan(); |
234 | #endif | 235 | #endif |
235 | QFile info; | 236 | QFile info; |
236 | info.setName( mFileName ); | 237 | info.setName( mFileName ); |
237 | bool ok = info.open( IO_WriteOnly ); | 238 | bool ok = info.open( IO_WriteOnly ); |
238 | if ( ok ) { | 239 | if ( ok ) { |
239 | mFormat->saveAll( addressBook(), this, &info ); | 240 | mFormat->saveAll( addressBook(), this, &info ); |
240 | 241 | ||
241 | info.close(); | 242 | info.close(); |
242 | ok = true; | 243 | ok = true; |
243 | } | 244 | } |
244 | else { | 245 | else { |
245 | 246 | ||
246 | } | 247 | } |
247 | 248 | ||
248 | if ( !ok ) | 249 | if ( !ok ) |
249 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | 250 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); |
250 | #ifndef NO_DIRWATCH | 251 | #ifndef NO_DIRWATCH |
251 | mDirWatch.startScan(); | 252 | mDirWatch.startScan(); |
252 | #endif | 253 | #endif |
253 | delete ticket; | 254 | delete ticket; |
254 | #ifdef ALLOW_LOCKING | 255 | #ifdef ALLOW_LOCKING |
255 | unlock( mFileName ); | 256 | unlock( mFileName ); |
256 | #endif | 257 | #endif |
257 | 258 | ||
258 | return ok; | 259 | return ok; |
259 | } | 260 | } |
260 | 261 | ||
261 | bool ResourceFile::lock( const QString &fileName ) | 262 | bool ResourceFile::lock( const QString &fileName ) |
262 | { | 263 | { |
263 | #ifdef ALLOW_LOCKING | 264 | #ifdef ALLOW_LOCKING |
264 | 265 | ||
265 | 266 | ||
266 | QString fn = fileName; | 267 | QString fn = fileName; |
267 | 268 | ||
268 | //US change the implementation how the lockfilename is getting created | 269 | //US change the implementation how the lockfilename is getting created |
269 | //US fn.replace( QRegExp("/"), "_" ); | 270 | //US fn.replace( QRegExp("/"), "_" ); |
270 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 271 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
271 | 272 | ||
272 | KURL url(fn); | 273 | KURL url(fn); |
273 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 274 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
274 | 275 | ||
275 | 276 | ||
276 | 277 | ||
277 | if (QFile::exists( lockName )) return false; | 278 | if (QFile::exists( lockName )) return false; |
278 | 279 | ||
279 | QString lockUniqueName; | 280 | QString lockUniqueName; |
280 | lockUniqueName = fn + KApplication::randomString( 8 ); | 281 | lockUniqueName = fn + KApplication::randomString( 8 ); |
281 | 282 | ||
282 | url = lockUniqueName; | 283 | url = lockUniqueName; |
283 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 284 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
284 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 285 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
285 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 286 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
286 | 287 | ||
287 | // Create unique file | 288 | // Create unique file |
288 | QFile file( mLockUniqueName ); | 289 | QFile file( mLockUniqueName ); |
289 | file.open( IO_WriteOnly ); | 290 | file.open( IO_WriteOnly ); |
290 | file.close(); | 291 | file.close(); |
291 | 292 | ||
292 | // Create lock file | 293 | // Create lock file |
293 | int result = 0; | 294 | int result = 0; |
294 | #ifndef _WIN32_ | 295 | #ifndef _WIN32_ |
295 | result = ::link( QFile::encodeName( mLockUniqueName ), | 296 | result = ::link( QFile::encodeName( mLockUniqueName ), |
296 | QFile::encodeName( lockName ) ); | 297 | QFile::encodeName( lockName ) ); |
297 | #endif | 298 | #endif |
298 | if ( result == 0 ) { | 299 | if ( result == 0 ) { |
299 | addressBook()->emitAddressBookLocked(); | 300 | addressBook()->emitAddressBookLocked(); |
300 | return true; | 301 | return true; |
301 | } | 302 | } |
302 | 303 | ||
303 | // TODO: check stat | 304 | // TODO: check stat |
304 | 305 | ||
305 | return false; | 306 | return false; |
306 | #else | 307 | #else |
307 | return true; | 308 | return true; |
308 | #endif | 309 | #endif |
309 | } | 310 | } |
310 | 311 | ||
311 | void ResourceFile::unlock( const QString &fileName ) | 312 | void ResourceFile::unlock( const QString &fileName ) |
312 | { | 313 | { |
313 | #ifdef ALLOW_LOCKING | 314 | #ifdef ALLOW_LOCKING |
314 | QString fn = fileName; | 315 | QString fn = fileName; |
315 | //US change the implementation how the lockfilename is getting created | 316 | //US change the implementation how the lockfilename is getting created |
316 | //US fn.replace( QRegExp( "/" ), "_" ); | 317 | //US fn.replace( QRegExp( "/" ), "_" ); |
317 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | 318 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); |
318 | //US QString lockName = fn + ".lock"; | 319 | //US QString lockName = fn + ".lock"; |
319 | KURL url(fn); | 320 | KURL url(fn); |
320 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 321 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
321 | 322 | ||
322 | QFile::remove( lockName ); | 323 | QFile::remove( lockName ); |
323 | QFile::remove( mLockUniqueName ); | 324 | QFile::remove( mLockUniqueName ); |
324 | addressBook()->emitAddressBookUnlocked(); | 325 | addressBook()->emitAddressBookUnlocked(); |
325 | #else | 326 | #else |
326 | return; | 327 | return; |
327 | #endif | 328 | #endif |
328 | } | 329 | } |
329 | 330 | ||
330 | void ResourceFile::setFileName( const QString &fileName ) | 331 | void ResourceFile::setFileName( const QString &fileName ) |
331 | { | 332 | { |
332 | #ifndef NO_DIRWATCH | 333 | #ifndef NO_DIRWATCH |
333 | mDirWatch.stopScan(); | 334 | mDirWatch.stopScan(); |
334 | mDirWatch.removeFile( mFileName ); | 335 | mDirWatch.removeFile( mFileName ); |
335 | mFileName = fileName; | 336 | mFileName = fileName; |
336 | 337 | ||
337 | 338 | ||
338 | mDirWatch.addFile( mFileName ); | 339 | mDirWatch.addFile( mFileName ); |
339 | mDirWatch.startScan(); | 340 | mDirWatch.startScan(); |
340 | #else | 341 | #else |
341 | mFileName = fileName; | 342 | mFileName = fileName; |
342 | #endif | 343 | #endif |
343 | 344 | ||
344 | //US simulate KDirWatch event | 345 | //US simulate KDirWatch event |
345 | //US fileChanged(); | 346 | //US fileChanged(); |
346 | } | 347 | } |
347 | 348 | ||
348 | QString ResourceFile::fileName() const | 349 | QString ResourceFile::fileName() const |
349 | { | 350 | { |
350 | return mFileName; | 351 | return mFileName; |
351 | } | 352 | } |
352 | 353 | ||
353 | void ResourceFile::setFormat( const QString &format ) | 354 | void ResourceFile::setFormat( const QString &format ) |
354 | { | 355 | { |
355 | mFormatName = format; | 356 | mFormatName = format; |
356 | delete mFormat; | 357 | delete mFormat; |
357 | 358 | ||
358 | FormatFactory *factory = FormatFactory::self(); | 359 | FormatFactory *factory = FormatFactory::self(); |
359 | mFormat = factory->format( mFormatName ); | 360 | mFormat = factory->format( mFormatName ); |
360 | /*US | 361 | /*US |
361 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); | 362 | //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); |
362 | if (mFormatName == "vcard") { | 363 | if (mFormatName == "vcard") { |
363 | mFormat = new VCardFormatPlugin2(); | 364 | mFormat = new VCardFormatPlugin2(); |
364 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 365 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
365 | } | 366 | } |
366 | else if (mFormatName == "binary") { | 367 | else if (mFormatName == "binary") { |
367 | mFormat = new BinaryFormat(); | 368 | mFormat = new BinaryFormat(); |
368 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); | 369 | // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); |
369 | } | 370 | } |
370 | else | 371 | else |
371 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); | 372 | qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); |
372 | */ | 373 | */ |
373 | 374 | ||
374 | } | 375 | } |
375 | 376 | ||
376 | QString ResourceFile::format() const | 377 | QString ResourceFile::format() const |
377 | { | 378 | { |
378 | return mFormatName; | 379 | return mFormatName; |
379 | } | 380 | } |
380 | 381 | ||
381 | void ResourceFile::fileChanged() | 382 | void ResourceFile::fileChanged() |
382 | { | 383 | { |
383 | // There is a small theoretical chance that KDirWatch calls us before | 384 | // There is a small theoretical chance that KDirWatch calls us before |
384 | // we are fully constructed | 385 | // we are fully constructed |
385 | if (!addressBook()) | 386 | if (!addressBook()) |
386 | return; | 387 | return; |
387 | 388 | ||
388 | 389 | ||
389 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 390 | QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); |
390 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 391 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
391 | load(); | 392 | load(); |
392 | addressBook()->emitAddressBookChanged(); | 393 | addressBook()->emitAddressBookChanged(); |
393 | } | 394 | } |
394 | } | 395 | } |
395 | 396 | ||
396 | void ResourceFile::removeAddressee( const Addressee &addr ) | 397 | void ResourceFile::removeAddressee( const Addressee &addr ) |
397 | { | 398 | { |
398 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); | 399 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); |
399 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); | 400 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); |
400 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); | 401 | QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); |
401 | } | 402 | } |
402 | 403 | ||
403 | void ResourceFile::cleanUp() | 404 | void ResourceFile::cleanUp() |
404 | { | 405 | { |
405 | unlock( mFileName ); | 406 | unlock( mFileName ); |
406 | } | 407 | } |
407 | 408 | ||
408 | //US #include "resourcefile.moc" | 409 | //US #include "resourcefile.moc" |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 48d3985..437bda8 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -1,400 +1,442 @@ | |||
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 "syncprefwidget.h" | 53 | #include "syncprefwidget.h" |
54 | 54 | ||
55 | #include "stdaddressbook.h" | 55 | #include "stdaddressbook.h" |
56 | 56 | ||
57 | #include "sharpdtmconverter.h" | 57 | #include "sharpdtmconverter.h" |
58 | //#define ALLOW_LOCKING | 58 | //#define ALLOW_LOCKING |
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | void *init_microkabc_sharpdtm() | 62 | void *init_microkabc_sharpdtm() |
63 | { | 63 | { |
64 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); | 64 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | 68 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) |
69 | : Resource( config, syncable ), mConverter (0) | 69 | : Resource( config, syncable ), mConverter (0) |
70 | { | 70 | { |
71 | // we can not choose the filename. Therefore use the default to display | 71 | // we can not choose the filename. Therefore use the default to display |
72 | 72 | ||
73 | QString fileName = SlZDataBase::addressbookFileName(); | 73 | QString fileName = SlZDataBase::addressbookFileName(); |
74 | init( fileName ); | 74 | init( fileName ); |
75 | } | 75 | } |
76 | 76 | ||
77 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | 77 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) |
78 | : Resource( 0, syncable ) | 78 | : Resource( 0, syncable ) |
79 | { | 79 | { |
80 | init( fileName ); | 80 | init( fileName ); |
81 | } | 81 | } |
82 | 82 | ||
83 | void ResourceSharpDTM::init( const QString &fileName ) | 83 | void ResourceSharpDTM::init( const QString &fileName ) |
84 | { | 84 | { |
85 | 85 | ||
86 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
87 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 87 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
88 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 88 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
89 | 89 | ||
90 | setFileName( fileName ); | 90 | setFileName( fileName ); |
91 | } | 91 | } |
92 | 92 | ||
93 | ResourceSharpDTM::~ResourceSharpDTM() | 93 | ResourceSharpDTM::~ResourceSharpDTM() |
94 | { | 94 | { |
95 | if (mConverter != 0) | 95 | if (mConverter != 0) |
96 | delete mConverter; | 96 | delete mConverter; |
97 | 97 | ||
98 | if(mAccess != 0) | 98 | if(mAccess != 0) |
99 | delete mAccess; | 99 | delete mAccess; |
100 | } | 100 | } |
101 | 101 | ||
102 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 102 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
103 | { | 103 | { |
104 | Resource::writeConfig( config ); | 104 | Resource::writeConfig( config ); |
105 | } | 105 | } |
106 | 106 | ||
107 | Ticket *ResourceSharpDTM::requestSaveTicket() | 107 | Ticket *ResourceSharpDTM::requestSaveTicket() |
108 | { | 108 | { |
109 | 109 | ||
110 | 110 | ||
111 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | 111 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); |
112 | 112 | ||
113 | if ( !addressBook() ) return 0; | 113 | if ( !addressBook() ) return 0; |
114 | 114 | ||
115 | #ifdef ALLOW_LOCKING | 115 | #ifdef ALLOW_LOCKING |
116 | if ( !lock( fileName() ) ) { | 116 | if ( !lock( fileName() ) ) { |
117 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); | 117 | qDebug("ResourceSharpDTM::requestSaveTicket(): Unable to lock file "); |
118 | return 0; | 118 | return 0; |
119 | } | 119 | } |
120 | #endif | 120 | #endif |
121 | return createTicket( this ); | 121 | return createTicket( this ); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | bool ResourceSharpDTM::doOpen() | 125 | bool ResourceSharpDTM::doOpen() |
126 | { | 126 | { |
127 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); | 127 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); |
128 | 128 | ||
129 | // the last parameter in the SlZDataBase constructor means "readonly" | 129 | // the last parameter in the SlZDataBase constructor means "readonly" |
130 | mAccess = new SlZDataBase(fileName(), | 130 | mAccess = new SlZDataBase(fileName(), |
131 | SlZDataBase::addressbookItems(), | 131 | SlZDataBase::addressbookItems(), |
132 | NULL, false); | 132 | NULL, false); |
133 | 133 | ||
134 | if ( !mAccess ) { | 134 | if ( !mAccess ) { |
135 | qDebug("Unable to load file() %s", fileName().latin1()); | 135 | qDebug("Unable to load file() %s", fileName().latin1()); |
136 | return false; | 136 | return false; |
137 | } | 137 | } |
138 | 138 | ||
139 | if (mConverter == 0) | 139 | if (mConverter == 0) |
140 | { | 140 | { |
141 | mConverter = new SharpDTMConverter(); | 141 | mConverter = new SharpDTMConverter(); |
142 | bool res = mConverter->init(); | 142 | bool res = mConverter->init(); |
143 | if ( !res ) | 143 | if ( !res ) |
144 | { | 144 | { |
145 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 145 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
146 | 146 | ||
147 | qDebug(msg); | 147 | qDebug(msg); |
148 | delete mAccess; | 148 | delete mAccess; |
149 | mAccess = 0; | 149 | mAccess = 0; |
150 | return false; | 150 | return false; |
151 | } | 151 | } |
152 | } | 152 | } |
153 | 153 | ||
154 | return true; | 154 | return true; |
155 | } | 155 | } |
156 | 156 | ||
157 | void ResourceSharpDTM::doClose() | 157 | void ResourceSharpDTM::doClose() |
158 | { | 158 | { |
159 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); | 159 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); |
160 | 160 | ||
161 | if(mAccess) | 161 | if(mAccess) |
162 | { | 162 | { |
163 | delete mAccess; | 163 | delete mAccess; |
164 | mAccess = 0; | 164 | mAccess = 0; |
165 | } | 165 | } |
166 | // it seems so, that deletion of access deletes backend as well | 166 | // it seems so, that deletion of access deletes backend as well |
167 | //delete backend; | 167 | //delete backend; |
168 | 168 | ||
169 | return; | 169 | return; |
170 | } | 170 | } |
171 | 171 | ||
172 | bool ResourceSharpDTM::load() | 172 | bool ResourceSharpDTM::load() |
173 | { | 173 | { |
174 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); | 174 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); |
175 | 175 | ||
176 | bool res = false; | 176 | bool res = false; |
177 | 177 | ||
178 | CardId id; | 178 | CardId id; |
179 | 179 | ||
180 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) | 180 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
181 | { | 181 | { |
182 | id = mAccess->cardId(); | 182 | id = mAccess->cardId(); |
183 | 183 | ||
184 | KABC::Addressee addressee; | 184 | KABC::Addressee addressee; |
185 | 185 | ||
186 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 186 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
187 | 187 | ||
188 | if ( !addressee.isEmpty() && res ) | 188 | if ( !addressee.isEmpty() && res ) |
189 | { | 189 | { |
190 | addressee.setResource( this ); | 190 | addressee.setResource( this ); |
191 | addressBook()->insertAddressee( addressee ); | 191 | addressBook()->insertAddressee( addressee ); |
192 | } | 192 | } |
193 | } | 193 | } |
194 | 194 | ||
195 | return true; | 195 | return true; |
196 | } | 196 | } |
197 | 197 | ||
198 | bool ResourceSharpDTM::save( Ticket *ticket ) | 198 | bool ResourceSharpDTM::save( Ticket *ticket ) |
199 | { | 199 | { |
200 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); | 200 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
201 | 201 | ||
202 | mDirWatch.stopScan(); | 202 | mDirWatch.stopScan(); |
203 | 203 | ||
204 | KABC::AddressBook::Iterator it; | 204 | KABC::AddressBook::Iterator it; |
205 | bool res; | 205 | bool res; |
206 | KABC::Addressee::List changedAddressees; | 206 | KABC::Addressee::List changedAddressees; |
207 | typedef QMap<int,QString> AddresseeMap; | ||
208 | AddresseeMap map; | ||
209 | CardId id ; | ||
207 | 210 | ||
208 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { | 211 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
209 | 212 | ||
210 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 213 | if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
211 | QString uid = (*it).originalExternalUID(); | 214 | QString uid = (*it).originalExternalUID(); |
212 | CardId id ; | ||
213 | bool res; | 215 | bool res; |
214 | if ( uid.isEmpty() ) | 216 | if ( uid.isEmpty() ) |
215 | id = 0; | 217 | id = 0; |
216 | else | 218 | else |
217 | id = uid.toUInt(); | 219 | id = uid.toUInt(); |
218 | KABC::Addressee addressee = (*it); | 220 | KABC::Addressee addressee = (*it); |
219 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { | 221 | if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_ADDED_EXTERNAL ) { |
220 | res = mAccess->startEditCard(id); | 222 | res = mAccess->startEditCard(id); |
221 | if (res == true) | 223 | if (res == true) |
222 | { | 224 | { |
223 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 225 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
224 | if (res == true) | 226 | if (res == true) |
225 | { | 227 | { |
228 | res = mAccess->finishEditCard(&id); | ||
229 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
230 | //(*it).setExternalUID( QString::number( id ) ); | ||
231 | //(*it).setOriginalExternalUID( QString::number( id ) ); | ||
232 | map.insert(id,(*it).uid()); | ||
233 | |||
234 | #if 0 | ||
226 | KABC::Addressee addressee; | 235 | KABC::Addressee addressee; |
227 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 236 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
228 | addressee.setUid((*it).uid() ); | 237 | addressee.setUid((*it).uid() ); |
229 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | 238 | (it*).setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); |
230 | res = mAccess->finishEditCard(&id); | 239 | res = mAccess->finishEditCard(&id); |
231 | //qDebug("2NEW id is %d", id); | 240 | //qDebug("2NEW id is %d", id); |
232 | addressee.setExternalUID( QString::number( id ) ); | 241 | addressee.setExternalUID( QString::number( id ) ); |
233 | addressee.setOriginalExternalUID( QString::number( id ) ); | 242 | addressee.setOriginalExternalUID( QString::number( id ) ); |
234 | changedAddressees.append( addressee ); | 243 | changedAddressees.append( addressee ); |
244 | #endif | ||
235 | 245 | ||
236 | if (res == false) | 246 | if (res == false) |
237 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 247 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
238 | 248 | ||
239 | } | 249 | } |
240 | else | 250 | else |
241 | { | 251 | { |
242 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 252 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
243 | mAccess->cancelEditCard(); | 253 | mAccess->cancelEditCard(); |
244 | } | 254 | } |
245 | } | 255 | } |
246 | 256 | ||
247 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { | 257 | } else if ( (*it).tempSyncStat() == SYNC_TEMPSTATE_DELETE ) { |
248 | res = mAccess->deleteCard(&id); | 258 | res = mAccess->deleteCard(&id); |
249 | if ( res ) | 259 | if ( res ) |
250 | qDebug("delete success "); | 260 | qDebug("delete success "); |
251 | else | 261 | else |
252 | qDebug("delete error "); | 262 | qDebug("delete error "); |
253 | 263 | ||
254 | 264 | ||
255 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { | 265 | } else if ( (*it).tempSyncStat() != SYNC_TEMPSTATE_NEW_EXTERNAL ) { |
256 | //changed | 266 | //changed |
257 | qDebug("changed ****"); | 267 | qDebug("changed ****"); |
258 | res = mAccess->startEditCard(id); | 268 | res = mAccess->startEditCard(id); |
259 | if (res == true) | 269 | if (res == true) |
260 | { | 270 | { |
261 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); | 271 | res = mConverter->addresseeToSharp( (*it), mAccess, id ); |
262 | if (res == true) | 272 | if (res == true) |
263 | { | 273 | { |
274 | res = mAccess->finishEditCard(&id); | ||
275 | //(*it).setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | ||
276 | map.insert(id,(*it).uid()); | ||
277 | |||
278 | #if 0 | ||
264 | KABC::Addressee addressee; | 279 | KABC::Addressee addressee; |
265 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | 280 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
266 | addressee.setUid((*it).uid() ); | 281 | addressee.setUid((*it).uid() ); |
267 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); | 282 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_CSUM ); |
268 | changedAddressees.append( addressee ); | 283 | changedAddressees.append( addressee ); |
269 | res = mAccess->finishEditCard(&id); | 284 | res = mAccess->finishEditCard(&id); |
285 | #endif | ||
270 | if (res == false) | 286 | if (res == false) |
271 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | 287 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); |
272 | 288 | ||
273 | } | 289 | } |
274 | else | 290 | else |
275 | { | 291 | { |
276 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); | 292 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
277 | mAccess->cancelEditCard(); | 293 | mAccess->cancelEditCard(); |
278 | } | 294 | } |
279 | } | 295 | } |
280 | } | 296 | } |
281 | } | 297 | } |
282 | 298 | ||
283 | } | 299 | } |
300 | AddresseeMap::Iterator itam; | ||
301 | res; | ||
302 | for ( res=mAccess->first(); res == true; res=mAccess->next()) | ||
303 | { | ||
304 | id = mAccess->cardId(); | ||
305 | int idint = id; | ||
306 | itam = map.find( idint ); | ||
307 | if ( itam != map.end() ) { | ||
308 | KABC::Addressee addressee; | ||
309 | qDebug("found change %d %s ", idint, itam.data().latin1()); | ||
310 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | ||
311 | |||
312 | if ( !addressee.isEmpty() && res ) | ||
313 | { | ||
314 | addressee.setResource( this ); | ||
315 | addressee.setUid( itam.data() ); | ||
316 | addressee.setTempSyncStat( SYNC_TEMPSTATE_NEW_ID ); | ||
317 | addressBook()->insertAddressee( addressee , false ); | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | #if 0 | ||
284 | KABC::Addressee::List::Iterator it2; | 322 | KABC::Addressee::List::Iterator it2; |
285 | for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) | 323 | for ( it2 = changedAddressees.begin(); it2 != changedAddressees.end(); ++it2 ) { |
324 | (*it2).computeCsum( "Sharp_DTM" ); | ||
325 | qDebug("CSUM: %s ",(*it2).getCsum( "Sharp_DTM" ).latin1() ); | ||
286 | addressBook()->insertAddressee((*it2)); | 326 | addressBook()->insertAddressee((*it2)); |
327 | } | ||
328 | #endif | ||
287 | //US mAccess->save(); | 329 | //US mAccess->save(); |
288 | 330 | ||
289 | mDirWatch.startScan(); | 331 | mDirWatch.startScan(); |
290 | delete ticket; | 332 | delete ticket; |
291 | unlock( fileName() ); | 333 | unlock( fileName() ); |
292 | 334 | ||
293 | return true; | 335 | return true; |
294 | } | 336 | } |
295 | 337 | ||
296 | bool ResourceSharpDTM::lock( const QString &lockfileName ) | 338 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
297 | { | 339 | { |
298 | #ifdef ALLOW_LOCKING | 340 | #ifdef ALLOW_LOCKING |
299 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); | 341 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
300 | 342 | ||
301 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 343 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
302 | 344 | ||
303 | QString fn = lockfileName; | 345 | QString fn = lockfileName; |
304 | 346 | ||
305 | KURL url(fn); | 347 | KURL url(fn); |
306 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 348 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
307 | 349 | ||
308 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 350 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
309 | 351 | ||
310 | if (QFile::exists( lockName )) | 352 | if (QFile::exists( lockName )) |
311 | { | 353 | { |
312 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); | 354 | qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); |
313 | return false; | 355 | return false; |
314 | } | 356 | } |
315 | 357 | ||
316 | 358 | ||
317 | QString lockUniqueName; | 359 | QString lockUniqueName; |
318 | lockUniqueName = fn + KApplication::randomString( 8 ); | 360 | lockUniqueName = fn + KApplication::randomString( 8 ); |
319 | 361 | ||
320 | url = lockUniqueName; | 362 | url = lockUniqueName; |
321 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 363 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
322 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 364 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
323 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 365 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
324 | 366 | ||
325 | // Create unique file | 367 | // Create unique file |
326 | QFile file( mLockUniqueName ); | 368 | QFile file( mLockUniqueName ); |
327 | file.open( IO_WriteOnly ); | 369 | file.open( IO_WriteOnly ); |
328 | file.close(); | 370 | file.close(); |
329 | 371 | ||
330 | // Create lock file | 372 | // Create lock file |
331 | int result = 0; | 373 | int result = 0; |
332 | #ifndef _WIN32_ | 374 | #ifndef _WIN32_ |
333 | result = ::link( QFile::encodeName( mLockUniqueName ), | 375 | result = ::link( QFile::encodeName( mLockUniqueName ), |
334 | QFile::encodeName( lockName ) ); | 376 | QFile::encodeName( lockName ) ); |
335 | #endif | 377 | #endif |
336 | if ( result == 0 ) { | 378 | if ( result == 0 ) { |
337 | addressBook()->emitAddressBookLocked(); | 379 | addressBook()->emitAddressBookLocked(); |
338 | return true; | 380 | return true; |
339 | } | 381 | } |
340 | 382 | ||
341 | // TODO: check stat | 383 | // TODO: check stat |
342 | 384 | ||
343 | return false; | 385 | return false; |
344 | #else | 386 | #else |
345 | return true; | 387 | return true; |
346 | #endif | 388 | #endif |
347 | } | 389 | } |
348 | 390 | ||
349 | void ResourceSharpDTM::unlock( const QString &fileName ) | 391 | void ResourceSharpDTM::unlock( const QString &fileName ) |
350 | { | 392 | { |
351 | #ifdef ALLOW_LOCKING | 393 | #ifdef ALLOW_LOCKING |
352 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | 394 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); |
353 | 395 | ||
354 | QString fn = fileName; | 396 | QString fn = fileName; |
355 | KURL url(fn); | 397 | KURL url(fn); |
356 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 398 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
357 | 399 | ||
358 | QFile::remove( lockName ); | 400 | QFile::remove( lockName ); |
359 | QFile::remove( mLockUniqueName ); | 401 | QFile::remove( mLockUniqueName ); |
360 | addressBook()->emitAddressBookUnlocked(); | 402 | addressBook()->emitAddressBookUnlocked(); |
361 | #endif | 403 | #endif |
362 | } | 404 | } |
363 | 405 | ||
364 | void ResourceSharpDTM::setFileName( const QString &newFileName ) | 406 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
365 | { | 407 | { |
366 | mDirWatch.stopScan(); | 408 | mDirWatch.stopScan(); |
367 | mDirWatch.removeFile( fileName() ); | 409 | mDirWatch.removeFile( fileName() ); |
368 | 410 | ||
369 | Resource::setFileName( newFileName ); | 411 | Resource::setFileName( newFileName ); |
370 | 412 | ||
371 | mDirWatch.addFile( fileName() ); | 413 | mDirWatch.addFile( fileName() ); |
372 | mDirWatch.startScan(); | 414 | mDirWatch.startScan(); |
373 | 415 | ||
374 | } | 416 | } |
375 | 417 | ||
376 | void ResourceSharpDTM::fileChanged() | 418 | void ResourceSharpDTM::fileChanged() |
377 | { | 419 | { |
378 | // There is a small theoretical chance that KDirWatch calls us before | 420 | // There is a small theoretical chance that KDirWatch calls us before |
379 | // we are fully constructed | 421 | // we are fully constructed |
380 | if (!addressBook()) | 422 | if (!addressBook()) |
381 | return; | 423 | return; |
382 | 424 | ||
383 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); | 425 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
384 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 426 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
385 | load(); | 427 | load(); |
386 | addressBook()->emitAddressBookChanged(); | 428 | addressBook()->emitAddressBookChanged(); |
387 | } | 429 | } |
388 | } | 430 | } |
389 | 431 | ||
390 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 432 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
391 | { | 433 | { |
392 | } | 434 | } |
393 | 435 | ||
394 | void ResourceSharpDTM::cleanUp() | 436 | void ResourceSharpDTM::cleanUp() |
395 | { | 437 | { |
396 | unlock( fileName() ); | 438 | unlock( fileName() ); |
397 | } | 439 | } |
398 | 440 | ||
399 | 441 | ||
400 | 442 | ||
diff --git a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp index f3bf2c5..fccf625 100644 --- a/kabc/plugins/sharpdtm/sharpdtmconverter.cpp +++ b/kabc/plugins/sharpdtm/sharpdtmconverter.cpp | |||
@@ -1,431 +1,442 @@ | |||
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)); // needs fix | 83 | addr.setFormattedName(db->readField(ZdbAdrs::FileAs)); // needs fix |
84 | 84 | ||
85 | addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); | 85 | addr.setFamilyName( db->readField(ZdbAdrs::LastName) ); |
86 | addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); | 86 | addr.setGivenName( db->readField(ZdbAdrs::FirstName) ); |
87 | addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); | 87 | addr.setAdditionalName( db->readField(ZdbAdrs::MiddleName) ); |
88 | addr.setPrefix( db->readField(ZdbAdrs::Title) ); | 88 | addr.setPrefix( db->readField(ZdbAdrs::Title) ); |
89 | addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); | 89 | addr.setSuffix( db->readField(ZdbAdrs::Suffix) ); |
90 | 90 | ||
91 | 91 | ||
92 | QString emailstr = db->readField(ZdbAdrs::Emails); | 92 | QString emailstr = db->readField(ZdbAdrs::Emails); |
93 | emailstr.replace( QRegExp(","), " " ); | 93 | emailstr.replace( QRegExp(","), " " ); |
94 | emailstr.replace( QRegExp(";"), " " ); | 94 | emailstr.replace( QRegExp(";"), " " ); |
95 | emailstr.replace( QRegExp(":"), " " ); | 95 | emailstr.replace( QRegExp(":"), " " ); |
96 | //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); | 96 | //qDebug("SharpDTMConverter::sharpToAddressee whats the character to seperate the emailadresses? %s ", emailstr.latin1()); |
97 | QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace()); | 97 | QStringList emails = QStringList::split(" ", emailstr.simplifyWhiteSpace()); |
98 | bool defE = false; | 98 | bool defE = false; |
99 | bool found = false; | 99 | bool found = false; |
100 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { | 100 | for ( QStringList::Iterator it = emails.begin(); it != emails.end(); ++it ) { |
101 | if (found ) | 101 | if (found ) |
102 | defE = false; | 102 | defE = false; |
103 | else | 103 | else |
104 | found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower()); | 104 | found = defE = ((*it).lower() == db->readField(ZdbAdrs::DefaultEmail).lower()); |
105 | addr.insertEmail( *it, defE ); | 105 | addr.insertEmail( *it, defE ); |
106 | } | 106 | } |
107 | if ( ! found ) | 107 | if ( ! found ) |
108 | if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) | 108 | if (!db->readField(ZdbAdrs::DefaultEmail).isEmpty()) |
109 | addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); | 109 | addr.insertEmail(db->readField(ZdbAdrs::DefaultEmail), true); |
110 | 110 | ||
111 | // home | 111 | // home |
112 | if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || | 112 | if ((!db->readField(ZdbAdrs::HomeStreet).isEmpty()) || |
113 | (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || | 113 | (!db->readField(ZdbAdrs::HomeCity).isEmpty()) || |
114 | (!db->readField(ZdbAdrs::HomeState).isEmpty()) || | 114 | (!db->readField(ZdbAdrs::HomeState).isEmpty()) || |
115 | (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || | 115 | (!db->readField(ZdbAdrs::HomeZip).isEmpty()) || |
116 | (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) | 116 | (!db->readField(ZdbAdrs::HomeCountry).isEmpty())) |
117 | { | 117 | { |
118 | Address homeaddress; | 118 | Address homeaddress; |
119 | homeaddress.setType(Address::Home); | 119 | homeaddress.setType(Address::Home); |
120 | //US homeaddress.setPostOfficeBox( "" ); | 120 | //US homeaddress.setPostOfficeBox( "" ); |
121 | //US homeaddress.setExtended( "" ); | 121 | //US homeaddress.setExtended( "" ); |
122 | homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet) ); | 122 | homeaddress.setStreet( db->readField(ZdbAdrs::HomeStreet) ); |
123 | homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); | 123 | homeaddress.setLocality( db->readField(ZdbAdrs::HomeCity) ); |
124 | homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); | 124 | homeaddress.setRegion( db->readField(ZdbAdrs::HomeState) ); |
125 | homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); | 125 | homeaddress.setPostalCode( db->readField(ZdbAdrs::HomeZip) ); |
126 | homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); | 126 | homeaddress.setCountry( db->readField(ZdbAdrs::HomeCountry) ); |
127 | 127 | ||
128 | addr.insertAddress( homeaddress ); | 128 | addr.insertAddress( homeaddress ); |
129 | } | 129 | } |
130 | 130 | ||
131 | if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) | 131 | if (!db->readField(ZdbAdrs::HomePhone).isEmpty()) |
132 | { | 132 | { |
133 | PhoneNumber homephone; | 133 | PhoneNumber homephone; |
134 | homephone.setType( PhoneNumber::Home ); | 134 | homephone.setType( PhoneNumber::Home ); |
135 | homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); | 135 | homephone.setNumber( db->readField(ZdbAdrs::HomePhone) ); |
136 | addr.insertPhoneNumber( homephone ); | 136 | addr.insertPhoneNumber( homephone ); |
137 | } | 137 | } |
138 | 138 | ||
139 | if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) | 139 | if (!db->readField(ZdbAdrs::HomeFax).isEmpty()) |
140 | { | 140 | { |
141 | PhoneNumber homefax; | 141 | PhoneNumber homefax; |
142 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); | 142 | homefax.setType( PhoneNumber::Home | PhoneNumber::Fax ); |
143 | homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); | 143 | homefax.setNumber( db->readField(ZdbAdrs::HomeFax) ); |
144 | addr.insertPhoneNumber( homefax ); | 144 | addr.insertPhoneNumber( homefax ); |
145 | } | 145 | } |
146 | 146 | ||
147 | if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) | 147 | if (!db->readField(ZdbAdrs::HomeMobile).isEmpty()) |
148 | { | 148 | { |
149 | PhoneNumber homemobile; | 149 | PhoneNumber homemobile; |
150 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); | 150 | homemobile.setType( PhoneNumber::Home | PhoneNumber::Cell ); |
151 | homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); | 151 | homemobile.setNumber( db->readField(ZdbAdrs::HomeMobile) ); |
152 | addr.insertPhoneNumber( homemobile ); | 152 | addr.insertPhoneNumber( homemobile ); |
153 | } | 153 | } |
154 | 154 | ||
155 | addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); | 155 | addr.setUrl( db->readField(ZdbAdrs::HomeWebPage) ); |
156 | 156 | ||
157 | 157 | ||
158 | // business | 158 | // business |
159 | if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || | 159 | if ((!db->readField(ZdbAdrs::BusinessStreet).isEmpty()) || |
160 | (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || | 160 | (!db->readField(ZdbAdrs::BusinessCity).isEmpty()) || |
161 | (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || | 161 | (!db->readField(ZdbAdrs::BusinessState).isEmpty()) || |
162 | (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || | 162 | (!db->readField(ZdbAdrs::BusinessZip).isEmpty()) || |
163 | (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) | 163 | (!db->readField(ZdbAdrs::BusinessCountry).isEmpty())) |
164 | { | 164 | { |
165 | Address businessaddress; | 165 | Address businessaddress; |
166 | businessaddress.setType(Address::Work); | 166 | businessaddress.setType(Address::Work); |
167 | //US businessaddress.setPostOfficeBox( "" ); | 167 | //US businessaddress.setPostOfficeBox( "" ); |
168 | //US businessaddress.setExtended( "" ); | 168 | //US businessaddress.setExtended( "" ); |
169 | businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet) ); | 169 | businessaddress.setStreet( db->readField(ZdbAdrs::BusinessStreet) ); |
170 | businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); | 170 | businessaddress.setLocality( db->readField(ZdbAdrs::BusinessCity) ); |
171 | businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); | 171 | businessaddress.setRegion( db->readField(ZdbAdrs::BusinessState) ); |
172 | businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); | 172 | businessaddress.setPostalCode( db->readField(ZdbAdrs::BusinessZip) ); |
173 | businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); | 173 | businessaddress.setCountry( db->readField(ZdbAdrs::BusinessCountry) ); |
174 | 174 | ||
175 | addr.insertAddress( businessaddress ); | 175 | addr.insertAddress( businessaddress ); |
176 | } | 176 | } |
177 | 177 | ||
178 | 178 | ||
179 | if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) | 179 | if (!db->readField(ZdbAdrs::BusinessPhone).isEmpty()) |
180 | { | 180 | { |
181 | PhoneNumber businessphone; | 181 | PhoneNumber businessphone; |
182 | businessphone.setType( PhoneNumber::Work ); | 182 | businessphone.setType( PhoneNumber::Work ); |
183 | businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); | 183 | businessphone.setNumber( db->readField(ZdbAdrs::BusinessPhone) ); |
184 | addr.insertPhoneNumber( businessphone ); | 184 | addr.insertPhoneNumber( businessphone ); |
185 | } | 185 | } |
186 | 186 | ||
187 | if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) | 187 | if (!db->readField(ZdbAdrs::BusinessFax).isEmpty()) |
188 | { | 188 | { |
189 | PhoneNumber businessfax; | 189 | PhoneNumber businessfax; |
190 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); | 190 | businessfax.setType( PhoneNumber::Work | PhoneNumber::Fax ); |
191 | businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); | 191 | businessfax.setNumber( db->readField(ZdbAdrs::BusinessFax) ); |
192 | addr.insertPhoneNumber( businessfax ); | 192 | addr.insertPhoneNumber( businessfax ); |
193 | } | 193 | } |
194 | 194 | ||
195 | if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) | 195 | if (!db->readField(ZdbAdrs::BusinessMobile).isEmpty()) |
196 | { | 196 | { |
197 | PhoneNumber businessmobile; | 197 | PhoneNumber businessmobile; |
198 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); | 198 | businessmobile.setType( PhoneNumber::Work | PhoneNumber::Cell ); |
199 | businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); | 199 | businessmobile.setNumber( db->readField(ZdbAdrs::BusinessMobile) ); |
200 | addr.insertPhoneNumber( businessmobile ); | 200 | addr.insertPhoneNumber( businessmobile ); |
201 | } | 201 | } |
202 | 202 | ||
203 | if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) | 203 | if (!db->readField(ZdbAdrs::BusinessPager).isEmpty()) |
204 | { | 204 | { |
205 | PhoneNumber businesspager; | 205 | PhoneNumber businesspager; |
206 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); | 206 | businesspager.setType( PhoneNumber::Work | PhoneNumber::Pager ); |
207 | businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); | 207 | businesspager.setNumber( db->readField(ZdbAdrs::BusinessPager) ); |
208 | addr.insertPhoneNumber( businesspager ); | 208 | addr.insertPhoneNumber( businesspager ); |
209 | } | 209 | } |
210 | 210 | ||
211 | addr.setRole( db->readField(ZdbAdrs::JobTitle) ); | 211 | addr.setRole( db->readField(ZdbAdrs::JobTitle) ); |
212 | addr.setOrganization( db->readField(ZdbAdrs::Company) ); | 212 | addr.setOrganization( db->readField(ZdbAdrs::Company) ); |
213 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); | 213 | addr.insertCustom( "KADDRESSBOOK", "X-Profession", db->readField(ZdbAdrs::Profession) ); |
214 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); | 214 | addr.insertCustom( "KADDRESSBOOK", "X-AssistantsName", db->readField(ZdbAdrs::Assistant) ); |
215 | addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); | 215 | addr.insertCustom( "KADDRESSBOOK", "X-Department", db->readField(ZdbAdrs::Department) ); |
216 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); | 216 | addr.insertCustom( "KADDRESSBOOK", "X-ManagersName", db->readField(ZdbAdrs::Manager) ); |
217 | addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); | 217 | addr.insertCustom( "KADDRESSBOOK", "X-Office", db->readField(ZdbAdrs::Office) ); |
218 | 218 | ||
219 | //personal | 219 | //personal |
220 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); | 220 | addr.insertCustom( "KADDRESSBOOK", "X-SpousesName", db->readField(ZdbAdrs::Spouse) ); |
221 | 221 | ||
222 | QString gen = db->readField(ZdbAdrs::Gender); | 222 | QString gen = db->readField(ZdbAdrs::Gender); |
223 | //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); | 223 | //qDebug("SharpDTMConverter::sharpToAddressee pleas check that gender works!! : Gender: %s", gen.latin1()); |
224 | //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); | 224 | //qDebug("SharpDTMConverter::sharpToAddressee: may be int db->readUshortField(\"ZdbAdrs::Gender\") is here better suited"); |
225 | 225 | ||
226 | if (gen == "male") | 226 | if (gen == "male") |
227 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); | 227 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "male"); |
228 | else if (gen == "female") | 228 | else if (gen == "female") |
229 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); | 229 | addr.insertCustom( "KADDRESSBOOK", "X-Gender", "female"); |
230 | 230 | ||
231 | 231 | ||
232 | QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); | 232 | QDate ann = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Anniversary) ); |
233 | if (ann.isValid()) { | 233 | if (ann.isValid()) { |
234 | QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); | 234 | QString dt = KGlobal::locale()->formatDate(ann, true, KLocale::ISODate); |
235 | //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); | 235 | //qDebug("qtopiaToAddressee annyversary found:%s", dt.latin1()); |
236 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); | 236 | addr.insertCustom( "KADDRESSBOOK", "X-Anniversary", dt); |
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); | 240 | addr.insertCustom( "KADDRESSBOOK", "X-Children", db->readField(ZdbAdrs::Children) ); |
241 | 241 | ||
242 | 242 | ||
243 | QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); | 243 | QDate birthd = KGlobal::locale()->readDate( db->readField(ZdbAdrs::Birthday) ); |
244 | //qDebug("birtd %s ", birthd.toString().latin1()); | 244 | //qDebug("birtd %s ", birthd.toString().latin1()); |
245 | if (birthd.isValid()) | 245 | if (birthd.isValid()) |
246 | addr.setBirthday( birthd ); | 246 | addr.setBirthday( birthd ); |
247 | 247 | ||
248 | addr.setNickName( db->readField(ZdbAdrs::Nickname) ); | 248 | addr.setNickName( db->readField(ZdbAdrs::Nickname) ); |
249 | 249 | ||
250 | // others | 250 | // others |
251 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. | 251 | //US I put opies BusinessWebPage into Ka/Pi's notes block, because no other native field is available. |
252 | QString notes = db->readField(ZdbAdrs::Notes); | 252 | QString notes = db->readField(ZdbAdrs::Notes); |
253 | //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; | 253 | //notes += "\nBusinessWebPage: " + db->readField(ZdbAdrs::BusinessWebPage) + "\n"; |
254 | if ( addr.url().isEmpty() ) | 254 | if ( addr.url().isEmpty() ) |
255 | addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); | 255 | addr.setUrl( db->readField(ZdbAdrs::BusinessWebPage) ); |
256 | addr.setNote( db->readField(ZdbAdrs::Notes) ); | 256 | addr.setNote( db->readField(ZdbAdrs::Notes) ); |
257 | 257 | ||
258 | 258 | ||
259 | 259 | ||
260 | //US QString groups() const { return find( Qtopia::Groups ); } | 260 | //US QString groups() const { return find( Qtopia::Groups ); } |
261 | //US QStringList groupList() const; | 261 | //US QStringList groupList() const; |
262 | 262 | ||
263 | //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); | 263 | //qDebug("SharpDTMConverter::sharpToAddressee please check that the categories will be converted" ); |
264 | QArray<int> catArray = db->readCategories(); | 264 | QArray<int> catArray = db->readCategories(); |
265 | QString cat; | 265 | QString cat; |
266 | 266 | ||
267 | for ( unsigned int i=0; i < catArray.size(); i++ ) { | 267 | for ( unsigned int i=0; i < catArray.size(); i++ ) { |
268 | cat = catDB->label(catArray[i]); | 268 | cat = catDB->label(catArray[i]); |
269 | if ( cat.isEmpty() ) | 269 | if ( cat.isEmpty() ) |
270 | addr.insertCategory(QString::number(catArray[i])); | 270 | addr.insertCategory(QString::number(catArray[i])); |
271 | else | 271 | else |
272 | addr.insertCategory( cat ); | 272 | addr.insertCategory( cat ); |
273 | } | 273 | } |
274 | 274 | ||
275 | return true; | 275 | return true; |
276 | } | 276 | } |
277 | 277 | ||
278 | bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) | 278 | bool SharpDTMConverter::addresseeToSharp( const Addressee &addr, SlZDataBase* database , const CardId &contact ) |
279 | { | 279 | { |
280 | bool cellHome = false, cellWork = false; | 280 | bool cellHome = false, cellWork = false; |
281 | // name | 281 | // name |
282 | database->writeField(ZdbAdrs::LastName, addr.familyName()); | 282 | database->writeField(ZdbAdrs::LastName, addr.familyName()); |
283 | database->writeField(ZdbAdrs::FirstName, addr.givenName()); | 283 | database->writeField(ZdbAdrs::FirstName, addr.givenName()); |
284 | database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); | 284 | database->writeField(ZdbAdrs::MiddleName, addr.additionalName()); |
285 | database->writeField(ZdbAdrs::Title, addr.prefix()); | 285 | database->writeField(ZdbAdrs::Title, addr.prefix()); |
286 | database->writeField(ZdbAdrs::Suffix, addr.suffix()); | 286 | database->writeField(ZdbAdrs::Suffix, addr.suffix()); |
287 | 287 | ||
288 | //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); | 288 | //qDebug("SharpDTMConverter::addresseeToSharp check if the fileAs transformation works!!\n%s",addr.formattedName().latin1() ); |
289 | database->writeField(ZdbAdrs::FileAs, addr.formattedName()); | 289 | QString formattedName = addr.formattedName(); |
290 | database->writeField(ZdbAdrs::FullName, addr.formattedName()); | 290 | if ( formattedName.isEmpty() ) { |
291 | if ( !addr.familyName().isEmpty() ) { | ||
292 | formattedName = addr.familyName(); | ||
293 | if ( !addr.givenName().isEmpty() ) { | ||
294 | formattedName += ", "; | ||
295 | formattedName += addr.givenName(); | ||
296 | } | ||
297 | } else | ||
298 | formattedName = addr.givenName(); | ||
299 | } | ||
300 | database->writeField(ZdbAdrs::FileAs, formattedName); | ||
301 | database->writeField(ZdbAdrs::FullName, formattedName); | ||
291 | 302 | ||
292 | 303 | ||
293 | //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); | 304 | //qDebug("SharpDTMConverter::addresseeToSharp check which seperator we need here for the emails!!"); |
294 | //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); | 305 | //qDebug("SharpDTMConverter::addresseeToSharp its probably the same from sharpToAddressee"); |
295 | QString emails = addr.emails().join(" "); | 306 | QString emails = addr.emails().join(" "); |
296 | database->writeField(ZdbAdrs::Emails, emails ); | 307 | database->writeField(ZdbAdrs::Emails, emails ); |
297 | 308 | ||
298 | database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); | 309 | database->writeField(ZdbAdrs::DefaultEmail, addr.preferredEmail() ); |
299 | 310 | ||
300 | 311 | ||
301 | // home | 312 | // home |
302 | const Address homeaddress = addr.address(Address::Home); | 313 | const Address homeaddress = addr.address(Address::Home); |
303 | if (!homeaddress.isEmpty()) { | 314 | if (!homeaddress.isEmpty()) { |
304 | database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); | 315 | database->writeField(ZdbAdrs::HomeStreet, homeaddress.street()); |
305 | database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); | 316 | database->writeField(ZdbAdrs::HomeCity, homeaddress.locality()); |
306 | database->writeField(ZdbAdrs::HomeState, homeaddress.region()); | 317 | database->writeField(ZdbAdrs::HomeState, homeaddress.region()); |
307 | database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); | 318 | database->writeField(ZdbAdrs::HomeZip, homeaddress.postalCode()); |
308 | database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); | 319 | database->writeField(ZdbAdrs::HomeCountry, homeaddress.country()); |
309 | } | 320 | } |
310 | 321 | ||
311 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); | 322 | PhoneNumber homephone = addr.phoneNumber( PhoneNumber::Home ); |
312 | if (!homephone.number().isEmpty()) | 323 | if (!homephone.number().isEmpty()) |
313 | database->writeField(ZdbAdrs::HomePhone, homephone.number()); | 324 | database->writeField(ZdbAdrs::HomePhone, homephone.number()); |
314 | 325 | ||
315 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); | 326 | PhoneNumber homefax = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Fax ); |
316 | if (!homefax.number().isEmpty()) | 327 | if (!homefax.number().isEmpty()) |
317 | database->writeField(ZdbAdrs::HomeFax, homefax.number()); | 328 | database->writeField(ZdbAdrs::HomeFax, homefax.number()); |
318 | 329 | ||
319 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); | 330 | PhoneNumber homemobile = addr.phoneNumber( PhoneNumber::Home | PhoneNumber::Cell ); |
320 | if (!homemobile.number().isEmpty()) { | 331 | if (!homemobile.number().isEmpty()) { |
321 | database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); | 332 | database->writeField(ZdbAdrs::HomeMobile, homemobile.number()); |
322 | cellHome = true; | 333 | cellHome = true; |
323 | } | 334 | } |
324 | 335 | ||
325 | database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); | 336 | database->writeField(ZdbAdrs::HomeWebPage, addr.url().url()); |
326 | 337 | ||
327 | 338 | ||
328 | // business | 339 | // business |
329 | const Address businessaddress = addr.address(Address::Work); | 340 | const Address businessaddress = addr.address(Address::Work); |
330 | if (!businessaddress.isEmpty()) { | 341 | if (!businessaddress.isEmpty()) { |
331 | database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); | 342 | database->writeField(ZdbAdrs::BusinessStreet, businessaddress.street()); |
332 | database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); | 343 | database->writeField(ZdbAdrs::BusinessCity, businessaddress.locality()); |
333 | database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); | 344 | database->writeField(ZdbAdrs::BusinessState, businessaddress.region()); |
334 | database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); | 345 | database->writeField(ZdbAdrs::BusinessZip, businessaddress.postalCode()); |
335 | database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); | 346 | database->writeField(ZdbAdrs::BusinessCountry, businessaddress.country()); |
336 | } | 347 | } |
337 | 348 | ||
338 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); | 349 | PhoneNumber businessphone = addr.phoneNumber( PhoneNumber::Work ); |
339 | if (!businessphone.number().isEmpty()) | 350 | if (!businessphone.number().isEmpty()) |
340 | database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); | 351 | database->writeField(ZdbAdrs::BusinessPhone, businessphone.number()); |
341 | 352 | ||
342 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); | 353 | PhoneNumber businessfax = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Fax ); |
343 | if (!businessfax.number().isEmpty()) | 354 | if (!businessfax.number().isEmpty()) |
344 | database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); | 355 | database->writeField(ZdbAdrs::BusinessFax, businessfax.number()); |
345 | 356 | ||
346 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); | 357 | PhoneNumber businessmobile = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Cell ); |
347 | if (!businessmobile.number().isEmpty()) { | 358 | if (!businessmobile.number().isEmpty()) { |
348 | cellWork = true; | 359 | cellWork = true; |
349 | database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); | 360 | database->writeField(ZdbAdrs::BusinessMobile, businessmobile.number()); |
350 | } | 361 | } |
351 | PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); | 362 | PhoneNumber mobile = addr.phoneNumber( PhoneNumber::Cell ); |
352 | if (!businessmobile.number().isEmpty()) { | 363 | if (! mobile.number().isEmpty()) { |
353 | if ( ! cellHome ) | 364 | if ( ! cellHome ) |
354 | database->writeField(ZdbAdrs::HomeMobile, mobile.number()); | 365 | database->writeField(ZdbAdrs::HomeMobile, mobile.number()); |
355 | else if (! cellWork ) | 366 | else if (! cellWork ) |
356 | database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); | 367 | database->writeField(ZdbAdrs::BusinessMobile, mobile.number()); |
357 | } | 368 | } |
358 | 369 | ||
359 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); | 370 | PhoneNumber businesspager = addr.phoneNumber( PhoneNumber::Work | PhoneNumber::Pager ); |
360 | if (!businesspager.number().isEmpty()) | 371 | if (!businesspager.number().isEmpty()) |
361 | database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); | 372 | database->writeField(ZdbAdrs::BusinessPager, businesspager.number()); |
362 | 373 | ||
363 | database->writeField(ZdbAdrs::JobTitle, addr.role()); | 374 | database->writeField(ZdbAdrs::JobTitle, addr.role()); |
364 | database->writeField(ZdbAdrs::Company, addr.organization()); | 375 | database->writeField(ZdbAdrs::Company, addr.organization()); |
365 | 376 | ||
366 | database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); | 377 | database->writeField(ZdbAdrs::Profession, addr.custom( "KADDRESSBOOK", "X-Profession" )); |
367 | database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); | 378 | database->writeField(ZdbAdrs::Assistant, addr.custom( "KADDRESSBOOK", "X-AssistantsName" )); |
368 | database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); | 379 | database->writeField(ZdbAdrs::Department, addr.custom( "KADDRESSBOOK", "X-Department" )); |
369 | database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); | 380 | database->writeField(ZdbAdrs::Manager, addr.custom( "KADDRESSBOOK", "X-ManagersName" )); |
370 | database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); | 381 | database->writeField(ZdbAdrs::Office, addr.custom( "KADDRESSBOOK", "X-Office" )); |
371 | 382 | ||
372 | //personal | 383 | //personal |
373 | database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); | 384 | database->writeField(ZdbAdrs::Spouse, addr.custom( "KADDRESSBOOK", "X-Spouse" )); |
374 | 385 | ||
375 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); | 386 | QString gt = addr.custom( "KADDRESSBOOK", "X-Gender" ); |
376 | //qDebug("SharpDTMConverter::addresseeToSharp please check that gender works!! : Gender: %s", gt.latin1()); | 387 | //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?"); | 388 | //qDebug("SharpDTMConverter::addresseeToSharp: may be writeField(\"ZdbAdrs::Gender\", ushort) is here better suited?"); |
378 | //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); | 389 | //qDebug("SharpDTMConverter::addresseeToSharp: check also the reverse functionality in sharpToAddressee"); |
379 | if (gt == "male") | 390 | if (gt == "male") |
380 | database->writeField(ZdbAdrs::Gender, "male"); | 391 | database->writeField(ZdbAdrs::Gender, "male"); |
381 | else if (gt == "female") | 392 | else if (gt == "female") |
382 | database->writeField(ZdbAdrs::Gender, "female"); | 393 | database->writeField(ZdbAdrs::Gender, "female"); |
383 | else | 394 | else |
384 | database->writeField(ZdbAdrs::Gender, ""); | 395 | database->writeField(ZdbAdrs::Gender, ""); |
385 | 396 | ||
386 | 397 | ||
387 | QDate dt = KGlobal::locale()->readDate( | 398 | QDate dt = KGlobal::locale()->readDate( |
388 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate | 399 | addr.custom("KADDRESSBOOK", "X-Anniversary" ), "%Y-%m-%d"); // = Qt::ISODate |
389 | if ( dt.isValid() ) { | 400 | if ( dt.isValid() ) { |
390 | QString dateS = KGlobal::locale()->formatDate(dt, true ); | 401 | QString dateS = KGlobal::locale()->formatDate(dt, true ); |
391 | database->writeField(ZdbAdrs::Anniversary, dateS ); | 402 | database->writeField(ZdbAdrs::Anniversary, dateS ); |
392 | } | 403 | } |
393 | database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); | 404 | database->writeField(ZdbAdrs::Children, addr.custom( "KADDRESSBOOK", "X-Children" )); |
394 | dt = addr.birthday().date(); | 405 | dt = addr.birthday().date(); |
395 | if ( dt.isValid() ) { | 406 | if ( dt.isValid() ) { |
396 | QString dateS = KGlobal::locale()->formatDate(dt, true ); | 407 | QString dateS = KGlobal::locale()->formatDate(dt, true ); |
397 | database->writeField(ZdbAdrs::Birthday, dateS); | 408 | database->writeField(ZdbAdrs::Birthday, dateS); |
398 | } | 409 | } |
399 | database->writeField(ZdbAdrs::Nickname, addr.nickName()); | 410 | database->writeField(ZdbAdrs::Nickname, addr.nickName()); |
400 | 411 | ||
401 | // other | 412 | // other |
402 | database->writeField(ZdbAdrs::Notes, addr.note()); | 413 | database->writeField(ZdbAdrs::Notes, addr.note()); |
403 | 414 | ||
404 | //US QString groups() const { return find( Qtopia::Groups ); } | 415 | //US QString groups() const { return find( Qtopia::Groups ); } |
405 | //US QStringList groupList() const; | 416 | //US QStringList groupList() const; |
406 | 417 | ||
407 | 418 | ||
408 | //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); | 419 | //qDebug("SharpDTMConverter::addresseeToSharp please check if category transformation works"); |
409 | 420 | ||
410 | QStringList cats = addr.categories(); | 421 | QStringList cats = addr.categories(); |
411 | int ii; | 422 | int ii; |
412 | for ( ii = 0; ii < cats.count() ;++ii ) { | 423 | for ( ii = 0; ii < cats.count() ;++ii ) { |
413 | if ( !catDB->exists( cats[ii] )) | 424 | if ( !catDB->exists( cats[ii] )) |
414 | catDB->addCategory(cats[ii]); | 425 | catDB->addCategory(cats[ii]); |
415 | } | 426 | } |
416 | QArray<int> iar; | 427 | QArray<int> iar; |
417 | if ( !cats.isEmpty() ) { | 428 | if ( !cats.isEmpty() ) { |
418 | QArray<int> iar = catDB->ids(cats); | 429 | QArray<int> iar = catDB->ids(cats); |
419 | qDebug("***cat count is %d ", iar.count()); | 430 | qDebug("***cat count is %d ", iar.count()); |
420 | database->updateCategories(contact, iar); | 431 | database->updateCategories(contact, iar); |
421 | } | 432 | } |
422 | 433 | ||
423 | return true; | 434 | return true; |
424 | } | 435 | } |
425 | 436 | ||
426 | QDate SharpDTMConverter::convertDate( QString s) | 437 | QDate SharpDTMConverter::convertDate( QString s) |
427 | { | 438 | { |
428 | QDate dt = KGlobal::locale()->readDate( s ); | 439 | QDate dt = KGlobal::locale()->readDate( s ); |
429 | return dt; | 440 | return dt; |
430 | return QDate (); | 441 | return QDate (); |
431 | } | 442 | } |