author | ulf69 <ulf69> | 2004-08-04 22:45:22 (UTC) |
---|---|---|
committer | ulf69 <ulf69> | 2004-08-04 22:45:22 (UTC) |
commit | c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852 (patch) (side-by-side diff) | |
tree | dc59744a6d59ba241e793ce051da485d0bf16d06 /kabc | |
parent | b83866e08ddcc5cb2734801977927f48b53a2e1c (diff) | |
download | kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.zip kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.tar.gz kdepimpi-c3a704f5acda9cf9fee66e5c0b1b864f3b7dd852.tar.bz2 |
final changes for addressbook sync config dialog
-rw-r--r-- | kabc/addressbook.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/dir/resourcedir.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/file/resourcefile.cpp | 28 | ||||
-rw-r--r-- | kabc/plugins/ldap/resourceldap.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/opie/resourceopie.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/qtopia/resourceqtopia.cpp | 2 | ||||
-rw-r--r-- | kabc/plugins/sharpdtm/resourcesharpdtm.cpp | 2 | ||||
-rw-r--r-- | kabc/resource.cpp | 5 | ||||
-rw-r--r-- | kabc/resource.h | 2 | ||||
-rw-r--r-- | kabc/stdaddressbook.cpp | 6 | ||||
-rw-r--r-- | kabc/syncprefwidget.cpp | 581 | ||||
-rw-r--r-- | kabc/syncprefwidget.h | 138 |
12 files changed, 350 insertions, 422 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 20310a0..c61b387 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -1,622 +1,622 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ /*US #include <qfile.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kinstance.h> #include <kstandarddirs.h> #include "errorhandler.h" */ #include <qptrlist.h> #include <kglobal.h> #include <klocale.h> #include <kdebug.h> #include "addressbook.h" #include "resource.h" //US #include "addressbook.moc" using namespace KABC; struct AddressBook::AddressBookData { Addressee::List mAddressees; Addressee::List mRemovedAddressees; Field::List mAllFields; KConfig *mConfig; KRES::Manager<Resource> *mManager; //US ErrorHandler *mErrorHandler; }; struct AddressBook::Iterator::IteratorData { Addressee::List::Iterator mIt; }; struct AddressBook::ConstIterator::ConstIteratorData { Addressee::List::ConstIterator mIt; }; AddressBook::Iterator::Iterator() { d = new IteratorData; } AddressBook::Iterator::Iterator( const AddressBook::Iterator &i ) { d = new IteratorData; d->mIt = i.d->mIt; } AddressBook::Iterator &AddressBook::Iterator::operator=( const AddressBook::Iterator &i ) { if( this == &i ) return *this; // guard against self assignment delete d; // delete the old data the Iterator was completely constructed before d = new IteratorData; d->mIt = i.d->mIt; return *this; } AddressBook::Iterator::~Iterator() { delete d; } const Addressee &AddressBook::Iterator::operator*() const { return *(d->mIt); } Addressee &AddressBook::Iterator::operator*() { return *(d->mIt); } Addressee *AddressBook::Iterator::operator->() { return &(*(d->mIt)); } AddressBook::Iterator &AddressBook::Iterator::operator++() { (d->mIt)++; return *this; } AddressBook::Iterator &AddressBook::Iterator::operator++(int) { (d->mIt)++; return *this; } AddressBook::Iterator &AddressBook::Iterator::operator--() { (d->mIt)--; return *this; } AddressBook::Iterator &AddressBook::Iterator::operator--(int) { (d->mIt)--; return *this; } bool AddressBook::Iterator::operator==( const Iterator &it ) { return ( d->mIt == it.d->mIt ); } bool AddressBook::Iterator::operator!=( const Iterator &it ) { return ( d->mIt != it.d->mIt ); } AddressBook::ConstIterator::ConstIterator() { d = new ConstIteratorData; } AddressBook::ConstIterator::ConstIterator( const AddressBook::ConstIterator &i ) { d = new ConstIteratorData; d->mIt = i.d->mIt; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator=( const AddressBook::ConstIterator &i ) { if( this == &i ) return *this; // guard for self assignment delete d; // delete the old data because the Iterator was really constructed before d = new ConstIteratorData; d->mIt = i.d->mIt; return *this; } AddressBook::ConstIterator::~ConstIterator() { delete d; } const Addressee &AddressBook::ConstIterator::operator*() const { return *(d->mIt); } const Addressee* AddressBook::ConstIterator::operator->() const { return &(*(d->mIt)); } AddressBook::ConstIterator &AddressBook::ConstIterator::operator++() { (d->mIt)++; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator++(int) { (d->mIt)++; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator--() { (d->mIt)--; return *this; } AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) { (d->mIt)--; return *this; } bool AddressBook::ConstIterator::operator==( const ConstIterator &it ) { return ( d->mIt == it.d->mIt ); } bool AddressBook::ConstIterator::operator!=( const ConstIterator &it ) { return ( d->mIt != it.d->mIt ); } AddressBook::AddressBook() { init(0, "contact"); } AddressBook::AddressBook( const QString &config ) { init(config, "contact"); } AddressBook::AddressBook( const QString &config, const QString &family ) { init(config, family); } // the default family is "contact" void AddressBook::init(const QString &config, const QString &family ) { d = new AddressBookData; if (config != 0) { - d->mConfig = new KConfig( config ); + d->mConfig = new KConfig( locateLocal("config", config) ); // qDebug("AddressBook::init 1 config=%s",config.latin1() ); } else { d->mConfig = 0; // qDebug("AddressBook::init 1 config=0"); } //US d->mErrorHandler = 0; d->mManager = new KRES::Manager<Resource>( family, false ); d->mManager->readConfig( d->mConfig ); } AddressBook::~AddressBook() { delete d->mConfig; d->mConfig = 0; delete d->mManager; d->mManager = 0; //US delete d->mErrorHandler; d->mErrorHandler = 0; delete d; d = 0; } bool AddressBook::load() { clear(); KRES::Manager<Resource>::ActiveIterator it; bool ok = true; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) if ( !(*it)->load() ) { error( i18n("Unable to load resource '%1'").arg( (*it)->resourceName() ) ); ok = false; } // mark all addressees as unchanged Addressee::List::Iterator addrIt; for ( addrIt = d->mAddressees.begin(); addrIt != d->mAddressees.end(); ++addrIt ) (*addrIt).setChanged( false ); return ok; } bool AddressBook::save( Ticket *ticket ) { kdDebug(5700) << "AddressBook::save()"<< endl; if ( ticket->resource() ) { deleteRemovedAddressees(); return ticket->resource()->save( ticket ); } return false; } AddressBook::Iterator AddressBook::begin() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::ConstIterator AddressBook::begin() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.begin(); return it; } AddressBook::Iterator AddressBook::end() { Iterator it = Iterator(); it.d->mIt = d->mAddressees.end(); return it; } AddressBook::ConstIterator AddressBook::end() const { ConstIterator it = ConstIterator(); it.d->mIt = d->mAddressees.end(); return it; } void AddressBook::clear() { d->mAddressees.clear(); } Ticket *AddressBook::requestSaveTicket( Resource *resource ) { kdDebug(5700) << "AddressBook::requestSaveTicket()" << endl; if ( !resource ) { qDebug("AddressBook::requestSaveTicket no resource" ); resource = standardResource(); } KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( (*it) == resource ) { if ( (*it)->readOnly() || !(*it)->isOpen() ) return 0; else return (*it)->requestSaveTicket(); } } return 0; } void AddressBook::insertAddressee( const Addressee &a ) { Addressee::List::Iterator it; for ( it = d->mAddressees.begin(); it != d->mAddressees.end(); ++it ) { if ( a.uid() == (*it).uid() ) { bool changed = false; Addressee addr = a; if ( addr != (*it) ) changed = true; (*it) = a; if ( (*it).resource() == 0 ) (*it).setResource( standardResource() ); if ( changed ) { (*it).setRevision( QDateTime::currentDateTime() ); (*it).setChanged( true ); } return; } } d->mAddressees.append( a ); Addressee& addr = d->mAddressees.last(); if ( addr.resource() == 0 ) addr.setResource( standardResource() ); addr.setChanged( true ); } void AddressBook::removeAddressee( const Addressee &a ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { removeAddressee( it ); return; } } } void AddressBook::removeAddressee( const Iterator &it ) { d->mRemovedAddressees.append( (*it) ); d->mAddressees.remove( it.d->mIt ); } AddressBook::Iterator AddressBook::find( const Addressee &a ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( a.uid() == (*it).uid() ) { return it; } } return end(); } Addressee AddressBook::findByUid( const QString &uid ) { Iterator it; for ( it = begin(); it != end(); ++it ) { if ( uid == (*it).uid() ) { return *it; } } return Addressee(); } Addressee::List AddressBook::allAddressees() { return d->mAddressees; } Addressee::List AddressBook::findByName( const QString &name ) { Addressee::List results; Iterator it; for ( it = begin(); it != end(); ++it ) { if ( name == (*it).name() ) { results.append( *it ); } } return results; } Addressee::List AddressBook::findByEmail( const QString &email ) { Addressee::List results; QStringList mailList; Iterator it; for ( it = begin(); it != end(); ++it ) { mailList = (*it).emails(); for ( QStringList::Iterator ite = mailList.begin(); ite != mailList.end(); ++ite ) { if ( email == (*ite) ) { results.append( *it ); } } } return results; } Addressee::List AddressBook::findByCategory( const QString &category ) { Addressee::List results; Iterator it; for ( it = begin(); it != end(); ++it ) { if ( (*it).hasCategory( category) ) { results.append( *it ); } } return results; } void AddressBook::dump() const { kdDebug(5700) << "AddressBook::dump() --- begin ---" << endl; ConstIterator it; for( it = begin(); it != end(); ++it ) { (*it).dump(); } kdDebug(5700) << "AddressBook::dump() --- end ---" << endl; } QString AddressBook::identifier() { QStringList identifier; KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) { if ( !(*it)->identifier().isEmpty() ) identifier.append( (*it)->identifier() ); } return identifier.join( ":" ); } Field::List AddressBook::fields( int category ) { if ( d->mAllFields.isEmpty() ) { d->mAllFields = Field::allFields(); } if ( category == Field::All ) return d->mAllFields; Field::List result; Field::List::ConstIterator it; for( it = d->mAllFields.begin(); it != d->mAllFields.end(); ++it ) { if ( (*it)->category() & category ) result.append( *it ); } return result; } bool AddressBook::addCustomField( const QString &label, int category, const QString &key, const QString &app ) { if ( d->mAllFields.isEmpty() ) { d->mAllFields = Field::allFields(); } //US QString a = app.isNull() ? KGlobal::instance()->instanceName() : app; QString a = app.isNull() ? KGlobal::getAppName() : app; QString k = key.isNull() ? label : key; Field *field = Field::createCustomField( label, category, k, a ); if ( !field ) return false; d->mAllFields.append( field ); return true; } QDataStream &KABC::operator<<( QDataStream &s, const AddressBook &ab ) { if (!ab.d) return s; return s << ab.d->mAddressees; } QDataStream &KABC::operator>>( QDataStream &s, AddressBook &ab ) { if (!ab.d) return s; s >> ab.d->mAddressees; return s; } bool AddressBook::addResource( Resource *resource ) { if ( !resource->open() ) { kdDebug(5700) << "AddressBook::addResource(): can't add resource" << endl; return false; } resource->setAddressBook( this ); d->mManager->add( resource ); return true; } bool AddressBook::removeResource( Resource *resource ) { resource->close(); if ( resource == standardResource() ) d->mManager->setStandardResource( 0 ); resource->setAddressBook( 0 ); d->mManager->remove( resource ); return true; } QPtrList<Resource> AddressBook::resources() { QPtrList<Resource> list; // qDebug("AddressBook::resources() 1"); KRES::Manager<Resource>::ActiveIterator it; for ( it = d->mManager->activeBegin(); it != d->mManager->activeEnd(); ++it ) list.append( *it ); return list; } /*US void AddressBook::setErrorHandler( ErrorHandler *handler ) { delete d->mErrorHandler; d->mErrorHandler = handler; } */ void AddressBook::error( const QString& msg ) { /*US if ( !d->mErrorHandler ) // create default error handler d->mErrorHandler = new ConsoleErrorHandler; if ( d->mErrorHandler ) d->mErrorHandler->error( msg ); else kdError(5700) << "no error handler defined" << endl; */ kdDebug(5700) << "msg" << endl; qDebug(msg); } void AddressBook::deleteRemovedAddressees() { Addressee::List::Iterator it; for ( it = d->mRemovedAddressees.begin(); it != d->mRemovedAddressees.end(); ++it ) { Resource *resource = (*it).resource(); if ( resource && !resource->readOnly() && resource->isOpen() ) resource->removeAddressee( *it ); } d->mRemovedAddressees.clear(); } diff --git a/kabc/plugins/dir/resourcedir.cpp b/kabc/plugins/dir/resourcedir.cpp index 29f1e3a..eccd482 100644 --- a/kabc/plugins/dir/resourcedir.cpp +++ b/kabc/plugins/dir/resourcedir.cpp @@ -1,365 +1,365 @@ /* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #ifndef _WIN32_ #include <unistd.h> #endif #include <qregexp.h> #include <qtimer.h> #include <qwidget.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> //US #include <kgenericfactory.h> #include <kglobal.h> #include <klocale.h> #include <kstandarddirs.h> #include <kurlrequester.h> #include <kmessagebox.h> #include "addressbook.h" #include "formatfactory.h" #include "resourcedirconfig.h" #include "stdaddressbook.h" //US #include <qdir.h> #include "resourcedir.h" #include "syncprefwidget.h" using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif //US void *init_kabc_dir() void *init_microkabc_dir() { - return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidget>(); + return new KRES::PluginFactory<ResourceDir,ResourceDirConfig, SyncPrefWidgetContainer>(); } #ifndef _WIN32_ } #endif ResourceDir::ResourceDir( const KConfig *config, bool syncable ) : Resource( config, syncable ) { QString path; KConfig *cfg = (KConfig *)config; if ( cfg ) { //US path = config->readEntry( "FilePath" ); path = cfg->readEntry( "FilePath", StdAddressBook::directoryName() ); //US mFormatName = config->readEntry( "FileFormat" ); mFormatName = cfg->readEntry( "FileFormat", "vcard" ); } else { path = StdAddressBook::directoryName(); mFormatName = "vcard"; } FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); if ( !mFormat ) { mFormatName = "vcard"; mFormat = factory->format( mFormatName ); } /*US //US qDebug("ResourceDir::ResourceDir initialized with format %s ", mFormatName.latin1()); if (mFormatName == "vcard") mFormat = new VCardFormatPlugin2(); else if (mFormatName == "binary") mFormat = new BinaryFormat(); else qDebug("ResourceFile::init format unknown !!! %s ", mFormatName.latin1()); */ connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( pathChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( pathChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( pathChanged() ) ); setPath( path ); } ResourceDir::~ResourceDir() { delete mFormat; mFormat = 0; } void ResourceDir::writeConfig( KConfig *config ) { config->setGroup( "Resource_" + identifier() ); Resource::writeConfig( config ); config->writeEntry( "FilePath", mPath ); config->writeEntry( "FileFormat", mFormatName ); } Ticket *ResourceDir::requestSaveTicket() { kdDebug(5700) << "ResourceDir::requestSaveTicket()" << endl; if ( !addressBook() ) return 0; if ( !lock( mPath ) ) { kdDebug(5700) << "ResourceDir::requestSaveTicket(): Unable to lock path '" << mPath << "'" << endl; return 0; } return createTicket( this ); } bool ResourceDir::doOpen() { QDir dir( mPath ); if ( !dir.exists() ) { // no directory available return dir.mkdir( dir.path() ); } else { QString testName = dir.entryList( QDir::Files )[0]; if ( testName.isNull() || testName.isEmpty() ) // no file in directory return true; QFile 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; QDir dir( mPath ); QStringList files = dir.entryList( QDir::Files ); QStringList::Iterator it; bool ok = true; for ( it = files.begin(); it != files.end(); ++it ) { QFile 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::save( Ticket *ticket ) { kdDebug(5700) << "ResourceDir::save(): '" << mPath << "'" << endl; AddressBook::Iterator it; bool ok = true; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { if ( (*it).resource() != this || !(*it).changed() ) continue; QFile 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(); } delete ticket; unlock( mPath ); return ok; } bool ResourceDir::lock( const QString &path ) { kdDebug(5700) << "ResourceDir::lock()" << endl; QString p = path; //US change the implementation how the lockfilename is getting created //US p.replace( QRegExp("/"), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + p + ".lock" ); KURL url(p); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if ( QFile::exists( lockName ) ) return false; QString lockUniqueName; lockUniqueName = p + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceDir::unlock( const QString &path ) { QString p = path; //US change the implementation how the lockfilename is getting created //US p.replace( QRegExp( "/" ), "_" ); //US QString lockName = locate( "data", "kabc/lock/" + p + ".lock" ); KURL url(p); QString lockName = locate( "data", "kabc/lock/" + url.fileName() + ".lock" ); ::unlink( QFile::encodeName( lockName ) ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceDir::setPath( const QString &path ) { mDirWatch.stopScan(); mDirWatch.removeDir( mPath ); mPath = path; mDirWatch.addDir( mPath, true ); mDirWatch.startScan(); //US simulate KDirWatch event //US pathChanged(); } QString ResourceDir::path() const { return mPath; } void ResourceDir::setFormat( const QString &format ) { mFormatName = format; if ( mFormat ) delete mFormat; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); /*US qDebug("ResourceDir::setFormat initialized with format %s ", format.latin1()); if (mFormatName == "vcard") mFormat = new VCardFormatPlugin2(); else if (mFormatName == "binary") mFormat = new BinaryFormat(); else qDebug("ResourceDir::setFormat format unknown !!! %s ", format.latin1()); */ } QString ResourceDir::format() const { return mFormatName; } void ResourceDir::pathChanged() { if ( !addressBook() ) return; QString text( i18n( "Dir resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mPath ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceDir::removeAddressee( const Addressee& addr ) { QFile::remove( mPath + "/" + addr.uid() ); } void ResourceDir::cleanUp() { unlock( mPath ); } //US #include "resourcedir.moc" diff --git a/kabc/plugins/file/resourcefile.cpp b/kabc/plugins/file/resourcefile.cpp index d98efc8..da2e4d7 100644 --- a/kabc/plugins/file/resourcefile.cpp +++ b/kabc/plugins/file/resourcefile.cpp @@ -1,399 +1,389 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #ifndef _WIN32_ #include <unistd.h> #endif #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include "formatfactory.h" #include "resource.h" #include "resourcefileconfig.h" #include "stdaddressbook.h" #include "resourcefile.h" #include "syncprefwidget.h" using namespace KABC; extern "C" #ifdef _WIN32_ __declspec(dllexport) #else { #endif //US void *init_kabc_file() void *init_microkabc_file() { - return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidget>(); + return new KRES::PluginFactory<ResourceFile,ResourceFileConfig, SyncPrefWidgetContainer>(); } #ifndef _WIN32_ } #endif ResourceFile::ResourceFile( const KConfig *config, bool syncable ) : Resource( config, syncable ) , mFormat( 0 ) { - QString fileName, formatName; + QString fileName, formatName, default_fileName; + + if (syncable == true) + default_fileName = "/home/polo/kdepim/apps/kabc/localfile.vcf"; + else + default_fileName = StdAddressBook::fileName(); KConfig *cfg = (KConfig *)config; if ( cfg ) { - fileName = cfg->readEntry( "FileName", StdAddressBook::fileName() ); + fileName = cfg->readEntry( "FileName", default_fileName ); formatName = cfg->readEntry( "FileFormat", "vcard" ); -// qDebug("ResourceFile::ResourceFile : 1 %s, %s", fileName.latin1(), formatName.latin1() ); } else { - fileName = StdAddressBook::fileName(); + fileName = default_fileName; formatName = "vcard"; -// qDebug("ResourceFile::ResourceFile : 2 %s, %s", fileName.latin1(), formatName.latin1() ); } init( fileName, formatName ); } ResourceFile::ResourceFile( const QString &fileName, bool syncable , const QString &formatName ) : Resource( 0, syncable ) { // qDebug("ResourceFile::ResourceFile : 3 %s, %s", fileName.latin1(), formatName.latin1()); init( fileName, formatName ); } void ResourceFile::init( const QString &fileName, const QString &formatName ) { mFormatName = formatName; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); if ( !mFormat ) { mFormatName = "vcard"; mFormat = factory->format( mFormatName ); } -/*US -//US qDebug("ResourceFile::init initialized with format %s ", formatName.latin1()); - if (mFormatName == "vcard") { - mFormat = new VCardFormatPlugin2(); -// qDebug("ResourceFile::init format VCardFormatPlugin2"); - } - else if (mFormatName == "binary") { - mFormat = new BinaryFormat(); -// qDebug("ResourceFile::init format BinaryFormat"); - } - else - qDebug("ResourceFile::init format unknown !!! %s ", formatName.latin1()); -*/ connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); setFileName( fileName ); } ResourceFile::~ResourceFile() { delete mFormat; mFormat = 0; } void ResourceFile::writeConfig( KConfig *config ) { config->setGroup( "Resource_" + identifier() ); Resource::writeConfig( config ); config->writeEntry( "FileName", mFileName ); config->writeEntry( "FileFormat", mFormatName ); // qDebug("ResourceFile::writeConfig format %s, %s", mFileName.latin1(), mFormatName.latin1()); } Ticket *ResourceFile::requestSaveTicket() { kdDebug(5700) << "ResourceFile::requestSaveTicket()" << endl; if ( !addressBook() ) return 0; if ( !lock( mFileName ) ) { kdDebug(5700) << "ResourceFile::requestSaveTicket(): Unable to lock file '" << mFileName << "'" << endl; return 0; } return createTicket( this ); } bool ResourceFile::doOpen() { QFile file( mFileName ); if ( !file.exists() ) { // try to create the file bool ok = file.open( IO_WriteOnly ); if ( ok ) file.close(); return ok; } else { if ( !file.open( IO_ReadWrite ) ) return false; if ( file.size() == 0 ) { file.close(); return true; } bool ok = mFormat->checkFormat( &file ); file.close(); return ok; } } void ResourceFile::doClose() { } bool ResourceFile::load() { QFile file( mFileName ); if ( !file.open( IO_ReadOnly ) ) { addressBook()->error( i18n( "Unable to open file '%1'." ).arg( mFileName ) ); return false; } // qDebug("ResourceFile::load format %s, %s", mFileName.latin1(), mFormatName.latin1()); return mFormat->loadAll( addressBook(), this, &file ); } bool ResourceFile::save( Ticket *ticket ) { // qDebug("ResourceFile::save format %s, %s", mFileName.latin1(), mFormatName.latin1()); // create backup file QString extension = "_" + QString::number( QDate::currentDate().dayOfWeek() ); /*US we use a simpler method to create a backupfile (void) KSaveFile::backupFile( mFileName, QString::null ,extension ); KSaveFile saveFile( mFileName ); bool ok = false; if ( saveFile.status() == 0 && saveFile.file() ) { mFormat->saveAll( addressBook(), this, saveFile.file() ); ok = saveFile.close(); } */ //US ToDo: write backupfile QFile info; info.setName( mFileName ); bool ok = info.open( IO_WriteOnly ); if ( ok ) { mFormat->saveAll( addressBook(), this, &info ); info.close(); ok = true; } else { } if ( !ok ) addressBook()->error( i18n( "Unable to save file '%1'." ).arg( mFileName ) ); delete ticket; unlock( mFileName ); return ok; qDebug("ResourceFile::save has to be changed"); return true; } bool ResourceFile::lock( const QString &fileName ) { QString fn = fileName; //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp("/"), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); if (QFile::exists( lockName )) return false; QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceFile::unlock( const QString &fileName ) { QString fn = fileName; //US change the implementation how the lockfilename is getting created //US fn.replace( QRegExp( "/" ), "_" ); //US QString lockName = locateLocal( "data", "kabc/lock/" + fn + ".lock" ); //US QString lockName = fn + ".lock"; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceFile::setFileName( const QString &fileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( mFileName ); mFileName = fileName; mDirWatch.addFile( mFileName ); mDirWatch.startScan(); //US simulate KDirWatch event //US fileChanged(); } QString ResourceFile::fileName() const { return mFileName; } void ResourceFile::setFormat( const QString &format ) { mFormatName = format; delete mFormat; FormatFactory *factory = FormatFactory::self(); mFormat = factory->format( mFormatName ); /*US //qDebug("ResourceFile::setFormat initialized with format %s ", format.latin1()); if (mFormatName == "vcard") { mFormat = new VCardFormatPlugin2(); // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); } else if (mFormatName == "binary") { mFormat = new BinaryFormat(); // qDebug("ResourceFile::setFormat format %s", mFormatName.latin1()); } else qDebug("ResourceFile::setFormat format unknown !!! %s ", format.latin1()); */ } QString ResourceFile::format() const { return mFormatName; } void ResourceFile::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; QString text( i18n( "File resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( mFileName ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceFile::removeAddressee( const Addressee &addr ) { QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/photos/" ) + addr.uid() ) ); QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/logos/" ) + addr.uid() ) ); QFile::remove( QFile::encodeName( locateLocal( "data", "kabc/sounds/" ) + addr.uid() ) ); } void ResourceFile::cleanUp() { unlock( mFileName ); } //US #include "resourcefile.moc" diff --git a/kabc/plugins/ldap/resourceldap.cpp b/kabc/plugins/ldap/resourceldap.cpp index 198e80a..17f115d 100644 --- a/kabc/plugins/ldap/resourceldap.cpp +++ b/kabc/plugins/ldap/resourceldap.cpp @@ -1,432 +1,432 @@ /* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <kdebug.h> #include <kglobal.h> #include <klineedit.h> #include <klocale.h> #include <kconfig.h> #include <kstringhandler.h> #include <stdlib.h> #include "resourceldap.h" #include "resourceldapconfig.h" #include "syncprefwidget.h" using namespace KABC; extern "C" { //US void *init_kabc_ldap() void *init_microkabc_ldap() { - return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidget>(); + return new KRES::PluginFactory<ResourceLDAP,ResourceLDAPConfig, SyncPrefWidgetContainer>(); } } void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ); ResourceLDAP::ResourceLDAP( const KConfig *config, bool syncable ) : Resource( config, syncable ), mPort( 389 ), mLdap( 0 ) { KConfig *cfg = (KConfig *)config; if ( cfg ) { mUser = cfg->readEntry( "LdapUser" ); mPassword = KStringHandler::obscure( cfg->readEntry( "LdapPassword" ) ); mDn = cfg->readEntry( "LdapDn" ); mHost = cfg->readEntry( "LdapHost" ); mPort = cfg->readNumEntry( "LdapPort", 389 ); mFilter = cfg->readEntry( "LdapFilter" ); mAnonymous = cfg->readBoolEntry( "LdapAnonymous" ); QStringList attributes = cfg->readListEntry( "LdapAttributes" ); for ( uint pos = 0; pos < attributes.count(); pos += 2 ) mAttributes.insert( attributes[ pos ], attributes[ pos + 1 ] ); } /** 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 from */ if ( mAttributes.count() == 0 ) { mAttributes.insert( "commonName", "cn" ); mAttributes.insert( "formattedName", "displayName" ); mAttributes.insert( "familyName", "sn" ); mAttributes.insert( "givenName", "givenName" ); mAttributes.insert( "mail", "mail" ); mAttributes.insert( "mailAlias", "" ); mAttributes.insert( "phoneNumber", "telephoneNumber" ); mAttributes.insert( "uid", "uid" ); } } void ResourceLDAP::writeConfig( KConfig *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 ); QStringList attributes; QMap<QString, QString>::Iterator it; for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) attributes << it.key() << it.data(); config->writeEntry( "LdapAttributes", attributes ); } Ticket *ResourceLDAP::requestSaveTicket() { if ( !addressBook() ) { kdDebug(5700) << "no addressbook" << endl; return 0; } return createTicket( this ); } bool ResourceLDAP::doOpen() { if ( mLdap ) return false; if ( !mPort ) mPort = 389; mLdap = ldap_init( mHost.local8Bit(), mPort ); if ( !mLdap ) { addressBook()->error( i18n( "Unable to connect to server '%1' on port '%2'" ).arg( mHost ).arg( mPort ) ); return false; } if ( !mUser.isEmpty() && !mAnonymous ) { if ( ldap_simple_bind_s( mLdap, mUser.local8Bit(), mPassword.local8Bit() ) != LDAP_SUCCESS ) { addressBook()->error( i18n( "Unable to bind to server '%1'" ).arg( mHost ) ); return false; } kdDebug(5700) << "ResourceLDAP: bind to server successfully" << endl; } else { if ( ldap_simple_bind_s( mLdap, NULL, NULL ) != LDAP_SUCCESS ) { addressBook()->error( i18n( "Unable to bind anonymously to server '%1'" ).arg( mHost ) ); return false; } kdDebug( 5700 ) << "ResourceLDAP: bind anonymously to server successfully" << endl; } int deref = LDAP_DEREF_ALWAYS; if ( ldap_set_option( mLdap, LDAP_OPT_DEREF, (void *) &deref ) != LDAP_OPT_SUCCESS ) { kdDebug(5700) << "ResourceLDAP: can't set 'deref' option" << endl; return false; } if ( ldap_set_option( mLdap, LDAP_OPT_REFERRALS, LDAP_OPT_ON ) != LDAP_OPT_SUCCESS ) { kdDebug(5700) << "ResourceLDAP: can't set 'referrals' option" << endl; return false; } return true; } void ResourceLDAP::doClose() { if ( ldap_unbind_s( mLdap ) != LDAP_SUCCESS ) { kdDebug(5700) << "ResourceLDAP: can't unbind from server" << endl; return; } mLdap = 0; } bool ResourceLDAP::load() { LDAPMessage *res; LDAPMessage *msg; BerElement *track; char *names; char **values; char **LdapSearchAttr = new char*[ mAttributes.count() + 1 ]; QMap<QString, QString>::Iterator it; int i = 0; for ( it = mAttributes.begin(); it != mAttributes.end(); ++it ) { if ( !it.data().isEmpty() ) { unsigned int len = it.data().utf8().length(); LdapSearchAttr[ i ] = new char[ len+1 ]; memcpy( LdapSearchAttr[ i ], it.data().utf8(), len ); LdapSearchAttr[ i ][ len ] = 0; ++i; } } LdapSearchAttr[ i ] = 0; QString filter = mFilter; if ( filter.isEmpty() ) filter = "cn=*"; int result; if ( ( result = ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, QString( "(%1)" ).arg( filter ).local8Bit(), LdapSearchAttr, 0, &res ) != LDAP_SUCCESS ) ) { addressBook()->error( i18n( "Unable to search on server '%1': %2" ) .arg( mHost ) .arg( ldap_err2string( result ) ) ); for ( i = 0; LdapSearchAttr[ i ]; ++i ) delete [] LdapSearchAttr[ i ]; delete [] LdapSearchAttr; return false; } for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { Addressee addr; addr.setResource( this ); for ( names = ldap_first_attribute( mLdap, msg, &track ); names; names = ldap_next_attribute( mLdap, msg, track ) ) { values = ldap_get_values( mLdap, msg, names ); for ( int i = 0; i < ldap_count_values( values ); ++i ) { QString name = QString::fromUtf8( names ).lower(); QString value = QString::fromUtf8( values[ i ] ); if ( name == mAttributes[ "commonName" ].lower() ) { if ( !addr.formattedName().isEmpty() ) { QString fn = addr.formattedName(); addr.setNameFromString( value ); addr.setFormattedName( fn ); } else addr.setNameFromString( value ); } else if ( name == mAttributes[ "formattedName" ].lower() ) { addr.setFormattedName( value ); } else if ( name == mAttributes[ "givenName" ].lower() ) { addr.setGivenName( value ); } else if ( name == mAttributes[ "mail" ].lower() ) { addr.insertEmail( value, true ); } else if ( name == mAttributes[ "mailAlias" ].lower() ) { addr.insertEmail( value, false ); } else if ( name == mAttributes[ "phoneNumber" ].lower() ) { PhoneNumber phone; phone.setNumber( value ); addr.insertPhoneNumber( phone ); break; // read only the home number } else if ( name == mAttributes[ "familyName" ].lower() ) { addr.setFamilyName( value ); } else if ( name == mAttributes[ "uid" ].lower() ) { addr.setUid( value ); } } ldap_value_free( values ); } ber_free( track, 0 ); addressBook()->insertAddressee( addr ); } ldap_msgfree( res ); for ( i = 0; LdapSearchAttr[ i ]; ++i ) delete [] LdapSearchAttr[ i ]; delete [] LdapSearchAttr; return true; } bool ResourceLDAP::save( Ticket * ) { AddressBook::Iterator it; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { if ( (*it).resource() == this && (*it).changed() ) { LDAPMod **mods = NULL; addModOp( &mods, "objectClass", "organizationalPerson" ); addModOp( &mods, "objectClass", "person" ); addModOp( &mods, "objectClass", "Top" ); addModOp( &mods, mAttributes[ "commonName" ].utf8(), (*it).assembledName() ); addModOp( &mods, mAttributes[ "formattedName" ].utf8(), (*it).formattedName() ); addModOp( &mods, mAttributes[ "givenName" ].utf8(), (*it).givenName() ); addModOp( &mods, mAttributes[ "familyName" ].utf8(), (*it).familyName() ); addModOp( &mods, mAttributes[ "uid" ].utf8(), (*it).uid() ); QStringList emails = (*it).emails(); QStringList::ConstIterator mailIt; bool first = true; for ( mailIt = emails.begin(); mailIt != emails.end(); ++mailIt ) { if ( first ) { addModOp( &mods, mAttributes[ "mail" ].utf8(), (*mailIt) ); first = false; } else addModOp( &mods, mAttributes[ "mailAlias" ].utf8(), (*mailIt) ); } PhoneNumber number = (*it).phoneNumber( PhoneNumber::Home ); addModOp( &mods, mAttributes[ "phoneNumber" ].utf8(), number.number() ); QString dn = "cn=" + (*it).assembledName() + "," + mDn; int retval; if ( (retval = ldap_add_s( mLdap, dn.local8Bit(), mods )) != LDAP_SUCCESS ) addressBook()->error( i18n( "Unable to modify '%1' on server '%2'" ).arg( (*it).uid() ).arg( mHost ) ); ldap_mods_free( mods, 1 ); // mark as unchanged (*it).setChanged( false ); } } return true; } void ResourceLDAP::removeAddressee( const Addressee &addr ) { LDAPMessage *res; LDAPMessage *msg; QString filter = QString( "(&(uid=%1)(%2))" ).arg( addr.uid() ).arg( mFilter ); kdDebug(5700) << "ldap:removeAddressee" << filter << endl; ldap_search_s( mLdap, mDn.local8Bit(), LDAP_SCOPE_SUBTREE, filter.local8Bit(), 0, 0, &res ); for ( msg = ldap_first_entry( mLdap, res ); msg; msg = ldap_next_entry( mLdap, msg ) ) { char *dn = ldap_get_dn( mLdap, msg ); kdDebug(5700) << "found " << dn << endl; if ( ldap_delete_s( mLdap, dn ) != LDAP_SUCCESS ) addressBook()->error( i18n( "Unable to delete '%1' on server '%2'" ).arg( dn ).arg( mHost ) ); ldap_memfree( dn ); } ldap_msgfree( res ); } void ResourceLDAP::setUser( const QString &user ) { mUser = user; } QString ResourceLDAP::user() const { return mUser; } void ResourceLDAP::setPassword( const QString &password ) { mPassword = password; } QString ResourceLDAP::password() const { return mPassword; } void ResourceLDAP::setDn( const QString &dn ) { mDn = dn; } QString ResourceLDAP::dn() const { return mDn; } void ResourceLDAP::setHost( const QString &host ) { mHost = host; } QString ResourceLDAP::host() const { return mHost; } void ResourceLDAP::setPort( int port ) { mPort = port; } int ResourceLDAP::port() const { return mPort; } void ResourceLDAP::setFilter( const QString &filter ) { mFilter = filter; } QString ResourceLDAP::filter() const { return mFilter; } void ResourceLDAP::setIsAnonymous( bool value ) { mAnonymous = value; } bool ResourceLDAP::isAnonymous() const { return mAnonymous; } void ResourceLDAP::setAttributes( const QMap<QString, QString> &attributes ) { mAttributes = attributes; } QMap<QString, QString> ResourceLDAP::attributes() const { return mAttributes; } void addModOp( LDAPMod ***pmods, const QString &attr, const QString &value ) { if ( value.isNull() ) return; LDAPMod **mods; mods = *pmods; uint i = 0; if ( mods != 0 ) for ( ; mods[ i ] != 0; ++i ); if (( mods = (LDAPMod **)realloc( mods, (i + 2) * sizeof( LDAPMod * ))) == 0 ) { kdError() << "ResourceLDAP: realloc" << endl; return; } diff --git a/kabc/plugins/opie/resourceopie.cpp b/kabc/plugins/opie/resourceopie.cpp index 9dfd473..4b811e9 100644 --- a/kabc/plugins/opie/resourceopie.cpp +++ b/kabc/plugins/opie/resourceopie.cpp @@ -1,348 +1,348 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> //US #include "formatfactory.h" //US #include <qpe/qpeapplication.h> #include <opie/ocontactaccess.h> #include <opie/ocontactaccessbackend_xml.h> #include "resourceopieconfig.h" #include "stdaddressbook.h" #include "syncprefwidget.h" #include "opieconverter.h" #include "resourceopie.h" using namespace KABC; extern "C" { void *init_microkabc_opie() { - return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidget>(); + return new KRES::PluginFactory<ResourceOpie,ResourceOpieConfig, SyncPrefWidgetContainer>(); } } ResourceOpie::ResourceOpie( const KConfig *config, bool syncable ) : Resource( config, syncable ), mAccess(0), mConverter (0) { QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; KConfig *cfg = (KConfig *)config; if ( cfg ) { fileName = cfg->readEntry( "FileName", fileName ); } init( fileName ); } ResourceOpie::ResourceOpie( const QString &fileName, bool syncable ) : Resource( 0, syncable ) { init( fileName ); } void ResourceOpie::init( const QString &fileName ) { qDebug("ResourceOpie::init()"); connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); setFileName( fileName ); } ResourceOpie::~ResourceOpie() { if (mConverter != 0) delete mConverter; if(mAccess != 0) delete mAccess; } void ResourceOpie::writeConfig( KConfig *config ) { Resource::writeConfig( config ); config->writeEntry( "FileName", fileName() ); } Ticket *ResourceOpie::requestSaveTicket() { kdDebug(5700) << "ResourceOpie::requestSaveTicket()" << endl; qDebug("ResourceOpie::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceOpie::requestSaveTicket(): Unable to lock file '" << fileName() << "'" << endl; return 0; } return createTicket( this ); } bool ResourceOpie::doOpen() { qDebug("ResourceOpie::doOpen: %s", fileName().latin1()); OContactAccessBackend_XML* backend = new OContactAccessBackend_XML( "KDEPim/Pi", fileName() ); mAccess = new OContactAccess("KDEPim/Pi", 0l, backend, false); if ( !mAccess ) { qDebug("Unable to load file() %s", fileName().latin1()); return false; } mAccess->setReadAhead( 32 ); // Use ReadAhead-Cache if available if (mConverter == 0) { mConverter = new OpieConverter(); bool res = mConverter->init(); if ( !res ) { qDebug("Unable to initialize opie converter. Most likely a problem with the category file"); delete mAccess; mAccess = 0; return false; } } return true; } void ResourceOpie::doClose() { qDebug("ResourceOpie::doClose: %s", fileName().latin1()); if(mAccess) { delete mAccess; mAccess = 0; } // it seems so, that deletion of access deletes backend as well //delete backend; return; } bool ResourceOpie::load() { qDebug("ResourceOpie::load: %s", fileName().latin1()); bool res = false; OContactAccess::List::Iterator it; OContactAccess::List allList = mAccess->allRecords(); for ( it = allList.begin(); it != allList.end(); ++it ) { const OContact c = (*it); KABC::Addressee addressee; res = mConverter->opieToAddressee( c, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } bool ResourceOpie::save( Ticket *ticket ) { qDebug("ResourceOpie::save: %s", fileName().latin1()); KABC::AddressBook::Iterator it; bool res; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { OContact c; KABC::Addressee addressee = (*it); res = mConverter->addresseeToOpie( *it, c ); if (res == true) { res = mAccess->add(c); if (res == false) qDebug("Unable to append Contact %s", c.fullName().latin1()); } else { qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } mAccess->save(); delete ticket; unlock( fileName() ); return true; } bool ResourceOpie::lock( const QString &lockfileName ) { qDebug("ResourceOpie::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceOpie::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceOpie::unlock( const QString &fileName ) { qDebug("ResourceOpie::unlock() %s", fileName.latin1()); QString fn = fileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceOpie::setFileName( const QString &newFileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( fileName() ); Resource::setFileName( newFileName ); mDirWatch.addFile( fileName() ); mDirWatch.startScan(); } void ResourceOpie::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; QString text( i18n( "Opie resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } load(); addressBook()->emitAddressBookChanged(); } void ResourceOpie::removeAddressee( const Addressee &addr ) { } void ResourceOpie::cleanUp() { // qDebug("ResourceOpie::cleanup() %s", mFileName.latin1()); unlock( fileName() ); } //US #include "resourceopie.moc" diff --git a/kabc/plugins/qtopia/resourceqtopia.cpp b/kabc/plugins/qtopia/resourceqtopia.cpp index 5565580..93a4d33 100644 --- a/kabc/plugins/qtopia/resourceqtopia.cpp +++ b/kabc/plugins/qtopia/resourceqtopia.cpp @@ -1,319 +1,319 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> //US #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include <qpe/pim/addressbookaccess.h> #include "resourceqtopiaconfig.h" #include "stdaddressbook.h" #include "qtopiaconverter.h" #include "syncprefwidget.h" #include "resourceqtopia.h" using namespace KABC; extern "C" { void *init_microkabc_qtopia() { - return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidget>(); + return new KRES::PluginFactory<ResourceQtopia,ResourceQtopiaConfig, SyncPrefWidgetContainer>(); } } ResourceQtopia::ResourceQtopia( const KConfig *config, bool syncable ) : Resource( config, syncable ), mConverter (0) { // we can not choose the filename. Therefore use the default to display QString fileName = QDir::homeDirPath() + "/Applications/addressbook/addressbook.xml"; init( fileName ); } ResourceQtopia::ResourceQtopia( const QString &fileName, bool syncable ) : Resource( 0, syncable ) { init( fileName ); } void ResourceQtopia::init( const QString &fileName ) { connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); setFileName( fileName ); } ResourceQtopia::~ResourceQtopia() { if (mConverter != 0) delete mConverter; if(mAccess != 0) delete mAccess; } void ResourceQtopia::writeConfig( KConfig *config ) { Resource::writeConfig( config ); } Ticket *ResourceQtopia::requestSaveTicket() { kdDebug(5700) << "ResourceQtopia::requestSaveTicket()" << endl; qDebug("ResourceQtopia::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceQtopia::requestSaveTicket(): Unable to lock file '" << fileName() << "'" << endl; return 0; } return createTicket( this ); } bool ResourceQtopia::doOpen() { qDebug("ResourceQtopia::doOpen(): %s", fileName().latin1()); mAccess = new AddressBookAccess(); if ( !mAccess ) { qDebug("Unable to load file() %s", fileName().latin1()); return false; } if (mConverter == 0) { mConverter = new QtopiaConverter(); bool res = mConverter->init(); if ( !res ) { QString msg("Unable to initialize qtopia converter. Most likely a problem with the category file"); qDebug(msg); delete mAccess; mAccess = 0; return false; } } return true; } void ResourceQtopia::doClose() { qDebug("ResourceQtopia::doClose: %s", fileName().latin1()); if(mAccess) { delete mAccess; mAccess = 0; } // it seems so, that deletion of access deletes backend as well //delete backend; return; } bool ResourceQtopia::load() { qDebug("ResourceQtopia::load: %s", fileName().latin1()); AddressBookIterator it(*mAccess); const PimContact* contact; bool res; for (contact=it.toFirst(); it.current(); ++it) { contact = it.current(); KABC::Addressee addressee; res = mConverter->qtopiaToAddressee( (*contact), addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } bool ResourceQtopia::save( Ticket *ticket ) { qDebug("ResourceQtopia::save: %s", fileName().latin1()); KABC::AddressBook::Iterator it; bool res; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { PimContact c; KABC::Addressee addressee = (*it); res = mConverter->addresseeToQtopia( *it, c ); if (res == true) { mAccess->addContact(c); // if (res == false) // qDebug("Unable to append Contact %s", c.fullName().latin1()); } else { qDebug("Unable to convert Addressee %s", addressee.formattedName().latin1()); } } // mAccess->addressBookUpdated(); delete ticket; unlock( fileName() ); return true; } bool ResourceQtopia::lock( const QString &lockfileName ) { qDebug("ResourceQtopia::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceQtopia::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceOpie::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName().latin1()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceQtopia::unlock( const QString &fileName ) { qDebug("ResourceQtopia::unlock() %s", fileName.latin1()); QString fn = fileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceQtopia::setFileName( const QString &newFileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( fileName() ); Resource::setFileName( newFileName ); mDirWatch.addFile( fileName() ); mDirWatch.startScan(); } void ResourceQtopia::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; QString text( i18n( "Qtopia resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceQtopia::removeAddressee( const Addressee &addr ) { } void ResourceQtopia::cleanUp() { unlock( fileName() ); } //US #include "resourceqtopia.moc" diff --git a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp index 70c3718..b63df0c 100644 --- a/kabc/plugins/sharpdtm/resourcesharpdtm.cpp +++ b/kabc/plugins/sharpdtm/resourcesharpdtm.cpp @@ -1,337 +1,337 @@ /* This file is part of libkabc. Copyright (c) 2004 Ulf Schenk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <qdir.h> #include <qfile.h> #include <qfileinfo.h> #include <qregexp.h> //US #include <qtimer.h> #include <kapplication.h> #include <kconfig.h> #include <kdebug.h> #include <klocale.h> //US #include <ksavefile.h> #include <kstandarddirs.h> #include <kmessagebox.h> #include <sl/slzdb.h> #include "resourcesharpdtmconfig.h" #include "resourcesharpdtm.h" #include "syncprefwidget.h" #include "stdaddressbook.h" #include "sharpdtmconverter.h" using namespace KABC; extern "C" { void *init_microkabc_sharpdtm() { - return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidget>(); + return new KRES::PluginFactory<ResourceSharpDTM,ResourceSharpDTMConfig,SyncPrefWidgetContainer>(); } } ResourceSharpDTM::ResourceSharpDTM( const KConfig *config, bool syncable ) : Resource( config, syncable ), mConverter (0) { // we can not choose the filename. Therefore use the default to display QString fileName = SlZDataBase::addressbookFileName(); init( fileName ); } ResourceSharpDTM::ResourceSharpDTM( const QString &fileName, bool syncable ) : Resource( 0, syncable ) { init( fileName ); } void ResourceSharpDTM::init( const QString &fileName ) { connect( &mDirWatch, SIGNAL( dirty(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( created(const QString&) ), SLOT( fileChanged() ) ); connect( &mDirWatch, SIGNAL( deleted(const QString&) ), SLOT( fileChanged() ) ); setFileName( fileName ); } ResourceSharpDTM::~ResourceSharpDTM() { if (mConverter != 0) delete mConverter; if(mAccess != 0) delete mAccess; } void ResourceSharpDTM::writeConfig( KConfig *config ) { Resource::writeConfig( config ); } Ticket *ResourceSharpDTM::requestSaveTicket() { kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket()" << endl; qDebug("ResourceSharpDTM::requestSaveTicket: %s", fileName().latin1()); if ( !addressBook() ) return 0; if ( !lock( fileName() ) ) { kdDebug(5700) << "ResourceSharpDTM::requestSaveTicket(): Unable to lock file '" << fileName() << "'" << endl; return 0; } return createTicket( this ); } bool ResourceSharpDTM::doOpen() { qDebug("ResourceSharpDTM::doOpen: %s", fileName().latin1()); // the last parameter in the SlZDataBase constructor means "readonly" mAccess = new SlZDataBase(fileName(), SlZDataBase::addressbookItems(), NULL, true); if ( !mAccess ) { qDebug("Unable to load file() %s", fileName().latin1()); return false; } if (mConverter == 0) { mConverter = new SharpDTMConverter(); bool res = mConverter->init(); if ( !res ) { QString msg("Unable to initialize sharp converter. Most likely a problem with the category file"); qDebug(msg); delete mAccess; mAccess = 0; return false; } } return true; } void ResourceSharpDTM::doClose() { qDebug("ResourceSharpDTM::doClose: %s", fileName().latin1()); if(mAccess) { delete mAccess; mAccess = 0; } // it seems so, that deletion of access deletes backend as well //delete backend; return; } bool ResourceSharpDTM::load() { qDebug("ResourceSharpDTM::load: %s", fileName().latin1()); bool res = false; CardId id; for (bool res=mAccess->first(); res == true; res=mAccess->next()) { id = mAccess->cardId(); KABC::Addressee addressee; res = mConverter->sharpToAddressee( id, mAccess, addressee ); if ( !addressee.isEmpty() && res ) { addressee.setResource( this ); addressBook()->insertAddressee( addressee ); } } return true; } bool ResourceSharpDTM::save( Ticket *ticket ) { qDebug("ResourceSharpDTM::save: %s", fileName().latin1()); KABC::AddressBook::Iterator it; bool res; for ( it = addressBook()->begin(); it != addressBook()->end(); ++it ) { CardId id = 0; // 0 means new card KABC::Addressee addressee = (*it); res = mAccess->startEditCard(id); if (res == true) { res = mConverter->addresseeToSharp( *it, mAccess, id ); if (res == true) { res = mAccess->finishEditCard(&id); if (res == false) qDebug("Unable to append Contact: %s", addressee.formattedName().latin1()); } else { qDebug("Unable to convert Addressee: %s", addressee.formattedName().latin1()); mAccess->cancelEditCard(); } } else { qDebug("Unable to add new card. Addressee: %s", addressee.formattedName().latin1()); } } //US mAccess->save(); delete ticket; unlock( fileName() ); return true; } bool ResourceSharpDTM::lock( const QString &lockfileName ) { qDebug("ResourceSharpDTM::lock: %s", fileName().latin1()); kdDebug(5700) << "ResourceSharpDTM::lock()" << endl; QString fn = lockfileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); kdDebug(5700) << "-- lock name: " << lockName << endl; if (QFile::exists( lockName )) { qDebug("ResourceSharpDTM::lock: lockfile %s already exists. (Delete it before continuing if nobody else is accessing the resourcefile %s)", lockName.latin1(), fileName()); return false; } QString lockUniqueName; lockUniqueName = fn + KApplication::randomString( 8 ); url = lockUniqueName; //US mLockUniqueName = locateLocal( "data", "kabc/lock/" + lockUniqueName ); mLockUniqueName = locateLocal( "data", "kabc/lock/" + url.fileName() ); kdDebug(5700) << "-- lock unique name: " << mLockUniqueName << endl; // Create unique file QFile file( mLockUniqueName ); file.open( IO_WriteOnly ); file.close(); // Create lock file int result = 0; #ifndef _WIN32_ result = ::link( QFile::encodeName( mLockUniqueName ), QFile::encodeName( lockName ) ); #endif if ( result == 0 ) { addressBook()->emitAddressBookLocked(); return true; } // TODO: check stat return false; } void ResourceSharpDTM::unlock( const QString &fileName ) { qDebug("ResourceSharpDTM::unlock() %s", fileName.latin1()); QString fn = fileName; KURL url(fn); QString lockName = locateLocal( "data", "kabc/lock/" + url.fileName() + ".lock" ); QFile::remove( lockName ); QFile::remove( mLockUniqueName ); addressBook()->emitAddressBookUnlocked(); } void ResourceSharpDTM::setFileName( const QString &newFileName ) { mDirWatch.stopScan(); mDirWatch.removeFile( fileName() ); Resource::setFileName( newFileName ); mDirWatch.addFile( fileName() ); mDirWatch.startScan(); } void ResourceSharpDTM::fileChanged() { // There is a small theoretical chance that KDirWatch calls us before // we are fully constructed if (!addressBook()) return; QString text( i18n( "Sharp DTM resource '%1'<br> has been changed by third party.<br>Do you want to reload?").arg( fileName() ) ); if ( readOnly() || KMessageBox::questionYesNo( 0, text ) == KMessageBox::Yes ) { load(); addressBook()->emitAddressBookChanged(); } } void ResourceSharpDTM::removeAddressee( const Addressee &addr ) { } void ResourceSharpDTM::cleanUp() { unlock( fileName() ); } diff --git a/kabc/resource.cpp b/kabc/resource.cpp index 2f03927..d39fd6a 100644 --- a/kabc/resource.cpp +++ b/kabc/resource.cpp @@ -1,139 +1,144 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <kdebug.h> #include <ksyncprofile.h> #include "resource.h" using namespace KABC; Resource::Resource( const KConfig *config, bool syncable ) : KRES::Resource( config ), mAddressBook( 0 ), mSyncProfile( 0 ) { if(syncable == true) { mSyncProfile = new KSyncProfile( identifier() ); mSyncProfile->setName(resourceName()); mSyncProfile->readConfig( (KConfig *)config ); } } Resource::~Resource() { if (mSyncProfile != 0) { delete mSyncProfile; } } void Resource::writeConfig( KConfig *config ) { KRES::Resource::writeConfig( config ); if(mSyncProfile != 0) mSyncProfile->writeConfig( config ); } void Resource::setAddressBook( AddressBook *ab ) { mAddressBook = ab; } AddressBook *Resource::addressBook() { return mAddressBook; } bool Resource::doOpen() { return true; } void Resource::doClose() { } Ticket *Resource::requestSaveTicket() { return 0; } bool Resource::load() { return true; } bool Resource::save( Ticket * ) { return false; } Ticket *Resource::createTicket( Resource *resource ) { return new Ticket( resource ); } void Resource::removeAddressee( const Addressee& ) { // do nothing } void Resource::cleanUp() { // do nothing } bool Resource::isSyncable() const { return (mSyncProfile != 0); } +KSyncProfile* Resource::getSyncProfile() +{ + return mSyncProfile; +} + QString Resource::fileName() const { return mFileName; } void Resource::setFileName( const QString &fileName ) { mFileName = fileName; } /** * Set the name of resource.You can override this method, * but also remember to call Resource::setResourceName(). */ void Resource::setResourceName( const QString &name ) { KRES::Resource::setResourceName(name); if(mSyncProfile != 0) { mSyncProfile->setName( name ); } } diff --git a/kabc/resource.h b/kabc/resource.h index 7d42f81..2024d2d 100644 --- a/kabc/resource.h +++ b/kabc/resource.h @@ -1,169 +1,171 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #ifndef KABC_RESOURCE_H #define KABC_RESOURCE_H #include <kresources/resource.h> #include "addressbook.h" class KSyncProfile; namespace KABC { /** * @short Helper class for handling coordinated save of address books. * * This class is used as helper class for saving address book. * @see requestSaveTicket(), save(). */ class Ticket { friend class Resource; public: Resource *resource() { return mResource; } private: Ticket( Resource *resource ) : mResource( resource ) {} Resource *mResource; }; /** * @internal */ class Resource : public KRES::Resource { private: /** * make this constructor private to force everybody to use the other one */ Resource( const KConfig *config); public: /** * Constructor */ Resource( const KConfig *config, bool syncable ); /** * Destructor. */ virtual ~Resource(); /** * Sets the address book of the resource. */ void setAddressBook( AddressBook* ); /** * Returns a pointer to the addressbook. */ AddressBook *addressBook(); /** * Writes the resource specific config to file. */ virtual void writeConfig( KConfig *config ); /** * Open the resource and returns if it was successfully */ virtual bool doOpen(); /** * Request a ticket, you have to pass through @ref save() to * allow locking. */ virtual Ticket *requestSaveTicket(); /** * Load all addressees to the addressbook */ virtual bool load(); /** * Save all addressees to the addressbook. * * @param ticket The ticket you get by @ref requestSaveTicket() */ virtual bool save( Ticket *ticket ); /** * Removes a addressee from resource. This method is mainly * used by record-based resources like LDAP or SQL. */ virtual void removeAddressee( const Addressee& addr ); /** * This method is called by an error handler if the application * crashed */ virtual void cleanUp(); /** * Set name of file to be used for saving. */ virtual void setFileName( const QString & ); /** * Return name of file used for loading and saving the address book. */ virtual QString fileName() const; virtual bool isSyncable() const; + virtual KSyncProfile* getSyncProfile(); + /** * Set the name of resource.You can override this method, * but also remember to call Resource::setResourceName(). */ virtual void setResourceName( const QString &name ); protected: Ticket *createTicket( Resource * ); virtual void doClose(); private: AddressBook *mAddressBook; KSyncProfile *mSyncProfile; QString mFileName; }; } #endif diff --git a/kabc/stdaddressbook.cpp b/kabc/stdaddressbook.cpp index 1e00cc6..760820e 100644 --- a/kabc/stdaddressbook.cpp +++ b/kabc/stdaddressbook.cpp @@ -1,228 +1,226 @@ /* This file is part of libkabc. Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* Enhanced Version of the file for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk $Id$ */ #include <qdir.h> #include "resource.h" #include <kresources/manager.h> #include <kdebug.h> #include <klocale.h> #include <kstaticdeleter.h> #include <kstandarddirs.h> #include "stdaddressbook.h" using namespace KABC; StdAddressBook *StdAddressBook::mSelf = 0; bool StdAddressBook::mAutomaticSave = true; static KStaticDeleter<StdAddressBook> addressBookDeleter; QString StdAddressBook::fileName() { return locateLocal( "data", "kabc/std.vcf" ); } QString StdAddressBook::directoryName() { return locateLocal( "data", "kabc/stdvcf" ); } void StdAddressBook::handleCrash() { StdAddressBook::self()->cleanUp(); } StdAddressBook *StdAddressBook::self() { if ( !mSelf ) { QString appdir = StdAddressBook::setTempAppDir(); kdDebug(5700) << "StdAddressBook::self()" << endl; // US im am not sure why I have to use the other format here?? #ifdef KAB_EMBEDDED mSelf = addressBookDeleter.setObject( new StdAddressBook ); #else //KAB_EMBEDDED addressBookDeleter.setObject( mSelf, new StdAddressBook ); #endif //KAB_EMBEDDED KStandardDirs::setAppDir( appdir ); } return mSelf; } QString StdAddressBook::setTempAppDir() { QString appDIR = KStandardDirs::appDir(); #ifdef DESKTOP_VERSION QString appdir = QDir::homeDirPath(); if ( appdir.right(1) == "\\" || appdir.right(1) == "/" ) appdir += "kaddressbook/"; else appdir += "/kaddressbook/"; KStandardDirs::setAppDir( QDir::convertSeparators( appdir )); #else QString appdir = QDir::homeDirPath() + "/kdepim/apps/kaddressbook"; KStandardDirs::setAppDir( appdir ); #endif return appDIR; } StdAddressBook *StdAddressBook::self( bool onlyFastResources ) { if ( !mSelf ) { QString appdir =StdAddressBook::setTempAppDir(); #ifdef KAB_EMBEDDED mSelf = addressBookDeleter.setObject( new StdAddressBook( onlyFastResources ) ); #else //KAB_EMBEDDED addressBookDeleter.setObject( mSelf, new StdAddressBook( onlyFastResources ) ); #endif //KAB_EMBEDDED KStandardDirs::setAppDir( appdir ); } return mSelf; } StdAddressBook::StdAddressBook() -//US : AddressBook( "kabcrc" ) - : AddressBook( locateLocal( "config", "kabcrc") ) + : AddressBook( "kabcrc" ) { init( false ); } StdAddressBook::StdAddressBook( bool onlyFastResources ) -//US : AddressBook( "kabcrc" ) - : AddressBook( locateLocal( "config", "kabcrc") ) + : AddressBook( "kabcrc" ) { init( onlyFastResources ); } StdAddressBook::~StdAddressBook() { if ( mAutomaticSave ) save(); } void StdAddressBook::init( bool ) { KRES::Manager<Resource> *manager = resourceManager(); KRES::Manager<Resource>::ActiveIterator it; for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { (*it)->setAddressBook( this ); if ( !(*it)->open() ) error( QString( "Unable to open resource '%1'!" ).arg( (*it)->resourceName() ) ); } Resource *res = standardResource(); if ( !res ) { res = manager->createResource( "file" ); if ( res ) { addResource( res ); } else qDebug(" No resource available!!!"); } setStandardResource( res ); manager->writeConfig(); load(); } bool StdAddressBook::save() { kdDebug(5700) << "StdAddressBook::save()" << endl; bool ok = true; AddressBook *ab = self(); ab->deleteRemovedAddressees(); KRES::Manager<Resource>::ActiveIterator it; KRES::Manager<Resource> *manager = ab->resourceManager(); for ( it = manager->activeBegin(); it != manager->activeEnd(); ++it ) { if ( !(*it)->readOnly() && (*it)->isOpen() ) { Ticket *ticket = ab->requestSaveTicket( *it ); // qDebug("StdAddressBook::save '%s'", (*it)->resourceName().latin1() ); if ( !ticket ) { ab->error( i18n( "Unable to save to resource '%1'. It is locked." ) .arg( (*it)->resourceName() ) ); return false; } if ( !ab->save( ticket ) ) ok = false; } } return ok; } void StdAddressBook::close() { //US destructObject is not defined on my system???. Is setObject(0) the same ??? //US addressBookDeleter.destructObject(); addressBookDeleter.setObject(0); } void StdAddressBook::setAutomaticSave( bool enable ) { mAutomaticSave = enable; } bool StdAddressBook::automaticSave() { return mAutomaticSave; } // should get const for 4.X Addressee StdAddressBook::whoAmI() { //US KConfig config( "kabcrc" ); KConfig config( locateLocal("config", "kabcrc") ); config.setGroup( "General" ); return findByUid( config.readEntry( "WhoAmI" ) ); } void StdAddressBook::setWhoAmI( const Addressee &addr ) { //US KConfig config( "kabcrc" ); KConfig config( locateLocal("config", "kabcrc") ); config.setGroup( "General" ); config.writeEntry( "WhoAmI", addr.uid() ); } diff --git a/kabc/syncprefwidget.cpp b/kabc/syncprefwidget.cpp index 51a8040..a2bde72 100644 --- a/kabc/syncprefwidget.cpp +++ b/kabc/syncprefwidget.cpp @@ -1,495 +1,410 @@ /* This file is part of KABC for platform independent KDE tools. Copyright (c) 2004 Ulf Schenk This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ /* $Id$ */ -/*US -#include <qlayout.h> -#include <qlabel.h> -#include <qgroupbox.h> -#include <qbuttongroup.h> -#include <qlineedit.h> -#include <qfont.h> -#include <qslider.h> -#include <qfile.h> -#include <qtextstream.h> -#include <qcombobox.h> -#include <qvbox.h> -#include <qhbox.h> -#include <qspinbox.h> -#include <qdatetime.h> -#include <qcheckbox.h> -#include <qradiobutton.h> -#include <qpushbutton.h> -#include <qstrlist.h> -#include <qapplication.h> - -#include <kcolorbutton.h> -#include <kdebug.h> -#include <klocale.h> -#include <kglobal.h> -#include <kfontdialog.h> -#include <kmessagebox.h> -#include <kcolordialog.h> -#include <kiconloader.h> -#include <kemailsettings.h> -#include <kstandarddirs.h> -#include <kfiledialog.h> -#include <kmessagebox.h> - -#include <kurlrequester.h> -#include <klineedit.h> -#include <libkdepim/ksyncprofile.h> - - -#include "koprefs.h" - -#include "kosyncprefsdialog.h" -#include "koglobals.h" -*/ #include <qlayout.h> #include <qbuttongroup.h> #include <qcheckbox.h> #include <qradiobutton.h> #include <qvbox.h> #include <qhbox.h> #include <qlabel.h> #include <qlineedit.h> #include <qpushbutton.h> +#include <qscrollview.h> +#include <qcombobox.h> #include <klocale.h> #include <kdialog.h> - +#include "ksyncprofile.h" +#include "resource.h" #include "syncprefwidget.h" -SyncPrefWidget::SyncPrefWidget(QWidget *parent) : - KRES::SyncWidget(parent) +SyncPrefWidget_Settings::SyncPrefWidget_Settings(QWidget *parent, const char *name) : + KRES::SyncWidget(parent, name) { - -//US setCaption( i18n("Synchronization Preferences")); - -//US mSyncProfiles.setAutoDelete( true ); init(); } -SyncPrefWidget::~SyncPrefWidget() +SyncPrefWidget_Settings::~SyncPrefWidget_Settings() { } -//US #include <qlayout.h> -//US #include <qscrollview.h> -void SyncPrefWidget::init() +void SyncPrefWidget_Settings::init() { - QLabel * lab; - QPushButton* button; - -/*US - //QFrame *page = addPage(i18n("Sync Prefs"),0,0); - QVBox * mainbox = new QVBox( this ); - QScrollView* sv = new QScrollView( mainbox ); - QHBoxLayout * lay = new QHBoxLayout( this ); - lay->addWidget( mainbox ); - QHBox * b_box = new QHBox( mainbox ); -*/ -/*US - QPushButton* button = new QPushButton( i18n("Ok"), b_box ); - connect ( button, SIGNAL( clicked()), this, SLOT (slotOK() ) ); - button = new QPushButton( i18n("Cancel"), b_box ); - connect ( button, SIGNAL( clicked()), this, SLOT (reject() ) ); -*/ - //QBoxLayout * sl = new QVBoxLayout(this ); - //sl->addWidget ( sv ); -/*US - sv->setResizePolicy ( QScrollView::AutoOneFit ); - QFrame *topFrame = new QFrame ( sv ); - sv->addChild( topFrame ); - mSetupSyncAlgTab = topFrame; - QGridLayout *topLayout = new QGridLayout(topFrame,6,2); - topLayout->setSpacing(spacingHint()); - topLayout->setMargin(marginHint()); -*/ -//US new code for the layout QGridLayout *topLayout = new QGridLayout( this, 6,2 ); topLayout->setMargin( KDialog::marginHint() ); topLayout->setSpacing( KDialog::spacingHint() ); - //lab = new QLabel(i18n("Sync settings not yet implemented. DO NOT USE!"), topFrame); int iii = 0; - //topLayout->addMultiCellWidget(lab , iii,iii,0,1); - //++iii; - -/*US - mMyMachineName = new QLineEdit(topFrame); - lab = new QLabel(mMyMachineName, i18n("Local device name:"), topFrame); - topLayout->addWidget(lab ,iii,0); - topLayout->addWidget(mMyMachineName,iii,1); - ++iii; - - QHBox* buttonbox = new QHBox( topFrame); - topLayout->addMultiCellWidget(buttonbox, iii,iii,0,1); - ++iii; - button = new QPushButton( i18n("New profile"), buttonbox ); - connect ( button, SIGNAL( clicked()), this, SLOT (newProfile() ) ); - - button = new QPushButton( i18n("Clone profile"), buttonbox ); - connect ( button, SIGNAL( clicked()), this, SLOT ( cloneProfile() ) ); - - button = new QPushButton( i18n("Delete profile"), buttonbox ); - connect ( button, SIGNAL( clicked()), this, SLOT (deleteProfile() ) ); - - mProfileBox = new QComboBox(topFrame); - mProfileBox->setEditable ( true ); - connect ( mProfileBox, SIGNAL(activated ( int ) ), this, SLOT (profileChanged( int ) ) ); - connect ( mProfileBox, SIGNAL( textChanged ( const QString & ) ), this, SLOT (textChanged( const QString & ) ) ); - - lab = new QLabel(mProfileBox, i18n("Profile:"), topFrame); - topLayout->addWidget(lab ,iii,0); - topLayout->addWidget(mProfileBox, iii,1); - ++iii; -*/ mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), this ); topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1); ++iii; mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), this ); topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1); ++iii; - QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Sync preferences"), this); - topLayout->addMultiCellWidget(gr, iii,iii,0,1); - ++iii; - loc = new QRadioButton ( i18n("Take local entry on conflict"), gr ); - rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr ); - newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr ); - ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr ); - f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr ); - f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr ); - // both = new QRadioButton ( i18n("Take both on conflict"), gr ); mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this ); topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1); ++iii; mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), this ); topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1); ++iii; - mWriteBackFile = new QCheckBox( i18n("Write back file"), this ); + mWriteBackFile = new QCheckBox( i18n("Write back synced data"), this ); topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1); ++iii; - mIsNotLocal = new QCheckBox( i18n("Remote file (w down/upload command)"), this ); - topLayout->addMultiCellWidget(mIsNotLocal, iii,iii,0,1); - connect (mIsNotLocal, SIGNAL( checked(bool)), this, SLOT (kindChanged(bool) ) ); -/*US - proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), this); - gr = proGr; - topLayout->addMultiCellWidget(gr, iii,iii,0,1); - ++iii; - mIsLocal = new QRadioButton ( i18n("Local file"), gr ); - mIsNotLocal = new QRadioButton ( i18n("Remote file (w down/upload command)"), gr ); - connect (mIsLocal, SIGNAL( toggled(bool)), this, SLOT (kindChanged(bool) ) ); -*/ +} -/*US - localFileWidget = new QVBox( topFrame); - topLayout->addMultiCellWidget(localFileWidget, iii,iii,0,1); - ++iii; - QHBox* temphb = new QHBox( localFileWidget ); - lab = new QLabel( i18n("Local file:"), temphb); - mRemoteFile = new QLineEdit(localFileWidget); +void SyncPrefWidget_Settings::loadSettings( KRES::Resource *res ) +{ + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); - button = new QPushButton( i18n("Choose..."), temphb ); - connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) ); -*/ - QHBox* temphb; + if (prof == 0) + { + qDebug("SyncPrefWidget_Settings::loadSettings: something is wrong, because resource does have no syncprofile" ); + return; + } - remoteFileWidget = new QVBox( this); - topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1); - ++iii; - lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget); - mRemotePrecommand = new QLineEdit(remoteFileWidget); + mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); + mAskForPreferences->setChecked( prof->getAskForPreferences()); + mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); + mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); + mWriteBackFile->setChecked( prof->getWriteBackFile()); +} - lab = new QLabel( i18n("Local temp file:"), remoteFileWidget); - mLocalTempFile = new QLineEdit(remoteFileWidget); +void SyncPrefWidget_Settings::saveSettings( KRES::Resource *res ) +{ + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + if (prof == 0) + { + qDebug("SyncPrefWidget_Settings::saveSettings: something is wrong, because resource does have no syncprofile" ); + return; + } - lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); - mRemotePostcommand = new QLineEdit(remoteFileWidget); + prof->setIncludeInRingSync( mIncludeInRing->isChecked() ); + prof->setAskForPreferences( mAskForPreferences->isChecked()); + prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() ); + prof->setWriteBackExisting(mWriteBackExisting->isChecked() ); + prof->setWriteBackFile( mWriteBackFile->isChecked()); +} - lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget); - temphb = new QHBox( remoteFileWidget ); - button = new QPushButton( i18n("ssh/scp"), temphb ); - connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) ); - button = new QPushButton( i18n("ftp"), temphb ); - connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) ); - lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget); +/*********************************************************************** + * + * + **********************************************************************/ -} -/*US -void SyncPrefWidget::slotOK() +SyncPrefWidget_Conflict::SyncPrefWidget_Conflict(QWidget *parent, const char *name) : + KRES::SyncWidget(parent, name) { - if ( mMyMachineName->text() == "undefined" ) { - KMessageBox::error(this,i18n("Local device name undefined!\nPlease define device name!"),i18n("KO/Pi config error")); - return; - } - int i; - for (i = 0; i < mSyncProfileNames.count(); ++ i) { - if ( mSyncProfileNames.contains( mSyncProfileNames[i]) > 1 ) { - KMessageBox::error(this,i18n("Multiple profiles with same name!\nPlease use unique profile names!"),i18n("KO/Pi config error")); - return; - } - } - usrWriteConfig(); - QDialog::accept(); + init(); } -void SyncPrefWidget::accept() + + +SyncPrefWidget_Conflict::~SyncPrefWidget_Conflict() { - slotOK(); } -void KOSyncPrefsDialog::chooseFile() + +void SyncPrefWidget_Conflict::init() { - QString fn =KOPrefs::instance()->mLastSyncedLocalFile; + QGridLayout *topLayout = new QGridLayout( this, 6,2 ); + topLayout->setMargin( KDialog::marginHint() ); + topLayout->setSpacing( KDialog::spacingHint() ); - fn =KFileDialog:: getOpenFileName( fn, i18n("Sync filename(*.ics/*.vcs)"), this ); - if ( fn == "" ) - return; - mRemoteFile->setText( fn ); + int iii = 0; + + QButtonGroup* gr = new QButtonGroup ( 1, Qt::Horizontal, i18n("In case of conflicts"), this); + topLayout->addMultiCellWidget(gr, iii,iii,0,1); + ++iii; + loc = new QRadioButton ( i18n("Take local entry on conflict"), gr ); + rem = new QRadioButton ( i18n("Take remote entry on conflict"), gr ); + newest = new QRadioButton ( i18n("Take newest entry on conflict"), gr ); + ask = new QRadioButton ( i18n("Ask for every entry on conflict"), gr ); + f_loc= new QRadioButton ( i18n("Force: Take local entry always"), gr ); + f_rem = new QRadioButton ( i18n("Force: Take remote entry always"), gr ); + // both = new QRadioButton ( i18n("Take both on conflict"), gr ); } -void KOSyncPrefsDialog::textChanged( const QString & s ) +void SyncPrefWidget_Conflict::loadSettings( KRES::Resource *res ) { - if ( mProfileBox->count() == 0 ) - return; - if ( currentSelection < 3 ) { - //KMessageBox::error(this,i18n("This profil name\ncannot be edited!\n"),i18n("KO/Pi config error")); - mProfileBox->blockSignals( true ); - mProfileBox->setCurrentItem(mProfileBox-> currentItem ()); - mProfileBox->blockSignals( false ); + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + + if (prof == 0) + { + qDebug("SyncPrefWidget_Conflict::loadSettings: something is wrong, because resource does have no syncprofile" ); return; } - //qDebug("cur i %d ",mProfileBox-> currentItem () ); - mProfileBox->changeItem ( s, mProfileBox-> currentItem () ) ; - KSyncProfile* prof = mSyncProfiles.at(mProfileBox-> currentItem ()) ; - prof->setName( s ); - mSyncProfileNames[mProfileBox-> currentItem ()] = s; -} -void KOSyncPrefsDialog::profileChanged( int item ) -{ - //qDebug("KOSyncPrefsDialog::profileChanged %d ", item ); - KSyncProfile* prof; - saveProfile(); - currentSelection = item; - prof = mSyncProfiles.at(item) ; - mRemotePrecommand->setText(prof->getPreSyncCommand()); - mRemotePostcommand->setText(prof->getPostSyncCommand()); - mLocalTempFile->setText(prof->getLocalTempFile()); - mRemoteFile->setText(prof->getRemoteFileName()) ; - mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); - mAskForPreferences->setChecked( prof->getAskForPreferences()); - mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); - mWriteBackFile->setChecked( prof->getWriteBackFile()); - mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); switch ( prof->getSyncPrefs() ) { case 0: loc->setChecked( true); break; case 1: rem->setChecked( true ); break; case 2: newest->setChecked( true); break; case 3: ask->setChecked( true); break; case 4: f_loc->setChecked( true); break; case 5: f_rem->setChecked( true); break; case 6: //both->setChecked( true); break; default: break; } - mIsLocal->setChecked(prof->getIsLocalFileSync()) ; - mIsNotLocal->setChecked(!prof->getIsLocalFileSync()); - proGr->setEnabled( item > 2 ); - if ( item < 3 ) { - localFileWidget->setEnabled(false); - remoteFileWidget->setEnabled(false); - - } else - kindChanged( prof->getIsLocalFileSync() ); } -void KOSyncPrefsDialog::fillSSH() +void SyncPrefWidget_Conflict::saveSettings( KRES::Resource *res ) { - mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); - mLocalTempFile->setText("/tmp/mycalendar.ics" ); - mRemotePostcommand->setText("scp /tmp/mycalendar.ics zaurus@192.168.0.65:/home/zaurus/kdepim/apps/korganizer/mycalendar.ics" ); + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + + if (prof == 0) + { + qDebug("SyncPrefWidget_Conftlict::saveSettings: something is wrong, because resource does have no syncprofile" ); + return; } -void KOSyncPrefsDialog::fillFTP() + + int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ; + prof->setSyncPrefs( syncprefs ); + +} + + +/*********************************************************************** + * + * + **********************************************************************/ + +SyncPrefWidget_Remote::SyncPrefWidget_Remote(QWidget *parent, const char *name) : + KRES::SyncWidget(parent, name) { - mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics" ); - mLocalTempFile->setText("/tmp/mycalendar.ics" ); - mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/apps/korganizer/mycalendar.ics /tmp/mycalendar.ics" ); + init(); +} + +SyncPrefWidget_Remote::~SyncPrefWidget_Remote() +{ } -void KOSyncPrefsDialog::kindChanged( bool b ) + +void SyncPrefWidget_Remote::init() { + QLabel * lab; + QPushButton* button; + + + QGridLayout *topLayout = new QGridLayout( this, 6,2 ); + topLayout->setMargin( KDialog::marginHint() ); + topLayout->setSpacing( KDialog::spacingHint() ); + + int iii = 0; + + QButtonGroup* gr; + + QButtonGroup *proGr = new QButtonGroup ( 1, Qt::Horizontal, i18n("Profile kind"), this); + gr = proGr; + topLayout->addMultiCellWidget(gr, iii,iii,0,1); + ++iii; + mProfileKind = new QComboBox( gr ); + + mProfileKind->insertItem( i18n("Local file"), Local ); + mProfileKind->insertItem( i18n("Remote file (w down/upload cmd)"),Remote ); + mProfileKind->insertItem( i18n("Mobile device (cell phone)"), Mobile ); + + connect( mProfileKind, SIGNAL( activated( int ) ), + this, SLOT (kindChanged( int ) ) ); - localFileWidget->setEnabled(b); - remoteFileWidget->setEnabled(!b); + + QHBox* temphb; + + remoteFileWidget = new QVBox( this); + topLayout->addMultiCellWidget(remoteFileWidget, iii,iii,0,1); + ++iii; + lab = new QLabel( i18n("Pre sync (download) command:"), remoteFileWidget); + mRemotePrecommand = new QLineEdit(remoteFileWidget); + + lab = new QLabel( i18n("Local temp file (=Location):"), remoteFileWidget); + mLocalTempFile = new QLineEdit(remoteFileWidget); + mLocalTempFile->setEnabled(false); + + + lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); + mRemotePostcommand = new QLineEdit(remoteFileWidget); + + lab = new QLabel( i18n("Fill in default values for:"), remoteFileWidget); + temphb = new QHBox( remoteFileWidget ); + button = new QPushButton( i18n("ssh/scp"), temphb ); + connect ( button, SIGNAL( clicked()), this, SLOT (fillSSH() ) ); + button = new QPushButton( i18n("ftp"), temphb ); + connect ( button, SIGNAL( clicked()), this, SLOT (fillFTP() ) ); + lab = new QLabel( i18n("Hint: Use $PWD$ for placeholder of password!"), remoteFileWidget); } -void KOSyncPrefsDialog::deleteProfile() + +void SyncPrefWidget_Remote::loadSettings( KRES::Resource *res ) +{ + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + + if (prof == 0) { - //qDebug("KOSyncPrefsDialog::deleteProfile() "); - if ( currentSelection >= 0 ) { - if ( currentSelection < 3 ) { - KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error")); + qDebug("SyncPrefWidget_Remote::loadSettings: something is wrong, because resource does have no syncprofile" ); return; } - KSyncProfile* temp = mSyncProfiles.at(currentSelection); - mSyncProfiles.remove( temp ); - mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection )); - insertProfiles(); + + int val; + + if (prof->getIsPhoneSync()) + val = Mobile; + else if (!prof->getIsLocalFileSync()) + val = Remote; + else // default value + val = Local; + + mProfileKind->setCurrentItem( val ); + kindChanged( val ); + + + mRemotePrecommand->setText(prof->getPreSyncCommand()); + mLocalTempFile->setText(resource->fileName()); + mRemotePostcommand->setText(prof->getPostSyncCommand()); } + +void SyncPrefWidget_Remote::saveSettings( KRES::Resource *res ) +{ + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + + if (prof == 0) + { + qDebug("SyncPrefWidget_Remote::saveSettings: something is wrong, because resource does have no syncprofile" ); + return; } -void KOSyncPrefsDialog::saveProfile() + int val = mProfileKind->currentItem(); + + if (val == Mobile) + { + prof->setIsLocalFileSync(true); + prof->setIsPhoneSync(true); + } + else if (val == Remote) { - KSyncProfile* prof; - if ( currentSelection >= 0 ) { - prof = mSyncProfiles.at(currentSelection) ; + prof->setIsLocalFileSync(false); + prof->setIsPhoneSync(false); + } + else // default value is Local + { + prof->setIsLocalFileSync(true); + prof->setIsPhoneSync(false); + } + + prof->setPreSyncCommand( mRemotePrecommand->text()); +//US prof->setLocalTempFile( mLocalTempFile->text()); prof->setPostSyncCommand( mRemotePostcommand->text() ); - prof->setLocalTempFile( mLocalTempFile->text()); - prof->setRemoteFileName( mRemoteFile->text() ); - prof->setShowSummaryAfterSync( mShowSummaryAfterSync->isChecked() ); - prof->setAskForPreferences( mAskForPreferences->isChecked()); - prof->setWriteBackExisting(mWriteBackExisting->isChecked() ); - prof->setWriteBackFile( mWriteBackFile->isChecked()); - prof->setIncludeInRingSync( mIncludeInRing->isChecked() ); - int syncprefs = rem->isChecked()*1+newest->isChecked()*2+ ask->isChecked()*3+ f_loc->isChecked()*4+ f_rem->isChecked()*5 ;//+ both->isChecked()*6 ; - prof->setSyncPrefs( syncprefs); - prof->setIsLocalFileSync( mIsLocal->isChecked() ); } -} -void KOSyncPrefsDialog::insertProfiles() -{ - int curItem = mProfileBox->currentItem(); - mProfileBox->blockSignals( true ); - mProfileBox->clear(); - mProfileBox->insertStringList (mSyncProfileNames ); - int item = mSyncProfileNames.count() -1; - if ( curItem >= 0 && mSyncProfileNames.count() > 0 && curItem < mSyncProfileNames.count() ) - mProfileBox->setCurrentItem( curItem ); - else if ( item >= 0 ) { - mProfileBox->setCurrentItem( item ); - } - currentSelection = -1; - if ( mSyncProfileNames.count() > 0 ) { - //qDebug(" profileChanged( mProfileBox->currentItem() "); - profileChanged( mProfileBox->currentItem() ); - currentSelection = mProfileBox->currentItem(); - } - mProfileBox->blockSignals( false ); -} - -void KOSyncPrefsDialog::addProfile ( KSyncProfile* temp ) +void SyncPrefWidget_Remote::fillSSH() { - saveProfile(); - mSyncProfiles.append( temp ); - mSyncProfileNames << temp->getName(); - insertProfiles(); - int last = mProfileBox->count() -1; - mProfileBox->blockSignals( true ); - mProfileBox->setCurrentItem( last ); - mProfileBox->blockSignals( false ); - profileChanged(last); -} -void KOSyncPrefsDialog::newProfile() + QString location = mLocalTempFile->text(); + + mRemotePrecommand->setText("scp zaurus@192.168.0.65:/home/zaurus/kdepim/"+location + " " + location ); +//US mLocalTempFile->setText("/tmp/mycalendar.ics" ); + mRemotePostcommand->setText("scp " + location + " zaurus@192.168.0.65:/home/zaurus/kdepim/"+location ); +} + +void SyncPrefWidget_Remote::fillFTP() { - addProfile ( new KSyncProfile () ); + QString location = mLocalTempFile->text(); + + mRemotePrecommand->setText("cd /tmp;ftp ftp://zaurus:a@192.168.0.65/kdepim/" + location ); +//US mLocalTempFile->setText("/tmp/mycalendar.ics" ); + mRemotePostcommand->setText("ftp -u ftp://zaurus:a@192.168.0.65/kdepim/"+location+ " " + location); + } -void KOSyncPrefsDialog::cloneProfile() + +void SyncPrefWidget_Remote::kindChanged( int newKind ) { - if ( currentSelection >= 0 ) - addProfile (mSyncProfiles.at(currentSelection)->clone()) ; - else - newProfile(); + + if (newKind == Mobile) + remoteFileWidget->setEnabled(false); + else if (newKind == Remote) + remoteFileWidget->setEnabled(true); + else // default value is local + remoteFileWidget->setEnabled(false); + } +/*********************************************************************** + * + * + **********************************************************************/ -void KOSyncPrefsDialog::usrReadConfig() + +SyncPrefWidgetContainer::SyncPrefWidgetContainer() + : SyncWidgetContainer() { - KConfig *config = KOGlobals::config(); - config->setGroup("SyncProfiles"); - mSyncProfileNames = KOPrefs::instance()->mSyncProfileNames; - int i; - KSyncProfile* temp ; - mSyncProfiles.clear(); - for ( i = 0; i < mSyncProfileNames.count();++i ) { - temp = new KSyncProfile (); - temp->setName( mSyncProfileNames[i] ); - temp->readConfig( config ); - mSyncProfiles.append( temp ); } - insertProfiles(); - mMyMachineName->setText(KOPrefs::instance()->mLocalMachineName ); + +KRES::SyncWidget* SyncPrefWidgetContainer::generateSettingsTab(QWidget *parent = 0, const char *name = 0) +{ + return new SyncPrefWidget_Settings(parent, name); } +KRES::SyncWidget* SyncPrefWidgetContainer::generateConflictsTab(QWidget *parent = 0, const char *name = 0) +{ + return new SyncPrefWidget_Conflict(parent, name); +} -void KOSyncPrefsDialog::usrWriteConfig() +KRES::SyncWidget* SyncPrefWidgetContainer::generateRemoteTab(QWidget *parent = 0, const char *name = 0) { - saveProfile(); - if ( currentSelection >= 0 ) - profileChanged(currentSelection); - KConfig *config = KOGlobals::config(); - config->setGroup("SyncProfiles"); - KSyncProfile* prof = mSyncProfiles.first(); - while ( prof ) { - prof->writeConfig(config); - prof = mSyncProfiles.next(); - } - KOPrefs::instance()->mSyncProfileNames = mSyncProfileNames; - KOPrefs::instance()->mLocalMachineName = mMyMachineName->text(); - config->writeEntry("SyncProfileNames",&mSyncProfileNames); + return new SyncPrefWidget_Remote(parent, name); } -*/ + diff --git a/kabc/syncprefwidget.h b/kabc/syncprefwidget.h index 3709d78..b20a68e 100644 --- a/kabc/syncprefwidget.h +++ b/kabc/syncprefwidget.h @@ -1,121 +1,139 @@ /* This file is part of KABC/Pi. Copyright (c) 2004 Ulf Schenk This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ /* $Id$ */ #ifndef _SYNCPREFWIDGET_H #define _SYNCPREFWIDGET_H #include <kresources/syncwidget.h> -/*US -//#include <qframe.h> -//#include <qdict.h> -#include <qvbox.h> -#include <qhbox.h> -//#include <qcolor.h> -//#include <qlistview.h> - -#include <kdialogbase.h> - -#include <libkdepim/kprefsdialog.h> -*/ - -//US class KColorButton; -//US class QSpinBox;; class QRadioButton; class QCheckBox; class QVBox; -//US class QSlider; -//US class KURLRequester; -//US class QComboBox; +class QComboBox; class QLineEdit; -//US class QStringList; -//US class KSyncProfile; +class KRES::Resource; - -/** Dialog to change the korganizer configuration. - */ -class SyncPrefWidget : public KRES::SyncWidget +class SyncPrefWidget_Settings : public KRES::SyncWidget { Q_OBJECT public: - SyncPrefWidget(QWidget *parent=0); - ~SyncPrefWidget(); -//US void usrReadConfig(); + SyncPrefWidget_Settings(QWidget *parent=0, const char *name = 0 ); + ~SyncPrefWidget_Settings(); public slots: - protected slots: -//US void accept(); -//US void deleteProfile(); -//US void newProfile(); -//US void cloneProfile(); -//US void kindChanged(bool); -//US void fillSSH(); -//US void fillFTP(); -//US void textChanged( const QString & ); -//US void profileChanged( int ); -//US void chooseFile(); -//US void slotOK(); + virtual void loadSettings( KRES::Resource *resource ); + virtual void saveSettings( KRES::Resource *resource ); - protected: -//US void usrWriteConfig(); + protected: void init(); private: + QCheckBox* mIncludeInRing; + QCheckBox* mWriteBackFile; + QCheckBox* mWriteBackExisting; + QCheckBox* mAskForPreferences; + QCheckBox* mShowSummaryAfterSync; +}; -//US int currentSelection; -//US QPtrList<KSyncProfile> mSyncProfiles; -//US QStringList mSyncProfileNames; -//US QLineEdit * mMyMachineName; -//US QComboBox * mProfileBox; -//US QRadioButton* mIsLocal; - QCheckBox* mIsNotLocal; - QCheckBox* mIncludeInRing; -//US void addProfile ( KSyncProfile* ); -//US void insertProfiles(); -//US void saveProfile(); -//US QButtonGroup* proGr; +class SyncPrefWidget_Conflict : public KRES::SyncWidget +{ + Q_OBJECT + public: + SyncPrefWidget_Conflict(QWidget *parent=0, const char *name = 0 ); + ~SyncPrefWidget_Conflict(); + + public slots: + virtual void loadSettings( KRES::Resource *resource ); + virtual void saveSettings( KRES::Resource *resource ); + + protected: + void init(); + + private: QRadioButton* loc, *rem, *newest, *ask, *f_loc,* f_rem, *both; +}; + + + + +class SyncPrefWidget_Remote : public KRES::SyncWidget +{ + Q_OBJECT + public: + SyncPrefWidget_Remote(QWidget *parent=0, const char *name = 0 ); + ~SyncPrefWidget_Remote(); + + enum Types { + Local = 0, + Remote = 1, + Mobile =2 + }; + + + public slots: + virtual void loadSettings( KRES::Resource *resource ); + virtual void saveSettings( KRES::Resource *resource ); + protected slots: + void fillSSH(); + void fillFTP(); + void kindChanged( int newKind ); + + protected: + void init(); + private: + QComboBox* mProfileKind; QLineEdit * mRemotePostcommand; QLineEdit * mRemotePrecommand; QLineEdit * mRemoteFile; QLineEdit * mLocalTempFile; -//US QWidget* mSetupSyncAlgTab; - -//US QVBox* localFileWidget; QVBox* remoteFileWidget; - QCheckBox* mWriteBackFile; - QCheckBox* mWriteBackExisting; - QCheckBox* mAskForPreferences; - QCheckBox* mShowSummaryAfterSync; }; + + + + +class SyncPrefWidgetContainer : public KRES::SyncWidgetContainer +{ + Q_OBJECT + +public: + SyncPrefWidgetContainer(); + + virtual KRES::SyncWidget* generateSettingsTab(QWidget *parent, const char *name); + virtual KRES::SyncWidget* generateConflictsTab(QWidget *parent, const char *name); + virtual KRES::SyncWidget* generateRemoteTab(QWidget *parent, const char *name); +}; + + + #endif |