diff options
author | Timothy Pearson <[email protected]> | 2013-01-26 13:17:21 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2013-01-26 13:17:21 -0600 |
commit | dfe289850f068f19ba4a83ab4e7e22a7e09c13c9 (patch) | |
tree | c297348a55df66c571de4525646e0b9762427353 /tderesources | |
parent | b7658a0d5eca24a9d37c6e04f88298ef02389db0 (diff) | |
download | tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.tar.gz tdelibs-dfe289850f068f19ba4a83ab4e7e22a7e09c13c9.zip |
Rename a number of libraries and executables to avoid conflicts with KDE4
Diffstat (limited to 'tderesources')
26 files changed, 3912 insertions, 0 deletions
diff --git a/tderesources/CMakeLists.txt b/tderesources/CMakeLists.txt new file mode 100644 index 000000000..05ea5a5af --- /dev/null +++ b/tderesources/CMakeLists.txt @@ -0,0 +1,78 @@ +################################################# +# +# (C) 2010 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${TQT_INCLUDE_DIRS} + ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_BINARY_DIR}/tdecore + ${CMAKE_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/dcop + ${CMAKE_SOURCE_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/tdeui + ${CMAKE_SOURCE_DIR}/kio + ${CMAKE_SOURCE_DIR}/kio/kio + ${CMAKE_SOURCE_DIR}/kio/kfile +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### headers ################################### + +install( FILES + resource.h configwidget.h factory.h manageriface.h + managerimpl.h manager.h selectdialog.h configdialog.h + configpage.h + DESTINATION ${INCLUDE_INSTALL_DIR}/tderesources ) + + +##### other data ################################ + +install( FILES tderesources_plugin.desktop tderesources_manager.desktop DESTINATION ${SERVICETYPES_INSTALL_DIR} ) + +# FIXME what is xdg_apps_DATA = tderesources.desktop +install( FILES tderesources.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} ) + + +##### tderesources ################################ + +set( target tderesources ) + +set( ${target}_SRCS + resource.cpp factory.cpp managerimpl.cpp configwidget.cpp + configdialog.cpp selectdialog.cpp configpage.cpp + manageriface.skel manageriface.stub +) + +tde_add_library( ${target} SHARED AUTOMOC + SOURCES ${${target}_SRCS} + VERSION 1.2.0 + LINK kio-shared + DESTINATION ${LIB_INSTALL_DIR} + DEPENDENCIES dcopidl +) + + +##### kcm_tderesources ############################ + +set( target kcm_tderesources ) + +set( ${target}_SRCS + kcmtderesources.cpp +) + +tde_add_kpart( ${target} AUTOMOC + SOURCES ${${target}_SRCS} + LINK tderesources-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tderesources/Makefile.am b/tderesources/Makefile.am new file mode 100644 index 000000000..fb7040ef5 --- /dev/null +++ b/tderesources/Makefile.am @@ -0,0 +1,49 @@ +INCLUDES = $(all_includes) + +METASOURCES = AUTO + +lib_LTLIBRARIES = libtderesources.la + +libtderesources_la_SOURCES = resource.cpp \ + factory.cpp \ + manageriface.skel \ + manageriface.stub \ + managerimpl.cpp \ + configwidget.cpp \ + configdialog.cpp \ + selectdialog.cpp \ + configpage.cpp + +libtderesources_la_LDFLAGS = $(all_libraries) -no-undefined -version-info 3:0:2 +libtderesources_la_LIBADD = $(LIB_TDEUI) $(LIB_KIO) $(LIB_QT) $(top_builddir)/dcop/libDCOP.la $(LIB_TDECORE) + +kresincludedir = $(includedir)/tderesources +kresinclude_HEADERS = resource.h \ + configwidget.h \ + factory.h \ + manageriface.h \ + managerimpl.h \ + manager.h \ + selectdialog.h \ + configdialog.h \ + configpage.h + +kde_module_LTLIBRARIES = kcm_tderesources.la + +kcm_tderesources_la_SOURCES = kcmtderesources.cpp +kcm_tderesources_la_LDFLAGS = $(all_libraries) -module -avoid-version -no-undefined +kcm_tderesources_la_LIBADD = libtderesources.la $(LIB_QT) $(LIB_TDEUI) $(LIB_TDECORE) + + +check_PROGRAMS = testresources + +testresources_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor +testresources_LDADD = libtderesources.la +testresources_SOURCES = testresources.cpp + +xdg_apps_DATA = tderesources.desktop + +servicetypedir = $(kde_servicetypesdir) +servicetype_DATA = tderesources_plugin.desktop tderesources_manager.desktop + +include ../admin/Doxyfile.am diff --git a/tderesources/README.design b/tderesources/README.design new file mode 100644 index 000000000..fc31a2078 --- /dev/null +++ b/tderesources/README.design @@ -0,0 +1,173 @@ +tderesources +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 tdelibs/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 TDEConfig, +in $HOME/.trinity/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 tdepim/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 +tdepim/tderesources/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/tderesources/TODO b/tderesources/TODO new file mode 100644 index 000000000..5034327a7 --- /dev/null +++ b/tderesources/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/tderesources/configdialog.cpp b/tderesources/configdialog.cpp new file mode 100644 index 000000000..b6d29dcd3 --- /dev/null +++ b/tderesources/configdialog.cpp @@ -0,0 +1,123 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqgroupbox.h> +#include <tqlabel.h> +#include <tqlayout.h> +#include <tqcheckbox.h> + +#include "factory.h" +#include "configdialog.h" + +using namespace KRES; + +ConfigDialog::ConfigDialog( TQWidget *parent, const TQString& resourceFamily, + /*const TQString& type,*/ Resource* resource, /*TDEConfig *config, */const char *name ) + : KDialogBase( parent, name, true, i18n( "Resource Configuration" ), + Ok|Cancel, Ok, false )/*, mConfig( config )*/, mResource( resource ) +{ + Factory *factory = Factory::self( resourceFamily ); + + TQFrame *main = makeMainWidget(); + + TQVBoxLayout *mainLayout = new TQVBoxLayout( main, 0, spacingHint() ); + + TQGroupBox *generalGroupBox = new TQGroupBox( 2, Qt::Horizontal, main ); + generalGroupBox->layout()->setSpacing( spacingHint() ); + generalGroupBox->setTitle( i18n( "General Settings" ) ); + + new TQLabel( i18n( "Name:" ), generalGroupBox ); + + mName = new KLineEdit( generalGroupBox ); + + mReadOnly = new TQCheckBox( i18n( "Read-only" ), generalGroupBox ); + + mName->setText( mResource->resourceName() ); + mReadOnly->setChecked( mResource->readOnly() ); + + mainLayout->addWidget( generalGroupBox ); + + TQGroupBox *resourceGroupBox = new TQGroupBox( 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, TQT_SIGNAL( setReadOnly( bool ) ), + TQT_SLOT( setReadOnly( bool ) ) ); + } + + connect( mName, TQT_SIGNAL( textChanged(const TQString &)), + TQT_SLOT( slotNameChanged(const TQString &))); + + slotNameChanged( mName->text() ); + setMinimumSize( sizeHint() ); +} + +void ConfigDialog::setInEditMode( bool value ) +{ + if ( mConfigWidget ) + mConfigWidget->setInEditMode( value ); +} + +void ConfigDialog::slotNameChanged( const TQString &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/tderesources/configdialog.h b/tderesources/configdialog.h new file mode 100644 index 000000000..c29d89273 --- /dev/null +++ b/tderesources/configdialog.h @@ -0,0 +1,60 @@ +/* + This file is part of libtderesources. + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 TQCheckBox; +class KButtonBox; + +namespace KRES { + class Resource; + class ConfigWidget; + +class KRESOURCES_EXPORT ConfigDialog : public KDialogBase +{ + Q_OBJECT + public: + // Resource=0: create new resource + ConfigDialog( TQWidget *parent, const TQString& resourceFamily, + Resource* resource, const char *name = 0); + + void setInEditMode( bool value ); + + protected slots: + void accept(); + void setReadOnly( bool value ); + void slotNameChanged( const TQString &text); + + private: + ConfigWidget *mConfigWidget; + Resource* mResource; + + KLineEdit *mName; + TQCheckBox *mReadOnly; +}; + +} + +#endif diff --git a/tderesources/configpage.cpp b/tderesources/configpage.cpp new file mode 100644 index 000000000..5b574c593 --- /dev/null +++ b/tderesources/configpage.cpp @@ -0,0 +1,535 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqgroupbox.h> +#include <tqlabel.h> +#include <tqlayout.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 TQCheckListItem +{ + public: + ConfigViewItem( TQListView *parent, Resource* resource ) : + TQCheckListItem( parent, resource->resourceName(), CheckBox ), + mResource( resource ), + mIsStandard( false ) + { + setText( 1, mResource->type() ); + setOn( mResource->isActive() ); + } + + void setStandard( bool value ) + { + setText( 2, ( value ? i18n( "Yes" ) : TQString::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" ) : TQString::null ); + } + + private: + Resource* mResource; + + bool mIsStandard; +}; + +ConfigPage::ConfigPage( TQWidget *parent, const char *name ) + : TQWidget( parent, name ), + mCurrentManager( 0 ), + mCurrentConfig( 0 ) +{ + setCaption( i18n( "Resource Configuration" ) ); + + TQVBoxLayout *mainLayout = new TQVBoxLayout( this ); + + TQGroupBox *groupBox = new TQGroupBox( i18n( "Resources" ), this ); + groupBox->setColumnLayout(0, Qt::Vertical ); + groupBox->layout()->setSpacing( 6 ); + groupBox->layout()->setMargin( 11 ); + TQGridLayout *groupBoxLayout = new TQGridLayout( 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, TQT_SIGNAL( doubleClicked( TQListViewItem *, const TQPoint &, int ) ), this, TQT_SLOT( slotEdit() ) ); + KButtonBox *buttonBox = new KButtonBox( groupBox, Qt::Vertical ); + mAddButton = buttonBox->addButton( i18n( "&Add..." ), TQT_TQOBJECT(this), TQT_SLOT(slotAdd()) ); + mRemoveButton = buttonBox->addButton( i18n( "&Remove" ), TQT_TQOBJECT(this), TQT_SLOT(slotRemove()) ); + mRemoveButton->setEnabled( false ); + mEditButton = buttonBox->addButton( i18n( "&Edit..." ), TQT_TQOBJECT(this), TQT_SLOT(slotEdit()) ); + mEditButton->setEnabled( false ); + mStandardButton = buttonBox->addButton( i18n( "&Use as Standard" ), TQT_TQOBJECT(this), TQT_SLOT(slotStandard()) ); + mStandardButton->setEnabled( false ); + buttonBox->layout(); + + groupBoxLayout->addWidget( buttonBox, 1, 1 ); + + mainLayout->addWidget( groupBox ); + + connect( mFamilyCombo, TQT_SIGNAL( activated( int ) ), + TQT_SLOT( slotFamilyChanged( int ) ) ); + connect( mListView, TQT_SIGNAL( selectionChanged() ), + TQT_SLOT( slotSelectionChanged() ) ); + connect( mListView, TQT_SIGNAL( clicked( TQListViewItem * ) ), + TQT_SLOT( slotItemClicked( TQListViewItem * ) ) ); + + mLastItem = 0; + + mConfig = new TDEConfig( "kcmtderesourcesrc" ); + mConfig->setGroup( "General" ); + + load(); +} + +ConfigPage::~ConfigPage() +{ + TQValueList<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(); + TQStringList familyDisplayNames; + + // KDE-3.3 compatibility code: get families from the plugins + TQStringList 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 TQString family = (*it)->property( "X-TDE-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 ) { + TQString displayName = (*m_it)->property( "Name" ).toString(); + familyDisplayNames.append( displayName ); + TQString family = (*m_it)->property( "X-TDE-ResourceFamily" ).toString(); + if ( !family.isEmpty() ) { + compatFamilyNames.remove( family ); + mFamilyMap.append( family ); + loadManager( family ); + } + } + + // Rest of the kde-3.3 compat code + TQStringList::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 TQString& family ) +{ + mCurrentManager = new Manager<Resource>( family ); + if ( mCurrentManager ) { + mCurrentManager->addObserver( this ); + + ResourcePageInfo *info = new ResourcePageInfo; + info->mManager = mCurrentManager; + info->mConfig = new TDEConfig( KRES::ManagerImpl::defaultConfigFile( family ) ); + info->mManager->readConfig( info->mConfig ); + + mInfoMap.append( KSharedPtr<ResourcePageInfo>(info) ); + } +} + +void ConfigPage::save() +{ + saveResourceSettings(); + + TQValueList<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; + + TQStringList types = mCurrentManager->resourceTypeNames(); + TQStringList descs = mCurrentManager->resourceTypeDescriptions(); + bool ok = false; + TQString desc = KInputDialog::getItem( i18n( "Resource Configuration" ), + i18n( "Please select type of the new resource:" ), descs, + 0, false, &ok, this ); + if ( !ok ) + return; + + TQString 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; + TQListViewItem *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; + + TQListViewItem *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; + + TQListViewItem *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; + } + + TQListViewItem *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 ) +{ + TQListViewItem *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( TQListViewItem *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 ) { + TQListViewItem *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/tderesources/configpage.h b/tderesources/configpage.h new file mode 100644 index 000000000..c7cc1156d --- /dev/null +++ b/tderesources/configpage.h @@ -0,0 +1,110 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqstringlist.h> +#include <tqwidget.h> + +#include "manager.h" + +class KComboBox; +class KListView; + +class TQListViewItem; +class TQPushButton; + +namespace KRES { + +class KRESOURCES_EXPORT ResourcePageInfo : public KShared +{ + public: + ResourcePageInfo(); + ~ResourcePageInfo(); + Manager<Resource> *mManager; + TDEConfig *mConfig; +}; + +class Resource; +class ConfigViewItem; + +class KRESOURCES_EXPORT ConfigPage : public TQWidget, public ManagerObserver<Resource> +{ + Q_OBJECT + + public: + ConfigPage( TQWidget *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( TQListViewItem * ); + + signals: + void changed( bool ); + + private: + void loadManager( const TQString& family ); + void saveResourceSettings(); + + Manager<Resource>* mCurrentManager; + TDEConfig* mCurrentConfig; + TDEConfig* mConfig; + TQString mFamily; + TQStringList mFamilyMap; + TQValueList<KSharedPtr<ResourcePageInfo> > mInfoMap; + + KComboBox* mFamilyCombo; + KListView* mListView; + TQPushButton* mAddButton; + TQPushButton* mRemoveButton; + TQPushButton* mEditButton; + TQPushButton* mStandardButton; + + TQListViewItem* mLastItem; +}; + +} + +#endif diff --git a/tderesources/configwidget.cpp b/tderesources/configwidget.cpp new file mode 100644 index 000000000..7f203842c --- /dev/null +++ b/tderesources/configwidget.cpp @@ -0,0 +1,37 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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( TQWidget *parent, const char *name ) + : TQWidget( parent, name ) +{ +} + +void ConfigWidget::setInEditMode( bool ) +{ +} + +#include "configwidget.moc" diff --git a/tderesources/configwidget.h b/tderesources/configwidget.h new file mode 100644 index 000000000..30ebf2a5a --- /dev/null +++ b/tderesources/configwidget.h @@ -0,0 +1,58 @@ +/* + This file is part of libtderesources. + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqwidget.h> + +namespace KRES { + +class KRESOURCES_EXPORT ConfigWidget : public TQWidget +{ + Q_OBJECT + public: + ConfigWidget( TQWidget *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/tderesources/factory.cpp b/tderesources/factory.cpp new file mode 100644 index 000000000..ea19e3b8a --- /dev/null +++ b/tderesources/factory.cpp @@ -0,0 +1,162 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqfile.h> + +#include "resource.h" +#include "factory.h" + +using namespace KRES; + +TQDict<Factory> *Factory::mSelves = 0; +static KStaticDeleter< TQDict<Factory> > staticDeleter; + +Factory *Factory::self( const TQString& resourceFamily ) +{ + kdDebug(5650) << "Factory::self()" << endl; + + Factory *factory = 0; + if ( !mSelves ) + staticDeleter.setObject( mSelves, new TQDict<Factory> ); + + factory = mSelves->find( resourceFamily ); + + if ( !factory ) { + factory = new Factory( resourceFamily ); + mSelves->insert( resourceFamily, factory ); + } + + return factory; +} + +Factory::Factory( const TQString& resourceFamily ) : + mResourceFamily( resourceFamily ) +{ + KTrader::OfferList plugins = KTrader::self()->query( "KResources/Plugin", TQString( "[X-TDE-ResourceFamily] == '%1'" ) + .arg( resourceFamily ) ); + KTrader::OfferList::ConstIterator it; + for ( it = plugins.begin(); it != plugins.end(); ++it ) { + TQVariant type = (*it)->property( "X-TDE-ResourceType" ); + if ( !type.toString().isEmpty() ) + mTypeMap.insert( type.toString(), *it ); + } +} + +Factory::~Factory() +{ +} + +TQStringList Factory::typeNames() const +{ + return mTypeMap.keys(); +} + +ConfigWidget *Factory::configWidget( const TQString& type, TQWidget *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; +} + +TQString Factory::typeName( const TQString &type ) const +{ + if ( type.isEmpty() || !mTypeMap.contains( type ) ) + return TQString(); + + KService::Ptr ptr = mTypeMap[ type ]; + return ptr->name(); +} + +TQString Factory::typeDescription( const TQString &type ) const +{ + if ( type.isEmpty() || !mTypeMap.contains( type ) ) + return TQString(); + + KService::Ptr ptr = mTypeMap[ type ]; + return ptr->comment(); +} + +Resource *Factory::resource( const TQString& type, const TDEConfig *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/tderesources/factory.h b/tderesources/factory.h new file mode 100644 index 000000000..e4b9f0af1 --- /dev/null +++ b/tderesources/factory.h @@ -0,0 +1,118 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqdict.h> +#include <tqstring.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. + * TDEConfig 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 TQString& 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 TQString& type, TQWidget *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 TQString& type, const TDEConfig *config ); + + /** + * Returns a list of all available resource types. + */ + TQStringList typeNames() const; + + /** + * Returns the name for a special type. + */ + TQString typeName( const TQString &type ) const; + + /** + * Returns the description for a special type. + */ + TQString typeDescription( const TQString &type ) const; + + protected: + Factory( const TQString& resourceFamily ); + + private: + static TQDict<Factory> *mSelves; + + TQString mResourceFamily; + TQMap<TQString, KService::Ptr> mTypeMap; +}; + +} +#endif diff --git a/tderesources/kcmtderesources.cpp b/tderesources/kcmtderesources.cpp new file mode 100644 index 000000000..6afc1c1f6 --- /dev/null +++ b/tderesources/kcmtderesources.cpp @@ -0,0 +1,68 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2003 Tobias Koenig <[email protected]> + + 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 <tqlayout.h> + +#include <kaboutdata.h> +#include <kgenericfactory.h> +#include <klocale.h> + +#include "configpage.h" + +#include "kcmtderesources.h" + +typedef KGenericFactory<KCMKResources, TQWidget> ResourcesFactory; +K_EXPORT_COMPONENT_FACTORY( kcm_tderesources, ResourcesFactory( "kcmtderesources" ) ) + +KCMKResources::KCMKResources( TQWidget *parent, const char *name, const TQStringList& ) + : TDECModule( ResourcesFactory::instance(), parent, name ) +{ + TQVBoxLayout *layout = new TQVBoxLayout( this ); + mConfigPage = new KRES::ConfigPage( this ); + layout->addWidget( mConfigPage ); + connect( mConfigPage, TQT_SIGNAL( changed( bool ) ), TQT_SIGNAL( changed( bool ) ) ); + setButtons( Help | Apply ); + TDEAboutData *about = + new TDEAboutData( I18N_NOOP( "kcmtderesources" ), + I18N_NOOP( "TDE Resources configuration module" ), + 0, 0, TDEAboutData::License_GPL, + I18N_NOOP( "(c) 2003 Tobias Koenig" ) ); + + about->addAuthor( "Tobias Koenig", 0, "[email protected]" ); + setAboutData(about); +} + +void KCMKResources::load() +{ + mConfigPage->load(); +} + +void KCMKResources::save() +{ + mConfigPage->save(); +} + +void KCMKResources::defaults() +{ + mConfigPage->defaults(); +} + +#include "kcmtderesources.moc" diff --git a/tderesources/kcmtderesources.h b/tderesources/kcmtderesources.h new file mode 100644 index 000000000..21176dff8 --- /dev/null +++ b/tderesources/kcmtderesources.h @@ -0,0 +1,42 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2003 Tobias Koenig <[email protected]> + + 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 <tdecmodule.h> + +class KRESOURCES_EXPORT KCMKResources : public TDECModule +{ + Q_OBJECT + + public: + KCMKResources( TQWidget *parent, const char *name, const TQStringList& ); + + void load(); + void save(); + void defaults(); + + private: + KRES::ConfigPage *mConfigPage; +}; + +#endif diff --git a/tderesources/manager.h b/tderesources/manager.h new file mode 100644 index 000000000..8fd35632b --- /dev/null +++ b/tderesources/manager.h @@ -0,0 +1,422 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqdict.h> +#include <tqstringlist.h> + +#include <kdebug.h> +#include <tderesources/factory.h> +#include <tderesources/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 TQString &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( TDEConfig *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( TDEConfig *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. + */ + TQStringList 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 TQString& type ) + { + return dynamic_cast<T *>( mFactory->resource( type, 0 ) ); + } + + /** + Returns a list of the names of all available resource types. + */ + TQStringList resourceTypeNames() const + { + return mFactory->typeNames(); + } + + /** + Return list of descriptions of all available resource types. + */ + TQStringList resourceTypeDescriptions() const + { + TQStringList typeDescs; + TQStringList types = mFactory->typeNames(); + + for ( TQStringList::ConstIterator it = types.begin(); it != types.end(); + ++it ) { + TQString desc = mFactory->typeName( *it ); + if ( !mFactory->typeDescription( *it ).isEmpty() ) + desc += TQString::fromLatin1(" (") + mFactory->typeDescription( *it ) + TQString::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; + TQPtrList<ManagerObserver<T> > mObservers; +}; + +} + +#endif diff --git a/tderesources/manageriface.h b/tderesources/manageriface.h new file mode 100644 index 000000000..63cab83f9 --- /dev/null +++ b/tderesources/manageriface.h @@ -0,0 +1,46 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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( TQString managerId, TQString resourceId ); + void signalKResourceModified( TQString managerId, TQString resourceId ); + void signalKResourceDeleted( TQString managerId, TQString resourceId ); + + k_dcop: + virtual ASYNC dcopKResourceAdded( TQString managerId, TQString resourceId ) = 0; + virtual ASYNC dcopKResourceModified( TQString managerId, TQString resourceId ) = 0; + virtual ASYNC dcopKResourceDeleted( TQString managerId, TQString resourceId ) = 0; +}; + +} + +#endif diff --git a/tderesources/managerimpl.cpp b/tderesources/managerimpl.cpp new file mode 100644 index 000000000..43c39964e --- /dev/null +++ b/tderesources/managerimpl.cpp @@ -0,0 +1,448 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 TQString &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 = TDEApplication::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( TQString, TQString )", + "dcopKResourceAdded( TQString, TQString )", false ) ) + kdWarning(5650) << "Could not connect ResourceAdded signal!" << endl; + + if ( !connectDCOPSignal( 0, "ManagerIface_" + family.utf8(), + "signalKResourceModified( TQString, TQString )", + "dcopKResourceModified( TQString, TQString )", false ) ) + kdWarning(5650) << "Could not connect ResourceModified signal!" << endl; + + if ( !connectDCOPSignal( 0, "ManagerIface_" + family.utf8(), + "signalKResourceDeleted( TQString, TQString )", + "dcopKResourceDeleted( TQString, TQString )", 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 ) { + TQString file = defaultConfigFile( mFamily ); + mStdConfig = new TDEConfig( file ); + } + + mConfig = mStdConfig; +} + +void ManagerImpl::readConfig( TDEConfig *cfg ) +{ + kdDebug(5650) << "ManagerImpl::readConfig()" << endl; + + delete mFactory; + mFactory = Factory::self( mFamily ); + + if ( !cfg ) { + createStandardConfig(); + } else { + mConfig = cfg; + } + + mStandard = 0; + + mConfig->setGroup( "General" ); + + TQStringList keys = mConfig->readListEntry( "ResourceKeys" ); + keys += mConfig->readListEntry( "PassiveResourceKeys" ); + + TQString standardKey = mConfig->readEntry( "Standard" ); + + for ( TQStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) { + readResourceConfig( *it, false ); + } + + mConfigRead = true; +} + +void ManagerImpl::writeConfig( TDEConfig *cfg ) +{ + kdDebug(5650) << "ManagerImpl::writeConfig()" << endl; + + if ( !cfg ) { + createStandardConfig(); + } else { + mConfig = cfg; + } + + TQStringList activeKeys; + TQStringList 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 ); + + TQString 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( TQString managerId, TQString 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( TQString managerId, TQString 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( TQString managerId, TQString 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; +} + +TQStringList ManagerImpl::resourceNames() +{ + TQStringList 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; +} + +TQPtrList<Resource> ManagerImpl::resources() +{ + TQPtrList<Resource> result; + + Resource::List::ConstIterator it; + for ( it = mResources.begin(); it != mResources.end(); ++it ) { + result.append( *it ); + } + return result; +} + +TQPtrList<Resource> ManagerImpl::resources( bool active ) +{ + TQPtrList<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 TQString &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 ); + + TQString type = mConfig->readEntry( "ResourceType" ); + TQString 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" ); + + TQString standardKey = mConfig->readEntry( "Standard" ); + if ( standardKey == identifier ) { + mStandard = resource; + } + + if ( checkActive ) { + TQStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); + resource->setActive( activeKeys.contains( identifier ) ); + } + mResources.append( resource ); + + return resource; +} + +void ManagerImpl::writeResourceConfig( Resource *resource, bool checkActive ) +{ + TQString key = resource->identifier(); + + kdDebug(5650) << "Saving resource " << key << endl; + + if ( !mConfig ) createStandardConfig(); + + mConfig->setGroup( "Resource_" + key ); + resource->writeConfig( mConfig ); + + mConfig->setGroup( "General" ); + TQString 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 ) { + TQStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); + TQStringList 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 ) +{ + TQString key = resource->identifier(); + + if ( !mConfig ) createStandardConfig(); + + mConfig->setGroup( "General" ); + TQStringList activeKeys = mConfig->readListEntry( "ResourceKeys" ); + if ( activeKeys.contains( key ) ) { + activeKeys.remove( key ); + mConfig->writeEntry( "ResourceKeys", activeKeys ); + } else { + TQStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" ); + passiveKeys.remove( key ); + mConfig->writeEntry( "PassiveResourceKeys", passiveKeys ); + } + + TQString standardKey = mConfig->readEntry( "Standard" ); + if ( standardKey == key ) { + mConfig->writeEntry( "Standard", "" ); + } + + mConfig->deleteGroup( "Resource_" + resource->identifier() ); + mConfig->sync(); +} + +Resource *ManagerImpl::getResource( const TQString &identifier ) +{ + Resource::List::ConstIterator it; + for ( it = mResources.begin(); it != mResources.end(); ++it ) { + if ( (*it)->identifier() == identifier ) + return *it; + } + return 0; +} + +TQString ManagerImpl::defaultConfigFile( const TQString &family ) +{ + return TQString( "tderesources/%1/stdrc" ).arg( family ); +} diff --git a/tderesources/managerimpl.h b/tderesources/managerimpl.h new file mode 100644 index 000000000..137fd9528 --- /dev/null +++ b/tderesources/managerimpl.h @@ -0,0 +1,107 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqstring.h> +#include <tqptrlist.h> +#include <tqdict.h> + +#include "manageriface.h" +#include <tderesources/resource.h> + +class TDEConfig; + +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 TQString &family ); + ~ManagerImpl(); + + void readConfig( TDEConfig * ); + void writeConfig( TDEConfig * ); + + 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(); + + TQPtrList<Resource> resources(); + + // Get only active or passive resources + TQPtrList<Resource> resources( bool active ); + + TQStringList resourceNames(); + + static TQString defaultConfigFile( const TQString &family ); + + private: + // dcop calls + void dcopKResourceAdded( TQString managerId, TQString resourceId ); + void dcopKResourceModified( TQString managerId, TQString resourceId ); + void dcopKResourceDeleted( TQString managerId, TQString resourceId ); + + private: + void createStandardConfig(); + + Resource *readResourceConfig( const TQString& identifier, bool checkActive ); + void writeResourceConfig( Resource *resource, bool checkActive ); + + void removeResource( Resource *resource ); + Resource *getResource( Resource *resource ); + Resource *getResource( const TQString& identifier ); + + ManagerNotifier *mNotifier; + TQString mFamily; + TDEConfig *mConfig; + TDEConfig *mStdConfig; + Resource *mStandard; + Factory *mFactory; + Resource::List mResources; + TQString mId; + bool mConfigRead; + + class ManagerImplPrivate; + ManagerImplPrivate *d; +}; + +} + +#endif diff --git a/tderesources/resource.cpp b/tderesources/resource.cpp new file mode 100644 index 000000000..00cdb8768 --- /dev/null +++ b/tderesources/resource.cpp @@ -0,0 +1,185 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2001 Cornelius Schumacher <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 + TQMutex mMutex; +#endif + int mOpenCount; + TQString mType; + TQString mIdentifier; + bool mReadOnly; + TQString mName; + bool mActive; + bool mIsOpen; +}; + +Resource::Resource( const TDEConfig* config ) + : TQObject( 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 = TDEApplication::randomString( 10 ); + } +} + +Resource::~Resource() +{ + delete d; + d = 0; +} + +void Resource::writeConfig( TDEConfig* 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 + TQMutexLocker 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 + TQMutexLocker 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 TQString& identifier ) +{ + d->mIdentifier = identifier; +} + +TQString Resource::identifier() const +{ + return d->mIdentifier; +} + +void Resource::setType( const TQString& type ) +{ + d->mType = type; +} + +TQString 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 TQString &name ) +{ + d->mName = name; +} + +TQString 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/tderesources/resource.h b/tderesources/resource.h new file mode 100644 index 000000000..65578bcd1 --- /dev/null +++ b/tderesources/resource.h @@ -0,0 +1,420 @@ +/* + This file is part of libtderesources + + Copyright (c) 2001-2003 Cornelius Schumacher <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + + 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 <tqmutex.h> +#include <tqvaluelist.h> +#include <tqwidget.h> + +#include <klibloader.h> + +class TDEConfig; + +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 <tderesources/resource.h> + +class ResourceExample : public KRES::Resource +{ + public: + ResourceExample( const TDEConfig * ); + ~ResourceExample(); + void writeConfig( TDEConfig *config ); + + private: + TQString mLocation; + TQString mPassword; +} +\endcode + + <B>resourceexample.cpp</B>: +\code +#include <kconfig.h> + +#include "resourceexample.h" + +ResourceExample::ResourceExample( const TDEConfig *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( TDEConfig *config ) +{ + KRES::Resource::writeConfig( config ); + config->writePathEntry( "Location", mLocation ); + config->writeEntry( "Password", KStringHandler::obscure( mPassword ) ); +} + +extern "C" +{ + KRES::ResourceExample *config_widget( TQWidget *parent ) { + return new ResourceExampleConfig( parent, "Configure Example Resource" ); + } + + KRES::Resource *resource( const TDEConfig *config ) { + return new ResourceExample( config ); + } +} +\endcode + + <B>resourceexampleconfig.h</B>: +\code +#include <klineedit.h> +#include <tderesources/resourceconfigwidget.h> + +#include "resourceexample.h" + +class ResourceExampleConfig : public KRES::ResourceConfigWidget +{ + Q_OBJECT + public: + ResourceExampleConfig( TQWidget *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 <tqlayout.h> +#include <tqlabel.h> +#include <tderesources/resourceconfigwidget.h> +#include "resourceexample.h" +#include "resourceexampleconfig.h" + +ResourceExampleConfig::ResourceExampleConfig( TQWidget *parent, const char *name ) + : KRES::ResourceConfigWidget( parent, name ) +{ + TQGridLayout *mainLayout = new TQGridLayout( this, 2, 2 ); + + TQLabel *label = new TQLabel( i18n( "Location:" ), this ); + mHostEdit = new KLineEdit( this ); + mainLayout->addWidget( label, 1, 0 ); + mainLayout->addWidget( mHostEdit, 1, 1 ); + + label = new TQLabel( i18n( "Password:" ), this ); + mPasswordEdit = new KLineEdit( this ); + mPasswordEdit->setEchoMode( TQLineEdit::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-TDE-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 = -ltderesources + +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 tderesources + 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 TQObject +{ + friend class Factory; + friend class ManagerImpl; + + Q_OBJECT + public: + typedef TQValueList<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 TDEConfig *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( TDEConfig *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 + */ + TQString identifier() const; + + /** + * Returns the type of this resource. + */ + TQString 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 TQString &name ); + + /** + * Returns the name of resource. + */ + virtual TQString 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 TQString &identifier ); + void setType( const TQString &type ); + + private: + class ResourcePrivate; + ResourcePrivate *d; +}; + +class KRESOURCES_EXPORT PluginFactoryBase : public KLibFactory +{ + public: + virtual Resource *resource( const TDEConfig *config ) = 0; + + virtual ConfigWidget *configWidget( TQWidget *parent ) = 0; + + protected: + virtual TQObject* createObject( TQObject *parent, const char *name, const char *className, + const TQStringList & 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 TDEConfig *config ) + { + return new TR( config ); + } + + ConfigWidget *configWidget( TQWidget *parent ) + { + return new TC( parent ); + } +}; + +} + +#endif diff --git a/tderesources/selectdialog.cpp b/tderesources/selectdialog.cpp new file mode 100644 index 000000000..e505140a6 --- /dev/null +++ b/tderesources/selectdialog.cpp @@ -0,0 +1,122 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqgroupbox.h> +#include <tqlayout.h> + +#include "resource.h" + +#include "selectdialog.h" + +using namespace KRES; + +SelectDialog::SelectDialog( TQPtrList<Resource> list, TQWidget *parent, + const char *name ) + : KDialog( parent, name, true ) +{ + setCaption( i18n( "Resource Selection" ) ); + resize( 300, 200 ); + + TQVBoxLayout *mainLayout = new TQVBoxLayout( this ); + mainLayout->setMargin( marginHint() ); + + TQGroupBox *groupBox = new TQGroupBox( 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(), TQT_TQOBJECT(this), TQT_SLOT( accept() ) ); + buttonBox->addButton( KStdGuiItem::cancel(), TQT_TQOBJECT(this), TQT_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, TQT_SIGNAL(returnPressed(TQListBoxItem*)), + TQT_SLOT(accept()) ); + connect( mResourceId, TQT_SIGNAL( executed( TQListBoxItem* ) ), + TQT_SLOT( accept() ) ); +} + +Resource *SelectDialog::resource() +{ + if ( mResourceId->currentItem() != -1 ) + return mResourceMap[ mResourceId->currentItem() ]; + else + return 0; +} + +Resource *SelectDialog::getResource( TQPtrList<Resource> list, TQWidget *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/tderesources/selectdialog.h b/tderesources/selectdialog.h new file mode 100644 index 000000000..878c32431 --- /dev/null +++ b/tderesources/selectdialog.h @@ -0,0 +1,87 @@ +/* + This file is part of libtderesources. + + Copyright (c) 2002 Tobias Koenig <[email protected]> + Copyright (c) 2002 Jan-Pascal van Best <[email protected]> + Copyright (c) 2003 Cornelius Schumacher <[email protected]> + + 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 <tqobject.h> +#include <tqptrlist.h> +#include <tqmap.h> + +#include <kdialog.h> + +class KListBox; + +namespace KRES { + +class Resource; + +/** + * Dialog for selecting a resource. + * + * Example: + * + * \code + * + * TQPtrList<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( TQPtrList<Resource> list, TQWidget *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( TQPtrList<Resource> list, TQWidget *parent = 0 ); + + private: + KListBox *mResourceId; + + TQMap<int, Resource*> mResourceMap; +}; + +} + +#endif diff --git a/tderesources/tderesources.desktop b/tderesources/tderesources.desktop new file mode 100644 index 000000000..0d907e0e0 --- /dev/null +++ b/tderesources/tderesources.desktop @@ -0,0 +1,210 @@ +[Desktop Entry] +Exec=kcmshell tderesources +Icon=about_kde +Type=Application +Terminal=false + +X-TDE-ModuleType=Library +X-TDE-Library=tderesources +X-TDE-FactoryName=tderesources +X-TDE-HasReadOnlyMode=false + +Name=TDE Resources +Name[af]=TDE Hulpbronne +Name[be]=Рэсурсы TDE +Name[bg]=Системни ресурси +Name[bn]=কে.ডি.ই রিসোর্সসমূহ +Name[br]=Danvezioù TDE +Name[bs]=TDE resursi +Name[ca]=Recursos TDE +Name[cs]=Zdroje TDE +Name[csb]=Dostónczi TDE +Name[da]=TDE Ressourcer +Name[de]=TDE-Ressourcen +Name[el]=Πόροι του TDE +Name[eo]=TDEa risurcoj +Name[es]=Recursos de TDE +Name[et]=TDE ressursid +Name[eu]=TDEren baliabideak +Name[fa]=منابع TDE +Name[fi]=TDE:n resurssiasetukset +Name[fr]=Ressources de TDE +Name[fy]=TDE Helpboarnen +Name[ga]=Acmhainní TDE +Name[gl]=Recursos de TDE +Name[he]=משאבים של TDE +Name[hr]=TDE resursi +Name[hu]=TDE-erőforrások +Name[id]=Sumber Daya TDE +Name[is]=TDE auðlindir +Name[it]=Risorse di TDE +Name[ja]=TDE リソース +Name[ka]=TDE რესურსები +Name[kk]=TDE ресурстары +Name[km]=ធនធាន TDE +Name[lb]=TDE-Ressourcen +Name[lt]=TDE resursai +Name[lv]=TDE resursi +Name[mk]=Ресурси на TDE +Name[ms]=Sumber TDE +Name[nb]=TDE-ressurser +Name[nds]=TDE-Ressourcen +Name[ne]=TDE संसाधन +Name[nl]=TDE-gegevensbronnen +Name[nn]=TDE-ressursar +Name[pa]=TDE ਸਰੋਤ +Name[pl]=Źródła danych TDE +Name[pt]=Recursos do TDE +Name[pt_BR]=Fontes de Dados do TDE +Name[ro]=Resurse TDE +Name[ru]=Ресурсы TDE +Name[rw]=Ibikorana TDE +Name[se]=TDE-resurssat +Name[sk]=Zdroje TDE +Name[sl]=Viri TDE +Name[sr]=TDE-ови ресурси +Name[sr@Latn]=TDE-ovi resursi +Name[sv]=TDE-resurser +Name[ta]=TDE மூலங்கள் +Name[te]=కెడిఈ వనరులు +Name[tg]=Манбаъи TDE +Name[th]=ทรัพยากร TDE +Name[tr]=TDE Kaynakları +Name[tt]=TDE Resursları +Name[uk]=Ресурси TDE +Name[uz]=TDE imkoniyatlari +Name[uz@cyrillic]=TDE имкониятлари +Name[vi]=Tài nguyên TDE +Name[zh_CN]=TDE 资源 +Name[zh_HK]=TDE 資源 +Name[zh_TW]=TDE 資源組態 + +Comment=Configure TDE Resources +Comment[af]=Stel TDE Hulpbronne op +Comment[be]=Настаўленне рэсурсаў TDE +Comment[bg]=Настройване на системните ресурси +Comment[bn]=কে.ডি.ই. রিসোর্সসমূহ কনফিগার করো +Comment[br]=Kefluniañ danvezioù TDE +Comment[bs]=Podesite TDE resurse +Comment[ca]=Configura els recursos TDE +Comment[cs]=Nastavení zdrojů TDE +Comment[csb]=Kònfigùracëjô dostónków TDE +Comment[da]=Indstil TDE's ressourcer +Comment[de]=TDE-Ressourcen einrichten +Comment[el]=Ρύθμιση πόρων του TDE +Comment[eo]=Agordu TDEajn risurcojn +Comment[es]=Configurar recursos de TDE +Comment[et]=TDE ressurside seadistamine +Comment[eu]=Konfiguratu TDEren baliabideak +Comment[fa]=پیکربندی منابع TDE +Comment[fi]=Muokkaa TDE:n resursseja +Comment[fr]=Configure les ressources de TDE +Comment[fy]=TDE helpboarne Ynstelle +Comment[ga]=Cumraigh Acmhainní TDE +Comment[gl]=Configurar os recursos de TDE +Comment[he]=תצורת משאבים של TDE +Comment[hi]=केडीई रीसोर्सेज़ कॉन्फ़िगर करें +Comment[hr]=Konfiguriranje TDE resursa +Comment[hu]=A TDE-s erőforrások beállítása +Comment[id]=Konfigurasikan Sumber Daya TDE +Comment[is]=Stilla TDE auðlindir +Comment[it]=Configura le risorse di TDE +Comment[ja]=TDE リソースの設定 +Comment[ka]=TDE რესურსების გამართვა +Comment[kk]=TDE ресурстарды баптау +Comment[km]=កំណត់រចនាសម្ព័ន្ធធនធាន TDE +Comment[lb]=TDE-Ressourcen astellen +Comment[lt]=Konfigūruoti TDE resursus +Comment[lv]=Konfigurē TDE resursus +Comment[mk]=Ги конфигурира TDE ресурсите +Comment[ms]=Selaraskan Sumber TDE +Comment[nb]=Sett opp TDE-ressurser +Comment[nds]=TDE-Ressourcen instellen +Comment[ne]=TDE संसाधन कन्फिगर गर्नुहोस् +Comment[nl]=TDE-gegevensbronnen instellen +Comment[nn]=Set opp TDE-ressursar +Comment[pa]=TDE ਸਰੋਤਾਂ ਦੀ ਸੰਰਚਨਾ +Comment[pl]=Konfiguracja źródeł danych TDE +Comment[pt]=Configurar Recursos do TDE +Comment[pt_BR]=Configura as Fontes de Dados do TDE +Comment[ro]=Configurează resursele TDE +Comment[ru]=Настройка ресурсов TDE +Comment[rw]=Kuboneza Ibikoraba bya TDE +Comment[se]=Heivet TDE-resurssaid +Comment[sk]=Nastavenie zdrojov TDE +Comment[sl]=Nastavi vire TDE +Comment[sr]=Подешавање TDE-ових ресурса +Comment[sr@Latn]=Podešavanje TDE-ovih resursa +Comment[sv]=Anpassa TDE-resurser +Comment[ta]=TDE மூலங்களை கட்டமை +Comment[te]=కెడిఈ వనరులను కూర్చుమూ +Comment[tg]=Танзими манбаъи истифодашуда тавассути китоби адрес +Comment[th]=ปรับแต่งทรัพยากรของ TDE +Comment[tr]=TDE Kaynaklarını Yapılandır +Comment[tt]=TDE Resursların Caylaw +Comment[uk]=Налаштування ресурсів TDE +Comment[uz]=TDE manbalarini moslash +Comment[uz@cyrillic]=TDE манбаларини мослаш +Comment[vi]=Cấu hình các tài nguyên TDE. +Comment[zh_CN]=配置 TDE 资源 +Comment[zh_HK]=設定 TDE 使用的資源 +Comment[zh_TW]=在此設定 TDE 的資源 + +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;TDE;X-TDE-settings-components; +OnlyShowIn=TDE; + diff --git a/tderesources/tderesources_manager.desktop b/tderesources/tderesources_manager.desktop new file mode 100644 index 000000000..35a0d1b5d --- /dev/null +++ b/tderesources/tderesources_manager.desktop @@ -0,0 +1,75 @@ +[Desktop Entry] +Type=ServiceType +X-TDE-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]=TDE 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]=TDE-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-TDE-ResourceFamily] +Type=TQString diff --git a/tderesources/tderesources_plugin.desktop b/tderesources/tderesources_plugin.desktop new file mode 100644 index 000000000..56cfe5bad --- /dev/null +++ b/tderesources/tderesources_plugin.desktop @@ -0,0 +1,79 @@ +[Desktop Entry] +Type=ServiceType +X-TDE-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ů TDE +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-TDE-ResourceFamily] +Type=TQString + +[PropertyDef::X-TDE-ResourceType] +Type=TQString diff --git a/tderesources/testresources.cpp b/tderesources/testresources.cpp new file mode 100644 index 000000000..515563172 --- /dev/null +++ b/tderesources/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 ) +{ + TDEAboutData aboutData( "testresources", "Kresource Test", "0" ); + TDECmdLineArgs::init( argc, argv, &aboutData ); + + TDEApplication 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(); + } + + +} |