summaryrefslogtreecommitdiffstats
path: root/tdeabc/plugins/file
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-02-15 21:57:54 -0600
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2013-02-15 21:57:54 -0600
commited99a30644c19b0a3cf0d2147243532df4daa16b (patch)
tree7f3f2850e59824fdf100a642367a82b1e7f0204f /tdeabc/plugins/file
parente5f2d46e9caf6942f365f1b454087dda71a340f7 (diff)
downloadtdelibs-ed99a30644c19b0a3cf0d2147243532df4daa16b.tar.gz
tdelibs-ed99a30644c19b0a3cf0d2147243532df4daa16b.zip
Rename additional header files to avoid conflicts with KDE4
Diffstat (limited to 'tdeabc/plugins/file')
-rw-r--r--tdeabc/plugins/file/CMakeLists.txt73
-rw-r--r--tdeabc/plugins/file/Makefile.am28
-rw-r--r--tdeabc/plugins/file/file.desktop82
-rw-r--r--tdeabc/plugins/file/resourcefile.cpp395
-rw-r--r--tdeabc/plugins/file/resourcefile.h162
-rw-r--r--tdeabc/plugins/file/resourcefileconfig.cpp118
-rw-r--r--tdeabc/plugins/file/resourcefileconfig.h57
-rw-r--r--tdeabc/plugins/file/resourcefileplugin.cpp32
8 files changed, 947 insertions, 0 deletions
diff --git a/tdeabc/plugins/file/CMakeLists.txt b/tdeabc/plugins/file/CMakeLists.txt
new file mode 100644
index 000000000..6c17d2dc7
--- /dev/null
+++ b/tdeabc/plugins/file/CMakeLists.txt
@@ -0,0 +1,73 @@
+#################################################
+#
+# (C) 2010 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+include_directories(
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${CMAKE_BINARY_DIR}/kabc
+ ${CMAKE_SOURCE_DIR}/kabc
+
+ ${TQT_INCLUDE_DIRS}
+ ${CMAKE_BINARY_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}
+ ${CMAKE_SOURCE_DIR}/dcop
+ ${CMAKE_SOURCE_DIR}/tdecore
+ ${CMAKE_SOURCE_DIR}/tdeui
+ ${CMAKE_SOURCE_DIR}/tdeio
+ ${CMAKE_SOURCE_DIR}/tdeio/tdeio
+ ${CMAKE_SOURCE_DIR}/tdeio/tdefile
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### headers ###################################
+
+install( FILES
+ resourcefile.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/kabc )
+
+
+##### other data ################################
+
+install( FILES file.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc )
+
+
+##### kabc_file (library) #######################
+
+set( target kabc_file )
+
+set( ${target}_SRCS
+ resourcefile.cpp resourcefileconfig.cpp
+)
+
+tde_add_library( ${target} SHARED AUTOMOC
+ SOURCES ${${target}_SRCS}
+ VERSION 1.0.0
+ LINK tdeabc-shared
+ DESTINATION ${LIB_INSTALL_DIR}
+)
+
+
+##### kabc_file (module) ########################
+
+set( target kabc_file )
+
+set( ${target}_SRCS
+ resourcefileplugin.cpp
+)
+
+tde_add_kpart( ${target}
+ SOURCES ${${target}_SRCS}
+ LINK kabc_file-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdeabc/plugins/file/Makefile.am b/tdeabc/plugins/file/Makefile.am
new file mode 100644
index 000000000..d00ffea3f
--- /dev/null
+++ b/tdeabc/plugins/file/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = -I$(top_builddir)/kabc -I$(top_srcdir)/kabc $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourcefileconfig.h
+
+lib_LTLIBRARIES = libkabc_file.la
+libkabc_file_la_SOURCES = resourcefile.cpp resourcefileconfig.cpp
+libkabc_file_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -version-info 1:0:0 -no-undefined
+libkabc_file_la_LIBADD = $(LIB_KABC) $(LIB_QT) $(top_builddir)/tderesources/libtderesources.la $(LIB_TDEFILE) $(LIB_TDECORE) $(LIB_TDEUI)
+libkabc_file_la_COMPILE_FIRST = $(top_builddir)/tdeabc/addressee.h
+
+
+kde_module_LTLIBRARIES = kabc_file.la
+kabc_file_la_SOURCES = resourcefileplugin.cpp
+kabc_file_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -no-undefined
+kabc_file_la_LIBADD = libkabc_file.la $(LIB_QT) $(LIB_TDECORE)
+kabc_file_la_COMPILE_FIRST = $(top_builddir)/tdeabc/addressee.h
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_file.pot
+
+kabcincludedir = $(includedir)/kabc
+kabcinclude_HEADERS = resourcefile.h
+
+servicedir = $(kde_servicesdir)/tderesources/kabc
+service_DATA = file.desktop
diff --git a/tdeabc/plugins/file/file.desktop b/tdeabc/plugins/file/file.desktop
new file mode 100644
index 000000000..1359dd1c6
--- /dev/null
+++ b/tdeabc/plugins/file/file.desktop
@@ -0,0 +1,82 @@
+[Desktop Entry]
+Name=File
+Name[af]=Lêer
+Name[ar]=ملفّ
+Name[az]=Fayl
+Name[be]=Файл
+Name[bn]=ফাইল
+Name[br]=Restr
+Name[bs]=Datoteka
+Name[ca]=Fitxer
+Name[cs]=Soubor
+Name[csb]=Lopk
+Name[cy]=Ffeil
+Name[da]=Fil
+Name[de]=Datei
+Name[el]=Αρχείο
+Name[eo]=Dosiero
+Name[es]=Archivo
+Name[et]=Fail
+Name[eu]=Fitxategia
+Name[fa]=پرونده
+Name[fi]=Tiedosto
+Name[fr]=Fichier
+Name[fy]=Triem
+Name[ga]=Comhad
+Name[gl]=Ficheiro
+Name[he]=קובץ
+Name[hi]=फ़ाइल
+Name[hr]=Datoteka
+Name[hsb]=Dataja
+Name[hu]=Fájl
+Name[id]=Berkas
+Name[is]=Skrá
+Name[ja]=ファイル
+Name[ka]=ფაილი
+Name[kk]=Файл
+Name[km]=ឯកសារ
+Name[ko]=파일
+Name[lb]=Datei
+Name[lt]=Byla
+Name[lv]=Fails
+Name[mk]=Датотека
+Name[mn]=Файл
+Name[ms]=Fail
+Name[nb]=Fil
+Name[nds]=Datei
+Name[ne]=फाइल
+Name[nl]=Bestand
+Name[nn]=Fil
+Name[pa]=ਫਾਇਲ
+Name[pl]=Plik
+Name[pt]=Ficheiro
+Name[pt_BR]=Arquivo
+Name[ro]=Fişier
+Name[ru]=Файл
+Name[rw]=Idosiye
+Name[se]=Fiila
+Name[sk]=Súbor
+Name[sl]=Datoteka
+Name[sq]=Skedë
+Name[sr]=Фајл
+Name[sr@Latn]=Fajl
+Name[sv]=Fil
+Name[ta]=கோப்பு
+Name[te]=దస్త్రం
+Name[tg]=Файл
+Name[th]=แฟ้ม
+Name[tr]=Dosya
+Name[tt]=Birem
+Name[uk]=Файл
+Name[uz]=Fayl
+Name[uz@cyrillic]=Файл
+Name[vi]=Tập tin
+Name[wa]=Fitchî
+Name[zh_CN]=文件
+Name[zh_HK]=檔案
+Name[zh_TW]=檔案
+X-TDE-Library=kabc_file
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=file
diff --git a/tdeabc/plugins/file/resourcefile.cpp b/tdeabc/plugins/file/resourcefile.cpp
new file mode 100644
index 000000000..b29cf33c3
--- /dev/null
+++ b/tdeabc/plugins/file/resourcefile.cpp
@@ -0,0 +1,395 @@
+/*
+ This file is part of libkabc.
+
+ Copyright (c) 2001,2003 Cornelius Schumacher <schumacher@kde.org>
+ Copyright (c) 2006 Tom Abers <tomalbers@kde.nl>
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <tqfile.h>
+#include <tqfileinfo.h>
+#include <tqtimer.h>
+
+#include <tdeapplication.h>
+#include <tdeconfig.h>
+#include <kdebug.h>
+#include <tdeio/scheduler.h>
+#include <tdelocale.h>
+#include <ksavefile.h>
+#include <kstandarddirs.h>
+
+#include "formatfactory.h"
+#include "resourcefileconfig.h"
+#include "stdaddressbook.h"
+#include "lock.h"
+
+#include "resourcefile.h"
+
+using namespace KABC;
+
+ResourceFile::ResourceFile( const TDEConfig *config )
+ : Resource( config ), mFormat( 0 ),
+ mAsynchronous( false )
+{
+ TQString fileName, formatName;
+
+ if ( config ) {
+ fileName = config->readPathEntry( "FileName", StdAddressBook::fileName() );
+ formatName = config->readEntry( "FileFormat", "vcard" );
+ } else {
+ fileName = StdAddressBook::fileName();
+ formatName = "vcard";
+ }
+
+ init( fileName, formatName );
+}
+
+ResourceFile::ResourceFile( const TQString &fileName,
+ const TQString &formatName )
+ : Resource( 0 ), mFormat( 0 ),
+ mAsynchronous( false )
+{
+ init( fileName, formatName );
+}
+
+void ResourceFile::init( const TQString &fileName, const TQString &formatName )
+{
+ mFormatName = formatName;
+
+ FormatFactory *factory = FormatFactory::self();
+ mFormat = factory->format( mFormatName );
+
+ if ( !mFormat ) {
+ mFormatName = "vcard";
+ mFormat = factory->format( mFormatName );
+ }
+
+ connect( &mDirWatch, TQT_SIGNAL( dirty(const TQString&) ), TQT_SLOT( fileChanged() ) );
+ connect( &mDirWatch, TQT_SIGNAL( created(const TQString&) ), TQT_SLOT( fileChanged() ) );
+ connect( &mDirWatch, TQT_SIGNAL( deleted(const TQString&) ), TQT_SLOT( fileChanged() ) );
+
+ setFileName( fileName );
+
+ mLock = 0;
+}
+
+ResourceFile::~ResourceFile()
+{
+ delete mFormat;
+ mFormat = 0;
+}
+
+void ResourceFile::writeConfig( TDEConfig *config )
+{
+ Resource::writeConfig( config );
+
+ if ( mFileName == StdAddressBook::fileName() )
+ config->deleteEntry( "FileName" );
+ else
+ config->writePathEntry( "FileName", mFileName );
+
+ config->writeEntry( "FileFormat", mFormatName );
+}
+
+Ticket *ResourceFile::requestSaveTicket()
+{
+ kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl;
+
+ if ( !addressBook() ) return 0;
+
+ delete mLock;
+ mLock = new Lock( mFileName );
+
+ if ( mLock->lock() ) {
+ addressBook()->emitAddressBookLocked();
+ } else {
+ addressBook()->error( mLock->error() );
+ kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '"
+ << mFileName << "': " << mLock->error() << endl;
+ return 0;
+ }
+
+ return createTicket( this );
+}
+
+void ResourceFile::releaseSaveTicket( Ticket *ticket )
+{
+ delete ticket;
+
+ delete mLock;
+ mLock = 0;
+
+ addressBook()->emitAddressBookUnlocked();
+}
+
+bool ResourceFile::doOpen()
+{
+ TQFile file( mFileName );
+
+ if ( !file.exists() ) {
+ // try to create the file
+ bool ok = file.open( IO_WriteOnly );
+ if ( ok )
+ file.close();
+
+ return ok;
+ } else {
+ TQFileInfo fileInfo( mFileName );
+ if ( readOnly() || !fileInfo.isWritable() ) {
+ if ( !file.open( IO_ReadOnly ) )
+ return false;
+ } else {
+ if ( !file.open( IO_ReadWrite ) )
+ return false;
+ }
+
+ if ( file.size() == 0 ) {
+ file.close();
+ kdDebug() << "File size is zero. Evaluating backups" << endl;
+ for (int i=0; i!=20; i++)
+ {
+ TQFile backup( mFileName + "__" + TQString::number(i) );
+ kdDebug() << "Evaluating" << backup.name() << " size: " << backup.size() << endl;
+ if ( backup.size() != 0 )
+ {
+ kdDebug() << "Restoring backup " << i << endl;
+ const TQString src = mFileName + "__" + TQString::number(i);
+ const TQString dest = mFileName;
+
+ // remove dest
+ TQFile::remove( dest );
+
+ // copy src to dest
+ if ( backup.open( IO_ReadOnly ) ) {
+ const TQByteArray data = backup.readAll();
+
+ TQFile out( dest );
+ if ( out.open( IO_WriteOnly ) ) {
+ out.writeBlock( data );
+ out.close();
+ }
+
+ backup.close();
+ }
+ return true;
+ }
+ }
+ return true;
+ }
+
+ bool ok = mFormat->checkFormat( &file );
+ file.close();
+
+ return ok;
+ }
+}
+
+void ResourceFile::doClose()
+{
+}
+
+bool ResourceFile::load()
+{
+ kdDebug(5700) << "ResourceFile::load(): '" << mFileName << "'" << endl;
+
+ mAsynchronous = false;
+
+ TQFile file( mFileName );
+ if ( !file.open( IO_ReadOnly ) ) {
+ addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) );
+ return false;
+ }
+
+ clear();
+
+ return mFormat->loadAll( addressBook(), this, &file );
+}
+
+bool ResourceFile::asyncLoad()
+{
+ kdDebug(5700) << "ResourceFile::asyncLoad()" << endl;
+
+ mAsynchronous = true;
+
+ bool ok = load();
+
+ if ( !ok )
+ emitLoadingError();
+ else
+ emitLoadingFinished();
+
+ return true;
+}
+
+bool ResourceFile::save( Ticket * )
+{
+ kdDebug(5700) << "ResourceFile::save()" << endl;
+
+ // Only do the logrotate dance when the __0 file is not 0 bytes.
+ TQFile file( mFileName + "__0" );
+ if ( file.size() != 0 ) {
+ const TQString last = mFileName + "__20";
+ kdDebug() << "deleting " << last << endl;
+
+ TQFile::remove( last );
+
+ for (int i=19; i>=0; i--)
+ {
+ const TQString src = mFileName + "__" + TQString::number(i);
+ const TQString dest = mFileName + "__" + TQString::number(i+1);
+ kdDebug() << "moving " << src << " -> " << dest << endl;
+
+ // copy src to dest
+ TQFile in( src );
+ if ( in.open( IO_ReadOnly ) ) {
+ const TQByteArray data = in.readAll();
+
+ TQFile out( dest );
+ if ( out.open( IO_WriteOnly ) ) {
+ out.writeBlock( data );
+ out.close();
+ }
+
+ in.close();
+ }
+
+ // remove src
+ TQFile::remove( src );
+ }
+ } else
+ kdDebug() << "Not starting logrotate __0 is 0 bytes." << endl;
+
+ TQString extension = "__0";
+ (void) KSaveFile::backupFile( mFileName, TQString::null /*directory*/,
+ extension );
+
+ mDirWatch.stopScan();
+
+ KSaveFile saveFile( mFileName );
+ bool ok = false;
+
+ if ( saveFile.status() == 0 && saveFile.file() ) {
+ mFormat->saveAll( addressBook(), this, saveFile.file() );
+ ok = saveFile.close();
+ }
+
+ if ( !ok ) {
+ saveFile.abort();
+ addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) );
+ }
+
+ mDirWatch.startScan();
+
+ return ok;
+}
+
+bool ResourceFile::asyncSave( Ticket *ticket )
+{
+ kdDebug(5700) << "ResourceFile::asyncSave()" << endl;
+
+ bool ok = save( ticket );
+
+ if ( !ok )
+ TQTimer::singleShot( 0, this, TQT_SLOT( emitSavingError() ) );
+ else
+ TQTimer::singleShot( 0, this, TQT_SLOT( emitSavingFinished() ) );
+
+ return ok;
+}
+
+void ResourceFile::setFileName( const TQString &fileName )
+{
+ mDirWatch.stopScan();
+ if ( mDirWatch.contains( mFileName ) )
+ mDirWatch.removeFile( mFileName );
+
+ mFileName = fileName;
+
+ mDirWatch.addFile( mFileName );
+ mDirWatch.startScan();
+}
+
+TQString ResourceFile::fileName() const
+{
+ return mFileName;
+}
+
+void ResourceFile::setFormat( const TQString &format )
+{
+ mFormatName = format;
+ delete mFormat;
+
+ FormatFactory *factory = FormatFactory::self();
+ mFormat = factory->format( mFormatName );
+}
+
+TQString ResourceFile::format() const
+{
+ return mFormatName;
+}
+
+void ResourceFile::fileChanged()
+{
+ kdDebug(5700) << "ResourceFile::fileChanged(): " << mFileName << endl;
+
+ if ( !addressBook() )
+ return;
+
+ if ( mAsynchronous )
+ asyncLoad();
+ else {
+ load();
+ kdDebug() << "addressBookChanged() " << endl;
+ addressBook()->emitAddressBookChanged();
+ }
+}
+
+void ResourceFile::removeAddressee( const Addressee &addr )
+{
+ TQFile::remove( TQFile::encodeName( locateLocal( "data", "tdeabc/photos/" ) + addr.uid() ) );
+ TQFile::remove( TQFile::encodeName( locateLocal( "data", "tdeabc/logos/" ) + addr.uid() ) );
+ TQFile::remove( TQFile::encodeName( locateLocal( "data", "tdeabc/sounds/" ) + addr.uid() ) );
+
+ mAddrMap.erase( addr.uid() );
+}
+
+void ResourceFile::emitSavingFinished()
+{
+ emit savingFinished( this );
+}
+
+void ResourceFile::emitSavingError()
+{
+ emit savingError( this, i18n( "Unable to save file '%1'." ).arg( mFileName ) );
+}
+
+void ResourceFile::emitLoadingFinished()
+{
+ emit loadingFinished( this );
+}
+
+void ResourceFile::emitLoadingError()
+{
+ emit loadingError( this, i18n( "Problems during parsing file '%1'." ).arg( mFileName ) );
+}
+
+#include "resourcefile.moc"
diff --git a/tdeabc/plugins/file/resourcefile.h b/tdeabc/plugins/file/resourcefile.h
new file mode 100644
index 000000000..a77f55798
--- /dev/null
+++ b/tdeabc/plugins/file/resourcefile.h
@@ -0,0 +1,162 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KABC_RESOURCEFILE_H
+#define KABC_RESOURCEFILE_H
+
+#include <tdeconfig.h>
+#include <kdirwatch.h>
+
+#include <sys/types.h>
+
+#include <tdeabc/resource.h>
+
+namespace KABC {
+
+class FormatPlugin;
+class ResourceConfigWidget;
+class Lock;
+
+/**
+ This resource allows access to a local file.
+*/
+class KABC_EXPORT ResourceFile : public Resource
+{
+ Q_OBJECT
+
+ public:
+ /**
+ Constructor.
+
+ @param cfg The config object where custom resource settings are stored.
+ */
+ ResourceFile( const TDEConfig *cfg );
+
+ /**
+ Construct file resource on file @arg fileName using format @arg formatName.
+ */
+ ResourceFile( const TQString &fileName, const TQString &formatName = "vcard" );
+
+ /**
+ Destructor.
+ */
+ ~ResourceFile();
+
+ /**
+ Writes the config back.
+ */
+ virtual void writeConfig( TDEConfig *cfg );
+
+ /**
+ Tries to open the file and checks for the proper format.
+ This method should be called before load().
+ */
+ virtual bool doOpen();
+
+ /**
+ Closes the file again.
+ */
+ virtual void doClose();
+
+ /**
+ Requests a save ticket, that is used by save()
+ */
+ virtual Ticket *requestSaveTicket();
+
+ virtual void releaseSaveTicket( Ticket* );
+
+ /**
+ Loads all addressees from file to the address book.
+ Returns true if all addressees could be loaded otherwise false.
+ */
+ virtual bool load();
+
+ virtual bool asyncLoad();
+
+ /**
+ Saves all addresses from address book to file.
+ Returns true if all addressees could be saved otherwise false.
+
+ @param ticket The ticket returned by requestSaveTicket()
+ */
+ virtual bool save( Ticket *ticket );
+
+ virtual bool asyncSave( Ticket *ticket );
+
+ /**
+ Set name of file to be used for saving.
+ */
+ void setFileName( const TQString & );
+
+ /**
+ Return name of file used for loading and saving the address book.
+ */
+ TQString fileName() const;
+
+ /**
+ Sets a new format by name.
+ */
+ void setFormat( const TQString &name );
+
+ /**
+ Returns the format name.
+ */
+ TQString format() const;
+
+ /**
+ Remove a addressee from its source.
+ This method is mainly called by KABC::AddressBook.
+ */
+ virtual void removeAddressee( const Addressee& addr );
+
+ private slots:
+ void emitLoadingFinished();
+ void emitLoadingError();
+ void emitSavingFinished();
+ void emitSavingError();
+
+ protected slots:
+ void fileChanged();
+
+ protected:
+ void init( const TQString &fileName, const TQString &format );
+
+ bool lock( const TQString &fileName );
+ void unlock( const TQString &fileName );
+
+ private:
+ TQString mFileName;
+ TQString mFormatName;
+
+ FormatPlugin *mFormat;
+
+ Lock *mLock;
+
+ KDirWatch mDirWatch;
+
+ bool mAsynchronous;
+
+ class ResourceFilePrivate;
+ ResourceFilePrivate *d;
+};
+
+}
+
+#endif
diff --git a/tdeabc/plugins/file/resourcefileconfig.cpp b/tdeabc/plugins/file/resourcefileconfig.cpp
new file mode 100644
index 000000000..7c3f4da15
--- /dev/null
+++ b/tdeabc/plugins/file/resourcefileconfig.cpp
@@ -0,0 +1,118 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 Tobias Koenig <tokoe@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <tqlabel.h>
+#include <tqlayout.h>
+
+#include <kdebug.h>
+#include <tdelocale.h>
+#include <kstandarddirs.h>
+#include <kdialog.h>
+
+#include <unistd.h>
+
+#include "formatfactory.h"
+#include "resourcefile.h"
+#include "stdaddressbook.h"
+
+#include "resourcefileconfig.h"
+
+using namespace KABC;
+
+ResourceFileConfig::ResourceFileConfig( TQWidget* parent, const char* name )
+ : ConfigWidget( parent, name )
+{
+ TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2, 0,
+ KDialog::spacingHint() );
+
+ TQLabel *label = new TQLabel( i18n( "Format:" ), this );
+ mFormatBox = new KComboBox( this );
+
+ mainLayout->addWidget( label, 0, 0 );
+ mainLayout->addWidget( mFormatBox, 0, 1 );
+
+ label = new TQLabel( i18n( "Location:" ), this );
+ mFileNameEdit = new KURLRequester( this );
+
+ connect( mFileNameEdit, TQT_SIGNAL( textChanged( const TQString & ) ),
+ TQT_SLOT( checkFilePermissions( const TQString & ) ) );
+
+ mainLayout->addWidget( label, 1, 0 );
+ mainLayout->addWidget( mFileNameEdit, 1, 1 );
+
+ FormatFactory *factory = FormatFactory::self();
+ TQStringList formats = factory->formats();
+ TQStringList::Iterator it;
+ for ( it = formats.begin(); it != formats.end(); ++it ) {
+ FormatInfo *info = factory->info( *it );
+ if ( info ) {
+ mFormatTypes << (*it);
+ mFormatBox->insertItem( info->nameLabel );
+ }
+ }
+
+ mInEditMode = false;
+}
+
+void ResourceFileConfig::setEditMode( bool value )
+{
+ mFormatBox->setEnabled( !value );
+ mInEditMode = value;
+}
+
+void ResourceFileConfig::loadSettings( KRES::Resource *res )
+{
+ ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceFileConfig::loadSettings(): cast failed" << endl;
+ return;
+ }
+
+ mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
+
+ mFileNameEdit->setURL( resource->fileName() );
+ if ( mFileNameEdit->url().isEmpty() )
+ mFileNameEdit->setURL( KABC::StdAddressBook::fileName() );
+}
+
+void ResourceFileConfig::saveSettings( KRES::Resource *res )
+{
+ ResourceFile *resource = dynamic_cast<ResourceFile*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceFileConfig::saveSettings(): cast failed" << endl;
+ return;
+ }
+
+ if ( !mInEditMode )
+ resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
+
+ resource->setFileName( mFileNameEdit->url() );
+}
+
+void ResourceFileConfig::checkFilePermissions( const TQString& fileName )
+{
+ // If file exist but is not writeable...
+ if ( access( TQFile::encodeName( fileName ), F_OK ) == 0 )
+ emit setReadOnly( access( TQFile::encodeName( fileName ), W_OK ) < 0 );
+}
+
+#include "resourcefileconfig.moc"
diff --git a/tdeabc/plugins/file/resourcefileconfig.h b/tdeabc/plugins/file/resourcefileconfig.h
new file mode 100644
index 000000000..18c217eda
--- /dev/null
+++ b/tdeabc/plugins/file/resourcefileconfig.h
@@ -0,0 +1,57 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 Tobias Koenig <tokoe@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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef RESOURCEFILECONFIG_H
+#define RESOURCEFILECONFIG_H
+
+#include <kcombobox.h>
+#include <kurlrequester.h>
+
+#include <tderesources/configwidget.h>
+
+namespace KABC {
+
+class KABC_EXPORT ResourceFileConfig : public KRES::ConfigWidget
+{
+ Q_OBJECT
+
+public:
+ ResourceFileConfig( TQWidget* parent = 0, const char* name = 0 );
+
+ void setEditMode( bool value );
+
+public slots:
+ void loadSettings( KRES::Resource *resource );
+ void saveSettings( KRES::Resource *resource );
+
+protected slots:
+ void checkFilePermissions( const TQString& fileName );
+
+private:
+ KComboBox* mFormatBox;
+ KURLRequester* mFileNameEdit;
+ bool mInEditMode;
+
+ TQStringList mFormatTypes;
+};
+
+}
+
+#endif
diff --git a/tdeabc/plugins/file/resourcefileplugin.cpp b/tdeabc/plugins/file/resourcefileplugin.cpp
new file mode 100644
index 000000000..4dce19bc0
--- /dev/null
+++ b/tdeabc/plugins/file/resourcefileplugin.cpp
@@ -0,0 +1,32 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "resourcefile.h"
+#include "resourcefileconfig.h"
+
+using namespace KABC;
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_file()
+ {
+ return new KRES::PluginFactory<ResourceFile, ResourceFileConfig>();
+ }
+}