24#ifndef KRESOURCES_MANAGER_H
25#define KRESOURCES_MANAGER_H
27#include "managerimpl.h"
32#include <QtCore/QList>
33#include <QtCore/QStringList>
52 virtual void resourceAdded( T *resource ) = 0;
53 virtual void resourceModified( T *resource ) = 0;
54 virtual void resourceDeleted( T *resource ) = 0;
64 virtual void notifyResourceAdded(
Resource *resource ) = 0;
65 virtual void notifyResourceModified(
Resource *resource ) = 0;
66 virtual void notifyResourceDeleted(
Resource *resource ) = 0;
93 Iterator(
const Iterator &it ) { mIt = it.mIt; }
95 T *operator*() {
return static_cast<T *
>( *mIt ); }
96 Iterator &operator++()
101 Iterator &operator++(
int )
106 Iterator &operator--()
111 Iterator &operator--(
int )
116 bool operator==(
const Iterator &it )
const
118 return mIt == it.mIt;
120 bool operator!=(
const Iterator &it )
const
122 return mIt != it.mIt;
126 Resource::List::Iterator mIt;
140 it.mIt = mImpl->resourceList()->begin();
150 it.mIt = mImpl->resourceList()->end();
159 friend class Manager;
161 ActiveIterator() : mList( 0 ) {}
162 ActiveIterator(
const ActiveIterator &it )
168 T *operator*() {
return static_cast<T *
>( *mIt ); }
169 ActiveIterator &operator++()
171 do { mIt++; }
while ( checkActive() );
174 ActiveIterator &operator++(
int )
176 do { mIt++; }
while ( checkActive() );
179 ActiveIterator &operator--()
181 do { mIt--; }
while ( checkActive() );
184 ActiveIterator &operator--(
int )
186 do { mIt--; }
while ( checkActive() );
189 bool operator==(
const ActiveIterator &it )
const {
return mIt == it.mIt; }
190 bool operator!=(
const ActiveIterator &it )
const {
return mIt != it.mIt; }
198 if ( !mList || mIt == mList->end() ) {
201 return !( *mIt )->isActive();
204 Resource::List::Iterator mIt;
205 Resource::List *mList;
215 it.mIt = mImpl->resourceList()->begin();
216 it.mList = mImpl->resourceList();
217 if ( it.mIt != mImpl->resourceList()->end() ) {
218 if ( !( *it )->isActive() ) {
231 it.mIt = mImpl->resourceList()->end();
232 it.mList = mImpl->resourceList();
240 bool isEmpty()
const {
return mImpl->resourceList()->isEmpty(); }
265 mImpl->readConfig( cfg );
274 mImpl->writeConfig( cfg );
284 mImpl->add( resource );
294 mImpl->remove( resource );
304 mImpl->change( resource );
312 return static_cast<T *
>( mImpl->standardResource() );
321 mImpl->setStandardResource( resource );
331 mImpl->setActive( resource, active );
341 return mImpl->resourceNames();
356 return dynamic_cast<T *
>( mFactory->resource( type ) );
364 return mFactory->typeNames();
372 QStringList typeDescs;
373 const QStringList types = mFactory->typeNames();
375 for ( QStringList::ConstIterator it = types.constBegin(); it != types.constEnd(); ++it ) {
376 QString desc = mFactory->typeName( *it );
377 if ( !mFactory->typeDescription( *it ).isEmpty() ) {
378 desc += QLatin1String(
" (" ) + mFactory->typeDescription( *it ) + QLatin1Char(
')' );
381 typeDescs.append( desc );
393 mObservers.append( observer );
402 mObservers.removeAll( observer );
409 void notifyResourceAdded(
Resource *res )
412 T *resource =
dynamic_cast<T *
>( res );
414 for (
int i = 0; i < mObservers.size(); ++i ) {
415 mObservers.at( i )->resourceAdded( resource );
423 void notifyResourceModified( Resource *res )
425 kDebug() << res->resourceName();
426 T *resource =
dynamic_cast<T *
>( res );
428 for (
int i = 0; i < mObservers.size(); ++i ) {
429 mObservers.at( i )->resourceAdded( resource );
437 void notifyResourceDeleted( Resource *res )
439 kDebug() << res->resourceName();
440 T *resource =
dynamic_cast<T *
>( res );
442 for (
int i = 0; i < mObservers.size(); ++i ) {
443 mObservers.at( i )->resourceDeleted( resource );
451 QList<ManagerObserver<T> *> mObservers;
static Factory * self(const QString &resourceFamily)
Returns the global resource factory.
Observer class for Manager class.
Iterator for iterations over only active resources managed by a manager.
Iterator for iterations over all resources managed by a manager.
This class provides a manager for resources of a specified family.
void removeObserver(ManagerObserver< T > *observer)
Remove Observer for resource changes from manager.
QStringList resourceNames() const
Returns a list of the names of the resources managed by the Manager for this family.
void setActive(Resource *resource, bool active)
Set active state of resource.
Iterator end()
Return Iterator indicating end of resource list.
void writeConfig(KConfig *cfg=0)
Write configuration of Resource objects to configuration file.
T * standardResource()
Return standard resource.
Manager(const QString &family)
Create manager for given resource family.
void addObserver(ManagerObserver< T > *observer)
Add observer for resource changes to manager.
QStringList resourceTypeDescriptions() const
Return list of descriptions of all available resource types.
Iterator begin()
Return Iterator on first resource.
void readConfig(KConfig *cfg=0)
Recreate Resource objects from configuration file.
bool isEmpty() const
Return true, if manager doesn't hold any resources.
ActiveIterator activeBegin()
Return Iterator on first active resource.
ActiveIterator activeEnd()
Return Iterator indicating end of active resource list.
void setStandardResource(T *resource)
Set standard resource.
T * createResource(const QString &type)
Creates a new resource of type type with default settings.
void change(T *resource)
Call this to notify manager about changes of the configuration of the given resource.
void add(Resource *resource)
Add resource to manager.
void remove(Resource *resource)
Remove resource from manager.
QStringList resourceTypeNames() const
Returns a list of the names of all available resource types.
This class provides a resource which is managed in a general way.
virtual QString resourceName() const
Returns the name of resource.
This file is part of the KDE resource framework and defines the Factory class.