summaryrefslogtreecommitdiffabout
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kresources/manager.h44
-rw-r--r--microkde/kresources/managerimpl.cpp70
-rw-r--r--microkde/kresources/syncwidget.cpp46
-rw-r--r--microkde/kresources/syncwidget.h62
4 files changed, 180 insertions, 42 deletions
diff --git a/microkde/kresources/manager.h b/microkde/kresources/manager.h
index b5e97fc..7e9e19a 100644
--- a/microkde/kresources/manager.h
+++ b/microkde/kresources/manager.h
@@ -1,35 +1,43 @@
/*
This file is part of libkresources.
Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
+ Copyright (c) 2004 Ulf Schenk
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
#ifndef KRESOURCES_MANAGER_H
#define KRESOURCES_MANAGER_H
#include <qdict.h>
#include <qstringlist.h>
#include "factory.h"
#include "managerimpl.h"
namespace KRES {
class Resource;
@@ -39,58 +47,58 @@ class ManagerListener
{
public:
virtual void resourceAdded( T *resource ) = 0;
virtual void resourceModified( T *resource ) = 0;
virtual void resourceDeleted( T *resource ) = 0;
};
// TODO:
// The resource manager should provide some signals
// to warn applications that resources have been added,
// removed or modified.
//
-// The manager should also keep track of which (or at least
+// The manager should also keep track of which (or at least
// how many) applications hve opened a resource, so that it
// is only closed if none of them is using it any more
template<class T>
class Manager : private ManagerImplListener
{
public:
class Iterator
{
friend class Manager;
public:
Iterator() {};
Iterator( const Iterator &it ) { mIt = it.mIt; }
T *operator*() { return static_cast<T *>( *mIt ); }
Iterator &operator++() { mIt++; return *this; }
Iterator &operator++(int) { mIt++; return *this; }
Iterator &operator--() { mIt--; return *this; }
Iterator &operator--(int) { mIt--; return *this; }
bool operator==( const Iterator &it ) { return mIt == it.mIt; }
bool operator!=( const Iterator &it ) { return mIt != it.mIt; }
- private:
+ private:
Resource::List::Iterator mIt;
};
Iterator begin()
{
Iterator it;
it.mIt = mImpl->resourceList()->begin();
return it;
}
-
+
Iterator end()
{
Iterator it;
it.mIt = mImpl->resourceList()->end();
return it;
}
class ActiveIterator
{
friend class Manager;
public:
ActiveIterator() : mList( 0 ) {};
@@ -150,37 +158,42 @@ class Manager : private ManagerImplListener
}
ActiveIterator activeEnd()
{
ActiveIterator it;
it.mIt = mImpl->resourceList()->end();
it.mList = mImpl->resourceList();
return it;
}
bool isEmpty() const { return mImpl->resourceList()->isEmpty(); }
- Manager( const QString &family )
+ /**
+ Return true, if the manager manages syncable resources.
+ */
+ bool manageSyncable() { return mImpl->manageSyncable(); }
+
+ Manager( const QString &family, bool syncable )
{
mFactory = Factory::self( family );
// The managerimpl will use the same Factory object as the manager
// because of the Factory::self() pattern
- mImpl = new ManagerImpl( family );
+ mImpl = new ManagerImpl( family, syncable );
mImpl->setListener( this );
-
+
mListeners = new QPtrList<ManagerListener<T> >;
}
virtual ~Manager()
- {
+ {
mImpl->setListener( 0 );
delete mListeners;
delete mImpl;
}
/**
Recreate Resource objects from configuration file. If cfg is 0, read standard
configuration file.
*/
void readConfig( KConfig *cfg = 0 )
{
mImpl->readConfig( cfg );
@@ -230,36 +243,37 @@ class Manager : private ManagerImplListener
*/
QStringList resourceNames() const
{
return mImpl->resourceNames();
}
ConfigWidget *configWidget( const QString& type, QWidget *parent = 0 )
{
return mFactory->resourceConfigWidget( type, parent );
}
/**
- Creates a new resource of type @param type, with default
- settings. The resource is
+ Creates a new resource of type @param type, with default
+ settings. The resource is
not added to the manager, the application has to do that.
Returns a pointer to a resource object or a null pointer
if resource type doesn't exist.
-
- @param type The type of the resource, one of those returned
+
+ @param type The type of the resource, one of those returned
by @ref resourceTypeNames()
+ * @param syncable If the resource should support syncing capabilities.
*/
T *createResource( const QString& type )
{
- return (T *)( mFactory->resource( type, 0 ) );
+ return (T *)( mFactory->resource( type, 0, mImpl->manageSyncable() ) );
}
/**
Returns a list of the names of all available resource types.
*/
QStringList resourceTypeNames() const
{
return mFactory->typeNames();
}
QStringList resourceTypeDescriptions() const
{
@@ -269,26 +283,26 @@ class Manager : private ManagerImplListener
for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) {
QString desc = mFactory->typeName( *it );
if ( !mFactory->typeDescription( *it ).isEmpty() )
desc += " (" + mFactory->typeDescription( *it ) + ")";
typeDescs.append( desc );
}
return typeDescs;
}
void resourceChanged( T *resource )
- {
- mImpl->resourceChanged( resource );
+ {
+ mImpl->resourceChanged( resource );
}
void addListener( ManagerListener<T> *listener )
{
mListeners->append( listener );
}
void removeListener( ManagerListener<T> *listener )
{
mListeners->remove( listener );
}
@@ -300,25 +314,25 @@ class Manager : private ManagerImplListener
for ( listener = mListeners->first(); listener; listener = mListeners->next() )
listener->resourceAdded( resource );
}
virtual void resourceModified( Resource *res )
{
kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl;
T* resource = (T *)( res );
ManagerListener<T> *listener;
for ( listener = mListeners->first(); listener; listener = mListeners->next() )
listener->resourceModified( resource );
}
-
+
virtual void resourceDeleted( Resource *res )
{
kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl;
T* resource = (T *)( res );
ManagerListener<T> *listener;
for ( listener = mListeners->first(); listener; listener = mListeners->next() ) {
kdDebug(5650) << "Notifying a listener to Manager..." << endl;
listener->resourceDeleted( resource );
}
}
private:
diff --git a/microkde/kresources/managerimpl.cpp b/microkde/kresources/managerimpl.cpp
index 785b6b4..3655f50 100644
--- a/microkde/kresources/managerimpl.cpp
+++ b/microkde/kresources/managerimpl.cpp
@@ -1,198 +1,205 @@
/*
This file is part of libkresources.
-
+
Copyright (c) 2002 Tobias Koenig <tokoe@kde.org>
Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/*
+Enhanced Version of the file for platform independent KDE tools.
+Copyright (c) 2004 Ulf Schenk
+
+$Id$
+*/
+
#include <kglobal.h>
#include <kapplication.h>
#include <kdebug.h>
#include <kconfig.h>
#include <kstandarddirs.h>
#include "resource.h"
#include "factory.h"
#include "managerimpl.h"
using namespace KRES;
-ManagerImpl::ManagerImpl( const QString &family )
- : mFamily( family ), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
+ManagerImpl::ManagerImpl( const QString &family, bool syncable )
+ : mFamily( family ), mSyncable(syncable), mConfig( 0 ), mStdConfig( 0 ), mStandard( 0 ),
mFactory( 0 )
{
kdDebug(5650) << "ManagerImpl::ManagerImpl()" << endl;
-
-
+
+
}
ManagerImpl::~ManagerImpl()
{
kdDebug(5650) << "ManagerImpl::~ManagerImpl()" << endl;
Resource::List::ConstIterator it;
for ( it = mResources.begin(); it != mResources.end(); ++it ) {
delete *it;
}
-
+
delete mStdConfig;
}
void ManagerImpl::createStandardConfig()
{
if ( !mStdConfig ) {
- QString file = locateLocal( "data", KGlobal::getAppName()
+ QString file = locateLocal( "data", KGlobal::getAppName()
+ "/kresources/" + mFamily + "rc" );
mStdConfig = new KConfig( file );
}
-
+
mConfig = mStdConfig;
}
void ManagerImpl::readConfig( KConfig *cfg )
{
kdDebug(5650) << "ManagerImpl::readConfig()" << endl;
delete mFactory;
mFactory = Factory::self( mFamily );
if ( !cfg ) {
createStandardConfig();
} else {
mConfig = cfg;
}
-
+
mStandard = 0;
mConfig->setGroup( "General" );
QStringList keys = mConfig->readListEntry( "ResourceKeys" );
keys += mConfig->readListEntry( "PassiveResourceKeys" );
QString standardKey = mConfig->readEntry( "Standard" );
for ( QStringList::Iterator it = keys.begin(); it != keys.end(); ++it ) {
readResourceConfig( *it, false );
}
-
+
}
void ManagerImpl::writeConfig( KConfig *cfg )
{
-//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
-
-
+//USqDebug("ManagerImpl::writeConfig begin this= %ul cfg=%ul", this, cfg);
+
+
kdDebug(5650) << "ManagerImpl::writeConfig()" << endl;
if ( !cfg ) {
createStandardConfig();
} else {
mConfig = cfg;
}
-
+
QStringList activeKeys;
QStringList passiveKeys;
// First write all keys, collect active and passive keys on the way
Resource::List::Iterator it;
for ( it = mResources.begin(); it != mResources.end(); ++it ) {
writeResourceConfig( *it, false );
QString key = (*it)->identifier();
if( (*it)->isActive() )
activeKeys.append( key );
else
passiveKeys.append( key );
}
// And then the general group
kdDebug(5650) << "Saving general info" << endl;
mConfig->setGroup( "General" );
mConfig->writeEntry( "ResourceKeys", activeKeys );
mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
- if ( mStandard )
+ if ( mStandard )
mConfig->writeEntry( "Standard", mStandard->identifier() );
else
mConfig->writeEntry( "Standard", "" );
mConfig->sync();
kdDebug(5650) << "ManagerImpl::save() finished" << endl;
-
-//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
-
+
+//US qDebug("ManagerImpl::writeConfig end this= %ul cfg=%ul", this, cfg);
+
}
void ManagerImpl::add( Resource *resource, bool useDCOP )
{
-qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
-
+qDebug("ManagerImpl::add begin this= %ul resource=%ul", this, resource);
+
resource->setActive( true );
if ( mResources.isEmpty() ) {
mStandard = resource;
}
mResources.append( resource );
writeResourceConfig( resource, true );
- qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
+ qDebug("ManagerImpl::add end this= %ul resource=%ul", this, resource);
}
void ManagerImpl::remove( Resource *resource, bool useDCOP )
{
if ( mStandard == resource ) mStandard = 0;
removeResource( resource );
mResources.remove( resource );
delete resource;
kdDebug(5650) << "Finished ManagerImpl::remove()" << endl;
}
void ManagerImpl::setActive( Resource *resource, bool active )
{
if ( resource && resource->isActive() != active ) {
resource->setActive( active );
}
}
-Resource *ManagerImpl::standardResource()
+Resource *ManagerImpl::standardResource()
{
return mStandard;
}
-void ManagerImpl::setStandardResource( Resource *resource )
+void ManagerImpl::setStandardResource( Resource *resource )
{
mStandard = resource;
}
void ManagerImpl::resourceChanged( Resource *resource )
{
writeResourceConfig( resource, true );
// ManagerIface_stub allManagers( "*", "ManagerIface_" + mFamily.utf8() );
// allManagers.dcopResourceModified( resource->identifier() );
}
@@ -240,37 +247,37 @@ QPtrList<Resource> ManagerImpl::resources( bool active )
return result;
}
void ManagerImpl::setListener( ManagerImplListener *listener )
{
mListener = listener;
}
Resource* ManagerImpl::readResourceConfig( const QString& identifier,
bool checkActive )
{
kdDebug() << "ManagerImpl::readResourceConfig() " << identifier << endl;
-
+
// qDebug("ManagerImpl::readResourceConfig() %s", identifier.latin1());
mConfig->setGroup( "Resource_" + identifier );
#ifdef _WIN32_
// we use plugins on win32. the group is stored in a static variable
// such that gourp info not avail on win32 plugins
// to fix that, it would be a looooot of work
mConfig->setTempGroup( "Resource_" + identifier );
#endif
QString type = mConfig->readEntry( "ResourceType" );
QString name = mConfig->readEntry( "ResourceName" );
- Resource *resource = mFactory->resource( type, mConfig );
+ Resource *resource = mFactory->resource( type, mConfig, mSyncable );
if ( !resource ) {
qDebug("Failed to create resource with id %s ",identifier.latin1() );
return 0;
}
if ( resource->identifier().isEmpty() )
resource->setIdentifier( identifier );
mConfig->setGroup( "General" );
QString standardKey = mConfig->readEntry( "Standard" );
if ( standardKey == identifier ) {
@@ -296,45 +303,45 @@ void ManagerImpl::writeResourceConfig( Resource *resource,
if ( !mConfig ) createStandardConfig();
mConfig->setGroup( "Resource_" + key );
resource->writeConfig( mConfig );
mConfig->setGroup( "General" );
QString standardKey = mConfig->readEntry( "Standard" );
if ( resource == mStandard && standardKey != key )
mConfig->writeEntry( "Standard", resource->identifier() );
else if ( resource != mStandard && standardKey == key )
mConfig->writeEntry( "Standard", "" );
-
+
if ( checkActive ) {
QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
if ( resource->isActive() && !activeKeys.contains( key ) ) {
activeKeys.append( resource->identifier() );
mConfig->writeEntry( "ResourceKeys", activeKeys );
} else if ( !resource->isActive() && activeKeys.contains( key ) ) {
activeKeys.remove( key );
mConfig->writeEntry( "ResourceKeys", activeKeys );
}
}
mConfig->sync();
}
void ManagerImpl::removeResource( Resource *resource )
{
QString key = resource->identifier();
if ( !mConfig ) createStandardConfig();
-
+
mConfig->setGroup( "General" );
QStringList activeKeys = mConfig->readListEntry( "ResourceKeys" );
if ( activeKeys.contains( key ) ) {
activeKeys.remove( key );
mConfig->writeEntry( "ResourceKeys", activeKeys );
} else {
QStringList passiveKeys = mConfig->readListEntry( "PassiveResourceKeys" );
passiveKeys.remove( key );
mConfig->writeEntry( "PassiveResourceKeys", passiveKeys );
}
QString standardKey = mConfig->readEntry( "Standard" );
@@ -347,12 +354,21 @@ void ManagerImpl::removeResource( Resource *resource )
mConfig->sync();
}
Resource* ManagerImpl::getResource( const QString& identifier )
{
Resource::List::ConstIterator it;
for ( it = mResources.begin(); it != mResources.end(); ++it ) {
if ( (*it)->identifier() == identifier )
return *it;
}
return 0;
}
+
+/**
+ Return true, if the manager manages syncable resources.
+*/
+bool ManagerImpl::manageSyncable() const
+{
+ return mSyncable;
+}
+
diff --git a/microkde/kresources/syncwidget.cpp b/microkde/kresources/syncwidget.cpp
new file mode 100644
index 0000000..9bb0df6
--- a/dev/null
+++ b/microkde/kresources/syncwidget.cpp
@@ -0,0 +1,46 @@
+/*
+ This file is part of libkresources.
+
+ Copyright (c) 2004 Ulf Schenk
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+// $Id$
+
+#include "syncwidget.h"
+
+using namespace KRES;
+
+
+SyncWidget::SyncWidget( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+}
+
+void SyncWidget::setInEditMode( bool )
+{
+}
+
+void SyncWidget::loadSettings( Resource * )
+{
+}
+
+void SyncWidget::saveSettings( Resource * )
+{
+}
+
+
diff --git a/microkde/kresources/syncwidget.h b/microkde/kresources/syncwidget.h
new file mode 100644
index 0000000..e94252c
--- a/dev/null
+++ b/microkde/kresources/syncwidget.h
@@ -0,0 +1,62 @@
+/*
+ This file is part of libkresources.
+ Copyright (c) 2004 Ulf Schenk
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+// $Id$
+
+#ifndef KRESOURCES_SYNCWIDGET_H
+#define KRESOURCES_SYNCWIDGET_H
+
+#include <qwidget.h>
+
+#include <kconfig.h>
+
+#include "resource.h"
+
+namespace KRES {
+
+class SyncWidget : public QWidget
+{
+ Q_OBJECT
+
+public:
+ SyncWidget( QWidget *parent = 0, const char *name = 0 );
+
+ /**
+ Sets the widget to 'edit' mode. Reimplement this method if you are
+ interested in the mode change (to disable some GUI element for
+ example). By default the widget is in 'create new' mode.
+ */
+ virtual void setInEditMode( bool value );
+
+public slots:
+ virtual void loadSettings( Resource *resource );
+ virtual void saveSettings( Resource *resource );
+
+signals:
+//US void setReadOnly( bool value );
+//US void setPersistentReadOnly( bool value );
+
+
+protected:
+//US Resource* mResource;
+};
+
+}
+#endif