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 /microkde/kresources | |
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-- | 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 |
7 files changed, 97 insertions, 27 deletions
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 @@ -1,65 +1,67 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.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_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 @@ -112,322 +112,331 @@ ConfigPage::ConfigPage( QWidget *parent, const char *name ) mListView->setAllColumnsShowFocus( true ); mListView->addColumn( i18n( "Name" ) ); mListView->addColumn( i18n( "Type" ) ); mListView->addColumn( i18n( "Standard" ) ); //US groupBoxLayout->addWidget( mListView, 1, 0 ); groupBoxLayout->addMultiCellWidget( mListView, 1, 1, 0, 1 ); mAddButton = new QPushButton( i18n( "&Add..." ), this ); groupBoxLayout->addWidget( mAddButton, 2, 0 ); mRemoveButton = new QPushButton( i18n( "&Remove" ), this ); groupBoxLayout->addWidget( mRemoveButton, 2, 1 ); mEditButton = new QPushButton( i18n( "&Edit..." ), this ); groupBoxLayout->addWidget( mEditButton, 3, 0 ); mStandardButton = new QPushButton( i18n( "&Use as Standard" ), this ); groupBoxLayout->addWidget( mStandardButton, 3, 1 ); mRemoveButton->setEnabled( false ); mEditButton->setEnabled( false ); mStandardButton->setEnabled( false ); connect( mAddButton, SIGNAL( clicked() ), SLOT(slotAdd()) ); connect( mRemoveButton, SIGNAL( clicked() ), SLOT(slotRemove()) ); connect( mEditButton, SIGNAL( clicked() ), SLOT(slotEdit()) ); connect( mStandardButton, SIGNAL( clicked() ), SLOT(slotStandard()) ); mainLayout->addWidget( groupBox ); connect( mFamilyCombo, SIGNAL( activated( int ) ), SLOT( slotFamilyChanged( int ) ) ); connect( mListView, SIGNAL( selectionChanged() ), SLOT( slotSelectionChanged() ) ); connect( mListView, SIGNAL( clicked( QListViewItem * ) ), SLOT( slotItemClicked( QListViewItem * ) ) ); mLastItem = 0; //US mConfig = new KConfig( "kcmkresourcesrc" ); mConfig = new KConfig( locateLocal( "config", "kcmkresourcesrc") ); mConfig->setGroup( "General" ); load(); } ConfigPage::~ConfigPage() { QValueList<ResourcePageInfo>::Iterator it; for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) { (*it).mManager->removeListener( this ); delete (*it).mManager; delete (*it).mConfig; } mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() ); delete mConfig; mConfig = 0; } void ConfigPage::load() { kdDebug(5650) << "ConfigPage::load()" << endl; 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() { } void ConfigPage::slotFamilyChanged( int pos ) { if ( pos < 0 || pos >= (int)mFamilyMap.count() ) return; saveResourceSettings(); mFamily = mFamilyMap[ pos ]; //US qDebug("ConfigPage::slotFamilyChanged 4 family=%s", mFamily.latin1()); mCurrentManager = mInfoMap[ pos ].mManager; mCurrentConfig = mInfoMap[ pos ].mConfig; if ( !mCurrentManager ) kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl; 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!<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; } } void ConfigPage::slotRemove() { if ( !mCurrentManager ) return; QListViewItem *item = mListView->currentItem(); ConfigViewItem *confItem = static_cast<ConfigViewItem*>( item ); if ( !confItem ) return; if ( confItem->standard() ) { KMessageBox::sorry( this, i18n( "You cannot remove your standard resource!\n Please select a new standard resource first." ) ); return; } mCurrentManager->remove( confItem->resource() ); if ( item == mLastItem ) mLastItem = 0; mListView->takeItem( item ); delete item; emit changed( true ); } void ConfigPage::slotEdit() { if ( !mCurrentManager ) return; QListViewItem *item = mListView->currentItem(); ConfigViewItem *configItem = static_cast<ConfigViewItem*>( item ); if ( !configItem ) return; Resource *resource = configItem->resource(); ConfigDialog dlg( this, mFamily, resource, "KRES::ConfigDialog" ); if ( dlg.exec() ) { 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<br> resource as standard!" ) ); configItem->setStandard( false ); } mCurrentManager->resourceChanged( resource ); emit changed( true ); } } void ConfigPage::slotStandard() { if ( !mCurrentManager ) return; ConfigViewItem *item = static_cast<ConfigViewItem*>( mListView->currentItem() ); if ( !item ) 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 @@ -94,196 +94,196 @@ Factory::Factory( const QString& resourceFamily) : info->nameLabel = i18n( "ldap" ); info->descriptionLabel = i18n( "No description available" ); mTypeMap.insert( "ldap", info ); //US add opie plugin only, if the library exists. QString libname = "microkabc_opie"; QString path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); if ( !path.isEmpty() ) { info = new PluginInfo; info->library = libname; info->nameLabel = i18n( "opie" ); info->descriptionLabel = i18n( "Opie PIM Addressbook." ); mTypeMap.insert( "opie", info ); } //US add qtopia plugin only, if the library exists. libname = "microkabc_qtopia"; path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); if ( !path.isEmpty() ) { info = new PluginInfo; info->library = libname; info->nameLabel = i18n( "qtopia" ); info->descriptionLabel = i18n( "Qtopia PIM Addressbook." ); mTypeMap.insert( "qtopia", info ); } //US add sharp plugin only, if the library exists. libname = "microkabc_sharpdtm"; path = KLibLoader::findLibrary( QFile::encodeName( libname ) ); if ( !path.isEmpty() ) { info = new PluginInfo; info->library = libname; info->nameLabel = i18n( "sharp" ); info->descriptionLabel = i18n( "Sharp DTM Addressbook." ); mTypeMap.insert( "sharp", info ); } } Factory::~Factory() { } QStringList Factory::typeNames() const { //US method QMap::keys() not available yet. SO collect the data manually //US return mTypeMap.keys(); QStringList result; QMap<QString, PluginInfo*>::ConstIterator it; for( it = mTypeMap.begin(); it != mTypeMap.end(); ++it ) { result << it.key().latin1(); // qDebug("Factory::typeNames() : %s ", it.key().latin1()); } return result; } 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; } Resource *Factory::resource( const QString& type, const KConfig *config, bool syncable ) { if ( type.isEmpty() || !mTypeMap.contains( type ) ) return 0; /*US load the lib not dynamicly. !! KService::Ptr ptr = mTypeMap[ type ]; KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() ); if ( !factory ) { kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; return 0; } */ PluginInfo* pi = mTypeMap[ type ]; KLibFactory *factory = (KLibFactory *)KLibLoader::self()->factory( pi->library.latin1() ); if ( !factory ) { qDebug("KRES::Factory::resource(): Factory creation failed for library %s", pi->library.latin1()); kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl; return 0; } PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory ); if ( !pluginFactory ) { qDebug("KRES::Factory::resource(): no plugin factory for library %s", pi->library.latin1()); kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl; return 0; } 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; } resource->setType( type ); return resource; } 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 @@ -1,136 +1,139 @@ /* 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. */ #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; QString mResourceFamily; //US QMap<QString, KService::Ptr> mTypeMap; //US lets store the pluginfo struct as value instead of a KService QMap<QString, PluginInfo*> mTypeMap; }; } #endif 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 @@ -1,139 +1,139 @@ /* This file is part of libkresources Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org> Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.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_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> * <li>Provide a .desktop file so that the new resource type can be found * automatically by the ResourceManager</li> * </ul> * * Example: * <B>resourceexample.h</B>: <pre> #include <kconfig.h> #include <kresources/resource.h> class ResourceExample : public KRES::ResourceExample { public: ResourceExample( const KConfig * ); ~ResourceCalendarExchange(); void writeConfig( KConfig *config ); private: QString mLocation; QString mPassword; } </pre> <B>resourceexample.cpp</B>: <pre> #include <kconfig.h> #include "resourceexample.h" ResourceExample::ResourceExample( const KConfig *config ) : Resource( config ) { if ( config ) { mLocation = config->readEntry( "Location" ); mPassword = KStringHandler::obscure( config->readEntry( "Password" ) ); } else { mLocation = ""; // Or some sensible default mPassword = ""; } } void ResourceExample::writeConfig( KConfig *config ) { KRES::Resource::writeConfig( config ); config->writeEntry( "Location", mLocation ); config->writeEntry( "Password", KStringHandler::obscure( mPassword ) ); } extern "C" { KRES::ResourceExample *config_widget( QWidget *parent ) { return new ResourceExampleConfig( parent, "Configure Example Resource" ); } KRES::Resource *resource( const KConfig *config ) { return new ResourceExample( config ); } } </pre> * <B>resourceexampleconfig.h</B>: <pre> #include <klineedit.h> #include <kresources/resourceconfigwidget.h> #include "resourceexample.h" @@ -285,132 +285,132 @@ class Resource : public QObject * Returns whether the resource is open or not. */ bool isOpen() const; /** * Returns a unique identifier. The identifier is unique for this resource. * It is created when the resource is first created, and it is retained * in the resource family configuration file for this resource. * @return This resource's identifier */ QString identifier() const; /** * Returns the type of this resource. */ QString type() const; /** * Mark the resource as read-only. You can override this method, * but also remember to call Resource::setReadOnly(). */ virtual void setReadOnly( bool value ); /** * Returns, if the resource is read-only. */ virtual bool readOnly() const; /** * Set the name of resource.You can override this method, * but also remember to call Resource::setResourceName(). */ virtual void setResourceName( const QString &name ); /** * Returns the name of resource. */ virtual QString resourceName() const; virtual bool isSyncable() const = 0; /** Sets, if the resource is active. */ void setActive( bool active ); /** Return true, if the resource is active. */ bool isActive() const; friend class Factory; friend class ManagerImpl; /** Print resource information as debug output. */ virtual void dump() const; protected: /** * 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 @@ -1,62 +1,72 @@ /* This file is part of libkresources. Copyright (c) 2004 Ulf Schenk This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #ifndef KRESOURCES_SYNCWIDGET_H #define KRESOURCES_SYNCWIDGET_H #include <qwidget.h> #include <kconfig.h> #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 |