24#ifndef TDERESOURCES_MANAGER_H
25#define TDERESOURCES_MANAGER_H
28#include <tqstringlist.h>
31#include <tderesources/factory.h>
32#include <tderesources/managerimpl.h>
50 virtual void resourceAdded( T *resource ) = 0;
51 virtual void resourceModified( T *resource ) = 0;
52 virtual void resourceDeleted( T *resource ) = 0;
61 virtual void notifyResourceAdded(
Resource *resource ) = 0;
62 virtual void notifyResourceModified(
Resource *resource ) = 0;
63 virtual void notifyResourceDeleted(
Resource *resource ) = 0;
90 Iterator(
const Iterator &it ) { mIt = it.mIt; }
92 T *operator*() {
return static_cast<T *
>( *mIt ); }
93 Iterator &operator++() { mIt++;
return *
this; }
94 Iterator &operator++(
int ) { mIt++;
return *
this; }
95 Iterator &operator--() { mIt--;
return *
this; }
96 Iterator &operator--(
int ) { mIt--;
return *
this; }
97 bool operator==(
const Iterator &it ) {
return mIt == it.mIt; }
98 bool operator!=(
const Iterator &it ) {
return mIt != it.mIt; }
101 Resource::List::Iterator mIt;
110 it.mIt = mImpl->resourceList()->begin();
120 it.mIt = mImpl->resourceList()->end();
129 friend class Manager;
131 ActiveIterator() : mList( 0 ) {};
132 ActiveIterator(
const ActiveIterator &it )
138 T *operator*() {
return static_cast<T *
>( *mIt ); }
139 ActiveIterator &operator++()
141 do { mIt++; }
while ( checkActive() );
144 ActiveIterator &operator++(
int )
146 do { mIt++; }
while ( checkActive() );
149 ActiveIterator &operator--()
151 do { mIt--; }
while ( checkActive() );
154 ActiveIterator &operator--(
int )
156 do { mIt--; }
while ( checkActive() );
159 bool operator==(
const ActiveIterator &it ) {
return mIt == it.mIt; }
160 bool operator!=(
const ActiveIterator &it ) {
return mIt != it.mIt; }
168 if ( !mList || mIt == mList->end() )
return false;
169 return !(*mIt)->isActive();
172 Resource::List::Iterator mIt;
173 Resource::List *mList;
183 it.mIt = mImpl->resourceList()->begin();
184 it.mList = mImpl->resourceList();
185 if ( it.mIt != mImpl->resourceList()->end() ) {
186 if ( !(*it)->isActive() ) it++;
197 it.mIt = mImpl->resourceList()->end();
198 it.mList = mImpl->resourceList();
206 bool isEmpty()
const {
return mImpl->resourceList()->isEmpty(); }
217 mImpl =
new ManagerImpl(
this, family );
218 mObservers.setAutoDelete(
false );
232 mImpl->readConfig( cfg );
241 mImpl->writeConfig( cfg );
250 if ( resource ) mImpl->add( resource );
258 if ( resource ) mImpl->remove( resource );
267 mImpl->change( resource );
275 return static_cast<T *
>( mImpl->standardResource() );
283 if ( resource ) mImpl->setStandardResource( resource );
291 if ( resource ) mImpl->setActive( resource, active );
300 return mImpl->resourceNames();
315 return dynamic_cast<T *
>( mFactory->resource( type, 0 ) );
323 return mFactory->typeNames();
331 TQStringList typeDescs;
332 TQStringList types = mFactory->typeNames();
334 for ( TQStringList::ConstIterator it = types.begin(); it != types.end();
336 TQString desc = mFactory->typeName( *it );
337 if ( !mFactory->typeDescription( *it ).isEmpty() )
338 desc += TQString::fromLatin1(
" (") + mFactory->typeDescription( *it ) + TQString::fromLatin1(
")");
340 typeDescs.append( desc );
352 mObservers.append( observer );
361 mObservers.remove( observer );
368 void notifyResourceAdded(
Resource *res )
370 kdDebug(5650) <<
"Manager::resourceAdded " << res->
resourceName() << endl;
371 T *resource =
dynamic_cast<T *
>( res );
374 for ( observer = mObservers.first(); observer;
375 observer = mObservers.next() )
376 observer->resourceAdded( resource );
383 void notifyResourceModified( Resource *res )
385 kdDebug(5650) <<
"Manager::resourceModified " << res->resourceName()
387 T *resource =
dynamic_cast<T *
>( res );
389 ManagerObserver<T> *observer;
390 for ( observer = mObservers.first(); observer;
391 observer = mObservers.next() )
392 observer->resourceModified( resource );
399 void notifyResourceDeleted( Resource *res )
401 kdDebug(5650) <<
"Manager::resourceDeleted " << res->resourceName()
403 T *resource =
dynamic_cast<T *
>( res );
405 ManagerObserver<T> *observer;
406 for ( observer = mObservers.first(); observer;
407 observer = mObservers.next() ) {
408 kdDebug(5650) <<
"Notifying a observer to Manager..." << endl;
409 observer->resourceDeleted( resource );
417 TQPtrList<ManagerObserver<T> > mObservers;
static Factory * self(const TQString &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.
void writeConfig(TDEConfig *cfg=0)
Write configuration of Resource objects to configuration file.
TQStringList resourceTypeDescriptions() const
Return list of descriptions of all available resource types.
void setActive(Resource *resource, bool active)
Set active state of resource.
TQStringList resourceNames() const
Returns a list of the names of the resources managed by the Manager for this family.
Iterator end()
Return Iterator indicating end of resource list.
void readConfig(TDEConfig *cfg=0)
Recreate Resource objects from configuration file.
T * standardResource()
Return standard resource.
void addObserver(ManagerObserver< T > *observer)
Add observer for resource changes to manager.
T * createResource(const TQString &type)
Creates a new resource of type type with default settings.
Iterator begin()
Return Iterator on first resource.
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.
TQStringList resourceTypeNames() const
Returns a list of the names of all available resource types.
void setStandardResource(T *resource)
Set standard resource.
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.
Manager(const TQString &family)
Create manager for given resource family.
void remove(Resource *resource)
Remove resource from manager.
This class provides a resource which is managed in a general way.
virtual TQString resourceName() const
Returns the name of resource.