summaryrefslogtreecommitdiffabout
path: root/kabc/plugins
Unidiff
Diffstat (limited to 'kabc/plugins') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/dir.pro5
-rw-r--r--kabc/plugins/dir/resourcedir.cpp11
-rw-r--r--kabc/plugins/file/file.pro5
-rw-r--r--kabc/plugins/file/resourcefile.cpp10
4 files changed, 28 insertions, 3 deletions
diff --git a/kabc/plugins/dir/dir.pro b/kabc/plugins/dir/dir.pro
index 3db201f..0023029 100644
--- a/kabc/plugins/dir/dir.pro
+++ b/kabc/plugins/dir/dir.pro
@@ -1,29 +1,34 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3#release debug 3#release debug
4 4
5TARGET = microkabc_dir 5TARGET = microkabc_dir
6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat 6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat
7DESTDIR = ../../../bin 7DESTDIR = ../../../bin
8#LIBS += -lmicrokde -lmicrokabc 8#LIBS += -lmicrokde -lmicrokabc
9#LIBS += -L$(QPEDIR)/lib 9#LIBS += -L$(QPEDIR)/lib
10 10
11INTERFACES = \ 11INTERFACES = \
12 12
13HEADERS = \ 13HEADERS = \
14 resourcedir.h \ 14 resourcedir.h \
15 resourcedirconfig.h 15 resourcedirconfig.h
16 16
17SOURCES = \ 17SOURCES = \
18 resourcedir.cpp \ 18 resourcedir.cpp \
19 resourcedirconfig.cpp 19 resourcedirconfig.cpp
20 20
21unix : { 21unix : {
22OBJECTS_DIR = obj/unix 22OBJECTS_DIR = obj/unix
23MOC_DIR = moc/unix 23MOC_DIR = moc/unix
24} 24}
25win32: { 25win32: {
26CONFIG += dll
26DEFINES += _WIN32_ 27DEFINES += _WIN32_
27OBJECTS_DIR = obj/win 28OBJECTS_DIR = obj/win
28MOC_DIR = moc/win 29MOC_DIR = moc/win
30LIBS += ../../../bin/microkdepim.lib
31LIBS += ../../../bin/microkcal.lib
32LIBS += ../../../bin/microkde.lib
33LIBS += ../../../bin/microkabc.lib
29} \ No newline at end of file 34} \ No newline at end of file
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index 6ea2f4b..3cb5179 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -1,360 +1,367 @@
1/* 1/*
2 This file is part of libkabc. 2 This file is part of libkabc.
3 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 3 Copyright (c) 2002 Tobias Koenig <tokoe@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 28
29#include <sys/types.h> 29#include <sys/types.h>
30#include <sys/stat.h> 30#include <sys/stat.h>
31#ifndef _WIN32_ 31#ifndef _WIN32_
32#include <unistd.h> 32#include <unistd.h>
33#endif 33#endif
34 34
35#include <qregexp.h> 35#include <qregexp.h>
36#include <qtimer.h> 36#include <qtimer.h>
37#include <qwidget.h> 37#include <qwidget.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//US #include <kgenericfactory.h> 42//US #include <kgenericfactory.h>
43#include <kglobal.h> 43#include <kglobal.h>
44#include <klocale.h> 44#include <klocale.h>
45#include <kstandarddirs.h> 45#include <kstandarddirs.h>
46#include <kurlrequester.h> 46#include <kurlrequester.h>
47 47
48#include "addressbook.h" 48#include "addressbook.h"
49 49
50#include "formatfactory.h" 50#include "formatfactory.h"
51 51
52#include "resourcedirconfig.h" 52#include "resourcedirconfig.h"
53#include "stdaddressbook.h" 53#include "stdaddressbook.h"
54 54
55//US 55//US
56#include <qdir.h> 56#include <qdir.h>
57//US #include "../../formats/vcardformatplugin2.h" 57//US #include "../../formats/vcardformatplugin2.h"
58//US #include "../../formats/binaryformat.h" 58//US #include "../../formats/binaryformat.h"
59 59
60#include "resourcedir.h" 60#include "resourcedir.h"
61 61
62using namespace KABC; 62using namespace KABC;
63 63
64extern "C" 64extern "C"
65#ifdef _WIN32_
66__declspec(dllexport)
67#else
65{ 68{
69#endif
70
66//US void *init_kabc_dir() 71//US void *init_kabc_dir()
67 void *init_microkabc_dir() 72 void *init_microkabc_dir()
68 { 73 {
69 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>(); 74 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
70 } 75 }
76#ifndef _WIN32_
71} 77}
72 78#endif
73 79
74ResourceDir::ResourceDir( const KConfig *config ) 80ResourceDir::ResourceDir( const KConfig *config )
75 : Resource( config ) 81 : Resource( config )
76{ 82{
77 QString path; 83 QString path;
78 84
79 KConfig *cfg = (KConfig *)config; 85 KConfig *cfg = (KConfig *)config;
80 if ( cfg ) { 86 if ( cfg ) {
81//US path = config->readEntry( "FilePath" ); 87//US path = config->readEntry( "FilePath" );
82 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); 88 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() );
83//US mFormatName = config->readEntry( "FileFormat" ); 89//US mFormatName = config->readEntry( "FileFormat" );
84 mFormatName = cfg->readEntry( "FileFormat", "vcard" ); 90 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
85 } else { 91 } else {
86 path = StdAddressBook::directoryName(); 92 path = StdAddressBook::directoryName();
87 mFormatName = "vcard"; 93 mFormatName = "vcard";
88 } 94 }
89 95
90 96
91 FormatFactory *factory = FormatFactory::self(); 97 FormatFactory *factory = FormatFactory::self();
92 mFormat = factory->format( mFormatName ); 98 mFormat = factory->format( mFormatName );
93 99
94 if ( !mFormat ) { 100 if ( !mFormat ) {
95 mFormatName = "vcard"; 101 mFormatName = "vcard";
96 mFormat = factory->format( mFormatName ); 102 mFormat = factory->format( mFormatName );
97 } 103 }
98 104
99/*US 105/*US
100//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 106//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
101 if (mFormatName == "vcard") 107 if (mFormatName == "vcard")
102 mFormat = new VCardFormatPlugin2(); 108 mFormat = new VCardFormatPlugin2();
103 else if (mFormatName == "binary") 109 else if (mFormatName == "binary")
104 mFormat = new BinaryFormat(); 110 mFormat = new BinaryFormat();
105 else 111 else
106 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 112 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
107*/ 113*/
108 114
109/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods 115/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
110 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 116 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
111 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 117 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
112 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 118 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
113*/ 119*/
114 120
115 setPath( path ); 121 setPath( path );
116} 122}
117 123
118ResourceDir::~ResourceDir() 124ResourceDir::~ResourceDir()
119{ 125{
120 delete mFormat; 126 delete mFormat;
121 mFormat = 0; 127 mFormat = 0;
122} 128}
123 129
124void ResourceDir::writeConfig( KConfig *config ) 130void ResourceDir::writeConfig( KConfig *config )
125{ 131{
132 config->setGroup( "Resource_" + identifier() );
126 Resource::writeConfig( config ); 133 Resource::writeConfig( config );
127 134
128 config->writeEntry( "FilePath", mPath ); 135 config->writeEntry( "FilePath", mPath );
129 config->writeEntry( "FileFormat", mFormatName ); 136 config->writeEntry( "FileFormat", mFormatName );
130} 137}
131 138
132Ticket *ResourceDir::requestSaveTicket() 139Ticket *ResourceDir::requestSaveTicket()
133{ 140{
134 kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; 141 kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl;
135 142
136 if ( !addressBook() ) return 0; 143 if ( !addressBook() ) return 0;
137 144
138 if ( !lock( mPath ) ) { 145 if ( !lock( mPath ) ) {
139 kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" 146 kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '"
140 << mPath << "'" << endl; 147 << mPath << "'" << endl;
141 return 0; 148 return 0;
142 } 149 }
143 return createTicket( this ); 150 return createTicket( this );
144} 151}
145 152
146 153
147bool ResourceDir::doOpen() 154bool ResourceDir::doOpen()
148{ 155{
149 QDir dir( mPath ); 156 QDir dir( mPath );
150 if ( !dir.exists() ) { // no directory available 157 if ( !dir.exists() ) { // no directory available
151 return dir.mkdir( dir.path() ); 158 return dir.mkdir( dir.path() );
152 } else { 159 } else {
153 QString testName = dir.entryList( QDir::Files )[0]; 160 QString testName = dir.entryList( QDir::Files )[0];
154 if ( testName.isNull() || testName.isEmpty() ) // no file in directory 161 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
155 return true; 162 return true;
156 163
157 QFile file( mPath + "/" + testName ); 164 QFile file( mPath + "/" + testName );
158 if ( file.open( IO_ReadOnly ) ) 165 if ( file.open( IO_ReadOnly ) )
159 return true; 166 return true;
160 167
161 if ( file.size() == 0 ) 168 if ( file.size() == 0 )
162 return true; 169 return true;
163 170
164 bool ok = mFormat->checkFormat( &file ); 171 bool ok = mFormat->checkFormat( &file );
165 file.close(); 172 file.close();
166 return ok; 173 return ok;
167 } 174 }
168} 175}
169 176
170void ResourceDir::doClose() 177void ResourceDir::doClose()
171{ 178{
172} 179}
173 180
174bool ResourceDir::load() 181bool ResourceDir::load()
175{ 182{
176 kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl; 183 kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl;
177 184
178 QDir dir( mPath ); 185 QDir dir( mPath );
179 QStringList files = dir.entryList( QDir::Files ); 186 QStringList files = dir.entryList( QDir::Files );
180 187
181 QStringList::Iterator it; 188 QStringList::Iterator it;
182 bool ok = true; 189 bool ok = true;
183 for ( it = files.begin(); it != files.end(); ++it ) { 190 for ( it = files.begin(); it != files.end(); ++it ) {
184 QFile file( mPath + "/" + (*it) ); 191 QFile file( mPath + "/" + (*it) );
185 192
186 if ( !file.open( IO_ReadOnly ) ) { 193 if ( !file.open( IO_ReadOnly ) ) {
187 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) ); 194 addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
188 ok = false; 195 ok = false;
189 continue; 196 continue;
190 } 197 }
191 198
192 if ( !mFormat->loadAll( addressBook(), this, &file ) ) 199 if ( !mFormat->loadAll( addressBook(), this, &file ) )
193 ok = false; 200 ok = false;
194 201
195 file.close(); 202 file.close();
196 } 203 }
197 204
198 return ok; 205 return ok;
199} 206}
200 207
201bool ResourceDir::save( Ticket *ticket ) 208bool ResourceDir::save( Ticket *ticket )
202{ 209{
203 kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; 210 kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl;
204 211
205 AddressBook::Iterator it; 212 AddressBook::Iterator it;
206 bool ok = true; 213 bool ok = true;
207 214
208 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 215 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
209 if ( (*it).resource() != this || !(*it).changed() ) 216 if ( (*it).resource() != this || !(*it).changed() )
210 continue; 217 continue;
211 218
212 QFile file( mPath + "/" + (*it).uid() ); 219 QFile file( mPath + "/" + (*it).uid() );
213 if ( !file.open( IO_WriteOnly ) ) { 220 if ( !file.open( IO_WriteOnly ) ) {
214 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) ); 221 addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
215 continue; 222 continue;
216 } 223 }
217 224
218 mFormat->save( *it, &file ); 225 mFormat->save( *it, &file );
219 226
220 // mark as unchanged 227 // mark as unchanged
221 (*it).setChanged( false ); 228 (*it).setChanged( false );
222 229
223 file.close(); 230 file.close();
224 } 231 }
225 232
226 delete ticket; 233 delete ticket;
227 unlock( mPath ); 234 unlock( mPath );
228 235
229 return ok; 236 return ok;
230} 237}
231 238
232bool ResourceDir::lock( const QString &path ) 239bool ResourceDir::lock( const QString &path )
233{ 240{
234 kdDebug(5700) << "ResourceDir::lock()" << endl; 241 kdDebug(5700) << "ResourceDir::lock()" << endl;
235 242
236 QString p = path; 243 QString p = path;
237//US change the implementation how the lockfilename is getting created 244//US change the implementation how the lockfilename is getting created
238//US p.replace( QRegExp("/"), "_" ); 245//US p.replace( QRegExp("/"), "_" );
239//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); 246//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
240 KURL url(p); 247 KURL url(p);
241 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 248 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
242 249
243 250
244 kdDebug(5700) << "-- lock name: " << lockName << endl; 251 kdDebug(5700) << "-- lock name: " << lockName << endl;
245 252
246 if ( QFile::exists( lockName ) ) return false; 253 if ( QFile::exists( lockName ) ) return false;
247 254
248 QString lockUniqueName; 255 QString lockUniqueName;
249 lockUniqueName = p + KApplication::randomString( 8 ); 256 lockUniqueName = p + KApplication::randomString( 8 );
250 257
251 url = lockUniqueName; 258 url = lockUniqueName;
252//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 259//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
253 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 260 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
254 261
255 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 262 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
256 263
257 // Create unique file 264 // Create unique file
258 QFile file( mLockUniqueName ); 265 QFile file( mLockUniqueName );
259 file.open( IO_WriteOnly ); 266 file.open( IO_WriteOnly );
260 file.close(); 267 file.close();
261 268
262 // Create lock file 269 // Create lock file
263 int result = 0; 270 int result = 0;
264#ifndef _WIN32_ 271#ifndef _WIN32_
265 result = ::link( QFile::encodeName( mLockUniqueName ), 272 result = ::link( QFile::encodeName( mLockUniqueName ),
266 QFile::encodeName( lockName ) ); 273 QFile::encodeName( lockName ) );
267#endif 274#endif
268 if ( result == 0 ) { 275 if ( result == 0 ) {
269 addressBook()->emitAddressBookLocked(); 276 addressBook()->emitAddressBookLocked();
270 return true; 277 return true;
271 } 278 }
272 279
273 // TODO: check stat 280 // TODO: check stat
274 281
275 return false; 282 return false;
276} 283}
277 284
278void ResourceDir::unlock( const QString &path ) 285void ResourceDir::unlock( const QString &path )
279{ 286{
280 QString p = path; 287 QString p = path;
281//US change the implementation how the lockfilename is getting created 288//US change the implementation how the lockfilename is getting created
282//US p.replace( QRegExp( "/" ), "_" ); 289//US p.replace( QRegExp( "/" ), "_" );
283//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); 290//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
284 KURL url(p); 291 KURL url(p);
285 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); 292 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" );
286 293
287 ::unlink( QFile::encodeName( lockName ) ); 294 ::unlink( QFile::encodeName( lockName ) );
288 QFile::remove( mLockUniqueName ); 295 QFile::remove( mLockUniqueName );
289 addressBook()->emitAddressBookUnlocked(); 296 addressBook()->emitAddressBookUnlocked();
290} 297}
291 298
292void ResourceDir::setPath( const QString &path ) 299void ResourceDir::setPath( const QString &path )
293{ 300{
294/*US ToDo: no synchronization so far. Has to be changed in the future 301/*US ToDo: no synchronization so far. Has to be changed in the future
295 mDirWatch.stopScan(); 302 mDirWatch.stopScan();
296 mDirWatch.removeDir( mPath ); 303 mDirWatch.removeDir( mPath );
297*/ 304*/
298 mPath = path; 305 mPath = path;
299 306
300/*US ToDo: no synchronization so far. Has to be changed in the future 307/*US ToDo: no synchronization so far. Has to be changed in the future
301 mDirWatch.addDir( mPath, true ); 308 mDirWatch.addDir( mPath, true );
302 mDirWatch.startScan(); 309 mDirWatch.startScan();
303*/ 310*/
304 311
305//US simulate KDirWatch event 312//US simulate KDirWatch event
306 pathChanged(); 313 pathChanged();
307 314
308} 315}
309 316
310QString ResourceDir::path() const 317QString ResourceDir::path() const
311{ 318{
312 return mPath; 319 return mPath;
313} 320}
314 321
315void ResourceDir::setFormat( const QString &format ) 322void ResourceDir::setFormat( const QString &format )
316{ 323{
317 mFormatName = format; 324 mFormatName = format;
318 325
319 if ( mFormat ) 326 if ( mFormat )
320 delete mFormat; 327 delete mFormat;
321 328
322 FormatFactory *factory = FormatFactory::self(); 329 FormatFactory *factory = FormatFactory::self();
323 mFormat = factory->format( mFormatName ); 330 mFormat = factory->format( mFormatName );
324/*US 331/*US
325qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); 332qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
326 if (mFormatName == "vcard") 333 if (mFormatName == "vcard")
327 mFormat = new VCardFormatPlugin2(); 334 mFormat = new VCardFormatPlugin2();
328 else if (mFormatName == "binary") 335 else if (mFormatName == "binary")
329 mFormat = new BinaryFormat(); 336 mFormat = new BinaryFormat();
330 else 337 else
331 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); 338 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1());
332*/ 339*/
333 340
334} 341}
335 342
336QString ResourceDir::format() const 343QString ResourceDir::format() const
337{ 344{
338 return mFormatName; 345 return mFormatName;
339} 346}
340 347
341void ResourceDir::pathChanged() 348void ResourceDir::pathChanged()
342{ 349{
343 if ( !addressBook() ) 350 if ( !addressBook() )
344 return; 351 return;
345 352
346 load(); 353 load();
347 addressBook()->emitAddressBookChanged(); 354 addressBook()->emitAddressBookChanged();
348} 355}
349 356
350void ResourceDir::removeAddressee( const Addressee& addr ) 357void ResourceDir::removeAddressee( const Addressee& addr )
351{ 358{
352 QFile::remove( mPath + "/" + addr.uid() ); 359 QFile::remove( mPath + "/" + addr.uid() );
353} 360}
354 361
355void ResourceDir::cleanUp() 362void ResourceDir::cleanUp()
356{ 363{
357 unlock( mPath ); 364 unlock( mPath );
358} 365}
359 366
360//US #include "resourcedir.moc" 367//US #include "resourcedir.moc"
diff --git a/kabc/plugins/file/file.pro b/kabc/plugins/file/file.pro
index a5ade93..7cf7c58 100644
--- a/kabc/plugins/file/file.pro
+++ b/kabc/plugins/file/file.pro
@@ -1,30 +1,35 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3#release debug 3#release debug
4 4
5TARGET = microkabc_file 5TARGET = microkabc_file
6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat 6INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../qtcompat
7 7
8DESTDIR = ../../../bin 8DESTDIR = ../../../bin
9#LIBS += -lmicrokde -lmicrokabc 9#LIBS += -lmicrokde -lmicrokabc
10#LIBS += -L$(QPEDIR)/lib 10#LIBS += -L$(QPEDIR)/lib
11 11
12INTERFACES = \ 12INTERFACES = \
13 13
14HEADERS = \ 14HEADERS = \
15 resourcefile.h \ 15 resourcefile.h \
16 resourcefileconfig.h 16 resourcefileconfig.h
17 17
18SOURCES = \ 18SOURCES = \
19 resourcefile.cpp \ 19 resourcefile.cpp \
20 resourcefileconfig.cpp 20 resourcefileconfig.cpp
21 21
22unix : { 22unix : {
23OBJECTS_DIR = obj/unix 23OBJECTS_DIR = obj/unix
24MOC_DIR = moc/unix 24MOC_DIR = moc/unix
25} 25}
26win32: { 26win32: {
27CONFIG += dll
27DEFINES += _WIN32_ 28DEFINES += _WIN32_
28OBJECTS_DIR = obj/win 29OBJECTS_DIR = obj/win
29MOC_DIR = moc/win 30MOC_DIR = moc/win
31LIBS += ../../../bin/microkdepim.lib
32LIBS += ../../../bin/microkcal.lib
33LIBS += ../../../bin/microkde.lib
34LIBS += ../../../bin/microkabc.lib
30} \ No newline at end of file 35} \ No newline at end of file
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 4b4c935..2d20706 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,391 +1,399 @@
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 45
46#include "formatfactory.h" 46#include "formatfactory.h"
47 47
48#include "resource.h" 48#include "resource.h"
49#include "resourcefileconfig.h" 49#include "resourcefileconfig.h"
50#include "stdaddressbook.h" 50#include "stdaddressbook.h"
51 51
52//US #include "../../formats/vcardformatplugin2.h" 52//US #include "../../formats/vcardformatplugin2.h"
53//US #include "../../formats/binaryformat.h" 53//US #include "../../formats/binaryformat.h"
54 54
55 55
56#include "resourcefile.h" 56#include "resourcefile.h"
57 57
58using namespace KABC; 58using namespace KABC;
59 59
60extern "C" 60extern "C"
61#ifdef _WIN32_
62__declspec(dllexport)
63#else
61{ 64{
65#endif
66
62//US void *init_kabc_file() 67//US void *init_kabc_file()
63 void *init_microkabc_file() 68 void *init_microkabc_file()
64 { 69 {
65 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); 70 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>();
66 } 71 }
72#ifndef _WIN32_
67} 73}
68 74#endif
69 75
70ResourceFile::ResourceFile( const KConfig *config ) 76ResourceFile::ResourceFile( const KConfig *config )
71 : Resource( config ) , mFormat( 0 ) 77 : Resource( config ) , mFormat( 0 )
72{ 78{
73 QString fileName, formatName; 79 QString fileName, formatName;
74 80
75 KConfig *cfg = (KConfig *)config; 81 KConfig *cfg = (KConfig *)config;
76 if ( cfg ) { 82 if ( cfg ) {
77 fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); 83 fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() );
78 formatName = cfg->readEntry( "FileFormat", "vcard" ); 84 formatName = cfg->readEntry( "FileFormat", "vcard" );
79// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); 85// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() );
80 } else { 86 } else {
81 fileName = StdAddressBook::fileName(); 87 fileName = StdAddressBook::fileName();
82 formatName = "vcard"; 88 formatName = "vcard";
83// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); 89// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() );
84 } 90 }
85 91
86 init( fileName, formatName ); 92 init( fileName, formatName );
87} 93}
88 94
89ResourceFile::ResourceFile( const QString &fileName, 95ResourceFile::ResourceFile( const QString &fileName,
90 const QString &formatName ) 96 const QString &formatName )
91 : Resource( 0 ) 97 : Resource( 0 )
92{ 98{
93// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 99// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
94 init( fileName, formatName ); 100 init( fileName, formatName );
95} 101}
96 102
97void ResourceFile::init( const QString &fileName, const QString &formatName ) 103void ResourceFile::init( const QString &fileName, const QString &formatName )
98{ 104{
99 mFormatName = formatName; 105 mFormatName = formatName;
100 106
101 FormatFactory *factory = FormatFactory::self(); 107 FormatFactory *factory = FormatFactory::self();
102 mFormat = factory->format( mFormatName ); 108 mFormat = factory->format( mFormatName );
103 109
104 if ( !mFormat ) { 110 if ( !mFormat ) {
105 mFormatName = "vcard"; 111 mFormatName = "vcard";
106 mFormat = factory->format( mFormatName ); 112 mFormat = factory->format( mFormatName );
107 } 113 }
108 114
109/*US 115/*US
110//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); 116//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1());
111 if (mFormatName == "vcard") { 117 if (mFormatName == "vcard") {
112 mFormat = new VCardFormatPlugin2(); 118 mFormat = new VCardFormatPlugin2();
113// qDebug("ResourceFile::init format VCardFormatPlugin2"); 119// qDebug("ResourceFile::init format VCardFormatPlugin2");
114 } 120 }
115 else if (mFormatName == "binary") { 121 else if (mFormatName == "binary") {
116 mFormat = new BinaryFormat(); 122 mFormat = new BinaryFormat();
117// qDebug("ResourceFile::init format BinaryFormat"); 123// qDebug("ResourceFile::init format BinaryFormat");
118 } 124 }
119 else 125 else
120 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); 126 qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1());
121*/ 127*/
122 128
123/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods 129/*US we have no KDirWatch. SO simulate the signals from inside the apropriate methods
124 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 130 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
125 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 131 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
126 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 132 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
127*/ 133*/
128 134
129 setFileName( fileName ); 135 setFileName( fileName );
130} 136}
131 137
132ResourceFile::~ResourceFile() 138ResourceFile::~ResourceFile()
133{ 139{
134 delete mFormat; 140 delete mFormat;
135 mFormat = 0; 141 mFormat = 0;
136} 142}
137 143
138void ResourceFile::writeConfig( KConfig *config ) 144void ResourceFile::writeConfig( KConfig *config )
139{ 145{
146
147 config->setGroup( "Resource_" + identifier() );
140 Resource::writeConfig( config ); 148 Resource::writeConfig( config );
141 149
142 config->writeEntry( "FileName", mFileName ); 150 config->writeEntry( "FileName", mFileName );
143 config->writeEntry( "FileFormat", mFormatName ); 151 config->writeEntry( "FileFormat", mFormatName );
144 152
145// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 153// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
146 154
147} 155}
148 156
149Ticket *ResourceFile::requestSaveTicket() 157Ticket *ResourceFile::requestSaveTicket()
150{ 158{
151 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 159 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
152 160
153 if ( !addressBook() ) return 0; 161 if ( !addressBook() ) return 0;
154 162
155 if ( !lock( mFileName ) ) { 163 if ( !lock( mFileName ) ) {
156 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" 164 kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '"
157 << mFileName << "'" << endl; 165 << mFileName << "'" << endl;
158 return 0; 166 return 0;
159 } 167 }
160 return createTicket( this ); 168 return createTicket( this );
161} 169}
162 170
163 171
164bool ResourceFile::doOpen() 172bool ResourceFile::doOpen()
165{ 173{
166 QFile file( mFileName ); 174 QFile file( mFileName );
167 175
168 if ( !file.exists() ) { 176 if ( !file.exists() ) {
169 // try to create the file 177 // try to create the file
170 bool ok = file.open( IO_WriteOnly ); 178 bool ok = file.open( IO_WriteOnly );
171 if ( ok ) 179 if ( ok )
172 file.close(); 180 file.close();
173 181
174 return ok; 182 return ok;
175 } else { 183 } else {
176 if ( !file.open( IO_ReadWrite ) ) 184 if ( !file.open( IO_ReadWrite ) )
177 return false; 185 return false;
178 186
179 if ( file.size() == 0 ) { 187 if ( file.size() == 0 ) {
180 file.close(); 188 file.close();
181 return true; 189 return true;
182 } 190 }
183 191
184 bool ok = mFormat->checkFormat( &file ); 192 bool ok = mFormat->checkFormat( &file );
185 file.close(); 193 file.close();
186 194
187 return ok; 195 return ok;
188 } 196 }
189} 197}
190 198
191void ResourceFile::doClose() 199void ResourceFile::doClose()
192{ 200{
193} 201}
194 202
195bool ResourceFile::load() 203bool ResourceFile::load()
196{ 204{
197 205
198 206
199 QFile file( mFileName ); 207 QFile file( mFileName );
200 if ( !file.open( IO_ReadOnly ) ) { 208 if ( !file.open( IO_ReadOnly ) ) {
201 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 209 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
202 return false; 210 return false;
203 } 211 }
204 212
205// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 213// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
206 214
207 return mFormat->loadAll( addressBook(), this, &file ); 215 return mFormat->loadAll( addressBook(), this, &file );
208} 216}
209 217
210bool ResourceFile::save( Ticket *ticket ) 218bool ResourceFile::save( Ticket *ticket )
211{ 219{
212// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 220// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
213 221
214 222
215 // create backup file 223 // create backup file
216 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 224 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
217 225
218/*US we use a simpler method to create a backupfile 226/*US we use a simpler method to create a backupfile
219 227
220 (void) KSaveFile::backupFile( mFileName, QString::null 228 (void) KSaveFile::backupFile( mFileName, QString::null
221 ,extension ); 229 ,extension );
222 230
223 KSaveFile saveFile( mFileName ); 231 KSaveFile saveFile( mFileName );
224 bool ok = false; 232 bool ok = false;
225 if ( saveFile.status() == 0 && saveFile.file() ) 233 if ( saveFile.status() == 0 && saveFile.file() )
226 { 234 {
227 mFormat->saveAll( addressBook(), this, saveFile.file() ); 235 mFormat->saveAll( addressBook(), this, saveFile.file() );
228 ok = saveFile.close(); 236 ok = saveFile.close();
229 } 237 }
230*/ 238*/
231 239
232//US ToDo: write backupfile 240//US ToDo: write backupfile
233 QFile info; 241 QFile info;
234 info.setName( mFileName ); 242 info.setName( mFileName );
235 bool ok = info.open( IO_WriteOnly ); 243 bool ok = info.open( IO_WriteOnly );
236 if ( ok ) { 244 if ( ok ) {
237 mFormat->saveAll( addressBook(), this, &info ); 245 mFormat->saveAll( addressBook(), this, &info );
238 246
239 info.close(); 247 info.close();
240 ok = true; 248 ok = true;
241 } 249 }
242 else { 250 else {
243 251
244 } 252 }
245 253
246 if ( !ok ) 254 if ( !ok )
247 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 255 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
248 256
249 delete ticket; 257 delete ticket;
250 unlock( mFileName ); 258 unlock( mFileName );
251 259
252 return ok; 260 return ok;
253 261
254 qDebug("ResourceFile::save has to be changed"); 262 qDebug("ResourceFile::save has to be changed");
255 return true; 263 return true;
256} 264}
257 265
258bool ResourceFile::lock( const QString &fileName ) 266bool ResourceFile::lock( const QString &fileName )
259{ 267{
260 268
261 269
262 QString fn = fileName; 270 QString fn = fileName;
263 271
264//US change the implementation how the lockfilename is getting created 272//US change the implementation how the lockfilename is getting created
265//US fn.replace( QRegExp("/"), "_" ); 273//US fn.replace( QRegExp("/"), "_" );
266//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 274//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
267 275
268 KURL url(fn); 276 KURL url(fn);
269 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 277 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
270 278
271 279
272 280
273 if (QFile::exists( lockName )) return false; 281 if (QFile::exists( lockName )) return false;
274 282
275 QString lockUniqueName; 283 QString lockUniqueName;
276 lockUniqueName = fn + KApplication::randomString( 8 ); 284 lockUniqueName = fn + KApplication::randomString( 8 );
277 285
278 url = lockUniqueName; 286 url = lockUniqueName;
279//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 287//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
280 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 288 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
281 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 289 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
282 290
283 // Create unique file 291 // Create unique file
284 QFile file( mLockUniqueName ); 292 QFile file( mLockUniqueName );
285 file.open( IO_WriteOnly ); 293 file.open( IO_WriteOnly );
286 file.close(); 294 file.close();
287 295
288 // Create lock file 296 // Create lock file
289 int result = 0; 297 int result = 0;
290#ifndef _WIN32_ 298#ifndef _WIN32_
291 result = ::link( QFile::encodeName( mLockUniqueName ), 299 result = ::link( QFile::encodeName( mLockUniqueName ),
292 QFile::encodeName( lockName ) ); 300 QFile::encodeName( lockName ) );
293#endif 301#endif
294 if ( result == 0 ) { 302 if ( result == 0 ) {
295 addressBook()->emitAddressBookLocked(); 303 addressBook()->emitAddressBookLocked();
296 return true; 304 return true;
297 } 305 }
298 306
299 // TODO: check stat 307 // TODO: check stat
300 308
301 return false; 309 return false;
302} 310}
303 311
304void ResourceFile::unlock( const QString &fileName ) 312void ResourceFile::unlock( const QString &fileName )
305{ 313{
306 QString fn = fileName; 314 QString fn = fileName;
307//US change the implementation how the lockfilename is getting created 315//US change the implementation how the lockfilename is getting created
308//US fn.replace( QRegExp( "/" ), "_" ); 316//US fn.replace( QRegExp( "/" ), "_" );
309//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 317//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
310//US QString lockName = fn + ".lock"; 318//US QString lockName = fn + ".lock";
311 KURL url(fn); 319 KURL url(fn);
312 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 320 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
313 321
314 QFile::remove( lockName ); 322 QFile::remove( lockName );
315 QFile::remove( mLockUniqueName ); 323 QFile::remove( mLockUniqueName );
316 addressBook()->emitAddressBookUnlocked(); 324 addressBook()->emitAddressBookUnlocked();
317} 325}
318 326
319void ResourceFile::setFileName( const QString &fileName ) 327void ResourceFile::setFileName( const QString &fileName )
320{ 328{
321/*US ToDo: no synchronization so far. Has to be changed in the future 329/*US ToDo: no synchronization so far. Has to be changed in the future
322 mDirWatch.stopScan(); 330 mDirWatch.stopScan();
323 mDirWatch.removeFile( mFileName ); 331 mDirWatch.removeFile( mFileName );
324*/ 332*/
325 mFileName = fileName; 333 mFileName = fileName;
326 334
327 335
328/*US ToDo: no synchronization so far. Has to be changed in the future 336/*US ToDo: no synchronization so far. Has to be changed in the future
329 mDirWatch.addFile( mFileName ); 337 mDirWatch.addFile( mFileName );
330 mDirWatch.startScan(); 338 mDirWatch.startScan();
331*/ 339*/
332//US simulate KDirWatch event 340//US simulate KDirWatch event
333 fileChanged(); 341 fileChanged();
334} 342}
335 343
336QString ResourceFile::fileName() const 344QString ResourceFile::fileName() const
337{ 345{
338 return mFileName; 346 return mFileName;
339} 347}
340 348
341void ResourceFile::setFormat( const QString &format ) 349void ResourceFile::setFormat( const QString &format )
342{ 350{
343 mFormatName = format; 351 mFormatName = format;
344 delete mFormat; 352 delete mFormat;
345 353
346 FormatFactory *factory = FormatFactory::self(); 354 FormatFactory *factory = FormatFactory::self();
347 mFormat = factory->format( mFormatName ); 355 mFormat = factory->format( mFormatName );
348/*US 356/*US
349//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 357//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
350 if (mFormatName == "vcard") { 358 if (mFormatName == "vcard") {
351 mFormat = new VCardFormatPlugin2(); 359 mFormat = new VCardFormatPlugin2();
352// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 360// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
353 } 361 }
354 else if (mFormatName == "binary") { 362 else if (mFormatName == "binary") {
355 mFormat = new BinaryFormat(); 363 mFormat = new BinaryFormat();
356// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 364// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
357 } 365 }
358 else 366 else
359 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 367 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
360*/ 368*/
361 369
362} 370}
363 371
364QString ResourceFile::format() const 372QString ResourceFile::format() const
365{ 373{
366 return mFormatName; 374 return mFormatName;
367} 375}
368 376
369void ResourceFile::fileChanged() 377void ResourceFile::fileChanged()
370{ 378{
371 // There is a small theoretical chance that KDirWatch calls us before 379 // There is a small theoretical chance that KDirWatch calls us before
372 // we are fully constructed 380 // we are fully constructed
373 if (!addressBook()) 381 if (!addressBook())
374 return; 382 return;
375 load(); 383 load();
376 addressBook()->emitAddressBookChanged(); 384 addressBook()->emitAddressBookChanged();
377} 385}
378 386
379void ResourceFile::removeAddressee( const Addressee &addr ) 387void ResourceFile::removeAddressee( const Addressee &addr )
380{ 388{
381 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); 389 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
382 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); 390 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
383 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); 391 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
384} 392}
385 393
386void ResourceFile::cleanUp() 394void ResourceFile::cleanUp()
387{ 395{
388 unlock( mFileName ); 396 unlock( mFileName );
389} 397}
390 398
391//US #include "resourcefile.moc" 399//US #include "resourcefile.moc"