-rw-r--r-- | microkde/kresources/configdialog.cpp | 55 | ||||
-rw-r--r-- | microkde/kresources/configdialog.h | 2 | ||||
-rw-r--r-- | microkde/kresources/configpage.cpp | 43 | ||||
-rw-r--r-- | microkde/kresources/configpage.h | 1 | ||||
-rw-r--r-- | microkde/kresources/factory.cpp | 38 | ||||
-rw-r--r-- | microkde/kresources/factory.h | 14 | ||||
-rw-r--r-- | microkde/microkdeE.pro | 2 |
7 files changed, 136 insertions, 19 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 @@ -40,12 +40,14 @@ #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 ); @@ -62,12 +64,14 @@ ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, generalGroupBox->setTitle( i18n( "General Settings" ) ); - new QLabel( i18n( "Name:" ), generalGroupBox ); + 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() ); - mReadOnly->setChecked( mResource->readOnly() ); mainLayout->addWidget( generalGroupBox ); @@ -93,4 +97,24 @@ ConfigDialog::ConfigDialog( QWidget *parent, const QString& resourceFamily, } + 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 &))); @@ -107,4 +131,8 @@ void ConfigDialog::setInEditMode( bool value ) if ( mConfigWidget ) mConfigWidget->setInEditMode( value ); + + if ( mSyncWidget ) + mSyncWidget->setInEditMode( value ); + } @@ -116,4 +144,6 @@ void ConfigDialog::slotNameChanged( const QString &text) void ConfigDialog::setReadOnly( bool value ) { + if (!mResource->isSyncable()) { + if (mPersistentReadOnly == false) mReadOnly->setChecked( value ); @@ -121,7 +151,10 @@ void ConfigDialog::setReadOnly( bool value ) mReadOnly->setChecked( true ); } +} void ConfigDialog::setPersistentReadOnly( bool value ) { + if (!mResource->isSyncable()) { + mPersistentReadOnly = value; @@ -130,5 +163,5 @@ void ConfigDialog::setPersistentReadOnly( bool value ) mReadOnly->setEnabled( !value ); - + } } @@ -136,9 +169,10 @@ 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() ); + if (!mResource->isSyncable()) mResource->setReadOnly( mReadOnly->isChecked() ); @@ -149,4 +183,11 @@ void ConfigDialog::accept() } + if ( mSyncWidget ) { + // First save generic information + // Also save setting of specific resource type + mSyncWidget->saveSettings( mResource ); + } + + KDialog::accept(); } 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 @@ -32,4 +32,5 @@ namespace KRES { class Resource; class ConfigWidget; + class SyncWidget; class ConfigDialog : public KDialogBase @@ -51,4 +52,5 @@ class ConfigDialog : public KDialogBase private: ConfigWidget *mConfigWidget; + SyncWidget *mSyncWidget; Resource* mResource; 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 @@ -22,4 +22,11 @@ */ +/* +Enhanced Version of the file for platform independent KDE tools. +Copyright (c) 2004 Ulf Schenk + +$Id$ +*/ + #include <qgroupbox.h> #include <qinputdialog.h> @@ -51,4 +58,7 @@ using namespace KRES; +const QString ConfigPage::syncfamily = "syncprofiles"; + + class ConfigViewItem : public QCheckListItem { @@ -165,5 +175,7 @@ void ConfigPage::load() //US QString family = tmp.toString(); QStringList families; - families << "contact" << "sync-contacts"; + families << "contact" << syncfamily; + + for ( QStringList::Iterator it = families.begin(); it != families.end(); ++it ) { @@ -171,5 +183,5 @@ void ConfigPage::load() if ( !family.isEmpty() ) { if ( !mFamilyMap.contains( family ) ) { - mCurrentManager = new Manager<Resource>( family ); + mCurrentManager = new Manager<Resource>( family, (family == syncfamily) ); if ( mCurrentManager ) { mFamilyMap.append( family ); @@ -266,5 +278,5 @@ void ConfigPage::slotFamilyChanged( int pos ) 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" ); @@ -284,7 +296,20 @@ void ConfigPage::slotAdd() QStringList descs = mCurrentManager->resourceTypeDescriptions(); bool ok = false; - QString desc = QInputDialog::getItem( i18n( "Resource Configuration" ), + + 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; @@ -381,5 +406,5 @@ void ConfigPage::slotEdit() 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 ); } @@ -400,10 +425,10 @@ void ConfigPage::slotStandard() 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; } @@ -465,5 +490,5 @@ void ConfigPage::slotItemClicked( QListViewItem *item ) 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; @@ -500,5 +525,5 @@ void ConfigPage::saveResourceSettings() 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." ) ); } 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 @@ -97,4 +97,5 @@ class ConfigPage : public QWidget, public ManagerListener<Resource> 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 @@ -188,4 +188,38 @@ ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent ) } +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 { @@ -212,5 +246,5 @@ QString Factory::typeDescription( const QString &type ) const } -Resource *Factory::resource( const QString& type, const KConfig *config ) +Resource *Factory::resource( const QString& type, const KConfig *config, bool syncable ) { @@ -243,5 +277,5 @@ Resource *Factory::resource( const QString& type, const KConfig *config ) } - Resource *resource = pluginFactory->resource( config ); + Resource *resource = pluginFactory->resource( config, syncable ); if ( !resource ) { //US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl; 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 @@ -85,4 +85,15 @@ class Factory /** + * 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. @@ -91,6 +102,7 @@ class Factory * @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 ); /** diff --git a/microkde/microkdeE.pro b/microkde/microkdeE.pro index ec2b1f7..b664c9a 100644 --- a/microkde/microkdeE.pro +++ b/microkde/microkdeE.pro @@ -90,4 +90,5 @@ osmartpointer.h \ kresources/configdialog.h \ kresources/kcmkresources.h \ + kresources/syncwidget.h \ kdecore/kmdcodec.h \ kdecore/kconfigbase.h \ @@ -170,4 +171,5 @@ oprocess.cpp \ kresources/resource.cpp \ kresources/selectdialog.cpp \ + kresources/syncwidget.cpp \ kutils/kcmultidialog.cpp |