-rw-r--r-- | kabc/kabcE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.cpp | 4 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 20 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 95 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 225 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.h | 3 |
8 files changed, 146 insertions, 211 deletions
diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro index 598d4fc..62a66eb 100644 --- a/kabc/kabcE.pro +++ b/kabc/kabcE.pro | |||
@@ -1,22 +1,22 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on | 2 | CONFIG += qt warn_on |
3 | TARGET = microkabc | 3 | TARGET = microkabc |
4 | 4 | ||
5 | 5 | ||
6 | INCLUDEPATH += . ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim ../qtcompat $(QPEDIR)/include | 6 | INCLUDEPATH += . .. ./vcard/include ./vcard/include/generated ../microkde ../microkde/kdecore ../microkde/kdeui ../microkde/kio/kfile ../microkde/kio/kio ../libkdepim ../qtcompat $(QPEDIR)/include |
7 | OBJECTS_DIR = obj/$(PLATFORM) | 7 | OBJECTS_DIR = obj/$(PLATFORM) |
8 | MOC_DIR = moc/$(PLATFORM) | 8 | MOC_DIR = moc/$(PLATFORM) |
9 | DESTDIR = $(QPEDIR)/lib | 9 | DESTDIR = $(QPEDIR)/lib |
10 | LIBS += -lmicrokde | 10 | LIBS += -lmicrokde |
11 | LIBS += -lmicrokdepim | 11 | LIBS += -lmicrokdepim |
12 | #LIBS += -lldap | 12 | #LIBS += -lldap |
13 | LIBS += -L$(QPEDIR)/lib | 13 | LIBS += -L$(QPEDIR)/lib |
14 | DEFINES += KAB_EMBEDDED | 14 | DEFINES += KAB_EMBEDDED |
15 | 15 | ||
16 | INTERFACES = \ | 16 | INTERFACES = \ |
17 | 17 | ||
18 | HEADERS = \ | 18 | HEADERS = \ |
19 | address.h \ | 19 | address.h \ |
20 | addressbook.h \ | 20 | addressbook.h \ |
21 | addressee.h \ | 21 | addressee.h \ |
22 | addresseedialog.h \ | 22 | addresseedialog.h \ |
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index d978e61..29f1e3a 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp | |||
@@ -44,47 +44,47 @@ $Id$ | |||
44 | #include <klocale.h> | 44 | #include <klocale.h> |
45 | #include <kstandarddirs.h> | 45 | #include <kstandarddirs.h> |
46 | #include <kurlrequester.h> | 46 | #include <kurlrequester.h> |
47 | #include <kmessagebox.h> | 47 | #include <kmessagebox.h> |
48 | 48 | ||
49 | #include "addressbook.h" | 49 | #include "addressbook.h" |
50 | 50 | ||
51 | #include "formatfactory.h" | 51 | #include "formatfactory.h" |
52 | 52 | ||
53 | #include "resourcedirconfig.h" | 53 | #include "resourcedirconfig.h" |
54 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
55 | 55 | ||
56 | //US | 56 | //US |
57 | #include <qdir.h> | 57 | #include <qdir.h> |
58 | 58 | ||
59 | #include "resourcedir.h" | 59 | #include "resourcedir.h" |
60 | #include "syncwidget.h" | 60 | #include "syncprefwidget.h" |
61 | 61 | ||
62 | using namespace KABC; | 62 | using namespace KABC; |
63 | 63 | ||
64 | extern "C" | 64 | extern "C" |
65 | #ifdef _WIN32_ | 65 | #ifdef _WIN32_ |
66 | __declspec(dllexport) | 66 | __declspec(dllexport) |
67 | #else | 67 | #else |
68 | { | 68 | { |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | //US void *init_kabc_dir() | 71 | //US void *init_kabc_dir() |
72 | void *init_microkabc_dir() | 72 | void *init_microkabc_dir() |
73 | { | 73 | { |
74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, KRES::SyncWidget>(); | 74 | return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidget>(); |
75 | } | 75 | } |
76 | #ifndef _WIN32_ | 76 | #ifndef _WIN32_ |
77 | } | 77 | } |
78 | #endif | 78 | #endif |
79 | 79 | ||
80 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) | 80 | ResourceDir::ResourceDir( const KConfig *config, bool syncable ) |
81 | : Resource( config, syncable ) | 81 | : Resource( config, syncable ) |
82 | { | 82 | { |
83 | QString path; | 83 | QString path; |
84 | 84 | ||
85 | KConfig *cfg = (KConfig *)config; | 85 | KConfig *cfg = (KConfig *)config; |
86 | if ( cfg ) { | 86 | if ( cfg ) { |
87 | //US path = config->readEntry( "FilePath" ); | 87 | //US path = config->readEntry( "FilePath" ); |
88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); | 88 | path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); |
89 | //US mFormatName = config->readEntry( "FileFormat" ); | 89 | //US mFormatName = config->readEntry( "FileFormat" ); |
90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); | 90 | mFormatName = cfg->readEntry( "FileFormat", "vcard" ); |
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 361b36b..d98efc8 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp | |||
@@ -38,48 +38,48 @@ $Id$ | |||
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 | 52 | ||
53 | #include "resourcefile.h" | 53 | #include "resourcefile.h" |
54 | #include "syncwidget.h" | 54 | #include "syncprefwidget.h" |
55 | 55 | ||
56 | 56 | ||
57 | using namespace KABC; | 57 | using namespace KABC; |
58 | 58 | ||
59 | extern "C" | 59 | extern "C" |
60 | #ifdef _WIN32_ | 60 | #ifdef _WIN32_ |
61 | __declspec(dllexport) | 61 | __declspec(dllexport) |
62 | #else | 62 | #else |
63 | { | 63 | { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | //US void *init_kabc_file() | 66 | //US void *init_kabc_file() |
67 | void *init_microkabc_file() | 67 | void *init_microkabc_file() |
68 | { | 68 | { |
69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, KRES::SyncWidget>(); | 69 | return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidget>(); |
70 | } | 70 | } |
71 | #ifndef _WIN32_ | 71 | #ifndef _WIN32_ |
72 | } | 72 | } |
73 | #endif | 73 | #endif |
74 | 74 | ||
75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) | 75 | ResourceFile::ResourceFile( const KConfig *config, bool syncable ) |
76 | : Resource( config, syncable ) , mFormat( 0 ) | 76 | : Resource( config, syncable ) , mFormat( 0 ) |
77 | { | 77 | { |
78 | QString fileName, formatName; | 78 | QString fileName, formatName; |
79 | 79 | ||
80 | KConfig *cfg = (KConfig *)config; | 80 | KConfig *cfg = (KConfig *)config; |
81 | if ( cfg ) { | 81 | if ( cfg ) { |
82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); | 82 | fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); |
83 | formatName = cfg->readEntry( "FileFormat", "vcard" ); | 83 | formatName = cfg->readEntry( "FileFormat", "vcard" ); |
84 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); | 84 | // qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); |
85 | } else { | 85 | } else { |
diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp index 4b9dede..198e80a 100644 --- a/kabc/plugins/ldap/resourceldap.cpp +++ b/kabc/plugins/ldap/resourceldap.cpp | |||
@@ -23,42 +23,42 @@ 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 <kdebug.h> | 28 | #include <kdebug.h> |
29 | #include <kglobal.h> | 29 | #include <kglobal.h> |
30 | #include <klineedit.h> | 30 | #include <klineedit.h> |
31 | #include <klocale.h> | 31 | #include <klocale.h> |
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <kstringhandler.h> | 33 | #include <kstringhandler.h> |
34 | 34 | ||
35 | #include <stdlib.h> | 35 | #include <stdlib.h> |
36 | 36 | ||
37 | #include "resourceldap.h" | 37 | #include "resourceldap.h" |
38 | #include "resourceldapconfig.h" | 38 | #include "resourceldapconfig.h" |
39 | #include "syncwidget.h" | 39 | #include "syncprefwidget.h" |
40 | 40 | ||
41 | using namespace KABC; | 41 | using namespace KABC; |
42 | 42 | ||
43 | extern "C" | 43 | extern "C" |
44 | { | 44 | { |
45 | //US void *init_kabc_ldap() | 45 | //US void *init_kabc_ldap() |
46 | void *init_microkabc_ldap() | 46 | void *init_microkabc_ldap() |
47 | { | 47 | { |
48 | return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, KRES::SyncWidget>(); | 48 | return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidget>(); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | 51 | ||
52 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); | 52 | void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); |
53 | 53 | ||
54 | 54 | ||
55 | ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) | 55 | ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) |
56 | : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) | 56 | : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) |
57 | { | 57 | { |
58 | KConfig *cfg = (KConfig *)config; | 58 | KConfig *cfg = (KConfig *)config; |
59 | if ( cfg ) { | 59 | if ( cfg ) { |
60 | mUser = cfg->readEntry( "LdapUser" ); | 60 | mUser = cfg->readEntry( "LdapUser" ); |
61 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); | 61 | mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); |
62 | mDn = cfg->readEntry( "LdapDn" ); | 62 | mDn = cfg->readEntry( "LdapDn" ); |
63 | mHost = cfg->readEntry( "LdapHost" ); | 63 | mHost = cfg->readEntry( "LdapHost" ); |
64 | mPort = cfg->readNumEntry( "LdapPort", 389 ); | 64 | mPort = cfg->readNumEntry( "LdapPort", 389 ); |
diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 1222242..5559827 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp | |||
@@ -37,90 +37,84 @@ $Id$ | |||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | //US #include "formatfactory.h" | 45 | //US #include "formatfactory.h" |
46 | //US #include <qpe/qpeapplication.h> | 46 | //US #include <qpe/qpeapplication.h> |
47 | 47 | ||
48 | #include <opie/ocontactaccess.h> | 48 | #include <opie/ocontactaccess.h> |
49 | #include <opie/ocontactaccessbackend_xml.h> | 49 | #include <opie/ocontactaccessbackend_xml.h> |
50 | 50 | ||
51 | #include "resourceopieconfig.h" | 51 | #include "resourceopieconfig.h" |
52 | #include "stdaddressbook.h" | 52 | #include "stdaddressbook.h" |
53 | #include "syncwidget.h" | 53 | #include "syncprefwidget.h" |
54 | 54 | ||
55 | #include "opieconverter.h" | 55 | #include "opieconverter.h" |
56 | 56 | ||
57 | #include "resourceopie.h" | 57 | #include "resourceopie.h" |
58 | 58 | ||
59 | using namespace KABC; | 59 | using namespace KABC; |
60 | extern "C" | 60 | extern "C" |
61 | { | 61 | { |
62 | void *init_microkabc_opie() | 62 | void *init_microkabc_opie() |
63 | { | 63 | { |
64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, KRES::SyncWidget>(); | 64 | return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidget>(); |
65 | } | 65 | } |
66 | } | 66 | } |
67 | 67 | ||
68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) | 68 | ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) |
69 | : Resource( config, syncable ), mAccess(0), mConverter (0) | 69 | : Resource( config, syncable ), mAccess(0), mConverter (0) |
70 | { | 70 | { |
71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 71 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
72 | 72 | ||
73 | KConfig *cfg = (KConfig *)config; | 73 | KConfig *cfg = (KConfig *)config; |
74 | if ( cfg ) { | 74 | if ( cfg ) { |
75 | fileName = cfg->readEntry( "FileName", fileName ); | 75 | fileName = cfg->readEntry( "FileName", fileName ); |
76 | 76 | ||
77 | } | 77 | } |
78 | 78 | ||
79 | // qDebug("ResourceOpie::ResourceOpie : %s", fileName.latin1() ); | ||
80 | |||
81 | init( fileName ); | 79 | init( fileName ); |
82 | } | 80 | } |
83 | 81 | ||
84 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) | 82 | ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) |
85 | : Resource( 0, syncable ) | 83 | : Resource( 0, syncable ) |
86 | { | 84 | { |
87 | // qDebug("ResourceOpie::ResourceOpie : 3 %s", fileName.latin1()); | ||
88 | init( fileName ); | 85 | init( fileName ); |
89 | } | 86 | } |
90 | 87 | ||
91 | void ResourceOpie::init( const QString &fileName ) | 88 | void ResourceOpie::init( const QString &fileName ) |
92 | { | 89 | { |
93 | 90 | ||
94 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 91 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
95 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 92 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
96 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 93 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
97 | 94 | ||
98 | |||
99 | setFileName( fileName ); | 95 | setFileName( fileName ); |
100 | |||
101 | } | 96 | } |
102 | 97 | ||
103 | ResourceOpie::~ResourceOpie() | 98 | ResourceOpie::~ResourceOpie() |
104 | { | 99 | { |
105 | if (mConverter != 0) | 100 | if (mConverter != 0) |
106 | delete mConverter; | 101 | delete mConverter; |
107 | 102 | ||
108 | if(mAccess != 0) | 103 | if(mAccess != 0) |
109 | delete mAccess; | 104 | delete mAccess; |
110 | |||
111 | } | 105 | } |
112 | 106 | ||
113 | void ResourceOpie::writeConfig( KConfig *config ) | 107 | void ResourceOpie::writeConfig( KConfig *config ) |
114 | { | 108 | { |
115 | Resource::writeConfig( config ); | 109 | Resource::writeConfig( config ); |
116 | 110 | ||
117 | config->writeEntry( "FileName", fileName() ); | 111 | config->writeEntry( "FileName", fileName() ); |
118 | } | 112 | } |
119 | 113 | ||
120 | Ticket *ResourceOpie::requestSaveTicket() | 114 | Ticket *ResourceOpie::requestSaveTicket() |
121 | { | 115 | { |
122 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; | 116 | kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; |
123 | 117 | ||
124 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); | 118 | qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); |
125 | 119 | ||
126 | if ( !addressBook() ) return 0; | 120 | if ( !addressBook() ) return 0; |
@@ -238,42 +232,36 @@ bool ResourceOpie::save( Ticket *ticket ) | |||
238 | } | 232 | } |
239 | } | 233 | } |
240 | 234 | ||
241 | mAccess->save(); | 235 | mAccess->save(); |
242 | 236 | ||
243 | delete ticket; | 237 | delete ticket; |
244 | unlock( fileName() ); | 238 | unlock( fileName() ); |
245 | 239 | ||
246 | return true; | 240 | return true; |
247 | 241 | ||
248 | } | 242 | } |
249 | 243 | ||
250 | bool ResourceOpie::lock( const QString &lockfileName ) | 244 | bool ResourceOpie::lock( const QString &lockfileName ) |
251 | { | 245 | { |
252 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); | 246 | qDebug("ResourceOpie::lock: %s", fileName().latin1()); |
253 | 247 | ||
254 | |||
255 | // qDebug("ResourceOpie::lock() %s", fileName.latin1()); | ||
256 | kdDebug(5700) << "ResourceOpie::lock()" << endl; | 248 | kdDebug(5700) << "ResourceOpie::lock()" << endl; |
257 | 249 | ||
258 | QString fn = lockfileName; | 250 | QString fn = lockfileName; |
259 | 251 | ||
260 | //US change the implementation how the lockfilename is getting created | ||
261 | //US fn.replace( QRegExp("/"), "_" ); | ||
262 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
263 | |||
264 | KURL url(fn); | 252 | KURL url(fn); |
265 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 253 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
266 | 254 | ||
267 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 255 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
268 | 256 | ||
269 | if (QFile::exists( lockName )) return false; | 257 | if (QFile::exists( lockName )) return false; |
270 | 258 | ||
271 | QString lockUniqueName; | 259 | QString lockUniqueName; |
272 | lockUniqueName = fn + KApplication::randomString( 8 ); | 260 | lockUniqueName = fn + KApplication::randomString( 8 ); |
273 | 261 | ||
274 | url = lockUniqueName; | 262 | url = lockUniqueName; |
275 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 263 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
276 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 264 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
277 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 265 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
278 | 266 | ||
279 | // Create unique file | 267 | // Create unique file |
@@ -289,36 +277,32 @@ bool ResourceOpie::lock( const QString &lockfileName ) | |||
289 | #endif | 277 | #endif |
290 | if ( result == 0 ) { | 278 | if ( result == 0 ) { |
291 | addressBook()->emitAddressBookLocked(); | 279 | addressBook()->emitAddressBookLocked(); |
292 | return true; | 280 | return true; |
293 | } | 281 | } |
294 | 282 | ||
295 | // TODO: check stat | 283 | // TODO: check stat |
296 | 284 | ||
297 | return false; | 285 | return false; |
298 | } | 286 | } |
299 | 287 | ||
300 | void ResourceOpie::unlock( const QString &fileName ) | 288 | void ResourceOpie::unlock( const QString &fileName ) |
301 | { | 289 | { |
302 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); | 290 | qDebug("ResourceOpie::unlock() %s", fileName.latin1()); |
303 | 291 | ||
304 | QString fn = fileName; | 292 | QString fn = fileName; |
305 | //US change the implementation how the lockfilename is getting created | ||
306 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
307 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
308 | //US QString lockName = fn + ".lock"; | ||
309 | KURL url(fn); | 293 | KURL url(fn); |
310 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 294 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
311 | 295 | ||
312 | QFile::remove( lockName ); | 296 | QFile::remove( lockName ); |
313 | QFile::remove( mLockUniqueName ); | 297 | QFile::remove( mLockUniqueName ); |
314 | addressBook()->emitAddressBookUnlocked(); | 298 | addressBook()->emitAddressBookUnlocked(); |
315 | } | 299 | } |
316 | 300 | ||
317 | void ResourceOpie::setFileName( const QString &newFileName ) | 301 | void ResourceOpie::setFileName( const QString &newFileName ) |
318 | { | 302 | { |
319 | mDirWatch.stopScan(); | 303 | mDirWatch.stopScan(); |
320 | mDirWatch.removeFile( fileName() ); | 304 | mDirWatch.removeFile( fileName() ); |
321 | 305 | ||
322 | Resource::setFileName( newFileName ); | 306 | Resource::setFileName( newFileName ); |
323 | 307 | ||
324 | mDirWatch.addFile( fileName() ); | 308 | mDirWatch.addFile( fileName() ); |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index dc88272..4a35f19 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -36,116 +36,116 @@ $Id$ | |||
36 | 36 | ||
37 | #include <kapplication.h> | 37 | #include <kapplication.h> |
38 | #include <kconfig.h> | 38 | #include <kconfig.h> |
39 | #include <kdebug.h> | 39 | #include <kdebug.h> |
40 | #include <klocale.h> | 40 | #include <klocale.h> |
41 | //US #include <ksavefile.h> | 41 | //US #include <ksavefile.h> |
42 | #include <kstandarddirs.h> | 42 | #include <kstandarddirs.h> |
43 | #include <kmessagebox.h> | 43 | #include <kmessagebox.h> |
44 | 44 | ||
45 | #include <qpe/pim/addressbookaccess.h> | 45 | #include <qpe/pim/addressbookaccess.h> |
46 | 46 | ||
47 | 47 | ||
48 | #include "resourceqtopiaconfig.h" | 48 | #include "resourceqtopiaconfig.h" |
49 | #include "stdaddressbook.h" | 49 | #include "stdaddressbook.h" |
50 | 50 | ||
51 | #include "qtopiaconverter.h" | 51 | #include "qtopiaconverter.h" |
52 | #include "syncwidget.h" | 52 | #include "syncprefwidget.h" |
53 | 53 | ||
54 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
55 | 55 | ||
56 | using namespace KABC; | 56 | using namespace KABC; |
57 | extern "C" | 57 | extern "C" |
58 | { | 58 | { |
59 | void *init_microkabc_qtopia() | 59 | void *init_microkabc_qtopia() |
60 | { | 60 | { |
61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, KRES::SyncWidget>(); | 61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidget>(); |
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | 65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
66 | : Resource( config, syncable ), mConverter (0) | 66 | : Resource( config, syncable ), mConverter (0) |
67 | { | 67 | { |
68 | // we can not choose the filename. Therefore use the default to display | 68 | // we can not choose the filename. Therefore use the default to display |
69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
70 | |||
71 | init( fileName ); | 70 | init( fileName ); |
72 | } | 71 | } |
73 | 72 | ||
74 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) | 73 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
75 | : Resource( 0, syncable ) | 74 | : Resource( 0, syncable ) |
76 | { | 75 | { |
77 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
78 | init( fileName ); | 76 | init( fileName ); |
79 | } | 77 | } |
80 | 78 | ||
81 | void ResourceQtopia::init( const QString &fileName ) | 79 | void ResourceQtopia::init( const QString &fileName ) |
82 | { | 80 | { |
83 | 81 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 82 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 83 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 84 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 85 | ||
88 | setFileName( fileName ); | 86 | setFileName( fileName ); |
89 | } | 87 | } |
90 | 88 | ||
91 | ResourceQtopia::~ResourceQtopia() | 89 | ResourceQtopia::~ResourceQtopia() |
92 | { | 90 | { |
93 | if (mConverter != 0) | 91 | if (mConverter != 0) |
94 | delete mConverter; | 92 | delete mConverter; |
95 | 93 | ||
96 | if(mAccess != 0) | 94 | if(mAccess != 0) |
97 | delete mAccess; | 95 | delete mAccess; |
98 | } | 96 | } |
99 | 97 | ||
100 | void ResourceQtopia::writeConfig( KConfig *config ) | 98 | void ResourceQtopia::writeConfig( KConfig *config ) |
101 | { | 99 | { |
102 | Resource::writeConfig( config ); | 100 | Resource::writeConfig( config ); |
103 | } | 101 | } |
104 | 102 | ||
105 | Ticket *ResourceQtopia::requestSaveTicket() | 103 | Ticket *ResourceQtopia::requestSaveTicket() |
106 | { | 104 | { |
107 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; |
108 | 106 | ||
107 | qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); | ||
108 | |||
109 | if ( !addressBook() ) return 0; | 109 | if ( !addressBook() ) return 0; |
110 | 110 | ||
111 | if ( !lock( fileName() ) ) { | 111 | if ( !lock( fileName() ) ) { |
112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
113 | << fileName() << "'" << endl; | 113 | << fileName() << "'" << endl; |
114 | return 0; | 114 | return 0; |
115 | } | 115 | } |
116 | return createTicket( this ); | 116 | return createTicket( this ); |
117 | } | 117 | } |
118 | 118 | ||
119 | 119 | ||
120 | bool ResourceQtopia::doOpen() | 120 | bool ResourceQtopia::doOpen() |
121 | { | 121 | { |
122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); | 122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
123 | 123 | ||
124 | mAccess = new AddressBookAccess(); | 124 | mAccess = new AddressBookAccess(); |
125 | 125 | ||
126 | if ( !mAccess ) { | 126 | if ( !mAccess ) { |
127 | qDebug("Unable to load file() %s", fileName().latin1()); | 127 | qDebug("Unable to load file() %s", fileName().latin1()); |
128 | return false; | 128 | return false; |
129 | } | 129 | } |
130 | 130 | ||
131 | bool res = false; | 131 | |
132 | if (mConverter == 0) | 132 | if (mConverter == 0) |
133 | { | 133 | { |
134 | mConverter = new QtopiaConverter(); | 134 | mConverter = new QtopiaConverter(); |
135 | res = mConverter->init(); | 135 | bool res = mConverter->init(); |
136 | if ( !res ) | 136 | if ( !res ) |
137 | { | 137 | { |
138 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); | 138 | QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); |
139 | qDebug(msg); | 139 | qDebug(msg); |
140 | delete mAccess; | 140 | delete mAccess; |
141 | mAccess = 0; | 141 | mAccess = 0; |
142 | return false; | 142 | return false; |
143 | } | 143 | } |
144 | } | 144 | } |
145 | 145 | ||
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | 148 | ||
149 | void ResourceQtopia::doClose() | 149 | void ResourceQtopia::doClose() |
150 | { | 150 | { |
151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | 151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); |
@@ -176,137 +176,112 @@ bool ResourceQtopia::load() | |||
176 | KABC::Addressee addressee; | 176 | KABC::Addressee addressee; |
177 | 177 | ||
178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); | 178 | res = mConverter->qtopiaToAddressee( (*contact), addressee ); |
179 | 179 | ||
180 | if ( !addressee.isEmpty() && res ) | 180 | if ( !addressee.isEmpty() && res ) |
181 | { | 181 | { |
182 | addressee.setResource( this ); | 182 | addressee.setResource( this ); |
183 | addressBook()->insertAddressee( addressee ); | 183 | addressBook()->insertAddressee( addressee ); |
184 | } | 184 | } |
185 | } | 185 | } |
186 | 186 | ||
187 | return true; | 187 | return true; |
188 | } | 188 | } |
189 | 189 | ||
190 | bool ResourceQtopia::save( Ticket *ticket ) | 190 | bool ResourceQtopia::save( Ticket *ticket ) |
191 | { | 191 | { |
192 | /*US | 192 | qDebug("ResourceQtopia::save: %s", fileName().latin1()); |
193 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
194 | kdDebug(5700) << "ResourceQtopia::save()" << endl; | ||
195 | |||
196 | // create backup file | ||
197 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
198 | 193 | ||
199 | /*US we use a simpler method to create a backupfile | ||
200 | |||
201 | (void) KSaveFile::backupFile( mFileName, QString::null | ||
202 | ,extension ); | ||
203 | |||
204 | KSaveFile saveFile( mFileName ); | ||
205 | bool ok = false; | ||
206 | if ( saveFile.status() == 0 && saveFile.file() ) | ||
207 | { | ||
208 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | ||
209 | ok = saveFile.close(); | ||
210 | } | ||
211 | */ | ||
212 | 194 | ||
213 | /*US | 195 | KABC::AddressBook::Iterator it; |
214 | //US ToDo: write backupfile | 196 | bool res; |
215 | QFile info; | ||
216 | info.setName( mFileName ); | ||
217 | bool ok = info.open( IO_WriteOnly ); | ||
218 | if ( ok ) { | ||
219 | //US mFormat->saveAll( addressBook(), this, &info ); | ||
220 | 197 | ||
221 | info.close(); | 198 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
222 | ok = true; | 199 | PimContact c; |
223 | } | 200 | KABC::Addressee addressee = (*it); |
224 | else { | ||
225 | 201 | ||
202 | res = mConverter->addresseeToQtopia( *it, c ); | ||
203 | if (res == true) | ||
204 | { | ||
205 | mAccess->addContact(c); | ||
206 | // if (res == false) | ||
207 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); | ||
212 | } | ||
226 | } | 213 | } |
227 | 214 | ||
228 | if ( !ok ) | 215 | // mAccess->addressBookUpdated(); |
229 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
230 | 216 | ||
231 | delete ticket; | 217 | delete ticket; |
232 | unlock( mFileName ); | 218 | unlock( fileName() ); |
233 | |||
234 | return ok; | ||
235 | |||
236 | qDebug("ResourceQtopia::save has to be changed"); | ||
237 | |||
238 | |||
239 | access->save(); | ||
240 | |||
241 | */ | ||
242 | 219 | ||
243 | return true; | 220 | return true; |
244 | } | 221 | } |
245 | 222 | ||
246 | bool ResourceQtopia::lock( const QString &fileName ) | 223 | bool ResourceQtopia::lock( const QString &lockfileName ) |
247 | { | 224 | { |
248 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; | 225 | qDebug("ResourceQtopia::lock: %s", fileName().latin1()); |
249 | 226 | ||
250 | QString fn = fileName; | 227 | kdDebug(5700) << "ResourceQtopia::lock()" << endl; |
251 | 228 | ||
252 | //US change the implementation how the lockfilename is getting created | 229 | QString fn = lockfileName; |
253 | //US fn.replace( QRegExp("/"), "_" ); | ||
254 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
255 | 230 | ||
256 | KURL url(fn); | 231 | KURL url(fn); |
257 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 232 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
258 | 233 | ||
259 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 234 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
260 | 235 | ||
261 | if (QFile::exists( lockName )) return false; | 236 | if (QFile::exists( lockName )) return false; |
262 | 237 | ||
263 | QString lockUniqueName; | 238 | QString lockUniqueName; |
264 | lockUniqueName = fn + KApplication::randomString( 8 ); | 239 | lockUniqueName = fn + KApplication::randomString( 8 ); |
265 | 240 | ||
266 | url = lockUniqueName; | 241 | url = lockUniqueName; |
267 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 242 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
268 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 243 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
269 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 244 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
270 | 245 | ||
271 | // Create unique file | 246 | // Create unique file |
272 | QFile file( mLockUniqueName ); | 247 | QFile file( mLockUniqueName ); |
273 | file.open( IO_WriteOnly ); | 248 | file.open( IO_WriteOnly ); |
274 | file.close(); | 249 | file.close(); |
275 | 250 | ||
276 | // Create lock file | 251 | // Create lock file |
277 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 252 | int result = 0; |
253 | #ifndef _WIN32_ | ||
254 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
278 | QFile::encodeName( lockName ) ); | 255 | QFile::encodeName( lockName ) ); |
279 | 256 | #endif | |
280 | if ( result == 0 ) { | 257 | if ( result == 0 ) { |
281 | addressBook()->emitAddressBookLocked(); | 258 | addressBook()->emitAddressBookLocked(); |
282 | return true; | 259 | return true; |
283 | } | 260 | } |
284 | 261 | ||
285 | // TODO: check stat | 262 | // TODO: check stat |
286 | 263 | ||
287 | return false; | 264 | return false; |
288 | } | 265 | } |
289 | 266 | ||
290 | void ResourceQtopia::unlock( const QString &fileName ) | 267 | void ResourceQtopia::unlock( const QString &fileName ) |
291 | { | 268 | { |
269 | qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); | ||
270 | |||
292 | QString fn = fileName; | 271 | QString fn = fileName; |
293 | //US change the implementation how the lockfilename is getting created | ||
294 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
295 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
296 | //US QString lockName = fn + ".lock"; | ||
297 | KURL url(fn); | 272 | KURL url(fn); |
298 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 273 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
299 | 274 | ||
300 | QFile::remove( lockName ); | 275 | QFile::remove( lockName ); |
301 | QFile::remove( mLockUniqueName ); | 276 | QFile::remove( mLockUniqueName ); |
302 | addressBook()->emitAddressBookUnlocked(); | 277 | addressBook()->emitAddressBookUnlocked(); |
303 | } | 278 | } |
304 | 279 | ||
305 | void ResourceQtopia::setFileName( const QString &newFileName ) | 280 | void ResourceQtopia::setFileName( const QString &newFileName ) |
306 | { | 281 | { |
307 | mDirWatch.stopScan(); | 282 | mDirWatch.stopScan(); |
308 | mDirWatch.removeFile( fileName() ); | 283 | mDirWatch.removeFile( fileName() ); |
309 | 284 | ||
310 | Resource::setFileName( newFileName ); | 285 | Resource::setFileName( newFileName ); |
311 | 286 | ||
312 | mDirWatch.addFile( fileName() ); | 287 | mDirWatch.addFile( fileName() ); |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 7b909de..14f272d 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp | |||
@@ -36,336 +36,309 @@ $Id$ | |||
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 | 48 | ||
49 | #include "resourcesharpdtmconfig.h" | 49 | #include "resourcesharpdtmconfig.h" |
50 | #include "resourcesharpdtm.h" | 50 | #include "resourcesharpdtm.h" |
51 | 51 | ||
52 | #include "syncprefwidget.h" | ||
53 | |||
52 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
53 | 55 | ||
54 | #include "sharpdtmconverter.h" | 56 | #include "sharpdtmconverter.h" |
55 | 57 | ||
56 | using namespace KABC; | 58 | using namespace KABC; |
57 | extern "C" | 59 | extern "C" |
58 | { | 60 | { |
59 | void *init_microkabc_sharpdtm() | 61 | void *init_microkabc_sharpdtm() |
60 | { | 62 | { |
61 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); | 63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>(); |
62 | } | 64 | } |
63 | } | 65 | } |
64 | 66 | ||
65 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | 67 | ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) |
66 | : Resource( config, syncable ), mConverter (0) | 68 | : Resource( config, syncable ), mConverter (0) |
67 | { | 69 | { |
68 | // we can not choose the filename. Therefore use the default to display | 70 | // we can not choose the filename. Therefore use the default to display |
69 | 71 | ||
70 | QString fileName = SlZDataBase::addressbookFileName(); | 72 | QString fileName = SlZDataBase::addressbookFileName(); |
71 | init( fileName ); | 73 | init( fileName ); |
72 | } | 74 | } |
73 | 75 | ||
74 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | 76 | ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) |
75 | : Resource( 0, syncable ) | 77 | : Resource( 0, syncable ) |
76 | { | 78 | { |
77 | // qDebug("ResourceFile::ResourceSharpDTM : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
78 | init( fileName ); | 79 | init( fileName ); |
79 | } | 80 | } |
80 | 81 | ||
81 | void ResourceSharpDTM::init( const QString &fileName ) | 82 | void ResourceSharpDTM::init( const QString &fileName ) |
82 | { | 83 | { |
83 | 84 | ||
84 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); | 85 | connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); |
85 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); | 86 | connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); |
86 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); | 87 | connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); |
87 | 88 | ||
88 | setFileName( fileName ); | 89 | setFileName( fileName ); |
89 | } | 90 | } |
90 | 91 | ||
91 | ResourceSharpDTM::~ResourceSharpDTM() | 92 | ResourceSharpDTM::~ResourceSharpDTM() |
92 | { | 93 | { |
93 | // if (mConverter != 0) | 94 | if (mConverter != 0) |
94 | // delete mConverter; | 95 | delete mConverter; |
95 | 96 | ||
97 | if(mAccess != 0) | ||
98 | delete mAccess; | ||
96 | } | 99 | } |
97 | 100 | ||
98 | void ResourceSharpDTM::writeConfig( KConfig *config ) | 101 | void ResourceSharpDTM::writeConfig( KConfig *config ) |
99 | { | 102 | { |
100 | Resource::writeConfig( config ); | 103 | Resource::writeConfig( config ); |
101 | } | 104 | } |
102 | 105 | ||
103 | Ticket *ResourceSharpDTM::requestSaveTicket() | 106 | Ticket *ResourceSharpDTM::requestSaveTicket() |
104 | { | 107 | { |
105 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; | 108 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; |
109 | |||
110 | qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); | ||
106 | 111 | ||
107 | if ( !addressBook() ) return 0; | 112 | if ( !addressBook() ) return 0; |
108 | 113 | ||
109 | if ( !lock( mFileName ) ) { | 114 | if ( !lock( fileName() ) ) { |
110 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 115 | kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" |
111 | << mFileName << "'" << endl; | 116 | << fileName() << "'" << endl; |
112 | return 0; | 117 | return 0; |
113 | } | 118 | } |
114 | return createTicket( this ); | 119 | return createTicket( this ); |
115 | } | 120 | } |
116 | 121 | ||
117 | 122 | ||
118 | bool ResourceSharpDTM::doOpen() | 123 | bool ResourceSharpDTM::doOpen() |
119 | { | 124 | { |
120 | /*US | 125 | qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); |
121 | QFile file( mFileName ); | ||
122 | |||
123 | if ( !file.exists() ) { | ||
124 | // try to create the file | ||
125 | bool ok = file.open( IO_WriteOnly ); | ||
126 | if ( ok ) | ||
127 | file.close(); | ||
128 | |||
129 | return ok; | ||
130 | } else { | ||
131 | if ( !file.open( IO_ReadWrite ) ) | ||
132 | return false; | ||
133 | |||
134 | if ( file.size() == 0 ) { | ||
135 | file.close(); | ||
136 | return true; | ||
137 | } | ||
138 | |||
139 | //US bool ok = mFormat->checkFormat( &file ); | ||
140 | bool ok = true; | ||
141 | |||
142 | file.close(); | ||
143 | |||
144 | return ok; | ||
145 | } | ||
146 | */ | ||
147 | return true; | ||
148 | } | ||
149 | |||
150 | void ResourceSharpDTM::doClose() | ||
151 | { | ||
152 | } | ||
153 | |||
154 | bool ResourceSharpDTM::load() | ||
155 | { | ||
156 | kdDebug(5700) << "ResourcSharpDTM::load(): '" << mFileName << "'" << endl; | ||
157 | |||
158 | // qDebug("ResourceSharpDTM::load: Try to load file() %s", mFileName.latin1()); | ||
159 | 126 | ||
160 | // the last parameter in the SlZDataBase constructor means "readonly" | 127 | // the last parameter in the SlZDataBase constructor means "readonly" |
161 | SlZDataBase* access = new SlZDataBase(mFileName, | 128 | mAccess = new SlZDataBase(fileName(), |
162 | SlZDataBase::addressbookItems(), | 129 | SlZDataBase::addressbookItems(), |
163 | NULL, true); | 130 | NULL, true); |
164 | if ( !access ) { | 131 | |
165 | qDebug("Unable to load file() %s", mFileName.latin1()); | 132 | if ( !mAccess ) { |
166 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | 133 | qDebug("Unable to load file() %s", fileName().latin1()); |
167 | return false; | 134 | return false; |
168 | } | 135 | } |
169 | 136 | ||
170 | bool res = false; | ||
171 | if (mConverter == 0) | 137 | if (mConverter == 0) |
172 | { | 138 | { |
173 | mConverter = new SharpDTMConverter(); | 139 | mConverter = new SharpDTMConverter(); |
174 | res = mConverter->init(); | 140 | bool res = mConverter->init(); |
175 | if ( !res ) | 141 | if ( !res ) |
176 | { | 142 | { |
177 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 143 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); |
178 | 144 | ||
179 | qDebug(msg); | 145 | qDebug(msg); |
180 | addressBook()->error( i18n( msg ) ); | 146 | delete mAccess; |
181 | delete access; | 147 | mAccess = 0; |
182 | return false; | 148 | return false; |
183 | } | 149 | } |
184 | } | 150 | } |
185 | 151 | ||
186 | { //create a new scope | 152 | return true; |
187 | CardId id; | 153 | } |
154 | |||
155 | void ResourceSharpDTM::doClose() | ||
156 | { | ||
157 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); | ||
188 | 158 | ||
189 | for (bool res=access->first(); res == true; res=access->next()) { | 159 | if(mAccess) |
190 | id = access->cardId(); | 160 | { |
161 | delete mAccess; | ||
162 | mAccess = 0; | ||
163 | } | ||
164 | // it seems so, that deletion of access deletes backend as well | ||
165 | //delete backend; | ||
191 | 166 | ||
192 | KABC::Addressee addressee; | 167 | return; |
168 | } | ||
193 | 169 | ||
194 | res = mConverter->sharpToAddressee( id, access, addressee ); | 170 | bool ResourceSharpDTM::load() |
171 | { | ||
172 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); | ||
195 | 173 | ||
196 | if ( !addressee.isEmpty() && res ) | 174 | bool res = false; |
197 | { | 175 | |
198 | addressee.setResource( this ); | 176 | CardId id; |
199 | addressBook()->insertAddressee( addressee ); | 177 | |
200 | } | 178 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
179 | { | ||
180 | id = mAccess->cardId(); | ||
181 | |||
182 | KABC::Addressee addressee; | ||
183 | |||
184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); | ||
185 | |||
186 | if ( !addressee.isEmpty() && res ) | ||
187 | { | ||
188 | addressee.setResource( this ); | ||
189 | addressBook()->insertAddressee( addressee ); | ||
201 | } | 190 | } |
202 | } | 191 | } |
203 | 192 | ||
204 | delete access; | ||
205 | return true; | 193 | return true; |
206 | } | 194 | } |
207 | 195 | ||
208 | bool ResourceSharpDTM::save( Ticket *ticket ) | 196 | bool ResourceSharpDTM::save( Ticket *ticket ) |
209 | { | 197 | { |
210 | /*US | 198 | qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); |
211 | // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); | ||
212 | kdDebug(5700) << "ResourceQtopia::save()" << endl; | ||
213 | 199 | ||
214 | // create backup file | ||
215 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
216 | 200 | ||
217 | /*US we use a simpler method to create a backupfile | 201 | KABC::AddressBook::Iterator it; |
202 | bool res; | ||
218 | 203 | ||
219 | (void) KSaveFile::backupFile( mFileName, QString::null | 204 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
220 | ,extension ); | 205 | CardId id = 0;// 0 means new card |
206 | KABC::Addressee addressee = (*it); | ||
221 | 207 | ||
222 | KSaveFile saveFile( mFileName ); | 208 | res = mAccess->startEditCard(id); |
223 | bool ok = false; | 209 | if (res == true) |
224 | if ( saveFile.status() == 0 && saveFile.file() ) | 210 | { |
225 | { | 211 | res = mConverter->addresseeToSharp( *it, mAccess, id ); |
226 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 212 | if (res == true) |
227 | ok = saveFile.close(); | 213 | { |
228 | } | 214 | res = mAccess->finishEditCard(&id); |
229 | */ | 215 | if (res == false) |
230 | 216 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | |
231 | /*US | 217 | } |
232 | //US ToDo: write backupfile | 218 | else |
233 | QFile info; | 219 | { |
234 | info.setName( mFileName ); | 220 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
235 | bool ok = info.open( IO_WriteOnly ); | 221 | mAccess->cancelEditCard(); |
236 | if ( ok ) { | 222 | } |
237 | //US mFormat->saveAll( addressBook(), this, &info ); | 223 | } |
238 | 224 | else | |
239 | info.close(); | 225 | { |
240 | ok = true; | 226 | qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); |
241 | } | 227 | } |
242 | else { | ||
243 | 228 | ||
244 | } | 229 | } |
245 | 230 | ||
246 | if ( !ok ) | 231 | //US mAccess->save(); |
247 | addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); | ||
248 | 232 | ||
249 | delete ticket; | 233 | delete ticket; |
250 | unlock( mFileName ); | 234 | unlock( fileName() ); |
251 | 235 | ||
252 | return ok; | ||
253 | |||
254 | qDebug("ResourceQtopia::save has to be changed"); | ||
255 | */ | ||
256 | return true; | 236 | return true; |
257 | } | 237 | } |
258 | 238 | ||
259 | bool ResourceSharpDTM::lock( const QString &fileName ) | 239 | bool ResourceSharpDTM::lock( const QString &lockfileName ) |
260 | { | 240 | { |
261 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; | 241 | qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); |
262 | 242 | ||
263 | QString fn = fileName; | 243 | kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; |
264 | 244 | ||
265 | //US change the implementation how the lockfilename is getting created | 245 | QString fn = lockfileName; |
266 | //US fn.replace( QRegExp("/"), "_" ); | ||
267 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
268 | 246 | ||
269 | KURL url(fn); | 247 | KURL url(fn); |
270 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 248 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
271 | 249 | ||
272 | kdDebug(5700) << "-- lock name: " << lockName << endl; | 250 | kdDebug(5700) << "-- lock name: " << lockName << endl; |
273 | 251 | ||
274 | if (QFile::exists( lockName )) return false; | 252 | if (QFile::exists( lockName )) return false; |
275 | 253 | ||
276 | QString lockUniqueName; | 254 | QString lockUniqueName; |
277 | lockUniqueName = fn + KApplication::randomString( 8 ); | 255 | lockUniqueName = fn + KApplication::randomString( 8 ); |
278 | 256 | ||
279 | url = lockUniqueName; | 257 | url = lockUniqueName; |
280 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); | 258 | //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); |
281 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); | 259 | mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); |
282 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; | 260 | kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; |
283 | 261 | ||
284 | // Create unique file | 262 | // Create unique file |
285 | QFile file( mLockUniqueName ); | 263 | QFile file( mLockUniqueName ); |
286 | file.open( IO_WriteOnly ); | 264 | file.open( IO_WriteOnly ); |
287 | file.close(); | 265 | file.close(); |
288 | 266 | ||
289 | // Create lock file | 267 | // Create lock file |
290 | int result = ::link( QFile::encodeName( mLockUniqueName ), | 268 | int result = 0; |
269 | #ifndef _WIN32_ | ||
270 | result = ::link( QFile::encodeName( mLockUniqueName ), | ||
291 | QFile::encodeName( lockName ) ); | 271 | QFile::encodeName( lockName ) ); |
292 | 272 | #endif | |
293 | if ( result == 0 ) { | 273 | if ( result == 0 ) { |
294 | addressBook()->emitAddressBookLocked(); | 274 | addressBook()->emitAddressBookLocked(); |
295 | return true; | 275 | return true; |
296 | } | 276 | } |
297 | 277 | ||
298 | // TODO: check stat | 278 | // TODO: check stat |
299 | 279 | ||
300 | return false; | 280 | return false; |
301 | } | 281 | } |
302 | 282 | ||
303 | void ResourceSharpDTM::unlock( const QString &fileName ) | 283 | void ResourceSharpDTM::unlock( const QString &fileName ) |
304 | { | 284 | { |
285 | qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); | ||
286 | |||
305 | QString fn = fileName; | 287 | QString fn = fileName; |
306 | //US change the implementation how the lockfilename is getting created | ||
307 | //US fn.replace( QRegExp( "/" ), "_" ); | ||
308 | //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); | ||
309 | //US QString lockName = fn + ".lock"; | ||
310 | KURL url(fn); | 288 | KURL url(fn); |
311 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); | 289 | QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); |
312 | 290 | ||
313 | QFile::remove( lockName ); | 291 | QFile::remove( lockName ); |
314 | QFile::remove( mLockUniqueName ); | 292 | QFile::remove( mLockUniqueName ); |
315 | addressBook()->emitAddressBookUnlocked(); | 293 | addressBook()->emitAddressBookUnlocked(); |
316 | } | 294 | } |
317 | 295 | ||
318 | void ResourceSharpDTM::setFileName( const QString &fileName ) | 296 | void ResourceSharpDTM::setFileName( const QString &newFileName ) |
319 | { | 297 | { |
320 | mDirWatch.stopScan(); | 298 | mDirWatch.stopScan(); |
321 | mDirWatch.removeFile( mFileName ); | 299 | mDirWatch.removeFile( fileName() ); |
322 | 300 | ||
323 | mFileName = fileName; | 301 | Resource::setFileName( newFileName ); |
324 | 302 | ||
325 | mDirWatch.addFile( mFileName ); | 303 | mDirWatch.addFile( fileName() ); |
326 | mDirWatch.startScan(); | 304 | mDirWatch.startScan(); |
327 | 305 | ||
328 | } | 306 | } |
329 | 307 | ||
330 | QString ResourceSharpDTM::fileName() const | ||
331 | { | ||
332 | return mFileName; | ||
333 | } | ||
334 | |||
335 | void ResourceSharpDTM::fileChanged() | 308 | void ResourceSharpDTM::fileChanged() |
336 | { | 309 | { |
337 | // There is a small theoretical chance that KDirWatch calls us before | 310 | // There is a small theoretical chance that KDirWatch calls us before |
338 | // we are fully constructed | 311 | // we are fully constructed |
339 | if (!addressBook()) | 312 | if (!addressBook()) |
340 | return; | 313 | return; |
341 | 314 | ||
342 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 315 | QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
343 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 316 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
344 | load(); | 317 | load(); |
345 | addressBook()->emitAddressBookChanged(); | 318 | addressBook()->emitAddressBookChanged(); |
346 | } | 319 | } |
347 | } | 320 | } |
348 | 321 | ||
349 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | 322 | void ResourceSharpDTM::removeAddressee( const Addressee &addr ) |
350 | { | 323 | { |
351 | } | 324 | } |
352 | 325 | ||
353 | void ResourceSharpDTM::cleanUp() | 326 | void ResourceSharpDTM::cleanUp() |
354 | { | 327 | { |
355 | unlock( mFileName ); | 328 | unlock( fileName() ); |
356 | } | 329 | } |
357 | 330 | ||
358 | /** | 331 | /** |
359 | * This method returns the number of elements that are currently in the resource. | 332 | * This method returns the number of elements that are currently in the resource. |
360 | */ | 333 | */ |
361 | int ResourceSharpDTM::count() const | 334 | int ResourceSharpDTM::count() const |
362 | { | 335 | { |
363 | if (mAccess != 0) | 336 | if (mAccess != 0) |
364 | return mAccess->count(); | 337 | return mAccess->count(); |
365 | else | 338 | else |
366 | return 0; | 339 | return 0; |
367 | } | 340 | } |
368 | 341 | ||
369 | 342 | ||
370 | /** | 343 | /** |
371 | * This method removes all elements from the resource!! (Not from the addressbook) | 344 | * This method removes all elements from the resource!! (Not from the addressbook) |
diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.h b/kabc/plugins/sharpdtm/resourcesharpdtm.h index f495e9d..60d38a1 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.h +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.h | |||
@@ -24,32 +24,34 @@ Copyright (c) 2004 Ulf Schenk | |||
24 | 24 | ||
25 | $Id$ | 25 | $Id$ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | 28 | ||
29 | #ifndef KABC_RESOURCESHARPDTM_H | 29 | #ifndef KABC_RESOURCESHARPDTM_H |
30 | #define KABC_RESOURCESHARPDTM_H | 30 | #define KABC_RESOURCESHARPDTM_H |
31 | 31 | ||
32 | #include <kconfig.h> | 32 | #include <kconfig.h> |
33 | #include <kdirwatch.h> | 33 | #include <kdirwatch.h> |
34 | 34 | ||
35 | #include <sys/types.h> | 35 | #include <sys/types.h> |
36 | 36 | ||
37 | #include "resource.h" | 37 | #include "resource.h" |
38 | 38 | ||
39 | 39 | ||
40 | class SlZDataBase; | ||
41 | |||
40 | namespace KABC { | 42 | namespace KABC { |
41 | 43 | ||
42 | class ResourceConfigWidget; | 44 | class ResourceConfigWidget; |
43 | class SharpDTMConverter; | 45 | class SharpDTMConverter; |
44 | 46 | ||
45 | /** | 47 | /** |
46 | @internal | 48 | @internal |
47 | */ | 49 | */ |
48 | class ResourceSharpDTM : public Resource | 50 | class ResourceSharpDTM : public Resource |
49 | { | 51 | { |
50 | Q_OBJECT | 52 | Q_OBJECT |
51 | 53 | ||
52 | public: | 54 | public: |
53 | 55 | ||
54 | /** | 56 | /** |
55 | Constructor. | 57 | Constructor. |
@@ -128,26 +130,27 @@ public: | |||
128 | /** | 130 | /** |
129 | * This method removes all elements from the resource!! (Not from the addressbook) | 131 | * This method removes all elements from the resource!! (Not from the addressbook) |
130 | */ | 132 | */ |
131 | virtual bool clear(); | 133 | virtual bool clear(); |
132 | 134 | ||
133 | 135 | ||
134 | protected slots: | 136 | protected slots: |
135 | void fileChanged(); | 137 | void fileChanged(); |
136 | 138 | ||
137 | protected: | 139 | protected: |
138 | void init( const QString &fileName ); | 140 | void init( const QString &fileName ); |
139 | 141 | ||
140 | bool lock( const QString &fileName ); | 142 | bool lock( const QString &fileName ); |
141 | void unlock( const QString &fileName ); | 143 | void unlock( const QString &fileName ); |
142 | 144 | ||
143 | private: | 145 | private: |
146 | SlZDataBase* mAccess; | ||
144 | SharpDTMConverter* mConverter; | 147 | SharpDTMConverter* mConverter; |
145 | 148 | ||
146 | QString mLockUniqueName; | 149 | QString mLockUniqueName; |
147 | 150 | ||
148 | KDirWatch mDirWatch; | 151 | KDirWatch mDirWatch; |
149 | }; | 152 | }; |
150 | 153 | ||
151 | } | 154 | } |
152 | 155 | ||
153 | #endif | 156 | #endif |