author | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-02 18:32:08 (UTC) |
commit | 863c4c3678e59ef125c08c00e9532ded5b540f67 (patch) (unidiff) | |
tree | 449428c45689ffe10ff1ce4caa18f959c4dfe402 /kabc/plugins/qtopia | |
parent | 983127ce46c9ff6663d08dedd450da3fe7dd549b (diff) | |
download | kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.zip kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.gz kdepimpi-863c4c3678e59ef125c08c00e9532ded5b540f67.tar.bz2 |
added support for syncprofiles for resources and export/import capabilities
-rw-r--r-- | kabc/plugins/qtopia/qtopiaE.pro | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 166 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.h | 31 |
3 files changed, 115 insertions, 84 deletions
diff --git a/kabc/plugins/qtopia/qtopiaE.pro b/kabc/plugins/qtopia/qtopiaE.pro index 56eae87..d956519 100644 --- a/kabc/plugins/qtopia/qtopiaE.pro +++ b/kabc/plugins/qtopia/qtopiaE.pro | |||
@@ -3,7 +3,7 @@ CONFIG += qt warn_on | |||
3 | 3 | ||
4 | TARGET = microkabc_qtopia | 4 | TARGET = microkabc_qtopia |
5 | 5 | ||
6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include | 6 | INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include |
7 | 7 | ||
8 | OBJECTS_DIR = obj/$(PLATFORM) | 8 | OBJECTS_DIR = obj/$(PLATFORM) |
9 | MOC_DIR = moc/$(PLATFORM) | 9 | MOC_DIR = moc/$(PLATFORM) |
diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 7e10e46..dc88272 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp | |||
@@ -49,6 +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 | 53 | ||
53 | #include "resourceqtopia.h" | 54 | #include "resourceqtopia.h" |
54 | 55 | ||
@@ -57,12 +58,12 @@ extern "C" | |||
57 | { | 58 | { |
58 | void *init_microkabc_qtopia() | 59 | void *init_microkabc_qtopia() |
59 | { | 60 | { |
60 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); | 61 | return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, KRES::SyncWidget>(); |
61 | } | 62 | } |
62 | } | 63 | } |
63 | 64 | ||
64 | ResourceQtopia::ResourceQtopia( const KConfig *config ) | 65 | ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) |
65 | : Resource( config ), mConverter (0) | 66 | : Resource( config, syncable ), mConverter (0) |
66 | { | 67 | { |
67 | // 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 |
68 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; | 69 | QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; |
@@ -70,8 +71,8 @@ ResourceQtopia::ResourceQtopia( const KConfig *config ) | |||
70 | init( fileName ); | 71 | init( fileName ); |
71 | } | 72 | } |
72 | 73 | ||
73 | ResourceQtopia::ResourceQtopia( const QString &fileName ) | 74 | ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) |
74 | : Resource( 0 ) | 75 | : Resource( 0, syncable ) |
75 | { | 76 | { |
76 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); | 77 | // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); |
77 | init( fileName ); | 78 | init( fileName ); |
@@ -92,6 +93,8 @@ ResourceQtopia::~ResourceQtopia() | |||
92 | if (mConverter != 0) | 93 | if (mConverter != 0) |
93 | delete mConverter; | 94 | delete mConverter; |
94 | 95 | ||
96 | if(mAccess != 0) | ||
97 | delete mAccess; | ||
95 | } | 98 | } |
96 | 99 | ||
97 | void ResourceQtopia::writeConfig( KConfig *config ) | 100 | void ResourceQtopia::writeConfig( KConfig *config ) |
@@ -105,9 +108,9 @@ Ticket *ResourceQtopia::requestSaveTicket() | |||
105 | 108 | ||
106 | if ( !addressBook() ) return 0; | 109 | if ( !addressBook() ) return 0; |
107 | 110 | ||
108 | if ( !lock( mFileName ) ) { | 111 | if ( !lock( fileName() ) ) { |
109 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" | 112 | kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" |
110 | << mFileName << "'" << endl; | 113 | << fileName() << "'" << endl; |
111 | return 0; | 114 | return 0; |
112 | } | 115 | } |
113 | return createTicket( this ); | 116 | return createTicket( this ); |
@@ -116,51 +119,12 @@ Ticket *ResourceQtopia::requestSaveTicket() | |||
116 | 119 | ||
117 | bool ResourceQtopia::doOpen() | 120 | bool ResourceQtopia::doOpen() |
118 | { | 121 | { |
119 | /*US | 122 | qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); |
120 | QFile file( mFileName ); | ||
121 | 123 | ||
122 | if ( !file.exists() ) { | 124 | mAccess = new AddressBookAccess(); |
123 | // try to create the file | ||
124 | bool ok = file.open( IO_WriteOnly ); | ||
125 | if ( ok ) | ||
126 | file.close(); | ||
127 | 125 | ||
128 | return ok; | 126 | if ( !mAccess ) { |
129 | } else { | 127 | qDebug("Unable to load file() %s", fileName().latin1()); |
130 | if ( !file.open( IO_ReadWrite ) ) | ||
131 | return false; | ||
132 | |||
133 | if ( file.size() == 0 ) { | ||
134 | file.close(); | ||
135 | return true; | ||
136 | } | ||
137 | |||
138 | //US bool ok = mFormat->checkFormat( &file ); | ||
139 | bool ok = true; | ||
140 | |||
141 | file.close(); | ||
142 | |||
143 | return ok; | ||
144 | } | ||
145 | */ | ||
146 | return true; | ||
147 | } | ||
148 | |||
149 | void ResourceQtopia::doClose() | ||
150 | { | ||
151 | } | ||
152 | |||
153 | bool ResourceQtopia::load() | ||
154 | { | ||
155 | kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl; | ||
156 | |||
157 | // qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1()); | ||
158 | |||
159 | AddressBookAccess* access = new AddressBookAccess(); | ||
160 | |||
161 | if ( !access ) { | ||
162 | qDebug("Unable to load file() %s", mFileName.latin1()); | ||
163 | addressBook()->error( i18n( "Unable to load file '%1'." ).arg( mFileName ) ); | ||
164 | return false; | 128 | return false; |
165 | } | 129 | } |
166 | 130 | ||
@@ -173,17 +137,40 @@ bool ResourceQtopia::load() | |||
173 | { | 137 | { |
174 | 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"); |
175 | qDebug(msg); | 139 | qDebug(msg); |
176 | addressBook()->error( i18n( msg ) ); | 140 | delete mAccess; |
177 | delete access; | 141 | mAccess = 0; |
178 | return false; | 142 | return false; |
179 | } | 143 | } |
180 | } | 144 | } |
181 | 145 | ||
182 | { //create a new scope | 146 | return true; |
183 | AddressBookIterator it(*access); | 147 | } |
148 | |||
149 | void ResourceQtopia::doClose() | ||
150 | { | ||
151 | qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); | ||
152 | |||
153 | if(mAccess) | ||
154 | { | ||
155 | delete mAccess; | ||
156 | mAccess = 0; | ||
157 | } | ||
158 | // it seems so, that deletion of access deletes backend as well | ||
159 | //delete backend; | ||
160 | |||
161 | return; | ||
162 | } | ||
163 | |||
164 | bool ResourceQtopia::load() | ||
165 | { | ||
166 | qDebug("ResourceQtopia::load: %s", fileName().latin1()); | ||
167 | |||
168 | AddressBookIterator it(*mAccess); | ||
184 | const PimContact* contact; | 169 | const PimContact* contact; |
170 | bool res; | ||
185 | 171 | ||
186 | for (contact=it.toFirst(); it.current(); ++it) { | 172 | for (contact=it.toFirst(); it.current(); ++it) |
173 | { | ||
187 | contact = it.current(); | 174 | contact = it.current(); |
188 | 175 | ||
189 | KABC::Addressee addressee; | 176 | KABC::Addressee addressee; |
@@ -196,9 +183,7 @@ bool ResourceQtopia::load() | |||
196 | addressBook()->insertAddressee( addressee ); | 183 | addressBook()->insertAddressee( addressee ); |
197 | } | 184 | } |
198 | } | 185 | } |
199 | } | ||
200 | 186 | ||
201 | delete access; | ||
202 | return true; | 187 | return true; |
203 | } | 188 | } |
204 | 189 | ||
@@ -249,7 +234,12 @@ bool ResourceQtopia::save( Ticket *ticket ) | |||
249 | return ok; | 234 | return ok; |
250 | 235 | ||
251 | qDebug("ResourceQtopia::save has to be changed"); | 236 | qDebug("ResourceQtopia::save has to be changed"); |
237 | |||
238 | |||
239 | access->save(); | ||
240 | |||
252 | */ | 241 | */ |
242 | |||
253 | return true; | 243 | return true; |
254 | } | 244 | } |
255 | 245 | ||
@@ -312,24 +302,17 @@ void ResourceQtopia::unlock( const QString &fileName ) | |||
312 | addressBook()->emitAddressBookUnlocked(); | 302 | addressBook()->emitAddressBookUnlocked(); |
313 | } | 303 | } |
314 | 304 | ||
315 | void ResourceQtopia::setFileName( const QString &fileName ) | 305 | void ResourceQtopia::setFileName( const QString &newFileName ) |
316 | { | 306 | { |
317 | mDirWatch.stopScan(); | 307 | mDirWatch.stopScan(); |
318 | mDirWatch.removeFile( mFileName ); | 308 | mDirWatch.removeFile( fileName() ); |
319 | 309 | ||
320 | mFileName = fileName; | 310 | Resource::setFileName( newFileName ); |
321 | 311 | ||
322 | mDirWatch.addFile( mFileName ); | 312 | mDirWatch.addFile( fileName() ); |
323 | mDirWatch.startScan(); | 313 | mDirWatch.startScan(); |
324 | |||
325 | //US simulate KDirWatch event | ||
326 | //US fileChanged(); | ||
327 | } | 314 | } |
328 | 315 | ||
329 | QString ResourceQtopia::fileName() const | ||
330 | { | ||
331 | return mFileName; | ||
332 | } | ||
333 | 316 | ||
334 | void ResourceQtopia::fileChanged() | 317 | void ResourceQtopia::fileChanged() |
335 | { | 318 | { |
@@ -338,7 +321,7 @@ void ResourceQtopia::fileChanged() | |||
338 | if (!addressBook()) | 321 | if (!addressBook()) |
339 | return; | 322 | return; |
340 | 323 | ||
341 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); | 324 | QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); |
342 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { | 325 | if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { |
343 | load(); | 326 | load(); |
344 | addressBook()->emitAddressBookChanged(); | 327 | addressBook()->emitAddressBookChanged(); |
@@ -351,7 +334,50 @@ void ResourceQtopia::removeAddressee( const Addressee &addr ) | |||
351 | 334 | ||
352 | void ResourceQtopia::cleanUp() | 335 | void ResourceQtopia::cleanUp() |
353 | { | 336 | { |
354 | unlock( mFileName ); | 337 | unlock( fileName() ); |
338 | } | ||
339 | |||
340 | |||
341 | |||
342 | /** | ||
343 | * This method returns the number of elements that are currently in the resource. | ||
344 | */ | ||
345 | int ResourceQtopia::count() const | ||
346 | { | ||
347 | if (mAccess != 0) | ||
348 | { | ||
349 | int counter = 0; | ||
350 | AddressBookIterator it2(*mAccess); | ||
351 | for (it2.toFirst(); it2.current(); ++it2) { | ||
352 | counter++; | ||
353 | } | ||
354 | |||
355 | return counter; | ||
356 | } | ||
357 | else | ||
358 | return 0; | ||
355 | } | 359 | } |
356 | 360 | ||
361 | |||
362 | /** | ||
363 | * This method removes all elements from the resource!! (Not from the addressbook) | ||
364 | */ | ||
365 | bool ResourceQtopia::clear() | ||
366 | { | ||
367 | if (mAccess != 0) | ||
368 | { | ||
369 | AddressBookIterator it2(*mAccess); | ||
370 | for (it2.toFirst(); it2.current(); ++it2) { | ||
371 | mAccess->removeContact(*it2.current()); | ||
372 | } | ||
373 | return true; | ||
374 | } | ||
375 | else | ||
376 | return false; | ||
377 | } | ||
378 | |||
379 | |||
380 | |||
381 | |||
382 | |||
357 | //US #include "resourceqtopia.moc" | 383 | //US #include "resourceqtopia.moc" |
diff --git a/kabc/plugins/qtopia/resourceqtopia.h b/kabc/plugins/qtopia/resourceqtopia.h index bf9dd45..90ab1f4 100644 --- a/kabc/plugins/qtopia/resourceqtopia.h +++ b/kabc/plugins/qtopia/resourceqtopia.h | |||
@@ -36,6 +36,7 @@ $Id$ | |||
36 | 36 | ||
37 | #include "resource.h" | 37 | #include "resource.h" |
38 | 38 | ||
39 | class AddressBookAccess; | ||
39 | 40 | ||
40 | namespace KABC { | 41 | namespace KABC { |
41 | 42 | ||
@@ -57,12 +58,12 @@ public: | |||
57 | 58 | ||
58 | @param cfg The config object where custom resource settings are stored. | 59 | @param cfg The config object where custom resource settings are stored. |
59 | */ | 60 | */ |
60 | ResourceQtopia( const KConfig *cfg ); | 61 | ResourceQtopia( const KConfig *cfg, bool syncable ); |
61 | 62 | ||
62 | /** | 63 | /** |
63 | Construct file resource on file @arg fileName using format @arg formatName. | 64 | Construct file resource on file @arg fileName using format @arg formatName. |
64 | */ | 65 | */ |
65 | ResourceQtopia( const QString &fileName ); | 66 | ResourceQtopia( const QString &fileName, bool syncable ); |
66 | 67 | ||
67 | /** | 68 | /** |
68 | * Destructor. | 69 | * Destructor. |
@@ -105,26 +106,31 @@ public: | |||
105 | virtual bool save( Ticket *ticket ); | 106 | virtual bool save( Ticket *ticket ); |
106 | 107 | ||
107 | /** | 108 | /** |
109 | * Remove a addressee from its source. | ||
110 | * This method is mainly called by KABC::AddressBook. | ||
111 | */ | ||
112 | virtual void removeAddressee( const Addressee& addr ); | ||
113 | |||
114 | /** | ||
108 | * Set name of file to be used for saving. | 115 | * Set name of file to be used for saving. |
109 | */ | 116 | */ |
110 | void setFileName( const QString & ); | 117 | virtual void setFileName( const QString & ); |
111 | 118 | ||
112 | /** | 119 | /** |
113 | * Return name of file used for loading and saving the address book. | 120 | * This method is called by an error handler if the application |
121 | * crashed | ||
114 | */ | 122 | */ |
115 | QString fileName() const; | 123 | virtual void cleanUp(); |
116 | 124 | ||
117 | /** | 125 | /** |
118 | * Remove a addressee from its source. | 126 | * This method returns the number of elements that are currently in the resource. |
119 | * This method is mainly called by KABC::AddressBook. | ||
120 | */ | 127 | */ |
121 | virtual void removeAddressee( const Addressee& addr ); | 128 | virtual int count() const; |
122 | 129 | ||
123 | /** | 130 | /** |
124 | * This method is called by an error handler if the application | 131 | * This method removes all elements from the resource!! (Not from the addressbook) |
125 | * crashed | ||
126 | */ | 132 | */ |
127 | virtual void cleanUp(); | 133 | virtual bool clear(); |
128 | 134 | ||
129 | protected slots: | 135 | protected slots: |
130 | void fileChanged(); | 136 | void fileChanged(); |
@@ -136,10 +142,9 @@ protected: | |||
136 | void unlock( const QString &fileName ); | 142 | void unlock( const QString &fileName ); |
137 | 143 | ||
138 | private: | 144 | private: |
145 | AddressBookAccess* mAccess; | ||
139 | QtopiaConverter* mConverter; | 146 | QtopiaConverter* mConverter; |
140 | 147 | ||
141 | QString mFileName; | ||
142 | |||
143 | QString mLockUniqueName; | 148 | QString mLockUniqueName; |
144 | 149 | ||
145 | KDirWatch mDirWatch; | 150 | KDirWatch mDirWatch; |