summaryrefslogtreecommitdiffstats
path: root/kresources
diff options
context:
space:
mode:
Diffstat (limited to 'kresources')
-rw-r--r--kresources/Makefile.am49
-rw-r--r--kresources/README.design173
-rw-r--r--kresources/TODO17
-rw-r--r--kresources/configdialog.cpp123
-rw-r--r--kresources/configdialog.h60
-rw-r--r--kresources/configpage.cpp535
-rw-r--r--kresources/configpage.h110
-rw-r--r--kresources/configwidget.cpp37
-rw-r--r--kresources/configwidget.h58
-rw-r--r--kresources/factory.cpp162
-rw-r--r--kresources/factory.h118
-rw-r--r--kresources/kcmkresources.cpp68
-rw-r--r--kresources/kcmkresources.h42
-rw-r--r--kresources/kresources.desktop210
-rw-r--r--kresources/kresources_manager.desktop75
-rw-r--r--kresources/kresources_plugin.desktop79
-rw-r--r--kresources/manager.h422
-rw-r--r--kresources/manageriface.h46
-rw-r--r--kresources/managerimpl.cpp448
-rw-r--r--kresources/managerimpl.h107
-rw-r--r--kresources/resource.cpp185
-rw-r--r--kresources/resource.h420
-rw-r--r--kresources/selectdialog.cpp122
-rw-r--r--kresources/selectdialog.h87
-rw-r--r--kresources/testresources.cpp81
25 files changed, 3834 insertions, 0 deletions
diff --git a/kresources/Makefile.am b/kresources/Makefile.am
new file mode 100644
index 000000000..c30d108a7
--- /dev/null
+++ b/kresources/Makefile.am
@@ -0,0 +1,49 @@
+INCLUDES = $(all_includes)
+
+METASOURCES = AUTO
+
+lib_LTLIBRARIES = libkresources.la
+
+libkresources_la_SOURCES = resource.cpp \
+ factory.cpp \
+ manageriface.skel \
+ manageriface.stub \
+ managerimpl.cpp \
+ configwidget.cpp \
+ configdialog.cpp \
+ selectdialog.cpp \
+ configpage.cpp
+
+libkresources_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 3:0:2
+libkresources_la_LIBADD = $(LIB_KDEUI) $(LIB_KIO)
+
+kresincludedir = $(includedir)/kresources
+kresinclude_HEADERS = resource.h \
+ configwidget.h \
+ factory.h \
+ manageriface.h \
+ managerimpl.h \
+ manager.h \
+ selectdialog.h \
+ configdialog.h \
+ configpage.h
+
+kde_module_LTLIBRARIES = kcm_kresources.la
+
+kcm_kresources_la_SOURCES = kcmkresources.cpp
+kcm_kresources_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined
+kcm_kresources_la_LIBADD = libkresources.la
+
+
+check_PROGRAMS = testresources
+
+testresources_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+testresources_LDADD = libkresources.la
+testresources_SOURCES = testresources.cpp
+
+xdg_apps_DATA = kresources.desktop
+
+servicetypedir = $(kde_servicetypesdir)
+servicetype_DATA = kresources_plugin.desktop kresources_manager.desktop
+
+include ../admin/Doxyfile.am
diff --git a/kresources/README.design b/kresources/README.design
new file mode 100644
index 000000000..563d0aeed
--- /dev/null
+++ b/kresources/README.design
@@ -0,0 +1,173 @@
+kresources
+README.design
+
+KDE RESOURCES
+-------------
+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 kdelibs/kabc and for
+calendar resources in libkcal.
+A resource family represents stores of information of a certain kind
+(appointments, contacts). A resource type class represents a way in
+which this information is stored, or a way to access the information.
+
+ resources
+ |
+ +----------+----------+----------------+---
+ | | |
+Families: calendar contacts ...
+ | |
+ +---+--+ +-----+-----+-----+--
+ | | | | | |
+Types: local Exchange file dir ldap ...
+ file server
+
+
+Resource families are usually implemented as (abstract) classes
+in a library, e.g. the calendar resource in libkcal en the
+addressbook resource family in libkabc. Resource type are like
+plugins: that can be loaded on-demand, they are implemented in
+their own library, and a .desktop file tells KDE where to find
+them.
+
+The user then configures one or more resources for a certain
+family, making use of the resource types. For instance, a user
+might define two Exchange-based resources, one with her own
+calendar data and one with the calendar data of her workgroup.
+She might also have two ldap contacts resources, together with
+a local file-based address book.
+
+Both Exchange-based calendar resources are objects of the same
+type, but with different settings. These resources are persistent,
+and they are managed by the ResourceManager for the calendar
+resource family. The list of resources, and the settings for
+each resource, are stored by the resource manager using KConfig,
+in $HOME/.kde/share/config/<family>.
+
+The resource manager is a singleton object for every resource family.
+Use the resource manager to get the list of available resource types
+in this family, to create a new resource of a given type, to get a
+configuration widget for a resource, to get the list of defined
+resources in this family, and to get a specific resource object.
+
+USE CASES
+---------
+Opening all resources of resource family "calendar". The associated
+(abstract) class is ResourceCalendar.
+
+ KRES::ResourceManager<ResourceCalendar> mManager = new KRES::ResourceManager<ResourceCalendar>( "calendar" );
+ QPtrList<ResourceCalendar> mResources = mManager->resources();
+ // Open resources
+ ResourceCalendar *resource;
+ for ( resource = mResources.first(); resource; resource = mResources.next() ) {
+ kdDebug() << "Opening resource " + resource->name() << endl;
+ bool result = resource->open();
+ if ( ! result )
+ kdDebug() << "Error opening resource" << endl;
+ }
+
+Note that the resources are configured by the user in a kcontrol
+applet. The singleton resourcemanager reads the configuration from
+the config file that the kcm applet writes.
+
+Getting the events for a certain date range from all resources.
+ResourceCalendar defines a function
+QPtrList<Event> rawEvents( QDate start, QDate end, bool inclusive )
+that returns the events in the resource in the date range. We just
+iterate over all available resources to harvest all events.
+
+ QPtrList<Event> result;
+ ResourceCalendar *resource;
+ for ( resource = mResources.first(); resource; resource = mResources.next() ) {
+ QPtrList<Event> list = resource->rawEvents( start, end, inclusive );
+ Event* item;
+ for ( item = list.first(); item; item = list.next() ) {
+ result.append( item );
+ }
+ }
+
+EXAMPLES
+--------
+For examples, check the following files in kdepim/libkcal:
+- resourcecalendar.{h,cpp}
+ Defines the base class of the calendar resource family
+- kcmcalendars.{h,cpp}
+ Defines the KControl applet for calendar resources
+- kcalendars.desktop
+ This .desktop files tells KControl where to find the
+ applet for calendar resources.
+- Makefile.am
+ How to build and install the calendar resource family
+
+The "local" resource is compiled and installed together
+with libkcal:
+- resourcelocal.{h,cpp}
+ Defines the local resource type, in the calendar resource family
+- resourcelocalconfig.{h,cpp}
+ Defines the configuration widget for the local resource
+- local.desktop
+ Information on the local resource type, in order to know
+ which resource types are available
+
+The "exchange" calendar resource is compiled in a separate
+library, dynamically loaded by the resource manager if
+resources of this type are used. This resource is in
+kdepim/kresources/exchange:
+- resourceexchange.{h,cpp}
+ Defines the exchange resource
+- resourceexchangeconfig.{h,cpp}
+ Defines the configuration widget for the exchange resource
+- exchange.desktop
+ This file is installed so that the resource manager can
+ find the exchange resource type
+- Makefile.am
+ How to build and install the exchange resource type
+
+IDEAS/ISSUES/PROBLEMS
+---------------------
+- What happens when there are resource manager in two separate
+processes (like kcontrol and korganizer, or two kcontrols) both
+accessing the same resource family?
+
+ + If there are more than one resource managers running in the
+ same KDE session, but in separate processes, they should keep
+ each other informed. I've implemented some DCOP stuff so that
+ the various managers know when resources have been added,
+ deleted or modified. These messages are not yet handled
+ completely.
+
+- The resource manager should send a signal when a resource
+has changed, so that the applications can update their information.
+
+ + Problem with this: ResourceManager is a template class.
+ Templates cannot have signals or slots. An app should
+ implement the ManagerObserver interface and register with the
+ resource manager.
+
+- Maybe the flags that marks each resource as active or passive,
+and the Standard resource, should be application-specific? E.g.,
+I can imagine karm looking only in the business calendar, so it
+should have only one active calendar, while KORganizer would also
+have my wife's calendar active read-only.
+
+- There should be a way to synchronize the concurrent use of a
+resource, be it in the same process, on different processes in
+the same KDE session, or even when e.g. korganizer uses an
+Exchange calendar while also Outlook is running on a Windows PC.
+
+- have the item that resource object delivers (events, contacts)
+derived from ResourceItem. Then introduce locking and unlocking,
+that every resource type should extend using its own locking
+mechanism, like SQL locks, or file locks, or whatever.
+
+ + This means that Addressee, Event etc. should be
+ derived from ResourceItem.
+ + Communication via DCOP via the Resource, I think.
+ + Drawback: flexibility is lost, because the Resource
+ would have to be a factory for these objects.
+
+- Maybe the resource class should have some generic support
+for searching. In the calendar family, you could search by
+date, by category or by key word, in the kabc family you
+could search by key word, name, country, etc.
+
diff --git a/kresources/TODO b/kresources/TODO
new file mode 100644
index 000000000..5034327a7
--- /dev/null
+++ b/kresources/TODO
@@ -0,0 +1,17 @@
+This is a collection of changes which should eventually be done:
+
+- Emit resourceClosed(Resource*) signal in Resource::close(). For othogonality
+we should probably also emit resourceOpened(), resourceLoaded(), resourceSaved()
+signals.
+- Add function to Resource to return the translated label of the type
+- Find better solution than passing the family name as string to the Manager
+ constructor.
+- Improve read-only handling (notify configuration widgets of read-only flag
+ changes, etc.)
+- Add ability to have subresources, so a single resource can have
+ multiple subdirs. The more general solution would be a complete
+ storage tree in each resource.
+- Framework widgets - like the resource chooser in KOrganizer and a
+ resource chooser for writing an entry for the first time
+- Improve usability - for example there should be only one of some of the
+ items
diff --git a/kresources/configdialog.cpp b/kresources/configdialog.cpp
new file mode 100644
index 000000000..3b88ff4b7
--- /dev/null
+++ b/kresources/configdialog.cpp
@@ -0,0 +1,123 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <klocale.h>
+#include <klineedit.h>
+#include <kmessagebox.h>
+
+#include <qgroupbox.h>
+#include <qlabel.h>
+#include <qlayout.h>
+#include <qcheckbox.h>
+
+#include "factory.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, false )/*, mConfig( config )*/, mResource( resource )
+{
+ Factory *factory = Factory::self( resourceFamily );
+
+ QFrame *main = makeMainWidget();
+
+ 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() );
+ setMinimumSize( sizeHint() );
+}
+
+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();
+}
+
+#include "configdialog.moc"
diff --git a/kresources/configdialog.h b/kresources/configdialog.h
new file mode 100644
index 000000000..6fa751687
--- /dev/null
+++ b/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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, 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 KRESOURCES_EXPORT 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/kresources/configpage.cpp b/kresources/configpage.cpp
new file mode 100644
index 000000000..e133d5b99
--- /dev/null
+++ b/kresources/configpage.cpp
@@ -0,0 +1,535 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qgroupbox.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>
+#include <ktrader.h>
+#include <kinputdialog.h>
+
+#include "resource.h"
+#include "configdialog.h"
+
+#include "configpage.h"
+
+namespace KRES {
+
+ResourcePageInfo::ResourcePageInfo() : KShared() {
+ mManager = 0L;
+ mConfig = 0L;
+}
+
+ResourcePageInfo::~ResourcePageInfo() {
+ //delete mManager;
+ mManager = 0L;
+ //delete mConfig;
+ mConfig = 0L;
+}
+
+
+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; }
+
+ void updateItem()
+ {
+ setOn( mResource->isActive() );
+ setText( 0, mResource->resourceName() );
+ setText( 1, mResource->type() );
+ setText( 2, mIsStandard ? i18n( "Yes" ) : QString::null );
+ }
+
+ 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 );
+
+ mFamilyCombo = new KComboBox( false, groupBox );
+ groupBoxLayout->addMultiCellWidget( mFamilyCombo, 0, 0, 0, 1 );
+
+ mListView = new KListView( groupBox );
+ mListView->setAllColumnsShowFocus( true );
+ mListView->setFullWidth( true );
+ mListView->addColumn( i18n( "Name" ) );
+ mListView->addColumn( i18n( "Type" ) );
+ mListView->addColumn( i18n( "Standard" ) );
+
+ groupBoxLayout->addWidget( mListView, 1, 0 );
+ connect( mListView, SIGNAL( doubleClicked( QListViewItem *, const QPoint &, int ) ), this, SLOT( slotEdit() ) );
+ 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;
+
+ mConfig = new KConfig( "kcmkresourcesrc" );
+ mConfig->setGroup( "General" );
+
+ load();
+}
+
+ConfigPage::~ConfigPage()
+{
+ QValueList<KSharedPtr<ResourcePageInfo> >::Iterator it;
+ for ( it = mInfoMap.begin(); it != mInfoMap.end(); ++it ) {
+ (*it)->mManager->removeObserver( this );
+ }
+
+ mConfig->writeEntry( "CurrentFamily", mFamilyCombo->currentItem() );
+ delete mConfig;
+ mConfig = 0;
+}
+
+void ConfigPage::load()
+{
+ kdDebug(5650) << "ConfigPage::load()" << endl;
+
+ mListView->clear();
+ mFamilyMap.clear();
+ mInfoMap.clear();
+ QStringList familyDisplayNames;
+
+ // KDE-3.3 compatibility code: get families from the plugins
+ QStringList compatFamilyNames;
+ const KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin" );
+ KTrader::OfferList::ConstIterator it = plugins.begin();
+ KTrader::OfferList::ConstIterator end = plugins.end();
+ for ( ; it != end; ++it ) {
+ const QString family = (*it)->property( "X-KDE-ResourceFamily" ).toString();
+ if ( compatFamilyNames.find( family ) == compatFamilyNames.end() )
+ compatFamilyNames.append( family );
+ }
+
+ const KTrader::OfferList managers = KTrader::self()->query( "KResources/Manager" );
+ KTrader::OfferList::ConstIterator m_it;
+ for( m_it = managers.begin(); m_it != managers.end(); ++m_it ) {
+ QString displayName = (*m_it)->property( "Name" ).toString();
+ familyDisplayNames.append( displayName );
+ QString family = (*m_it)->property( "X-KDE-ResourceFamily" ).toString();
+ if ( !family.isEmpty() ) {
+ compatFamilyNames.remove( family );
+ mFamilyMap.append( family );
+ loadManager( family );
+ }
+ }
+
+ // Rest of the kde-3.3 compat code
+ QStringList::ConstIterator cfit = compatFamilyNames.begin();
+ for ( ; cfit != compatFamilyNames.end(); ++cfit ) {
+ mFamilyMap.append( *cfit );
+ familyDisplayNames.append( *cfit );
+ loadManager( *cfit );
+ }
+
+ mCurrentManager = 0;
+
+ mFamilyCombo->clear();
+ mFamilyCombo->insertStringList( familyDisplayNames );
+
+ int currentFamily = mConfig->readNumEntry( "CurrentFamily", 0 );
+ mFamilyCombo->setCurrentItem( currentFamily );
+ slotFamilyChanged( currentFamily );
+ emit changed( false );
+}
+
+void ConfigPage::loadManager( const QString& family )
+{
+ mCurrentManager = new Manager<Resource>( family );
+ if ( mCurrentManager ) {
+ mCurrentManager->addObserver( this );
+
+ ResourcePageInfo *info = new ResourcePageInfo;
+ info->mManager = mCurrentManager;
+ info->mConfig = new KConfig( KRES::ManagerImpl::defaultConfigFile( family ) );
+ info->mManager->readConfig( info->mConfig );
+
+ mInfoMap.append( KSharedPtr<ResourcePageInfo>(info) );
+ }
+}
+
+void ConfigPage::save()
+{
+ saveResourceSettings();
+
+ QValueList<KSharedPtr<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 ];
+
+ mCurrentManager = mInfoMap[ pos ]->mManager;
+ mCurrentConfig = mInfoMap[ pos ]->mConfig;
+
+ if ( !mCurrentManager )
+ kdDebug(5650) << "ERROR: cannot create ResourceManager<Resource>( mFamily )" << endl;
+
+ mListView->clear();
+
+ if ( mCurrentManager->isEmpty() )
+ defaults();
+
+ Resource *standardResource = mCurrentManager->standardResource();
+
+ 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 ) {
+ defaults();
+ emit changed( true );
+ mCurrentManager->writeConfig( mCurrentConfig );
+ } else {
+ if ( !standardResource )
+ KMessageBox::sorry( this, i18n( "There is no standard resource! Please select one." ) );
+
+ emit changed( false );
+ }
+}
+
+void ConfigPage::slotAdd()
+{
+ if ( !mCurrentManager )
+ return;
+
+ QStringList types = mCurrentManager->resourceTypeNames();
+ QStringList descs = mCurrentManager->resourceTypeDescriptions();
+ bool ok = false;
+ QString desc = KInputDialog::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! 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->change( 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 )
+{
+ kdDebug(5650) << "ConfigPage::resourceAdded( " << resource->resourceName()
+ << " )" << endl;
+
+ ConfigViewItem *item = new ConfigViewItem( mListView, resource );
+
+ item->setOn( resource->isActive() );
+
+ mLastItem = item;
+
+ emit changed( true );
+}
+
+void ConfigPage::resourceModified( Resource *resource )
+{
+ kdDebug(5650) << "ConfigPage::resourceModified( " << resource->resourceName()
+ << " )" << endl;
+ ConfigViewItem *item = findItem( resource );
+ if ( !item ) return;
+
+ // TODO: Reread resource config. Otherwise we won't see the modification.
+
+ item->updateItem();
+}
+
+void ConfigPage::resourceDeleted( Resource *resource )
+{
+ kdDebug(5650) << "ConfigPage::resourceDeleted( " << resource->resourceName()
+ << " )" << endl;
+
+ ConfigViewItem *item = findItem( resource );
+ if ( !item ) return;
+
+ delete item;
+}
+
+ConfigViewItem *ConfigPage::findItem( Resource *resource )
+{
+ QListViewItem *i;
+ for( i = mListView->firstChild(); i; i = i->nextSibling() ) {
+ ConfigViewItem *item = static_cast<ConfigViewItem *>( i );
+ if ( item->resource() == resource ) return item;
+ }
+ return 0;
+}
+
+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()
+{
+ 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." ) );
+ }
+}
+
+}
+
+#include "configpage.moc"
+
diff --git a/kresources/configpage.h b/kresources/configpage.h
new file mode 100644
index 000000000..4a4231f07
--- /dev/null
+++ b/kresources/configpage.h
@@ -0,0 +1,110 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KRESOURCES_CONFIGPAGE_H
+#define KRESOURCES_CONFIGPAGE_H
+
+#include <ksharedptr.h>
+#include <qstringlist.h>
+#include <qwidget.h>
+
+#include "manager.h"
+
+class KComboBox;
+class KListView;
+
+class QListViewItem;
+class QPushButton;
+
+namespace KRES {
+
+class KRESOURCES_EXPORT ResourcePageInfo : public KShared
+{
+ public:
+ ResourcePageInfo();
+ ~ResourcePageInfo();
+ Manager<Resource> *mManager;
+ KConfig *mConfig;
+};
+
+class Resource;
+class ConfigViewItem;
+
+class KRESOURCES_EXPORT ConfigPage : public QWidget, public ManagerObserver<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();
+
+ public:
+ // From ManagerObserver<Resource>
+ virtual void resourceAdded( Resource *resource );
+ virtual void resourceModified( Resource *resource );
+ virtual void resourceDeleted( Resource *resource );
+
+ protected:
+ ConfigViewItem *findItem( Resource *resource );
+
+ protected slots:
+ void slotItemClicked( QListViewItem * );
+
+ signals:
+ void changed( bool );
+
+ private:
+ void loadManager( const QString& family );
+ void saveResourceSettings();
+
+ Manager<Resource>* mCurrentManager;
+ KConfig* mCurrentConfig;
+ KConfig* mConfig;
+ QString mFamily;
+ QStringList mFamilyMap;
+ QValueList<KSharedPtr<ResourcePageInfo> > mInfoMap;
+
+ KComboBox* mFamilyCombo;
+ KListView* mListView;
+ QPushButton* mAddButton;
+ QPushButton* mRemoveButton;
+ QPushButton* mEditButton;
+ QPushButton* mStandardButton;
+
+ QListViewItem* mLastItem;
+};
+
+}
+
+#endif
diff --git a/kresources/configwidget.cpp b/kresources/configwidget.cpp
new file mode 100644
index 000000000..20197d81a
--- /dev/null
+++ b/kresources/configwidget.cpp
@@ -0,0 +1,37 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "configwidget.h"
+
+using namespace KRES;
+
+ConfigWidget::ConfigWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+}
+
+void ConfigWidget::setInEditMode( bool )
+{
+}
+
+#include "configwidget.moc"
diff --git a/kresources/configwidget.h b/kresources/configwidget.h
new file mode 100644
index 000000000..ae763978a
--- /dev/null
+++ b/kresources/configwidget.h
@@ -0,0 +1,58 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRESOURCES_CONFIGWIDGET_H
+#define KRESOURCES_CONFIGWIDGET_H
+
+#include "resource.h"
+
+#include <kconfig.h>
+
+#include <qwidget.h>
+
+namespace KRES {
+
+class KRESOURCES_EXPORT 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 ) = 0;
+ virtual void saveSettings( Resource *resource ) = 0;
+
+ signals:
+ void setReadOnly( bool value );
+
+ protected:
+ Resource *mResource;
+};
+
+}
+#endif
diff --git a/kresources/factory.cpp b/kresources/factory.cpp
new file mode 100644
index 000000000..eadd7a2c2
--- /dev/null
+++ b/kresources/factory.cpp
@@ -0,0 +1,162 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <ksimpleconfig.h>
+#include <kstandarddirs.h>
+#include <kstaticdeleter.h>
+
+#include <qfile.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 )
+ staticDeleter.setObject( mSelves, 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 )
+{
+ 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 );
+ }
+}
+
+Factory::~Factory()
+{
+}
+
+QStringList Factory::typeNames() const
+{
+ return mTypeMap.keys();
+}
+
+ConfigWidget *Factory::configWidget( const QString& type, QWidget *parent )
+{
+ if ( type.isEmpty() || !mTypeMap.contains( type ) )
+ return 0;
+
+ KService::Ptr ptr = mTypeMap[ type ];
+ KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
+ if ( !factory ) {
+ kdDebug(5650) << "KRES::Factory::configWidget(): Factory creation failed "
+ << KLibLoader::self()->lastErrorMessage() << endl;
+ return 0;
+ }
+
+ PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
+
+ if ( !pluginFactory ) {
+ kdDebug(5650) << "KRES::Factory::configWidget(): no plugin factory."
+ << endl;
+ return 0;
+ }
+
+ ConfigWidget *wdg = pluginFactory->configWidget( parent );
+ if ( !wdg ) {
+ kdDebug(5650) << "'" << ptr->library() << "' doesn't provide a ConfigWidget" << endl;
+ return 0;
+ }
+
+ return wdg;
+}
+
+QString Factory::typeName( const QString &type ) const
+{
+ if ( type.isEmpty() || !mTypeMap.contains( type ) )
+ return QString();
+
+ KService::Ptr ptr = mTypeMap[ type ];
+ return ptr->name();
+}
+
+QString Factory::typeDescription( const QString &type ) const
+{
+ if ( type.isEmpty() || !mTypeMap.contains( type ) )
+ return QString();
+
+ KService::Ptr ptr = mTypeMap[ type ];
+ return ptr->comment();
+}
+
+Resource *Factory::resource( const QString& type, const KConfig *config )
+{
+ kdDebug(5650) << "Factory::resource( " << type << ", config )" << endl;
+
+ if ( type.isEmpty() || !mTypeMap.contains( type ) ) {
+ kdDebug(5650) << "Factory::resource() no such type " << type << endl;
+ return 0;
+ }
+
+ KService::Ptr ptr = mTypeMap[ type ];
+ KLibFactory *factory = KLibLoader::self()->factory( ptr->library().latin1() );
+ if ( !factory ) {
+ kdDebug(5650) << "KRES::Factory::resource(): Factory creation failed "
+ << KLibLoader::self()->lastErrorMessage() << endl;
+ return 0;
+ }
+
+ PluginFactoryBase *pluginFactory = static_cast<PluginFactoryBase *>( factory );
+
+ if ( !pluginFactory ) {
+ kdDebug(5650) << "KRES::Factory::resource(): no plugin factory." << endl;
+ return 0;
+ }
+
+ Resource *resource = pluginFactory->resource( config );
+ if ( !resource ) {
+ kdDebug(5650) << "'" << ptr->library() << "' is not a " + mResourceFamily +
+ " plugin." << endl;
+ return 0;
+ }
+
+ resource->setType( type );
+
+ return resource;
+}
diff --git a/kresources/factory.h b/kresources/factory.h
new file mode 100644
index 000000000..d7a1e069e
--- /dev/null
+++ b/kresources/factory.h
@@ -0,0 +1,118 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRESOURCES_FACTORY_H
+#define KRESOURCES_FACTORY_H
+
+#include <qdict.h>
+#include <qstring.h>
+
+#include <kconfig.h>
+#include <klibloader.h>
+#include <ktrader.h>
+
+#include "resource.h"
+#include "configwidget.h"
+
+namespace KRES {
+
+/**
+ * Class for loading resource plugins.
+ * Use this class if you need resources with special
+ * settings, otherwise use KRES::Manager::createResource()
+ * to get resources with the default settings.
+ *
+ * Example:
+ *
+ * \code
+ * KABC::Factory *factory = KABC::Factory::self( "contact" );
+ *
+ * // to allow a transparent configuration of resources, we have
+ * // to use a kconfig object.
+ * KConfig config( "tst" );
+ * config.writePathEntry( "FileName", "/home/foobar/test.vcf" );// resource dependend
+ * config.writeEntry( "FileFormat", "vcard" ); // resource dependend
+ *
+ * KABC::Resource *res = factory->resource( "file", &config );
+ *
+ * // do something with resource
+ *
+ * \endcode
+ */
+class KRESOURCES_EXPORT 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 typeNames()
+ * @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 typeNames()
+ * @param config The config object where the resource get it settings from,
+ * or 0 if a resource with default values 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;
+ QMap<QString, KService::Ptr> mTypeMap;
+};
+
+}
+#endif
diff --git a/kresources/kcmkresources.cpp b/kresources/kcmkresources.cpp
new file mode 100644
index 000000000..be7b22b5a
--- /dev/null
+++ b/kresources/kcmkresources.cpp
@@ -0,0 +1,68 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <qlayout.h>
+
+#include <kaboutdata.h>
+#include <kgenericfactory.h>
+#include <klocale.h>
+
+#include "configpage.h"
+
+#include "kcmkresources.h"
+
+typedef KGenericFactory<KCMKResources, QWidget> ResourcesFactory;
+K_EXPORT_COMPONENT_FACTORY( kcm_kresources, ResourcesFactory( "kcmkresources" ) )
+
+KCMKResources::KCMKResources( QWidget *parent, const char *name, const QStringList& )
+ : KCModule( ResourcesFactory::instance(), parent, name )
+{
+ QVBoxLayout *layout = new QVBoxLayout( this );
+ mConfigPage = new KRES::ConfigPage( this );
+ layout->addWidget( mConfigPage );
+ connect( mConfigPage, SIGNAL( changed( bool ) ), SIGNAL( changed( bool ) ) );
+ setButtons( Help | Apply );
+ KAboutData *about =
+ new KAboutData( I18N_NOOP( "kcmkresources" ),
+ I18N_NOOP( "KDE Resources configuration module" ),
+ 0, 0, KAboutData::License_GPL,
+ I18N_NOOP( "(c) 2003 Tobias Koenig" ) );
+
+ about->addAuthor( "Tobias Koenig", 0, "tokoe@kde.org" );
+ setAboutData(about);
+}
+
+void KCMKResources::load()
+{
+ mConfigPage->load();
+}
+
+void KCMKResources::save()
+{
+ mConfigPage->save();
+}
+
+void KCMKResources::defaults()
+{
+ mConfigPage->defaults();
+}
+
+#include "kcmkresources.moc"
diff --git a/kresources/kcmkresources.h b/kresources/kcmkresources.h
new file mode 100644
index 000000000..2f090bdec
--- /dev/null
+++ b/kresources/kcmkresources.h
@@ -0,0 +1,42 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRESOURCES_KCMKRESOURCES_H
+#define KRESOURCES_KCMKRESOURCES_H
+
+#include <kcmodule.h>
+
+class KRESOURCES_EXPORT KCMKResources : public KCModule
+{
+ Q_OBJECT
+
+ public:
+ KCMKResources( QWidget *parent, const char *name, const QStringList& );
+
+ void load();
+ void save();
+ void defaults();
+
+ private:
+ KRES::ConfigPage *mConfigPage;
+};
+
+#endif
diff --git a/kresources/kresources.desktop b/kresources/kresources.desktop
new file mode 100644
index 000000000..6c7739bdc
--- /dev/null
+++ b/kresources/kresources.desktop
@@ -0,0 +1,210 @@
+[Desktop Entry]
+Exec=kcmshell kresources
+Icon=date
+Type=Application
+Terminal=false
+
+X-KDE-ModuleType=Library
+X-KDE-Library=kresources
+X-KDE-FactoryName=kresources
+X-KDE-HasReadOnlyMode=false
+
+Name=KDE Resources
+Name[af]=KDE Hulpbronne
+Name[be]=Рэсурсы KDE
+Name[bg]=Системни ресурси
+Name[bn]=কে.ডি.ই রিসোর্সসমূহ
+Name[br]=Danvezioù KDE
+Name[bs]=KDE resursi
+Name[ca]=Recursos KDE
+Name[cs]=Zdroje KDE
+Name[csb]=Dostónczi KDE
+Name[da]=KDE Ressourcer
+Name[de]=KDE-Ressourcen
+Name[el]=Πόροι του KDE
+Name[eo]=KDEa risurcoj
+Name[es]=Recursos de KDE
+Name[et]=KDE ressursid
+Name[eu]=KDEren baliabideak
+Name[fa]=منابع KDE
+Name[fi]=KDE:n resurssiasetukset
+Name[fr]=Ressources de KDE
+Name[fy]=KDE Helpboarnen
+Name[ga]=Acmhainní KDE
+Name[gl]=Recursos de KDE
+Name[he]=משאבים של KDE
+Name[hr]=KDE resursi
+Name[hu]=KDE-erőforrások
+Name[id]=Sumber Daya KDE
+Name[is]=KDE auðlindir
+Name[it]=Risorse di KDE
+Name[ja]=KDE リソース
+Name[ka]=KDE რესურსები
+Name[kk]=KDE ресурстары
+Name[km]=ធនធាន KDE
+Name[lb]=KDE-Ressourcen
+Name[lt]=KDE resursai
+Name[lv]=KDE resursi
+Name[mk]=Ресурси на KDE
+Name[ms]=Sumber KDE
+Name[nb]=KDE-ressurser
+Name[nds]=KDE-Ressourcen
+Name[ne]=KDE संसाधन
+Name[nl]=KDE-gegevensbronnen
+Name[nn]=KDE-ressursar
+Name[pa]=KDE ਸਰੋਤ
+Name[pl]=Źródła danych KDE
+Name[pt]=Recursos do KDE
+Name[pt_BR]=Fontes de Dados do KDE
+Name[ro]=Resurse KDE
+Name[ru]=Ресурсы KDE
+Name[rw]=Ibikorana KDE
+Name[se]=KDE-resurssat
+Name[sk]=Zdroje KDE
+Name[sl]=Viri KDE
+Name[sr]=KDE-ови ресурси
+Name[sr@Latn]=KDE-ovi resursi
+Name[sv]=KDE-resurser
+Name[ta]=KDE மூலங்கள்
+Name[te]=కెడిఈ వనరులు
+Name[tg]=Манбаъи KDE
+Name[th]=ทรัพยากร KDE
+Name[tr]=KDE Kaynakları
+Name[tt]=KDE Resursları
+Name[uk]=Ресурси KDE
+Name[uz]=KDE imkoniyatlari
+Name[uz@cyrillic]=KDE имкониятлари
+Name[vi]=Tài nguyên KDE
+Name[zh_CN]=KDE 资源
+Name[zh_HK]=KDE 資源
+Name[zh_TW]=KDE 資源組態
+
+Comment=Configure KDE Resources
+Comment[af]=Stel KDE Hulpbronne op
+Comment[be]=Настаўленне рэсурсаў KDE
+Comment[bg]=Настройване на системните ресурси
+Comment[bn]=কে.ডি.ই. রিসোর্সসমূহ কনফিগার করো
+Comment[br]=Kefluniañ danvezioù KDE
+Comment[bs]=Podesite KDE resurse
+Comment[ca]=Configura els recursos KDE
+Comment[cs]=Nastavení zdrojů KDE
+Comment[csb]=Kònfigùracëjô dostónków KDE
+Comment[da]=Indstil KDE's ressourcer
+Comment[de]=KDE-Ressourcen einrichten
+Comment[el]=Ρύθμιση πόρων του KDE
+Comment[eo]=Agordu KDEajn risurcojn
+Comment[es]=Configurar recursos de KDE
+Comment[et]=KDE ressurside seadistamine
+Comment[eu]=Konfiguratu KDEren baliabideak
+Comment[fa]=پیکربندی منابع KDE
+Comment[fi]=Muokkaa KDE:n resursseja
+Comment[fr]=Configure les ressources de KDE
+Comment[fy]=KDE helpboarne Ynstelle
+Comment[ga]=Cumraigh Acmhainní KDE
+Comment[gl]=Configurar os recursos de KDE
+Comment[he]=תצורת משאבים של KDE
+Comment[hi]=केडीई रीसोर्सेज़ कॉन्फ़िगर करें
+Comment[hr]=Konfiguriranje KDE resursa
+Comment[hu]=A KDE-s erőforrások beállítása
+Comment[id]=Konfigurasikan Sumber Daya KDE
+Comment[is]=Stilla KDE auðlindir
+Comment[it]=Configura le risorse di KDE
+Comment[ja]=KDE リソースの設定
+Comment[ka]=KDE რესურსების გამართვა
+Comment[kk]=KDE ресурстарды баптау
+Comment[km]=កំណត់​រចនាសម្ព័ន្ធ​ធនធាន KDE
+Comment[lb]=KDE-Ressourcen astellen
+Comment[lt]=Konfigūruoti KDE resursus
+Comment[lv]=Konfigurē KDE resursus
+Comment[mk]=Ги конфигурира KDE ресурсите
+Comment[ms]=Selaraskan Sumber KDE
+Comment[nb]=Sett opp KDE-ressurser
+Comment[nds]=KDE-Ressourcen instellen
+Comment[ne]=KDE संसाधन कन्फिगर गर्नुहोस्
+Comment[nl]=KDE-gegevensbronnen instellen
+Comment[nn]=Set opp KDE-ressursar
+Comment[pa]=KDE ਸਰੋਤਾਂ ਦੀ ਸੰਰਚਨਾ
+Comment[pl]=Konfiguracja źródeł danych KDE
+Comment[pt]=Configurar Recursos do KDE
+Comment[pt_BR]=Configura as Fontes de Dados do KDE
+Comment[ro]=Configurează resursele KDE
+Comment[ru]=Настройка ресурсов KDE
+Comment[rw]=Kuboneza Ibikoraba bya KDE
+Comment[se]=Heivet KDE-resurssaid
+Comment[sk]=Nastavenie zdrojov KDE
+Comment[sl]=Nastavi vire KDE
+Comment[sr]=Подешавање KDE-ових ресурса
+Comment[sr@Latn]=Podešavanje KDE-ovih resursa
+Comment[sv]=Anpassa KDE-resurser
+Comment[ta]=KDE மூலங்களை கட்டமை
+Comment[te]=కెడిఈ వనరులను కూర్చుమూ
+Comment[tg]=Танзими манбаъи истифодашуда тавассути китоби адрес
+Comment[th]=ปรับแต่งทรัพยากรของ KDE
+Comment[tr]=KDE Kaynaklarını Yapılandır
+Comment[tt]=KDE Resursların Caylaw
+Comment[uk]=Налаштування ресурсів KDE
+Comment[uz]=KDE manbalarini moslash
+Comment[uz@cyrillic]=KDE манбаларини мослаш
+Comment[vi]=Cấu hình các tài nguyên KDE.
+Comment[zh_CN]=配置 KDE 资源
+Comment[zh_HK]=設定 KDE 使用的資源
+Comment[zh_TW]=在此設定 KDE 的資源
+
+Keywords=resources,konnector resource,contact resource,calendar resource,notes resource,imap
+Keywords[af]=hulpbronne,konnector hulpbron,kontak hulpbron,kalender hulpbron, notas hulpbron, imap
+Keywords[be]=рэсурсы,кантакты,каляндар,нататкі,resources,konnector resource,contact resource,calendar resource,notes resource,imap
+Keywords[bg]=ресурс, ресурси, настройки, бележки, адресна, адресник, книга, календар, resources, konnector resource, contact resource, calendar resource, notes resource, imap
+Keywords[bs]=resources,konnector resource,contact resource,calendar resource,notes resource,imap,resursi,konektor resurs,kontakt resurs,kalendar resurs,bilješke resurs
+Keywords[ca]=recursos,recurs konnector,recurs de contacte,recurs de calendari,recurs de notes,imap
+Keywords[cs]=zdroje,konektor,kontakty,kalendář,poznámky,IMAP
+Keywords[csb]=dostónczi,konnector, dostónczi kalãdzôrza,dostónczi wizutnych biletów, dosŧónczi notownika,imap
+Keywords[da]=ressourcer,konnector ressource,kontakt resource,kalender ressource,noter ressource,imap
+Keywords[de]=Ressourcen,Kontakt-Ressource,Kalender-Ressource,Notizen-Ressource,IMAP
+Keywords[el]=πόροι,πόροι του konnector,πόροι επαφών,πόροι ημερολογίου,πόροι σημειώσεων,imap
+Keywords[eo]=risurcoj,kontakrisurco,kalendarrisurco,notrisuroco
+Keywords[es]=recursos, recurso konnector, recurso de contacto, recurso de calendario, recurso de notas, konnector, contacto, calendario, notas, imap
+Keywords[et]=ressursid,konnectori ressurss,kontakti ressurss,kalendri ressurss,sedelite ressurss,imap
+Keywords[eu]=baliabideak,konnector baliabidea,contact baliabidea,egutegi baliabidea,oharren baliabidea,imap
+Keywords[fa]=منابع، منبع konnector، منبع تماس، منبع تقویم، منبع یادداشتها، imap
+Keywords[fi]=resurssit,konnektor-resurssi,yhteystietojen resurssi,muistiinpanojen resurssi,imap
+Keywords[fr]=resources,konnector,contact,calendrier,notes,imap,agenda,rendez-vous
+Keywords[fy]=helpboarne,ferbinings-helpboarne,kontakt-helpboarne,kalinder-helpboarne,notysje-helpboarne,imap,kontakt,kalinder,notysje,ferbining
+Keywords[ga]=acmhainní,acmhainn konnector,acmhainn teagmhála,acmhainn fhéilire,acmhainn nótaí,imap
+Keywords[gl]=recursos,recurso konnector,recurso contactos,recurso axenda,recurso notas ,recurso imap
+Keywords[he]=משאבים, konnector, לוח שנה, פתקים, imap, פתק, esources, resource,contact resource,calendar resource,notes resource
+Keywords[hi]=रीसोर्सेज़,कनेक्टर रीसोर्स,कॉन्टेक्ट रीसोर्स,कैलेंडर रीसोर्स,नोट्स रीसोर्स,आईमैप
+Keywords[hr]=resursi,konnector resurs,contact resurs,calendar resurs,notes resurs,imap
+Keywords[hu]=erőforrások,csatoló-erőforrás,névjegy-erőforrás,naptár-erőforrás,feljegyzés-erőforrás,IMAP
+Keywords[it]=risorse,risorsa konnector,risorsa contatti, risorsa calendario,risorsa note,imap
+Keywords[ja]=リソース,konnector resource, コネクターリソース,コンタクトリソース,カレンダーリソース, ノートリソース,imap
+Keywords[ka]=რესურსები,კავშირის რესურსები,საკონტაქტო რესურსები,კალენდრის რესურსები,შენიშვნათა რესურსები,imap
+Keywords[km]=ធនធាន, ធនធាន konnector, ធនធាន​ទំនាក់ទំនង, ធនធាន​ប្រតិទិន, ធនធាន​ចំណាំ,imap
+Keywords[lb]=Ressourcen,Konnector-Ressource,Kontakt-Ressource,Kalenner-Ressource,Notizen-Ressource,imap
+Keywords[lt]=resursai,konnector resursas,kontaktų resursas,kalendoriaus resursas,priminimų resursas,imap
+Keywords[ms]=sumber, sumber konnector, sumber hubungan, sumber kalendar, sumber nota,imap
+Keywords[nb]=ressurser,konnector-ressurs,kontaktressurs,kalenderressurs, notatressurs,imap
+Keywords[nds]=Ressourcen,konnector-Ressource,Kontakt-Ressource,Kalenner-Ressource,Notiz-Ressource,IMAP
+Keywords[ne]=संसाधन, जडानकर्ता संसाधन, सम्पर्क संसाधन, पात्रो संसाधन, टिपोट संसाधन, आई म्याप
+Keywords[nl]=gegevensbron,verbindingsgegevensbron,contact-gegevensbron,kalender-gegevensbron,notities-gegevensbron,imap,contact,kalender,notitie,verbinding
+Keywords[nn]=ressursar,konnector-ressurs,kontaktressurs,kalenderressurs,notatressurs,imap
+Keywords[pl]=zasoby,konnector,zasoby wizytówek,zasoby kalendarzy,zasoby notatek,źródła danych wizytówek,źródła danych kalendarzy,źródła danych notatek,imap
+Keywords[pt]=recursos,recurso de conector,recurso de contacto,recurso de calendário,recurso de notas,imap
+Keywords[pt_BR]=fontes de dados,konnector,contato,conector,calendário, notas,imap
+Keywords[ro]=resurse,konnector,contact,calendar,notiţe,imap
+Keywords[rw]=ibikorana, ibikorana impuza, ibikorana aderesi, ibikorana kalindari, ibikorana impugukirwa, imap
+Keywords[se]=resurssat,konnector-resursa,oktavuohtaresursa,kaleandarresursa,nohtaresursa,imap
+Keywords[sk]=zdroje,zdroj pre konnector,zdroj kontaktov,zdroj kalendára,zdroj poznámok,imap
+Keywords[sl]=resurs,vir,stikov vir,koledarski vir,imap,
+Keywords[sr]=resources,konnector resource,contact resource,calendar resource,notes resource,imap,ресурси,ресурс,повезивач,контакт ресурс, календарски ресурс
+Keywords[sr@Latn]=resources,konnector resource,contact resource,calendar resource,notes resource,imap,resursi,resurs,povezivač,kontakt resurs, kalendarski resurs
+Keywords[sv]=resurser,konnector-resurs,kontaktresurs,kalenderresurs,anteckningsresurs,IMAP
+Keywords[ta]=மூலங்கள்,இணைப்பு மூலம்,தொடர்பு மூலம்,நாள்காட்டி மூலம்,குறிப்புகள் மூலம்e,imap
+Keywords[te]=వనరులు,కన్నెక్టర్ వనరు,సంప్రదింపు వనరు, పంచాంగం వనరు, నోట్స్ వనరు, ఐమేప్
+Keywords[tr]=kaynaklar,bağlantı kaynağı,iletiişm kaynağı,takvim kaynak,not kaynağı,imap
+Keywords[uk]=ресурси,ресурс для konnector,ресурс контактів,ресурс календаря,ресурс приміток,imap
+Keywords[vi]=tài nguyên,tài nguyên konnector,tài nguyên liên lạc,tài nguyên lịch,tài nguyên ghi chú,imap
+Keywords[zh_CN]=resources,konnector resource,contact resource,calendar resource,notes resource,imap资源,konnector 资源,联系人资源,日历资源,备忘资源
+
+Categories=Qt;KDE;X-KDE-settings-components;
+OnlyShowIn=KDE;
+
diff --git a/kresources/kresources_manager.desktop b/kresources/kresources_manager.desktop
new file mode 100644
index 000000000..66d5731fa
--- /dev/null
+++ b/kresources/kresources_manager.desktop
@@ -0,0 +1,75 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=KResources/Manager
+Comment=KResource Manager
+Comment[af]=KHulpbron bestuurder
+Comment[be]=Кіраўнік рэсурсаў KResource
+Comment[bg]=Мениджър на KResource
+Comment[bn]=কে-রিসোর্স ম্যানেজার
+Comment[br]=Merour KResource
+Comment[bs]=K Upravitelj resursima
+Comment[ca]=Gestor KResource
+Comment[cs]=Správce zdrojů
+Comment[csb]=Menedżer systemë KResource
+Comment[da]=KResource-håndtering
+Comment[de]=KDE Ressourcen-Verwaltung
+Comment[el]=Διαχειριστής του KResource
+Comment[eo]=Risurca administranto
+Comment[es]=Administrador de KResource
+Comment[et]=KResource'i haldur
+Comment[eu]=KResource kudeatzailea
+Comment[fa]=مدیر KResource
+Comment[fi]=KResource hallinta
+Comment[fr]=Gestionnaire de KResource
+Comment[fy]=KResource-behearder
+Comment[ga]=Bainisteoir KResource
+Comment[gl]=Xestor de KResource
+Comment[he]=מנהל משאבים KResource
+Comment[hi]=के-रीसोर्स प्रबंधक
+Comment[hr]=KResource upravljanje
+Comment[hu]=KResource-kezelőprogram
+Comment[id]=Manajer KResource
+Comment[is]=KResource stjóri
+Comment[it]=Gestore KResource
+Comment[ja]=K リソースマネージャ
+Comment[ka]=KResource-ის მმართველი
+Comment[kk]=KResource менеджері
+Comment[km]=កម្មវិធី​គ្រប់គ្រង KResource
+Comment[lb]=KResource-Manager
+Comment[lt]=KResouse tvarkyklė
+Comment[lv]=KResursu menedžeris
+Comment[mk]=Менаџер на KResource
+Comment[ms]=Pengurus KResource
+Comment[nb]=KRessurshåndterer
+Comment[nds]=KResource-Pleger
+Comment[ne]=KResource प्रबन्धक
+Comment[nl]=KResource-beheerder
+Comment[nn]=KResource-handtering
+Comment[pa]=KResource ਪ੍ਰਬੰਧਕ
+Comment[pl]=Menedżer systemu KResource
+Comment[pt]=Gestor KResource
+Comment[pt_BR]=Gerenciador de Fontes de Dados
+Comment[ro]=Manager KResource
+Comment[ru]=Администратор KResource
+Comment[se]=KResource-gieđahalli
+Comment[sk]=Správca KResource
+Comment[sl]=Upravitelj virov KResource
+Comment[sr]=KResource менаџер
+Comment[sr@Latn]=KResource menadžer
+Comment[sv]=KDE-resurshantering
+Comment[ta]=கேமூல மேலாளர்
+Comment[te]=కెవనరు అభికర్త
+Comment[tg]=Менеҷери KResource
+Comment[th]=ตัวจัดการทรัพยากร K
+Comment[tr]=KResource Yöneticisi
+Comment[tt]=KResource İdäräçese
+Comment[uk]=Менеджер KResource
+Comment[uz]=KResource boshqaruvchisi
+Comment[uz@cyrillic]=KResource бошқарувчиси
+Comment[vi]=Bộ quản lý tài nguyên KResource
+Comment[zh_CN]=KResource 管理器
+Comment[zh_HK]=KResource 管理員
+Comment[zh_TW]=KRsource 管理員
+
+[PropertyDef::X-KDE-ResourceFamily]
+Type=QString
diff --git a/kresources/kresources_plugin.desktop b/kresources/kresources_plugin.desktop
new file mode 100644
index 000000000..52959e614
--- /dev/null
+++ b/kresources/kresources_plugin.desktop
@@ -0,0 +1,79 @@
+[Desktop Entry]
+Type=ServiceType
+X-KDE-ServiceType=KResources/Plugin
+Comment=KResource Framework Plugin
+Comment[af]=KHulpbron Raamwerk Inprop module
+Comment[az]=KResource Əlavəsi
+Comment[be]=Модуль падсістэмы кіравання рэсурсамі KResource
+Comment[bg]=Приставка за ресурсната системата KResource Framework
+Comment[bn]=কে-রিসোর্স ফ্রেম-ওয়ার্ক প্লাগ-ইন
+Comment[bs]=KResource Framework dodatak
+Comment[ca]=Connector per a l'estructura de KResource
+Comment[cs]=Modul systému zdrojů KDE
+Comment[csb]=Plugins systemë KResource
+Comment[cy]=Ategyn Fframwaith KAdnoddau
+Comment[da]=KResource-omgivelsesplugin
+Comment[de]=KResource Framework-Modul
+Comment[el]=Πρόσθετο KResource Framework
+Comment[eo]=Risurckadraĵa kromaĵo
+Comment[es]=Plugin del entorno de KResource
+Comment[et]=KResource'i raamistiku plugin
+Comment[eu]=KResource sistemako plugin-a
+Comment[fa]=وصلۀ چارچوب KResource
+Comment[fi]=KResource Framework -lisäosa
+Comment[fr]=Module externe du cadre de KResource
+Comment[gl]=Plugin do entorno de KResource
+Comment[he]=קובץ מסגרת תיאור משאבים (RDF)
+Comment[hi]=केरिसोर्स फ्रेमवर्क प्लगइन
+Comment[hr]=Dodatak KResource radnog okvira
+Comment[hu]=Bővítőmodul a KResource keretrendszerhez
+Comment[id]=Plugin Kerangka KResource
+Comment[is]=KResource uppbygginar íforrit
+Comment[it]=Plugin per l'infrastruttura KResource
+Comment[ja]=K リソース・フレームワーク・プラグイン
+Comment[ka]=KResource-ის ბლოკის მოდული
+Comment[kk]=KResource жүйесінің модулі
+Comment[km]=កម្មវិធី​ជំនួយ​ខាង​ក្នុងនៃ​គ្រោង KResource
+Comment[ko]=K자원 프레임워크 플러그인
+Comment[lb]=KResource-Framework-Plugin
+Comment[lt]=KResource struktūros priedas
+Comment[mk]=KResource рамковен приклучок
+Comment[mn]=Нөөц Тодорхойлох-Файлын плугин (RDF)
+Comment[ms]=Plug masuk Kerangka KResource
+Comment[nb]=KRessursrammeverk programtillegg
+Comment[nds]=Plugin för dat KResource-Rahmenwark
+Comment[ne]=KResource फ्रेमवर्क प्लगइन
+Comment[nl]=KResource Framework-plugin
+Comment[nn]=Programtillegg for KResource-rammeverket
+Comment[pa]=KResource ਫਰੇਮਵਰਕ ਪਲੱਗਿੰਨ
+Comment[pl]=Wtyczka systemu KResource
+Comment[pt]='Plugin' da Plataforma do KResource
+Comment[pt_BR]=Plug-in do KResource
+Comment[ro]=Modul cadru KResource
+Comment[ru]=Модуль подсистемы KResource
+Comment[rw]=Icomeka ry'Imiterere rya KIbikorana
+Comment[sk]=KResource Framework plugin
+Comment[sl]=Vstavek za ogrodje KResource
+Comment[sq]=Shtojca KResource Framework
+Comment[sr]=Прикључак KResource Framework-а
+Comment[sr@Latn]=Priključak KResource Framework-a
+Comment[sv]=Insticksprogram för resursramverk
+Comment[ta]=கேவழிமுறை கட்டமைப்பு சொருகுபொருள்
+Comment[te]=కెవనరు తడక ప్లగిన్
+Comment[tg]=Мутассалкунандаи қолабгар барои KResource
+Comment[th]=ปลั๊กอินโครงงานของ KResource
+Comment[tr]=KResource Eklentisi
+Comment[tt]=KResource Eşçara Östämäse
+Comment[uk]=Втулок структури KResource
+Comment[uz]=KResource toʻplam plagini
+Comment[uz@cyrillic]=KResource тўплам плагини
+Comment[vi]=Bộ cầm phít khuôn khổ tài nguyên KResource
+Comment[zh_CN]=KResource 框架插件
+Comment[zh_HK]=KResource Framework 外掛程式
+Comment[zh_TW]=KRsource Framework 外掛程式
+
+[PropertyDef::X-KDE-ResourceFamily]
+Type=QString
+
+[PropertyDef::X-KDE-ResourceType]
+Type=QString
diff --git a/kresources/manager.h b/kresources/manager.h
new file mode 100644
index 000000000..b129a7317
--- /dev/null
+++ b/kresources/manager.h
@@ -0,0 +1,422 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRESOURCES_MANAGER_H
+#define KRESOURCES_MANAGER_H
+
+#include <qdict.h>
+#include <qstringlist.h>
+
+#include <kdebug.h>
+#include <kresources/factory.h>
+#include <kresources/managerimpl.h>
+
+namespace KRES {
+
+class Resource;
+
+/**
+ Observer class for Manager class. For getting notified about changes of
+ Resources managed by a Manager object implement this Observer interface and
+ add an object of this implementation to the Manager using addObserver(). The
+ resourceAdded(), resourceModified() and resourceDeleted() functions of your
+ implementation will be called whenever resources managed by the Manager object
+ are added, modified or deleted.
+*/
+template<class T>
+class ManagerObserver
+{
+ public:
+ virtual void resourceAdded( T *resource ) = 0;
+ virtual void resourceModified( T *resource ) = 0;
+ virtual void resourceDeleted( T *resource ) = 0;
+};
+
+/**
+ @internal
+*/
+class ManagerNotifier
+{
+ public:
+ virtual void notifyResourceAdded( Resource *resource ) = 0;
+ virtual void notifyResourceModified( Resource *resource ) = 0;
+ virtual void notifyResourceDeleted( Resource *resource ) = 0;
+};
+
+/**
+ This class provides a manager for resources of a specified family. It takes
+ care of loading and saving resource configurations and provides access to the
+ resources and their attributes. External changes in the resource configuration
+ are notified by the ManagerObserver interface. If your application needs to be
+ notified about resource configuration changes, you have to subclass
+ ManagerObserver and add it to the Manager by addObserver().
+
+ Since KDE 3.4 it's required to supply your application with a *.desktop
+ file for each resource family you introduce. The ServiceType should be of
+ KResources/Manager.
+*/
+template<class T>
+class Manager : private ManagerNotifier
+{
+ public:
+ /**
+ Iterator for iterations over all resources managed by a manager.
+ */
+ 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;
+ };
+
+ /**
+ Return Iterator on first resource. If there is no resource returns end().
+ */
+ Iterator begin()
+ {
+ Iterator it;
+ it.mIt = mImpl->resourceList()->begin();
+ return it;
+ }
+
+ /**
+ Return Iterator indicating end of resource list.
+ */
+ Iterator end()
+ {
+ Iterator it;
+ it.mIt = mImpl->resourceList()->end();
+ return it;
+ }
+
+ /**
+ Iterator for iterations over only active resources managed by a manager.
+ */
+ 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;
+ };
+
+ /**
+ Return Iterator on first active resource. If there is no active resource
+ returns end().
+ */
+ 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;
+ }
+
+ /**
+ Return Iterator indicating end of active resource list.
+ */
+ ActiveIterator activeEnd()
+ {
+ ActiveIterator it;
+ it.mIt = mImpl->resourceList()->end();
+ it.mList = mImpl->resourceList();
+ return it;
+ }
+
+ /**
+ Return true, if manager doesn't hold any resources. If there are resources
+ return false.
+ */
+ bool isEmpty() const { return mImpl->resourceList()->isEmpty(); }
+
+ /**
+ Create manager for given resource family. The family argument is used as
+ identifier for loading and saving resource configurations.
+ */
+ 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( this, family );
+ mObservers.setAutoDelete( false );
+ }
+
+ virtual ~Manager()
+ {
+ delete mImpl;
+ }
+
+ /**
+ Recreate Resource objects from configuration file. If cfg is 0, read
+ standard configuration file determined by family name.
+ */
+ 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 determined by family name.
+ */
+ 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 );
+ }
+
+ /**
+ Remove resource from manager. This deletes the Resource object.
+ */
+ void remove( Resource *resource )
+ {
+ if ( resource ) mImpl->remove( resource );
+ }
+
+ /**
+ Call this to notify manager about changes of the configuration of the
+ given resource.
+ */
+ void change( T *resource )
+ {
+ mImpl->change( resource );
+ }
+
+ /**
+ Return standard resource.
+ */
+ T *standardResource()
+ {
+ return static_cast<T *>( mImpl->standardResource() );
+ }
+
+ /**
+ Set standard resource.
+ */
+ void setStandardResource( T *resource )
+ {
+ if ( resource ) mImpl->setStandardResource( resource );
+ }
+
+ /**
+ Set active state of resource.
+ */
+ void setActive( Resource *resource, bool active )
+ {
+ if ( resource ) mImpl->setActive( resource, active );
+ }
+
+ /**
+ Returns a list of the names of the resources managed by the
+ Manager for this family.
+ */
+ QStringList resourceNames() const
+ {
+ return mImpl->resourceNames();
+ }
+
+ /**
+ Creates a new resource of type @p 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 resourceTypeNames()
+ */
+ T *createResource( const QString& type )
+ {
+ return dynamic_cast<T *>( mFactory->resource( type, 0 ) );
+ }
+
+ /**
+ Returns a list of the names of all available resource types.
+ */
+ QStringList resourceTypeNames() const
+ {
+ return mFactory->typeNames();
+ }
+
+ /**
+ Return list of descriptions of all available resource types.
+ */
+ 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 += QString::fromLatin1(" (") + mFactory->typeDescription( *it ) + QString::fromLatin1(")");
+
+ typeDescs.append( desc );
+ }
+
+ return typeDescs;
+ }
+
+ /**
+ Add observer for resource changes to manager. See ManagerObserver. The
+ Manager does not take ownership of the Observer object.
+ */
+ void addObserver( ManagerObserver<T> *observer )
+ {
+ mObservers.append( observer );
+ }
+
+ /**
+ Remove Observer for resource changes from manager. See ManagerObserver.
+ The Observer is not deleted by the Manager after being removed.
+ */
+ void removeObserver( ManagerObserver<T> *observer )
+ {
+ mObservers.remove( observer );
+ }
+
+ private:
+ /**
+ Implementation of the ManagerNotifier interface.
+ */
+ void notifyResourceAdded( Resource *res )
+ {
+ kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl;
+ T *resource = dynamic_cast<T *>( res );
+ if ( resource ) {
+ ManagerObserver<T> *observer;
+ for ( observer = mObservers.first(); observer;
+ observer = mObservers.next() )
+ observer->resourceAdded( resource );
+ }
+ }
+
+ /**
+ Implementation of the ManagerNotifier interface.
+ */
+ void notifyResourceModified( Resource *res )
+ {
+ kdDebug(5650) << "Manager::resourceModified " << res->resourceName()
+ << endl;
+ T *resource = dynamic_cast<T *>( res );
+ if ( resource ) {
+ ManagerObserver<T> *observer;
+ for ( observer = mObservers.first(); observer;
+ observer = mObservers.next() )
+ observer->resourceModified( resource );
+ }
+ }
+
+ /**
+ Implementation of the ManagerNotifier interface.
+ */
+ void notifyResourceDeleted( Resource *res )
+ {
+ kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName()
+ << endl;
+ T *resource = dynamic_cast<T *>( res );
+ if ( resource ) {
+ ManagerObserver<T> *observer;
+ for ( observer = mObservers.first(); observer;
+ observer = mObservers.next() ) {
+ kdDebug(5650) << "Notifying a observer to Manager..." << endl;
+ observer->resourceDeleted( resource );
+ }
+ }
+ }
+
+ private:
+ ManagerImpl *mImpl;
+ Factory *mFactory;
+ QPtrList<ManagerObserver<T> > mObservers;
+};
+
+}
+
+#endif
diff --git a/kresources/manageriface.h b/kresources/manageriface.h
new file mode 100644
index 000000000..7644d7bc2
--- /dev/null
+++ b/kresources/manageriface.h
@@ -0,0 +1,46 @@
+/*
+ This file is part of libkresources.
+
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KRES_MANAGERIFACE_H
+#define KRES_MANAGERIFACE_H
+
+#include <dcopobject.h>
+
+namespace KRES {
+
+class KRESOURCES_EXPORT ManagerIface : virtual public DCOPObject
+{
+ K_DCOP
+
+ k_dcop_signals:
+ void signalKResourceAdded( QString managerId, QString resourceId );
+ void signalKResourceModified( QString managerId, QString resourceId );
+ void signalKResourceDeleted( QString managerId, QString resourceId );
+
+ k_dcop:
+ virtual ASYNC dcopKResourceAdded( QString managerId, QString resourceId ) = 0;
+ virtual ASYNC dcopKResourceModified( QString managerId, QString resourceId ) = 0;
+ virtual ASYNC dcopKResourceDeleted( QString managerId, QString resourceId ) = 0;
+};
+
+}
+
+#endif
diff --git a/kresources/managerimpl.cpp b/kresources/managerimpl.cpp
new file mode 100644
index 000000000..01380e03b
--- /dev/null
+++ b/kresources/managerimpl.cpp
@@ -0,0 +1,448 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <dcopclient.h>
+
+#include <kaboutdata.h>
+#include <kapplication.h>
+#include <kdebug.h>
+#include <kconfig.h>
+#include <kstandarddirs.h>
+
+#include "resource.h"
+#include "factory.h"
+#include "manager.h"
+#include "managerimpl.h"
+#include "manageriface_stub.h"
+
+using namespace KRES;
+
+ManagerImpl::ManagerImpl( ManagerNotifier *notifier, const QString &family )
+ : DCOPObject( "ManagerIface_" + family.utf8() ),
+ mNotifier( notifier ),
+ mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
+ mFactory( 0 ), mConfigRead( false )
+{
+ kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
+
+ mId = KApplication::randomString( 8 );
+
+ // Register with DCOP
+ if ( !kapp->dcopClient()->isRegistered() ) {
+ kapp->dcopClient()->registerAs( "KResourcesManager" );
+ kapp->dcopClient()->setDefaultObject( objId() );
+ }
+
+ kdDebug(5650) << "Connecting DCOP signals..." << endl;
+ if ( !connectDCOPSignal( 0, "ManagerIface_" + family.utf8(),
+ "signalKResourceAdded( QString, QString )",
+ "dcopKResourceAdded( QString, QString )", false ) )
+ kdWarning(5650) << "Could not connect ResourceAdded signal!" << endl;
+
+ if ( !connectDCOPSignal( 0, "ManagerIface_" + family.utf8(),
+ "signalKResourceModified( QString, QString )",
+ "dcopKResourceModified( QString, QString )", false ) )
+ kdWarning(5650) << "Could not connect ResourceModified signal!" << endl;
+
+ if ( !connectDCOPSignal( 0, "ManagerIface_" + family.utf8(),
+ "signalKResourceDeleted( QString, QString )",
+ "dcopKResourceDeleted( QString, QString )", false ) )
+ kdWarning(5650) << "Could not connect ResourceDeleted signal!" << endl;
+
+ kapp->dcopClient()->setNotifications( true );
+}
+
+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 = defaultConfigFile( mFamily );
+ 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 );
+ }
+
+ mConfigRead = true;
+}
+
+void ManagerImpl::writeConfig( KConfig *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;
+}
+
+void ManagerImpl::add( Resource *resource )
+{
+ resource->setActive( true );
+
+ if ( mResources.isEmpty() ) {
+ mStandard = resource;
+ }
+
+ mResources.append( resource );
+
+ if ( mConfigRead )
+ writeResourceConfig( resource, true );
+
+ signalKResourceAdded( mId, resource->identifier() );
+}
+
+void ManagerImpl::remove( Resource *resource )
+{
+ if ( mStandard == resource ) mStandard = 0;
+ removeResource( resource );
+
+ mResources.remove( resource );
+
+ signalKResourceDeleted( mId, resource->identifier() );
+
+ delete resource;
+
+ kdDebug(5650) << "Finished ManagerImpl::remove()" << endl;
+}
+
+void ManagerImpl::change( Resource *resource )
+{
+ writeResourceConfig( resource, true );
+
+ signalKResourceModified( mId, resource->identifier() );
+}
+
+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;
+}
+
+// DCOP asynchronous functions
+
+void ManagerImpl::dcopKResourceAdded( QString managerId, QString resourceId )
+{
+ if ( managerId == mId ) {
+ kdDebug(5650) << "Ignore DCOP notification to myself" << endl;
+ return;
+ }
+ kdDebug(5650) << "Receive DCOP call: added resource " << resourceId << endl;
+
+ if ( getResource( resourceId ) ) {
+ kdDebug(5650) << "This resource is already known to me." << endl;
+ }
+
+ if ( !mConfig ) createStandardConfig();
+
+ mConfig->reparseConfiguration();
+ Resource *resource = readResourceConfig( resourceId, true );
+
+ if ( resource ) {
+ mNotifier->notifyResourceAdded( resource );
+ } else
+ kdError() << "Received DCOP: resource added for unknown resource "
+ << resourceId << endl;
+}
+
+void ManagerImpl::dcopKResourceModified( QString managerId, QString resourceId )
+{
+ if ( managerId == mId ) {
+ kdDebug(5650) << "Ignore DCOP notification to myself" << endl;
+ return;
+ }
+ kdDebug(5650) << "Receive DCOP call: modified resource " << resourceId << endl;
+
+ Resource *resource = getResource( resourceId );
+ if ( resource ) {
+ mNotifier->notifyResourceModified( resource );
+ } else
+ kdError() << "Received DCOP: resource modified for unknown resource "
+ << resourceId << endl;
+}
+
+void ManagerImpl::dcopKResourceDeleted( QString managerId, QString resourceId )
+{
+ if ( managerId == mId ) {
+ kdDebug(5650) << "Ignore DCOP notification to myself" << endl;
+ return;
+ }
+ kdDebug(5650) << "Receive DCOP call: deleted resource " << resourceId << endl;
+
+ Resource *resource = getResource( resourceId );
+ if ( resource ) {
+ mNotifier->notifyResourceDeleted( resource );
+
+ kdDebug(5650) << "Removing item from mResources" << endl;
+ // Now delete item
+ if ( mStandard == resource )
+ mStandard = 0;
+ mResources.remove( resource );
+ } else
+ kdError() << "Received DCOP: resource deleted for unknown resource "
+ << resourceId << endl;
+}
+
+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;
+}
+
+Resource *ManagerImpl::readResourceConfig( const QString &identifier,
+ bool checkActive )
+{
+ kdDebug(5650) << "ManagerImpl::readResourceConfig() " << identifier << endl;
+
+ if ( !mFactory ) {
+ kdError(5650) << "ManagerImpl::readResourceConfig: mFactory is 0. Did the app forget to call readConfig?" << endl;
+ return 0;
+ }
+
+ 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" );
+ QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" );
+ if ( resource->isActive() ) {
+ if ( passiveKeys.contains( key ) ) { // remove it from passive list
+ passiveKeys.remove( key );
+ mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
+ }
+ if ( !activeKeys.contains( key ) ) { // add it to active list
+ activeKeys.append( key );
+ mConfig->writeEntry( "ResourceKeys", activeKeys );
+ }
+ } else if ( !resource->isActive() ) {
+ if ( activeKeys.contains( key ) ) { // remove it from active list
+ activeKeys.remove( key );
+ mConfig->writeEntry( "ResourceKeys", activeKeys );
+ }
+ if ( !passiveKeys.contains( key ) ) { // add it to passive list
+ passiveKeys.append( key );
+ mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
+ }
+ }
+ }
+
+ 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;
+}
+
+QString ManagerImpl::defaultConfigFile( const QString &family )
+{
+ return QString( "kresources/%1/stdrc" ).arg( family );
+}
diff --git a/kresources/managerimpl.h b/kresources/managerimpl.h
new file mode 100644
index 000000000..107f7b1f0
--- /dev/null
+++ b/kresources/managerimpl.h
@@ -0,0 +1,107 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KRESOURCES_MANAGERIMPL_H
+#define KRESOURCES_MANAGERIMPL_H
+
+#include <qstring.h>
+#include <qptrlist.h>
+#include <qdict.h>
+
+#include "manageriface.h"
+#include <kresources/resource.h>
+
+class KConfig;
+
+namespace KRES {
+
+class Resource;
+class Factory;
+class ManagerNotifier;
+
+/**
+ @internal
+
+ Do not use this class directly. Use ResourceManager instead
+*/
+class KRESOURCES_EXPORT ManagerImpl : virtual public ManagerIface
+{
+ public:
+ ManagerImpl( ManagerNotifier *, const QString &family );
+ ~ManagerImpl();
+
+ void readConfig( KConfig * );
+ void writeConfig( KConfig * );
+
+ void add( Resource *resource );
+ void remove( Resource *resource );
+ void change( Resource *resource );
+
+ 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();
+
+ static QString defaultConfigFile( const QString &family );
+
+ private:
+ // dcop calls
+ void dcopKResourceAdded( QString managerId, QString resourceId );
+ void dcopKResourceModified( QString managerId, QString resourceId );
+ void dcopKResourceDeleted( QString managerId, QString resourceId );
+
+ 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 );
+
+ ManagerNotifier *mNotifier;
+ QString mFamily;
+ KConfig *mConfig;
+ KConfig *mStdConfig;
+ Resource *mStandard;
+ Factory *mFactory;
+ Resource::List mResources;
+ QString mId;
+ bool mConfigRead;
+
+ class ManagerImplPrivate;
+ ManagerImplPrivate *d;
+};
+
+}
+
+#endif
diff --git a/kresources/resource.cpp b/kresources/resource.cpp
new file mode 100644
index 000000000..ff30cb552
--- /dev/null
+++ b/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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kconfig.h>
+#include <klocale.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;
+
+ if ( config ) {
+ d->mType = config->readEntry( "ResourceType" );
+ d->mName = config->readEntry( "ResourceName" );
+ d->mReadOnly = config->readBoolEntry( "ResourceIsReadOnly", false );
+ d->mActive = config->readBoolEntry( "ResourceIsActive", true );
+ d->mIdentifier = config->readEntry( "ResourceIdentifier" );
+ } else {
+ d->mType = "type";
+ d->mName = i18n("resource");
+ 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;
+}
+
+#include "resource.moc"
diff --git a/kresources/resource.h b/kresources/resource.h
new file mode 100644
index 000000000..f0e988fe3
--- /dev/null
+++ b/kresources/resource.h
@@ -0,0 +1,420 @@
+/*
+ This file is part of libkresources
+
+ Copyright (c) 2001-2003 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef KRESOURCES_RESOURCE_H
+#define KRESOURCES_RESOURCE_H
+
+#include <qmutex.h>
+#include <qvaluelist.h>
+#include <qwidget.h>
+
+#include <klibloader.h>
+
+class KConfig;
+
+namespace KRES {
+
+class ConfigWidget;
+
+/**
+ \mainpage The KDE Resource library
+
+ The KDE Resource framework can be used to manage resources of
+ different types, organized in families. The Resource framework
+ is for example 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>In your application, you can use ResourceManager to keep track
+ of the resources in your family, and you can use 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>:
+\code
+#include <kconfig.h>
+#include <kresources/resource.h>
+
+class ResourceExample : public KRES::Resource
+{
+ public:
+ ResourceExample( const KConfig * );
+ ~ResourceExample();
+ void writeConfig( KConfig *config );
+
+ private:
+ QString mLocation;
+ QString mPassword;
+}
+\endcode
+
+ <B>resourceexample.cpp</B>:
+\code
+#include <kconfig.h>
+
+#include "resourceexample.h"
+
+ResourceExample::ResourceExample( const KConfig *config )
+ : Resource( config )
+{
+ if ( config ) {
+ mLocation = config->readPathEntry( "Location" );
+ mPassword = KStringHandler::obscure( config->readEntry( "Password" ) );
+ } else {
+ mLocation = ""; // Or some sensible default
+ mPassword = "";
+ }
+}
+
+void ResourceExample::writeConfig( KConfig *config )
+{
+ KRES::Resource::writeConfig( config );
+ config->writePathEntry( "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 );
+ }
+}
+\endcode
+
+ <B>resourceexampleconfig.h</B>:
+\code
+#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;
+};
+\endcode
+
+ <B>resourceexampleconfig.cpp</B>:
+\code
+#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 )
+{
+ 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() << "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() << "ERROR: ResourceExampleConfig::saveSettings(): no ResourceExample, cast failed" << endl;
+}
+\endcode
+
+ <B>resourceexample.desktop</B>:
+\code
+[Desktop Entry]
+Type=Service
+
+[Misc]
+Encoding=UTF-8
+Name=Example Resource
+
+[Plugin]
+Type=exchange
+X-KDE-Library=resourceexample
+\endcode
+
+ <B>Makefile.am</B>
+\code
+kde_module_LTLIBRARIES = resourceexample.la
+
+resourceexample_la_SOURCES = resourceexample.cpp resourceexampleconfig.cpp
+resourceexample_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN)
+resourceexample_la_LIBADD = -lkresources
+
+servicedir = $(kde_datadir)/resources/example
+service_DATA = resourceexample.desktop
+\endcode
+
+*/
+
+/**
+ This class provides a resource which is managed in a general way.
+
+ A Resource represents the concept of an object with the following attributes:
+
+ - Applications operate on sets of one or more Resource objects.
+ - Creation and deletetion of Resource objects is done in a general way,
+ independent of concrete functionality of the Resource.
+ - The end user has control over creation, deletion and configuration of
+ Resource object.
+ - Properties, behaviour and configuration of different Resource objects can
+ widely differ.
+ - Resources can be active or inactive.
+ - There is one special Resource which is the standard Resource. This can for
+ example be used as default destination for newly created object managed
+ by a certain Resource family.
+ - Activation of Resources can be covered by a two step process of being opened
+ and then loaded. Deactivation corresponds to saving and closing.
+ - Different application ususally share the same set of Resources.
+
+ The Resource base class provides the management functionality. Classes
+ inheriting from Resource automatically appear in the general kresources
+ kcontrol module.
+
+ Concrete functionality of Resources is specified per family by a subclass of
+ Resource. This classes in turn have subclasses which implement the different
+ flavours of the functionality represented by the family.
+
+ A subclass should reimplement at least the constructor and the
+ writeConfig method.
+
+ An example for a Resource subclass hierarchy would be the "calendar" family.
+ The ResourceCalendar subclass would specify an API for accessing calendar
+ data. Subclasses of ResourceCalendar would implement this API for local files,
+ remote files, specific calendar servers etc.
+*/
+class KRESOURCES_EXPORT Resource : public QObject
+{
+ friend class Factory;
+ friend class ManagerImpl;
+
+ Q_OBJECT
+ public:
+ typedef QValueList<Resource *> List;
+
+ /**
+ * Constructor. Construct resource from config.
+ * @param config Configuration to read persistence information from.
+ * If config is 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 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 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;
+
+ /**
+ 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 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 KRESOURCES_EXPORT PluginFactoryBase : public KLibFactory
+{
+ public:
+ virtual Resource *resource( const KConfig *config ) = 0;
+
+ virtual ConfigWidget *configWidget( QWidget *parent ) = 0;
+
+ protected:
+ virtual QObject* createObject( QObject *parent, const char *name, const char *className,
+ const QStringList & args)
+ {
+ Q_UNUSED(parent);
+ Q_UNUSED(name);
+ Q_UNUSED(className);
+ Q_UNUSED(args);
+ 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/kresources/selectdialog.cpp b/kresources/selectdialog.cpp
new file mode 100644
index 000000000..a36e7ec48
--- /dev/null
+++ b/kresources/selectdialog.cpp
@@ -0,0 +1,122 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include <kbuttonbox.h>
+#include <klistbox.h>
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include <qgroupbox.h>
+#include <qlayout.h>
+
+#include "resource.h"
+
+#include "selectdialog.h"
+
+using namespace KRES;
+
+SelectDialog::SelectDialog( QPtrList<Resource> list, QWidget *parent,
+ const char *name )
+ : KDialog( parent, name, true )
+{
+ setCaption( i18n( "Resource Selection" ) );
+ resize( 300, 200 );
+
+ QVBoxLayout *mainLayout = new QVBoxLayout( this );
+ mainLayout->setMargin( marginHint() );
+
+ QGroupBox *groupBox = new QGroupBox( 2, Qt::Horizontal, this );
+ groupBox->setTitle( i18n( "Resources" ) );
+
+ mResourceId = new KListBox( groupBox );
+
+ mainLayout->addWidget( groupBox );
+
+ mainLayout->addSpacing( 10 );
+
+ KButtonBox *buttonBox = new KButtonBox( this );
+
+ buttonBox->addStretch();
+ buttonBox->addButton( KStdGuiItem::ok(), this, SLOT( accept() ) );
+ buttonBox->addButton( KStdGuiItem::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()) );
+ connect( mResourceId, SIGNAL( executed( 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 );
+ if ( dlg.exec() == KDialog::Accepted ) return dlg.resource();
+ else return 0;
+}
diff --git a/kresources/selectdialog.h b/kresources/selectdialog.h
new file mode 100644
index 000000000..5ec90fc58
--- /dev/null
+++ b/kresources/selectdialog.h
@@ -0,0 +1,87 @@
+/*
+ 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., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef KRESOURCES_SELECTDIALOG_H
+#define KRESOURCES_SELECTDIALOG_H
+
+#include <qobject.h>
+#include <qptrlist.h>
+#include <qmap.h>
+
+#include <kdialog.h>
+
+class KListBox;
+
+namespace KRES {
+
+class Resource;
+
+/**
+ * Dialog for selecting a resource.
+ *
+ * Example:
+ *
+ * \code
+ *
+ * QPtrList<Resource> list = ... // can be retrived from KRES::Manager (e.g. KABC::AddressBook)
+ *
+ * KABC::Resource *res = KABC::SelectDialog::getResource( list, parentWdg );
+ * if ( !res ) {
+ * // no resource selected
+ * } else {
+ * // do something with resource
+ * }
+ * \endcode
+ */
+class KRESOURCES_EXPORT SelectDialog : KDialog
+{
+ public:
+ /**
+ * Constructor.
+ * @param list The list of available resources
+ * @param parent The parent widget
+ * @param name The name of the dialog
+ */
+ SelectDialog( QPtrList<Resource> list, QWidget *parent = 0,
+ const char *name = 0);
+
+ /**
+ * Returns selected resource.
+ */
+ Resource *resource();
+
+ /**
+ * Opens a dialog showing the available resources and returns the resource the
+ * user has selected. Returns 0, if the dialog was canceled.
+ */
+ static Resource *getResource( QPtrList<Resource> list, QWidget *parent = 0 );
+
+ private:
+ KListBox *mResourceId;
+
+ QMap<int, Resource*> mResourceMap;
+};
+
+}
+
+#endif
diff --git a/kresources/testresources.cpp b/kresources/testresources.cpp
new file mode 100644
index 000000000..257f58ca1
--- /dev/null
+++ b/kresources/testresources.cpp
@@ -0,0 +1,81 @@
+#include <kdebug.h>
+#include <kapplication.h>
+#include <kaboutdata.h>
+#include <kcmdlineargs.h>
+
+#include "resource.h"
+#include "manager.h"
+
+using namespace KRES;
+
+class TestResource : public Resource
+{
+ public:
+ TestResource() : Resource( 0 ) {}
+
+};
+
+class TestSubResource : public TestResource
+{
+ public:
+ TestSubResource() : TestResource() {}
+
+ void dump() const
+ {
+ kdDebug() << "TestSubResource" << endl;
+ TestResource::dump();
+ }
+};
+
+int main( int argc, char **argv )
+{
+ KAboutData aboutData( "testresources", "Kresource Test", "0" );
+ KCmdLineArgs::init( argc, argv, &aboutData );
+
+ KApplication app;
+
+ Manager<TestResource> manager( "test" );
+
+ TestResource *resource1 = new TestResource;
+ resource1->setResourceName( "One" );
+ manager.add( resource1 );
+
+ TestResource *resource2 = new TestSubResource;
+ resource2->setResourceName( "Two" );
+ manager.add( resource2 );
+
+ TestResource *resource3 = new TestSubResource;
+ resource3->setResourceName( "Three" );
+ manager.add( resource3 );
+
+ kdDebug() << "LIST ALL:" << endl;
+ Manager<TestResource>::Iterator it;
+ for( it = manager.begin(); it != manager.end(); ++it ) {
+ (*it)->dump();
+ }
+
+ resource2->setActive( false );
+ resource3->setActive( true );
+
+ kdDebug() << "LIST ACTIVE" << endl;
+ Manager<TestResource>::ActiveIterator it2;
+ for( it2 = manager.activeBegin(); it2 != manager.activeEnd(); ++it2 ) {
+ (*it2)->dump();
+ }
+
+ resource1->setActive( false );
+ resource2->setActive( true );
+ resource3->setActive( true );
+
+ kdDebug() << "LIST ACTIVE" << endl;
+ for( it2 = manager.activeBegin(); it2 != manager.activeEnd(); ++it2 ) {
+ (*it2)->dump();
+ }
+
+ kdDebug() << "LIST ALL" << endl;
+ for( it = manager.begin(); it != manager.end(); ++it ) {
+ (*it)->dump();
+ }
+
+
+}