summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-09-15 10:22:55 (UTC)
committer zautrix <zautrix>2004-09-15 10:22:55 (UTC)
commitd4adafe41cf399585b8e35cb600ff35706d55ae0 (patch) (unidiff)
tree1becc87f6c40390fd73082996d18f71fb5e9c772
parent8889ffd6f6958c3a1d07bafedcc8af5d786a1660 (diff)
downloadkdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.zip
kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.tar.gz
kdepimpi-d4adafe41cf399585b8e35cb600ff35706d55ae0.tar.bz2
fixes for desktop version
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/dir/resourcedir.cpp17
-rw-r--r--kabc/plugins/dir/resourcedir.h3
-rw-r--r--kabc/plugins/file/resourcefile.cpp20
-rw-r--r--kabc/plugins/file/resourcefile.h3
-rw-r--r--microkde/kresources/configpage.cpp14
5 files changed, 35 insertions, 22 deletions
diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp
index 7d96cb7..e58e4f7 100644
--- a/kabc/plugins/dir/resourcedir.cpp
+++ b/kabc/plugins/dir/resourcedir.cpp
@@ -1,370 +1,375 @@
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#include <kmessagebox.h> 47#include <kmessagebox.h>
48 48
49#include "addressbook.h" 49#include "addressbook.h"
50 50
51#include "formatfactory.h" 51#include "formatfactory.h"
52 52
53#include "resourcedirconfig.h" 53#include "resourcedirconfig.h"
54#include "stdaddressbook.h" 54#include "stdaddressbook.h"
55 55
56//US 56//US
57#include <qdir.h> 57#include <qdir.h>
58 58
59#define NO_DIRWATCH
59#include "resourcedir.h" 60#include "resourcedir.h"
60#include "syncprefwidget.h" 61#include "syncprefwidget.h"
61 62
62//#define ALLOW_LOCKING 63//#define ALLOW_LOCKING
63 64
64using namespace KABC; 65using namespace KABC;
65 66
66extern "C" 67extern "C"
67#ifdef _WIN32_ 68#ifdef _WIN32_
68__declspec(dllexport) 69__declspec(dllexport)
69#else 70#else
70{ 71{
71#endif 72#endif
72 73
73//US void *init_kabc_dir() 74//US void *init_kabc_dir()
74 void *init_microkabc_dir() 75 void *init_microkabc_dir()
75 { 76 {
76 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); 77 return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>();
77 } 78 }
78#ifndef _WIN32_ 79#ifndef _WIN32_
79} 80}
80#endif 81#endif
81 82
82ResourceDir::ResourceDir( const KConfig *config, bool syncable ) 83ResourceDir::ResourceDir( const KConfig *config, bool syncable )
83 : Resource( config, syncable ) 84 : Resource( config, syncable )
84{ 85{
85 QString path; 86 QString path;
86 87
87 KConfig *cfg = (KConfig *)config; 88 KConfig *cfg = (KConfig *)config;
88 if ( cfg ) { 89 if ( cfg ) {
89//US path = config->readEntry( "FilePath" ); 90//US path = config->readEntry( "FilePath" );
90 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); 91 path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() );
91//US mFormatName = config->readEntry( "FileFormat" ); 92//US mFormatName = config->readEntry( "FileFormat" );
92 mFormatName = cfg->readEntry( "FileFormat", "vcard" ); 93 mFormatName = cfg->readEntry( "FileFormat", "vcard" );
93 } else { 94 } else {
94 path = StdAddressBook::directoryName(); 95 path = StdAddressBook::directoryName();
95 mFormatName = "vcard"; 96 mFormatName = "vcard";
96 } 97 }
97 98
98 99
99 FormatFactory *factory = FormatFactory::self(); 100 FormatFactory *factory = FormatFactory::self();
100 mFormat = factory->format( mFormatName ); 101 mFormat = factory->format( mFormatName );
101 102
102 if ( !mFormat ) { 103 if ( !mFormat ) {
103 mFormatName = "vcard"; 104 mFormatName = "vcard";
104 mFormat = factory->format( mFormatName ); 105 mFormat = factory->format( mFormatName );
105 } 106 }
106 107
107/*US 108/*US
108//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); 109//US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1());
109 if (mFormatName == "vcard") 110 if (mFormatName == "vcard")
110 mFormat = new VCardFormatPlugin2(); 111 mFormat = new VCardFormatPlugin2();
111 else if (mFormatName == "binary") 112 else if (mFormatName == "binary")
112 mFormat = new BinaryFormat(); 113 mFormat = new BinaryFormat();
113 else 114 else
114 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); 115 qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1());
115*/ 116*/
116 117#ifndef NO_DIRWATCH
117 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); 118 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) );
118 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); 119 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) );
119 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); 120 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) );
120 121#endif
121 setPath( path ); 122 setPath( path );
122} 123}
123 124
124ResourceDir::~ResourceDir() 125ResourceDir::~ResourceDir()
125{ 126{
126 delete mFormat; 127 delete mFormat;
127 mFormat = 0; 128 mFormat = 0;
128} 129}
129 130
130void ResourceDir::writeConfig( KConfig *config ) 131void ResourceDir::writeConfig( KConfig *config )
131{ 132{
132 config->setGroup( "Resource_" + identifier() ); 133 config->setGroup( "Resource_" + identifier() );
133 Resource::writeConfig( config ); 134 Resource::writeConfig( config );
134 135
135 config->writeEntry( "FilePath", mPath ); 136 config->writeEntry( "FilePath", mPath );
136 config->writeEntry( "FileFormat", mFormatName ); 137 config->writeEntry( "FileFormat", mFormatName );
137} 138}
138 139
139Ticket *ResourceDir::requestSaveTicket() 140Ticket *ResourceDir::requestSaveTicket()
140{ 141{
141 142
142 143
143 if ( !addressBook() ) return 0; 144 if ( !addressBook() ) return 0;
144#ifdef ALLOW_LOCKING 145#ifdef ALLOW_LOCKING
145 if ( !lock( mPath ) ) { 146 if ( !lock( mPath ) ) {
146 147
147 return 0; 148 return 0;
148 } 149 }
149#endif 150#endif
150 return createTicket( this ); 151 return createTicket( this );
151 152
152} 153}
153 154
154 155
155bool ResourceDir::doOpen() 156bool ResourceDir::doOpen()
156{ 157{
157 QDir dir( mPath ); 158 QDir dir( mPath );
158 if ( !dir.exists() ) { // no directory available 159 if ( !dir.exists() ) { // no directory available
159 return dir.mkdir( dir.path() ); 160 return dir.mkdir( dir.path() );
160 } else { 161 } else {
161 QString testName = dir.entryList( QDir::Files )[0]; 162 QString testName = dir.entryList( QDir::Files )[0];
162 if ( testName.isNull() || testName.isEmpty() ) // no file in directory 163 if ( testName.isNull() || testName.isEmpty() ) // no file in directory
163 return true; 164 return true;
164 165
165 QFile file( mPath + "/" + testName ); 166 QFile file( mPath + "/" + testName );
166 if ( file.open( IO_ReadOnly ) ) 167 if ( file.open( IO_ReadOnly ) )
167 return true; 168 return true;
168 169
169 if ( file.size() == 0 ) 170 if ( file.size() == 0 )
170 return true; 171 return true;
171 172
172 bool ok = mFormat->checkFormat( &file ); 173 bool ok = mFormat->checkFormat( &file );
173 file.close(); 174 file.close();
174 return ok; 175 return ok;
175 } 176 }
176} 177}
177 178
178void ResourceDir::doClose() 179void ResourceDir::doClose()
179{ 180{
180} 181}
181 182
182bool ResourceDir::load() 183bool ResourceDir::load()
183{ 184{
184 QDir dir( mPath ); 185 QDir dir( mPath );
185 QStringList files = dir.entryList( QDir::Files ); 186 QStringList files = dir.entryList( QDir::Files );
186 187
187 QStringList::Iterator it; 188 QStringList::Iterator it;
188 bool ok = true; 189 bool ok = true;
189 for ( it = files.begin(); it != files.end(); ++it ) { 190 for ( it = files.begin(); it != files.end(); ++it ) {
190 QFile file( mPath + "/" + (*it) ); 191 QFile file( mPath + "/" + (*it) );
191 192
192 if ( !file.open( IO_ReadOnly ) ) { 193 if ( !file.open( IO_ReadOnly ) ) {
193 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() ) );
194 ok = false; 195 ok = false;
195 continue; 196 continue;
196 } 197 }
197 198
198 if ( !mFormat->loadAll( addressBook(), this, &file ) ) 199 if ( !mFormat->loadAll( addressBook(), this, &file ) )
199 ok = false; 200 ok = false;
200 201
201 file.close(); 202 file.close();
202 } 203 }
203 204
204 return ok; 205 return ok;
205} 206}
206 207
207bool ResourceDir::save( Ticket *ticket ) 208bool ResourceDir::save( Ticket *ticket )
208{ 209{
209 AddressBook::Iterator it; 210 AddressBook::Iterator it;
210 bool ok = true; 211 bool ok = true;
211 212#ifndef NO_DIRWATCH
212 mDirWatch.stopScan(); 213 mDirWatch.stopScan();
213 214#endif
214 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { 215 for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
215 if ( (*it).resource() != this || !(*it).changed() ) 216 if ( (*it).resource() != this || !(*it).changed() )
216 continue; 217 continue;
217 218
218 QFile file( mPath + "/" + (*it).uid() ); 219 QFile file( mPath + "/" + (*it).uid() );
219 if ( !file.open( IO_WriteOnly ) ) { 220 if ( !file.open( IO_WriteOnly ) ) {
220 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() ) );
221 continue; 222 continue;
222 } 223 }
223 224
224 mFormat->save( *it, &file ); 225 mFormat->save( *it, &file );
225 226
226 // mark as unchanged 227 // mark as unchanged
227 (*it).setChanged( false ); 228 (*it).setChanged( false );
228 229
229 file.close(); 230 file.close();
230 } 231 }
232#ifndef NO_DIRWATCH
231 mDirWatch.startScan(); 233 mDirWatch.startScan();
232 234#endif
233 delete ticket; 235 delete ticket;
234#ifdef ALLOW_LOCKING 236#ifdef ALLOW_LOCKING
235 unlock( mPath ); 237 unlock( mPath );
236#endif 238#endif
237 return ok; 239 return ok;
238} 240}
239 241
240bool ResourceDir::lock( const QString &path ) 242bool ResourceDir::lock( const QString &path )
241{ 243{
242#ifdef ALLOW_LOCKING 244#ifdef ALLOW_LOCKING
243 QString p = path; 245 QString p = path;
244//US change the implementation how the lockfilename is getting created 246//US change the implementation how the lockfilename is getting created
245//US p.replace( QRegExp("/"), "_" ); 247//US p.replace( QRegExp("/"), "_" );
246//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); 248//US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" );
247 KURL url(p); 249 KURL url(p);
248 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 250 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
249 251
250 252
251 if ( QFile::exists( lockName ) ) return false; 253 if ( QFile::exists( lockName ) ) return false;
252 254
253 QString lockUniqueName; 255 QString lockUniqueName;
254 lockUniqueName = p + KApplication::randomString( 8 ); 256 lockUniqueName = p + KApplication::randomString( 8 );
255 257
256 url = lockUniqueName; 258 url = lockUniqueName;
257//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 259//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
258 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 260 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
259 261
260 // Create unique file 262 // Create unique file
261 QFile file( mLockUniqueName ); 263 QFile file( mLockUniqueName );
262 file.open( IO_WriteOnly ); 264 file.open( IO_WriteOnly );
263 file.close(); 265 file.close();
264 266
265 // Create lock file 267 // Create lock file
266 int result = 0; 268 int result = 0;
267#ifndef _WIN32_ 269#ifndef _WIN32_
268 result = ::link( QFile::encodeName( mLockUniqueName ), 270 result = ::link( QFile::encodeName( mLockUniqueName ),
269 QFile::encodeName( lockName ) ); 271 QFile::encodeName( lockName ) );
270#endif 272#endif
271 if ( result == 0 ) { 273 if ( result == 0 ) {
272 addressBook()->emitAddressBookLocked(); 274 addressBook()->emitAddressBookLocked();
273 return true; 275 return true;
274 } 276 }
275 277
276 // TODO: check stat 278 // TODO: check stat
277 279
278 return false; 280 return false;
279#else 281#else
280 return true; 282 return true;
281#endif 283#endif
282} 284}
283 285
284void ResourceDir::unlock( const QString &path ) 286void ResourceDir::unlock( const QString &path )
285{ 287{
286#ifdef ALLOW_LOCKING 288#ifdef ALLOW_LOCKING
287 QString p = path; 289 QString p = path;
288//US change the implementation how the lockfilename is getting created 290//US change the implementation how the lockfilename is getting created
289//US p.replace( QRegExp( "/" ), "_" ); 291//US p.replace( QRegExp( "/" ), "_" );
290//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); 292//US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" );
291 KURL url(p); 293 KURL url(p);
292 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); 294 QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" );
293 295
294 ::unlink( QFile::encodeName( lockName ) ); 296 ::unlink( QFile::encodeName( lockName ) );
295 QFile::remove( mLockUniqueName ); 297 QFile::remove( mLockUniqueName );
296 addressBook()->emitAddressBookUnlocked(); 298 addressBook()->emitAddressBookUnlocked();
297#else 299#else
298 return; 300 return;
299#endif 301#endif
300} 302}
301 303
302void ResourceDir::setPath( const QString &path ) 304void ResourceDir::setPath( const QString &path )
303{ 305{
306#ifndef NO_DIRWATCH
304 mDirWatch.stopScan(); 307 mDirWatch.stopScan();
305 mDirWatch.removeDir( mPath ); 308 mDirWatch.removeDir( mPath );
306 309
307 mPath = path; 310 mPath = path;
308 311
309 mDirWatch.addDir( mPath, true ); 312 mDirWatch.addDir( mPath, true );
310 mDirWatch.startScan(); 313 mDirWatch.startScan();
311 314#else
315 mPath = path;
316#endif
312//US simulate KDirWatch event 317//US simulate KDirWatch event
313//US pathChanged(); 318//US pathChanged();
314 319
315} 320}
316 321
317QString ResourceDir::path() const 322QString ResourceDir::path() const
318{ 323{
319 return mPath; 324 return mPath;
320} 325}
321 326
322void ResourceDir::setFormat( const QString &format ) 327void ResourceDir::setFormat( const QString &format )
323{ 328{
324 mFormatName = format; 329 mFormatName = format;
325 330
326 if ( mFormat ) 331 if ( mFormat )
327 delete mFormat; 332 delete mFormat;
328 333
329 FormatFactory *factory = FormatFactory::self(); 334 FormatFactory *factory = FormatFactory::self();
330 mFormat = factory->format( mFormatName ); 335 mFormat = factory->format( mFormatName );
331/*US 336/*US
332qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); 337qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1());
333 if (mFormatName == "vcard") 338 if (mFormatName == "vcard")
334 mFormat = new VCardFormatPlugin2(); 339 mFormat = new VCardFormatPlugin2();
335 else if (mFormatName == "binary") 340 else if (mFormatName == "binary")
336 mFormat = new BinaryFormat(); 341 mFormat = new BinaryFormat();
337 else 342 else
338 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); 343 qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1());
339*/ 344*/
340 345
341} 346}
342 347
343QString ResourceDir::format() const 348QString ResourceDir::format() const
344{ 349{
345 return mFormatName; 350 return mFormatName;
346} 351}
347 352
348void ResourceDir::pathChanged() 353void ResourceDir::pathChanged()
349{ 354{
350 if ( !addressBook() ) 355 if ( !addressBook() )
351 return; 356 return;
352 357
353 QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); 358 QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) );
354 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 359 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
355 load(); 360 load();
356 addressBook()->emitAddressBookChanged(); 361 addressBook()->emitAddressBookChanged();
357 } 362 }
358} 363}
359 364
360void ResourceDir::removeAddressee( const Addressee& addr ) 365void ResourceDir::removeAddressee( const Addressee& addr )
361{ 366{
362 QFile::remove( mPath + "/" + addr.uid() ); 367 QFile::remove( mPath + "/" + addr.uid() );
363} 368}
364 369
365void ResourceDir::cleanUp() 370void ResourceDir::cleanUp()
366{ 371{
367 unlock( mPath ); 372 unlock( mPath );
368} 373}
369 374
370//US #include "resourcedir.moc" 375//US #include "resourcedir.moc"
diff --git a/kabc/plugins/dir/resourcedir.h b/kabc/plugins/dir/resourcedir.h
index c2aedad..77cd18c 100644
--- a/kabc/plugins/dir/resourcedir.h
+++ b/kabc/plugins/dir/resourcedir.h
@@ -1,115 +1,116 @@
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#ifndef KABC_RESOURCEDIR_H 28#ifndef KABC_RESOURCEDIR_H
29#define KABC_RESOURCEDIR_H 29#define KABC_RESOURCEDIR_H
30 30
31#include <kconfig.h> 31#include <kconfig.h>
32#include <kdirwatch.h> 32#include <kdirwatch.h>
33 33
34#include <sys/types.h> 34#include <sys/types.h>
35 35
36#include "resource.h" 36#include "resource.h"
37 37
38class QTimer; 38class QTimer;
39 39
40namespace KABC { 40namespace KABC {
41 41
42class FormatPlugin; 42class FormatPlugin;
43 43
44/** 44/**
45 @internal 45 @internal
46*/ 46*/
47class ResourceDir : public Resource 47class ResourceDir : public Resource
48{ 48{
49 Q_OBJECT 49 Q_OBJECT
50 50
51public: 51public:
52 ResourceDir( const KConfig*, bool syncable ); 52 ResourceDir( const KConfig*, bool syncable );
53 ~ResourceDir(); 53 ~ResourceDir();
54 54
55 virtual void writeConfig( KConfig* ); 55 virtual void writeConfig( KConfig* );
56 56
57 virtual bool doOpen(); 57 virtual bool doOpen();
58 virtual void doClose(); 58 virtual void doClose();
59 59
60 virtual Ticket *requestSaveTicket(); 60 virtual Ticket *requestSaveTicket();
61 61
62 virtual bool load(); 62 virtual bool load();
63 virtual bool save( Ticket * ); 63 virtual bool save( Ticket * );
64 64
65 /** 65 /**
66 * Set path to be used for saving. 66 * Set path to be used for saving.
67 */ 67 */
68 void setPath( const QString & ); 68 void setPath( const QString & );
69 69
70 /** 70 /**
71 * Return path used for loading and saving the address book. 71 * Return path used for loading and saving the address book.
72 */ 72 */
73 QString path() const; 73 QString path() const;
74 74
75 /** 75 /**
76 * Set the format by name. 76 * Set the format by name.
77 */ 77 */
78 void setFormat( const QString &format ); 78 void setFormat( const QString &format );
79 79
80 /** 80 /**
81 * Returns the format name. 81 * Returns the format name.
82 */ 82 */
83 QString format() const; 83 QString format() const;
84 84
85 /** 85 /**
86 * Remove a addressee from its source. 86 * Remove a addressee from its source.
87 * This method is mainly called by KABC::AddressBook. 87 * This method is mainly called by KABC::AddressBook.
88 */ 88 */
89 virtual void removeAddressee( const Addressee& addr ); 89 virtual void removeAddressee( const Addressee& addr );
90 90
91 /** 91 /**
92 * This method is called by an error handler if the application 92 * This method is called by an error handler if the application
93 * crashed 93 * crashed
94 */ 94 */
95 virtual void cleanUp(); 95 virtual void cleanUp();
96 96
97protected slots: 97protected slots:
98 void pathChanged(); 98 void pathChanged();
99 99
100protected: 100protected:
101 bool lock( const QString &path ); 101 bool lock( const QString &path );
102 void unlock( const QString &path ); 102 void unlock( const QString &path );
103 103
104private: 104private:
105 FormatPlugin *mFormat; 105 FormatPlugin *mFormat;
106 106
107#ifndef NO_DIRWATCH
107 KDirWatch mDirWatch; 108 KDirWatch mDirWatch;
108 109#endif
109 QString mPath; 110 QString mPath;
110 QString mFormatName; 111 QString mFormatName;
111 QString mLockUniqueName; 112 QString mLockUniqueName;
112}; 113};
113 114
114} 115}
115#endif 116#endif
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index 17263ae..b8c32d5 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -1,402 +1,408 @@
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 52#define NO_DIRWATCH
53#include "resourcefile.h" 53#include "resourcefile.h"
54#include "syncprefwidget.h" 54#include "syncprefwidget.h"
55 55
56//#define ALLOW_LOCKING 56//#define ALLOW_LOCKING
57 57
58
59
58using namespace KABC; 60using namespace KABC;
59 61
60extern "C" 62extern "C"
61#ifdef _WIN32_ 63#ifdef _WIN32_
62__declspec(dllexport) 64__declspec(dllexport)
63#else 65#else
64{ 66{
65#endif 67#endif
66 68
67//US void *init_kabc_file() 69//US void *init_kabc_file()
68 void *init_microkabc_file() 70 void *init_microkabc_file()
69 { 71 {
70 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); 72 return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>();
71 } 73 }
72#ifndef _WIN32_ 74#ifndef _WIN32_
73} 75}
74#endif 76#endif
75 77
76ResourceFile::ResourceFile( const KConfig *config, bool syncable ) 78ResourceFile::ResourceFile( const KConfig *config, bool syncable )
77 : Resource( config, syncable ) , mFormat( 0 ) 79 : Resource( config, syncable ) , mFormat( 0 )
78{ 80{
79 QString fileName, formatName, default_fileName; 81 QString fileName, formatName, default_fileName;
80 82
81 if (syncable == true) 83 if (syncable == true)
82 default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; 84 default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf";
83 else 85 else
84 default_fileName = StdAddressBook::fileName(); 86 default_fileName = StdAddressBook::fileName();
85 87
86 KConfig *cfg = (KConfig *)config; 88 KConfig *cfg = (KConfig *)config;
87 if ( cfg ) { 89 if ( cfg ) {
88 fileName = cfg->readEntry( "FileName", default_fileName ); 90 fileName = cfg->readEntry( "FileName", default_fileName );
89 formatName = cfg->readEntry( "FileFormat", "vcard" ); 91 formatName = cfg->readEntry( "FileFormat", "vcard" );
90 } else { 92 } else {
91 fileName = default_fileName; 93 fileName = default_fileName;
92 formatName = "vcard"; 94 formatName = "vcard";
93 } 95 }
94 96
95 init( fileName, formatName ); 97 init( fileName, formatName );
96} 98}
97 99
98ResourceFile::ResourceFile( const QString &fileName, bool syncable , 100ResourceFile::ResourceFile( const QString &fileName, bool syncable ,
99 const QString &formatName ) 101 const QString &formatName )
100 : Resource( 0, syncable ) 102 : Resource( 0, syncable )
101{ 103{
102// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); 104// qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1());
103 init( fileName, formatName ); 105 init( fileName, formatName );
104} 106}
105 107
106void ResourceFile::init( const QString &fileName, const QString &formatName ) 108void ResourceFile::init( const QString &fileName, const QString &formatName )
107{ 109{
108 mFormatName = formatName; 110 mFormatName = formatName;
109 111
110 FormatFactory *factory = FormatFactory::self(); 112 FormatFactory *factory = FormatFactory::self();
111 mFormat = factory->format( mFormatName ); 113 mFormat = factory->format( mFormatName );
112 114
113 if ( !mFormat ) { 115 if ( !mFormat ) {
114 mFormatName = "vcard"; 116 mFormatName = "vcard";
115 mFormat = factory->format( mFormatName ); 117 mFormat = factory->format( mFormatName );
116 } 118 }
117 119
118 120#ifndef NO_DIRWATCH
119 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); 121 connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) );
120 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); 122 connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) );
121 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); 123 connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) );
122 124#endif
123 setFileName( fileName ); 125 setFileName( fileName );
124} 126}
125 127
126ResourceFile::~ResourceFile() 128ResourceFile::~ResourceFile()
127{ 129{
128 delete mFormat; 130 delete mFormat;
129 mFormat = 0; 131 mFormat = 0;
130} 132}
131 133
132void ResourceFile::writeConfig( KConfig *config ) 134void ResourceFile::writeConfig( KConfig *config )
133{ 135{
134 136
135 config->setGroup( "Resource_" + identifier() ); 137 config->setGroup( "Resource_" + identifier() );
136 Resource::writeConfig( config ); 138 Resource::writeConfig( config );
137 139
138 config->writeEntry( "FileName", mFileName ); 140 config->writeEntry( "FileName", mFileName );
139 config->writeEntry( "FileFormat", mFormatName ); 141 config->writeEntry( "FileFormat", mFormatName );
140 142
141// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 143// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
142 144
143} 145}
144 146
145Ticket *ResourceFile::requestSaveTicket() 147Ticket *ResourceFile::requestSaveTicket()
146{ 148{
147 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 149 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
148 150
149 if ( !addressBook() ) return 0; 151 if ( !addressBook() ) return 0;
150 152
151#ifdef ALLOW_LOCKING 153#ifdef ALLOW_LOCKING
152 if ( !lock( mFileName ) ) { 154 if ( !lock( mFileName ) ) {
153 qDebug("unablt to lock file "); 155 qDebug("unablt to lock file ");
154 return 0; 156 return 0;
155 } 157 }
156#endif 158#endif
157 return createTicket( this ); 159 return createTicket( this );
158} 160}
159 161
160 162
161bool ResourceFile::doOpen() 163bool ResourceFile::doOpen()
162{ 164{
163 QFile file( mFileName ); 165 QFile file( mFileName );
164 166
165 if ( !file.exists() ) { 167 if ( !file.exists() ) {
166 // try to create the file 168 // try to create the file
167 bool ok = file.open( IO_WriteOnly ); 169 bool ok = file.open( IO_WriteOnly );
168 if ( ok ) 170 if ( ok )
169 file.close(); 171 file.close();
170 172
171 return ok; 173 return ok;
172 } else { 174 } else {
173 if ( !file.open( IO_ReadWrite ) ) 175 if ( !file.open( IO_ReadWrite ) )
174 return false; 176 return false;
175 177
176 if ( file.size() == 0 ) { 178 if ( file.size() == 0 ) {
177 file.close(); 179 file.close();
178 return true; 180 return true;
179 } 181 }
180 182
181 bool ok = mFormat->checkFormat( &file ); 183 bool ok = mFormat->checkFormat( &file );
182 file.close(); 184 file.close();
183 185
184 return ok; 186 return ok;
185 } 187 }
186} 188}
187 189
188void ResourceFile::doClose() 190void ResourceFile::doClose()
189{ 191{
190} 192}
191 193
192bool ResourceFile::load() 194bool ResourceFile::load()
193{ 195{
194 196
195 197
196 QFile file( mFileName ); 198 QFile file( mFileName );
197 if ( !file.open( IO_ReadOnly ) ) { 199 if ( !file.open( IO_ReadOnly ) ) {
198 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); 200 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
199 return false; 201 return false;
200 } 202 }
201 203
202// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 204// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
203 205
204 return mFormat->loadAll( addressBook(), this, &file ); 206 return mFormat->loadAll( addressBook(), this, &file );
205} 207}
206 208
207bool ResourceFile::save( Ticket *ticket ) 209bool ResourceFile::save( Ticket *ticket )
208{ 210{
209// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 211// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
210 212
211 213
212 // create backup file 214 // create backup file
213 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 215 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
214 216
215/*US we use a simpler method to create a backupfile 217/*US we use a simpler method to create a backupfile
216 218
217 (void) KSaveFile::backupFile( mFileName, QString::null 219 (void) KSaveFile::backupFile( mFileName, QString::null
218 ,extension ); 220 ,extension );
219 221
220 KSaveFile saveFile( mFileName ); 222 KSaveFile saveFile( mFileName );
221 bool ok = false; 223 bool ok = false;
222 if ( saveFile.status() == 0 && saveFile.file() ) 224 if ( saveFile.status() == 0 && saveFile.file() )
223 { 225 {
224 mFormat->saveAll( addressBook(), this, saveFile.file() ); 226 mFormat->saveAll( addressBook(), this, saveFile.file() );
225 ok = saveFile.close(); 227 ok = saveFile.close();
226 } 228 }
227*/ 229*/
228 230
229//US ToDo: write backupfile 231//US ToDo: write backupfile
232#ifndef NO_DIRWATCH
230 mDirWatch.stopScan(); 233 mDirWatch.stopScan();
231 234#endif
232 QFile info; 235 QFile info;
233 info.setName( mFileName ); 236 info.setName( mFileName );
234 bool ok = info.open( IO_WriteOnly ); 237 bool ok = info.open( IO_WriteOnly );
235 if ( ok ) { 238 if ( ok ) {
236 mFormat->saveAll( addressBook(), this, &info ); 239 mFormat->saveAll( addressBook(), this, &info );
237 240
238 info.close(); 241 info.close();
239 ok = true; 242 ok = true;
240 } 243 }
241 else { 244 else {
242 245
243 } 246 }
244 247
245 if ( !ok ) 248 if ( !ok )
246 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); 249 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
247 250#ifndef NO_DIRWATCH
248 mDirWatch.startScan(); 251 mDirWatch.startScan();
249 252#endif
250 delete ticket; 253 delete ticket;
251#ifdef ALLOW_LOCKING 254#ifdef ALLOW_LOCKING
252 unlock( mFileName ); 255 unlock( mFileName );
253#endif 256#endif
254 257
255 return ok; 258 return ok;
256} 259}
257 260
258bool ResourceFile::lock( const QString &fileName ) 261bool ResourceFile::lock( const QString &fileName )
259{ 262{
260#ifdef ALLOW_LOCKING 263#ifdef ALLOW_LOCKING
261 264
262 265
263 QString fn = fileName; 266 QString fn = fileName;
264 267
265//US change the implementation how the lockfilename is getting created 268//US change the implementation how the lockfilename is getting created
266//US fn.replace( QRegExp("/"), "_" ); 269//US fn.replace( QRegExp("/"), "_" );
267//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 270//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
268 271
269 KURL url(fn); 272 KURL url(fn);
270 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 273 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
271 274
272 275
273 276
274 if (QFile::exists( lockName )) return false; 277 if (QFile::exists( lockName )) return false;
275 278
276 QString lockUniqueName; 279 QString lockUniqueName;
277 lockUniqueName = fn + KApplication::randomString( 8 ); 280 lockUniqueName = fn + KApplication::randomString( 8 );
278 281
279 url = lockUniqueName; 282 url = lockUniqueName;
280//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 283//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
281 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 284 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
282 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 285 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
283 286
284 // Create unique file 287 // Create unique file
285 QFile file( mLockUniqueName ); 288 QFile file( mLockUniqueName );
286 file.open( IO_WriteOnly ); 289 file.open( IO_WriteOnly );
287 file.close(); 290 file.close();
288 291
289 // Create lock file 292 // Create lock file
290 int result = 0; 293 int result = 0;
291#ifndef _WIN32_ 294#ifndef _WIN32_
292 result = ::link( QFile::encodeName( mLockUniqueName ), 295 result = ::link( QFile::encodeName( mLockUniqueName ),
293 QFile::encodeName( lockName ) ); 296 QFile::encodeName( lockName ) );
294#endif 297#endif
295 if ( result == 0 ) { 298 if ( result == 0 ) {
296 addressBook()->emitAddressBookLocked(); 299 addressBook()->emitAddressBookLocked();
297 return true; 300 return true;
298 } 301 }
299 302
300 // TODO: check stat 303 // TODO: check stat
301 304
302 return false; 305 return false;
303#else 306#else
304 return true; 307 return true;
305#endif 308#endif
306} 309}
307 310
308void ResourceFile::unlock( const QString &fileName ) 311void ResourceFile::unlock( const QString &fileName )
309{ 312{
310#ifdef ALLOW_LOCKING 313#ifdef ALLOW_LOCKING
311 QString fn = fileName; 314 QString fn = fileName;
312//US change the implementation how the lockfilename is getting created 315//US change the implementation how the lockfilename is getting created
313//US fn.replace( QRegExp( "/" ), "_" ); 316//US fn.replace( QRegExp( "/" ), "_" );
314//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 317//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
315//US QString lockName = fn + ".lock"; 318//US QString lockName = fn + ".lock";
316 KURL url(fn); 319 KURL url(fn);
317 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 320 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
318 321
319 QFile::remove( lockName ); 322 QFile::remove( lockName );
320 QFile::remove( mLockUniqueName ); 323 QFile::remove( mLockUniqueName );
321 addressBook()->emitAddressBookUnlocked(); 324 addressBook()->emitAddressBookUnlocked();
322#else 325#else
323 return; 326 return;
324#endif 327#endif
325} 328}
326 329
327void ResourceFile::setFileName( const QString &fileName ) 330void ResourceFile::setFileName( const QString &fileName )
328{ 331{
332#ifndef NO_DIRWATCH
329 mDirWatch.stopScan(); 333 mDirWatch.stopScan();
330 mDirWatch.removeFile( mFileName ); 334 mDirWatch.removeFile( mFileName );
331
332 mFileName = fileName; 335 mFileName = fileName;
333 336
334 337
335 mDirWatch.addFile( mFileName ); 338 mDirWatch.addFile( mFileName );
336 mDirWatch.startScan(); 339 mDirWatch.startScan();
340#else
341 mFileName = fileName;
342#endif
337 343
338//US simulate KDirWatch event 344//US simulate KDirWatch event
339//US fileChanged(); 345//US fileChanged();
340} 346}
341 347
342QString ResourceFile::fileName() const 348QString ResourceFile::fileName() const
343{ 349{
344 return mFileName; 350 return mFileName;
345} 351}
346 352
347void ResourceFile::setFormat( const QString &format ) 353void ResourceFile::setFormat( const QString &format )
348{ 354{
349 mFormatName = format; 355 mFormatName = format;
350 delete mFormat; 356 delete mFormat;
351 357
352 FormatFactory *factory = FormatFactory::self(); 358 FormatFactory *factory = FormatFactory::self();
353 mFormat = factory->format( mFormatName ); 359 mFormat = factory->format( mFormatName );
354/*US 360/*US
355//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); 361//qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1());
356 if (mFormatName == "vcard") { 362 if (mFormatName == "vcard") {
357 mFormat = new VCardFormatPlugin2(); 363 mFormat = new VCardFormatPlugin2();
358// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 364// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
359 } 365 }
360 else if (mFormatName == "binary") { 366 else if (mFormatName == "binary") {
361 mFormat = new BinaryFormat(); 367 mFormat = new BinaryFormat();
362// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); 368// qDebug("ResourceFile::setFormat format %s", mFormatName.latin1());
363 } 369 }
364 else 370 else
365 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); 371 qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1());
366*/ 372*/
367 373
368} 374}
369 375
370QString ResourceFile::format() const 376QString ResourceFile::format() const
371{ 377{
372 return mFormatName; 378 return mFormatName;
373} 379}
374 380
375void ResourceFile::fileChanged() 381void ResourceFile::fileChanged()
376{ 382{
377 // There is a small theoretical chance that KDirWatch calls us before 383 // There is a small theoretical chance that KDirWatch calls us before
378 // we are fully constructed 384 // we are fully constructed
379 if (!addressBook()) 385 if (!addressBook())
380 return; 386 return;
381 387
382 388
383 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); 389 QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) );
384 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { 390 if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) {
385 load(); 391 load();
386 addressBook()->emitAddressBookChanged(); 392 addressBook()->emitAddressBookChanged();
387 } 393 }
388} 394}
389 395
390void ResourceFile::removeAddressee( const Addressee &addr ) 396void ResourceFile::removeAddressee( const Addressee &addr )
391{ 397{
392 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); 398 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) );
393 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); 399 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) );
394 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); 400 QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) );
395} 401}
396 402
397void ResourceFile::cleanUp() 403void ResourceFile::cleanUp()
398{ 404{
399 unlock( mFileName ); 405 unlock( mFileName );
400} 406}
401 407
402//US #include "resourcefile.moc" 408//US #include "resourcefile.moc"
diff --git a/kabc/plugins/file/resourcefile.h b/kabc/plugins/file/resourcefile.h
index 0a3027c..8339340 100644
--- a/kabc/plugins/file/resourcefile.h
+++ b/kabc/plugins/file/resourcefile.h
@@ -28,135 +28,136 @@ $Id$
28 28
29#ifndef KABC_RESOURCEFILE_H 29#ifndef KABC_RESOURCEFILE_H
30#define KABC_RESOURCEFILE_H 30#define KABC_RESOURCEFILE_H
31 31
32#include <kconfig.h> 32#include <kconfig.h>
33#include <kdirwatch.h> 33#include <kdirwatch.h>
34 34
35#include <sys/types.h> 35#include <sys/types.h>
36 36
37#include <resource.h> 37#include <resource.h>
38 38
39class QTimer; 39class QTimer;
40class FormatPlugin; 40class FormatPlugin;
41 41
42namespace KABC { 42namespace KABC {
43 43
44//US class FormatPlugin; 44//US class FormatPlugin;
45class ResourceConfigWidget; 45class ResourceConfigWidget;
46 46
47/** 47/**
48 @internal 48 @internal
49*/ 49*/
50class ResourceFile : public Resource 50class ResourceFile : public Resource
51{ 51{
52 Q_OBJECT 52 Q_OBJECT
53 53
54public: 54public:
55 55
56 /** 56 /**
57 Constructor. 57 Constructor.
58 58
59 @param cfg The config object where custom resource settings are stored. 59 @param cfg The config object where custom resource settings are stored.
60 */ 60 */
61 ResourceFile( const KConfig *cfg, bool syncable ); 61 ResourceFile( const KConfig *cfg, bool syncable );
62 62
63 /** 63 /**
64 Construct file resource on file @arg fileName using format @arg formatName. 64 Construct file resource on file @arg fileName using format @arg formatName.
65 */ 65 */
66 ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" ); 66 ResourceFile( const QString &fileName, bool syncable , const QString &formatName = "vcard" );
67 67
68 /** 68 /**
69 * Destructor. 69 * Destructor.
70 */ 70 */
71 ~ResourceFile(); 71 ~ResourceFile();
72 72
73 /** 73 /**
74 Writes the config back. 74 Writes the config back.
75 */ 75 */
76 virtual void writeConfig( KConfig *cfg ); 76 virtual void writeConfig( KConfig *cfg );
77 77
78 /** 78 /**
79 * Tries to open the file and checks for the proper format. 79 * Tries to open the file and checks for the proper format.
80 * This method should be called before @ref load(). 80 * This method should be called before @ref load().
81 */ 81 */
82 virtual bool doOpen(); 82 virtual bool doOpen();
83 83
84 /** 84 /**
85 * Closes the file again. 85 * Closes the file again.
86 */ 86 */
87 virtual void doClose(); 87 virtual void doClose();
88 88
89 /** 89 /**
90 * Requests a save ticket, that is used by @ref save() 90 * Requests a save ticket, that is used by @ref save()
91 */ 91 */
92 virtual Ticket *requestSaveTicket(); 92 virtual Ticket *requestSaveTicket();
93 93
94 /** 94 /**
95 * Loads all addressees from file to the address book. 95 * Loads all addressees from file to the address book.
96 * Returns true if all addressees could be loaded otherwise false. 96 * Returns true if all addressees could be loaded otherwise false.
97 */ 97 */
98 virtual bool load(); 98 virtual bool load();
99 99
100 /** 100 /**
101 * Saves all addresses from address book to file. 101 * Saves all addresses from address book to file.
102 * Returns true if all addressees could be saved otherwise false. 102 * Returns true if all addressees could be saved otherwise false.
103 * 103 *
104 * @param ticket The ticket returned by @ref requestSaveTicket() 104 * @param ticket The ticket returned by @ref requestSaveTicket()
105 */ 105 */
106 virtual bool save( Ticket *ticket ); 106 virtual bool save( Ticket *ticket );
107 107
108 /** 108 /**
109 * Set name of file to be used for saving. 109 * Set name of file to be used for saving.
110 */ 110 */
111 void setFileName( const QString & ); 111 void setFileName( const QString & );
112 112
113 /** 113 /**
114 * Return name of file used for loading and saving the address book. 114 * Return name of file used for loading and saving the address book.
115 */ 115 */
116 QString fileName() const; 116 QString fileName() const;
117 117
118 /** 118 /**
119 Sets a new format by name. 119 Sets a new format by name.
120 */ 120 */
121 void setFormat( const QString &name ); 121 void setFormat( const QString &name );
122 122
123 /** 123 /**
124 Returns the format name. 124 Returns the format name.
125 */ 125 */
126 QString format() const; 126 QString format() const;
127 127
128 /** 128 /**
129 * Remove a addressee from its source. 129 * Remove a addressee from its source.
130 * This method is mainly called by KABC::AddressBook. 130 * This method is mainly called by KABC::AddressBook.
131 */ 131 */
132 virtual void removeAddressee( const Addressee& addr ); 132 virtual void removeAddressee( const Addressee& addr );
133 133
134 /** 134 /**
135 * This method is called by an error handler if the application 135 * This method is called by an error handler if the application
136 * crashed 136 * crashed
137 */ 137 */
138 virtual void cleanUp(); 138 virtual void cleanUp();
139 139
140protected slots: 140protected slots:
141 void fileChanged(); 141 void fileChanged();
142 142
143protected: 143protected:
144 void init( const QString &fileName, const QString &format ); 144 void init( const QString &fileName, const QString &format );
145 145
146 bool lock( const QString &fileName ); 146 bool lock( const QString &fileName );
147 void unlock( const QString &fileName ); 147 void unlock( const QString &fileName );
148 148
149private: 149private:
150 QString mFileName; 150 QString mFileName;
151 QString mFormatName; 151 QString mFormatName;
152 152
153 FormatPlugin *mFormat; 153 FormatPlugin *mFormat;
154 154
155 QString mLockUniqueName; 155 QString mLockUniqueName;
156 156#ifndef NO_DIRWATCH
157 KDirWatch mDirWatch; 157 KDirWatch mDirWatch;
158#endif
158}; 159};
159 160
160} 161}
161 162
162#endif 163#endif
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp
index 1a3a22c..02c5fb1 100644
--- a/microkde/kresources/configpage.cpp
+++ b/microkde/kresources/configpage.cpp
@@ -1,255 +1,255 @@
1/* 1/*
2 This file is part of libkresources. 2 This file is part of libkresources.
3 3
4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> 4 Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> 5 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 6 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
7 7
8 This library is free software; you can redistribute it and/or 8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Library General Public 9 modify it under the terms of the GNU Library General Public
10 License as published by the Free Software Foundation; either 10 License as published by the Free Software Foundation; either
11 version 2 of the License, or (at your option) any later version. 11 version 2 of the License, or (at your option) any later version.
12 12
13 This library is distributed in the hope that it will be useful, 13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Library General Public License for more details. 16 Library General Public License for more details.
17 17
18 You should have received a copy of the GNU Library General Public License 18 You should have received a copy of the GNU Library General Public License
19 along with this library; see the file COPYING.LIB. If not, write to 19 along with this library; see the file COPYING.LIB. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. 21 Boston, MA 02111-1307, USA.
22*/ 22*/
23 23
24/* 24/*
25Enhanced Version of the file for platform independent KDE tools. 25Enhanced Version of the file for platform independent KDE tools.
26Copyright (c) 2004 Ulf Schenk 26Copyright (c) 2004 Ulf Schenk
27 27
28$Id$ 28$Id$
29*/ 29*/
30 30
31#include <qgroupbox.h> 31#include <qgroupbox.h>
32#include <qinputdialog.h> 32#include <qinputdialog.h>
33#include <qlabel.h> 33#include <qlabel.h>
34#include <qlayout.h> 34#include <qlayout.h>
35 35
36#include <kapplication.h> 36#include <kapplication.h>
37#include <kcombobox.h> 37#include <kcombobox.h>
38#include <kdebug.h> 38#include <kdebug.h>
39#include <klocale.h> 39#include <klocale.h>
40#include <kmessagebox.h> 40#include <kmessagebox.h>
41#include <ksimpleconfig.h> 41#include <ksimpleconfig.h>
42#include <kstandarddirs.h> 42#include <kstandarddirs.h>
43#include <kurlrequester.h> 43#include <kurlrequester.h>
44#include <klistview.h> 44#include <klistview.h>
45#include <kbuttonbox.h> 45#include <kbuttonbox.h>
46//US #include <ktrader.h> 46//US #include <ktrader.h>
47 47
48#include "resource.h" 48#include "resource.h"
49#include "configdialog.h" 49#include "configdialog.h"
50 50
51#include "configpage.h" 51#include "configpage.h"
52 52
53//US 53//US
54#include <qpushbutton.h> 54#include <qpushbutton.h>
55#include <qfile.h> 55#include <qfile.h>
56#include <kglobal.h> 56#include <kglobal.h>
57 57
58using namespace KRES; 58using namespace KRES;
59 59
60const QString ConfigPage::syncfamily = "syncprofiles"; 60const QString ConfigPage::syncfamily = "syncprofiles";
61 61
62 62
63class ConfigViewItem : public QCheckListItem 63class ConfigViewItem : public QCheckListItem
64{ 64{
65 public: 65 public:
66 ConfigViewItem( QListView *parent, Resource* resource ) : 66 ConfigViewItem( QListView *parent, Resource* resource ) :
67 QCheckListItem( parent, resource->resourceName(), CheckBox ), 67 QCheckListItem( parent, resource->resourceName(), CheckBox ),
68 mResource( resource ), 68 mResource( resource ),
69 mIsStandard( false ) 69 mIsStandard( false )
70 { 70 {
71 setText( 1, mResource->type() ); 71 setText( 1, mResource->type() );
72 setOn( mResource->isActive() ); 72 setOn( mResource->isActive() );
73 } 73 }
74 74
75 void setStandard( bool value ) 75 void setStandard( bool value )
76 { 76 {
77 setText( 2, ( value ? i18n( "Yes" ) : QString::null ) ); 77 setText( 2, ( value ? i18n( "Yes" ) : QString::null ) );
78 mIsStandard = value; 78 mIsStandard = value;
79 } 79 }
80 80
81 bool standard() const { return mIsStandard; } 81 bool standard() const { return mIsStandard; }
82 bool readOnly() const { return mResource->readOnly(); } 82 bool readOnly() const { return mResource->readOnly(); }
83 83
84 Resource *resource() { return mResource; } 84 Resource *resource() { return mResource; }
85 85
86 private: 86 private:
87 Resource* mResource; 87 Resource* mResource;
88 88
89 bool mIsStandard; 89 bool mIsStandard;
90}; 90};
91 91
92ConfigPage::ConfigPage( QWidget *parent, const char *name ) 92ConfigPage::ConfigPage( QWidget *parent, const char *name )
93 : QWidget( parent, name ), 93 : QWidget( parent, name ),
94 mCurrentManager( 0 ), 94 mCurrentManager( 0 ),
95 mCurrentConfig( 0 ) 95 mCurrentConfig( 0 )
96{ 96{
97 setCaption( i18n( "Resource Configuration" ) ); 97 setCaption( i18n( "Resource Configuration" ) );
98 98
99 QVBoxLayout *mainLayout = new QVBoxLayout( this ); 99 QVBoxLayout *mainLayout = new QVBoxLayout( this );
100 100
101 QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this ); 101 QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this );
102 groupBox->setColumnLayout(0, Qt::Vertical ); 102 groupBox->setColumnLayout(0, Qt::Vertical );
103 groupBox->layout()->setSpacing( 6 ); 103 groupBox->layout()->setSpacing( 3 );
104 groupBox->layout()->setMargin( 11 ); 104 groupBox->layout()->setMargin( 5 );
105 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 ); 105 QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 4, 2 );
106 106
107//US mFamilyCombo = new KComboBox( false, groupBox ); 107//US mFamilyCombo = new KComboBox( false, groupBox );
108 mFamilyCombo = new KComboBox( groupBox ); 108 mFamilyCombo = new KComboBox( groupBox );
109 groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 ); 109 groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 );
110 110
111 mListView = new KListView( groupBox ); 111 mListView = new KListView( groupBox );
112 mListView->setAllColumnsShowFocus( true ); 112 mListView->setAllColumnsShowFocus( true );
113 mListView->addColumn( i18n( "Name" ) ); 113 mListView->addColumn( i18n( "Name" ) );
114 mListView->addColumn( i18n( "Type" ) ); 114 mListView->addColumn( i18n( "Type" ) );
115 mListView->addColumn( i18n( "Standard" ) ); 115 mListView->addColumn( i18n( "Standard" ) );
116 116
117//US groupBoxLayout->addWidget( mListView, 1, 0 ); 117//US groupBoxLayout->addWidget( mListView, 1, 0 );
118 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); 118 groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 );
119 119
120 120
121 mAddButton = new QPushButton( i18n( "&Add..." ), this ); 121 mAddButton = new QPushButton( i18n( "&Add..." ), groupBox );
122 groupBoxLayout->addWidget( mAddButton, 2, 0 ); 122 groupBoxLayout->addWidget( mAddButton, 2, 0 );
123 mRemoveButton = new QPushButton( i18n( "&Remove" ), this ); 123 mRemoveButton = new QPushButton( i18n( "&Remove" ), groupBox );
124 groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); 124 groupBoxLayout->addWidget( mRemoveButton, 2, 1 );
125 mEditButton = new QPushButton( i18n( "&Edit..." ), this ); 125 mEditButton = new QPushButton( i18n( "&Edit..." ), groupBox );
126 groupBoxLayout->addWidget( mEditButton, 3, 0 ); 126 groupBoxLayout->addWidget( mEditButton, 3, 0 );
127 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), this ); 127 mStandardButton = new QPushButton( i18n( "&Use as Standard" ), groupBox );
128 groupBoxLayout->addWidget( mStandardButton, 3, 1 ); 128 groupBoxLayout->addWidget( mStandardButton, 3, 1 );
129 129
130 mRemoveButton->setEnabled( false ); 130 mRemoveButton->setEnabled( false );
131 mEditButton->setEnabled( false ); 131 mEditButton->setEnabled( false );
132 mStandardButton->setEnabled( false ); 132 mStandardButton->setEnabled( false );
133 133
134 134
135 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); 135 connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) );
136 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); 136 connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) );
137 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); 137 connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) );
138 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); 138 connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) );
139 139
140 140
141 mainLayout->addWidget( groupBox ); 141 mainLayout->addWidget( groupBox );
142 142
143 connect( mFamilyCombo, SIGNAL( activated( int ) ), 143 connect( mFamilyCombo, SIGNAL( activated( int ) ),
144 SLOT( slotFamilyChanged( int ) ) ); 144 SLOT( slotFamilyChanged( int ) ) );
145 connect( mListView, SIGNAL( selectionChanged() ), 145 connect( mListView, SIGNAL( selectionChanged() ),
146 SLOT( slotSelectionChanged() ) ); 146 SLOT( slotSelectionChanged() ) );
147 connect( mListView, SIGNAL( clicked( QListViewItem * ) ), 147 connect( mListView, SIGNAL( clicked( QListViewItem * ) ),
148 SLOT( slotItemClicked( QListViewItem * ) ) ); 148 SLOT( slotItemClicked( QListViewItem * ) ) );
149 149
150 mLastItem = 0; 150 mLastItem = 0;
151 151
152//US mConfig = new KConfig( "kcmkresourcesrc" ); 152//US mConfig = new KConfig( "kcmkresourcesrc" );
153 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); 153 mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") );
154 mConfig->setGroup( "General" ); 154 mConfig->setGroup( "General" );
155 155
156 load(); 156 load();
157} 157}
158 158
159ConfigPage::~ConfigPage() 159ConfigPage::~ConfigPage()
160{ 160{
161 QValueList<ResourcePageInfo>::Iterator it; 161 QValueList<ResourcePageInfo>::Iterator it;
162 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { 162 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) {
163 (*it).mManager->removeListener( this ); 163 (*it).mManager->removeListener( this );
164 delete (*it).mManager; 164 delete (*it).mManager;
165 delete (*it).mConfig; 165 delete (*it).mConfig;
166 } 166 }
167 167
168 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); 168 mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() );
169 delete mConfig; 169 delete mConfig;
170 mConfig = 0; 170 mConfig = 0;
171} 171}
172 172
173void ConfigPage::load() 173void ConfigPage::load()
174{ 174{
175 kdDebug(5650) << "ConfigPage::load()" << endl; 175 kdDebug(5650) << "ConfigPage::load()" << endl;
176 176
177 mListView->clear(); 177 mListView->clear();
178 178
179//US we remove the dynamic pluginloader, and set the one family we need (contact) manually. 179//US we remove the dynamic pluginloader, and set the one family we need (contact) manually.
180 180
181//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); 181//US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" );
182//US KTrader::OfferList::ConstIterator it; 182//US KTrader::OfferList::ConstIterator it;
183//US for ( it = plugins.begin(); it != plugins.end(); ++it ) { 183//US for ( it = plugins.begin(); it != plugins.end(); ++it ) {
184//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); 184//US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" );
185//US QString family = tmp.toString(); 185//US QString family = tmp.toString();
186 QStringList families; 186 QStringList families;
187 families << "contact" << syncfamily; 187 families << "contact" << syncfamily;
188 188
189 189
190 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) 190 for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it )
191 { 191 {
192 QString family = (*it); 192 QString family = (*it);
193 if ( !family.isEmpty() ) { 193 if ( !family.isEmpty() ) {
194 if ( !mFamilyMap.contains( family ) ) { 194 if ( !mFamilyMap.contains( family ) ) {
195 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); 195 mCurrentManager = new Manager<Resource>( family, (family == syncfamily) );
196 if ( mCurrentManager ) { 196 if ( mCurrentManager ) {
197 mFamilyMap.append( family ); 197 mFamilyMap.append( family );
198 mCurrentManager->addListener( this ); 198 mCurrentManager->addListener( this );
199 199
200 ResourcePageInfo info; 200 ResourcePageInfo info;
201 info.mManager = mCurrentManager; 201 info.mManager = mCurrentManager;
202 QString configDir = KGlobal::dirs()->saveLocation( "config" ); 202 QString configDir = KGlobal::dirs()->saveLocation( "config" );
203 //QString configDir = KStandardDirs::appDir() + "/config"; 203 //QString configDir = KStandardDirs::appDir() + "/config";
204 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { 204 if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) {
205 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); 205 info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) );
206 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { 206 } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) {
207 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); 207 info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) );
208 } else if ( family == syncfamily && QFile::exists( configDir + "/kabcsyncrc" ) ) { 208 } else if ( family == syncfamily && QFile::exists( configDir + "/kabcsyncrc" ) ) {
209 info.mConfig = new KConfig( locateLocal( "config", "kabcsyncrc" ) ); 209 info.mConfig = new KConfig( locateLocal( "config", "kabcsyncrc" ) );
210 } else { 210 } else {
211 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); 211 QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) );
212 info.mConfig = new KConfig( configFile ); 212 info.mConfig = new KConfig( configFile );
213 } 213 }
214 info.mManager->readConfig( info.mConfig ); 214 info.mManager->readConfig( info.mConfig );
215 215
216 mInfoMap.append( info ); 216 mInfoMap.append( info );
217 } 217 }
218 } 218 }
219 } 219 }
220 } 220 }
221 mCurrentManager = 0; 221 mCurrentManager = 0;
222 222
223 mFamilyCombo->insertStringList( mFamilyMap ); 223 mFamilyCombo->insertStringList( mFamilyMap );
224 224
225 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); 225 int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 );
226 mFamilyCombo->setCurrentItem( currentFamily ); 226 mFamilyCombo->setCurrentItem( currentFamily );
227 slotFamilyChanged( currentFamily ); 227 slotFamilyChanged( currentFamily );
228} 228}
229 229
230void ConfigPage::save() 230void ConfigPage::save()
231{ 231{
232 saveResourceSettings(); 232 saveResourceSettings();
233 233
234 QValueList<ResourcePageInfo>::Iterator it; 234 QValueList<ResourcePageInfo>::Iterator it;
235 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) 235 for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it )
236 (*it).mManager->writeConfig( (*it).mConfig ); 236 (*it).mManager->writeConfig( (*it).mConfig );
237 237
238 emit changed( false ); 238 emit changed( false );
239} 239}
240 240
241void ConfigPage::defaults() 241void ConfigPage::defaults()
242{ 242{
243} 243}
244 244
245void ConfigPage::slotFamilyChanged( int pos ) 245void ConfigPage::slotFamilyChanged( int pos )
246{ 246{
247 if ( pos < 0 || pos >= (int)mFamilyMap.count() ) 247 if ( pos < 0 || pos >= (int)mFamilyMap.count() )
248 return; 248 return;
249 249
250 saveResourceSettings(); 250 saveResourceSettings();
251 251
252 mFamily = mFamilyMap[ pos ]; 252 mFamily = mFamilyMap[ pos ];
253 253
254//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); 254//US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1());
255 255