summaryrefslogtreecommitdiffstats
path: root/tdeabc/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'tdeabc/plugins')
-rw-r--r--tdeabc/plugins/CMakeLists.txt15
-rw-r--r--tdeabc/plugins/Makefile.am1
-rw-r--r--tdeabc/plugins/dir/CMakeLists.txt73
-rw-r--r--tdeabc/plugins/dir/Makefile.am28
-rw-r--r--tdeabc/plugins/dir/dir.desktop92
-rw-r--r--tdeabc/plugins/dir/resourcedir.cpp310
-rw-r--r--tdeabc/plugins/dir/resourcedir.h113
-rw-r--r--tdeabc/plugins/dir/resourcedirconfig.cpp107
-rw-r--r--tdeabc/plugins/dir/resourcedirconfig.h54
-rw-r--r--tdeabc/plugins/dir/resourcedirplugin.cpp32
-rw-r--r--tdeabc/plugins/evolution/Makefile.am19
-rw-r--r--tdeabc/plugins/evolution/README15
-rw-r--r--tdeabc/plugins/evolution/dbwrapper.cpp187
-rw-r--r--tdeabc/plugins/evolution/dbwrapper.h60
-rw-r--r--tdeabc/plugins/evolution/evolution.desktop26
-rw-r--r--tdeabc/plugins/evolution/resourceevo.cpp132
-rw-r--r--tdeabc/plugins/evolution/resourceevo.h23
-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
-rw-r--r--tdeabc/plugins/ldaptdeio/CMakeLists.txt73
-rw-r--r--tdeabc/plugins/ldaptdeio/Makefile.am28
-rw-r--r--tdeabc/plugins/ldaptdeio/ldaptdeio.desktop10
-rw-r--r--tdeabc/plugins/ldaptdeio/resourceldaptdeio.cpp1041
-rw-r--r--tdeabc/plugins/ldaptdeio/resourceldaptdeio.h171
-rw-r--r--tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp388
-rw-r--r--tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.h118
-rw-r--r--tdeabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp36
-rw-r--r--tdeabc/plugins/net/CMakeLists.txt73
-rw-r--r--tdeabc/plugins/net/Makefile.am28
-rw-r--r--tdeabc/plugins/net/net.desktop90
-rw-r--r--tdeabc/plugins/net/resourcenet.cpp393
-rw-r--r--tdeabc/plugins/net/resourcenet.h117
-rw-r--r--tdeabc/plugins/net/resourcenetconfig.cpp102
-rw-r--r--tdeabc/plugins/net/resourcenetconfig.h53
-rw-r--r--tdeabc/plugins/net/resourcenetplugin.cpp32
-rw-r--r--tdeabc/plugins/sql/Makefile.am20
-rw-r--r--tdeabc/plugins/sql/resourcesql.cpp338
-rw-r--r--tdeabc/plugins/sql/resourcesql.h63
-rw-r--r--tdeabc/plugins/sql/resourcesqlconfig.cpp95
-rw-r--r--tdeabc/plugins/sql/resourcesqlconfig.h51
-rw-r--r--tdeabc/plugins/sql/sql.desktop10
47 files changed, 5564 insertions, 0 deletions
diff --git a/tdeabc/plugins/CMakeLists.txt b/tdeabc/plugins/CMakeLists.txt
new file mode 100644
index 000000000..597486816
--- /dev/null
+++ b/tdeabc/plugins/CMakeLists.txt
@@ -0,0 +1,15 @@
+#################################################
+#
+# (C) 2010 Serghei Amelian
+# serghei (DOT) amelian (AT) gmail.com
+#
+# Improvements and feedback are welcome
+#
+# This file is released under GPL >= 2
+#
+#################################################
+
+add_subdirectory( file )
+add_subdirectory( dir )
+add_subdirectory( net )
+add_subdirectory( ldaptdeio )
diff --git a/tdeabc/plugins/Makefile.am b/tdeabc/plugins/Makefile.am
new file mode 100644
index 000000000..bdedbec0f
--- /dev/null
+++ b/tdeabc/plugins/Makefile.am
@@ -0,0 +1 @@
+SUBDIRS = file dir net ldaptdeio
diff --git a/tdeabc/plugins/dir/CMakeLists.txt b/tdeabc/plugins/dir/CMakeLists.txt
new file mode 100644
index 000000000..fd4161342
--- /dev/null
+++ b/tdeabc/plugins/dir/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
+ resourcedir.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/kabc )
+
+
+##### other data ################################
+
+install( FILES dir.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc )
+
+
+##### kabc_dir (library) ########################
+
+set( target kabc_dir )
+
+set( ${target}_SRCS
+ resourcedir.cpp resourcedirconfig.cpp
+)
+
+tde_add_library( ${target} SHARED AUTOMOC
+ SOURCES ${${target}_SRCS}
+ VERSION 1.0.0
+ LINK tdeabc-shared
+ DESTINATION ${LIB_INSTALL_DIR}
+)
+
+
+##### kabc_dir (module) #########################
+
+set( target kabc_dir )
+
+set( ${target}_SRCS
+ resourcedirplugin.cpp
+)
+
+tde_add_kpart( ${target}
+ SOURCES ${${target}_SRCS}
+ LINK kabc_dir-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdeabc/plugins/dir/Makefile.am b/tdeabc/plugins/dir/Makefile.am
new file mode 100644
index 000000000..94ddad3cc
--- /dev/null
+++ b/tdeabc/plugins/dir/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = -I$(top_builddir)/kabc -I$(top_srcdir)/kabc -I$(top_builddir) $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourcedirconfig.h
+
+lib_LTLIBRARIES = libkabc_dir.la
+libkabc_dir_la_SOURCES = resourcedir.cpp resourcedirconfig.cpp
+libkabc_dir_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -version-info 1:0:0 -no-undefined
+libkabc_dir_la_LIBADD = $(LIB_KABC) $(LIB_QT) $(top_builddir)/tderesources/libtderesources.la $(LIB_TDECORE) $(LIB_TDEFILE) $(LIB_TDEUI)
+libkabc_dir_la_COMPILE_FIRST = $(top_builddir)/tdeabc/addressee.h
+
+kde_module_LTLIBRARIES = kabc_dir.la
+kabc_dir_la_SOURCES = resourcedirplugin.cpp
+kabc_dir_la_LDFLAGS = -module $(KDE_PLUGIN) $(KDE_RPATH) $(all_libraries) -no-undefined
+kabc_dir_la_LIBADD = libkabc_dir.la $(LIB_QT) $(LIB_TDECORE)
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_dir.pot
+
+kabcincludedir = $(includedir)/kabc
+kabcinclude_HEADERS = resourcedir.h
+
+servicedir = $(kde_servicesdir)/tderesources/kabc
+service_DATA = dir.desktop
+
+resourcedirplugin.lo: ../../addressee.h
diff --git a/tdeabc/plugins/dir/dir.desktop b/tdeabc/plugins/dir/dir.desktop
new file mode 100644
index 000000000..a841040f9
--- /dev/null
+++ b/tdeabc/plugins/dir/dir.desktop
@@ -0,0 +1,92 @@
+[Desktop Entry]
+Name=Directory
+Name[af]=Gids
+Name[ar]=دليل
+Name[az]=Cərgə
+Name[be]=Тэчка
+Name[bn]=ডিরেক্টরি
+Name[br]=Renkell
+Name[bs]=Direktorij
+Name[ca]=Directori
+Name[cs]=Adresář
+Name[csb]=Katalog
+Name[cy]=Cyfeiriadur
+Name[da]=Mappe
+Name[de]=Verzeichnis
+Name[el]=Κατάλογος
+Name[eo]=Dosierujo
+Name[es]=Directorio
+Name[et]=Kataloog
+Name[eu]=Direktorioa
+Name[fa]=فهرست راهنما
+Name[fi]=Hakemisto
+Name[fo]=Fíluskrá
+Name[fr]=Dossier
+Name[fy]=Map
+Name[ga]=Comhadlann
+Name[gl]=Directório
+Name[he]=ספריה
+Name[hi]=डिरेक्ट्री
+Name[hr]=Mapa
+Name[hsb]=Zapisk
+Name[hu]=Könyvtár
+Name[id]=Direktori
+Name[is]=Mappa
+Name[it]=Cartella
+Name[ja]=ディレクトリ
+Name[ka]=დასტა
+Name[kk]=Каталог
+Name[km]=ថត
+Name[ko]=자료방
+Name[ku]=Peldank
+Name[lb]=Verzeechnis
+Name[lt]=Aplankas
+Name[lv]=Direktorija
+Name[mk]=Именик
+Name[mn]=Лавлах
+Name[ms]=Direktori
+Name[mt]=Direttorju
+Name[nb]=Katalog
+Name[nds]=Orner
+Name[ne]=डाइरेक्टरी
+Name[nl]=Map
+Name[nn]=Katalog
+Name[nso]=Tshupetso
+Name[oc]=Directori
+Name[pa]=ਡਾਇਰੈਕਟਰੀ
+Name[pl]=Katalog
+Name[pt]=Directoria
+Name[pt_BR]=Diretório
+Name[ro]=Director
+Name[ru]=Каталог
+Name[rw]=ububiko
+Name[se]=Ohcu
+Name[sk]=Priečinok
+Name[sl]=Imenik
+Name[sq]=Fioka
+Name[sr]=Фасцикла
+Name[sr@Latn]=Fascikla
+Name[ss]=I-directory
+Name[sv]=Katalog
+Name[ta]=அடைவு
+Name[te]=డైరక్టరి
+Name[tg]=Феҳраст
+Name[th]=ไดเรกทอรี
+Name[tr]=Dizin
+Name[tt]=Törgäk
+Name[uk]=Каталог
+Name[uz]=Jild
+Name[uz@cyrillic]=Жилд
+Name[ven]=Tsumbavhulwo
+Name[vi]=Thư mục
+Name[wa]=Ridant
+Name[xh]=Ulawulo
+Name[zh_CN]=目录
+Name[zh_HK]=目錄
+Name[zh_TW]=目錄
+Name[zu]=Uhlu lwamafayela
+X-TDE-Library=kabc_dir
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=dir
diff --git a/tdeabc/plugins/dir/resourcedir.cpp b/tdeabc/plugins/dir/resourcedir.cpp
new file mode 100644
index 000000000..53f178a6d
--- /dev/null
+++ b/tdeabc/plugins/dir/resourcedir.cpp
@@ -0,0 +1,310 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 - 2003 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 <errno.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <tqregexp.h>
+#include <tqtimer.h>
+#include <tqwidget.h>
+
+#include <tdeapplication.h>
+#include <tdeconfig.h>
+#include <kdebug.h>
+#include <kgenericfactory.h>
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <kstandarddirs.h>
+#include <kurlrequester.h>
+
+#include "addressbook.h"
+#include "formatfactory.h"
+#include "resourcedirconfig.h"
+#include "stdaddressbook.h"
+#include "lock.h"
+
+#include "resourcedir.h"
+
+using namespace KABC;
+
+extern "C"
+{
+ void *init_kabc_dir()
+ {
+ return new KRES::PluginFactory<ResourceDir,ResourceDirConfig>();
+ }
+}
+
+
+ResourceDir::ResourceDir( const TDEConfig *config )
+ : Resource( config ), mAsynchronous( false )
+{
+ if ( config ) {
+ init( config->readPathEntry( "FilePath", StdAddressBook::directoryName() ),
+ config->readEntry( "FileFormat", "vcard" ) );
+ } else {
+ init( StdAddressBook::directoryName(), "vcard" );
+ }
+}
+
+ResourceDir::ResourceDir( const TQString &path, const TQString &format )
+ : Resource( 0 ), mAsynchronous( false )
+{
+ init( path, format );
+}
+
+void ResourceDir::init( const TQString &path, const TQString &format )
+{
+ mFormatName = format;
+
+ FormatFactory *factory = FormatFactory::self();
+ mFormat = factory->format( mFormatName );
+
+ if ( !mFormat ) {
+ mFormatName = "vcard";
+ mFormat = factory->format( mFormatName );
+ }
+
+ mLock = 0;
+
+ connect( &mDirWatch, TQT_SIGNAL( dirty(const TQString&) ), TQT_SLOT( pathChanged() ) );
+ connect( &mDirWatch, TQT_SIGNAL( created(const TQString&) ), TQT_SLOT( pathChanged() ) );
+ connect( &mDirWatch, TQT_SIGNAL( deleted(const TQString&) ), TQT_SLOT( pathChanged() ) );
+
+ setPath( path );
+}
+
+ResourceDir::~ResourceDir()
+{
+ delete mFormat;
+ mFormat = 0;
+}
+
+void ResourceDir::writeConfig( TDEConfig *config )
+{
+ Resource::writeConfig( config );
+
+ if ( mPath == StdAddressBook::directoryName() )
+ config->deleteEntry( "FilePath" );
+ else
+ config->writePathEntry( "FilePath", mPath );
+
+ config->writeEntry( "FileFormat", mFormatName );
+}
+
+Ticket *ResourceDir::requestSaveTicket()
+{
+ kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl;
+
+ if ( !addressBook() ) return 0;
+
+ delete mLock;
+ mLock = new Lock( mPath );
+
+ if ( mLock->lock() ) {
+ addressBook()->emitAddressBookLocked();
+ } else {
+ addressBook()->error( mLock->error() );
+ kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock path '"
+ << mPath << "': " << mLock->error() << endl;
+ return 0;
+ }
+
+ return createTicket( this );
+}
+
+void ResourceDir::releaseSaveTicket( Ticket *ticket )
+{
+ delete ticket;
+
+ delete mLock;
+ mLock = 0;
+}
+
+bool ResourceDir::doOpen()
+{
+ TQDir dir( mPath );
+ if ( !dir.exists() ) { // no directory available
+ return dir.mkdir( dir.path() );
+ } else {
+ TQString testName = dir.entryList( TQDir::Files )[0];
+ if ( testName.isNull() || testName.isEmpty() ) // no file in directory
+ return true;
+
+ TQFile file( mPath + "/" + testName );
+ if ( file.open( IO_ReadOnly ) )
+ return true;
+
+ if ( file.size() == 0 )
+ return true;
+
+ bool ok = mFormat->checkFormat( &file );
+ file.close();
+ return ok;
+ }
+}
+
+void ResourceDir::doClose()
+{
+}
+
+bool ResourceDir::load()
+{
+ kdDebug(5700) << "ResourceDir::load(): '" << mPath << "'" << endl;
+
+ mAsynchronous = false;
+
+ TQDir dir( mPath );
+ TQStringList files = dir.entryList( TQDir::Files );
+
+ TQStringList::Iterator it;
+ bool ok = true;
+ for ( it = files.begin(); it != files.end(); ++it ) {
+ TQFile file( mPath + "/" + (*it) );
+
+ if ( !file.open( IO_ReadOnly ) ) {
+ addressBook()->error( i18n( "Unable to open file '%1' for reading" ).arg( file.name() ) );
+ ok = false;
+ continue;
+ }
+
+ if ( !mFormat->loadAll( addressBook(), this, &file ) )
+ ok = false;
+
+ file.close();
+ }
+
+ return ok;
+}
+
+bool ResourceDir::asyncLoad()
+{
+ mAsynchronous = true;
+
+ bool ok = load();
+ if ( !ok )
+ emit loadingError( this, i18n( "Loading resource '%1' failed!" )
+ .arg( resourceName() ) );
+ else
+ emit loadingFinished( this );
+
+ return ok;
+}
+
+bool ResourceDir::save( Ticket * )
+{
+ kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl;
+
+ Addressee::Map::Iterator it;
+ bool ok = true;
+
+ mDirWatch.stopScan();
+
+ for ( it = mAddrMap.begin(); it != mAddrMap.end(); ++it ) {
+ if ( !it.data().changed() )
+ continue;
+
+ TQFile file( mPath + "/" + (*it).uid() );
+ if ( !file.open( IO_WriteOnly ) ) {
+ addressBook()->error( i18n( "Unable to open file '%1' for writing" ).arg( file.name() ) );
+ continue;
+ }
+
+ mFormat->save( *it, &file );
+
+ // mark as unchanged
+ (*it).setChanged( false );
+
+ file.close();
+ }
+
+ mDirWatch.startScan();
+
+ return ok;
+}
+
+bool ResourceDir::asyncSave( Ticket *ticket )
+{
+ bool ok = save( ticket );
+ if ( !ok )
+ emit savingError( this, i18n( "Saving resource '%1' failed!" )
+ .arg( resourceName() ) );
+ else
+ emit savingFinished( this );
+
+ return ok;
+}
+
+void ResourceDir::setPath( const TQString &path )
+{
+ mDirWatch.stopScan();
+ if ( mDirWatch.contains( mPath ) )
+ mDirWatch.removeDir( mPath );
+
+ mPath = path;
+ mDirWatch.addDir( mPath, true );
+ mDirWatch.startScan();
+}
+
+TQString ResourceDir::path() const
+{
+ return mPath;
+}
+
+void ResourceDir::setFormat( const TQString &format )
+{
+ mFormatName = format;
+
+ if ( mFormat )
+ delete mFormat;
+
+ FormatFactory *factory = FormatFactory::self();
+ mFormat = factory->format( mFormatName );
+}
+
+TQString ResourceDir::format() const
+{
+ return mFormatName;
+}
+
+void ResourceDir::pathChanged()
+{
+ if ( !addressBook() )
+ return;
+
+ clear();
+ if ( mAsynchronous )
+ asyncLoad();
+ else {
+ load();
+ addressBook()->emitAddressBookChanged();
+ }
+}
+
+void ResourceDir::removeAddressee( const Addressee& addr )
+{
+ TQFile::remove( mPath + "/" + addr.uid() );
+ mAddrMap.erase( addr.uid() );
+}
+
+#include "resourcedir.moc"
diff --git a/tdeabc/plugins/dir/resourcedir.h b/tdeabc/plugins/dir/resourcedir.h
new file mode 100644
index 000000000..dc3bdbd23
--- /dev/null
+++ b/tdeabc/plugins/dir/resourcedir.h
@@ -0,0 +1,113 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 - 2003 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 KABC_RESOURCEDIR_H
+#define KABC_RESOURCEDIR_H
+
+#include <tdeconfig.h>
+#include <kdirwatch.h>
+
+#include <sys/types.h>
+
+#include <tdeabc/resource.h>
+
+class TQTimer;
+
+namespace KABC {
+
+class FormatPlugin;
+class Lock;
+
+/**
+ @internal
+*/
+class KABC_EXPORT ResourceDir : public Resource
+{
+ Q_OBJECT
+
+ public:
+ ResourceDir( const TDEConfig* );
+ ResourceDir( const TQString &path, const TQString &type = "vcard" );
+ ~ResourceDir();
+
+ virtual void writeConfig( TDEConfig* );
+
+ virtual bool doOpen();
+ virtual void doClose();
+
+ virtual Ticket *requestSaveTicket();
+ virtual void releaseSaveTicket( Ticket* );
+
+ virtual bool load();
+ virtual bool asyncLoad();
+ virtual bool save( Ticket* ticket );
+ virtual bool asyncSave( Ticket* ticket );
+
+ /**
+ Set path to be used for saving.
+ */
+ void setPath( const TQString & );
+
+ /**
+ Return path used for loading and saving the address book.
+ */
+ TQString path() const;
+
+ /**
+ Set the format by name.
+ */
+ void setFormat( const TQString &format );
+
+ /**
+ 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 );
+
+ protected slots:
+ void pathChanged();
+
+ protected:
+ void init( const TQString &path, const TQString &format );
+
+ private:
+ FormatPlugin *mFormat;
+
+ KDirWatch mDirWatch;
+
+ TQString mPath;
+ TQString mFormatName;
+
+ Lock *mLock;
+
+ bool mAsynchronous;
+
+ class ResourceDirPrivate;
+ ResourceDirPrivate *d;
+};
+
+}
+
+#endif
diff --git a/tdeabc/plugins/dir/resourcedirconfig.cpp b/tdeabc/plugins/dir/resourcedirconfig.cpp
new file mode 100644
index 000000000..2807872f8
--- /dev/null
+++ b/tdeabc/plugins/dir/resourcedirconfig.cpp
@@ -0,0 +1,107 @@
+/*
+ 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 "formatfactory.h"
+#include "resourcedir.h"
+#include "stdaddressbook.h"
+
+#include "resourcedirconfig.h"
+
+using namespace KABC;
+
+ResourceDirConfig::ResourceDirConfig( TQWidget* parent, const char* name )
+ : KRES::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 );
+ mFileNameEdit->setMode( KFile::Directory );
+
+ 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 ResourceDirConfig::setEditMode( bool value )
+{
+ mFormatBox->setEnabled( !value );
+ mInEditMode = value;
+}
+
+void ResourceDirConfig::loadSettings( KRES::Resource *res )
+{
+ ResourceDir *resource = dynamic_cast<ResourceDir*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl;
+ return;
+ }
+
+ mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
+
+ mFileNameEdit->setURL( resource->path() );
+ if ( mFileNameEdit->url().isEmpty() )
+ mFileNameEdit->setURL( KABC::StdAddressBook::directoryName() );
+}
+
+void ResourceDirConfig::saveSettings( KRES::Resource *res )
+{
+ ResourceDir *resource = dynamic_cast<ResourceDir*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceDirConfig::loadSettings(): cast failed" << endl;
+ return;
+ }
+
+ if ( mInEditMode )
+ resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
+
+ resource->setPath( mFileNameEdit->url() );
+}
+
+#include "resourcedirconfig.moc"
diff --git a/tdeabc/plugins/dir/resourcedirconfig.h b/tdeabc/plugins/dir/resourcedirconfig.h
new file mode 100644
index 000000000..9df1778d3
--- /dev/null
+++ b/tdeabc/plugins/dir/resourcedirconfig.h
@@ -0,0 +1,54 @@
+/*
+ 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 RESOURCEDIRCONFIG_H
+#define RESOURCEDIRCONFIG_H
+
+#include <kcombobox.h>
+#include <kurlrequester.h>
+
+#include <tderesources/configwidget.h>
+
+namespace KABC {
+
+class KABC_EXPORT ResourceDirConfig : public KRES::ConfigWidget
+{
+ Q_OBJECT
+
+public:
+ ResourceDirConfig( TQWidget* parent = 0, const char* name = 0 );
+
+ void setEditMode( bool value );
+
+public slots:
+ void loadSettings( KRES::Resource* );
+ void saveSettings( KRES::Resource* );
+
+private:
+ KComboBox* mFormatBox;
+ KURLRequester* mFileNameEdit;
+
+ TQStringList mFormatTypes;
+
+ bool mInEditMode;
+};
+
+}
+#endif
diff --git a/tdeabc/plugins/dir/resourcedirplugin.cpp b/tdeabc/plugins/dir/resourcedirplugin.cpp
new file mode 100644
index 000000000..a2bd6d138
--- /dev/null
+++ b/tdeabc/plugins/dir/resourcedirplugin.cpp
@@ -0,0 +1,32 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 - 2003 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 "resourcedir.h"
+#include "resourcedirconfig.h"
+
+using namespace KABC;
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_dir()
+ {
+ return new KRES::PluginFactory<ResourceDir, ResourceDirConfig>();
+ }
+}
diff --git a/tdeabc/plugins/evolution/Makefile.am b/tdeabc/plugins/evolution/Makefile.am
new file mode 100644
index 000000000..2c22cf376
--- /dev/null
+++ b/tdeabc/plugins/evolution/Makefile.am
@@ -0,0 +1,19 @@
+INCLUDES = -I$(top_builddir)/kabc -I$(top_srcdir)/kabc $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourceevo.h dbwrapper.h
+
+kde_module_LTLIBRARIES = kabc_evo.la
+
+kabc_evo_la_SOURCES = dbwrapper.cpp resourceevo.cpp
+
+kabc_evo_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kabc_evo_la_LIBADD = ../../../tdeabc/libkabc.la ../../../tdeui/libtdeui.la -ldb ../../../tdeabc/vcardparser/libvcards.la
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_evolution.pot
+
+servicedir = $(kde_servicesdir)/tderesources/kabc
+service_DATA = evolution.desktop
diff --git a/tdeabc/plugins/evolution/README b/tdeabc/plugins/evolution/README
new file mode 100644
index 000000000..7dfefce00
--- /dev/null
+++ b/tdeabc/plugins/evolution/README
@@ -0,0 +1,15 @@
+A Resource using DB3 to access the evolution
+addressbook make sure the wombat is not running
+In future versions I may use bonobo to access it...
+
+
+DESIGN:
+The Format vs Resource idea is somehow not applyable to the
+Evolution PAS
+
+Format would be vCard and Resource would be DB3..
+BUT
+Format get's a QFile* pointer which is just not usable
+with a DB3
+INSTEAD we will use the vCardImpl directly to convert
+a string to Addressee \ No newline at end of file
diff --git a/tdeabc/plugins/evolution/dbwrapper.cpp b/tdeabc/plugins/evolution/dbwrapper.cpp
new file mode 100644
index 000000000..fbdff165a
--- /dev/null
+++ b/tdeabc/plugins/evolution/dbwrapper.cpp
@@ -0,0 +1,187 @@
+#include <db.h>
+
+#include <tqfile.h>
+
+#include "dbwrapper.h"
+
+
+using namespace Evolution;
+
+struct DBIterator::Data {
+ DBWrapper *wrapper;
+ TQString key;
+ TQString data;
+ DBC* cursor;
+ bool atEnd;
+};
+
+DBIterator::DBIterator( DBWrapper* wra) {
+ data = new Data;
+ data->wrapper = wra;
+ data->atEnd = false;
+ data->cursor = 0l;
+}
+DBIterator::DBIterator( const DBIterator& copy ) {
+ data = new Data;
+ data->wrapper = copy.data->wrapper;
+ data->key = copy.data->key;
+ data->data = copy.data->data;
+ data->atEnd = copy.data->atEnd;
+ if (copy.data->cursor )
+ copy.data->cursor->c_dup(copy.data->cursor, &data->cursor, 0 );
+ else
+ data->cursor = 0l;
+}
+DBIterator::~DBIterator() {
+ if (data->cursor)
+ data->cursor->c_close(data->cursor);
+ delete data;
+}
+DBIterator& DBIterator::operator=( const DBIterator& rhs ) {
+ if ( *this == rhs )
+ return *this;
+ if (data->cursor)
+ data->cursor->c_close(data->cursor);
+ delete data;
+ data = new Data;
+ data->wrapper = rhs.data->wrapper;
+ data->key = rhs.data->key;
+ data->data = rhs.data->data;
+ data->atEnd = rhs.data->atEnd;
+ if ( rhs.data->cursor )
+ rhs.data->cursor->c_dup(rhs.data->cursor, &data->cursor, 0 );
+ else
+ data->cursor = 0l;
+
+ return *this;
+}
+TQString DBIterator::key()const{
+ return data->key;
+}
+TQString DBIterator::value()const {
+ return data->data;
+}
+TQString DBIterator::operator*() {
+ return data->data;
+}
+DBIterator& DBIterator::operator++() {
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+ if ( data->cursor )
+ if ( data->cursor->c_get(data->cursor, &key, &val,DB_NEXT ) != 0 )
+ data->atEnd = true;
+ data->key = TQString::fromUtf8( (char*)key.data, key.size );
+ data->data = TQString::fromUtf8( (char*)val.data, val.size );
+ return *this;
+}
+DBIterator& DBIterator::operator--() {
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+ if ( data->cursor )
+ if ( data->cursor->c_get(data->cursor, &key, &val,DB_PREV ) != 0 )
+ data->atEnd = true;
+ data->key = TQString::fromUtf8( (char*)key.data, key.size );
+ data->data = TQString::fromUtf8( (char*)val.data, val.size );
+ return *this;
+}
+bool DBIterator::operator==( const DBIterator& rhs ) {
+ if ( data->atEnd && data->atEnd == rhs.data->atEnd ) return true;
+
+ return false;
+}
+bool DBIterator::operator!=( const DBIterator& rhs ) {
+ return !this->operator==(rhs );
+}
+struct DBWrapper::Data {
+ DB* db;
+ bool only;
+};
+DBWrapper::DBWrapper() {
+ data = new Data;
+ (void)db_create(&data->db, NULL, 0 );
+ data->only = false;
+}
+DBWrapper::~DBWrapper() {
+ data->db->close(data->db, 0 );
+ delete data;
+}
+bool DBWrapper::open( const TQString& file, bool on) {
+ data->only = on;
+ return !data->db->open(data->db, TQFile::encodeName( file ), NULL, DB_HASH, 0, 0666 );
+}
+bool DBWrapper::save() {
+ return true;
+}
+DBIterator DBWrapper::begin() {
+ DBIterator it(this);
+ DBC* cursor;
+ DBT key, val;
+ int ret;
+ ret = data->db->cursor(data->db, NULL, &cursor, 0 );
+ if (ret ) {
+ it.data->atEnd = true;
+ return it;
+ }
+
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+ ret = cursor->c_get(cursor, &key, &val, DB_FIRST );
+ if (ret ) {
+ it.data->atEnd = true;
+ return it;
+ }
+
+ it.data->cursor = cursor;
+ it.data->key = TQString::fromUtf8((char*)key.data, key.size );
+ it.data->data = TQString::fromUtf8((char*)val.data, val.size );
+
+ return it;
+}
+DBIterator DBWrapper::end() {
+ DBIterator it(this);
+ it.data->atEnd = true;
+
+ return it;
+}
+bool DBWrapper::find( const TQString& _key, TQString& _val ) {
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+
+ TQCString db_key = _key.local8Bit();
+ key.data = db_key.data();
+ key.size = db_key.size();
+
+ int ret = data->db->get(data->db, NULL, &key, &val, 0 );
+ if (!ret) {
+ _val = TQString::fromUtf8( (char*)val.data, val.size );
+ tqWarning("key: %s val: %sXXX", (char*)key.data, (char*)val.data );
+ return true;
+ }
+ return false;
+}
+bool DBWrapper::add( const TQString& _key, const TQString& _val ) {
+ TQCString db_key = _key.local8Bit();
+ TQCString db_val = _val.local8Bit();
+ DBT key, val;
+ ::memset(&key, 0, sizeof(key) );
+ ::memset(&val, 0, sizeof(val) );
+
+ key.data = db_key.data();
+ key.size = db_key.size();
+ val.data = db_val.data();
+ val.size = db_val.size();
+
+ return !data->db->put(data->db, NULL, &key, &val, 0 );
+}
+bool DBWrapper::remove( const TQString& _key ) {
+ TQCString db_key = _key.local8Bit();
+ DBT key;
+ memset(&key, 0, sizeof(key) );
+ key.data = db_key.data();
+ key.size = db_key.size();
+
+ return !data->db->del(data->db, NULL, &key, 0 );
+}
diff --git a/tdeabc/plugins/evolution/dbwrapper.h b/tdeabc/plugins/evolution/dbwrapper.h
new file mode 100644
index 000000000..e5e0a2c33
--- /dev/null
+++ b/tdeabc/plugins/evolution/dbwrapper.h
@@ -0,0 +1,60 @@
+#ifndef KABC_EVOLUTION_DB_WRAPPER
+#define KABC_EVOLUTION_DB_WRAPPER
+
+#include <db.h>
+
+#include <tqstring.h>
+#include <tqpair.h>
+
+namespace Evolution {
+
+ class DBWrapper;
+ class DBIterator {
+ friend class DBWrapper;
+ public:
+ DBIterator( DBWrapper* = 0l );
+ ~DBIterator();
+
+ DBIterator( const DBIterator& );
+ DBIterator &operator=( const DBIterator& );
+
+ TQString key()const;
+ TQString value()const;
+
+ TQString operator*();
+
+ DBIterator &operator++();
+ DBIterator &operator--();
+
+ bool operator==( const DBIterator& );
+ bool operator!=( const DBIterator& );
+ private:
+ struct Data;
+ Data* data;
+ };
+ class DBWrapper {
+ public:
+ DBWrapper();
+ ~DBWrapper();
+
+ TQString lastError()const;
+
+ bool open( const TQString& file, bool readOnly = false);
+ bool save();
+ DBIterator begin();
+ DBIterator end();
+
+ bool find( const TQString& key, TQString& value );
+ bool add( const TQString& key, const TQString& val );
+ bool remove( const TQString& key );
+ private:
+ // DBT element( const TQString& );
+ struct Data;
+ Data* data;
+
+ };
+
+}
+
+
+#endif
diff --git a/tdeabc/plugins/evolution/evolution.desktop b/tdeabc/plugins/evolution/evolution.desktop
new file mode 100644
index 000000000..98030e906
--- /dev/null
+++ b/tdeabc/plugins/evolution/evolution.desktop
@@ -0,0 +1,26 @@
+[Desktop Entry]
+Name=Evolution
+Name[be]=Эвалюцыя
+Name[bn]=ইভোলিউশন
+Name[eo]=Evoluo
+Name[fa]=اوولوشن
+Name[hi]=एवॉल्यूशन
+Name[ko]=에볼루션
+Name[mn]=Хөгжил
+Name[ne]=इभोल्युसन
+Name[pa]=ਏਵੂਲੇਸ਼ਨ
+Name[sr]=Еволуција
+Name[sr@Latn]=Evolucija
+Name[ta]=படிப்படியான வளர்ச்சி
+Name[te]=ఎవల్యుషన్
+Name[th]=เอฟโวลูชัน
+Name[tt]=Üseş
+Name[ven]=Tsikoni
+Name[wa]=Evolucion
+Name[xh]=Utshintsho lwendawo ngokwenqanawa
+Name[zu]=Evolushini
+X-TDE-Library=kabc_evo
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=evolution
diff --git a/tdeabc/plugins/evolution/resourceevo.cpp b/tdeabc/plugins/evolution/resourceevo.cpp
new file mode 100644
index 000000000..e6545f738
--- /dev/null
+++ b/tdeabc/plugins/evolution/resourceevo.cpp
@@ -0,0 +1,132 @@
+#include <tqdir.h>
+
+#include <tdeglobal.h>
+#include <tdelocale.h>
+#include <kdebug.h>
+
+#include <stdio.h>
+
+#include <tdeabc/vcardparser/vcardtool.h>
+
+#include "dbwrapper.h"
+#include "resourceevo.h"
+
+using namespace Evolution;
+using namespace KABC;
+
+class EvolutionFactory : public KRES::PluginFactoryBase
+{
+ public:
+ KRES::Resource *resource( const TDEConfig *config )
+ {
+ return new ResourceEvolution( config );
+ }
+
+ KRES::ConfigWidget *configWidget( TQWidget * )
+ {
+ return 0;
+ }
+};
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_evo()
+ {
+ return ( new EvolutionFactory() );
+ }
+}
+
+ResourceEvolution::ResourceEvolution( const TDEConfig* conf )
+ : Resource( conf ), mWrap(0l)
+{
+ m_isOpen = false;
+}
+ResourceEvolution::~ResourceEvolution() {
+ delete mWrap;
+}
+bool ResourceEvolution::doOpen() {
+ mWrap = new DBWrapper;
+ if (!mWrap->open( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db" ) ) {
+ return false;
+ }
+
+ TQString val;
+ if (!mWrap->find( "PAS-DB-VERSION", val ) )
+ return false;
+
+ if (!val.startsWith("0.2") )
+ return false;
+
+ m_isOpen = true;
+
+ return true;
+}
+void ResourceEvolution::doClose() {
+ delete mWrap;
+ mWrap = 0l;
+ m_isOpen = false;
+}
+Ticket* ResourceEvolution::requestSaveTicket() {
+ if ( !addressBook() ) return 0;
+ return createTicket( this );
+}
+/*
+ * skip the first key
+ */
+
+bool ResourceEvolution::load() {
+ /* doOpen never get's called :( */
+ if (!doOpen()) return false;
+ if (!mWrap ) return false; // open first!
+
+ DBIterator it = mWrap->begin();
+ // skip the "PAS-DB-VERSION"
+
+ for ( ; it != mWrap->end(); ++it ) {
+ if ( it.key().startsWith("PAS-DB-VERSION") )
+ continue;
+
+ tqWarning( "val:%s", it.value().latin1() );
+ VCardTool tool;
+ TQString str = it.value().stripWhiteSpace();
+ Addressee::List list = tool.parseVCards( str );
+ if (!list.first().isEmpty() ) {
+ Addressee adr = list.first();
+ adr.setResource(this);
+ addressBook()->insertAddressee( adr );
+ }
+ }
+ return true;
+}
+bool ResourceEvolution::save( Ticket* ticket ) {
+ delete ticket;
+ if (!m_isOpen ) return false;
+
+ // just delete the summary so evolution will regenerate it
+ // on next start up
+ (void)TQFile::remove( TQDir::homeDirPath() + "/evolution/local/Contacts/addressbook.db.summary" );
+
+
+ AddressBook::Iterator it;
+ Addressee::List list;
+ for ( it = addressBook()->begin(); it !=addressBook()->end(); ++it ) {
+ if ( (*it).resource() != this || !(*it).changed() )
+ continue;
+
+ // remove, convert add set unchanged false
+ list.clear();
+ mWrap->remove( (*it).uid() );
+ VCardTool tool;
+ list.append( (*it) );
+ mWrap->add( (*it).uid(), tool.createVCards( list, VCard::v2_1) );
+
+ (*it).setChanged( false );
+ }
+
+ return true;
+}
+void ResourceEvolution::removeAddressee( const Addressee& rem) {
+ if (!m_isOpen) return;
+
+ mWrap->remove( rem.uid() );
+}
diff --git a/tdeabc/plugins/evolution/resourceevo.h b/tdeabc/plugins/evolution/resourceevo.h
new file mode 100644
index 000000000..29e163e1c
--- /dev/null
+++ b/tdeabc/plugins/evolution/resourceevo.h
@@ -0,0 +1,23 @@
+#include "resource.h"
+
+namespace Evolution {
+ class DBWrapper;
+}
+
+namespace KABC {
+ class ResourceEvolution : public Resource {
+ public:
+ ResourceEvolution( const TDEConfig* config );
+ ~ResourceEvolution();
+
+ bool doOpen();
+ void doClose();
+ Ticket* requestSaveTicket();
+ bool load();
+ bool save( Ticket* ticket );
+ void removeAddressee( const Addressee& );
+ private:
+ Evolution::DBWrapper *mWrap;
+ bool m_isOpen : 1;
+ };
+}
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>();
+ }
+}
diff --git a/tdeabc/plugins/ldaptdeio/CMakeLists.txt b/tdeabc/plugins/ldaptdeio/CMakeLists.txt
new file mode 100644
index 000000000..820f6e017
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/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/tdefiles
+)
+
+link_directories(
+ ${TQT_LIBRARY_DIRS}
+)
+
+
+##### headers ###################################
+
+install( FILES
+ resourceldaptdeio.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/kabc )
+
+
+##### other data ################################
+
+install( FILES ldaptdeio.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc )
+
+
+##### kabc_ldaptdeio ##############################
+
+set( target kabc_ldaptdeio )
+
+set( ${target}_SRCS
+ resourceldaptdeio.cpp resourceldaptdeioconfig.cpp
+)
+
+tde_add_library( ${target} SHARED AUTOMOC
+ SOURCES ${${target}_SRCS}
+ VERSION 1.0.0
+ LINK tdeabc-shared
+ DESTINATION ${LIB_INSTALL_DIR}
+)
+
+
+##### kabc_ldaptdeio ##############################
+
+set( target kabc_ldaptdeio )
+
+set( ${target}_SRCS
+ resourceldaptdeioplugin.cpp
+)
+
+tde_add_kpart( ${target}
+ SOURCES ${${target}_SRCS}
+ LINK kabc_ldaptdeio-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdeabc/plugins/ldaptdeio/Makefile.am b/tdeabc/plugins/ldaptdeio/Makefile.am
new file mode 100644
index 000000000..bc81d13d8
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = -I$(top_srcdir)/kabc -I$(top_builddir)/kabc $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourceldaptdeioconfig.h
+
+lib_LTLIBRARIES = libkabc_ldaptdeio.la
+libkabc_ldaptdeio_la_SOURCES = resourceldaptdeio.cpp resourceldaptdeioconfig.cpp
+libkabc_ldaptdeio_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -version-info 1:0:0 -no-undefined
+libkabc_ldaptdeio_la_LIBADD = $(LIB_KABC) $(LIB_KIO) $(LIB_QT) $(top_builddir)/tderesources/libtderesources.la $(LIB_TDEUI) $(LIB_TDECORE)
+libkabc_ldaptdeio_la_COMPILE_FIRST = $(top_builddir)/tdeabc/addressee.h
+
+kde_module_LTLIBRARIES = kabc_ldaptdeio.la
+kabc_ldaptdeio_la_SOURCES = resourceldaptdeioplugin.cpp
+kabc_ldaptdeio_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kabc_ldaptdeio_la_LIBADD = libkabc_ldaptdeio.la $(LIB_QT) $(LIB_TDECORE)
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_ldaptdeio.pot
+
+kabcincludedir = $(includedir)/kabc
+kabcinclude_HEADERS = resourceldaptdeio.h
+
+servicedir = $(kde_servicesdir)/tderesources/kabc
+service_DATA = ldaptdeio.desktop
+
+resourceldaptdeioplugin.lo: ../../addressee.h
diff --git a/tdeabc/plugins/ldaptdeio/ldaptdeio.desktop b/tdeabc/plugins/ldaptdeio/ldaptdeio.desktop
new file mode 100644
index 000000000..9bcd13337
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/ldaptdeio.desktop
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Name=LDAP
+Name[bn]=এল-ডি-এ-পি (LDAP)
+Name[hi]=एलडीएपी (LDAP)
+Name[te]=ఎల్డిఏపి
+X-TDE-Library=kabc_ldaptdeio
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=ldaptdeio
diff --git a/tdeabc/plugins/ldaptdeio/resourceldaptdeio.cpp b/tdeabc/plugins/ldaptdeio/resourceldaptdeio.cpp
new file mode 100644
index 000000000..ea1a4294c
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/resourceldaptdeio.cpp
@@ -0,0 +1,1041 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+ Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
+
+ 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 <tqapplication.h>
+#include <tqbuffer.h>
+#include <tqfile.h>
+
+#include <kdebug.h>
+#include <tdeglobal.h>
+#include <kstandarddirs.h>
+#include <klineedit.h>
+#include <tdelocale.h>
+#include <tdeconfig.h>
+#include <kstringhandler.h>
+#include <tdetempfile.h>
+
+#include <stdlib.h>
+#include <tdeio/netaccess.h>
+#include <tdeabc/ldif.h>
+#include <tdeabc/ldapurl.h>
+
+#include "resourceldaptdeio.h"
+#include "resourceldaptdeioconfig.h"
+
+using namespace KABC;
+
+// Hack from Netaccess
+void tqt_enter_modal( TQWidget *widget );
+void tqt_leave_modal( TQWidget *widget );
+
+class ResourceLDAPTDEIO::ResourceLDAPTDEIOPrivate
+{
+ public:
+ LDIF mLdif;
+ bool mTLS,mSSL,mSubTree;
+ TQString mResultDn;
+ Addressee mAddr;
+ Address mAd;
+ Resource::Iterator mSaveIt;
+ bool mSASL;
+ TQString mMech;
+ TQString mRealm, mBindDN;
+ LDAPUrl mLDAPUrl;
+ int mVer, mSizeLimit, mTimeLimit, mRDNPrefix;
+ int mError;
+ int mCachePolicy;
+ bool mReadOnly;
+ bool mAutoCache;
+ TQString mCacheDst;
+ KTempFile *mTmp;
+};
+
+ResourceLDAPTDEIO::ResourceLDAPTDEIO( const TDEConfig *config )
+ : Resource( config )
+{
+ d = new ResourceLDAPTDEIOPrivate;
+ if ( config ) {
+ TQMap<TQString, TQString> attrList;
+ TQStringList attributes = config->readListEntry( "LdapAttributes" );
+ for ( uint pos = 0; pos < attributes.count(); pos += 2 )
+ mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] );
+
+ mUser = config->readEntry( "LdapUser" );
+ mPassword = KStringHandler::obscure( config->readEntry( "LdapPassword" ) );
+ mDn = config->readEntry( "LdapDn" );
+ mHost = config->readEntry( "LdapHost" );
+ mPort = config->readNumEntry( "LdapPort", 389 );
+ mFilter = config->readEntry( "LdapFilter" );
+ mAnonymous = config->readBoolEntry( "LdapAnonymous" );
+ d->mTLS = config->readBoolEntry( "LdapTLS" );
+ d->mSSL = config->readBoolEntry( "LdapSSL" );
+ d->mSubTree = config->readBoolEntry( "LdapSubTree" );
+ d->mSASL = config->readBoolEntry( "LdapSASL" );
+ d->mMech = config->readEntry( "LdapMech" );
+ d->mRealm = config->readEntry( "LdapRealm" );
+ d->mBindDN = config->readEntry( "LdapBindDN" );
+ d->mVer = config->readNumEntry( "LdapVer", 3 );
+ d->mTimeLimit = config->readNumEntry( "LdapTimeLimit", 0 );
+ d->mSizeLimit = config->readNumEntry( "LdapSizeLimit", 0 );
+ d->mRDNPrefix = config->readNumEntry( "LdapRDNPrefix", 0 );
+ d->mCachePolicy = config->readNumEntry( "LdapCachePolicy", 0 );
+ d->mAutoCache = config->readBoolEntry( "LdapAutoCache", true );
+ } else {
+ mPort = 389;
+ mAnonymous = true;
+ mUser = mPassword = mHost = mFilter = mDn = "";
+ d->mMech = d->mRealm = d->mBindDN = "";
+ d->mTLS = d->mSSL = d->mSubTree = d->mSASL = false;
+ d->mVer = 3; d->mRDNPrefix = 0;
+ d->mTimeLimit = d->mSizeLimit = 0;
+ d->mCachePolicy = Cache_No;
+ d->mAutoCache = true;
+ }
+ d->mCacheDst = TDEGlobal::dirs()->saveLocation("cache", "ldaptdeio") + "/" +
+ type() + "_" + identifier();
+ init();
+}
+
+ResourceLDAPTDEIO::~ResourceLDAPTDEIO()
+{
+ delete d;
+}
+
+void ResourceLDAPTDEIO::enter_loop()
+{
+ TQWidget dummy(0,0,(WFlags)(WType_Dialog | WShowModal));
+ dummy.setFocusPolicy( TQ_NoFocus );
+ tqt_enter_modal(&dummy);
+ tqApp->enter_loop();
+ tqt_leave_modal(&dummy);
+}
+
+void ResourceLDAPTDEIO::entries( TDEIO::Job*, const TDEIO::UDSEntryList & list )
+{
+ TDEIO::UDSEntryListConstIterator it = list.begin();
+ TDEIO::UDSEntryListConstIterator end = list.end();
+ for (; it != end; ++it) {
+ TDEIO::UDSEntry::ConstIterator it2 = (*it).begin();
+ for( ; it2 != (*it).end(); it2++ ) {
+ if ( (*it2).m_uds == TDEIO::UDS_URL ) {
+ KURL tmpurl( (*it2).m_str );
+ d->mResultDn = tmpurl.path();
+ kdDebug(7125) << "findUid(): " << d->mResultDn << endl;
+ if ( d->mResultDn.startsWith("/") ) d->mResultDn.remove(0,1);
+ return;
+ }
+ }
+ }
+}
+
+void ResourceLDAPTDEIO::listResult( TDEIO::Job *job)
+{
+ d->mError = job->error();
+ if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED )
+ mErrorMsg = job->errorString();
+ else
+ mErrorMsg = "";
+ tqApp->exit_loop();
+}
+
+TQString ResourceLDAPTDEIO::findUid( const TQString &uid )
+{
+ LDAPUrl url( d->mLDAPUrl );
+ TDEIO::UDSEntry entry;
+
+ mErrorMsg = d->mResultDn = "";
+
+ url.setAttributes("dn");
+ url.setFilter( "(" + mAttributes[ "uid" ] + "=" + uid + ")" + mFilter );
+ url.setExtension( "x-dir", "one" );
+
+ kdDebug(7125) << "ResourceLDAPTDEIO::findUid() uid: " << uid << " url " <<
+ url.prettyURL() << endl;
+
+ TDEIO::ListJob * listJob = TDEIO::listDir( url, false /* no GUI */ );
+ connect( listJob,
+ TQT_SIGNAL( entries( TDEIO::Job *, const TDEIO::UDSEntryList& ) ),
+ TQT_SLOT( entries( TDEIO::Job*, const TDEIO::UDSEntryList& ) ) );
+ connect( listJob, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( listResult( TDEIO::Job* ) ) );
+
+ enter_loop();
+ return d->mResultDn;
+}
+
+TQCString ResourceLDAPTDEIO::addEntry( const TQString &attr, const TQString &value, bool mod )
+{
+ TQCString tmp;
+ if ( !attr.isEmpty() ) {
+ if ( mod ) tmp += LDIF::assembleLine( "replace", attr ) + "\n";
+ tmp += LDIF::assembleLine( attr, value ) + "\n";
+ if ( mod ) tmp += "-\n";
+ }
+ return ( tmp );
+}
+
+bool ResourceLDAPTDEIO::AddresseeToLDIF( TQByteArray &ldif, const Addressee &addr,
+ const TQString &olddn )
+{
+ TQCString tmp;
+ TQString dn;
+ TQByteArray data;
+ bool mod = false;
+
+ if ( olddn.isEmpty() ) {
+ //insert new entry
+ switch ( d->mRDNPrefix ) {
+ case 1:
+ dn = mAttributes[ "uid" ] + "=" + addr.uid() + "," +mDn;
+ break;
+ case 0:
+ default:
+ dn = mAttributes[ "commonName" ] + "=" + addr.assembledName() + "," +mDn;
+ break;
+ }
+ } else {
+ //modify existing entry
+ mod = true;
+ if ( olddn.startsWith( mAttributes[ "uid" ] ) ) {
+ dn = mAttributes[ "uid" ] + "=" + addr.uid() + "," + olddn.section( ',', 1 );
+ } else if ( olddn.startsWith( mAttributes[ "commonName" ] ) ) {
+ dn = mAttributes[ "commonName" ] + "=" + addr.assembledName() + "," +
+ olddn.section( ',', 1 );
+ } else {
+ dn = olddn;
+ }
+
+ if ( olddn.lower() != dn.lower() ) {
+ tmp = LDIF::assembleLine( "dn", olddn ) + "\n";
+ tmp += "changetype: modrdn\n";
+ tmp += LDIF::assembleLine( "newrdn", dn.section( ',', 0, 0 ) ) + "\n";
+ tmp += "deleteoldrdn: 1\n\n";
+ }
+ }
+
+
+ tmp += LDIF::assembleLine( "dn", dn ) + "\n";
+ if ( mod ) tmp += "changetype: modify\n";
+ if ( !mod ) {
+ tmp += "objectClass: top\n";
+ TQStringList obclass = TQStringList::split( ',', mAttributes[ "objectClass" ] );
+ for ( TQStringList::iterator it = obclass.begin(); it != obclass.end(); it++ ) {
+ tmp += LDIF::assembleLine( "objectClass", *it ) + "\n";
+ }
+ }
+
+ tmp += addEntry( mAttributes[ "commonName" ], addr.assembledName(), mod );
+ tmp += addEntry( mAttributes[ "formattedName" ], addr.formattedName(), mod );
+ tmp += addEntry( mAttributes[ "givenName" ], addr.givenName(), mod );
+ tmp += addEntry( mAttributes[ "familyName" ], addr.familyName(), mod );
+ tmp += addEntry( mAttributes[ "uid" ], addr.uid(), mod );
+
+ PhoneNumber number;
+ number = addr.phoneNumber( PhoneNumber::Home );
+ tmp += addEntry( mAttributes[ "phoneNumber" ], number.number().utf8(), mod );
+ number = addr.phoneNumber( PhoneNumber::Work );
+ tmp += addEntry( mAttributes[ "telephoneNumber" ], number.number().utf8(), mod );
+ number = addr.phoneNumber( PhoneNumber::Fax );
+ tmp += addEntry( mAttributes[ "facsimileTelephoneNumber" ], number.number().utf8(), mod );
+ number = addr.phoneNumber( PhoneNumber::Cell );
+ tmp += addEntry( mAttributes[ "mobile" ], number.number().utf8(), mod );
+ number = addr.phoneNumber( PhoneNumber::Pager );
+ tmp += addEntry( mAttributes[ "pager" ], number.number().utf8(), mod );
+
+ tmp += addEntry( mAttributes[ "description" ], addr.note(), mod );
+ tmp += addEntry( mAttributes[ "title" ], addr.title(), mod );
+ tmp += addEntry( mAttributes[ "organization" ], addr.organization(), mod );
+
+ Address ad = addr.address( Address::Home );
+ if ( !ad.isEmpty() ) {
+ tmp += addEntry( mAttributes[ "street" ], ad.street(), mod );
+ tmp += addEntry( mAttributes[ "state" ], ad.region(), mod );
+ tmp += addEntry( mAttributes[ "city" ], ad.locality(), mod );
+ tmp += addEntry( mAttributes[ "postalcode" ], ad.postalCode(), mod );
+ }
+
+ TQStringList emails = addr.emails();
+ TQStringList::ConstIterator mailIt = emails.begin();
+
+ if ( !mAttributes[ "mail" ].isEmpty() ) {
+ if ( mod ) tmp +=
+ LDIF::assembleLine( "replace", mAttributes[ "mail" ] ) + "\n";
+ if ( mailIt != emails.end() ) {
+ tmp += LDIF::assembleLine( mAttributes[ "mail" ], *mailIt ) + "\n";
+ mailIt ++;
+ }
+ if ( mod && mAttributes[ "mail" ] != mAttributes[ "mailAlias" ] ) tmp += "-\n";
+ }
+
+ if ( !mAttributes[ "mailAlias" ].isEmpty() ) {
+ if ( mod && mAttributes[ "mail" ] != mAttributes[ "mailAlias" ] ) tmp +=
+ LDIF::assembleLine( "replace", mAttributes[ "mailAlias" ] ) + "\n";
+ for ( ; mailIt != emails.end(); ++mailIt ) {
+ tmp += LDIF::assembleLine( mAttributes[ "mailAlias" ], *mailIt ) + "\n" ;
+ }
+ if ( mod ) tmp += "-\n";
+ }
+
+ if ( !mAttributes[ "jpegPhoto" ].isEmpty() ) {
+ TQByteArray pic;
+ TQBuffer buffer( pic );
+ buffer.open( IO_WriteOnly );
+ addr.photo().data().save( &buffer, "JPEG" );
+
+ if ( mod ) tmp +=
+ LDIF::assembleLine( "replace", mAttributes[ "jpegPhoto" ] ) + "\n";
+ tmp += LDIF::assembleLine( mAttributes[ "jpegPhoto" ], pic, 76 ) + "\n";
+ if ( mod ) tmp += "-\n";
+ }
+
+ tmp += "\n";
+ kdDebug(7125) << "ldif: " << TQString(TQString::fromUtf8(tmp)) << endl;
+ ldif = tmp;
+ return true;
+}
+
+void ResourceLDAPTDEIO::setReadOnly( bool value )
+{
+ //save the original readonly flag, because offline using disables writing
+ d->mReadOnly = true;
+ Resource::setReadOnly( value );
+}
+
+void ResourceLDAPTDEIO::init()
+{
+ if ( mPort == 0 ) mPort = 389;
+
+ /**
+ If you want to add new attributes, append them here, add a
+ translation string in the ctor of AttributesDialog and
+ handle them in the load() method below.
+ These are the default values
+ */
+ if ( !mAttributes.contains("objectClass") )
+ mAttributes.insert( "objectClass", "inetOrgPerson" );
+ if ( !mAttributes.contains("commonName") )
+ mAttributes.insert( "commonName", "cn" );
+ if ( !mAttributes.contains("formattedName") )
+ mAttributes.insert( "formattedName", "displayName" );
+ if ( !mAttributes.contains("familyName") )
+ mAttributes.insert( "familyName", "sn" );
+ if ( !mAttributes.contains("givenName") )
+ mAttributes.insert( "givenName", "givenName" );
+ if ( !mAttributes.contains("mail") )
+ mAttributes.insert( "mail", "mail" );
+ if ( !mAttributes.contains("mailAlias") )
+ mAttributes.insert( "mailAlias", "" );
+ if ( !mAttributes.contains("phoneNumber") )
+ mAttributes.insert( "phoneNumber", "homePhone" );
+ if ( !mAttributes.contains("telephoneNumber") )
+ mAttributes.insert( "telephoneNumber", "telephoneNumber" );
+ if ( !mAttributes.contains("facsimileTelephoneNumber") )
+ mAttributes.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" );
+ if ( !mAttributes.contains("mobile") )
+ mAttributes.insert( "mobile", "mobile" );
+ if ( !mAttributes.contains("pager") )
+ mAttributes.insert( "pager", "pager" );
+ if ( !mAttributes.contains("description") )
+ mAttributes.insert( "description", "description" );
+
+ if ( !mAttributes.contains("title") )
+ mAttributes.insert( "title", "title" );
+ if ( !mAttributes.contains("street") )
+ mAttributes.insert( "street", "street" );
+ if ( !mAttributes.contains("state") )
+ mAttributes.insert( "state", "st" );
+ if ( !mAttributes.contains("city") )
+ mAttributes.insert( "city", "l" );
+ if ( !mAttributes.contains("organization") )
+ mAttributes.insert( "organization", "o" );
+ if ( !mAttributes.contains("postalcode") )
+ mAttributes.insert( "postalcode", "postalCode" );
+
+ if ( !mAttributes.contains("uid") )
+ mAttributes.insert( "uid", "uid" );
+ if ( !mAttributes.contains("jpegPhoto") )
+ mAttributes.insert( "jpegPhoto", "jpegPhoto" );
+
+ d->mLDAPUrl = KURL();
+ if ( !mAnonymous ) {
+ d->mLDAPUrl.setUser( mUser );
+ d->mLDAPUrl.setPass( mPassword );
+ }
+ d->mLDAPUrl.setProtocol( d->mSSL ? "ldaps" : "ldap");
+ d->mLDAPUrl.setHost( mHost );
+ d->mLDAPUrl.setPort( mPort );
+ d->mLDAPUrl.setDn( mDn );
+
+ if (!mAttributes.empty()) {
+ TQMap<TQString,TQString>::Iterator it;
+ TQStringList attr;
+ for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
+ if ( !it.data().isEmpty() && it.key() != "objectClass" )
+ attr.append( it.data() );
+ }
+ d->mLDAPUrl.setAttributes( attr );
+ }
+
+ d->mLDAPUrl.setScope( d->mSubTree ? LDAPUrl::Sub : LDAPUrl::One );
+ if ( !mFilter.isEmpty() && mFilter != "(objectClass=*)" )
+ d->mLDAPUrl.setFilter( mFilter );
+ d->mLDAPUrl.setExtension( "x-dir", "base" );
+ if ( d->mTLS ) d->mLDAPUrl.setExtension( "x-tls", "" );
+ d->mLDAPUrl.setExtension( "x-ver", TQString::number( d->mVer ) );
+ if ( d->mSizeLimit )
+ d->mLDAPUrl.setExtension( "x-sizelimit", TQString::number( d->mSizeLimit ) );
+ if ( d->mTimeLimit )
+ d->mLDAPUrl.setExtension( "x-timelimit", TQString::number( d->mTimeLimit ) );
+ if ( d->mSASL ) {
+ d->mLDAPUrl.setExtension( "x-sasl", "" );
+ if ( !d->mBindDN.isEmpty() ) d->mLDAPUrl.setExtension( "bindname", d->mBindDN );
+ if ( !d->mMech.isEmpty() ) d->mLDAPUrl.setExtension( "x-mech", d->mMech );
+ if ( !d->mRealm.isEmpty() ) d->mLDAPUrl.setExtension( "x-realm", d->mRealm );
+ }
+
+ d->mReadOnly = readOnly();
+
+ kdDebug(7125) << "resource_ldaptdeio url: " << d->mLDAPUrl.prettyURL() << endl;
+}
+
+void ResourceLDAPTDEIO::writeConfig( TDEConfig *config )
+{
+ Resource::writeConfig( config );
+
+ config->writeEntry( "LdapUser", mUser );
+ config->writeEntry( "LdapPassword", KStringHandler::obscure( mPassword ) );
+ config->writeEntry( "LdapDn", mDn );
+ config->writeEntry( "LdapHost", mHost );
+ config->writeEntry( "LdapPort", mPort );
+ config->writeEntry( "LdapFilter", mFilter );
+ config->writeEntry( "LdapAnonymous", mAnonymous );
+ config->writeEntry( "LdapTLS", d->mTLS );
+ config->writeEntry( "LdapSSL", d->mSSL );
+ config->writeEntry( "LdapSubTree", d->mSubTree );
+ config->writeEntry( "LdapSASL", d->mSASL );
+ config->writeEntry( "LdapMech", d->mMech );
+ config->writeEntry( "LdapVer", d->mVer );
+ config->writeEntry( "LdapTimeLimit", d->mTimeLimit );
+ config->writeEntry( "LdapSizeLimit", d->mSizeLimit );
+ config->writeEntry( "LdapRDNPrefix", d->mRDNPrefix );
+ config->writeEntry( "LdapRealm", d->mRealm );
+ config->writeEntry( "LdapBindDN", d->mBindDN );
+ config->writeEntry( "LdapCachePolicy", d->mCachePolicy );
+ config->writeEntry( "LdapAutoCache", d->mAutoCache );
+
+ TQStringList attributes;
+ TQMap<TQString, TQString>::Iterator it;
+ for ( it = mAttributes.begin(); it != mAttributes.end(); ++it )
+ attributes << it.key() << it.data();
+
+ config->writeEntry( "LdapAttributes", attributes );
+}
+
+Ticket *ResourceLDAPTDEIO::requestSaveTicket()
+{
+ if ( !addressBook() ) {
+ kdDebug(7125) << "no addressbook" << endl;
+ return 0;
+ }
+
+ return createTicket( this );
+}
+
+void ResourceLDAPTDEIO::releaseSaveTicket( Ticket *ticket )
+{
+ delete ticket;
+}
+
+bool ResourceLDAPTDEIO::doOpen()
+{
+ return true;
+}
+
+void ResourceLDAPTDEIO::doClose()
+{
+}
+
+void ResourceLDAPTDEIO::createCache()
+{
+ d->mTmp = NULL;
+ if ( d->mCachePolicy == Cache_NoConnection && d->mAutoCache ) {
+ d->mTmp = new KTempFile( d->mCacheDst, "tmp" );
+ d->mTmp->setAutoDelete( true );
+ }
+}
+
+void ResourceLDAPTDEIO::activateCache()
+{
+ if ( d->mTmp && d->mError == 0 ) {
+ d->mTmp->close();
+ rename( TQFile::encodeName( d->mTmp->name() ), TQFile::encodeName( d->mCacheDst ) );
+ }
+ if ( d->mTmp ) {
+ delete d->mTmp;
+ d->mTmp = 0;
+ }
+}
+
+TDEIO::Job *ResourceLDAPTDEIO::loadFromCache()
+{
+ TDEIO::Job *job = NULL;
+ if ( d->mCachePolicy == Cache_Always ||
+ ( d->mCachePolicy == Cache_NoConnection &&
+ d->mError == TDEIO::ERR_COULD_NOT_CONNECT ) ) {
+
+ d->mAddr = Addressee();
+ d->mAd = Address( Address::Home );
+ //initialize ldif parser
+ d->mLdif.startParsing();
+
+ Resource::setReadOnly( true );
+
+ KURL url( d->mCacheDst );
+ job = TDEIO::get( url, true, false );
+ connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ),
+ this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) );
+ }
+ return job;
+}
+
+bool ResourceLDAPTDEIO::load()
+{
+ kdDebug(7125) << "ResourceLDAPTDEIO::load()" << endl;
+ TDEIO::Job *job;
+
+ clear();
+ //clear the addressee
+ d->mAddr = Addressee();
+ d->mAd = Address( Address::Home );
+ //initialize ldif parser
+ d->mLdif.startParsing();
+
+ //set to original settings, offline use will disable writing
+ Resource::setReadOnly( d->mReadOnly );
+
+ createCache();
+ if ( d->mCachePolicy != Cache_Always ) {
+ job = TDEIO::get( d->mLDAPUrl, true, false );
+ connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ),
+ this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) );
+ connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) );
+ enter_loop();
+ }
+
+ job = loadFromCache();
+ if ( job ) {
+ connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) );
+ enter_loop();
+ }
+ if ( mErrorMsg.isEmpty() ) {
+ kdDebug(7125) << "ResourceLDAPTDEIO load ok!" << endl;
+ return true;
+ } else {
+ kdDebug(7125) << "ResourceLDAPTDEIO load finished with error: " << mErrorMsg << endl;
+ addressBook()->error( mErrorMsg );
+ return false;
+ }
+}
+
+bool ResourceLDAPTDEIO::asyncLoad()
+{
+ clear();
+ //clear the addressee
+ d->mAddr = Addressee();
+ d->mAd = Address( Address::Home );
+ //initialize ldif parser
+ d->mLdif.startParsing();
+
+ Resource::setReadOnly( d->mReadOnly );
+
+ createCache();
+ if ( d->mCachePolicy != Cache_Always ) {
+ TDEIO::Job *job = TDEIO::get( d->mLDAPUrl, true, false );
+ connect( job, TQT_SIGNAL( data( TDEIO::Job*, const TQByteArray& ) ),
+ this, TQT_SLOT( data( TDEIO::Job*, const TQByteArray& ) ) );
+ connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( result( TDEIO::Job* ) ) );
+ } else {
+ result( NULL );
+ }
+ return true;
+}
+
+void ResourceLDAPTDEIO::data( TDEIO::Job *, const TQByteArray &data )
+{
+ if ( data.size() ) {
+ d->mLdif.setLDIF( data );
+ if ( d->mTmp ) {
+ d->mTmp->file()->writeBlock( data );
+ }
+ } else {
+ d->mLdif.endLDIF();
+ }
+
+ LDIF::ParseVal ret;
+ TQString name;
+ TQByteArray value;
+ do {
+ ret = d->mLdif.nextItem();
+ switch ( ret ) {
+ case LDIF::NewEntry:
+ kdDebug(7125) << "new entry: " << d->mLdif.dn() << endl;
+ break;
+ case LDIF::Item:
+ name = d->mLdif.attr().lower();
+ value = d->mLdif.val();
+ if ( name == mAttributes[ "commonName" ].lower() ) {
+ if ( !d->mAddr.formattedName().isEmpty() ) {
+ TQString fn = d->mAddr.formattedName();
+ d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) );
+ d->mAddr.setFormattedName( fn );
+ } else
+ d->mAddr.setNameFromString( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "formattedName" ].lower() ) {
+ d->mAddr.setFormattedName( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "givenName" ].lower() ) {
+ d->mAddr.setGivenName( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "mail" ].lower() ) {
+ d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ), true );
+ } else if ( name == mAttributes[ "mailAlias" ].lower() ) {
+ d->mAddr.insertEmail( TQString::fromUtf8( value, value.size() ), false );
+ } else if ( name == mAttributes[ "phoneNumber" ].lower() ) {
+ PhoneNumber phone;
+ phone.setNumber( TQString::fromUtf8( value, value.size() ) );
+ d->mAddr.insertPhoneNumber( phone );
+ } else if ( name == mAttributes[ "telephoneNumber" ].lower() ) {
+ PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
+ PhoneNumber::Work );
+ d->mAddr.insertPhoneNumber( phone );
+ } else if ( name == mAttributes[ "facsimileTelephoneNumber" ].lower() ) {
+ PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
+ PhoneNumber::Fax );
+ d->mAddr.insertPhoneNumber( phone );
+ } else if ( name == mAttributes[ "mobile" ].lower() ) {
+ PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
+ PhoneNumber::Cell );
+ d->mAddr.insertPhoneNumber( phone );
+ } else if ( name == mAttributes[ "pager" ].lower() ) {
+ PhoneNumber phone( TQString::fromUtf8( value, value.size() ),
+ PhoneNumber::Pager );
+ d->mAddr.insertPhoneNumber( phone );
+ } else if ( name == mAttributes[ "description" ].lower() ) {
+ d->mAddr.setNote( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "title" ].lower() ) {
+ d->mAddr.setTitle( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "street" ].lower() ) {
+ d->mAd.setStreet( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "state" ].lower() ) {
+ d->mAd.setRegion( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "city" ].lower() ) {
+ d->mAd.setLocality( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "postalcode" ].lower() ) {
+ d->mAd.setPostalCode( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "organization" ].lower() ) {
+ d->mAddr.setOrganization( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "familyName" ].lower() ) {
+ d->mAddr.setFamilyName( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "uid" ].lower() ) {
+ d->mAddr.setUid( TQString::fromUtf8( value, value.size() ) );
+ } else if ( name == mAttributes[ "jpegPhoto" ].lower() ) {
+ KABC::Picture photo;
+ TQImage img( value );
+ if ( !img.isNull() ) {
+ photo.setData( img );
+ photo.setType( "image/jpeg" );
+ d->mAddr.setPhoto( photo );
+ }
+ }
+
+ break;
+ case LDIF::EndEntry: {
+ d->mAddr.setResource( this );
+ d->mAddr.insertAddress( d->mAd );
+ d->mAddr.setChanged( false );
+ insertAddressee( d->mAddr );
+ //clear the addressee
+ d->mAddr = Addressee();
+ d->mAd = Address( Address::Home );
+ }
+ break;
+ default:
+ break;
+ }
+ } while ( ret != LDIF::MoreData );
+}
+
+void ResourceLDAPTDEIO::loadCacheResult( TDEIO::Job *job )
+{
+ mErrorMsg = "";
+ d->mError = job->error();
+ if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) {
+ mErrorMsg = job->errorString();
+ }
+ if ( !mErrorMsg.isEmpty() )
+ emit loadingError( this, mErrorMsg );
+ else
+ emit loadingFinished( this );
+}
+
+void ResourceLDAPTDEIO::result( TDEIO::Job *job )
+{
+ mErrorMsg = "";
+ if ( job ) {
+ d->mError = job->error();
+ if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED ) {
+ mErrorMsg = job->errorString();
+ }
+ } else {
+ d->mError = 0;
+ }
+ activateCache();
+
+ TDEIO::Job *cjob;
+ cjob = loadFromCache();
+ if ( cjob ) {
+ connect( cjob, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( loadCacheResult( TDEIO::Job* ) ) );
+ } else {
+ if ( !mErrorMsg.isEmpty() )
+ emit loadingError( this, mErrorMsg );
+ else
+ emit loadingFinished( this );
+ }
+}
+
+bool ResourceLDAPTDEIO::save( Ticket* )
+{
+ kdDebug(7125) << "ResourceLDAPTDEIO save" << endl;
+
+ d->mSaveIt = begin();
+ TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1, true, false, false );
+ connect( job, TQT_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ),
+ this, TQT_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) );
+ connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( syncLoadSaveResult( TDEIO::Job* ) ) );
+ enter_loop();
+ if ( mErrorMsg.isEmpty() ) {
+ kdDebug(7125) << "ResourceLDAPTDEIO save ok!" << endl;
+ return true;
+ } else {
+ kdDebug(7125) << "ResourceLDAPTDEIO finished with error: " << mErrorMsg << endl;
+ addressBook()->error( mErrorMsg );
+ return false;
+ }
+}
+
+bool ResourceLDAPTDEIO::asyncSave( Ticket* )
+{
+ kdDebug(7125) << "ResourceLDAPTDEIO asyncSave" << endl;
+ d->mSaveIt = begin();
+ TDEIO::Job *job = TDEIO::put( d->mLDAPUrl, -1, true, false, false );
+ connect( job, TQT_SIGNAL( dataReq( TDEIO::Job*, TQByteArray& ) ),
+ this, TQT_SLOT( saveData( TDEIO::Job*, TQByteArray& ) ) );
+ connect( job, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( saveResult( TDEIO::Job* ) ) );
+ return true;
+}
+
+void ResourceLDAPTDEIO::syncLoadSaveResult( TDEIO::Job *job )
+{
+ d->mError = job->error();
+ if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED )
+ mErrorMsg = job->errorString();
+ else
+ mErrorMsg = "";
+ activateCache();
+
+ tqApp->exit_loop();
+}
+
+void ResourceLDAPTDEIO::saveResult( TDEIO::Job *job )
+{
+ d->mError = job->error();
+ if ( d->mError && d->mError != TDEIO::ERR_USER_CANCELED )
+ emit savingError( this, job->errorString() );
+ else
+ emit savingFinished( this );
+}
+
+void ResourceLDAPTDEIO::saveData( TDEIO::Job*, TQByteArray& data )
+{
+ while ( d->mSaveIt != end() &&
+ !(*d->mSaveIt).changed() ) d->mSaveIt++;
+
+ if ( d->mSaveIt == end() ) {
+ kdDebug(7125) << "ResourceLDAPTDEIO endData" << endl;
+ data.resize(0);
+ return;
+ }
+
+ kdDebug(7125) << "ResourceLDAPTDEIO saveData: " << (*d->mSaveIt).assembledName() << endl;
+
+ AddresseeToLDIF( data, *d->mSaveIt, findUid( (*d->mSaveIt).uid() ) );
+// kdDebug(7125) << "ResourceLDAPTDEIO save LDIF: " << TQString::fromUtf8(data) << endl;
+ // mark as unchanged
+ (*d->mSaveIt).setChanged( false );
+
+ d->mSaveIt++;
+}
+
+void ResourceLDAPTDEIO::removeAddressee( const Addressee& addr )
+{
+ TQString dn = findUid( addr.uid() );
+
+ kdDebug(7125) << "ResourceLDAPTDEIO: removeAddressee: " << dn << endl;
+
+ if ( !mErrorMsg.isEmpty() ) {
+ addressBook()->error( mErrorMsg );
+ return;
+ }
+ if ( !dn.isEmpty() ) {
+ kdDebug(7125) << "ResourceLDAPTDEIO: found uid: " << dn << endl;
+ LDAPUrl url( d->mLDAPUrl );
+ url.setPath( "/" + dn );
+ url.setExtension( "x-dir", "base" );
+ url.setScope( LDAPUrl::Base );
+ if ( TDEIO::NetAccess::del( url, NULL ) ) mAddrMap.erase( addr.uid() );
+ } else {
+ //maybe it's not saved yet
+ mAddrMap.erase( addr.uid() );
+ }
+}
+
+
+void ResourceLDAPTDEIO::setUser( const TQString &user )
+{
+ mUser = user;
+}
+
+TQString ResourceLDAPTDEIO::user() const
+{
+ return mUser;
+}
+
+void ResourceLDAPTDEIO::setPassword( const TQString &password )
+{
+ mPassword = password;
+}
+
+TQString ResourceLDAPTDEIO::password() const
+{
+ return mPassword;
+}
+
+void ResourceLDAPTDEIO::setDn( const TQString &dn )
+{
+ mDn = dn;
+}
+
+TQString ResourceLDAPTDEIO::dn() const
+{
+ return mDn;
+}
+
+void ResourceLDAPTDEIO::setHost( const TQString &host )
+{
+ mHost = host;
+}
+
+TQString ResourceLDAPTDEIO::host() const
+{
+ return mHost;
+}
+
+void ResourceLDAPTDEIO::setPort( int port )
+{
+ mPort = port;
+}
+
+int ResourceLDAPTDEIO::port() const
+{
+ return mPort;
+}
+
+void ResourceLDAPTDEIO::setVer( int ver )
+{
+ d->mVer = ver;
+}
+
+int ResourceLDAPTDEIO::ver() const
+{
+ return d->mVer;
+}
+
+void ResourceLDAPTDEIO::setSizeLimit( int sizelimit )
+{
+ d->mSizeLimit = sizelimit;
+}
+
+int ResourceLDAPTDEIO::sizeLimit()
+{
+ return d->mSizeLimit;
+}
+
+void ResourceLDAPTDEIO::setTimeLimit( int timelimit )
+{
+ d->mTimeLimit = timelimit;
+}
+
+int ResourceLDAPTDEIO::timeLimit()
+{
+ return d->mTimeLimit;
+}
+
+void ResourceLDAPTDEIO::setFilter( const TQString &filter )
+{
+ mFilter = filter;
+}
+
+TQString ResourceLDAPTDEIO::filter() const
+{
+ return mFilter;
+}
+
+void ResourceLDAPTDEIO::setIsAnonymous( bool value )
+{
+ mAnonymous = value;
+}
+
+bool ResourceLDAPTDEIO::isAnonymous() const
+{
+ return mAnonymous;
+}
+
+void ResourceLDAPTDEIO::setIsTLS( bool value )
+{
+ d->mTLS = value;
+}
+
+bool ResourceLDAPTDEIO::isTLS() const
+{
+ return d->mTLS;
+}
+void ResourceLDAPTDEIO::setIsSSL( bool value )
+{
+ d->mSSL = value;
+}
+
+bool ResourceLDAPTDEIO::isSSL() const
+{
+ return d->mSSL;
+}
+
+void ResourceLDAPTDEIO::setIsSubTree( bool value )
+{
+ d->mSubTree = value;
+}
+
+bool ResourceLDAPTDEIO::isSubTree() const
+{
+ return d->mSubTree;
+}
+
+void ResourceLDAPTDEIO::setAttributes( const TQMap<TQString, TQString> &attributes )
+{
+ mAttributes = attributes;
+}
+
+TQMap<TQString, TQString> ResourceLDAPTDEIO::attributes() const
+{
+ return mAttributes;
+}
+
+void ResourceLDAPTDEIO::setRDNPrefix( int value )
+{
+ d->mRDNPrefix = value;
+}
+
+int ResourceLDAPTDEIO::RDNPrefix() const
+{
+ return d->mRDNPrefix;
+}
+
+void ResourceLDAPTDEIO::setIsSASL( bool value )
+{
+ d->mSASL = value;
+}
+
+bool ResourceLDAPTDEIO::isSASL() const
+{
+ return d->mSASL;
+}
+
+void ResourceLDAPTDEIO::setMech( const TQString &mech )
+{
+ d->mMech = mech;
+}
+
+TQString ResourceLDAPTDEIO::mech() const
+{
+ return d->mMech;
+}
+
+void ResourceLDAPTDEIO::setRealm( const TQString &realm )
+{
+ d->mRealm = realm;
+}
+
+TQString ResourceLDAPTDEIO::realm() const
+{
+ return d->mRealm;
+}
+
+void ResourceLDAPTDEIO::setBindDN( const TQString &binddn )
+{
+ d->mBindDN = binddn;
+}
+
+TQString ResourceLDAPTDEIO::bindDN() const
+{
+ return d->mBindDN;
+}
+
+void ResourceLDAPTDEIO::setCachePolicy( int pol )
+{
+ d->mCachePolicy = pol;
+}
+
+int ResourceLDAPTDEIO::cachePolicy() const
+{
+ return d->mCachePolicy;
+}
+
+void ResourceLDAPTDEIO::setAutoCache( bool value )
+{
+ d->mAutoCache = value;
+}
+
+bool ResourceLDAPTDEIO::autoCache()
+{
+ return d->mAutoCache;
+}
+
+TQString ResourceLDAPTDEIO::cacheDst() const
+{
+ return d->mCacheDst;
+}
+
+
+#include "resourceldaptdeio.moc"
diff --git a/tdeabc/plugins/ldaptdeio/resourceldaptdeio.h b/tdeabc/plugins/ldaptdeio/resourceldaptdeio.h
new file mode 100644
index 000000000..bf1b70ec0
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/resourceldaptdeio.h
@@ -0,0 +1,171 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+ Copyright (c) 2004 Szombathelyi György <gyurco@freemail.hu>
+
+ 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_RESOURCELDAP_H
+#define KABC_RESOURCELDAP_H
+
+#include <tdeabc/resource.h>
+#include <tdeabc/ldif.h>
+#include <tdeio/job.h>
+
+class TDEConfig;
+
+namespace KABC {
+
+class KABC_EXPORT ResourceLDAPTDEIO : public Resource
+{
+ Q_OBJECT
+
+ public:
+ enum CachePolicy{ Cache_No, Cache_NoConnection, Cache_Always };
+
+ ResourceLDAPTDEIO( const TDEConfig* );
+ virtual ~ResourceLDAPTDEIO();
+ /**
+ * Call this after you used one of the set... methods
+ */
+ virtual void init();
+
+ virtual void writeConfig( TDEConfig* );
+
+ virtual bool doOpen();
+ virtual void doClose();
+
+ virtual Ticket *requestSaveTicket();
+ virtual void releaseSaveTicket( Ticket* );
+
+ virtual bool readOnly() const { return Resource::readOnly(); }
+ virtual void setReadOnly( bool value );
+
+ virtual bool load();
+ virtual bool asyncLoad();
+ virtual bool save( Ticket * ticket );
+ virtual bool asyncSave( Ticket * ticket );
+
+ virtual void removeAddressee( const Addressee& addr );
+
+ void setUser( const TQString &user );
+ TQString user() const;
+
+ void setPassword( const TQString &password );
+ TQString password() const;
+
+ void setRealm( const TQString &realm );
+ TQString realm() const;
+
+ void setBindDN( const TQString &binddn );
+ TQString bindDN() const;
+
+ void setDn( const TQString &dn );
+ TQString dn() const;
+
+ void setHost( const TQString &host );
+ TQString host() const;
+
+ void setPort( int port );
+ int port() const;
+
+ void setVer( int ver );
+ int ver() const;
+
+ void setSizeLimit( int sizelimit );
+ int sizeLimit();
+
+ void setTimeLimit( int timelimit );
+ int timeLimit();
+
+ void setFilter( const TQString &filter );
+ TQString filter() const;
+
+ void setIsAnonymous( bool value );
+ bool isAnonymous() const;
+
+ void setAttributes( const TQMap<TQString, TQString> &attributes );
+ TQMap<TQString, TQString> attributes() const;
+
+ void setRDNPrefix( int value );
+ int RDNPrefix() const;
+
+ void setIsTLS( bool value );
+ bool isTLS() const ;
+
+ void setIsSSL( bool value );
+ bool isSSL() const;
+
+ void setIsSubTree( bool value );
+ bool isSubTree() const ;
+
+ void setIsSASL( bool value );
+ bool isSASL() const ;
+
+ void setMech( const TQString &mech );
+ TQString mech() const;
+
+ void setCachePolicy( int pol );
+ int cachePolicy() const;
+
+ void setAutoCache( bool value );
+ bool autoCache();
+
+ TQString cacheDst() const;
+
+protected slots:
+ void entries( TDEIO::Job*, const TDEIO::UDSEntryList& );
+ void data( TDEIO::Job*, const TQByteArray& );
+ void result( TDEIO::Job* );
+ void listResult( TDEIO::Job* );
+ void syncLoadSaveResult( TDEIO::Job* );
+ void saveResult( TDEIO::Job* );
+ void saveData( TDEIO::Job*, TQByteArray& );
+ void loadCacheResult( TDEIO::Job* );
+
+ private:
+ TQString mUser;
+ TQString mPassword;
+ TQString mDn;
+ TQString mHost;
+ TQString mFilter;
+ int mPort;
+ bool mAnonymous;
+ TQMap<TQString, TQString> mAttributes;
+
+ KURL mLDAPUrl;
+ int mGetCounter; //KDE 4: remove
+ bool mErrorOccured; //KDE 4: remove
+ TQString mErrorMsg;
+ TQMap<TDEIO::Job*, TQByteArray> mJobMap; //KDE 4: remove
+
+ TDEIO::Job *loadFromCache();
+ void createCache();
+ void activateCache();
+ void enter_loop();
+ TQCString addEntry( const TQString &attr, const TQString &value, bool mod );
+ TQString findUid( const TQString &uid );
+ bool AddresseeToLDIF( TQByteArray &ldif, const Addressee &addr,
+ const TQString &olddn );
+
+ class ResourceLDAPTDEIOPrivate;
+ ResourceLDAPTDEIOPrivate *d;
+};
+
+}
+
+#endif
diff --git a/tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp b/tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp
new file mode 100644
index 000000000..a6af7d065
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.cpp
@@ -0,0 +1,388 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 - 2003 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 <tqapplication.h>
+
+#include <tqcheckbox.h>
+#include <tqlabel.h>
+#include <tqlayout.h>
+#include <tqpushbutton.h>
+#include <tqspinbox.h>
+#include <tqvbox.h>
+#include <tqvgroupbox.h>
+#include <tqhbuttongroup.h>
+#include <tqradiobutton.h>
+
+#include <tdeaccelmanager.h>
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <kdialogbase.h>
+#include <tdelocale.h>
+#include <klineedit.h>
+#include <tdemessagebox.h>
+#include <tdeio/netaccess.h>
+
+#include "resourceldaptdeio.h"
+
+#include "resourceldaptdeioconfig.h"
+#include "resourceldaptdeioconfig.moc"
+
+using namespace KABC;
+
+ResourceLDAPTDEIOConfig::ResourceLDAPTDEIOConfig( TQWidget* parent, const char* name )
+ : KRES::ConfigWidget( parent, name )
+{
+ TQBoxLayout *mainLayout = new TQVBoxLayout( this );
+ mainLayout->setAutoAdd( true );
+ cfg = new LdapConfigWidget( LdapConfigWidget::W_ALL, this );
+
+ mSubTree = new TQCheckBox( i18n( "Sub-tree query" ), this );
+ TQHBox *box = new TQHBox( this );
+ box->setSpacing( KDialog::spacingHint() );
+ mEditButton = new TQPushButton( i18n( "Edit Attributes..." ), box );
+ mCacheButton = new TQPushButton( i18n( "Offline Use..." ), box );
+
+ connect( mEditButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editAttributes() ) );
+ connect( mCacheButton, TQT_SIGNAL( clicked() ), TQT_SLOT( editCache() ) );
+}
+
+void ResourceLDAPTDEIOConfig::loadSettings( KRES::Resource *res )
+{
+ ResourceLDAPTDEIO *resource = dynamic_cast<ResourceLDAPTDEIO*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceLDAPTDEIOConfig::loadSettings(): cast failed" << endl;
+ return;
+ }
+
+ cfg->setUser( resource->user() );
+ cfg->setPassword( resource->password() );
+ cfg->setRealm( resource->realm() );
+ cfg->setBindDN( resource->bindDN() );
+ cfg->setHost( resource->host() );
+ cfg->setPort( resource->port() );
+ cfg->setVer( resource->ver() );
+ cfg->setTimeLimit( resource->timeLimit() );
+ cfg->setSizeLimit( resource->sizeLimit() );
+ cfg->setDn( resource->dn() );
+ cfg->setFilter( resource->filter() );
+ cfg->setMech( resource->mech() );
+ if ( resource->isTLS() ) cfg->setSecTLS();
+ else if ( resource->isSSL() ) cfg->setSecSSL();
+ else cfg->setSecNO();
+ if ( resource->isAnonymous() ) cfg->setAuthAnon();
+ else if ( resource->isSASL() ) cfg->setAuthSASL();
+ else cfg->setAuthSimple();
+
+ mSubTree->setChecked( resource->isSubTree() );
+ mAttributes = resource->attributes();
+ mRDNPrefix = resource->RDNPrefix();
+ mCachePolicy = resource->cachePolicy();
+ mCacheDst = resource->cacheDst();
+ mAutoCache = resource->autoCache();
+}
+
+void ResourceLDAPTDEIOConfig::saveSettings( KRES::Resource *res )
+{
+ ResourceLDAPTDEIO *resource = dynamic_cast<ResourceLDAPTDEIO*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceLDAPTDEIOConfig::saveSettings(): cast failed" << endl;
+ return;
+ }
+
+ resource->setUser( cfg->user() );
+ resource->setPassword( cfg->password() );
+ resource->setRealm( cfg->realm() );
+ resource->setBindDN( cfg->bindDN() );
+ resource->setHost( cfg->host() );
+ resource->setPort( cfg->port() );
+ resource->setVer( cfg->ver() );
+ resource->setTimeLimit( cfg->timeLimit() );
+ resource->setSizeLimit( cfg->sizeLimit() );
+ resource->setDn( cfg->dn() );
+ resource->setFilter( cfg->filter() );
+ resource->setIsAnonymous( cfg->isAuthAnon() );
+ resource->setIsSASL( cfg->isAuthSASL() );
+ resource->setMech( cfg->mech() );
+ resource->setIsTLS( cfg->isSecTLS() );
+ resource->setIsSSL( cfg->isSecSSL() );
+ resource->setIsSubTree( mSubTree->isChecked() );
+ resource->setAttributes( mAttributes );
+ resource->setRDNPrefix( mRDNPrefix );
+ resource->setCachePolicy( mCachePolicy );
+ resource->init();
+
+}
+
+void ResourceLDAPTDEIOConfig::editAttributes()
+{
+ AttributesDialog dlg( mAttributes, mRDNPrefix, this );
+ if ( dlg.exec() ) {
+ mAttributes = dlg.attributes();
+ mRDNPrefix = dlg.rdnprefix();
+ }
+}
+
+void ResourceLDAPTDEIOConfig::editCache()
+{
+ LDAPUrl src;
+ TQStringList attr;
+
+ src = cfg->url();
+ src.setScope( mSubTree->isChecked() ? LDAPUrl::Sub : LDAPUrl::One );
+ if (!mAttributes.empty()) {
+ TQMap<TQString,TQString>::Iterator it;
+ TQStringList attr;
+ for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) {
+ if ( !it.data().isEmpty() && it.key() != "objectClass" )
+ attr.append( it.data() );
+ }
+ src.setAttributes( attr );
+ }
+ src.setExtension( "x-dir", "base" );
+ OfflineDialog dlg( mAutoCache, mCachePolicy, src, mCacheDst, this );
+ if ( dlg.exec() ) {
+ mCachePolicy = dlg.cachePolicy();
+ mAutoCache = dlg.autoCache();
+ }
+
+}
+
+AttributesDialog::AttributesDialog( const TQMap<TQString, TQString> &attributes,
+ int rdnprefix,
+ TQWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Attributes Configuration" ), Ok | Cancel,
+ Ok, parent, name, true, true )
+{
+ mNameDict.setAutoDelete( true );
+ mNameDict.insert( "objectClass", new TQString( i18n( "Object classes" ) ) );
+ mNameDict.insert( "commonName", new TQString( i18n( "Common name" ) ) );
+ mNameDict.insert( "formattedName", new TQString( i18n( "Formatted name" ) ) );
+ mNameDict.insert( "familyName", new TQString( i18n( "Family name" ) ) );
+ mNameDict.insert( "givenName", new TQString( i18n( "Given name" ) ) );
+ mNameDict.insert( "organization", new TQString( i18n( "Organization" ) ) );
+ mNameDict.insert( "title", new TQString( i18n( "Title" ) ) );
+ mNameDict.insert( "street", new TQString( i18n( "Street" ) ) );
+ mNameDict.insert( "state", new TQString( i18n( "State" ) ) );
+ mNameDict.insert( "city", new TQString( i18n( "City" ) ) );
+ mNameDict.insert( "postalcode", new TQString( i18n( "Postal code" ) ) );
+ mNameDict.insert( "mail", new TQString( i18n( "Email" ) ) );
+ mNameDict.insert( "mailAlias", new TQString( i18n( "Email alias" ) ) );
+ mNameDict.insert( "phoneNumber", new TQString( i18n( "Telephone number" ) ) );
+ mNameDict.insert( "telephoneNumber", new TQString( i18n( "Work telephone number" ) ) );
+ mNameDict.insert( "facsimileTelephoneNumber", new TQString( i18n( "Fax number" ) ) );
+ mNameDict.insert( "mobile", new TQString( i18n( "Cell phone number" ) ) );
+ mNameDict.insert( "pager", new TQString( i18n( "Pager" ) ) );
+ mNameDict.insert( "description", new TQString( i18n( "Note" ) ) );
+ mNameDict.insert( "uid", new TQString( i18n( "UID" ) ) );
+ mNameDict.insert( "jpegPhoto", new TQString( i18n( "Photo" ) ) );
+
+ // default map
+ mDefaultMap.insert( "objectClass", "inetOrgPerson" );
+ mDefaultMap.insert( "commonName", "cn" );
+ mDefaultMap.insert( "formattedName", "displayName" );
+ mDefaultMap.insert( "familyName", "sn" );
+ mDefaultMap.insert( "givenName", "givenName" );
+ mDefaultMap.insert( "title", "title" );
+ mDefaultMap.insert( "street", "street" );
+ mDefaultMap.insert( "state", "st" );
+ mDefaultMap.insert( "city", "l" );
+ mDefaultMap.insert( "organization", "o" );
+ mDefaultMap.insert( "postalcode", "postalCode" );
+ mDefaultMap.insert( "mail", "mail" );
+ mDefaultMap.insert( "mailAlias", "" );
+ mDefaultMap.insert( "phoneNumber", "homePhone" );
+ mDefaultMap.insert( "telephoneNumber", "telephoneNumber" );
+ mDefaultMap.insert( "facsimileTelephoneNumber", "facsimileTelephoneNumber" );
+ mDefaultMap.insert( "mobile", "mobile" );
+ mDefaultMap.insert( "pager", "pager" );
+ mDefaultMap.insert( "description", "description" );
+ mDefaultMap.insert( "uid", "uid" );
+ mDefaultMap.insert( "jpegPhoto", "jpegPhoto" );
+
+ // overwrite the default values here
+ TQMap<TQString, TQString> kolabMap, netscapeMap, evolutionMap, outlookMap;
+
+ // kolab
+ kolabMap.insert( "formattedName", "display-name" );
+ kolabMap.insert( "mailAlias", "mailalias" );
+
+ // evolution
+ evolutionMap.insert( "formattedName", "fileAs" );
+
+ mMapList.append( attributes );
+ mMapList.append( kolabMap );
+ mMapList.append( netscapeMap );
+ mMapList.append( evolutionMap );
+ mMapList.append( outlookMap );
+
+ TQFrame *page = plainPage();
+ TQGridLayout *layout = new TQGridLayout( page, 4, ( attributes.count() + 4 ) >> 1,
+ 0, spacingHint() );
+
+ TQLabel *label = new TQLabel( i18n( "Template:" ), page );
+ layout->addWidget( label, 0, 0 );
+ mMapCombo = new KComboBox( page );
+ layout->addWidget( mMapCombo, 0, 1 );
+
+ mMapCombo->insertItem( i18n( "User Defined" ) );
+ mMapCombo->insertItem( i18n( "Kolab" ) );
+ mMapCombo->insertItem( i18n( "Netscape" ) );
+ mMapCombo->insertItem( i18n( "Evolution" ) );
+ mMapCombo->insertItem( i18n( "Outlook" ) );
+ connect( mMapCombo, TQT_SIGNAL( activated( int ) ), TQT_SLOT( mapChanged( int ) ) );
+
+ label = new TQLabel( i18n( "RDN prefix attribute:" ), page );
+ layout->addWidget( label, 1, 0 );
+ mRDNCombo = new KComboBox( page );
+ layout->addWidget( mRDNCombo, 1, 1 );
+ mRDNCombo->insertItem( i18n( "commonName" ) );
+ mRDNCombo->insertItem( i18n( "UID" ) );
+ mRDNCombo->setCurrentItem( rdnprefix );
+
+ TQMap<TQString, TQString>::ConstIterator it;
+ int i, j = 0;
+ for ( i = 2, it = attributes.begin(); it != attributes.end(); ++it, ++i ) {
+ if ( mNameDict[ it.key() ] == 0 ) {
+ i--;
+ continue;
+ }
+ if ( (uint)(i - 2) == ( mNameDict.count() >> 1 ) ) {
+ i = 0;
+ j = 2;
+ }
+ kdDebug(7125) << "itkey: " << it.key() << " i: " << i << endl;
+ label = new TQLabel( *mNameDict[ it.key() ] + ":", page );
+ KLineEdit *lineedit = new KLineEdit( page );
+ mLineEditDict.insert( it.key(), lineedit );
+ lineedit->setText( it.data() );
+ label->setBuddy( lineedit );
+ layout->addWidget( label, i, j );
+ layout->addWidget( lineedit, i, j+1 );
+ }
+
+ for ( i = 1; i < mMapCombo->count(); i++ ) {
+ TQDictIterator<KLineEdit> it2( mLineEditDict );
+ for ( ; it2.current(); ++it2 ) {
+ if ( mMapList[ i ].contains( it2.currentKey() ) ) {
+ if ( mMapList[ i ][ it2.currentKey() ] != it2.current()->text() ) break;
+ } else {
+ if ( mDefaultMap[ it2.currentKey() ] != it2.current()->text() ) break;
+ }
+ }
+ if ( !it2.current() ) {
+ mMapCombo->setCurrentItem( i );
+ break;
+ }
+ }
+
+ TDEAcceleratorManager::manage( this );
+}
+
+AttributesDialog::~AttributesDialog()
+{
+}
+
+TQMap<TQString, TQString> AttributesDialog::attributes() const
+{
+ TQMap<TQString, TQString> map;
+
+ TQDictIterator<KLineEdit> it( mLineEditDict );
+ for ( ; it.current(); ++it )
+ map.insert( it.currentKey(), it.current()->text() );
+
+ return map;
+}
+
+int AttributesDialog::rdnprefix() const
+{
+ return mRDNCombo->currentItem();
+}
+
+void AttributesDialog::mapChanged( int pos )
+{
+
+ // apply first the default and than the spezific changes
+ TQMap<TQString, TQString>::Iterator it;
+ for ( it = mDefaultMap.begin(); it != mDefaultMap.end(); ++it )
+ mLineEditDict[ it.key() ]->setText( it.data() );
+
+ for ( it = mMapList[ pos ].begin(); it != mMapList[ pos ].end(); ++it ) {
+ if ( !it.data().isEmpty() ) {
+ KLineEdit *le = mLineEditDict[ it.key() ];
+ if ( le ) le->setText( it.data() );
+ }
+ }
+}
+
+OfflineDialog::OfflineDialog( bool autoCache, int cachePolicy, const KURL &src,
+ const TQString &dst, TQWidget *parent, const char *name )
+ : KDialogBase( Plain, i18n( "Offline Configuration" ), Ok | Cancel,
+ Ok, parent, name, true, true )
+{
+ TQFrame *page = plainPage();
+ TQVBoxLayout *layout = new TQVBoxLayout( page );
+ layout->setAutoAdd( true );
+
+ mSrc = src; mDst = dst;
+ mCacheGroup = new TQButtonGroup( 1, Qt::Horizontal,
+ i18n("Offline Cache Policy"), page );
+
+ TQRadioButton *bt;
+ new TQRadioButton( i18n("Do not use offline cache"), mCacheGroup );
+ bt = new TQRadioButton( i18n("Use local copy if no connection"), mCacheGroup );
+ new TQRadioButton( i18n("Always use local copy"), mCacheGroup );
+ mCacheGroup->setButton( cachePolicy );
+
+ mAutoCache = new TQCheckBox( i18n("Refresh offline cache automatically"),
+ page );
+ mAutoCache->setChecked( autoCache );
+ mAutoCache->setEnabled( bt->isChecked() );
+
+ connect( bt, TQT_SIGNAL(toggled(bool)), mAutoCache, TQT_SLOT(setEnabled(bool)) );
+
+ TQPushButton *lcache = new TQPushButton( i18n("Load into Cache"), page );
+ connect( lcache, TQT_SIGNAL( clicked() ), TQT_SLOT( loadCache() ) );
+}
+
+OfflineDialog::~OfflineDialog()
+{
+}
+
+bool OfflineDialog::autoCache() const
+{
+ return mAutoCache->isChecked();
+}
+
+int OfflineDialog::cachePolicy() const
+{
+ return mCacheGroup->selectedId();
+}
+
+void OfflineDialog::loadCache()
+{
+ if ( TDEIO::NetAccess::download( mSrc, mDst, this ) ) {
+ KMessageBox::information( this,
+ i18n("Successfully downloaded directory server contents!") );
+ } else {
+ KMessageBox::error( this,
+ i18n("An error occurred downloading directory server contents into file %1.").arg(mDst) );
+ }
+}
diff --git a/tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.h b/tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.h
new file mode 100644
index 000000000..121cf639e
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/resourceldaptdeioconfig.h
@@ -0,0 +1,118 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2002 - 2003 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 RESOURCELDAPCONFIG_H
+#define RESOURCELDAPCONFIG_H
+
+#include <tqmap.h>
+#include <tqradiobutton.h>
+#include <tqcombobox.h>
+#include <tqdict.h>
+
+#include <kdialogbase.h>
+#include <tderesources/configwidget.h>
+#include <tdeabc/ldif.h>
+#include <tdeabc/ldapconfigwidget.h>
+
+
+class TQCheckBox;
+class TQPushButton;
+class TQSpinBox;
+class TQString;
+
+class KComboBox;
+class KLineEdit;
+
+namespace KABC {
+
+class KABC_EXPORT ResourceLDAPTDEIOConfig : public KRES::ConfigWidget
+{
+ Q_OBJECT
+
+ public:
+ ResourceLDAPTDEIOConfig( TQWidget* parent = 0, const char* name = 0 );
+
+ public slots:
+ void loadSettings( KRES::Resource* );
+ void saveSettings( KRES::Resource* );
+
+ private slots:
+ void editAttributes();
+ void editCache();
+ private:
+ TQPushButton *mEditButton, *mCacheButton;
+ LdapConfigWidget *cfg;
+ TQCheckBox *mSubTree;
+ TQMap<TQString, TQString> mAttributes;
+ int mRDNPrefix, mCachePolicy;
+ bool mAutoCache;
+ TQString mCacheDst;
+};
+
+class AttributesDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ AttributesDialog( const TQMap<TQString, TQString> &attributes, int rdnprefix,
+ TQWidget *parent, const char *name = 0 );
+ ~AttributesDialog();
+
+ TQMap<TQString, TQString> attributes() const;
+ int rdnprefix() const;
+
+ private slots:
+ void mapChanged( int pos );
+
+ private:
+ enum { UserMap, KolabMap, NetscapeMap, EvolutionMap, OutlookMap };
+
+ KComboBox *mMapCombo, *mRDNCombo;
+ TQValueList< TQMap<TQString, TQString> > mMapList;
+ TQMap<TQString, TQString> mDefaultMap;
+ TQDict<KLineEdit> mLineEditDict;
+ TQDict<TQString> mNameDict;
+};
+
+class OfflineDialog : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ OfflineDialog( bool autoCache, int cachePolicy, const KURL &src,
+ const TQString &dst, TQWidget *parent, const char *name = 0 );
+ ~OfflineDialog();
+
+ int cachePolicy() const;
+ bool autoCache() const;
+
+ private slots:
+ void loadCache();
+
+ private:
+ KURL mSrc;
+ TQString mDst;
+ TQButtonGroup *mCacheGroup;
+ TQCheckBox *mAutoCache;
+};
+
+}
+
+#endif
diff --git a/tdeabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp b/tdeabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp
new file mode 100644
index 000000000..6d173eb51
--- /dev/null
+++ b/tdeabc/plugins/ldaptdeio/resourceldaptdeioplugin.cpp
@@ -0,0 +1,36 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 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 "resourceldaptdeio.h"
+#include "resourceldaptdeioconfig.h"
+
+#include <tdeglobal.h>
+#include <tdelocale.h>
+
+using namespace KABC;
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_ldaptdeio()
+ {
+ TDEGlobal::locale()->insertCatalogue("kabc_ldaptdeio");
+ return new KRES::PluginFactory<ResourceLDAPTDEIO, ResourceLDAPTDEIOConfig>();
+ }
+}
diff --git a/tdeabc/plugins/net/CMakeLists.txt b/tdeabc/plugins/net/CMakeLists.txt
new file mode 100644
index 000000000..cc9564995
--- /dev/null
+++ b/tdeabc/plugins/net/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
+ resourcenet.h
+ DESTINATION ${INCLUDE_INSTALL_DIR}/kabc )
+
+
+##### other data ################################
+
+install( FILES net.desktop DESTINATION ${SERVICES_INSTALL_DIR}/tderesources/kabc )
+
+
+##### kabc_net (library) ########################
+
+set( target kabc_net )
+
+set( ${target}_SRCS
+ resourcenet.cpp resourcenetconfig.cpp
+)
+
+tde_add_library( ${target} SHARED AUTOMOC
+ SOURCES ${${target}_SRCS}
+ VERSION 1.0.0
+ LINK tdeabc-shared
+ DESTINATION ${LIB_INSTALL_DIR}
+)
+
+
+##### kabc_net (module) #########################
+
+set( target kabc_net )
+
+set( ${target}_SRCS
+ resourcenetplugin.cpp
+)
+
+tde_add_kpart( ${target} AUTOMOC
+ SOURCES ${${target}_SRCS}
+ LINK kabc_net-shared
+ DESTINATION ${PLUGIN_INSTALL_DIR}
+)
diff --git a/tdeabc/plugins/net/Makefile.am b/tdeabc/plugins/net/Makefile.am
new file mode 100644
index 000000000..c2ded1b44
--- /dev/null
+++ b/tdeabc/plugins/net/Makefile.am
@@ -0,0 +1,28 @@
+INCLUDES = -I$(top_srcdir)/kabc -I$(top_builddir)/kabc $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourcenetconfig.h
+
+lib_LTLIBRARIES = libkabc_net.la
+libkabc_net_la_SOURCES = resourcenet.cpp resourcenetconfig.cpp
+libkabc_net_la_LDFLAGS = $(KDE_RPATH) $(all_libraries) -version-info 1:0:0 -no-undefined
+libkabc_net_la_LIBADD = $(top_builddir)/tdeabc/libkabc.la $(LIB_KIO)
+libkabc_net_la_COMPILE_FIRST = $(top_builddir)/tdeabc/addressee.h
+
+kde_module_LTLIBRARIES = kabc_net.la
+kabc_net_la_SOURCES = resourcenetplugin.cpp
+kabc_net_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) $(LIB_QT) -L../../../tdecore/.libs/ -ltdecore
+kabc_net_la_LIBADD = libkabc_net.la
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_net.pot
+
+kabcincludedir = $(includedir)/kabc
+kabcinclude_HEADERS = resourcenet.h
+
+servicedir = $(kde_servicesdir)/tderesources/kabc
+service_DATA = net.desktop
+
+resourcenetplugin.lo: ../../addressee.h
diff --git a/tdeabc/plugins/net/net.desktop b/tdeabc/plugins/net/net.desktop
new file mode 100644
index 000000000..2c72c202d
--- /dev/null
+++ b/tdeabc/plugins/net/net.desktop
@@ -0,0 +1,90 @@
+[Desktop Entry]
+Name=Network
+Name[af]=Netwerk
+Name[ar]=الشبكة
+Name[az]=Şəbəkə
+Name[be]=Сетка
+Name[bn]=নেটওয়ার্ক
+Name[br]=Rouedad
+Name[bs]=Mreža
+Name[ca]=Xarxa
+Name[cs]=Síť
+Name[csb]=Sec
+Name[cy]=Rhydwaith
+Name[da]=Netværk
+Name[de]=Netzwerk
+Name[el]=Δίκτυο
+Name[eo]=Reto
+Name[es]=Red
+Name[et]=Võrk
+Name[eu]=Sarea
+Name[fa]=شبکه
+Name[fi]=Verkko
+Name[fr]=Réseau
+Name[fy]=Netwurk
+Name[ga]=Líonra
+Name[gl]=Rede
+Name[he]=רשת
+Name[hi]=नेटवर्क
+Name[hr]=Mreža
+Name[hsb]=Syć
+Name[hu]=Hálózat
+Name[id]=Jaringan
+Name[is]=Net
+Name[it]=Rete
+Name[ja]=ネットワーク
+Name[ka]=ქსელი
+Name[kk]=Желі
+Name[km]=បណ្តាញ
+Name[ko]=네트워크
+Name[ku]=Tor
+Name[lb]=Netzwierk
+Name[lt]=Tinklas
+Name[lv]=Tīkls
+Name[mi]=Hao
+Name[mk]=Мрежа
+Name[mn]=Сүлжээ
+Name[ms]=Jaringan
+Name[nds]=Nettwark
+Name[ne]=सञ्जाल
+Name[nl]=Netwerk
+Name[nn]=Nettverk
+Name[nso]=Kgokagano
+Name[oc]=Resèu
+Name[pa]=ਨੈੱਟਵਰਕ
+Name[pl]=Sieć
+Name[pt]=Rede
+Name[pt_BR]=Rede
+Name[ro]=Reţea
+Name[ru]=Сеть
+Name[rw]=Urusobe
+Name[se]=Fierbmi
+Name[sk]=Sieť
+Name[sl]=Omrežje
+Name[sq]=Rrjeta
+Name[sr]=Мрежа
+Name[sr@Latn]=Mreža
+Name[ss]=Luchungechunge
+Name[sv]=Nätverk
+Name[ta]=பிணையம்
+Name[te]=కలన జాలం
+Name[tg]=Шабака
+Name[th]=ระบบเครือข่าย
+Name[tr]=Ağ
+Name[tt]=Çeltär
+Name[uk]=Мережа
+Name[uz]=Tarmoq
+Name[uz@cyrillic]=Tarмоқ
+Name[ven]=Vhukwamani
+Name[vi]=mạng
+Name[wa]=Rantoele
+Name[xh]=Umsebenzi womnatha
+Name[zh_CN]=网络
+Name[zh_HK]=網絡
+Name[zh_TW]=網路
+Name[zu]=Umsebenzi wokuxhumana okusakazekile
+X-TDE-Library=kabc_net
+Type=Service
+ServiceTypes=KResources/Plugin
+X-TDE-ResourceFamily=contact
+X-TDE-ResourceType=net
diff --git a/tdeabc/plugins/net/resourcenet.cpp b/tdeabc/plugins/net/resourcenet.cpp
new file mode 100644
index 000000000..5a46890d8
--- /dev/null
+++ b/tdeabc/plugins/net/resourcenet.cpp
@@ -0,0 +1,393 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 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 <tqfile.h>
+
+#include <kdebug.h>
+#include <tdeio/netaccess.h>
+#include <tdeio/scheduler.h>
+#include <tdelocale.h>
+#include <ksavefile.h>
+#include <tdetempfile.h>
+#include <kurlrequester.h>
+
+#include "addressbook.h"
+#include "formatfactory.h"
+#include "resourcenetconfig.h"
+#include "stdaddressbook.h"
+
+#include "resourcenet.h"
+
+using namespace KABC;
+
+class ResourceNet::ResourceNetPrivate
+{
+ public:
+ TDEIO::Job *mLoadJob;
+ bool mIsLoading;
+
+ TDEIO::Job *mSaveJob;
+ bool mIsSaving;
+
+ TQString mLastErrorString;
+};
+
+ResourceNet::ResourceNet( const TDEConfig *config )
+ : Resource( config ), mFormat( 0 ),
+ mTempFile( 0 ),
+ d( new ResourceNetPrivate )
+{
+ if ( config ) {
+ init( KURL( config->readPathEntry( "NetUrl" ) ), config->readEntry( "NetFormat" ) );
+ } else {
+ init( KURL(), TQString("vcard").latin1() );
+ }
+}
+
+ResourceNet::ResourceNet( const KURL &url, const TQString &format )
+ : Resource( 0 ), mFormat( 0 ),
+ mTempFile( 0 ),
+ d( new ResourceNetPrivate )
+{
+ init( url, format );
+}
+
+void ResourceNet::init( const KURL &url, const TQString &format )
+{
+ d->mLoadJob = 0;
+ d->mIsLoading = false;
+ d->mSaveJob = 0;
+ d->mIsSaving = false;
+
+ mFormatName = format;
+
+ FormatFactory *factory = FormatFactory::self();
+ mFormat = factory->format( mFormatName );
+ if ( !mFormat ) {
+ mFormatName = TQString("vcard").latin1();
+ mFormat = factory->format( mFormatName );
+ }
+
+ setUrl( url );
+}
+
+ResourceNet::~ResourceNet()
+{
+ if ( d->mIsLoading )
+ d->mLoadJob->kill();
+ if ( d->mIsSaving )
+ d->mSaveJob->kill();
+
+ delete d;
+ d = 0;
+
+ delete mFormat;
+ mFormat = 0;
+
+ deleteLocalTempFile();
+}
+
+void ResourceNet::writeConfig( TDEConfig *config )
+{
+ Resource::writeConfig( config );
+
+ config->writePathEntry( "NetUrl", mUrl.url() );
+ config->writeEntry( "NetFormat", mFormatName );
+}
+
+Ticket *ResourceNet::requestSaveTicket()
+{
+ kdDebug(5700) << "ResourceNet::requestSaveTicket()" << endl;
+
+ return createTicket( this );
+}
+
+void ResourceNet::releaseSaveTicket( Ticket *ticket )
+{
+ delete ticket;
+}
+
+bool ResourceNet::doOpen()
+{
+ return true;
+}
+
+void ResourceNet::doClose()
+{
+}
+
+bool ResourceNet::load()
+{
+ TQString tempFile;
+
+ if ( !TDEIO::NetAccess::download( mUrl, tempFile, 0 ) ) {
+ addressBook()->error( i18n( "Unable to download file '%1'." ).arg( mUrl.prettyURL() ) );
+ return false;
+ }
+
+ TQFile file( tempFile );
+ if ( !file.open( IO_ReadOnly ) ) {
+ addressBook()->error( i18n( "Unable to open file '%1'." ).arg( tempFile ) );
+ TDEIO::NetAccess::removeTempFile( tempFile );
+ return false;
+ }
+
+ bool result = clearAndLoad( &file );
+ if ( !result )
+ addressBook()->error( i18n( "Problems during parsing file '%1'." ).arg( tempFile ) );
+
+ TDEIO::NetAccess::removeTempFile( tempFile );
+
+ return result;
+}
+
+bool ResourceNet::clearAndLoad( TQFile *file )
+{
+ clear();
+ return mFormat->loadAll( addressBook(), this, file );
+}
+
+bool ResourceNet::asyncLoad()
+{
+ if ( d->mIsLoading ) {
+ abortAsyncLoading();
+ }
+
+ if (d->mIsSaving) {
+ kdWarning(5700) << "Aborted asyncLoad() because we're still asyncSave()ing!" << endl;
+ return false;
+ }
+
+ bool ok = createLocalTempFile();
+ if ( ok )
+ mTempFile->sync();
+ ok = mTempFile->close();
+
+ if ( !ok ) {
+ emit loadingError( this, i18n( "Unable to open file '%1'." ).arg( mTempFile->name() ) );
+ deleteLocalTempFile();
+ return false;
+ }
+
+ KURL dest;
+ dest.setPath( mTempFile->name() );
+
+ TDEIO::Scheduler::checkSlaveOnHold( true );
+ d->mLoadJob = TDEIO::file_copy( mUrl, dest, -1, true, false, false );
+ d->mIsLoading = true;
+ connect( d->mLoadJob, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( downloadFinished( TDEIO::Job* ) ) );
+
+ return true;
+}
+
+void ResourceNet::abortAsyncLoading()
+{
+ kdDebug(5700) << "ResourceNet::abortAsyncLoading()" << endl;
+
+ if ( d->mLoadJob ) {
+ d->mLoadJob->kill(); // result not emitted
+ d->mLoadJob = 0;
+ }
+
+ deleteLocalTempFile();
+ d->mIsLoading = false;
+}
+
+void ResourceNet::abortAsyncSaving()
+{
+ kdDebug(5700) << "ResourceNet::abortAsyncSaving()" << endl;
+
+ if ( d->mSaveJob ) {
+ d->mSaveJob->kill(); // result not emitted
+ d->mSaveJob = 0;
+ }
+
+ deleteLocalTempFile();
+ d->mIsSaving = false;
+}
+
+bool ResourceNet::save( Ticket* )
+{
+ kdDebug(5700) << "ResourceNet::save()" << endl;
+
+ if (d->mIsSaving) {
+ abortAsyncSaving();
+ }
+
+ KTempFile tempFile;
+ tempFile.setAutoDelete( true );
+ bool ok = false;
+
+ if ( tempFile.status() == 0 && tempFile.file() ) {
+ saveToFile( tempFile.file() );
+ tempFile.sync();
+ ok = tempFile.close();
+ }
+
+ if ( !ok ) {
+ addressBook()->error( i18n( "Unable to save file '%1'." ).arg( tempFile.name() ) );
+ return false;
+ }
+
+ ok = TDEIO::NetAccess::upload( tempFile.name(), mUrl, 0 );
+ if ( !ok )
+ addressBook()->error( i18n( "Unable to upload to '%1'." ).arg( mUrl.prettyURL() ) );
+
+ return ok;
+}
+
+bool ResourceNet::asyncSave( Ticket* )
+{
+ kdDebug(5700) << "ResourceNet::asyncSave()" << endl;
+
+ if (d->mIsSaving) {
+ abortAsyncSaving();
+ }
+
+ if (d->mIsLoading) {
+ kdWarning(5700) << "Aborted asyncSave() because we're still asyncLoad()ing!" << endl;
+ return false;
+ }
+
+ bool ok = createLocalTempFile();
+ if ( ok ) {
+ saveToFile( mTempFile->file() );
+ mTempFile->sync();
+ ok = mTempFile->close();
+ }
+
+ if ( !ok ) {
+ emit savingError( this, i18n( "Unable to save file '%1'." ).arg( mTempFile->name() ) );
+ deleteLocalTempFile();
+ return false;
+ }
+
+ KURL src;
+ src.setPath( mTempFile->name() );
+
+ TDEIO::Scheduler::checkSlaveOnHold( true );
+ d->mIsSaving = true;
+ d->mSaveJob = TDEIO::file_copy( src, mUrl, -1, true, false, false );
+ connect( d->mSaveJob, TQT_SIGNAL( result( TDEIO::Job* ) ),
+ this, TQT_SLOT( uploadFinished( TDEIO::Job* ) ) );
+
+ return true;
+}
+
+bool ResourceNet::createLocalTempFile()
+{
+ deleteStaleTempFile();
+ mTempFile = new KTempFile();
+ mTempFile->setAutoDelete( true );
+ return mTempFile->status() == 0;
+}
+
+void ResourceNet::deleteStaleTempFile()
+{
+ if ( hasTempFile() ) {
+ kdDebug(5700) << "stale temp file detected " << mTempFile->name() << endl;
+ deleteLocalTempFile();
+ }
+}
+
+void ResourceNet::deleteLocalTempFile()
+{
+ delete mTempFile;
+ mTempFile = 0;
+}
+
+void ResourceNet::saveToFile( TQFile *file )
+{
+ mFormat->saveAll( addressBook(), this, file );
+}
+
+void ResourceNet::setUrl( const KURL &url )
+{
+ mUrl = url;
+}
+
+KURL ResourceNet::url() const
+{
+ return mUrl;
+}
+
+void ResourceNet::setFormat( const TQString &name )
+{
+ mFormatName = name;
+ if ( mFormat )
+ delete mFormat;
+
+ FormatFactory *factory = FormatFactory::self();
+ mFormat = factory->format( mFormatName );
+}
+
+TQString ResourceNet::format() const
+{
+ return mFormatName;
+}
+
+void ResourceNet::downloadFinished( TDEIO::Job* )
+{
+ kdDebug(5700) << "ResourceNet::downloadFinished()" << endl;
+
+ d->mIsLoading = false;
+
+ if ( !hasTempFile() || mTempFile->status() != 0 ) {
+ d->mLastErrorString = i18n( "Download failed: Unable to create temporary file" );
+ TQTimer::singleShot( 0, this, TQT_SLOT( signalError() ) );
+ return;
+ }
+
+ TQFile file( mTempFile->name() );
+ if ( file.open( IO_ReadOnly ) ) {
+ if ( clearAndLoad( &file ) )
+ emit loadingFinished( this );
+ else
+ emit loadingError( this, i18n( "Problems during parsing file '%1'." ).arg( mTempFile->name() ) );
+ }
+ else {
+ emit loadingError( this, i18n( "Unable to open file '%1'." ).arg( mTempFile->name() ) );
+ }
+
+ deleteLocalTempFile();
+}
+
+void ResourceNet::uploadFinished( TDEIO::Job *job )
+{
+ kdDebug(5700) << "ResourceFile::uploadFinished()" << endl;
+
+ d->mIsSaving = false;
+
+ if ( job->error() )
+ emit savingError( this, job->errorString() );
+ else
+ emit savingFinished( this );
+
+ deleteLocalTempFile();
+}
+
+void ResourceNet::signalError()
+{
+ emit loadingError( this, d->mLastErrorString );
+ d->mLastErrorString.truncate( 0 );
+}
+
+#include "resourcenet.moc"
diff --git a/tdeabc/plugins/net/resourcenet.h b/tdeabc/plugins/net/resourcenet.h
new file mode 100644
index 000000000..49707081e
--- /dev/null
+++ b/tdeabc/plugins/net/resourcenet.h
@@ -0,0 +1,117 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 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 KABC_RESOURCENET_H
+#define KABC_RESOURCENET_H
+
+#include <tdeconfig.h>
+
+#include <sys/types.h>
+
+#include <tdeabc/resource.h>
+
+class TQFile;
+class TQTimer;
+class KTempFile;
+
+namespace TDEIO {
+class Job;
+}
+
+namespace KABC {
+
+class FormatPlugin;
+
+/**
+ @internal
+*/
+class KABC_EXPORT ResourceNet : public Resource
+{
+ Q_OBJECT
+
+ public:
+ ResourceNet( const TDEConfig* );
+ ResourceNet( const KURL &url, const TQString &format );
+ ~ResourceNet();
+
+ virtual void writeConfig( TDEConfig* );
+
+ virtual bool doOpen();
+ virtual void doClose();
+
+ virtual Ticket *requestSaveTicket();
+ virtual void releaseSaveTicket( Ticket* );
+
+ virtual bool load();
+ virtual bool asyncLoad();
+ virtual bool save( Ticket* ticket );
+ virtual bool asyncSave( Ticket* ticket );
+
+ /**
+ Set url of directory to be used for saving.
+ */
+ void setUrl( const KURL & );
+
+ /**
+ Return url of directory used for loading and saving the address book.
+ */
+ KURL url() const;
+
+ /**
+ Sets a new format by name.
+ */
+ void setFormat( const TQString &name );
+
+ /**
+ Returns the format name.
+ */
+ TQString format() const;
+
+ protected:
+ void init( const KURL &url, const TQString &format );
+
+ private slots:
+ void downloadFinished( TDEIO::Job* );
+ void uploadFinished( TDEIO::Job* );
+ void signalError();
+
+ private:
+ bool clearAndLoad( TQFile *file );
+ void saveToFile( TQFile *file );
+ bool hasTempFile() const { return mTempFile != 0; }
+ void abortAsyncLoading();
+ void abortAsyncSaving();
+ bool createLocalTempFile();
+ void deleteLocalTempFile();
+ void deleteStaleTempFile();
+
+ FormatPlugin *mFormat;
+ TQString mFormatName;
+
+ KURL mUrl;
+ KTempFile *mTempFile;
+
+ class ResourceNetPrivate;
+ ResourceNetPrivate *d;
+};
+
+}
+
+#endif
diff --git a/tdeabc/plugins/net/resourcenetconfig.cpp b/tdeabc/plugins/net/resourcenetconfig.cpp
new file mode 100644
index 000000000..8d5903f8b
--- /dev/null
+++ b/tdeabc/plugins/net/resourcenetconfig.cpp
@@ -0,0 +1,102 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 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 <kdialog.h>
+
+#include "formatfactory.h"
+#include "resourcenet.h"
+#include "stdaddressbook.h"
+
+#include "resourcenetconfig.h"
+
+using namespace KABC;
+
+ResourceNetConfig::ResourceNetConfig( TQWidget* parent, const char* name )
+ : ConfigWidget( parent, name ), mInEditMode( false )
+{
+ 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 );
+ mUrlEdit = new KURLRequester( this );
+ mUrlEdit->setMode( KFile::File );
+
+ mainLayout->addWidget( label, 1, 0 );
+ mainLayout->addWidget( mUrlEdit, 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 );
+ }
+ }
+}
+
+void ResourceNetConfig::setEditMode( bool value )
+{
+ mFormatBox->setEnabled( !value );
+ mInEditMode = value;
+}
+
+void ResourceNetConfig::loadSettings( KRES::Resource *res )
+{
+ ResourceNet *resource = dynamic_cast<ResourceNet*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceNetConfig::loadSettings(): cast failed" << endl;
+ return;
+ }
+
+ mFormatBox->setCurrentItem( mFormatTypes.findIndex( resource->format() ) );
+
+ mUrlEdit->setURL( resource->url().url() );
+}
+
+void ResourceNetConfig::saveSettings( KRES::Resource *res )
+{
+ ResourceNet *resource = dynamic_cast<ResourceNet*>( res );
+
+ if ( !resource ) {
+ kdDebug(5700) << "ResourceNetConfig::saveSettings(): cast failed" << endl;
+ return;
+ }
+
+ if ( !mInEditMode )
+ resource->setFormat( mFormatTypes[ mFormatBox->currentItem() ] );
+
+ resource->setUrl( KURL( mUrlEdit->url() ) );
+}
+
+#include "resourcenetconfig.moc"
diff --git a/tdeabc/plugins/net/resourcenetconfig.h b/tdeabc/plugins/net/resourcenetconfig.h
new file mode 100644
index 000000000..3c8986122
--- /dev/null
+++ b/tdeabc/plugins/net/resourcenetconfig.h
@@ -0,0 +1,53 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 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 RESOURCENETCONFIG_H
+#define RESOURCENETCONFIG_H
+
+#include <kcombobox.h>
+#include <kurlrequester.h>
+
+#include <tderesources/configwidget.h>
+
+namespace KABC {
+
+class KABC_EXPORT ResourceNetConfig : public KRES::ConfigWidget
+{
+ Q_OBJECT
+
+ public:
+ ResourceNetConfig( TQWidget* parent = 0, const char* name = 0 );
+
+ void setEditMode( bool value );
+
+ public slots:
+ void loadSettings( KRES::Resource *resource );
+ void saveSettings( KRES::Resource *resource );
+
+ private:
+ KComboBox* mFormatBox;
+ KURLRequester* mUrlEdit;
+
+ TQStringList mFormatTypes;
+ bool mInEditMode;
+};
+
+}
+#endif
diff --git a/tdeabc/plugins/net/resourcenetplugin.cpp b/tdeabc/plugins/net/resourcenetplugin.cpp
new file mode 100644
index 000000000..189bab051
--- /dev/null
+++ b/tdeabc/plugins/net/resourcenetplugin.cpp
@@ -0,0 +1,32 @@
+/*
+ This file is part of libkabc.
+ Copyright (c) 2003 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 "resourcenet.h"
+#include "resourcenetconfig.h"
+
+using namespace KABC;
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_net()
+ {
+ return new KRES::PluginFactory<ResourceNet, ResourceNetConfig>();
+ }
+}
diff --git a/tdeabc/plugins/sql/Makefile.am b/tdeabc/plugins/sql/Makefile.am
new file mode 100644
index 000000000..3fa3986ce
--- /dev/null
+++ b/tdeabc/plugins/sql/Makefile.am
@@ -0,0 +1,20 @@
+INCLUDES = -I$(top_srcdir)/kabc -I$(top_builddir)/kabc $(all_includes)
+
+# these are the headers for your project
+noinst_HEADERS = resourcesql.h resourcesqlconfig.h
+
+kde_module_LTLIBRARIES = kabc_sql.la
+
+kabc_sql_la_SOURCES = resourcesql.cpp resourcesqlconfig.cpp
+
+kabc_sql_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+kabc_sql_la_LIBADD = ../../libkabc.la ../../../tdeui/libtdeui.la
+
+METASOURCES = AUTO
+
+messages: rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kabc_sql.pot
+
+linkdir = $(kde_datadir)/tderesources/contact
+link_DATA = sql.desktop
+EXTRA_DIST = $(link_DATA)
diff --git a/tdeabc/plugins/sql/resourcesql.cpp b/tdeabc/plugins/sql/resourcesql.cpp
new file mode 100644
index 000000000..e3744eeec
--- /dev/null
+++ b/tdeabc/plugins/sql/resourcesql.cpp
@@ -0,0 +1,338 @@
+/*
+ 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 <tqsqldatabase.h>
+#include <tqsqlcursor.h>
+
+#include <kdebug.h>
+#include <tdeglobal.h>
+#include <klineedit.h>
+#include <tdelocale.h>
+
+#include "resourcesql.h"
+#include "resourcesqlconfig.h"
+
+using namespace KABC;
+
+extern "C"
+{
+ KDE_EXPORT void *init_kabc_sql()
+ {
+ return new KRES::PluginFactory<ResourceSql,ResourceSqlConfig>();
+ }
+}
+
+ResourceSql::ResourceSql( AddressBook *ab, const TDEConfig *config )
+ : Resource( ab ), mDb( 0 )
+{
+ TQString user, password, db, host;
+
+ user = config->readEntry( "SqlUser" );
+ password = cryptStr( config->readEntry( "SqlPassword " ) );
+ db = config->readEntry( "SqlName" );
+ host = config->readEntry( "SqlHost" );
+
+ init( user, password, db, host );
+}
+
+ResourceSql::ResourceSql( AddressBook *ab, const TQString &user,
+ const TQString &password, const TQString &db, const TQString &host )
+ : Resource( ab ), mDb( 0 )
+{
+ init( user, password, db, host );
+}
+
+void ResourceSql::init( const TQString &user, const TQString &password,
+ const TQString &db, const TQString &host )
+{
+ mUser = user;
+ mPassword = password;
+ mDbName = db;
+ mHost = host;
+}
+
+Ticket *ResourceSql::requestSaveTicket()
+{
+ if ( !addressBook() ) {
+ kdDebug(5700) << "no addressbook" << endl;
+ return 0;
+ }
+
+ return createTicket( this );
+}
+
+bool ResourceSql::open()
+{
+ TQStringList drivers = TQSqlDatabase::drivers();
+ for ( TQStringList::Iterator it = drivers.begin(); it != drivers.end(); ++it ) {
+ kdDebug(5700) << "Driver: " << (*it) << endl;
+ }
+
+ mDb = TQSqlDatabase::addDatabase( "QMYSQL3" );
+
+ if ( !mDb ) {
+ kdDebug(5700) << "Error. Unable to connect to database." << endl;
+ return false;
+ }
+
+ mDb->setDatabaseName( mDbName );
+ mDb->setUserName( mUser );
+ mDb->setPassword( mPassword );
+ mDb->setHostName( mHost );
+
+ if ( !mDb->open() ) {
+ kdDebug(5700) << "Error. Unable to open database '" << mDbName << "'." << endl;
+ return false;
+ }
+
+ return true;
+}
+
+void ResourceSql::close()
+{
+ mDb->close();
+}
+
+bool ResourceSql::load()
+{
+ TQSqlQuery query( "select addressId, name, familyName, givenName, "
+ "additionalName, prefix, suffix, nickname, birthday, "
+ "mailer, timezone, geo_latitude, geo_longitude, title, "
+ "role, organization, note, productId, revision, "
+ "sortString, url from kaddressbook_main_" + mUser );
+
+ while ( query.next() ) {
+ TQString addrId = query.value(0).toString();
+
+ Addressee addr;
+ addr.setResource( this );
+ addr.setUid( addrId );
+ addr.setName( query.value(1).toString() );
+ addr.setFamilyName( query.value(2).toString() );
+ addr.setGivenName( query.value(3).toString() );
+ addr.setAdditionalName( query.value(4).toString() );
+ addr.setPrefix( query.value(5).toString() );
+ addr.setSuffix( query.value(6).toString() );
+ addr.setNickName( query.value(7).toString() );
+ addr.setBirthday( query.value(8).toDateTime() );
+ addr.setMailer( query.value(9).toString() );
+ addr.setTimeZone( TimeZone( query.value(10).toInt() ) );
+ addr.setGeo( Geo( query.value(11).toDouble(), query.value(12).toDouble() ) );
+ addr.setTitle( query.value(13).toString() );
+ addr.setRole( query.value(14).toString() );
+ addr.setOrganization( query.value(15).toString() );
+ addr.setNote( query.value(16).toString() );
+ addr.setProductId( query.value(17).toString() );
+ addr.setRevision( query.value(18).toDateTime() );
+ addr.setSortString( query.value(19).toString() );
+ addr.setUrl( query.value(20).toString() );
+
+ // emails
+ {
+ TQSqlQuery emailsQuery( "select email, preferred from kaddressbook_emails "
+ "where addressId = '" + addrId + "'" );
+ while ( emailsQuery.next() )
+ addr.insertEmail( emailsQuery.value( 0 ).toString(),
+ emailsQuery.value( 1 ).toInt() );
+ }
+
+ // phones
+ {
+ TQSqlQuery phonesQuery( "select number, type from kaddressbook_phones "
+ "where addressId = '" + addrId + "'" );
+ while ( phonesQuery.next() )
+ addr.insertPhoneNumber( PhoneNumber( phonesQuery.value( 0 ).toString(),
+ phonesQuery.value( 1 ).toInt() ) );
+ }
+
+ // addresses
+ {
+ TQSqlQuery addressesQuery( "select postOfficeBox, extended, street, "
+ "locality, region, postalCode, country, label, type "
+ "from kaddressbook_addresses where addressId = '" + addrId + "'" );
+ while ( addressesQuery.next() ) {
+ Address a;
+ a.setPostOfficeBox( addressesQuery.value(0).toString() );
+ a.setExtended( addressesQuery.value(1).toString() );
+ a.setStreet( addressesQuery.value(2).toString() );
+ a.setLocality( addressesQuery.value(3).toString() );
+ a.setRegion( addressesQuery.value(4).toString() );
+ a.setPostalCode( addressesQuery.value(5).toString() );
+ a.setCountry( addressesQuery.value(6).toString() );
+ a.setLabel( addressesQuery.value(7).toString() );
+ a.setType( addressesQuery.value(8).toInt() );
+
+ addr.insertAddress( a );
+ }
+ }
+
+ // categories
+ {
+ TQSqlQuery categoriesQuery( "select category from kaddressbook_categories "
+ "where addressId = '" + addrId + "'" );
+ while ( categoriesQuery.next() )
+ addr.insertCategory( categoriesQuery.value( 0 ).toString() );
+ }
+
+ // customs
+ {
+ TQSqlQuery customsQuery( "select app, name, value from kaddressbook_customs "
+ "where addressId = '" + addrId + "'" );
+ while ( customsQuery.next() )
+ addr.insertCustom( customsQuery.value( 0 ).toString(),
+ customsQuery.value( 1 ).toString(),
+ customsQuery.value( 2 ).toString());
+ }
+
+ addressBook()->insertAddressee( addr );
+ }
+
+ return true;
+}
+
+bool ResourceSql::save( Ticket * )
+{
+ // we have to delete all entries for this user and reinsert them
+ TQSqlQuery query( "select addressId from kaddressbook_main_" + mUser );
+
+ while ( query.next() ) {
+ TQString addrId = query.value( 0 ).toString();
+ TQSqlQuery q;
+
+ q.exec( "DELETE FROM kaddressbook_emails WHERE addressId = '" + addrId + "'" );
+ q.exec( "DELETE FROM kaddressbook_phones WHERE addressId = '" + addrId + "'" );
+ q.exec( "DELETE FROM kaddressbook_addresses WHERE addressId = '" + addrId + "'" );
+ q.exec( "DELETE FROM kaddressbook_categories WHERE addressId = '" + addrId + "'" );
+ q.exec( "DELETE FROM kaddressbook_customs WHERE addressId = '" + addrId + "'" );
+
+ q.exec( "DELETE FROM kaddressbook_main_" + mUser + " WHERE addressId = '" + addrId + "'" );
+ }
+
+ // let's start...
+ AddressBook::Iterator it;
+ for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) {
+ if ( (*it).resource() != this && (*it).resource() != 0 ) // save only my and new entries
+ continue;
+
+ TQString uid = (*it).uid();
+
+ query.exec( "INSERT INTO kaddressbook_main_" + mUser + " VALUES ('" +
+ (*it).uid() + "','" +
+ (*it).name() + "','" +
+ (*it).familyName() + "','" +
+ (*it).givenName() + "','" +
+ (*it).additionalName() + "','" +
+ (*it).prefix() + "','" +
+ (*it).suffix() + "','" +
+ (*it).nickName() + "','" +
+ (*it).birthday().toString( Qt::ISODate ) + "','" +
+ (*it).mailer() + "','" +
+ TQString::number( (*it).timeZone().offset() ) + "','" +
+ TQString::number( (*it).geo().latitude() ) + "','" +
+ TQString::number( (*it).geo().longitude() ) + "','" +
+ (*it).title() + "','" +
+ (*it).role() + "','" +
+ (*it).organization() + "','" +
+ (*it).note() + "','" +
+ (*it).productId() + "','" +
+ (*it).revision().toString( Qt::ISODate ) + "','" +
+ (*it).sortString() + "','" +
+ (*it).url().url() + "')"
+ );
+
+ // emails
+ {
+ TQStringList emails = (*it).emails();
+ TQStringList::ConstIterator it;
+ bool preferred = true;
+ for( it = emails.begin(); it != emails.end(); ++it ) {
+ query.exec("INSERT INTO kaddressbook_emails VALUES ('" +
+ uid + "','" +
+ (*it) + "','" +
+ TQString::number(preferred) + "')");
+ preferred = false;
+ }
+ }
+
+ // phonenumbers
+ {
+ PhoneNumber::List phoneNumberList = (*it).phoneNumbers();
+ PhoneNumber::List::ConstIterator it;
+ for( it = phoneNumberList.begin(); it != phoneNumberList.end(); ++it ) {
+ query.exec("INSERT INTO kaddressbook_phones VALUES ('" +
+ uid + "','" +
+ (*it).number() + "','" +
+ TQString::number( (*it).type() ) + "')");
+ }
+ }
+
+ // postal addresses
+ {
+ Address::List addressList = (*it).addresses();
+ Address::List::ConstIterator it;
+ for( it = addressList.begin(); it != addressList.end(); ++it ) {
+ query.exec("INSERT INTO kaddressbook_addresses VALUES ('" +
+ uid + "','" +
+ (*it).postOfficeBox() + "','" +
+ (*it).extended() + "','" +
+ (*it).street() + "','" +
+ (*it).locality() + "','" +
+ (*it).region() + "','" +
+ (*it).postalCode() + "','" +
+ (*it).country() + "','" +
+ (*it).label() + "','" +
+ TQString::number( (*it).type() ) + "')");
+ }
+ }
+
+ // categories
+ {
+ TQStringList categories = (*it).categories();
+ TQStringList::ConstIterator it;
+ for( it = categories.begin(); it != categories.end(); ++it )
+ query.exec("INSERT INTO kaddressbook_categories VALUES ('" +
+ uid + "','" +
+ (*it) + "')");
+ }
+
+ // customs
+ {
+ TQStringList list = (*it).customs();
+ TQStringList::ConstIterator it;
+ for( it = list.begin(); it != list.end(); ++it ) {
+ int dashPos = (*it).find( '-' );
+ int colonPos = (*it).find( ':' );
+ TQString app = (*it).left( dashPos );
+ TQString name = (*it).mid( dashPos + 1, colonPos - dashPos - 1 );
+ TQString value = (*it).right( (*it).length() - colonPos - 1 );
+
+ query.exec("INSERT INTO kaddressbook_categories VALUES ('" +
+ uid + "','" + app + "','" + name + "','" + value + "')");
+ }
+ }
+ }
+
+ return true;
+}
+
+TQString ResourceSql::identifier() const
+{
+ return mHost + "_" + mDbName;
+}
diff --git a/tdeabc/plugins/sql/resourcesql.h b/tdeabc/plugins/sql/resourcesql.h
new file mode 100644
index 000000000..770e5b73b
--- /dev/null
+++ b/tdeabc/plugins/sql/resourcesql.h
@@ -0,0 +1,63 @@
+/*
+ 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 KABC_RESOURCESQL_H
+#define KABC_RESOURCESQL_H
+
+#include <tdeconfig.h>
+
+#include "addressbook.h"
+#include "resource.h"
+
+class TQSqlDatabase;
+
+namespace KABC {
+
+class ResourceSql : public Resource
+{
+public:
+ ResourceSql( AddressBook *ab, const TQString &user, const TQString &password,
+ const TQString &db, const TQString &host );
+ ResourceSql( AddressBook *ab, const TDEConfig * );
+
+ bool open();
+ void close();
+
+ Ticket *requestSaveTicket();
+
+ bool load();
+ bool save( Ticket * ticket );
+
+ TQString identifier() const;
+
+private:
+ void init(const TQString &user, const TQString &password,
+ const TQString &db, const TQString &host );
+
+ TQString mUser;
+ TQString mPassword;
+ TQString mDbName;
+ TQString mHost;
+
+ TQSqlDatabase *mDb;
+};
+
+}
+#endif
diff --git a/tdeabc/plugins/sql/resourcesqlconfig.cpp b/tdeabc/plugins/sql/resourcesqlconfig.cpp
new file mode 100644
index 000000000..2f5b9d5b7
--- /dev/null
+++ b/tdeabc/plugins/sql/resourcesqlconfig.cpp
@@ -0,0 +1,95 @@
+/*
+ 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 <tqspinbox.h>
+#include <tqvbox.h>
+
+#include <klineedit.h>
+#include <tdelocale.h>
+
+#include "resource.h"
+#include "resourcesqlconfig.h"
+
+using namespace KABC;
+
+ResourceSqlConfig::ResourceSqlConfig( TQWidget* parent, const char* name )
+ : ResourceConfigWidget( parent, name )
+{
+ resize( 290, 170 );
+
+ TQGridLayout *mainLayout = new TQGridLayout( this, 4, 2 );
+
+ TQLabel *label = new TQLabel( i18n( "Username:" ), this );
+ mUser = new KLineEdit( this );
+
+ mainLayout->addWidget( label, 0, 0 );
+ mainLayout->addWidget( mUser, 0, 1 );
+
+ label = new TQLabel( i18n( "Password:" ), this );
+ mPassword = new KLineEdit( this );
+ mPassword->setEchoMode( KLineEdit::Password );
+
+ mainLayout->addWidget( label, 1, 0 );
+ mainLayout->addWidget( mPassword, 1, 1 );
+
+ label = new TQLabel( i18n( "Host:" ), this );
+ mHost = new KLineEdit( this );
+
+ mainLayout->addWidget( label, 2, 0 );
+ mainLayout->addWidget( mHost, 2, 1 );
+
+ label = new TQLabel( i18n( "Port:" ), this );
+ TQVBox *box = new TQVBox(this);
+ mPort = new TQSpinBox(0, 65535, 1, box );
+ mPort->setSizePolicy(TQSizePolicy(TQSizePolicy::Maximum, TQSizePolicy::Preferred));
+ mPort->setValue(389);
+ new TQWidget(box, "dummy");
+
+ mainLayout->addWidget( label, 3, 0 );
+ mainLayout->addWidget( box, 3, 1 );
+
+ label = new TQLabel( i18n( "Database:" ), this );
+ mDbName = new KLineEdit( this );
+
+ mainLayout->addWidget( label, 4, 0 );
+ mainLayout->addWidget( mDbName, 4, 1 );
+}
+
+void ResourceSqlConfig::loadSettings( TDEConfig *config )
+{
+ mUser->setText( config->readEntry( "SqlUser" ) );
+ mPassword->setText( KABC::Resource::cryptStr( config->readEntry( "SqlPassword" ) ) );
+ mDbName->setText( config->readEntry( "SqlName" ) );
+ mHost->setText( config->readEntry( "SqlHost" ) );
+ mPort->setValue( config->readNumEntry( "SqlPort" ) );
+}
+
+void ResourceSqlConfig::saveSettings( TDEConfig *config )
+{
+ config->writeEntry( "SqlUser", mUser->text() );
+ config->writeEntry( "SqlPassword", KABC::Resource::cryptStr( mPassword->text() ) );
+ config->writeEntry( "SqlName", mDbName->text() );
+ config->writeEntry( "SqlHost", mHost->text() );
+ config->writeEntry( "SqlPort", mPort->value() );
+}
+
+#include "resourcesqlconfig.moc"
diff --git a/tdeabc/plugins/sql/resourcesqlconfig.h b/tdeabc/plugins/sql/resourcesqlconfig.h
new file mode 100644
index 000000000..ae2de7d6d
--- /dev/null
+++ b/tdeabc/plugins/sql/resourcesqlconfig.h
@@ -0,0 +1,51 @@
+/*
+ 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 RESOURCESQLCONFIG_H
+#define RESOURCESQLCONFIG_H
+
+#include "resourceconfigwidget.h"
+
+class KLineEdit;
+class TQSpinBox;
+
+namespace KABC {
+
+class ResourceSqlConfig : public ResourceConfigWidget
+{
+ Q_OBJECT
+
+public:
+ ResourceSqlConfig( TQWidget* parent = 0, const char* name = 0 );
+
+public slots:
+ void loadSettings( TDEConfig *config );
+ void saveSettings( TDEConfig *config );
+
+private:
+ KLineEdit* mUser;
+ KLineEdit* mPassword;
+ KLineEdit* mDbName;
+ KLineEdit* mHost;
+ TQSpinBox* mPort;
+};
+
+}
+#endif
diff --git a/tdeabc/plugins/sql/sql.desktop b/tdeabc/plugins/sql/sql.desktop
new file mode 100644
index 000000000..4ac553008
--- /dev/null
+++ b/tdeabc/plugins/sql/sql.desktop
@@ -0,0 +1,10 @@
+[Misc]
+Name=SQL
+Name[bn]=এস-কিউ-এল (SQL)
+Name[hi]=एसक्यूएल (SQL)
+Name[ss]=I-SQL
+Name[te]=ఏస్క్యుఎల్
+
+[Plugin]
+Type=sql
+X-TDE-Library=kabc_sql