-rw-r--r-- | microkde/kresources/configdialog.cpp | 89 | ||||
-rw-r--r-- | microkde/kresources/configdialog.h | 4 | ||||
-rw-r--r-- | microkde/kresources/configpage.cpp | 75 | ||||
-rw-r--r-- | microkde/kresources/configpage.h | 1 | ||||
-rw-r--r-- | microkde/kresources/factory.cpp | 44 | ||||
-rw-r--r-- | microkde/kresources/factory.h | 26 |
6 files changed, 177 insertions, 62 deletions
diff --git a/microkde/kresources/configdialog.cpp b/microkde/kresources/configdialog.cpp index 0fc199c..90febca 100644 --- a/microkde/kresources/configdialog.cpp +++ b/microkde/kresources/configdialog.cpp @@ -38,16 +38,18 @@ #include "factory.h" #include "configwidget.h" #include "configdialog.h" +#include "syncwidget.h" using namespace KRES; ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, - /*const QString& type,*/ Resource* resource, /*KConfig *config, */const char *name ) - : KDialogBase( parent, name, true, i18n( "Resource Configuration" ), - Ok|Cancel, Ok, true )/*, mConfig( config )*/, mResource( resource ), mPersistentReadOnly(false) + 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) { + Factory *factory = Factory::self( resourceFamily ); //US resize( 250, 240 ); resize( KMIN(KGlobal::getDesktopWidth(), 250), KMIN(KGlobal::getDesktopHeight(), 240)); @@ -60,16 +62,18 @@ ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, QGroupBox *generalGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); generalGroupBox->layout()->setSpacing( spacingHint() ); generalGroupBox->setTitle( i18n( "General Settings" ) ); - new QLabel( i18n( "Name:" ), generalGroupBox ); + new QLabel( mResource->isSyncable()?i18n( "Profile Name:" ):i18n( "Name:" ), generalGroupBox ); mName = new KLineEdit( generalGroupBox ); - mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox ); + if (!mResource->isSyncable()) { + mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox ); + mReadOnly->setChecked( mResource->readOnly() ); + } mName->setText( mResource->resourceName() ); - mReadOnly->setChecked( mResource->readOnly() ); mainLayout->addWidget( generalGroupBox ); QGroupBox *resourceGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); @@ -81,23 +85,43 @@ ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, mainLayout->addStretch(); mConfigWidget = factory->configWidget( resource->type(), resourceGroupBox ); if ( mConfigWidget ) { - connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), + connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ), SLOT( setReadOnly( bool ) ) ); - connect( mConfigWidget, SIGNAL( setPersistentReadOnly( bool ) ), + connect( mConfigWidget, SIGNAL( setPersistentReadOnly( bool ) ), SLOT( setPersistentReadOnly( bool ) ) ); mConfigWidget->setInEditMode( false ); mConfigWidget->loadSettings( mResource ); mConfigWidget->show(); - + } - connect( mName, SIGNAL( textChanged(const QString &)), + if (mResource->isSyncable()) + { + QGroupBox *syncGroupBox = new QGroupBox( 2, Qt::Horizontal, main ); + syncGroupBox->layout()->setSpacing( spacingHint()); + syncGroupBox->setTitle( i18n( "Syncronize Preferences" ) ); + mainLayout->addWidget( syncGroupBox ); + + mainLayout->addStretch(); + + mSyncWidget = factory->syncWidget( resource->type(), syncGroupBox ); + 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)); } @@ -105,8 +129,12 @@ ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, void ConfigDialog::setInEditMode( bool value ) { if ( mConfigWidget ) mConfigWidget->setInEditMode( value ); + + if ( mSyncWidget ) + mSyncWidget->setInEditMode( value ); + } void ConfigDialog::slotNameChanged( const QString &text) { @@ -114,41 +142,54 @@ void ConfigDialog::slotNameChanged( const QString &text) } void ConfigDialog::setReadOnly( bool value ) { - if (mPersistentReadOnly == false) - mReadOnly->setChecked( value ); - else - mReadOnly->setChecked( true ); + if (!mResource->isSyncable()) { + + if (mPersistentReadOnly == false) + mReadOnly->setChecked( value ); + else + mReadOnly->setChecked( true ); + } } void ConfigDialog::setPersistentReadOnly( bool value ) { - mPersistentReadOnly = value; - - if (value == true) - setReadOnly( true ); - - mReadOnly->setEnabled( !value ); - + if (!mResource->isSyncable()) { + + mPersistentReadOnly = value; + + if (value == true) + setReadOnly( true ); + + mReadOnly->setEnabled( !value ); + } } void ConfigDialog::accept() { if ( mName->text().isEmpty() ) { - KMessageBox::sorry( this, i18n( "Please enter a resource name" ) ); + KMessageBox::sorry( this, mResource->isSyncable()?i18n( "Please enter a profile name" ):i18n( "Please enter a resource name" ) ); return; } mResource->setResourceName( mName->text() ); - mResource->setReadOnly( mReadOnly->isChecked() ); + 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 ); + } + + KDialog::accept(); } //US #include "configdialog.moc" diff --git a/microkde/kresources/configdialog.h b/microkde/kresources/configdialog.h index ba66f8e..b629347 100644 --- a/microkde/kresources/configdialog.h +++ b/microkde/kresources/configdialog.h @@ -30,8 +30,9 @@ class KButtonBox; namespace KRES { class Resource; class ConfigWidget; + class SyncWidget; class ConfigDialog : public KDialogBase { Q_OBJECT @@ -49,14 +50,15 @@ class ConfigDialog : public KDialogBase void slotNameChanged( const QString &text); private: ConfigWidget *mConfigWidget; + SyncWidget *mSyncWidget; Resource* mResource; KLineEdit *mName; QCheckBox *mReadOnly; //US add a persistent readonly flag. We need that for opie and qtopia addressbooks. - bool mPersistentReadOnly; + bool mPersistentReadOnly; }; } diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp index 8782ffd..912c62e 100644 --- a/microkde/kresources/configpage.cpp +++ b/microkde/kresources/configpage.cpp @@ -20,8 +20,15 @@ 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 <qgroupbox.h> #include <qinputdialog.h> #include <qlabel.h> #include <qlayout.h> @@ -49,8 +56,11 @@ #include <kglobal.h> using namespace KRES; +const QString ConfigPage::syncfamily = "syncprofiles"; + + class ConfigViewItem : public QCheckListItem { public: ConfigViewItem( QListView *parent, Resource* resource ) : @@ -163,15 +173,17 @@ void ConfigPage::load() //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" << "sync-contacts"; + 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 ); + mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); if ( mCurrentManager ) { mFamilyMap.append( family ); mCurrentManager->addListener( this ); @@ -227,9 +239,9 @@ void ConfigPage::slotFamilyChanged( int pos ) mFamily = mFamilyMap[ pos ]; //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); - + mCurrentManager = mInfoMap[ pos ].mManager; mCurrentConfig = mInfoMap[ pos ].mConfig; if ( !mCurrentManager ) @@ -238,38 +250,38 @@ void ConfigPage::slotFamilyChanged( int pos ) mListView->clear(); if ( mCurrentManager->isEmpty() ) { //US qDebug("ConfigPage::slotFamilyChanged 4.1 mCurrentManager=%ul", mCurrentManager ); - + defaults(); } - + Resource *standardResource = mCurrentManager->standardResource(); - + //US qDebug("ConfigPage::slotFamilyChanged 4.4 resourcename=%s", standardResource->resourceName().latin1()); - + Manager<Resource>::Iterator it; for ( it = mCurrentManager->begin(); it != mCurrentManager->end(); ++it ) { ConfigViewItem *item = new ConfigViewItem( mListView, *it ); if ( *it == standardResource ) item->setStandard( true ); } - + if ( mListView->childCount() == 0 ) { //US qDebug("ConfigPage::slotFamilyChanged 4.5 "); 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! Please select one." ) ); - + KMessageBox::sorry( this, i18n( "There is no standard resource!<br> Please select one." ) ); + //US qDebug("ConfigPage::slotFamilyChanged 4.7" ); - + } emit changed( false ); } @@ -282,11 +294,24 @@ void ConfigPage::slotAdd() QStringList types = mCurrentManager->resourceTypeNames(); QStringList descs = mCurrentManager->resourceTypeDescriptions(); bool ok = false; - QString desc = QInputDialog::getItem( i18n( "Resource Configuration" ), - i18n( "Please select type of the new resource:" ), descs, 0, + + QString desc; + + if (mFamily == syncfamily) + { + desc = QInputDialog::getItem( i18n( "Sync Configuration" ), + i18n( "Please select resource type for 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, false, &ok, this ); + } + if ( !ok ) return; QString type = types[ descs.findIndex( desc ) ]; @@ -379,9 +404,9 @@ void ConfigPage::slotEdit() configItem->setText( 0, resource->resourceName() ); configItem->setText( 1, resource->type() ); if ( configItem->standard() && configItem->readOnly() ) { - KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) ); + KMessageBox::sorry( this, i18n( "You cannot use a read-only<br> resource as standard!" ) ); configItem->setStandard( false ); } mCurrentManager->resourceChanged( resource ); @@ -398,14 +423,14 @@ void ConfigPage::slotStandard() if ( !item ) return; if ( item->readOnly() ) { - KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) ); + KMessageBox::sorry( this, i18n( "You cannot use a read-only<br>resource as standard!" ) ); return; } if ( !item->isOn() ) { - KMessageBox::sorry( this, i18n( "You cannot use an inactive resource as standard!" ) ); + KMessageBox::sorry( this, i18n( "You cannot use an inactive<br>resource as standard!" ) ); return; } QListViewItem *it = mListView->firstChild(); @@ -463,9 +488,9 @@ void ConfigPage::slotItemClicked( QListViewItem *item ) ConfigViewItem *configItem = static_cast<ConfigViewItem *>( item ); if ( !configItem ) return; if ( configItem->standard() && !configItem->isOn() ) { - KMessageBox::sorry( this, i18n( "You cannot deactivate the standard resource. Choose another standard resource first." ) ); + KMessageBox::sorry( this, i18n( "You cannot deactivate the<br>standard resource. Choose<br>another standard resource first." ) ); configItem->setOn( true ); return; } @@ -478,33 +503,33 @@ void ConfigPage::saveResourceSettings() { qDebug("ConfigPage::saveResourceSettings() begin"); if ( mCurrentManager ) { - + QListViewItem *item = mListView->firstChild(); while ( item ) { ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); // check if standard resource if ( configItem->standard() && !configItem->readOnly() && configItem->isOn() ) { - + mCurrentManager->setStandardResource( configItem->resource() ); } - + // check if active or passive resource configItem->resource()->setActive( configItem->isOn() ); item = item->nextSibling(); } mCurrentManager->writeConfig( mCurrentConfig ); if ( !mCurrentManager->standardResource() ) - KMessageBox::sorry( this, i18n( "There is no valid standard resource! Please select one which is neither read-only nor inactive." ) ); + KMessageBox::sorry( this, i18n( "There is no valid standard resource!<br>Please select one which is neither read-only nor inactive." ) ); } - + qDebug("ConfigPage::saveResourceSettings() end"); - + } //US #include "configpage.moc" diff --git a/microkde/kresources/configpage.h b/microkde/kresources/configpage.h index 492ea54..be9239e 100644 --- a/microkde/kresources/configpage.h +++ b/microkde/kresources/configpage.h @@ -95,8 +95,9 @@ class ConfigPage : public QWidget, public ManagerListener<Resource> QPushButton* mEditButton; QPushButton* mStandardButton; QListViewItem* mLastItem; + static const QString syncfamily; }; } diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp index f82e94c..7a5c2f6 100644 --- a/microkde/kresources/factory.cpp +++ b/microkde/kresources/factory.cpp @@ -38,9 +38,9 @@ using namespace KRES; QDict<Factory> *Factory::mSelves = 0; static KStaticDeleter< QDict<Factory> > staticDeleter; -Factory *Factory::self( const QString& resourceFamily ) +Factory *Factory::self( const QString& resourceFamily) { Factory *factory = 0; @@ -51,16 +51,16 @@ Factory *Factory::self( const QString& resourceFamily ) factory = mSelves->find( resourceFamily ); if ( !factory ) { - factory = new Factory( resourceFamily ); + factory = new Factory( resourceFamily); mSelves->insert( resourceFamily, factory ); } return factory; } -Factory::Factory( const QString& resourceFamily ) : +Factory::Factory( const QString& resourceFamily) : mResourceFamily( resourceFamily ) { //US so far we have three types available for resourceFamily "contact" // and that are "file", "dir", "ldap" @@ -186,8 +186,42 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) return wdg; } +SyncWidget *Factory::syncWidget( 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::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 ); + 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(); @@ -210,9 +244,9 @@ QString Factory::typeDescription( const QString &type ) const PluginInfo* pi = mTypeMap[ type ]; return pi->descriptionLabel; } -Resource *Factory::resource( const QString& type, const KConfig *config ) +Resource *Factory::resource( const QString& type, const KConfig *config, bool syncable ) { if ( type.isEmpty() || !mTypeMap.contains( type ) ) @@ -241,9 +275,9 @@ Resource *Factory::resource( const QString& type, const KConfig *config ) kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; return 0; } - Resource *resource = pluginFactory->resource( config ); + Resource *resource = pluginFactory->resource( config, syncable ); if ( !resource ) { //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; qDebug("%s is not a %s plugin.", pi->library.latin1(), mResourceFamily.latin1()); return 0; diff --git a/microkde/kresources/factory.h b/microkde/kresources/factory.h index ad67ab3..a265bc8 100644 --- a/microkde/kresources/factory.h +++ b/microkde/kresources/factory.h @@ -33,9 +33,9 @@ #include "resource.h" namespace KRES { -//US +//US struct PluginInfo { QString library; QString nameLabel; @@ -64,9 +64,9 @@ struct PluginInfo class Factory { public: - + /** * Returns the global resource factory. */ static Factory *self( const QString& resourceFamily ); @@ -77,22 +77,34 @@ class 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 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 ); + + /** * 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 ); + Resource *resource( const QString& type, const KConfig *config, bool syncable ); /** * Returns a list of all available resource types. */ @@ -108,17 +120,17 @@ class Factory */ QString typeDescription( const QString &type ) const; protected: - Factory( const QString& resourceFamily ); + Factory( const QString& resourceFamily); private: static QDict<Factory> *mSelves; QString mResourceFamily; //US QMap<QString, KService::Ptr> mTypeMap; -//US lets store the pluginfo struct as value instead of a KService - QMap<QString, PluginInfo*> mTypeMap; +//US lets store the pluginfo struct as value instead of a KService + QMap<QString, PluginInfo*> mTypeMap; }; } #endif |