summaryrefslogtreecommitdiffabout
path: root/kabc/plugins/file
authorMichael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
committer Michael Krelin <hacker@klever.net>2007-07-04 11:23:42 (UTC)
commita08aff328d4393031d5ba7d622c2b05705a89d73 (patch) (unidiff)
tree8ee90d686081c52e7c69b5ce946e9b1a7d690001 /kabc/plugins/file
parent11edc920afe4f274c0964436633aa632c8288a40 (diff)
downloadkdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.zip
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.gz
kdepimpi-a08aff328d4393031d5ba7d622c2b05705a89d73.tar.bz2
initial public commit of qt4 portp1
Diffstat (limited to 'kabc/plugins/file') (more/less context) (ignore whitespace changes)
-rw-r--r--kabc/plugins/file/file.pro14
-rw-r--r--kabc/plugins/file/fileE.pro4
-rw-r--r--kabc/plugins/file/resourcefile.cpp10
-rw-r--r--kabc/plugins/file/resourcefileconfig.cpp4
4 files changed, 19 insertions, 13 deletions
diff --git a/kabc/plugins/file/file.pro b/kabc/plugins/file/file.pro
index 2d17313..e4f1270 100644
--- a/kabc/plugins/file/file.pro
+++ b/kabc/plugins/file/file.pro
@@ -1,37 +1,41 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3#release debug 3#release debug
4 4
5include( ../../../variables.pri ) 5include( ../../../variables.pri )
6 6
7TARGET = microkabc_file 7TARGET = xmicrokabc_file
8INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat 8INCLUDEPATH += ../.. ../../../microkde ../../../microkde/kdecore ../../../microkde/kio/kfile ../../../microkde/kio/kio ../../../microkde/kresources ../../../qtcompat
9 9
10DESTDIR = ../../../bin 10DESTDIR = ../../../bin
11#LIBS += -lmicrokde -lmicrokabc 11#LIBS += -lxmicrokde -lxmicrokabc
12#LIBS += -L$(QPEDIR)/lib 12#LIBS += -L$(QPEDIR)/lib
13 13
14INTERFACES = \ 14INTERFACES = \
15 15
16HEADERS = \ 16HEADERS = \
17 resourcefile.h \ 17 resourcefile.h \
18 resourcefileconfig.h 18 resourcefileconfig.h
19 19
20SOURCES = \ 20SOURCES = \
21 resourcefile.cpp \ 21 resourcefile.cpp \
22 resourcefileconfig.cpp 22 resourcefileconfig.cpp
23 23
24unix : { 24unix : {
25OBJECTS_DIR = obj/unix 25OBJECTS_DIR = obj/unix
26MOC_DIR = moc/unix 26MOC_DIR = moc/unix
27} 27}
28win32: { 28win32: {
29CONFIG += dll 29CONFIG += dll
30DEFINES += _WIN32_ 30DEFINES += _WIN32_
31OBJECTS_DIR = obj/win 31OBJECTS_DIR = obj/win
32MOC_DIR = moc/win 32MOC_DIR = moc/win
33LIBS += ../../../bin/microkdepim.lib 33LIBS += ../../../bin/xmicrokdepim.lib
34LIBS += ../../../bin/microkcal.lib 34LIBS += ../../../bin/xmicrokcal.lib
35LIBS += ../../../bin/microkde.lib 35LIBS += ../../../bin/xmicrokde.lib
36LIBS += ../../../bin/microkabc.lib 36LIBS += ../../../bin/microkabc.lib
37} 37}
38#The following line was inserted by qt3to4
39QT += qt3support
40#The following line was inserted by qt3to4
41QT += xml
diff --git a/kabc/plugins/file/fileE.pro b/kabc/plugins/file/fileE.pro
index 16707e5..5044cd9 100644
--- a/kabc/plugins/file/fileE.pro
+++ b/kabc/plugins/file/fileE.pro
@@ -1,21 +1,21 @@
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 = xmicrokabc_file
6INCLUDEPATH += $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat 6INCLUDEPATH += $(KDEPIMDIR)/kabc $(KDEPIMDIR)/microkde $(KDEPIMDIR)/microkde/kdecore $(KDEPIMDIR)/microkde/kio/kfile $(KDEPIMDIR)/microkde/kio/kio $(KDEPIMDIR)/microkde/kresources $(KDEPIMDIR)/qtcompat
7OBJECTS_DIR = obj/$(PLATFORM) 7OBJECTS_DIR = obj/$(PLATFORM)
8MOC_DIR = moc/$(PLATFORM) 8MOC_DIR = moc/$(PLATFORM)
9DESTDIR = $(QPEDIR)/lib 9DESTDIR = $(QPEDIR)/lib
10LIBS += -lmicrokde -lmicrokabc 10LIBS += -lxmicrokde -lxmicrokabc
11LIBS += -L$(QPEDIR)/lib 11LIBS += -L$(QPEDIR)/lib
12 12
13INTERFACES = \ 13INTERFACES = \
14 14
15HEADERS = \ 15HEADERS = \
16 resourcefile.h \ 16 resourcefile.h \
17 resourcefileconfig.h 17 resourcefileconfig.h
18 18
19SOURCES = \ 19SOURCES = \
20 resourcefile.cpp \ 20 resourcefile.cpp \
21 resourcefileconfig.cpp 21 resourcefileconfig.cpp
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp
index dad4571..3ed850c 100644
--- a/kabc/plugins/file/resourcefile.cpp
+++ b/kabc/plugins/file/resourcefile.cpp
@@ -156,259 +156,259 @@ void ResourceFile::init( const QString &fileName, const QString &formatName )
156 } 156 }
157 157
158 } 158 }
159 setFileName( fileName ); 159 setFileName( fileName );
160} 160}
161 161
162ResourceFile::~ResourceFile() 162ResourceFile::~ResourceFile()
163{ 163{
164 delete mFormat; 164 delete mFormat;
165 mFormat = 0; 165 mFormat = 0;
166} 166}
167 167
168void ResourceFile::writeConfig( KConfig *config ) 168void ResourceFile::writeConfig( KConfig *config )
169{ 169{
170 170
171 config->setGroup( "Resource_" + identifier() ); 171 config->setGroup( "Resource_" + identifier() );
172 Resource::writeConfig( config ); 172 Resource::writeConfig( config );
173 173
174 config->writeEntry( "FileName", fileName() ); 174 config->writeEntry( "FileName", fileName() );
175 config->writeEntry( "FileFormat", mFormatName ); 175 config->writeEntry( "FileFormat", mFormatName );
176 176
177// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); 177// qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1());
178 178
179} 179}
180 180
181Ticket *ResourceFile::requestSaveTicket() 181Ticket *ResourceFile::requestSaveTicket()
182{ 182{
183 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; 183 kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
184 184
185 if ( !addressBook() ) return 0; 185 if ( !addressBook() ) return 0;
186 186
187#ifdef ALLOW_LOCKING 187#ifdef ALLOW_LOCKING
188 if ( !lock( mFileName ) ) { 188 if ( !lock( mFileName ) ) {
189 qDebug("unablt to lock file "); 189 qDebug("unablt to lock file ");
190 return 0; 190 return 0;
191 } 191 }
192#endif 192#endif
193 return createTicket( this ); 193 return createTicket( this );
194} 194}
195 195
196 196
197bool ResourceFile::doOpen() 197bool ResourceFile::doOpen()
198{ 198{
199 QFile file( fileName() ); 199 QFile file( fileName() );
200 qDebug("ResourceFile::openfile %s ", fileName().latin1()); 200 qDebug("ResourceFile::openfile %s ", fileName().latin1());
201 201
202 if ( !file.exists() ) { 202 if ( !file.exists() ) {
203 // try to create the file 203 // try to create the file
204 bool ok = file.open( IO_WriteOnly ); 204 bool ok = file.open( QIODevice::WriteOnly );
205 if ( ok ) 205 if ( ok )
206 file.close(); 206 file.close();
207 207
208 return ok; 208 return ok;
209 } else { 209 } else {
210 if ( !file.open( IO_ReadWrite ) ) 210 if ( !file.open( QIODevice::ReadWrite ) )
211 return false; 211 return false;
212 212
213 if ( file.size() < 10 ) { 213 if ( file.size() < 10 ) {
214 file.close(); 214 file.close();
215 return true; 215 return true;
216 } 216 }
217 217
218 bool ok = mFormat->checkFormat( &file ); 218 bool ok = mFormat->checkFormat( &file );
219 file.close(); 219 file.close();
220 220
221 return ok; 221 return ok;
222 } 222 }
223} 223}
224 224
225void ResourceFile::doClose() 225void ResourceFile::doClose()
226{ 226{
227} 227}
228 228
229bool ResourceFile::load() 229bool ResourceFile::load()
230{ 230{
231 231
232 QFile file( fileName() ); 232 QFile file( fileName() );
233 if ( !file.open( IO_ReadOnly ) ) { 233 if ( !file.open( QIODevice::ReadOnly ) ) {
234 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) ); 234 addressBook()->error( i18n( "Unable to open file '%1'." ).arg( fileName() ) );
235 return false; 235 return false;
236 } 236 }
237 237
238// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); 238// qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1());
239 239
240 return mFormat->loadAll( addressBook(), this, &file ); 240 return mFormat->loadAll( addressBook(), this, &file );
241} 241}
242 242
243bool ResourceFile::save( Ticket *ticket ) 243bool ResourceFile::save( Ticket *ticket )
244{ 244{
245// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); 245// qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1());
246 246
247 247
248 // create backup file 248 // create backup file
249 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); 249 QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() );
250 250
251/*US we use a simpler method to create a backupfile 251/*US we use a simpler method to create a backupfile
252 252
253 (void) KSaveFile::backupFile( mFileName, QString::null 253 (void) KSaveFile::backupFile( mFileName, QString::null
254 ,extension ); 254 ,extension );
255 255
256 KSaveFile saveFile( mFileName ); 256 KSaveFile saveFile( mFileName );
257 bool ok = false; 257 bool ok = false;
258 if ( saveFile.status() == 0 && saveFile.file() ) 258 if ( saveFile.status() == 0 && saveFile.file() )
259 { 259 {
260 mFormat->saveAll( addressBook(), this, saveFile.file() ); 260 mFormat->saveAll( addressBook(), this, saveFile.file() );
261 ok = saveFile.close(); 261 ok = saveFile.close();
262 } 262 }
263*/ 263*/
264 264
265//US ToDo: write backupfile 265//US ToDo: write backupfile
266#ifndef NO_DIRWATCH 266#ifndef NO_DIRWATCH
267 mDirWatch.stopScan(); 267 mDirWatch.stopScan();
268#endif 268#endif
269 if ( mLastBackupDate >= 0 && mFamily != "sync_res") { 269 if ( mLastBackupDate >= 0 && mFamily != "sync_res") {
270 KConfig conf (locateLocal("config","microkdeglobalrc")); 270 KConfig conf (locateLocal("config","microkdeglobalrc"));
271 conf.setGroup( "BackupSettings" ); 271 conf.setGroup( "BackupSettings" );
272 bool b_enabled = conf.readBoolEntry( "BackupEnabled" ); 272 bool b_enabled = conf.readBoolEntry( "BackupEnabled" );
273 if ( b_enabled ) { 273 if ( b_enabled ) {
274 int num = conf.readNumEntry( "BackupNumbers" ); 274 int num = conf.readNumEntry( "BackupNumbers" );
275 int d_count = conf.readNumEntry( "BackupDayCount" ); 275 int d_count = conf.readNumEntry( "BackupDayCount" );
276 bool stdDir = conf.readBoolEntry( "BackupUseDefaultDir" ); 276 bool stdDir = conf.readBoolEntry( "BackupUseDefaultDir" );
277 QString bupDir = conf.readEntry( "BackupDatadir" ); 277 QString bupDir = conf.readEntry( "BackupDatadir" );
278 QDate reference ( 2000,1,1 ); 278 QDate reference ( 2000,1,1 );
279 int daysTo = reference.daysTo ( QDate::currentDate() ); 279 int daysTo = reference.daysTo ( QDate::currentDate() );
280 bool saveDate = false; 280 bool saveDate = false;
281 if ( daysTo - d_count >= mLastBackupDate ) { 281 if ( daysTo - d_count >= mLastBackupDate ) {
282 qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate ); 282 qDebug("KA: Last backup was %d days ago ", daysTo - mLastBackupDate );
283 if ( stdDir ) 283 if ( stdDir )
284 bupDir = KGlobalSettings::backupDataDir(); 284 bupDir = KGlobalSettings::backupDataDir();
285 int retval = KApplication::createBackup( fileName(), bupDir, num ); 285 int retval = KApplication::createBackup( fileName(), bupDir, num );
286 if ( retval == 0 ) { 286 if ( retval == 0 ) {
287 qDebug("KO: Backup cancelled. Will try again tomorrow "); 287 qDebug("KO: Backup cancelled. Will try again tomorrow ");
288 // retval == 0 : backup skipped for today, try again tomorrow 288 // retval == 0 : backup skipped for today, try again tomorrow
289 mLastBackupDate = daysTo - d_count+1; 289 mLastBackupDate = daysTo - d_count+1;
290 saveDate = true; 290 saveDate = true;
291 } else if ( retval == 1 ){ 291 } else if ( retval == 1 ){
292 qDebug("KO: Backup created."); 292 qDebug("KO: Backup created.");
293 // backup ok 293 // backup ok
294 mLastBackupDate = daysTo; 294 mLastBackupDate = daysTo;
295 saveDate = true; 295 saveDate = true;
296 } else if ( retval == 2 ){ 296 } else if ( retval == 2 ){
297 qDebug("KO: Backup globally cancelled."); 297 qDebug("KO: Backup globally cancelled.");
298 // backup globally cancelled 298 // backup globally cancelled
299 b_enabled = false; 299 b_enabled = false;
300 } 300 }
301 if ( !b_enabled ) { 301 if ( !b_enabled ) {
302 conf.writeEntry( "mBackupEnabled", false ); 302 conf.writeEntry( "mBackupEnabled", false );
303 } 303 }
304 if ( saveDate ) { 304 if ( saveDate ) {
305 KConfig config ( locateLocal("config","kabcrc") ); 305 KConfig config ( locateLocal("config","kabcrc") );
306 config.setGroup( "Resource_" + identifier() ); 306 config.setGroup( "Resource_" + identifier() );
307 config.writeEntry( "LastBackupDate", mLastBackupDate ); 307 config.writeEntry( "LastBackupDate", mLastBackupDate );
308 } 308 }
309 } 309 }
310 } 310 }
311 } 311 }
312 QFile info; 312 QFile info;
313 info.setName( fileName() ); 313 info.setName( fileName() );
314 bool ok = info.open( IO_WriteOnly ); 314 bool ok = info.open( QIODevice::WriteOnly );
315 if ( ok ) { 315 if ( ok ) {
316 mFormat->saveAll( addressBook(), this, &info ); 316 mFormat->saveAll( addressBook(), this, &info );
317 317
318 info.close(); 318 info.close();
319 ok = true; 319 ok = true;
320 } 320 }
321 else { 321 else {
322 322
323 } 323 }
324 324
325 if ( !ok ) 325 if ( !ok )
326 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) ); 326 addressBook()->error( i18n( "Unable to save file '%1'." ).arg( fileName() ) );
327#ifndef NO_DIRWATCH 327#ifndef NO_DIRWATCH
328 mDirWatch.startScan(); 328 mDirWatch.startScan();
329#endif 329#endif
330 delete ticket; 330 delete ticket;
331#ifdef ALLOW_LOCKING 331#ifdef ALLOW_LOCKING
332 unlock( mFileName ); 332 unlock( mFileName );
333#endif 333#endif
334 334
335 return ok; 335 return ok;
336} 336}
337 337
338bool ResourceFile::lock( const QString &fileName ) 338bool ResourceFile::lock( const QString &fileName )
339{ 339{
340#ifdef ALLOW_LOCKING 340#ifdef ALLOW_LOCKING
341 341
342 342
343 QString fn = fileName; 343 QString fn = fileName;
344 344
345//US change the implementation how the lockfilename is getting created 345//US change the implementation how the lockfilename is getting created
346//US fn.replace( QRegExp("/"), "_" ); 346//US fn.replace( QRegExp("/"), "_" );
347//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 347//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
348 348
349 KURL url(fn); 349 KURL url(fn);
350 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 350 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
351 351
352 352
353 353
354 if (QFile::exists( lockName )) return false; 354 if (QFile::exists( lockName )) return false;
355 355
356 QString lockUniqueName; 356 QString lockUniqueName;
357 lockUniqueName = fn + KApplication::randomString( 8 ); 357 lockUniqueName = fn + KApplication::randomString( 8 );
358 358
359 url = lockUniqueName; 359 url = lockUniqueName;
360//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); 360//US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName );
361 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); 361 mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() );
362 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; 362 kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl;
363 363
364 // Create unique file 364 // Create unique file
365 QFile file( mLockUniqueName ); 365 QFile file( mLockUniqueName );
366 file.open( IO_WriteOnly ); 366 file.open( QIODevice::WriteOnly );
367 file.close(); 367 file.close();
368 368
369 // Create lock file 369 // Create lock file
370 int result = 0; 370 int result = 0;
371#ifndef _WIN32_ 371#ifndef _WIN32_
372 result = ::link( QFile::encodeName( mLockUniqueName ), 372 result = ::link( QFile::encodeName( mLockUniqueName ),
373 QFile::encodeName( lockName ) ); 373 QFile::encodeName( lockName ) );
374#endif 374#endif
375 if ( result == 0 ) { 375 if ( result == 0 ) {
376 addressBook()->emitAddressBookLocked(); 376 addressBook()->emitAddressBookLocked();
377 return true; 377 return true;
378 } 378 }
379 379
380 // TODO: check stat 380 // TODO: check stat
381 381
382 return false; 382 return false;
383#else 383#else
384 return true; 384 return true;
385#endif 385#endif
386} 386}
387 387
388void ResourceFile::unlock( const QString &fileName ) 388void ResourceFile::unlock( const QString &fileName )
389{ 389{
390#ifdef ALLOW_LOCKING 390#ifdef ALLOW_LOCKING
391 QString fn = fileName; 391 QString fn = fileName;
392//US change the implementation how the lockfilename is getting created 392//US change the implementation how the lockfilename is getting created
393//US fn.replace( QRegExp( "/" ), "_" ); 393//US fn.replace( QRegExp( "/" ), "_" );
394//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); 394//US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" );
395//US QString lockName = fn + ".lock"; 395//US QString lockName = fn + ".lock";
396 KURL url(fn); 396 KURL url(fn);
397 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); 397 QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" );
398 398
399 QFile::remove( lockName ); 399 QFile::remove( lockName );
400 QFile::remove( mLockUniqueName ); 400 QFile::remove( mLockUniqueName );
401 addressBook()->emitAddressBookUnlocked(); 401 addressBook()->emitAddressBookUnlocked();
402#else 402#else
403 return; 403 return;
404#endif 404#endif
405} 405}
406 406
407void ResourceFile::setFileName( const QString &fileName ) 407void ResourceFile::setFileName( const QString &fileName )
408{ 408{
409#ifndef NO_DIRWATCH 409#ifndef NO_DIRWATCH
410 mDirWatch.stopScan(); 410 mDirWatch.stopScan();
411 mDirWatch.removeFile( mFileName ); 411 mDirWatch.removeFile( mFileName );
412 mFileName = fileName; 412 mFileName = fileName;
413 413
414 414
diff --git a/kabc/plugins/file/resourcefileconfig.cpp b/kabc/plugins/file/resourcefileconfig.cpp
index b63775d..70b0bac 100644
--- a/kabc/plugins/file/resourcefileconfig.cpp
+++ b/kabc/plugins/file/resourcefileconfig.cpp
@@ -1,101 +1,103 @@
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#include <qlabel.h> 28#include <qlabel.h>
29#include <qlayout.h> 29#include <qlayout.h>
30#include <qfileinfo.h> 30#include <qfileinfo.h>
31//Added by qt3to4:
32#include <Q3GridLayout>
31 33
32#include <kdebug.h> 34#include <kdebug.h>
33#include <klocale.h> 35#include <klocale.h>
34#include <kstandarddirs.h> 36#include <kstandarddirs.h>
35#include <kdialog.h> 37#include <kdialog.h>
36#ifndef _WIN32_ 38#ifndef _WIN32_
37#include <unistd.h> 39#include <unistd.h>
38#endif 40#endif
39//US #include "formatfactory.h" 41//US #include "formatfactory.h"
40#include <qfile.h> 42#include <qfile.h>
41#include "resourcefile.h" 43#include "resourcefile.h"
42#include "stdaddressbook.h" 44#include "stdaddressbook.h"
43 45
44#include "resourcefileconfig.h" 46#include "resourcefileconfig.h"
45 47
46using namespace KABC; 48using namespace KABC;
47 49
48ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name ) 50ResourceFileConfig::ResourceFileConfig( QWidget* parent, const char* name )
49 : ConfigWidget( parent, name ) 51 : ConfigWidget( parent, name )
50{ 52{
51//qDebug("ResourceFileConfig::ResourceFileConfig"); 53//qDebug("ResourceFileConfig::ResourceFileConfig");
52 54
53 QGridLayout *mainLayout = new QGridLayout( this, 2, 2, 0, 55 Q3GridLayout *mainLayout = new Q3GridLayout( this, 2, 2, 0,
54 KDialog::spacingHint() ); 56 KDialog::spacingHint() );
55 57
56 QLabel *label = new QLabel( i18n( "Format:" ), this ); 58 QLabel *label = new QLabel( i18n( "Format:" ), this );
57 mFormatBox = new KComboBox( this ); 59 mFormatBox = new KComboBox( this );
58 60
59 mainLayout->addWidget( label, 0, 0 ); 61 mainLayout->addWidget( label, 0, 0 );
60 mainLayout->addWidget( mFormatBox, 0, 1 ); 62 mainLayout->addWidget( mFormatBox, 0, 1 );
61 63
62 label = new QLabel( i18n( "Location:" ), this ); 64 label = new QLabel( i18n( "Location:" ), this );
63 mFileNameEdit = new KURLRequester( this ); 65 mFileNameEdit = new KURLRequester( this );
64 66
65 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ), 67 connect( mFileNameEdit, SIGNAL( textChanged( const QString & ) ),
66 SLOT( checkFilePermissions( const QString & ) ) ); 68 SLOT( checkFilePermissions( const QString & ) ) );
67 69
68 mainLayout->addWidget( label, 1, 0 ); 70 mainLayout->addWidget( label, 1, 0 );
69 mainLayout->addWidget( mFileNameEdit, 1, 1 ); 71 mainLayout->addWidget( mFileNameEdit, 1, 1 );
70 72
71 73
72/*US lets hardcode the formats instead of using a factory 74/*US lets hardcode the formats instead of using a factory
73 FormatFactory *factory = FormatFactory::self(); 75 FormatFactory *factory = FormatFactory::self();
74 QStringList formats = factory->formats(); 76 QStringList formats = factory->formats();
75 QStringList::Iterator it; 77 QStringList::Iterator it;
76 78
77 for ( it = formats.begin(); it != formats.end(); ++it ) { 79 for ( it = formats.begin(); it != formats.end(); ++it ) {
78 FormatInfo *info = factory->info( *it ); 80 FormatInfo *info = factory->info( *it );
79 if ( info ) { 81 if ( info ) {
80 mFormatTypes << (*it); 82 mFormatTypes << (*it);
81 mFormatBox->insertItem( info->nameLabel ); 83 mFormatBox->insertItem( info->nameLabel );
82 } 84 }
83 } 85 }
84*/ 86*/
85 mFormatTypes << "vcard"; 87 mFormatTypes << "vcard";
86 mFormatTypes << "binary"; 88 mFormatTypes << "binary";
87 mFormatBox->insertItem( "vcard" ); 89 mFormatBox->insertItem( "vcard" );
88 mFormatBox->insertItem( "binary" ); 90 mFormatBox->insertItem( "binary" );
89 91
90 mInEditMode = false; 92 mInEditMode = false;
91} 93}
92 94
93void ResourceFileConfig::setEditMode( bool value ) 95void ResourceFileConfig::setEditMode( bool value )
94{ 96{
95 mFormatBox->setEnabled( !value ); 97 mFormatBox->setEnabled( !value );
96 mInEditMode = value; 98 mInEditMode = value;
97} 99}
98 100
99void ResourceFileConfig::loadSettings( KRES::Resource *res ) 101void ResourceFileConfig::loadSettings( KRES::Resource *res )
100{ 102{
101//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res ); 103//US ResourceFile *resource = dynamic_cast<ResourceFile*>( res );