-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 | 89 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 205 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.h | 3 |
8 files changed, 133 insertions, 198 deletions
diff --git a/kabc/kabcE.pro b/kabc/kabcE.pro index 598d4fc..62a66eb 100644 --- a/kabc/kabcE.pro +++ b/kabc/kabcE.pro | |||
@@ -3,7 +3,7 @@ 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 |
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 | |||
@@ -57,7 +57,7 @@ $Id$ | |||
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 | ||
@@ -71,7 +71,7 @@ __declspec(dllexport) | |||
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 | } |
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 | |||
@@ -51,7 +51,7 @@ $Id$ | |||
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; |
@@ -66,7 +66,7 @@ __declspec(dllexport) | |||
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 | } |
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 | |||
@@ -36,7 +36,7 @@ $Id$ | |||
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 | ||
@@ -45,7 +45,7 @@ extern "C" | |||
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 | ||
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 | |||
@@ -50,7 +50,7 @@ $Id$ | |||
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 | ||
@@ -61,7 +61,7 @@ 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 | ||
@@ -76,15 +76,12 @@ ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) | |||
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 | ||
@@ -95,9 +92,7 @@ void ResourceOpie::init( const QString &fileName ) | |||
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() |
@@ -107,7 +102,6 @@ ResourceOpie::~ResourceOpie() | |||
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 ) |
@@ -251,16 +245,10 @@ 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 | ||
@@ -302,10 +290,6 @@ void ResourceOpie::unlock( const QString &fileName ) | |||
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 | ||
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 | |||
@@ -49,7 +49,7 @@ $Id$ | |||
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 | ||
@@ -58,7 +58,7 @@ 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 | ||
@@ -67,14 +67,12 @@ ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) | |||
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 | ||
@@ -106,6 +104,8 @@ 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() ) ) { |
@@ -128,11 +128,11 @@ bool ResourceQtopia::doOpen() | |||
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"); |
@@ -189,69 +189,44 @@ bool ResourceQtopia::load() | |||
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 | 193 | ||
196 | // create backup file | ||
197 | QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); | ||
198 | 194 | ||
199 | /*US we use a simpler method to create a backupfile | 195 | KABC::AddressBook::Iterator it; |
196 | bool res; | ||
200 | 197 | ||
201 | (void) KSaveFile::backupFile( mFileName, QString::null | 198 | for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { |
202 | ,extension ); | 199 | PimContact c; |
200 | KABC::Addressee addressee = (*it); | ||
203 | 201 | ||
204 | KSaveFile saveFile( mFileName ); | 202 | res = mConverter->addresseeToQtopia( *it, c ); |
205 | bool ok = false; | 203 | if (res == true) |
206 | if ( saveFile.status() == 0 && saveFile.file() ) | ||
207 | { | 204 | { |
208 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 205 | mAccess->addContact(c); |
209 | ok = saveFile.close(); | 206 | // if (res == false) |
207 | // qDebug("Unable to append Contact %s", c.fullName().latin1()); | ||
210 | } | 208 | } |
211 | */ | 209 | else |
212 | 210 | { | |
213 | /*US | 211 | qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); |
214 | //US ToDo: write backupfile | ||
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 | |||
221 | info.close(); | ||
222 | ok = true; | ||
223 | } | 212 | } |
224 | else { | ||
225 | |||
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" ); |
@@ -274,9 +249,11 @@ bool ResourceQtopia::lock( const QString &fileName ) | |||
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; |
@@ -289,11 +266,9 @@ bool ResourceQtopia::lock( const QString &fileName ) | |||
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 | ||
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 | |||
@@ -49,6 +49,8 @@ $Id$ | |||
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" |
@@ -58,7 +60,7 @@ 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 | ||
@@ -74,7 +76,6 @@ ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) | |||
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 | ||
@@ -90,9 +91,11 @@ void ResourceSharpDTM::init( const QString &fileName ) | |||
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 ) |
@@ -102,13 +105,15 @@ void ResourceSharpDTM::writeConfig( KConfig *config ) | |||
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 ); |
@@ -117,81 +122,66 @@ Ticket *ResourceSharpDTM::requestSaveTicket() | |||
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 | 126 | ||
123 | if ( !file.exists() ) { | 127 | // the last parameter in the SlZDataBase constructor means "readonly" |
124 | // try to create the file | 128 | mAccess = new SlZDataBase(fileName(), |
125 | bool ok = file.open( IO_WriteOnly ); | 129 | SlZDataBase::addressbookItems(), |
126 | if ( ok ) | 130 | NULL, true); |
127 | file.close(); | ||
128 | 131 | ||
129 | return ok; | 132 | if ( !mAccess ) { |
130 | } else { | 133 | qDebug("Unable to load file() %s", fileName().latin1()); |
131 | if ( !file.open( IO_ReadWrite ) ) | ||
132 | return false; | 134 | return false; |
133 | |||
134 | if ( file.size() == 0 ) { | ||
135 | file.close(); | ||
136 | return true; | ||
137 | } | 135 | } |
138 | 136 | ||
139 | //US bool ok = mFormat->checkFormat( &file ); | 137 | if (mConverter == 0) |
140 | bool ok = true; | 138 | { |
141 | 139 | mConverter = new SharpDTMConverter(); | |
142 | file.close(); | 140 | bool res = mConverter->init(); |
141 | if ( !res ) | ||
142 | { | ||
143 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | ||
143 | 144 | ||
144 | return ok; | 145 | qDebug(msg); |
146 | delete mAccess; | ||
147 | mAccess = 0; | ||
148 | return false; | ||
145 | } | 149 | } |
146 | */ | 150 | } |
151 | |||
147 | return true; | 152 | return true; |
148 | } | 153 | } |
149 | 154 | ||
150 | void ResourceSharpDTM::doClose() | 155 | void ResourceSharpDTM::doClose() |
151 | { | 156 | { |
152 | } | 157 | qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); |
153 | 158 | ||
154 | bool ResourceSharpDTM::load() | 159 | if(mAccess) |
155 | { | 160 | { |
156 | kdDebug(5700) << "ResourcSharpDTM::load(): '" << mFileName << "'" << endl; | 161 | delete mAccess; |
157 | 162 | mAccess = 0; | |
158 | // qDebug("ResourceSharpDTM::load: Try to load file() %s", mFileName.latin1()); | 163 | } |
164 | // it seems so, that deletion of access deletes backend as well | ||
165 | //delete backend; | ||
159 | 166 | ||
160 | // the last parameter in the SlZDataBase constructor means "readonly" | 167 | return; |
161 | SlZDataBase* access = new SlZDataBase(mFileName, | ||
162 | SlZDataBase::addressbookItems(), | ||
163 | NULL, true); | ||
164 | if ( !access ) { | ||
165 | qDebug("Unable to load file() %s", mFileName.latin1()); | ||
166 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | ||
167 | return false; | ||
168 | } | 168 | } |
169 | 169 | ||
170 | bool res = false; | 170 | bool ResourceSharpDTM::load() |
171 | if (mConverter == 0) | ||
172 | { | ||
173 | mConverter = new SharpDTMConverter(); | ||
174 | res = mConverter->init(); | ||
175 | if ( !res ) | ||
176 | { | 171 | { |
177 | QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); | 172 | qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); |
178 | 173 | ||
179 | qDebug(msg); | 174 | bool res = false; |
180 | addressBook()->error( i18n( msg ) ); | ||
181 | delete access; | ||
182 | return false; | ||
183 | } | ||
184 | } | ||
185 | 175 | ||
186 | { //create a new scope | ||
187 | CardId id; | 176 | CardId id; |
188 | 177 | ||
189 | for (bool res=access->first(); res == true; res=access->next()) { | 178 | for (bool res=mAccess->first(); res == true; res=mAccess->next()) |
190 | id = access->cardId(); | 179 | { |
180 | id = mAccess->cardId(); | ||
191 | 181 | ||
192 | KABC::Addressee addressee; | 182 | KABC::Addressee addressee; |
193 | 183 | ||
194 | res = mConverter->sharpToAddressee( id, access, addressee ); | 184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
195 | 185 | ||
196 | if ( !addressee.isEmpty() && res ) | 186 | if ( !addressee.isEmpty() && res ) |
197 | { | 187 | { |
@@ -199,72 +189,60 @@ bool ResourceSharpDTM::load() | |||
199 | addressBook()->insertAddressee( addressee ); | 189 | addressBook()->insertAddressee( addressee ); |
200 | } | 190 | } |
201 | } | 191 | } |
202 | } | ||
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() ) | ||
225 | { | 210 | { |
226 | mFormat->saveAll( addressBook(), this, saveFile.file() ); | 211 | res = mConverter->addresseeToSharp( *it, mAccess, id ); |
227 | ok = saveFile.close(); | 212 | if (res == true) |
213 | { | ||
214 | res = mAccess->finishEditCard(&id); | ||
215 | if (res == false) | ||
216 | qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); | ||
228 | } | 217 | } |
229 | */ | 218 | else |
230 | 219 | { | |
231 | /*US | 220 | qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); |
232 | //US ToDo: write backupfile | 221 | mAccess->cancelEditCard(); |
233 | QFile info; | 222 | } |
234 | info.setName( mFileName ); | 223 | } |
235 | bool ok = info.open( IO_WriteOnly ); | 224 | else |
236 | if ( ok ) { | 225 | { |
237 | //US mFormat->saveAll( addressBook(), this, &info ); | 226 | qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); |
238 | |||
239 | info.close(); | ||
240 | ok = true; | ||
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" ); |
@@ -287,9 +265,11 @@ bool ResourceSharpDTM::lock( const QString &fileName ) | |||
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; |
@@ -302,11 +282,9 @@ bool ResourceSharpDTM::lock( const QString &fileName ) | |||
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 | ||
@@ -315,23 +293,18 @@ void ResourceSharpDTM::unlock( const QString &fileName ) | |||
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 |
@@ -339,7 +312,7 @@ void ResourceSharpDTM::fileChanged() | |||
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(); |
@@ -352,7 +325,7 @@ void ResourceSharpDTM::removeAddressee( const Addressee &addr ) | |||
352 | 325 | ||
353 | void ResourceSharpDTM::cleanUp() | 326 | void ResourceSharpDTM::cleanUp() |
354 | { | 327 | { |
355 | unlock( mFileName ); | 328 | unlock( fileName() ); |
356 | } | 329 | } |
357 | 330 | ||
358 | /** | 331 | /** |
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 | |||
@@ -37,6 +37,8 @@ $Id$ | |||
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; |
@@ -141,6 +143,7 @@ protected: | |||
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; |