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 | |
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 | 36 | ||||
-rw-r--r-- | kabc/syncprefwidget.cpp | 681 | ||||
-rw-r--r-- | kabc/syncprefwidget.h | 138 | ||||
-rw-r--r-- | microkde/kresources/configdialog.cpp | 78 | ||||
-rw-r--r-- | microkde/kresources/configdialog.h | 4 | ||||
-rw-r--r-- | microkde/kresources/configpage.cpp | 15 | ||||
-rw-r--r-- | microkde/kresources/factory.cpp | 4 | ||||
-rw-r--r-- | microkde/kresources/factory.h | 5 | ||||
-rw-r--r-- | microkde/kresources/resource.h | 8 | ||||
-rw-r--r-- | microkde/kresources/syncwidget.h | 10 |
19 files changed, 512 insertions, 514 deletions
diff --git a/kabc/addressbook.cpp b/kabc/addressbook.cpp index 20310a0..c61b387 100644 --- a/kabc/addressbook.cpp +++ b/kabc/addressbook.cpp @@ -206,65 +206,65 @@ AddressBook::ConstIterator &AddressBook::ConstIterator::operator--(int) 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; 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 @@ -42,65 +42,65 @@ $Id$ //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()); 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 @@ -37,122 +37,112 @@ $Id$ #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; 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 @@ -16,65 +16,65 @@ 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" ); 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 @@ -32,65 +32,65 @@ $Id$ #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 ); 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 @@ -29,65 +29,65 @@ $Id$ #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; 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 @@ -31,65 +31,65 @@ $Id$ #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; diff --git a/kabc/resource.cpp b/kabc/resource.cpp index 2f03927..d39fd6a 100644 --- a/kabc/resource.cpp +++ b/kabc/resource.cpp @@ -84,56 +84,61 @@ Ticket *Resource::requestSaveTicket() } 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 @@ -113,57 +113,59 @@ public: * 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 @@ -30,199 +30,197 @@ $Id$ #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 ); +#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 ); + + 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 ); +#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(); + 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 ); + int iii = 0; + mIncludeInRing = new QCheckBox( i18n("Include in multiple sync"), this ); + topLayout->addMultiCellWidget(mIncludeInRing, iii,iii,0,1); + ++iii; - 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 ); - 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) ) ); -*/ + mAskForPreferences = new QCheckBox( i18n("Ask for preferences before sync"), this ); + topLayout->addMultiCellWidget(mAskForPreferences, iii,iii,0,1); + ++iii; -/*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); + mShowSummaryAfterSync = new QCheckBox( i18n("Show summary after sync"), this ); + topLayout->addMultiCellWidget(mShowSummaryAfterSync, iii,iii,0,1); + ++iii; - button = new QPushButton( i18n("Choose..."), temphb ); - connect ( button, SIGNAL( clicked()), this, SLOT ( chooseFile() ) ); -*/ - QHBox* temphb; + mWriteBackExisting= new QCheckBox( i18n("Write back existing entries only"), this ); + topLayout->addMultiCellWidget(mWriteBackExisting, iii,iii,0,1); + ++iii; - 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); + mWriteBackFile = new QCheckBox( i18n("Write back synced data"), this ); + topLayout->addMultiCellWidget(mWriteBackFile, iii,iii,0,1); + ++iii; - lab = new QLabel( i18n("Local temp file:"), remoteFileWidget); - mLocalTempFile = new QLineEdit(remoteFileWidget); +} +void SyncPrefWidget_Settings::loadSettings( KRES::Resource *res ) +{ + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + + if (prof == 0) + { + qDebug("SyncPrefWidget_Settings::loadSettings: something is wrong, because resource does have no syncprofile" ); + return; + } + + mIncludeInRing->setChecked( prof->getIncludeInRingSync() ); + mAskForPreferences->setChecked( prof->getAskForPreferences()); + mShowSummaryAfterSync->setChecked( prof->getShowSummaryAfterSync()); + mWriteBackExisting->setChecked( prof->getWriteBackExisting() ); + mWriteBackFile->setChecked( prof->getWriteBackFile()); +} - lab = new QLabel( i18n("Post sync (upload) command:"), remoteFileWidget); - mRemotePostcommand = 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; + } + + 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 ); - 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; + 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; + } + + 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; + } } -void KOSyncPrefsDialog::profileChanged( int item ) + +void SyncPrefWidget_Conflict::saveSettings( KRES::Resource *res ) { - //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() ); + 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; + } + + 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) +{ + init(); } -void KOSyncPrefsDialog::fillSSH() + +SyncPrefWidget_Remote::~SyncPrefWidget_Remote() { - 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" ); } -void KOSyncPrefsDialog::fillFTP() + +void SyncPrefWidget_Remote::init() { - 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" ); + 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 ) ) ); + + + 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::kindChanged( bool b ) + +void SyncPrefWidget_Remote::loadSettings( KRES::Resource *res ) { + KABC::Resource* resource = (KABC::Resource*)( res ); + KSyncProfile* prof = resource->getSyncProfile(); + + if (prof == 0) + { + qDebug("SyncPrefWidget_Remote::loadSettings: something is wrong, because resource does have no syncprofile" ); + return; + } - localFileWidget->setEnabled(b); - remoteFileWidget->setEnabled(!b); + 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 KOSyncPrefsDialog::deleteProfile() + +void SyncPrefWidget_Remote::saveSettings( KRES::Resource *res ) { - //qDebug("KOSyncPrefsDialog::deleteProfile() "); - if ( currentSelection >= 0 ) { - if ( currentSelection < 3 ) { - KMessageBox::error(this,i18n("This profil cannot be deleted!\n"),i18n("KO/Pi config error")); - return; - } - KSyncProfile* temp = mSyncProfiles.at(currentSelection); - mSyncProfiles.remove( temp ); - mSyncProfileNames.remove( mSyncProfileNames.at( currentSelection )); - insertProfiles(); - } + 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; + } + + int val = mProfileKind->currentItem(); + + if (val == Mobile) + { + prof->setIsLocalFileSync(true); + prof->setIsPhoneSync(true); + } + else if (val == Remote) + { + 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() ); } -void KOSyncPrefsDialog::saveProfile() + +void SyncPrefWidget_Remote::fillSSH() { - KSyncProfile* prof; - if ( currentSelection >= 0 ) { - prof = mSyncProfiles.at(currentSelection) ; - prof->setPreSyncCommand( mRemotePrecommand->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() ); - } + 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 KOSyncPrefsDialog::insertProfiles() +void SyncPrefWidget_Remote::fillFTP() { - 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 ); + 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::addProfile ( KSyncProfile* temp ) + +void SyncPrefWidget_Remote::kindChanged( int newKind ) { - saveProfile(); - mSyncProfiles.append( temp ); - mSyncProfileNames << temp->getName(); - insertProfiles(); - int last = mProfileBox->count() -1; - mProfileBox->blockSignals( true ); - mProfileBox->setCurrentItem( last ); - mProfileBox->blockSignals( false ); - profileChanged(last); + + if (newKind == Mobile) + remoteFileWidget->setEnabled(false); + else if (newKind == Remote) + remoteFileWidget->setEnabled(true); + else // default value is local + remoteFileWidget->setEnabled(false); + } -void KOSyncPrefsDialog::newProfile() + +/*********************************************************************** + * + * + **********************************************************************/ + + +SyncPrefWidgetContainer::SyncPrefWidgetContainer() + : SyncWidgetContainer() { - addProfile ( new KSyncProfile () ); } -void KOSyncPrefsDialog::cloneProfile() +KRES::SyncWidget* SyncPrefWidgetContainer::generateSettingsTab(QWidget *parent = 0, const char *name = 0) { - if ( currentSelection >= 0 ) - addProfile (mSyncProfiles.at(currentSelection)->clone()) ; - else - newProfile(); + return new SyncPrefWidget_Settings(parent, name); } - -void KOSyncPrefsDialog::usrReadConfig() +KRES::SyncWidget* SyncPrefWidgetContainer::generateConflictsTab(QWidget *parent = 0, const char *name = 0) { - 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 ); + 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 diff --git a/microkde/kresources/configdialog.cpp b/microkde/kresources/configdialog.cpp index 90febca..f8240f9 100644 --- a/microkde/kresources/configdialog.cpp +++ b/microkde/kresources/configdialog.cpp @@ -1,195 +1,241 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> Copyright (c) 2003 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. */ #include <klocale.h> #include <kglobal.h> #include <kmessagebox.h> #include <qgroupbox.h> #include <qlabel.h> #include <qlayout.h> #include <qpushbutton.h> +#include <qvbox.h> #include <qcheckbox.h> +#include <qscrollview.h> #include <kbuttonbox.h> #include <kdialog.h> #include <klineedit.h> #include "factory.h" #include "configwidget.h" #include "configdialog.h" #include "syncwidget.h" using namespace KRES; ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, Resource* resource, const char *name ) : KDialogBase( parent, name, true, resource->isSyncable()?i18n( "Sync Profile Configuration" ):i18n( "Resource Configuration" ), - Ok|Cancel, Ok, true )/*, mConfig( config )*/, mSyncWidget(0), mResource( resource ), mPersistentReadOnly(false) + Ok|Cancel, Ok, true )/*, mConfig( config )*/, mSyncWidget_Settings(0), mSyncWidget_Conflicts(0),mSyncWidget_Remote(0), mResource( resource ), mPersistentReadOnly(false) { Factory *factory = Factory::self( resourceFamily ); //US resize( 250, 240 ); resize( KMIN(KGlobal::getDesktopWidth(), 250), KMIN(KGlobal::getDesktopHeight(), 240)); -//US QFrame *main = makeMainWidget(); - QFrame *main = plainPage(); + QFrame *main; + + if (!mResource->isSyncable()) + main = plainPage(); + else + main = addPage("Profile"); QVBoxLayout *mainLayout = new QVBoxLayout( main, 0, spacingHint() ); + QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); generalGroupBox->layout()->setSpacing( spacingHint() ); generalGroupBox->setTitle( i18n( "General Settings" ) ); new QLabel( mResource->isSyncable()?i18n( "Profile Name:" ):i18n( "Name:" ), generalGroupBox ); mName = new KLineEdit( generalGroupBox ); if (!mResource->isSyncable()) { mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox ); mReadOnly->setChecked( mResource->readOnly() ); } mName->setText( mResource->resourceName() ); mainLayout->addWidget( generalGroupBox ); QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); resourceGroupBox->layout()->setSpacing( spacingHint()); resourceGroupBox->setTitle( i18n( "%1 Resource Settings" ) .arg( factory->typeName( resource->type() ) ) ); mainLayout->addWidget( resourceGroupBox ); mainLayout->addStretch(); mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox ); if ( mConfigWidget ) { connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), SLOT( setReadOnly( bool ) ) ); connect( mConfigWidget, SIGNAL( setPersistentReadOnly( bool ) ), SLOT( setPersistentReadOnly( bool ) ) ); mConfigWidget->setInEditMode( false ); mConfigWidget->loadSettings( mResource ); mConfigWidget->show(); } if (mResource->isSyncable()) { - QGroupBox *syncGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); - syncGroupBox->layout()->setSpacing( spacingHint()); - syncGroupBox->setTitle( i18n( "Syncronize Preferences" ) ); - mainLayout->addWidget( syncGroupBox ); + SyncWidgetContainer* c = factory->syncWidgetContainer( resource->type() ); + + QFrame* syncPage = addPage("Settings"); + QVBoxLayout *syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() ); + mSyncWidget_Settings = c->generateSettingsTab(syncPage); + syncLayout->addWidget( mSyncWidget_Settings ); + + syncPage = addPage("Conflicts"); + syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() ); + mSyncWidget_Conflicts = c->generateConflictsTab(syncPage); + syncLayout->addWidget( mSyncWidget_Conflicts ); + + syncPage = addPage("Remote"); + syncLayout = new QVBoxLayout( syncPage, 0, spacingHint() ); + mSyncWidget_Remote = c->generateRemoteTab(syncPage); + syncLayout->addWidget( mSyncWidget_Remote ); + - mainLayout->addStretch(); + mSyncWidget_Settings->setInEditMode( false ); + mSyncWidget_Settings->loadSettings( mResource ); + mSyncWidget_Settings->show(); - mSyncWidget = factory->syncWidget( resource->type(), syncGroupBox ); + mSyncWidget_Conflicts->setInEditMode( false ); + mSyncWidget_Conflicts->loadSettings( mResource ); + mSyncWidget_Conflicts->show(); + + mSyncWidget_Remote->setInEditMode( false ); + mSyncWidget_Remote->loadSettings( mResource ); + mSyncWidget_Remote->show(); + + delete c; + +// QGroupBox *syncGroupBox = new QGroupBox( 2, Qt::Horizontal, syncPage ); +// syncGroupBox->layout()->setSpacing( spacingHint()); +// syncGroupBox->setTitle( i18n( "Syncronize Preferences" ) ); +// syncLayout->addWidget( syncGroupBox ); + +// syncLayout->addStretch(); +/*US + mSyncWidget = factory->syncWidget( resource->type(), syncPage ); + syncLayout->addWidget( mSyncWidget ); if ( mSyncWidget ) { mSyncWidget->setInEditMode( false ); mSyncWidget->loadSettings( mResource ); mSyncWidget->show(); } + */ } connect( mName, SIGNAL( textChanged(const QString &)), SLOT( slotNameChanged(const QString &))); slotNameChanged( mName->text() ); //US setMinimumSize( 400, 250 ); setMinimumSize( KMIN(KGlobal::getDesktopWidth(), 400), KMIN(KGlobal::getDesktopHeight(), 250)); } void ConfigDialog::setInEditMode( bool value ) { if ( mConfigWidget ) mConfigWidget->setInEditMode( value ); - if ( mSyncWidget ) - mSyncWidget->setInEditMode( value ); + if ( mSyncWidget_Settings ) + mSyncWidget_Settings->setInEditMode( value ); + if ( mSyncWidget_Conflicts ) + mSyncWidget_Conflicts->setInEditMode( value ); + if ( mSyncWidget_Remote ) + mSyncWidget_Remote->setInEditMode( value ); } void ConfigDialog::slotNameChanged( const QString &text) { enableButtonOK( !text.isEmpty() ); } void ConfigDialog::setReadOnly( bool value ) { if (!mResource->isSyncable()) { if (mPersistentReadOnly == false) mReadOnly->setChecked( value ); else mReadOnly->setChecked( true ); } } void ConfigDialog::setPersistentReadOnly( bool value ) { if (!mResource->isSyncable()) { mPersistentReadOnly = value; if (value == true) setReadOnly( true ); mReadOnly->setEnabled( !value ); } } void ConfigDialog::accept() { if ( mName->text().isEmpty() ) { KMessageBox::sorry( this, mResource->isSyncable()?i18n( "Please enter a profile name" ):i18n( "Please enter a resource name" ) ); return; } mResource->setResourceName( mName->text() ); if (!mResource->isSyncable()) mResource->setReadOnly( mReadOnly->isChecked() ); if ( mConfigWidget ) { // First save generic information // Also save setting of specific resource type mConfigWidget->saveSettings( mResource ); } - if ( mSyncWidget ) { - // First save generic information - // Also save setting of specific resource type - mSyncWidget->saveSettings( mResource ); - } + if ( mSyncWidget_Settings ) + mSyncWidget_Settings->saveSettings( mResource ); + if ( mSyncWidget_Conflicts ) + mSyncWidget_Conflicts->saveSettings( mResource ); + if ( mSyncWidget_Remote ) + mSyncWidget_Remote->saveSettings( mResource ); KDialog::accept(); } //US #include "configdialog.moc" diff --git a/microkde/kresources/configdialog.h b/microkde/kresources/configdialog.h index b629347..63cd4e9 100644 --- a/microkde/kresources/configdialog.h +++ b/microkde/kresources/configdialog.h @@ -22,44 +22,46 @@ #ifndef KRESOURCES_CONFIGDIALOG_H #define KRESOURCES_CONFIGDIALOG_H #include <kdialogbase.h> class KLineEdit; class QCheckBox; class KButtonBox; namespace KRES { class Resource; class ConfigWidget; class SyncWidget; class ConfigDialog : public KDialogBase { Q_OBJECT public: // Resource=0: create new resource ConfigDialog( QWidget *parent, const QString& resourceFamily, Resource* resource, const char *name = 0); void setInEditMode( bool value ); protected slots: void accept(); void setReadOnly( bool value ); void setPersistentReadOnly( bool value ); void slotNameChanged( const QString &text); private: ConfigWidget *mConfigWidget; - SyncWidget *mSyncWidget; + SyncWidget *mSyncWidget_Settings; + SyncWidget *mSyncWidget_Conflicts; + SyncWidget *mSyncWidget_Remote; Resource* mResource; KLineEdit *mName; QCheckBox *mReadOnly; //US add a persistent readonly flag. We need that for opie and qtopia addressbooks. bool mPersistentReadOnly; }; } #endif diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp index 2fe021d..1a3a22c 100644 --- a/microkde/kresources/configpage.cpp +++ b/microkde/kresources/configpage.cpp @@ -176,64 +176,66 @@ void ConfigPage::load() mListView->clear(); //US we remove the dynamic pluginloader, and set the one family we need (contact) manually. //US KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" ); //US KTrader::OfferList::ConstIterator it; //US for ( it = plugins.begin(); it != plugins.end(); ++it ) { //US QVariant tmp = (*it)->property( "X-KDE-ResourceFamily" ); //US QString family = tmp.toString(); QStringList families; families << "contact" << syncfamily; for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) { QString family = (*it); if ( !family.isEmpty() ) { if ( !mFamilyMap.contains( family ) ) { mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); if ( mCurrentManager ) { mFamilyMap.append( family ); mCurrentManager->addListener( this ); ResourcePageInfo info; info.mManager = mCurrentManager; QString configDir = KGlobal::dirs()->saveLocation( "config" ); //QString configDir = KStandardDirs::appDir() + "/config"; if ( family == "contact" && QFile::exists( configDir + "/kabcrc" ) ) { info.mConfig = new KConfig( locateLocal( "config", "kabcrc" ) ); } else if ( family == "calendar" && QFile::exists( configDir + "/kcalrc" ) ) { info.mConfig = new KConfig( locateLocal( "config", "kcalrc" ) ); + } else if ( family == syncfamily && QFile::exists( configDir + "/kabcsyncrc" ) ) { + info.mConfig = new KConfig( locateLocal( "config", "kabcsyncrc" ) ); } else { QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) ); info.mConfig = new KConfig( configFile ); } info.mManager->readConfig( info.mConfig ); mInfoMap.append( info ); } } } } mCurrentManager = 0; mFamilyCombo->insertStringList( mFamilyMap ); int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 ); mFamilyCombo->setCurrentItem( currentFamily ); slotFamilyChanged( currentFamily ); } void ConfigPage::save() { saveResourceSettings(); QValueList<ResourcePageInfo>::Iterator it; for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) (*it).mManager->writeConfig( (*it).mConfig ); emit changed( false ); } void ConfigPage::defaults() @@ -282,88 +284,95 @@ void ConfigPage::slotFamilyChanged( int pos ) defaults(); emit changed( true ); mCurrentManager->writeConfig( mCurrentConfig ); } else { //US qDebug("ConfigPage::slotFamilyChanged 4.6 "); if ( !standardResource ) { KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); } emit changed( false ); } } void ConfigPage::slotAdd() { if ( !mCurrentManager ) return; QStringList types = mCurrentManager->resourceTypeNames(); QStringList descs = mCurrentManager->resourceTypeDescriptions(); bool ok = false; QString desc; if (mFamily == syncfamily) { desc = QInputDialog::getItem( i18n( "Sync Configuration" ), - i18n( "Please select resource type for new sync profile:" ), descs, 0, + i18n( "Select resource type for the new sync profile:" ), descs, 0, false, &ok, this ); } else { desc = QInputDialog::getItem( i18n( "Resource Configuration" ), - i18n( "Please select type of the new resource:" ), descs, 0, + i18n( "Select type of the new resource:" ), descs, 0, false, &ok, this ); } if ( !ok ) return; QString type = types[ descs.findIndex( desc ) ]; // Create new resource Resource *resource = mCurrentManager->createResource( type ); if ( !resource ) { KMessageBox::error( this, i18n("Unable to create resource of type '%1'.") .arg( type ) ); return; } - resource->setResourceName( type + "-resource" ); + if (mFamily == syncfamily) + { + resource->setResourceName( type + "-syncprofile" ); + } + else + { + resource->setResourceName( type + "-resource" ); + } ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); if ( dlg.exec() ) { mCurrentManager->add( resource ); ConfigViewItem *item = new ConfigViewItem( mListView, resource ); mLastItem = item; // if there are only read-only resources we'll set this resource // as standard resource if ( !resource->readOnly() ) { bool onlyReadOnly = true; QListViewItem *it = mListView->firstChild(); while ( it != 0 ) { ConfigViewItem *confIt = static_cast<ConfigViewItem*>( it ); if ( !confIt->readOnly() && confIt != item ) onlyReadOnly = false; it = it->itemBelow(); } if ( onlyReadOnly ) item->setStandard( true ); } emit changed( true ); } else { delete resource; resource = 0; } diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp index 7a5c2f6..e44fce3 100644 --- a/microkde/kresources/factory.cpp +++ b/microkde/kresources/factory.cpp @@ -158,88 +158,88 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) { if ( type.isEmpty() || !mTypeMap.contains( type ) ) return 0; //US KService::Ptr ptr = mTypeMap[ type ]; //US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); PluginInfo* pi = mTypeMap[ type ]; KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); if ( !factory ) { qDebug("KRES::Factory::configWidget(): Factory creation failed for library %s", pi->library.latin1()); kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl; return 0; } PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); if ( !pluginFactory ) { qDebug("KRES::Factory::configWidget(): no plugin factory for library %s", pi->library.latin1()); kdDebug() << "KRES::Factory::configWidget(): no plugin factory." << endl; return 0; } ConfigWidget *wdg = pluginFactory->configWidget( parent ); if ( !wdg ) { //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); return 0; } return wdg; } -SyncWidget *Factory::syncWidget( const QString& type, QWidget *parent ) +SyncWidgetContainer *Factory::syncWidgetContainer( const QString& type ) { if ( type.isEmpty() || !mTypeMap.contains( type ) ) return 0; //US KService::Ptr ptr = mTypeMap[ type ]; //US KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); PluginInfo* pi = mTypeMap[ type ]; KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); if ( !factory ) { qDebug("KRES::Factory::syncWidget(): Factory creation failed for library %s", pi->library.latin1()); kdDebug() << "KRES::Factory::syncWidget(): Factory creation failed" << endl; return 0; } PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); if ( !pluginFactory ) { qDebug("KRES::Factory::syncWidget(): no plugin factory for library %s", pi->library.latin1()); kdDebug() << "KRES::Factory::syncWidget(): no plugin factory." << endl; return 0; } - SyncWidget *wdg = pluginFactory->syncWidget( parent ); + SyncWidgetContainer *wdg = pluginFactory->syncWidgetContainer( ); if ( !wdg ) { //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); return 0; } return wdg; } QString Factory::typeName( const QString &type ) const { if ( type.isEmpty() || !mTypeMap.contains( type ) ) return QString(); //US KService::Ptr ptr = mTypeMap[ type ]; //US return ptr->name(); PluginInfo* pi = mTypeMap[ type ]; return pi->nameLabel; } QString Factory::typeDescription( const QString &type ) const { if ( type.isEmpty() || !mTypeMap.contains( type ) ) return QString(); //US KService::Ptr ptr = mTypeMap[ type ]; //US return ptr->comment(); PluginInfo* pi = mTypeMap[ type ]; return pi->descriptionLabel; diff --git a/microkde/kresources/factory.h b/microkde/kresources/factory.h index a265bc8..0e4231b 100644 --- a/microkde/kresources/factory.h +++ b/microkde/kresources/factory.h @@ -5,123 +5,126 @@ Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> Copyright (c) 2003 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. */ #ifndef KRESOURCES_FACTORY_H #define KRESOURCES_FACTORY_H #include <qdict.h> #include <qstring.h> #include <kconfig.h> #include "resource.h" namespace KRES { +class SyncWidgetContainer; +class ConfigWidget; + //US struct PluginInfo { QString library; QString nameLabel; QString descriptionLabel; }; /** * Class for loading resource plugins. * Do not use this class directly. Use ResourceManager instead * * Example: * * <pre> * KABC::Factory<Calendar> *factory = KABC::Factory<Calendar>::self(); * * QStringList list = factory->resources(); * QStringList::Iterator it; * for ( it = list.begin(); it != list.end(); ++it ) { * Resource<Calendar> *resource = factory->resource( (*it), * KABC::StdAddressBook::self(), 0 ); * // do something with resource * } * </pre> */ class Factory { public: /** * Returns the global resource factory. */ static Factory *self( const QString& resourceFamily ); ~Factory(); /** * Returns the config widget for the given resource type, * or a null pointer if resource type doesn't exist. * * @param type The type of the resource, returned by @ref resources() * @param resource The resource to be editted. * @param parent The parent widget */ ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 ); /** * Returns the sync widget for the given resource type, * or a null pointer if resource type doesn't exist, * or a null pointer if resource does not support syncing. * * @param type The type of the resource, returned by @ref resources() * @param resource The resource to be editted. * @param parent The parent widget */ - SyncWidget *syncWidget( const QString& type, QWidget *parent = 0 ); + SyncWidgetContainer *syncWidgetContainer( const QString& type ); /** * Returns a pointer to a resource object or a null pointer * if resource type doesn't exist. * * @param type The type of the resource, returned by @ref resources() * @param ab The address book, the resource should belong to * @param config The config object where the resource get it settings from, or 0 if a new resource should be created. * @param syncable If the resource should support syncing capabilities. */ Resource *resource( const QString& type, const KConfig *config, bool syncable ); /** * Returns a list of all available resource types. */ QStringList typeNames() const; /** * Returns the name for a special type. */ QString typeName( const QString &type ) const; /** * Returns the description for a special type. */ QString typeDescription( const QString &type ) const; protected: Factory( const QString& resourceFamily); private: static QDict<Factory> *mSelves; diff --git a/microkde/kresources/resource.h b/microkde/kresources/resource.h index c9202c9..580b5d1 100644 --- a/microkde/kresources/resource.h +++ b/microkde/kresources/resource.h @@ -11,65 +11,65 @@ 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. */ #ifndef KRESOURCES_RESOURCE_H #define KRESOURCES_RESOURCE_H //US #ifdef QT_THREAD_SUPPORT #include <qmutex.h> #endif //QT_THREAD_SUPPORT #include <qvaluelist.h> #include <qwidget.h> #include <qobject.h> #include <klibloader.h> class KConfig; namespace KRES { class ConfigWidget; -class SyncWidget; +class SyncWidgetContainer; /** * @internal * @libdoc The KDE Resource library * * NOTE: this library is NOT (YET?) PUBLIC. Do not publish this * interface, it is in constant flux. * * The KDE Resource framework can be used to manage resources of * different types, organized in families. The Resource framework * is currently used for addressbook resources in libkabc and for * calendar resources in libkcal. * * When you want to use the framework for a new family, you need to * <ul><li>Define a name for your resource family</li> * <li>subclass Resource and add the fields and method that are needed * in your application</li> * <li>If needed, override the doOpen() and doClose() methods. * <li> Provide a configuration possibility for resources in your * new family. You can use @ref ResourcesConfigPage to easily create a * KControl applet</li> * <li>In your application, you can use @ref ResourceManager to keep track * of the resources in your family, and you can use @ref ResourceSelectDialog * to let the user select a single resource.</li> * </ul> * * When you want to add a new resource type to an existing resource family, * you need to * <ul><li>Further subclass the family-specific Resource to implement * resource type-specific operation</li> * <li>Subclass ResourceConfigWidget to provide a configuration widget * for your new resource type</li> @@ -349,68 +349,68 @@ class Resource : public QObject /** * Open this resource. When called, the resource must be in * a closed state. * * Returns true if the resource was opened successfully; * returns false if the resource was not opened successfully. * * The result of this call can be accessed later by @ref isOpen() */ virtual bool doOpen() { return true; } /** * Close this resource. Pre-condition: resource is open. * Post-condition: resource is closed. */ virtual void doClose() {} void setIdentifier( const QString& identifier ); void setType( const QString& type ); private: class ResourcePrivate; ResourcePrivate *d; }; class PluginFactoryBase : public KLibFactory { public: virtual Resource *resource( const KConfig *config, bool syncable ) = 0; virtual ConfigWidget *configWidget( QWidget *parent ) = 0; - virtual SyncWidget *syncWidget( QWidget *parent ) = 0; + virtual SyncWidgetContainer *syncWidgetContainer() = 0; protected: virtual QObject* createObject( QObject*, const char*, const char*, const QStringList & ) { return 0; } }; template<class TR,class TC, class TS> class PluginFactory : public PluginFactoryBase { public: Resource *resource( const KConfig *config, bool syncable ) { return new TR( config, syncable ); } ConfigWidget *configWidget( QWidget *parent ) { return new TC( parent ); } - virtual SyncWidget *syncWidget( QWidget *parent ) + SyncWidgetContainer *syncWidgetContainer() { - return new TS( parent ); + return new TS(); } }; } #endif diff --git a/microkde/kresources/syncwidget.h b/microkde/kresources/syncwidget.h index e94252c..6632b69 100644 --- a/microkde/kresources/syncwidget.h +++ b/microkde/kresources/syncwidget.h @@ -29,34 +29,44 @@ #include "resource.h" namespace KRES { class SyncWidget : public QWidget { Q_OBJECT public: SyncWidget( QWidget *parent = 0, const char *name = 0 ); /** Sets the widget to 'edit' mode. Reimplement this method if you are interested in the mode change (to disable some GUI element for example). By default the widget is in 'create new' mode. */ virtual void setInEditMode( bool value ); public slots: virtual void loadSettings( Resource *resource ); virtual void saveSettings( Resource *resource ); signals: //US void setReadOnly( bool value ); //US void setPersistentReadOnly( bool value ); protected: //US Resource* mResource; }; +class SyncWidgetContainer : public QObject +{ + Q_OBJECT + +public: + virtual SyncWidget* generateSettingsTab(QWidget *parent = 0, const char *name = 0) = 0; + virtual SyncWidget* generateConflictsTab(QWidget *parent = 0, const char *name = 0) = 0; + virtual SyncWidget* generateRemoteTab(QWidget *parent = 0, const char *name = 0) = 0; +}; + } #endif |