summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/qtopia
Unidiff
Diffstat (limited to 'kabc/plugins/qtopia') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/qtopia/qtopiaE.pro2
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.cpp182
-rw-r--r--kabc/plugins/qtopia/resourceqtopia.h35
3 files changed, 125 insertions, 94 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
@@ -5,3 +5,3 @@ TARGET = microkabc_qtopia
5 5
6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../qtcompat $(QPEDIR)/include 6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat $(QPEDIR)/include
7 7
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
@@ -51,2 +51,3 @@ $Id$
51#include "qtopiaconverter.h" 51#include "qtopiaconverter.h"
52#include "syncwidget.h"
52 53
@@ -59,3 +60,3 @@ extern "C"
59 { 60 {
60 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig>(); 61 return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, KRES::SyncWidget>();
61 } 62 }
@@ -63,4 +64,4 @@ extern "C"
63 64
64ResourceQtopia::ResourceQtopia( const KConfig *config ) 65ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable )
65 : Resource( config ), mConverter (0) 66 : Resource( config, syncable ), mConverter (0)
66{ 67{
@@ -72,4 +73,4 @@ ResourceQtopia::ResourceQtopia( const KConfig *config )
72 73
73ResourceQtopia::ResourceQtopia( const QString &fileName ) 74ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable )
74 : Resource( 0 ) 75 : Resource( 0, syncable )
75{ 76{
@@ -94,2 +95,4 @@ ResourceQtopia::~ResourceQtopia()
94 95
96 if(mAccess != 0)
97 delete mAccess;
95} 98}
@@ -107,5 +110,5 @@ Ticket *ResourceQtopia::requestSaveTicket()
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;
@@ -118,47 +121,8 @@ bool ResourceQtopia::doOpen()
118{ 121{
119/*US 122 qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1());
120 QFile file( mFileName );
121
122 if ( !file.exists() ) {
123 // try to create the file
124 bool ok = file.open( IO_WriteOnly );
125 if ( ok )
126 file.close();
127
128 return ok;
129 } else {
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
149void ResourceQtopia::doClose()
150{
151}
152 123
153bool ResourceQtopia::load() 124 mAccess = new AddressBookAccess();
154{
155 kdDebug(5700) << "ResourceQtopia::load(): '" << mFileName << "'" << endl;
156
157// qDebug("ResourceQtopia::load: Try to load file() %s", mFileName.latin1());
158 125
159 AddressBookAccess* access = new AddressBookAccess(); 126 if ( !mAccess ) {
160 127 qDebug("Unable to load file() %s", fileName().latin1());
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;
@@ -175,4 +139,4 @@ bool ResourceQtopia::load()
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;
@@ -181,18 +145,40 @@ bool ResourceQtopia::load()
181 145
182 { //create a new scope 146 return true;
183 AddressBookIterator it(*access); 147}
184 const PimContact* contact;
185 148
186 for (contact=it.toFirst(); it.current(); ++it) { 149void ResourceQtopia::doClose()
187 contact = it.current(); 150{
151 qDebug("ResourceQtopia::doClose: %s", fileName().latin1());
188 152
189 KABC::Addressee addressee; 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
164bool ResourceQtopia::load()
165{
166 qDebug("ResourceQtopia::load: %s", fileName().latin1());
190 167
191 res = mConverter->qtopiaToAddressee( (*contact), addressee ); 168 AddressBookIterator it(*mAccess);
169 const PimContact* contact;
170 bool res;
171
172 for (contact=it.toFirst(); it.current(); ++it)
173 {
174 contact = it.current();
192 175
193 if ( !addressee.isEmpty() && res ) 176 KABC::Addressee addressee;
194 { 177
195 addressee.setResource( this ); 178 res = mConverter->qtopiaToAddressee( (*contact), addressee );
196 addressBook()->insertAddressee( addressee ); 179
197 } 180 if ( !addressee.isEmpty() && res )
181 {
182 addressee.setResource( this );
183 addressBook()->insertAddressee( addressee );
198 } 184 }
@@ -200,3 +186,2 @@ bool ResourceQtopia::load()
200 186
201 delete access;
202 return true; 187 return true;
@@ -251,3 +236,8 @@ bool ResourceQtopia::save( Ticket *ticket )
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;
@@ -314,20 +304,13 @@ void ResourceQtopia::unlock( const QString &fileName )
314 304
315void ResourceQtopia::setFileName( const QString &fileName ) 305void 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
329QString ResourceQtopia::fileName() const
330{
331 return mFileName;
332}
333 316
@@ -340,3 +323,3 @@ void ResourceQtopia::fileChanged()
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 ) {
@@ -353,5 +336,48 @@ void ResourceQtopia::cleanUp()
353{ 336{
354 unlock( mFileName ); 337 unlock( fileName() );
355} 338}
356 339
340
341
342/**
343 * This method returns the number of elements that are currently in the resource.
344 */
345int 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;
359}
360
361
362/**
363 * This method removes all elements from the resource!! (Not from the addressbook)
364 */
365bool 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
@@ -38,2 +38,3 @@ $Id$
38 38
39class AddressBookAccess;
39 40
@@ -59,3 +60,3 @@ public:
59 */ 60 */
60 ResourceQtopia( const KConfig *cfg ); 61 ResourceQtopia( const KConfig *cfg, bool syncable );
61 62
@@ -64,3 +65,3 @@ public:
64 */ 65 */
65 ResourceQtopia( const QString &fileName ); 66 ResourceQtopia( const QString &fileName, bool syncable );
66 67
@@ -86,3 +87,3 @@ public:
86 virtual void doClose(); 87 virtual void doClose();
87 88
88 /** 89 /**
@@ -107,22 +108,27 @@ public:
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
@@ -138,8 +144,7 @@ protected:
138private: 144private:
145 AddressBookAccess* mAccess;
139 QtopiaConverter* mConverter; 146 QtopiaConverter* mConverter;
140
141 QString mFileName;
142 147
143 QString mLockUniqueName; 148 QString mLockUniqueName;
144 149
145 KDirWatch mDirWatch; 150 KDirWatch mDirWatch;