summaryrefslogtreecommitdiffabout
path: root/microkde/kresources
Side-by-side diff
Diffstat (limited to 'microkde/kresources') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/configdialog.cpp137
-rw-r--r--microkde/kresources/configdialog.h60
-rw-r--r--microkde/kresources/configpage.cpp507
-rw-r--r--microkde/kresources/configpage.h103
-rw-r--r--microkde/kresources/configwidget.cpp45
-rw-r--r--microkde/kresources/configwidget.h59
-rw-r--r--microkde/kresources/factory.cpp216
-rw-r--r--microkde/kresources/factory.h113
-rw-r--r--microkde/kresources/kcmkresources.cpp89
-rw-r--r--microkde/kresources/kcmkresources.h54
-rw-r--r--microkde/kresources/manager.h332
-rw-r--r--microkde/kresources/managerimpl.cpp353
-rw-r--r--microkde/kresources/managerimpl.h113
-rw-r--r--microkde/kresources/resource.cpp185
-rw-r--r--microkde/kresources/resource.h401
-rw-r--r--microkde/kresources/resourceselectdialog.h12
-rw-r--r--microkde/kresources/selectdialog.cpp154
-rw-r--r--microkde/kresources/selectdialog.h92
18 files changed, 3025 insertions, 0 deletions
diff --git a/microkde/kresources/configdialog.cpp b/microkde/kresources/configdialog.cpp
new file mode 100644
index 0000000..48d9137
--- a/dev/null
+++ b/microkde/kresources/configdialog.cpp
@@ -0,0 +1,137 @@
+/*
+ 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 <qcheckbox.h>
+
+#include <kbuttonbox.h>
+#include <kdialog.h>
+#include <klineedit.h>
+
+#include "factory.h"
+#include "configwidget.h"
+#include "configdialog.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 )
+{
+ 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();
+
+ 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( i18n( "Name:" ), generalGroupBox );
+
+ mName = new KLineEdit( generalGroupBox );
+
+ mReadOnly = new QCheckBox( i18n( "Read-only" ), generalGroupBox );
+
+ mName->setText( mResource->resourceName() );
+ mReadOnly->setChecked( mResource->readOnly() );
+
+ 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 ) {
+ mConfigWidget->setInEditMode( false );
+ mConfigWidget->loadSettings( mResource );
+ mConfigWidget->show();
+ connect( mConfigWidget, SIGNAL( setReadOnly( bool ) ),
+ SLOT( setReadOnly( bool ) ) );
+ }
+
+ 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 );
+}
+
+void ConfigDialog::slotNameChanged( const QString &text)
+{
+ enableButtonOK( !text.isEmpty() );
+}
+
+void ConfigDialog::setReadOnly( bool value )
+{
+ mReadOnly->setChecked( value );
+}
+
+void ConfigDialog::accept()
+{
+ if ( mName->text().isEmpty() ) {
+ KMessageBox::sorry( this, i18n( "Please enter a resource name" ) );
+ return;
+ }
+
+ mResource->setResourceName( mName->text() );
+ mResource->setReadOnly( mReadOnly->isChecked() );
+
+ if ( mConfigWidget ) {
+ // First save generic information
+ // Also save setting of specific resource type
+ mConfigWidget->saveSettings( mResource );
+ }
+
+ KDialog::accept();
+}
+
+//US #include "configdialog.moc"
diff --git a/microkde/kresources/configdialog.h b/microkde/kresources/configdialog.h
new file mode 100644
index 0000000..6acc5d9
--- a/dev/null
+++ b/microkde/kresources/configdialog.h
@@ -0,0 +1,60 @@
+/*
+ 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 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 slotNameChanged( const QString &text);
+
+ private:
+ ConfigWidget *mConfigWidget;
+ Resource* mResource;
+
+ KLineEdit *mName;
+ QCheckBox *mReadOnly;
+};
+
+}
+
+#endif
diff --git a/microkde/kresources/configpage.cpp b/microkde/kresources/configpage.cpp
new file mode 100644
index 0000000..0f1469d
--- a/dev/null
+++ b/microkde/kresources/configpage.cpp
@@ -0,0 +1,507 @@
+/*
+ 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 <qgroupbox.h>
+#include <qinputdialog.h>
+#include <qlabel.h>
+#include <qlayout.h>
+
+#include <kapplication.h>
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+#include <kurlrequester.h>
+#include <klistview.h>
+#include <kbuttonbox.h>
+//US #include <ktrader.h>
+
+#include "resource.h"
+#include "configdialog.h"
+
+#include "configpage.h"
+
+//US
+#include <qpushbutton.h>
+#include <qfile.h>
+#include <kglobal.h>
+
+using namespace KRES;
+
+class ConfigViewItem : public QCheckListItem
+{
+ public:
+ ConfigViewItem( QListView *parent, Resource* resource ) :
+ QCheckListItem( parent, resource->resourceName(), CheckBox ),
+ mResource( resource ),
+ mIsStandard( false )
+ {
+ setText( 1, mResource->type() );
+ setOn( mResource->isActive() );
+ }
+
+ void setStandard( bool value )
+ {
+ setText( 2, ( value ? i18n( "Yes" ) : QString::null ) );
+ mIsStandard = value;
+ }
+
+ bool standard() const { return mIsStandard; }
+ bool readOnly() const { return mResource->readOnly(); }
+
+ Resource *resource() { return mResource; }
+
+ private:
+ Resource* mResource;
+
+ bool mIsStandard;
+};
+
+ConfigPage::ConfigPage( QWidget *parent, const char *name )
+ : QWidget( parent, name ),
+ mCurrentManager( 0 ),
+ mCurrentConfig( 0 )
+{
+ setCaption( i18n( "Resource Configuration" ) );
+
+ QVBoxLayout *mainLayout = new QVBoxLayout( this );
+
+ QGroupBox *groupBox = new QGroupBox( i18n( "Resources" ), this );
+ groupBox->setColumnLayout(0, Qt::Vertical );
+ groupBox->layout()->setSpacing( 6 );
+ groupBox->layout()->setMargin( 11 );
+ QGridLayout *groupBoxLayout = new QGridLayout( groupBox->layout(), 2, 2 );
+
+//US mFamilyCombo = new KComboBox( false, groupBox );
+ mFamilyCombo = new KComboBox( groupBox );
+ groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 );
+
+ mListView = new KListView( groupBox );
+ mListView->setAllColumnsShowFocus( true );
+ mListView->addColumn( i18n( "Name" ) );
+ mListView->addColumn( i18n( "Type" ) );
+ mListView->addColumn( i18n( "Standard" ) );
+
+ groupBoxLayout->addWidget( mListView, 1, 0 );
+
+ KButtonBox *buttonBox = new KButtonBox( groupBox, Vertical );
+ mAddButton = buttonBox->addButton( i18n( "&Add..." ), this, SLOT(slotAdd()) );
+ mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), this, SLOT(slotRemove()) );
+ mRemoveButton->setEnabled( false );
+ mEditButton = buttonBox->addButton( i18n( "&Edit..." ), this, SLOT(slotEdit()) );
+ mEditButton->setEnabled( false );
+ mStandardButton = buttonBox->addButton( i18n( "&Use as Standard" ), this, SLOT(slotStandard()) );
+ mStandardButton->setEnabled( false );
+ buttonBox->layout();
+
+ groupBoxLayout->addWidget( buttonBox, 1, 1 );
+
+ 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();
+
+ QString family = "contact";
+ if ( !family.isEmpty() ) {
+ if ( !mFamilyMap.contains( family ) ) {
+ mCurrentManager = new Manager<Resource>( family );
+ 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 {
+ QString configFile = locateLocal( "config", QString( "kresources/%1/stdrc" ).arg( family ) );
+ info.mConfig = new KConfig( configFile );
+ }
+ info.mManager->readConfig( info.mConfig );
+
+ mInfoMap.append( info );
+ }
+ }
+ }
+//US }
+ 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! 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 = 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 ) ];
+
+ // 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" );
+
+ 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 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 )
+ return;
+
+ if ( item->readOnly() ) {
+ KMessageBox::sorry( this, i18n( "You cannot use a read-only resource as standard!" ) );
+ return;
+ }
+
+ if ( !item->isOn() ) {
+ KMessageBox::sorry( this, i18n( "You cannot use an inactive resource as standard!" ) );
+ return;
+ }
+
+ QListViewItem *it = mListView->firstChild();
+ while ( it != 0 ) {
+ ConfigViewItem *configItem = static_cast<ConfigViewItem*>( it );
+ if ( configItem->standard() )
+ configItem->setStandard( false );
+ it = it->itemBelow();
+ }
+
+ item->setStandard( true );
+ mCurrentManager->setStandardResource( item->resource() );
+ emit changed( true );
+
+}
+
+void ConfigPage::slotSelectionChanged()
+{
+ bool state = ( mListView->currentItem() != 0 );
+
+ mRemoveButton->setEnabled( state );
+ mEditButton->setEnabled( state );
+ mStandardButton->setEnabled( state );
+}
+
+void ConfigPage::resourceAdded( Resource* resource )
+{
+ qDebug("ConfigPage::resourceAdded : %s", resource->resourceName().latin1());
+ kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName() << " )" << endl;
+ ConfigViewItem *item = new ConfigViewItem( mListView, resource );
+
+ // FIXME: this sucks. This should be in the config file,
+ // or application-dependent, in which case it's always Off
+ item->setOn( false );
+
+ mLastItem = item;
+
+ emit changed( true );
+}
+
+void ConfigPage::resourceModified( Resource* resource )
+{
+ qDebug("ConfigPage::resourceModified : %s", resource->resourceName().latin1());
+ kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName() << " )" << endl;
+}
+
+void ConfigPage::resourceDeleted( Resource* resource )
+{
+ qDebug("ConfigPage::resourceDeleted : %s", resource->resourceName().latin1());
+ kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName() << " )" << endl;
+}
+
+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." ) );
+ configItem->setOn( true );
+ return;
+ }
+
+ if ( configItem->isOn() != configItem->resource()->isActive() ) {
+ emit changed( true );
+ }
+}
+
+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." ) );
+ }
+
+ qDebug("ConfigPage::saveResourceSettings() end");
+
+}
+
+//US #include "configpage.moc"
+
diff --git a/microkde/kresources/configpage.h b/microkde/kresources/configpage.h
new file mode 100644
index 0000000..492ea54
--- a/dev/null
+++ b/microkde/kresources/configpage.h
@@ -0,0 +1,103 @@
+/*
+ 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_CONFIGPAGE_H
+#define KRESOURCES_CONFIGPAGE_H
+
+#include <qstringlist.h>
+#include <qwidget.h>
+
+#include "manager.h"
+
+class KComboBox;
+class KListView;
+
+class QListViewItem;
+class QPushButton;
+
+
+namespace KRES {
+
+class ResourcePageInfo
+{
+ public:
+ Manager<Resource> *mManager;
+ KConfig *mConfig;
+};
+
+class Resource;
+
+class ConfigPage : public QWidget, public ManagerListener<Resource>
+{
+ Q_OBJECT
+
+ public:
+ ConfigPage( QWidget *parent = 0, const char *name = 0 );
+ virtual ~ConfigPage();
+
+ void load();
+ void save();
+ virtual void defaults();
+
+ public slots:
+ void slotFamilyChanged( int );
+ void slotAdd();
+ void slotRemove();
+ void slotEdit();
+ void slotStandard();
+ void slotSelectionChanged();
+
+ // From ManagerListener<Resource>
+ public:
+ virtual void resourceAdded( Resource* resource );
+ virtual void resourceModified( Resource* resource );
+ virtual void resourceDeleted( Resource* resource );
+
+ protected slots:
+ void slotItemClicked( QListViewItem * );
+
+ signals:
+ void changed( bool );
+
+ private:
+ void saveResourceSettings();
+
+ Manager<Resource>* mCurrentManager;
+ KConfig* mCurrentConfig;
+ KConfig* mConfig;
+ QString mFamily;
+ QStringList mFamilyMap;
+ QValueList<ResourcePageInfo> mInfoMap;
+
+ KComboBox* mFamilyCombo;
+ KListView* mListView;
+ QPushButton* mAddButton;
+ QPushButton* mRemoveButton;
+ QPushButton* mEditButton;
+ QPushButton* mStandardButton;
+
+ QListViewItem* mLastItem;
+};
+
+}
+
+#endif
diff --git a/microkde/kresources/configwidget.cpp b/microkde/kresources/configwidget.cpp
new file mode 100644
index 0000000..c42cbd4
--- a/dev/null
+++ b/microkde/kresources/configwidget.cpp
@@ -0,0 +1,45 @@
+/*
+ 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 "configwidget.h"
+
+using namespace KRES;
+
+ConfigWidget::ConfigWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+}
+
+void ConfigWidget::setInEditMode( bool )
+{
+}
+
+void ConfigWidget::loadSettings( Resource * )
+{
+}
+
+void ConfigWidget::saveSettings( Resource * )
+{
+}
+
+//US #include "configwidget.moc"
diff --git a/microkde/kresources/configwidget.h b/microkde/kresources/configwidget.h
new file mode 100644
index 0000000..04dd696
--- a/dev/null
+++ b/microkde/kresources/configwidget.h
@@ -0,0 +1,59 @@
+/*
+ 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_CONFIGWIDGET_H
+#define KRESOURCES_CONFIGWIDGET_H
+
+#include <qwidget.h>
+
+#include <kconfig.h>
+
+#include "resource.h"
+
+namespace KRES {
+
+class ConfigWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ ConfigWidget( 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:
+ void setReadOnly( bool value );
+
+protected:
+ Resource* mResource;
+};
+
+}
+#endif
diff --git a/microkde/kresources/factory.cpp b/microkde/kresources/factory.cpp
new file mode 100644
index 0000000..709cd4a
--- a/dev/null
+++ b/microkde/kresources/factory.cpp
@@ -0,0 +1,216 @@
+/*
+ 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 <kdebug.h>
+#include <klocale.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+#include <kstaticdeleter.h>
+
+#include <qfile.h>
+
+#include <plugins/file/resourcefile.h>
+#include <plugins/file/resourcefileconfig.h>
+#include <plugins/dir/resourcedir.h>
+#include <plugins/dir/resourcedirconfig.h>
+//#include <plugins/ldap/resourceldap.h>
+//#include <plugins/ldap/resourceldapconfig.h>
+
+
+#include "resource.h"
+#include "factory.h"
+
+using namespace KRES;
+
+QDict<Factory> *Factory::mSelves = 0;
+static KStaticDeleter< QDict<Factory> > staticDeleter;
+
+Factory *Factory::self( const QString& resourceFamily )
+{
+ kdDebug(5650) << "Factory::self()" << endl;
+
+ Factory *factory = 0;
+ if ( !mSelves )
+ {
+ mSelves = staticDeleter.setObject( new QDict<Factory> );
+ }
+
+ factory = mSelves->find( resourceFamily );
+
+ if ( !factory ) {
+ factory = new Factory( resourceFamily );
+ mSelves->insert( resourceFamily, factory );
+ }
+
+ return factory;
+}
+
+Factory::Factory( const QString& resourceFamily ) :
+ mResourceFamily( resourceFamily )
+{
+//US so far we have three types available for resourceFamily "contact"
+// and that are "file", "dir", "ldap"
+/*US
+
+ KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", QString( "[X-KDE-ResourceFamily] == '%1'" )
+ .arg( resourceFamily ) );
+ KTrader::OfferList::ConstIterator it;
+ for ( it = plugins.begin(); it != plugins.end(); ++it ) {
+ QVariant type = (*it)->property( "X-KDE-ResourceType" );
+ if ( !type.toString().isEmpty() )
+ mTypeMap.insert( type.toString(), *it );
+ }
+*/
+
+//US !!!!!!!!!!!!!!!
+ KRES::PluginFactoryBase* pf = (KRES::PluginFactoryBase*)new KRES::PluginFactory<KABC::ResourceFile,KABC::ResourceFileConfig>();
+ mTypeMap.insert( "file", pf );
+
+ pf = (KRES::PluginFactoryBase*)new KRES::PluginFactory<KABC::ResourceDir,KABC::ResourceDirConfig>();
+ mTypeMap.insert( "dir", pf );
+ /*
+ pf = (KRES::PluginFactoryBase*)new KRES::PluginFactory<KABC::ResourceLDAP,KABC::ResourceLDAPConfig>();
+ mTypeMap.insert( "ldap", pf );
+ */
+}
+
+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, PluginFactoryBase*>::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 load the lib not dynamically. !!
+ KService::Ptr ptr = mTypeMap[ type ];
+ KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
+ if ( !factory ) {
+ kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
+ return 0;
+ }
+*/
+ PluginFactoryBase *factory = mTypeMap[ type ];
+ if ( !factory ) {
+ kdDebug() << "KRES::Factory::configWidget(): Factory creation failed" << endl;
+ return 0;
+ }
+
+
+ PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
+
+ if ( !pluginFactory ) {
+ 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;
+ kdDebug() << " is not a " + mResourceFamily + " plugin." << endl;
+ 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();
+//US I guess this is correct since we loaded the factory staticly.
+ return type;
+
+}
+
+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();
+//US I guess this is correct since we loaded the factory staticly.
+ return type;
+
+}
+
+Resource *Factory::resource( const QString& type, const KConfig *config )
+{
+ kdDebug() << "Factory::resource( " << type << ", config)" << endl;
+
+ 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;
+ }
+*/
+ PluginFactoryBase *factory = mTypeMap[ type ];
+ if ( !factory ) {
+ kdDebug() << "KRES::Factory::resource(): Factory creation failed" << endl;
+ return 0;
+ }
+
+ PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
+
+ if ( !pluginFactory ) {
+ kdDebug() << "KRES::Factory::resource(): no plugin factory." << endl;
+ return 0;
+ }
+
+ Resource *resource = pluginFactory->resource( config );
+ if ( !resource ) {
+//US kdDebug() << "'" << ptr->library() << "' is not a " + mResourceFamily + " plugin." << endl;
+ kdDebug() << " is not a " + mResourceFamily + " plugin." << endl;
+ return 0;
+ }
+
+ resource->setType( type );
+
+ return resource;
+}
diff --git a/microkde/kresources/factory.h b/microkde/kresources/factory.h
new file mode 100644
index 0000000..f391bb3
--- a/dev/null
+++ b/microkde/kresources/factory.h
@@ -0,0 +1,113 @@
+/*
+ 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 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 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.
+ */
+ Resource *resource( const QString& type, const KConfig *config );
+
+ /**
+ * 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;
+ QMap<QString, PluginFactoryBase*> mTypeMap;
+};
+
+}
+#endif
diff --git a/microkde/kresources/kcmkresources.cpp b/microkde/kresources/kcmkresources.cpp
new file mode 100644
index 0000000..d600a31
--- a/dev/null
+++ b/microkde/kresources/kcmkresources.cpp
@@ -0,0 +1,89 @@
+/*
+ This file is part of libkresources.
+
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <qlayout.h>
+
+//US #include <kaboutdata.h>
+//US #include <kgenericfactory.h>
+#include <klocale.h>
+
+#include "configpage.h"
+
+#include "kcmkresources.h"
+
+using namespace KRES;
+
+//US typedef KGenericFactory<KCMKResources, QWidget> ResourcesFactory;
+//US K_EXPORT_COMPONENT_FACTORY( kcm_kresources, ResourcesFactory( "kcmkresources" ) );
+
+//US KCMKResources::KCMKResources( QWidget *parent, const char *name, const QStringList& )
+//US : KCModule( ResourcesFactory::instance(), parent, name )
+KCMKResources::KCMKResources( QWidget *parent, const char *name, const QStringList& )
+ : KDialogBase( parent, name, true, i18n( "Configure Resources" ),
+ Ok|Cancel, Ok, true )
+{
+ QFrame *main = plainPage();
+
+ QVBoxLayout *layout = new QVBoxLayout( main );
+ mConfigPage = new KRES::ConfigPage( main );
+ layout->addWidget( mConfigPage );
+
+
+ connect( mConfigPage, SIGNAL( changed( bool ) ), SLOT( changed( bool ) ) );
+#ifndef DESKTOP_VERSION
+ showMaximized();
+#endif
+}
+
+void KCMKResources::changed( bool changed)
+{
+ modified = changed;
+}
+
+void KCMKResources::slotOk()
+{
+ if (modified) {
+ mConfigPage->save();
+ modified = false;
+ }
+
+ KDialogBase::slotOk();
+}
+
+void KCMKResources::load()
+{
+ qDebug("KCMKResources::load" );
+ mConfigPage->load();
+}
+
+void KCMKResources::save()
+{
+ qDebug("KCMKResources::save" );
+ mConfigPage->save();
+}
+
+void KCMKResources::defaults()
+{
+ qDebug("KCMKResources::defaults" );
+ mConfigPage->defaults();
+}
+
+//US #include "kcmkresources.moc"
diff --git a/microkde/kresources/kcmkresources.h b/microkde/kresources/kcmkresources.h
new file mode 100644
index 0000000..a83bb33
--- a/dev/null
+++ b/microkde/kresources/kcmkresources.h
@@ -0,0 +1,54 @@
+/*
+ This file is part of libkresources.
+
+ Copyright (c) 2003 Tobias Koenig <tokoe@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#ifndef KRESOURCES_KCMKRESOURCES_H
+#define KRESOURCES_KCMKRESOURCES_H
+
+#include <kdialogbase.h>
+
+namespace KRES {
+
+class ConfigPage;
+
+
+//US class KCMKResources : public KCModule
+class KCMKResources : public KDialogBase
+{
+ Q_OBJECT
+
+ public:
+ KCMKResources( QWidget *parent, const char *name, const QStringList& );
+
+ void load();
+ void save();
+ void defaults();
+
+ protected slots:
+ virtual void slotOk();
+ void changed( bool );
+
+ private:
+ KRES::ConfigPage *mConfigPage;
+ bool modified;
+};
+
+}
+#endif
diff --git a/microkde/kresources/manager.h b/microkde/kresources/manager.h
new file mode 100644
index 0000000..b5e97fc
--- a/dev/null
+++ b/microkde/kresources/manager.h
@@ -0,0 +1,332 @@
+/*
+ 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_MANAGER_H
+#define KRESOURCES_MANAGER_H
+
+#include <qdict.h>
+#include <qstringlist.h>
+
+#include "factory.h"
+#include "managerimpl.h"
+
+namespace KRES {
+
+class Resource;
+
+template<class T>
+class ManagerListener
+{
+ public:
+ virtual void resourceAdded( T *resource ) = 0;
+ virtual void resourceModified( T *resource ) = 0;
+ virtual void resourceDeleted( T *resource ) = 0;
+};
+
+// TODO:
+// The resource manager should provide some signals
+// to warn applications that resources have been added,
+// removed or modified.
+//
+// The manager should also keep track of which (or at least
+// how many) applications hve opened a resource, so that it
+// is only closed if none of them is using it any more
+
+template<class T>
+class Manager : private ManagerImplListener
+{
+ public:
+ class Iterator
+ {
+ friend class Manager;
+ public:
+ Iterator() {};
+ Iterator( const Iterator &it ) { mIt = it.mIt; }
+
+ T *operator*() { return static_cast<T *>( *mIt ); }
+ Iterator &operator++() { mIt++; return *this; }
+ Iterator &operator++(int) { mIt++; return *this; }
+ Iterator &operator--() { mIt--; return *this; }
+ Iterator &operator--(int) { mIt--; return *this; }
+ bool operator==( const Iterator &it ) { return mIt == it.mIt; }
+ bool operator!=( const Iterator &it ) { return mIt != it.mIt; }
+
+ private:
+ Resource::List::Iterator mIt;
+ };
+
+ Iterator begin()
+ {
+ Iterator it;
+ it.mIt = mImpl->resourceList()->begin();
+ return it;
+ }
+
+ Iterator end()
+ {
+ Iterator it;
+ it.mIt = mImpl->resourceList()->end();
+ return it;
+ }
+
+ class ActiveIterator
+ {
+ friend class Manager;
+ public:
+ ActiveIterator() : mList( 0 ) {};
+ ActiveIterator( const ActiveIterator &it )
+ {
+ mIt = it.mIt;
+ mList = it.mList;
+ }
+
+ T *operator*() { return static_cast<T *>( *mIt ); }
+ ActiveIterator &operator++()
+ {
+ do { mIt++; } while ( checkActive() );
+ return *this;
+ }
+ ActiveIterator &operator++(int)
+ {
+ do { mIt++; } while ( checkActive() );
+ return *this;
+ }
+ ActiveIterator &operator--()
+ {
+ do { mIt--; } while ( checkActive() );
+ return *this;
+ }
+ ActiveIterator &operator--(int)
+ {
+ do { mIt--; } while ( checkActive() );
+ return *this;
+ }
+ bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; }
+ bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; }
+
+ private:
+ /**
+ Check if iterator needs to be advanced once more.
+ */
+ bool checkActive()
+ {
+ if ( !mList || mIt == mList->end() ) return false;
+ return !(*mIt)->isActive();
+ }
+
+ Resource::List::Iterator mIt;
+ Resource::List *mList;
+ };
+
+ ActiveIterator activeBegin()
+ {
+ ActiveIterator it;
+ it.mIt = mImpl->resourceList()->begin();
+ it.mList = mImpl->resourceList();
+ if ( it.mIt != mImpl->resourceList()->end() ) {
+ if ( !(*it)->isActive() ) it++;
+ }
+ return it;
+ }
+
+ ActiveIterator activeEnd()
+ {
+ ActiveIterator it;
+ it.mIt = mImpl->resourceList()->end();
+ it.mList = mImpl->resourceList();
+ return it;
+ }
+
+ bool isEmpty() const { return mImpl->resourceList()->isEmpty(); }
+
+ Manager( const QString &family )
+ {
+ mFactory = Factory::self( family );
+ // The managerimpl will use the same Factory object as the manager
+ // because of the Factory::self() pattern
+ mImpl = new ManagerImpl( family );
+ mImpl->setListener( this );
+
+ mListeners = new QPtrList<ManagerListener<T> >;
+ }
+
+ virtual ~Manager()
+ {
+ mImpl->setListener( 0 );
+ delete mListeners;
+ delete mImpl;
+ }
+
+ /**
+ Recreate Resource objects from configuration file. If cfg is 0, read standard
+ configuration file.
+ */
+ void readConfig( KConfig *cfg = 0 )
+ {
+ mImpl->readConfig( cfg );
+ }
+
+ /**
+ Write configuration of Resource objects to configuration file. If cfg is 0, write
+ to standard configuration file.
+ */
+ void writeConfig( KConfig *cfg = 0 )
+ {
+ mImpl->writeConfig( cfg );
+ }
+
+ /**
+ Add resource to manager. This passes ownership of the Resource object
+ to the manager.
+ */
+ void add( Resource *resource )
+ {
+ if ( resource ) mImpl->add( resource );
+ }
+
+ void remove( Resource *resource )
+ {
+ if ( resource ) mImpl->remove( resource );
+ }
+
+ T* standardResource()
+ {
+ return static_cast<T *>( mImpl->standardResource() );
+ }
+
+ void setStandardResource( T *resource )
+ {
+ if ( resource ) mImpl->setStandardResource( resource );
+ }
+
+ void setActive( Resource *resource, bool active )
+ {
+ if ( resource ) mImpl->setActive( resource, active );
+ }
+
+ /**
+ Returns a list of the names of the reources managed by the
+ Manager for this family.
+ */
+ QStringList resourceNames() const
+ {
+ return mImpl->resourceNames();
+ }
+
+ ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 )
+ {
+ return mFactory->resourceConfigWidget( type, parent );
+ }
+
+ /**
+ Creates a new resource of type @param type, with default
+ settings. The resource is
+ not added to the manager, the application has to do that.
+ Returns a pointer to a resource object or a null pointer
+ if resource type doesn't exist.
+
+ @param type The type of the resource, one of those returned
+ by @ref resourceTypeNames()
+ */
+ T *createResource( const QString& type )
+ {
+ return (T *)( mFactory->resource( type, 0 ) );
+ }
+
+ /**
+ Returns a list of the names of all available resource types.
+ */
+ QStringList resourceTypeNames() const
+ {
+ return mFactory->typeNames();
+ }
+
+ QStringList resourceTypeDescriptions() const
+ {
+ QStringList typeDescs;
+ QStringList types = mFactory->typeNames();
+
+ for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) {
+ QString desc = mFactory->typeName( *it );
+ if ( !mFactory->typeDescription( *it ).isEmpty() )
+ desc += " (" + mFactory->typeDescription( *it ) + ")";
+
+ typeDescs.append( desc );
+ }
+
+ return typeDescs;
+ }
+
+ void resourceChanged( T *resource )
+ {
+ mImpl->resourceChanged( resource );
+ }
+
+ void addListener( ManagerListener<T> *listener )
+ {
+ mListeners->append( listener );
+ }
+
+ void removeListener( ManagerListener<T> *listener )
+ {
+ mListeners->remove( listener );
+ }
+
+ virtual void resourceAdded( Resource *res )
+ {
+ kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl;
+ T* resource = (T *)( res );
+ ManagerListener<T> *listener;
+ for ( listener = mListeners->first(); listener; listener = mListeners->next() )
+ listener->resourceAdded( resource );
+ }
+
+ virtual void resourceModified( Resource *res )
+ {
+ kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl;
+ T* resource = (T *)( res );
+ ManagerListener<T> *listener;
+ for ( listener = mListeners->first(); listener; listener = mListeners->next() )
+ listener->resourceModified( resource );
+ }
+
+ virtual void resourceDeleted( Resource *res )
+ {
+ kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl;
+ T* resource = (T *)( res );
+ ManagerListener<T> *listener;
+ for ( listener = mListeners->first(); listener; listener = mListeners->next() ) {
+ kdDebug(5650) << "Notifying a listener to Manager..." << endl;
+ listener->resourceDeleted( resource );
+ }
+ }
+
+ private:
+ ManagerImpl *mImpl;
+ Factory *mFactory;
+ QPtrList<ManagerListener<T> > *mListeners;
+};
+
+}
+
+#endif
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp
new file mode 100644
index 0000000..1baa6be
--- a/dev/null
+++ b/microkde/kresources/managerimpl.cpp
@@ -0,0 +1,353 @@
+/*
+ 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 <kglobal.h>
+
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kconfig.h>
+#include <kstandarddirs.h>
+
+#include "resource.h"
+#include "factory.h"
+#include "managerimpl.h"
+
+using namespace KRES;
+
+ManagerImpl::ManagerImpl( const QString &family )
+ : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
+ mFactory( 0 )
+
+{
+ kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
+
+
+}
+
+ManagerImpl::~ManagerImpl()
+{
+ kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl;
+
+ Resource::List::ConstIterator it;
+ for ( it = mResources.begin(); it != mResources.end(); ++it ) {
+ delete *it;
+ }
+
+ delete mStdConfig;
+}
+
+void ManagerImpl::createStandardConfig()
+{
+ if ( !mStdConfig ) {
+ QString file = locateLocal( "data", KGlobal::getAppName()
+ + "/kresources/" + mFamily + "rc" );
+ mStdConfig = new KConfig( file );
+ }
+
+ mConfig = mStdConfig;
+}
+
+void ManagerImpl::readConfig( KConfig *cfg )
+{
+ kdDebug(5650) << "ManagerImpl::readConfig()" << endl;
+
+ delete mFactory;
+ mFactory = Factory::self( mFamily );
+
+ if ( !cfg ) {
+ createStandardConfig();
+ } else {
+ mConfig = cfg;
+ }
+
+ mStandard = 0;
+
+ mConfig->setGroup( "General" );
+
+ QStringList keys = mConfig->readListEntry( "ResourceKeys" );
+ keys += mConfig->readListEntry( "PassiveResourceKeys" );
+
+ QString standardKey = mConfig->readEntry( "Standard" );
+
+ for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
+ readResourceConfig( *it, false );
+ }
+
+}
+
+void ManagerImpl::writeConfig( KConfig *cfg )
+{
+//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
+
+
+ kdDebug(5650) << "ManagerImpl::writeConfig()" << endl;
+
+ if ( !cfg ) {
+ createStandardConfig();
+ } else {
+ mConfig = cfg;
+ }
+
+ QStringList activeKeys;
+ QStringList passiveKeys;
+
+ // First write all keys, collect active and passive keys on the way
+ Resource::List::Iterator it;
+ for ( it = mResources.begin(); it != mResources.end(); ++it ) {
+ writeResourceConfig( *it, false );
+
+ QString key = (*it)->identifier();
+ if( (*it)->isActive() )
+ activeKeys.append( key );
+ else
+ passiveKeys.append( key );
+ }
+
+ // And then the general group
+
+ kdDebug(5650) << "Saving general info" << endl;
+ mConfig->setGroup( "General" );
+ mConfig->writeEntry( "ResourceKeys", activeKeys );
+ mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
+ if ( mStandard )
+ mConfig->writeEntry( "Standard", mStandard->identifier() );
+ else
+ mConfig->writeEntry( "Standard", "" );
+
+ mConfig->sync();
+ kdDebug(5650) << "ManagerImpl::save() finished" << endl;
+
+//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
+
+}
+
+void ManagerImpl::add( Resource *resource, bool useDCOP )
+{
+qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
+
+ resource->setActive( true );
+
+ if ( mResources.isEmpty() ) {
+ mStandard = resource;
+ }
+
+ mResources.append( resource );
+
+ writeResourceConfig( resource, true );
+
+ qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
+
+}
+
+void ManagerImpl::remove( Resource *resource, bool useDCOP )
+{
+ if ( mStandard == resource ) mStandard = 0;
+ removeResource( resource );
+
+ mResources.remove( resource );
+
+ delete resource;
+
+ kdDebug(5650) << "Finished ManagerImpl::remove()" << endl;
+}
+
+void ManagerImpl::setActive( Resource *resource, bool active )
+{
+ if ( resource && resource->isActive() != active ) {
+ resource->setActive( active );
+ }
+}
+
+Resource *ManagerImpl::standardResource()
+{
+ return mStandard;
+}
+
+void ManagerImpl::setStandardResource( Resource *resource )
+{
+ mStandard = resource;
+}
+
+void ManagerImpl::resourceChanged( Resource *resource )
+{
+ writeResourceConfig( resource, true );
+
+
+// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() );
+// allManagers.dcopResourceModified( resource->identifier() );
+}
+
+// DCOP asynchronous functions
+//US since we work from inside the application, we call the methods directly.
+
+QStringList ManagerImpl::resourceNames()
+{
+ QStringList result;
+
+ Resource::List::ConstIterator it;
+ for ( it = mResources.begin(); it != mResources.end(); ++it ) {
+ result.append( (*it)->resourceName() );
+ }
+ return result;
+}
+
+Resource::List *ManagerImpl::resourceList()
+{
+ return &mResources;
+}
+
+QPtrList<Resource> ManagerImpl::resources()
+{
+ QPtrList<Resource> result;
+
+ Resource::List::ConstIterator it;
+ for ( it = mResources.begin(); it != mResources.end(); ++it ) {
+ result.append( *it );
+ }
+ return result;
+}
+
+QPtrList<Resource> ManagerImpl::resources( bool active )
+{
+ QPtrList<Resource> result;
+
+ Resource::List::ConstIterator it;
+ for ( it = mResources.begin(); it != mResources.end(); ++it ) {
+ if ( (*it)->isActive() == active ) {
+ result.append( *it );
+ }
+ }
+ return result;
+}
+
+void ManagerImpl::setListener( ManagerImplListener *listener )
+{
+ mListener = listener;
+}
+
+Resource* ManagerImpl::readResourceConfig( const QString& identifier,
+ bool checkActive )
+{
+ kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl;
+
+// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1());
+
+ mConfig->setGroup( "Resource_" + identifier );
+
+ QString type = mConfig->readEntry( "ResourceType" );
+ QString name = mConfig->readEntry( "ResourceName" );
+ Resource *resource = mFactory->resource( type, mConfig );
+ if ( !resource ) {
+ kdDebug(5650) << "Failed to create resource with id " << identifier << endl;
+ return 0;
+ }
+
+ if ( resource->identifier().isEmpty() )
+ resource->setIdentifier( identifier );
+
+ mConfig->setGroup( "General" );
+
+ QString standardKey = mConfig->readEntry( "Standard" );
+ if ( standardKey == identifier ) {
+ mStandard = resource;
+ }
+
+ if ( checkActive ) {
+ QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
+ resource->setActive( activeKeys.contains( identifier ) );
+ }
+ mResources.append( resource );
+
+ return resource;
+}
+
+void ManagerImpl::writeResourceConfig( Resource *resource,
+ bool checkActive )
+{
+ QString key = resource->identifier();
+
+ kdDebug(5650) << "Saving resource " << key << endl;
+
+ if ( !mConfig ) createStandardConfig();
+
+ mConfig->setGroup( "Resource_" + key );
+ resource->writeConfig( mConfig );
+
+ mConfig->setGroup( "General" );
+ QString standardKey = mConfig->readEntry( "Standard" );
+
+ if ( resource == mStandard && standardKey != key )
+ mConfig->writeEntry( "Standard", resource->identifier() );
+ else if ( resource != mStandard && standardKey == key )
+ mConfig->writeEntry( "Standard", "" );
+
+ if ( checkActive ) {
+ QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
+ if ( resource->isActive() && !activeKeys.contains( key ) ) {
+ activeKeys.append( resource->identifier() );
+ mConfig->writeEntry( "ResourceKeys", activeKeys );
+ } else if ( !resource->isActive() && activeKeys.contains( key ) ) {
+ activeKeys.remove( key );
+ mConfig->writeEntry( "ResourceKeys", activeKeys );
+ }
+ }
+
+ mConfig->sync();
+}
+
+void ManagerImpl::removeResource( Resource *resource )
+{
+ QString key = resource->identifier();
+
+ if ( !mConfig ) createStandardConfig();
+
+ mConfig->setGroup( "General" );
+ QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
+ if ( activeKeys.contains( key ) ) {
+ activeKeys.remove( key );
+ mConfig->writeEntry( "ResourceKeys", activeKeys );
+ } else {
+ QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" );
+ passiveKeys.remove( key );
+ mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
+ }
+
+ QString standardKey = mConfig->readEntry( "Standard" );
+ if ( standardKey == key ) {
+ mConfig->writeEntry( "Standard", "" );
+ }
+
+ mConfig->deleteGroup( "Resource_" + resource->identifier() );
+
+ mConfig->sync();
+}
+
+Resource* ManagerImpl::getResource( const QString& identifier )
+{
+ Resource::List::ConstIterator it;
+ for ( it = mResources.begin(); it != mResources.end(); ++it ) {
+ if ( (*it)->identifier() == identifier )
+ return *it;
+ }
+ return 0;
+}
diff --git a/microkde/kresources/managerimpl.h b/microkde/kresources/managerimpl.h
new file mode 100644
index 0000000..a049bcc
--- a/dev/null
+++ b/microkde/kresources/managerimpl.h
@@ -0,0 +1,113 @@
+/*
+ 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_MANAGERIMPL_H
+#define KRESOURCES_MANAGERIMPL_H
+
+#include <qstring.h>
+#include <qptrlist.h>
+#include <qdict.h>
+//US
+#include <qobject.h>
+
+#include "resource.h"
+
+
+class KConfig;
+
+namespace KRES {
+
+class Resource;
+class Factory;
+
+class ManagerImplListener
+{
+ public:
+ virtual void resourceAdded( Resource *resource ) = 0;
+ virtual void resourceModified( Resource *resource ) = 0;
+ virtual void resourceDeleted( Resource *resource ) = 0;
+};
+
+
+/**
+ @internal
+
+ Do not use this class directly. Use ResourceManager instead
+*/
+class ManagerImpl : public QObject
+{
+ Q_OBJECT
+ public:
+ ManagerImpl( const QString &family );
+ ~ManagerImpl();
+
+ void readConfig( KConfig * );
+ void writeConfig( KConfig * );
+
+ void add( Resource *resource, bool useDCOP = true );
+ void remove( Resource *resource, bool useDCOP = true );
+
+ Resource *standardResource();
+ void setStandardResource( Resource *resource );
+
+ void setActive( Resource *resource, bool active );
+
+ Resource::List *resourceList();
+
+ QPtrList<Resource> resources();
+
+ // Get only active or passive resources
+ QPtrList<Resource> resources( bool active );
+
+ QStringList resourceNames();
+
+ void setListener( ManagerImplListener *listener );
+
+ public slots:
+ void resourceChanged( Resource *resource );
+
+ private:
+ // dcop calls
+
+ private:
+ void createStandardConfig();
+
+ Resource *readResourceConfig( const QString& identifier, bool checkActive );
+ void writeResourceConfig( Resource *resource, bool checkActive );
+
+ void removeResource( Resource *resource );
+ Resource *getResource( Resource *resource );
+ Resource *getResource( const QString& identifier );
+
+ QString mFamily;
+ KConfig *mConfig;
+ KConfig *mStdConfig;
+ Resource *mStandard;
+ Factory *mFactory;
+ Resource::List mResources;
+ ManagerImplListener *mListener;
+};
+
+}
+
+#endif
diff --git a/microkde/kresources/resource.cpp b/microkde/kresources/resource.cpp
new file mode 100644
index 0000000..169eaa4
--- a/dev/null
+++ b/microkde/kresources/resource.cpp
@@ -0,0 +1,185 @@
+/*
+ This file is part of libkresources.
+
+ Copyright (c) 2001 Cornelius Schumacher <schumacher@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 <kdebug.h>
+#include <kapplication.h>
+#include <kconfig.h>
+
+#include "resource.h"
+
+using namespace KRES;
+
+class Resource::ResourcePrivate
+{
+ public:
+#ifdef QT_THREAD_SUPPORT
+ QMutex mMutex;
+#endif
+ int mOpenCount;
+ QString mType;
+ QString mIdentifier;
+ bool mReadOnly;
+ QString mName;
+ bool mActive;
+ bool mIsOpen;
+};
+
+Resource::Resource( const KConfig* config )
+ : QObject( 0, "" ), d( new ResourcePrivate )
+{
+ d->mOpenCount = 0;
+ d->mIsOpen = false;
+
+ //US compiler claimed that const discards qualifier
+ KConfig* cfg = (KConfig*)config;
+ if ( cfg ) {
+ d->mType = cfg->readEntry( "ResourceType" );
+ d->mName = cfg->readEntry( "ResourceName" );
+ d->mReadOnly = cfg->readBoolEntry( "ResourceIsReadOnly", false );
+ d->mActive = cfg->readBoolEntry( "ResourceIsActive", true );
+ d->mIdentifier = cfg->readEntry( "ResourceIdentifier" );
+ } else {
+ d->mType = "type";
+ d->mName = "resource-name";
+ d->mReadOnly = false;
+ d->mActive = true;
+ d->mIdentifier = KApplication::randomString( 10 );
+ }
+}
+
+Resource::~Resource()
+{
+ delete d;
+ d = 0;
+}
+
+void Resource::writeConfig( KConfig* config )
+{
+ kdDebug(5650) << "Resource::writeConfig()" << endl;
+
+ config->writeEntry( "ResourceType", d->mType );
+ config->writeEntry( "ResourceName", d->mName );
+ config->writeEntry( "ResourceIsReadOnly", d->mReadOnly );
+ config->writeEntry( "ResourceIsActive", d->mActive );
+ config->writeEntry( "ResourceIdentifier", d->mIdentifier );
+}
+
+bool Resource::open()
+{
+ d->mIsOpen = true;
+#ifdef QT_THREAD_SUPPORT
+ QMutexLocker guard( &(d->mMutex) );
+#endif
+ if ( !d->mOpenCount ) {
+ kdDebug(5650) << "Opening resource " << resourceName() << endl;
+ d->mIsOpen = doOpen();
+ }
+ d->mOpenCount++;
+ return d->mIsOpen;
+}
+
+void Resource::close()
+{
+#ifdef QT_THREAD_SUPPORT
+ QMutexLocker guard( &(d->mMutex) );
+#endif
+ if ( !d->mOpenCount ) {
+ kdDebug(5650) << "ERROR: Resource " << resourceName() << " closed more times than previously opened" << endl;
+ return;
+ }
+ d->mOpenCount--;
+ if ( !d->mOpenCount ) {
+ kdDebug(5650) << "Closing resource " << resourceName() << endl;
+ doClose();
+ d->mIsOpen = false;
+ } else {
+ kdDebug(5650) << "Not yet closing resource " << resourceName() << ", open count = " << d->mOpenCount << endl;
+ }
+}
+
+bool Resource::isOpen() const
+{
+ return d->mIsOpen;
+}
+
+void Resource::setIdentifier( const QString& identifier )
+{
+ d->mIdentifier = identifier;
+}
+
+QString Resource::identifier() const
+{
+ return d->mIdentifier;
+}
+
+void Resource::setType( const QString& type )
+{
+ d->mType = type;
+}
+
+QString Resource::type() const
+{
+ return d->mType;
+}
+
+void Resource::setReadOnly( bool value )
+{
+ d->mReadOnly = value;
+}
+
+bool Resource::readOnly() const
+{
+ return d->mReadOnly;
+}
+
+void Resource::setResourceName( const QString &name )
+{
+ d->mName = name;
+}
+
+QString Resource::resourceName() const
+{
+ return d->mName;
+}
+
+void Resource::setActive( bool value )
+{
+ d->mActive = value;
+}
+
+bool Resource::isActive() const
+{
+ return d->mActive;
+}
+
+void Resource::dump() const
+{
+ kdDebug(5650) << "Resource:" << endl;
+ kdDebug(5650) << " Name: " << d->mName << endl;
+ kdDebug(5650) << " Identifier: " << d->mIdentifier << endl;
+ kdDebug(5650) << " Type: " << d->mType << endl;
+ kdDebug(5650) << " OpenCount: " << d->mOpenCount << endl;
+ kdDebug(5650) << " ReadOnly: " << ( d->mReadOnly ? "yes" : "no" ) << endl;
+ kdDebug(5650) << " Active: " << ( d->mActive ? "yes" : "no" ) << endl;
+ kdDebug(5650) << " IsOpen: " << ( d->mIsOpen ? "yes" : "no" ) << endl;
+}
diff --git a/microkde/kresources/resource.h b/microkde/kresources/resource.h
new file mode 100644
index 0000000..7ff4f23
--- a/dev/null
+++ b/microkde/kresources/resource.h
@@ -0,0 +1,401 @@
+/*
+ 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>
+
+class KConfig;
+
+namespace KRES {
+
+class KLibFactory;
+class ConfigWidget;
+
+/**
+ * @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"
+
+class ResourceExampleConfig : public KRES::ResourceConfigWidget
+{
+ Q_OBJECT
+
+public:
+ ResourceExampleConfig( QWidget* parent = 0, const char* name = 0 );
+
+public slots:
+ virtual void loadSettings( KRES::Resource *resource);
+ virtual void saveSettings( KRES::Resource *resource );
+
+private:
+ KLineEdit* mLocationEdit;
+ KLineEdit* mPasswordEdit;
+};
+</pre>
+* <B>resourceexampleconfig.cpp</B>:
+<pre>
+#include <qlayout.h>
+#include <qlabel.h"
+#include <kresources/resourceconfigwidget.h>
+#include "resourceexample.h"
+#include "resourceexampleconfig.h"
+
+ResourceExampleConfig::ResourceExampleConfig( QWidget* parent, const char* name )
+ : KRES::ResourceConfigWidget( parent, name )
+{
+ resize( 245, 115 );
+ QGridLayout *mainLayout = new QGridLayout( this, 2, 2 );
+
+ QLabel *label = new QLabel( i18n( "Location:" ), this );
+ mHostEdit = new KLineEdit( this );
+ mainLayout->addWidget( label, 1, 0 );
+ mainLayout->addWidget( mHostEdit, 1, 1 );
+
+ label = new QLabel( i18n( "Password:" ), this );
+ mPasswordEdit = new KLineEdit( this );
+ mPasswordEdit->setEchoMode( QLineEdit::Password );
+ mainLayout->addWidget( label, 2, 0 );
+ mainLayout->addWidget( mPasswordEdit, 2, 1 );
+}
+
+void ResourceExampleConfig::loadSettings( KRES::Resource *resource )
+{
+ ResourceExample* res = dynamic_cast<ResourceExample *>( resource );
+ if (res) {
+ mHostEdit->setText( res->host() );
+ mPasswordEdit->setText( res->password() );
+ } else
+ kdDebug(5700) << "ERROR: ResourceExampleConfig::loadSettings(): no ResourceExample, cast failed" << endl;
+}
+
+void ResourceExampleConfig::saveSettings( KRES::Resource *resource )
+{
+ ResourceExample* res = dynamic_cast<ResourceExample *>( resource );
+ if (res) {
+ res->setHost(mHostEdit->text());
+ res->setPassword(mPasswordEdit->text());
+ } else
+ kdDebug(5700) << "ERROR: ResourceExampleConfig::saveSettings(): no ResourceExample, cast failed" << endl;
+}
+</pre>
+* <B>resourceexample.desktop</B>:
+<pre>
+[Desktop Entry]
+Type=Service
+
+[Misc]
+Encoding=UTF-8
+Name=Example Resource
+
+[Plugin]
+Type=exchange
+X-KDE-Library=resourceexample
+</pre>
+* <B>Makefile.am</B>
+<pre>
+kde_module_LTLIBRARIES = resourceexample.la
+
+resourceexample_la_SOURCES = resourceexample.cpp resourceexampleconfig.cpp
+resourceexample_la_LDFLAGS= $(all_libraries) -module $(KDE_PLUGIN)
+resourceexample_la_LIBADD= -lkderesources
+
+linkdir= $(kde_datadir)/resources/family
+link_DATA= resourceexample.desktop
+</pre>
+ *
+ *
+ */
+
+/**
+ * A @ref Resource is a ...
+ *
+ * A subclass should reimplement at least the constructor and the
+ * @ref writeConfig method.
+ *
+ */
+class Resource : public QObject
+{
+ Q_OBJECT
+
+ public:
+ typedef QValueList<Resource *> List;
+
+ /**
+ * Constructor. Construct resource from config.
+ * @param config Configuration to read persistence information from.
+ * If config==0, create object using default settings.
+ */
+ Resource( const KConfig* config );
+
+ /**
+ * Destructor.
+ */
+ virtual ~Resource();
+
+ /**
+ * Write configuration information for this resource to a configuration
+ * file. If you override this method, remember to call Resource::writeConfig
+ * or Terrible Things(TM) will happen.
+ * @param config Configuration to write persistence information to.
+ */
+ virtual void writeConfig( KConfig* config );
+
+ /**
+ * Open this resource, if it not already open. Increase the open
+ * count of this object, and open the resource by calling @ref doOpen().
+ * This method may block while another thread is concurrently opening
+ * or closing the resource.
+ *
+ * Returns true if the resource was already opened or if it was opened
+ * successfully; returns false if the resource was not opened successfully.
+ */
+ bool open();
+
+ /**
+ * Decrease the open count of this object, and if the count reaches
+ * zero, close this resource by calling @ref doClose().
+ * This method may block while another thread is concurrently closing
+ * or opening the resource.
+ */
+ void close();
+
+ /**
+ * 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;
+
+ /**
+ 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;
+};
+
+//US class PluginFactoryBase : public KLibFactory
+class PluginFactoryBase
+{
+ public:
+ virtual Resource *resource( const KConfig *config ) = 0;
+
+ virtual ConfigWidget *configWidget( QWidget *parent ) = 0;
+
+ protected:
+ virtual QObject* createObject( QObject*, const char*, const char*,
+ const QStringList & )
+ {
+ return 0;
+ }
+};
+
+template<class TR,class TC>
+class PluginFactory : public PluginFactoryBase
+{
+ public:
+ Resource *resource( const KConfig *config )
+ {
+ return new TR( config );
+ }
+
+ ConfigWidget *configWidget( QWidget *parent )
+ {
+ return new TC( parent );
+ }
+};
+
+
+
+}
+
+#endif
diff --git a/microkde/kresources/resourceselectdialog.h b/microkde/kresources/resourceselectdialog.h
new file mode 100644
index 0000000..fef689d
--- a/dev/null
+++ b/microkde/kresources/resourceselectdialog.h
@@ -0,0 +1,12 @@
+#ifndef MICRO_KRES_RESOURCESELECTDIALOG_H
+#define MICRO_KRES_RESOURCESELECTDIALOG_H
+
+namespace KRES {
+
+class ResourceSelectDialog
+{
+};
+
+}
+
+#endif
diff --git a/microkde/kresources/selectdialog.cpp b/microkde/kresources/selectdialog.cpp
new file mode 100644
index 0000000..fba8648
--- a/dev/null
+++ b/microkde/kresources/selectdialog.cpp
@@ -0,0 +1,154 @@
+/*
+ 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.
+*/
+
+/*US
+#include <kbuttonbox.h>
+#include <klistbox.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+*/
+#include <klocale.h>
+#include <kmessagebox.h>
+
+//US
+#include <kglobal.h>
+
+#include <qlistbox.h>
+#include <qlayout.h>
+#include <qgroupbox.h>
+
+#include "resource.h"
+
+#include "selectdialog.h"
+
+using namespace KRES;
+
+//US I am using KBaseDialog instead of KDialog
+//US : KDialog( parent, name, true )
+SelectDialog::SelectDialog( QPtrList<Resource> list, QWidget *parent,
+ const char *name )
+ : KDialogBase( parent, name, true, i18n( "Resource Selection" ), Help | Ok | Cancel,
+ Ok, true)
+
+{
+//US setCaption( i18n( "Resource Selection" ) );
+//US resize( 300, 200 );
+ resize( KMIN(KGlobal::getDesktopWidth(), 300), KMIN(KGlobal::getDesktopHeight(), 200) );
+
+//US
+ QFrame *main = plainPage();
+/*US
+ QVBoxLayout *layout = new QVBoxLayout( main );
+ mConfigPage = new KRES::ConfigPage( main );
+ layout->addWidget( mConfigPage );
+*/
+
+//US QVBoxLayout *mainLayout = new QVBoxLayout( this );
+ QVBoxLayout *mainLayout = new QVBoxLayout( main );
+ mainLayout->setMargin( marginHint() );
+
+//US QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, this );
+ QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, main );
+ groupBox->setTitle( i18n( "Resources" ) );
+
+//US mResourceId = new KListBox( groupBox );
+ mResourceId = new QListBox( groupBox );
+
+ mainLayout->addWidget( groupBox );
+
+ mainLayout->addSpacing( 40 );
+
+/*US
+ KButtonBox *buttonBox = new KButtonBox( this );
+
+ buttonBox->addStretch();
+ buttonBox->addButton( i18n( "&OK" ), this, SLOT( accept() ) );
+ buttonBox->addButton( i18n( "&Cancel" ), this, SLOT( reject() ) );
+ buttonBox->layout();
+
+ mainLayout->addWidget( buttonBox );
+*/
+ // setup listbox
+ uint counter = 0;
+ for ( uint i = 0; i < list.count(); ++i ) {
+ Resource *resource = list.at( i );
+ if ( resource && !resource->readOnly() ) {
+ mResourceMap.insert( counter, resource );
+ mResourceId->insertItem( resource->resourceName() );
+ counter++;
+ }
+ }
+
+ mResourceId->setCurrentItem( 0 );
+ connect( mResourceId, SIGNAL(returnPressed(QListBoxItem*)),
+ SLOT(accept()) );
+}
+
+Resource *SelectDialog::resource()
+{
+ if ( mResourceId->currentItem() != -1 )
+ return mResourceMap[ mResourceId->currentItem() ];
+ else
+ return 0;
+}
+
+Resource *SelectDialog::getResource( QPtrList<Resource> list, QWidget *parent )
+{
+ if ( list.count() == 0 ) {
+ KMessageBox::error( parent, i18n( "There is no resource available!" ) );
+ return 0;
+ }
+
+ if ( list.count() == 1 ) return list.first();
+
+ // the following lines will return a writeable resource if only _one_ writeable
+ // resource exists
+ Resource *found = 0;
+ Resource *it = list.first();
+ while ( it ) {
+ if ( !it->readOnly() ) {
+ if ( found ) {
+ found = 0;
+ break;
+ } else
+ found = it;
+ }
+ it = list.next();
+ }
+
+ if ( found )
+ return found;
+
+ SelectDialog dlg( list, parent);
+//US if ( dlg.exec() == KDialog::Accepted )
+ if ( dlg.exec() )
+ return dlg.resource();
+ else
+ return 0;
+}
+
+/*US
+#include "selectdialog.moc"
+*/
+
diff --git a/microkde/kresources/selectdialog.h b/microkde/kresources/selectdialog.h
new file mode 100644
index 0000000..7026212
--- a/dev/null
+++ b/microkde/kresources/selectdialog.h
@@ -0,0 +1,92 @@
+/*
+ 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_SELECTDIALOG_H
+#define KRESOURCES_SELECTDIALOG_H
+
+#include <qobject.h>
+#include <qptrlist.h>
+#include <qmap.h>
+
+#include <kdialogbase.h>
+
+//US class KListBox;
+class QListBox;
+
+namespace KRES {
+
+class Resource;
+
+/**
+ * Dialog for selecting a resource.
+ *
+ * Example:
+ *
+ * <pre>
+ * KABC::Resource *res = KABC::SelectDialog::getResource();
+ * if ( !( res ) ) {
+ * // no resource selected
+ * } else {
+ * // do something with resource
+ * }
+ * </pre>
+ */
+//US class SelectDialog : KDialog
+class SelectDialog : KDialogBase
+{
+ // Q_OBJECT
+ public:
+ /**
+ * Constructor.
+ * @param ab The address book you want to select the resource from
+ * @param parent The parent widget
+ * @param name The name of the dialog
+ */
+ SelectDialog( QPtrList<Resource> list, QWidget *parent = 0,
+ const char *name = 0);
+
+ // ~SelectDialog();
+
+ /**
+ * Return selected resource.
+ */
+ Resource *resource();
+
+ /**
+ * Open a dialog showing the available resources and return the resource the
+ * user has selected. Returns 0, if the dialog was canceled.
+ */
+ static Resource *getResource( QPtrList<Resource> list, QWidget *parent = 0 );
+
+ private:
+//US KListBox *mResourceId;
+ QListBox *mResourceId;
+
+ QMap<int, Resource*> mResourceMap;
+};
+
+
+
+}
+
+#endif