-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 205 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.h | 3 |
2 files changed, 92 insertions, 116 deletions
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 | |||
@@ -51,2 +51,4 @@ $Id$ | |||
51 | 51 | ||
52 | #include "syncprefwidget.h" | ||
53 | |||
52 | #include "stdaddressbook.h" | 54 | #include "stdaddressbook.h" |
@@ -60,3 +62,3 @@ extern "C" | |||
60 | { | 62 | { |
61 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig>(); | 63 | return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>(); |
62 | } | 64 | } |
@@ -76,3 +78,2 @@ ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) | |||
76 | { | 78 | { |
77 | // qDebug("ResourceFile::ResourceSharpDTM : 3 %s, %s", fileName.latin1(), formatName.latin1()); | ||
78 | init( fileName ); | 79 | init( fileName ); |
@@ -92,5 +93,7 @@ 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 | } |
@@ -104,3 +107,5 @@ 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 | ||
@@ -108,5 +113,5 @@ Ticket *ResourceSharpDTM::requestSaveTicket() | |||
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; |
@@ -119,29 +124,29 @@ 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; |
@@ -151,41 +156,26 @@ 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 | ||
@@ -193,3 +183,3 @@ bool ResourceSharpDTM::load() | |||
193 | 183 | ||
194 | res = mConverter->sharpToAddressee( id, access, addressee ); | 184 | res = mConverter->sharpToAddressee( id, mAccess, addressee ); |
195 | 185 | ||
@@ -201,5 +191,3 @@ bool ResourceSharpDTM::load() | |||
201 | } | 191 | } |
202 | } | ||
203 | 192 | ||
204 | delete access; | ||
205 | return true; | 193 | return true; |
@@ -209,35 +197,32 @@ 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 | ||
@@ -245,12 +230,7 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
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; |
@@ -258,11 +238,9 @@ bool ResourceSharpDTM::save( Ticket *ticket ) | |||
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 | ||
@@ -289,5 +267,7 @@ bool ResourceSharpDTM::lock( const QString &fileName ) | |||
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 ) { |
@@ -304,7 +284,5 @@ 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); |
@@ -317,10 +295,10 @@ void ResourceSharpDTM::unlock( const QString &fileName ) | |||
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(); |
@@ -329,7 +307,2 @@ void ResourceSharpDTM::setFileName( const QString &fileName ) | |||
329 | 307 | ||
330 | QString ResourceSharpDTM::fileName() const | ||
331 | { | ||
332 | return mFileName; | ||
333 | } | ||
334 | |||
335 | void ResourceSharpDTM::fileChanged() | 308 | void ResourceSharpDTM::fileChanged() |
@@ -341,3 +314,3 @@ void ResourceSharpDTM::fileChanged() | |||
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 ) { |
@@ -354,3 +327,3 @@ void ResourceSharpDTM::cleanUp() | |||
354 | { | 327 | { |
355 | unlock( mFileName ); | 328 | unlock( fileName() ); |
356 | } | 329 | } |
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 | |||
@@ -39,2 +39,4 @@ $Id$ | |||
39 | 39 | ||
40 | class SlZDataBase; | ||
41 | |||
40 | namespace KABC { | 42 | namespace KABC { |
@@ -143,2 +145,3 @@ protected: | |||
143 | private: | 145 | private: |
146 | SlZDataBase* mAccess; | ||
144 | SharpDTMConverter* mConverter; | 147 | SharpDTMConverter* mConverter; |