Diffstat (limited to 'kabc/plugins/file/resourcefile.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index 163f2b4..dc5932f 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -1,198 +1,194 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #ifndef _WIN32_ #include <unistd.h> #endif #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include "formatfactory.h" #include "resource.h" #include "resourcefileconfig.h" #include "stdaddressbook.h" #define NO_DIRWATCH #include "resourcefile.h" -#include "syncprefwidget.h" //#define ALLOW_LOCKING using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif //US void *init_kabc_file() void *init_microkabc_file() { - return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); + return new KRES::PluginFactory<ResourceFile,ResourceFileConfig>(); } #ifndef _WIN32_ } #endif -ResourceFile::ResourceFile( const KConfig *config, bool syncable ) - : Resource( config, syncable ) , mFormat( 0 ) +ResourceFile::ResourceFile( const KConfig *config ) + : Resource( config ) , mFormat( 0 ) { QString fileName, formatName, default_fileName; - if (syncable == true) - default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; - else - default_fileName = StdAddressBook::fileName(); + default_fileName = StdAddressBook::fileName(); KConfig *cfg = (KConfig *)config; if ( cfg ) { fileName = cfg->readEntry( "FileName", default_fileName ); formatName = cfg->readEntry( "FileFormat", "vcard" ); } else { fileName = default_fileName; formatName = "vcard"; } init( fileName, formatName ); } -ResourceFile::ResourceFile( const QString &fileName, bool syncable , +ResourceFile::ResourceFile( const QString &fileName , const QString &formatName ) - : Resource( 0, syncable ) + : Resource( 0 ) { // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); init( fileName, formatName ); } void ResourceFile::init( const QString &fileName, const QString &formatName ) { mFormatName = formatName; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); if ( !mFormat ) { mFormatName = "vcard"; mFormat = factory->format( mFormatName ); } #ifndef NO_DIRWATCH connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); #endif setFileName( fileName ); } ResourceFile::~ResourceFile() { delete mFormat; mFormat = 0; } void ResourceFile::writeConfig( KConfig *config ) { config->setGroup( "Resource_" + identifier() ); Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); config->writeEntry( "FileFormat", mFormatName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceFile::requestSaveTicket() { kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; if ( !addressBook() ) return 0; #ifdef ALLOW_LOCKING if ( !lock( mFileName ) ) { qDebug("unablt to lock file "); return 0; } #endif return createTicket( this ); } bool ResourceFile::doOpen() { QFile file( mFileName ); qDebug("ResourceFile::openfile %s ", mFileName.latin1()); if ( !file.exists() ) { // try to create the file bool ok = file.open( IO_WriteOnly ); if ( ok ) file.close(); return ok; } else { if ( !file.open( IO_ReadWrite ) ) return false; if ( file.size() == 0 ) { file.close(); return true; } bool ok = mFormat->checkFormat( &file ); file.close(); return ok; } } void ResourceFile::doClose() { } bool ResourceFile::load() { QFile file( mFileName ); |