summaryrefslogtreecommitdiffabout
path: root/kabc
authorzautrix <zautrix>2005-04-04 11:29:55 (UTC)
committer zautrix <zautrix>2005-04-04 11:29:55 (UTC)
commit23db4aa99cb7a5feb540b6be578efaee8ec6ef80 (patch) (unidiff)
treef60d08e53dc09cf8a9ca901697797de9cf5dc669 /kabc
parent69a388bdef8d4a31063f983735d2b7d25775f3cf (diff)
downloadkdepimpi-23db4aa99cb7a5feb540b6be578efaee8ec6ef80.zip
kdepimpi-23db4aa99cb7a5feb540b6be578efaee8ec6ef80.tar.gz
kdepimpi-23db4aa99cb7a5feb540b6be578efaee8ec6ef80.tar.bz2
sync fixes
Diffstat (limited to 'kabc') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/resourcefile.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index af76558..2bd9e71 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,433 +1,433 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> 3 Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
4 4
5 This library is free software; you can redistribute it and/or 5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public 6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either 7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version. 8 version 2 of the License, or (at your option) any later version.
9 9
10 This library is distributed in the hope that it will be useful, 10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details. 13 Library General Public License for more details.
14 14
15 You should have received a copy of the GNU Library General Public License 15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to 16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/* 21/*
22Enhanced Version of the file for platform independent KDE tools. 22Enhanced Version of the file for platform independent KDE tools.
23Copyright (c) 2004 Ulf Schenk 23Copyright (c) 2004 Ulf Schenk
24 24
25$Id$ 25$Id$
26*/ 26*/
27 27
28#include <sys/types.h> 28#include <sys/types.h>
29#include <sys/stat.h> 29#include <sys/stat.h>
30#ifndef _WIN32_ 30#ifndef _WIN32_
31#include <unistd.h> 31#include <unistd.h>
32#endif 32#endif
33 33
34#include <qfile.h> 34#include <qfile.h>
35#include <qfileinfo.h> 35#include <qfileinfo.h>
36#include <qregexp.h> 36#include <qregexp.h>
37#include <qtimer.h> 37#include <qtimer.h>
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#define NO_DIRWATCH 52#define NO_DIRWATCH
53#include "resourcefile.h" 53#include "resourcefile.h"
54 54
55//#define ALLOW_LOCKING 55//#define ALLOW_LOCKING
56 56
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60extern "C" 60extern "C"
61#ifdef _WIN32_ 61#ifdef _WIN32_
62__declspec(dllexport) 62__declspec(dllexport)
63#else 63#else
64{ 64{
65#endif 65#endif
66 66
67//US void *init_kabc_file() 67//US void *init_kabc_file()
68 void *init_microkabc_file() 68 void *init_microkabc_file()
69 { 69 {
70 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); 70 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
71 } 71 }
72#ifndef _WIN32_ 72#ifndef _WIN32_
73} 73}
74#endif 74#endif
75 75
76ResourceFile::ResourceFile( const KConfig *config ) 76ResourceFile::ResourceFile( const KConfig *config )
77 : Resource( config ) , mFormat( 0 ) 77 : Resource( config ) , mFormat( 0 )
78{ 78{
79 QString fileName, formatName, default_fileName; 79 QString fileName, formatName, default_fileName;
80 80
81 default_fileName = StdAddressBook::fileName(); 81 default_fileName = StdAddressBook::fileName();
82 82
83 KConfig *cfg = (KConfig *)config; 83 KConfig *cfg = (KConfig *)config;
84 if ( cfg ) { 84 if ( cfg ) {
85 fileName = cfg->readEntry( "FileName", default_fileName ); 85 fileName = cfg->readEntry( "FileName", default_fileName );
86 formatName = cfg->readEntry( "FileFormat", "vcard" ); 86 formatName = cfg->readEntry( "FileFormat", "vcard" );
87 mFamily = cfg->readEntry( "ResourceName", "std" ); 87 mFamily = cfg->readEntry( "ResourceName", "std" );
88 } else { 88 } else {
89 fileName = default_fileName; 89 fileName = default_fileName;
90 formatName = "vcard"; 90 formatName = "vcard";
91 } 91 }
92 92
93 init( fileName, formatName ); 93 init( fileName, formatName );
94} 94}
95 95
96ResourceFile::ResourceFile( const QString &fileName , 96ResourceFile::ResourceFile( const QString &fileName ,
97 const QString &formatName ) 97 const QString &formatName )
98 : Resource( 0 ) 98 : Resource( 0 )
99{ 99{
100// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 100// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
101 101
102 102
103 103
104 init( fileName, formatName ); 104 init( fileName, formatName );
105} 105}
106 106
107void ResourceFile::init( const QString &fileName, const QString &formatName ) 107void ResourceFile::init( const QString &fileName, const QString &formatName )
108{ 108{
109 mFormatName = formatName; 109 mFormatName = formatName;
110 110
111 FormatFactory *factory = FormatFactory::self(); 111 FormatFactory *factory = FormatFactory::self();
112 mFormat = factory->format( mFormatName ); 112 mFormat = factory->format( mFormatName );
113 113
114 if ( !mFormat ) { 114 if ( !mFormat ) {
115 mFormatName = "vcard"; 115 mFormatName = "vcard";
116 mFormat = factory->format( mFormatName ); 116 mFormat = factory->format( mFormatName );
117 } 117 }
118 118
119#ifndef NO_DIRWATCH 119#ifndef NO_DIRWATCH
120 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 120 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
121 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 121 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
122 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 122 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
123#endif 123#endif
124 124
125 QString localKdeDir; 125 QString localKdeDir;
126 localKdeDir = readEnvPath("LOCALMICROKDEHOME"); 126 localKdeDir = readEnvPath("LOCALMICROKDEHOME");
127 if ( ! localKdeDir.isEmpty() ) { 127 if ( ! localKdeDir.isEmpty() ) {
128 qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() ); 128 qDebug("LOCALMICROKDEHOME is set to: %s",localKdeDir.latin1() );
129 QFileInfo fi ( fileName ); 129 QFileInfo fi ( fileName );
130 QString localname = localKdeDir + "/apps/kabc/" + fi.fileName (); 130 QString localname = localKdeDir + "/apps/kabc/" + fi.fileName ();
131 QFileInfo fi2 ( localname ); 131 QFileInfo fi2 ( localname );
132 if ( ! fi2.exists() || mFamily == "sync_res" ) { 132 if ( ! fi2.exists() || mFamily == "sync_res" ) {
133 if ( fi.exists() && mFamily == "sync_res") { 133 if ( fi.exists() && mFamily == "sync_res") {
134 qDebug("LOCAL mode SYNC mode using absolute file path "); 134 qDebug("LOCAL mode SYNC mode using absolute file path ");
135 setFileName( fileName ); 135 setFileName( fileName );
136 return; 136 return;
137 } else { 137 } else {
138 KMessageBox::error(0,i18n("Addressbook resource file not found:\n '%1'.\nIn LOCAL mode only resource files in\n'%2'\nare supported.\n(i.e. in the dir ./apps/kabc/ relative to the kapi(.exe) binary.)\n\nIf you are starting KA/Pi for the very first time\nyou will get this error message as well.\nIt will create the missing file automatically for you.").arg(localname).arg(localKdeDir+"/apps/kabc/") ); 138 KMessageBox::error(0,i18n("Addressbook resource file not found:\n '%1'.\nIn LOCAL mode only resource files in\n'%2'\nare supported.\n(i.e. in the dir ./apps/kabc/ relative to the kapi(.exe) binary.)\n\nIf you are starting KA/Pi for the very first time\nyou will get this error message as well.\nIt will create the missing file automatically for you.").arg(localname).arg(localKdeDir+"/apps/kabc/") );
139 setFileName( localname ); 139 setFileName( localname );
140 return; 140 return;
141 } 141 }
142 142
143 } else { 143 } else {
144 qDebug("Local resource file found. Changing filename to: %s",localname.latin1() ); 144 qDebug("Local resource file found. Changing filename to: %s",localname.latin1() );
145 setFileName( localname ); 145 setFileName( localname );
146 return; 146 return;
147 } 147 }
148 148
149 } 149 }
150 setFileName( fileName ); 150 setFileName( fileName );
151} 151}
152 152
153ResourceFile::~ResourceFile() 153ResourceFile::~ResourceFile()
154{ 154{
155 delete mFormat; 155 delete mFormat;
156 mFormat = 0; 156 mFormat = 0;
157} 157}
158 158
159void ResourceFile::writeConfig( KConfig *config ) 159void ResourceFile::writeConfig( KConfig *config )
160{ 160{
161 161
162 config->setGroup( "Resource_" + identifier() ); 162 config->setGroup( "Resource_" + identifier() );
163 Resource::writeConfig( config ); 163 Resource::writeConfig( config );
164 164
165 config->writeEntry( "FileName", fileName() ); 165 config->writeEntry( "FileName", fileName() );
166 config->writeEntry( "FileFormat", mFormatName ); 166 config->writeEntry( "FileFormat", mFormatName );
167 167
168// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 168// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
169 169
170} 170}
171 171
172Ticket *ResourceFile::requestSaveTicket() 172Ticket *ResourceFile::requestSaveTicket()
173{ 173{
174 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 174 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
175 175
176 if ( !addressBook() ) return 0; 176 if ( !addressBook() ) return 0;
177 177
178#ifdef ALLOW_LOCKING 178#ifdef ALLOW_LOCKING
179 if ( !lock( mFileName ) ) { 179 if ( !lock( mFileName ) ) {
180 qDebug("unablt to lock file "); 180 qDebug("unablt to lock file ");
181 return 0; 181 return 0;
182 } 182 }
183#endif 183#endif
184 return createTicket( this ); 184 return createTicket( this );
185} 185}
186 186
187 187
188bool ResourceFile::doOpen() 188bool ResourceFile::doOpen()
189{ 189{
190 QFile file( fileName() ); 190 QFile file( fileName() );
191 qDebug("ResourceFile::openfile %s ", fileName().latin1()); 191 qDebug("ResourceFile::openfile %s ", fileName().latin1());
192 192
193 if ( !file.exists() ) { 193 if ( !file.exists() ) {
194 // try to create the file 194 // try to create the file
195 bool ok = file.open( IO_WriteOnly ); 195 bool ok = file.open( IO_WriteOnly );
196 if ( ok ) 196 if ( ok )
197 file.close(); 197 file.close();
198 198
199 return ok; 199 return ok;
200 } else { 200 } else {
201 if ( !file.open( IO_ReadWrite ) ) 201 if ( !file.open( IO_ReadWrite ) )
202 return false; 202 return false;
203 203
204 if ( file.size() == 0 ) { 204 if ( file.size() < 10 ) {
205 file.close(); 205 file.close();
206 return true; 206 return true;
207 } 207 }
208 208
209 bool ok = mFormat->checkFormat( &file ); 209 bool ok = mFormat->checkFormat( &file );
210 file.close(); 210 file.close();
211 211
212 return ok; 212 return ok;
213 } 213 }
214} 214}
215 215
216void ResourceFile::doClose() 216void ResourceFile::doClose()
217{ 217{
218} 218}
219 219
220bool ResourceFile::load() 220bool ResourceFile::load()
221{ 221{
222 222
223 QFile file( fileName() ); 223 QFile file( fileName() );
224 if ( !file.open( IO_ReadOnly ) ) { 224 if ( !file.open( IO_ReadOnly ) ) {
225 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) ); 225 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) );
226 return false; 226 return false;
227 } 227 }
228 228
229// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 229// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
230 230
231 return mFormat->loadAll( addressBook(), this, &file ); 231 return mFormat->loadAll( addressBook(), this, &file );
232} 232}
233 233
234bool ResourceFile::save( Ticket *ticket ) 234bool ResourceFile::save( Ticket *ticket )
235{ 235{
236// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 236// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
237 237
238 238
239 // create backup file 239 // create backup file
240 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 240 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
241 241
242/*US we use a simpler method to create a backupfile 242/*US we use a simpler method to create a backupfile
243 243
244 (void) KSaveFile::backupFile( mFileName, QString::null 244 (void) KSaveFile::backupFile( mFileName, QString::null
245 ,extension ); 245 ,extension );
246 246
247 KSaveFile saveFile( mFileName ); 247 KSaveFile saveFile( mFileName );
248 bool ok = false; 248 bool ok = false;
249 if ( saveFile.status() == 0 && saveFile.file() ) 249 if ( saveFile.status() == 0 && saveFile.file() )
250 { 250 {
251 mFormat->saveAll( addressBook(), this, saveFile.file() ); 251 mFormat->saveAll( addressBook(), this, saveFile.file() );
252 ok = saveFile.close(); 252 ok = saveFile.close();
253 } 253 }
254*/ 254*/
255 255
256//US ToDo: write backupfile 256//US ToDo: write backupfile
257#ifndef NO_DIRWATCH 257#ifndef NO_DIRWATCH
258 mDirWatch.stopScan(); 258 mDirWatch.stopScan();
259#endif 259#endif
260 QFile info; 260 QFile info;
261 info.setName( fileName() ); 261 info.setName( fileName() );
262 bool ok = info.open( IO_WriteOnly ); 262 bool ok = info.open( IO_WriteOnly );
263 if ( ok ) { 263 if ( ok ) {
264 mFormat->saveAll( addressBook(), this, &info ); 264 mFormat->saveAll( addressBook(), this, &info );
265 265
266 info.close(); 266 info.close();
267 ok = true; 267 ok = true;
268 } 268 }
269 else { 269 else {
270 270
271 } 271 }
272 272
273 if ( !ok ) 273 if ( !ok )
274 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) ); 274 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) );
275#ifndef NO_DIRWATCH 275#ifndef NO_DIRWATCH
276 mDirWatch.startScan(); 276 mDirWatch.startScan();
277#endif 277#endif
278 delete ticket; 278 delete ticket;
279#ifdef ALLOW_LOCKING 279#ifdef ALLOW_LOCKING
280 unlock( mFileName ); 280 unlock( mFileName );
281#endif 281#endif
282 282
283 return ok; 283 return ok;
284} 284}
285 285
286bool ResourceFile::lock( const QString &fileName ) 286bool ResourceFile::lock( const QString &fileName )
287{ 287{
288#ifdef ALLOW_LOCKING 288#ifdef ALLOW_LOCKING
289 289
290 290
291 QString fn = fileName; 291 QString fn = fileName;
292 292
293//US change the implementation how the lockfilename is getting created 293//US change the implementation how the lockfilename is getting created
294//US fn.replace( QRegExp("/"), "_" ); 294//US fn.replace( QRegExp("/"), "_" );
295//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 295//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
296 296
297 KURL url(fn); 297 KURL url(fn);
298 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 298 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
299 299
300 300
301 301
302 if (QFile::exists( lockName )) return false; 302 if (QFile::exists( lockName )) return false;
303 303
304 QString lockUniqueName; 304 QString lockUniqueName;
305 lockUniqueName = fn + KApplication::randomString( 8 ); 305 lockUniqueName = fn + KApplication::randomString( 8 );
306 306
307 url = lockUniqueName; 307 url = lockUniqueName;
308//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 308//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
309 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 309 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
310 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 310 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
311 311
312 // Create unique file 312 // Create unique file
313 QFile file( mLockUniqueName ); 313 QFile file( mLockUniqueName );
314 file.open( IO_WriteOnly ); 314 file.open( IO_WriteOnly );
315 file.close(); 315 file.close();
316 316
317 // Create lock file 317 // Create lock file
318 int result = 0; 318 int result = 0;
319#ifndef _WIN32_ 319#ifndef _WIN32_
320 result = ::link( QFile::encodeName( mLockUniqueName ), 320 result = ::link( QFile::encodeName( mLockUniqueName ),
321 QFile::encodeName( lockName ) ); 321 QFile::encodeName( lockName ) );
322#endif 322#endif
323 if ( result == 0 ) { 323 if ( result == 0 ) {
324 addressBook()->emitAddressBookLocked(); 324 addressBook()->emitAddressBookLocked();
325 return true; 325 return true;
326 } 326 }
327 327
328 // TODO: check stat 328 // TODO: check stat
329 329
330 return false; 330 return false;
331#else 331#else
332 return true; 332 return true;
333#endif 333#endif
334} 334}
335 335
336void ResourceFile::unlock( const QString &fileName ) 336void ResourceFile::unlock( const QString &fileName )
337{ 337{
338#ifdef ALLOW_LOCKING 338#ifdef ALLOW_LOCKING
339 QString fn = fileName; 339 QString fn = fileName;
340//US change the implementation how the lockfilename is getting created 340//US change the implementation how the lockfilename is getting created
341//US fn.replace( QRegExp( "/" ), "_" ); 341//US fn.replace( QRegExp( "/" ), "_" );
342//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 342//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
343//US QString lockName = fn + ".lock"; 343//US QString lockName = fn + ".lock";
344 KURL url(fn); 344 KURL url(fn);
345 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 345 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
346 346
347 QFile::remove( lockName ); 347 QFile::remove( lockName );
348 QFile::remove( mLockUniqueName ); 348 QFile::remove( mLockUniqueName );
349 addressBook()->emitAddressBookUnlocked(); 349 addressBook()->emitAddressBookUnlocked();
350#else 350#else
351 return; 351 return;
352#endif 352#endif
353} 353}
354 354
355void ResourceFile::setFileName( const QString &fileName ) 355void ResourceFile::setFileName( const QString &fileName )
356{ 356{
357#ifndef NO_DIRWATCH 357#ifndef NO_DIRWATCH
358 mDirWatch.stopScan(); 358 mDirWatch.stopScan();
359 mDirWatch.removeFile( mFileName ); 359 mDirWatch.removeFile( mFileName );
360 mFileName = fileName; 360 mFileName = fileName;
361 361
362 362
363 mDirWatch.addFile( mFileName ); 363 mDirWatch.addFile( mFileName );
364 mDirWatch.startScan(); 364 mDirWatch.startScan();
365#else 365#else
366 mFileName2 = fileName; 366 mFileName2 = fileName;
367#endif 367#endif
368 368
369//US simulate KDirWatch event 369//US simulate KDirWatch event
370//US fileChanged(); 370//US fileChanged();
371} 371}
372 372
373QString ResourceFile::fileName() const 373QString ResourceFile::fileName() const
374{ 374{
375 return mFileName2; 375 return mFileName2;
376} 376}
377 377
378void ResourceFile::setFormat( const QString &format ) 378void ResourceFile::setFormat( const QString &format )
379{ 379{
380 mFormatName = format; 380 mFormatName = format;
381 delete mFormat; 381 delete mFormat;
382 382
383 FormatFactory *factory = FormatFactory::self(); 383 FormatFactory *factory = FormatFactory::self();
384 mFormat = factory->format( mFormatName ); 384 mFormat = factory->format( mFormatName );
385/*US 385/*US
386//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 386//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
387 if (mFormatName == "vcard") { 387 if (mFormatName == "vcard") {
388 mFormat = new VCardFormatPlugin2(); 388 mFormat = new VCardFormatPlugin2();
389// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 389// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
390 } 390 }
391 else if (mFormatName == "binary") { 391 else if (mFormatName == "binary") {
392 mFormat = new BinaryFormat(); 392 mFormat = new BinaryFormat();
393// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 393// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
394 } 394 }
395 else 395 else
396 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 396 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
397*/ 397*/
398 398
399} 399}
400 400
401QString ResourceFile::format() const 401QString ResourceFile::format() const
402{ 402{
403 return mFormatName; 403 return mFormatName;
404} 404}
405 405
406void ResourceFile::fileChanged() 406void ResourceFile::fileChanged()
407{ 407{
408 // There is a small theoretical chance that KDirWatch calls us before 408 // There is a small theoretical chance that KDirWatch calls us before
409 // we are fully constructed 409 // we are fully constructed
410 if (!addressBook()) 410 if (!addressBook())
411 return; 411 return;
412 412
413 413
414 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); 414 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) );
415 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 415 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
416 load(); 416 load();
417 addressBook()->emitAddressBookChanged(); 417 addressBook()->emitAddressBookChanged();
418 } 418 }
419} 419}
420 420
421void ResourceFile::removeAddressee( const Addressee &addr ) 421void ResourceFile::removeAddressee( const Addressee &addr )
422{ 422{
423 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); 423 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
424 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); 424 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
425 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); 425 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
426} 426}
427 427
428void ResourceFile::cleanUp() 428void ResourceFile::cleanUp()
429{ 429{
430 unlock( fileName() ); 430 unlock( fileName() );
431} 431}
432 432
433//US #include "resourcefile.moc" 433//US #include "resourcefile.moc"