24 #ifndef KRESOURCES_MANAGER_H 25 #define KRESOURCES_MANAGER_H 28 #include <tqstringlist.h> 31 #include <kresources/factory.h> 32 #include <kresources/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;
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();
138 T *operator*() {
return static_cast<T *
>( *mIt ); }
141 do { mIt++; }
while ( checkActive() );
146 do { mIt++; }
while ( checkActive() );
151 do { mIt--; }
while ( checkActive() );
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 );
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 );
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;
Manager(const TQString &family)
Create manager for given resource family.
TQStringList resourceTypeDescriptions() const
Return list of descriptions of all available resource types.
void setActive(Resource *resource, bool active)
Set active state of resource.
T * standardResource()
Return standard 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.
TQStringList resourceTypeNames() const
Returns a list of the names of all available resource types.
bool isEmpty() const
Return true, if manager doesn't hold any resources.
void removeObserver(ManagerObserver< T > *observer)
Remove Observer for resource changes from manager.
ActiveIterator activeEnd()
Return Iterator indicating end of active resource list.
virtual TQString resourceName() const
Returns the name of resource.
T * createResource(const TQString &type)
Creates a new resource of type type with default settings.
Iterator begin()
Return Iterator on first resource.
Observer class for Manager class.
void change(T *resource)
Call this to notify manager about changes of the configuration of the given resource.
void setStandardResource(T *resource)
Set standard resource.
Iterator for iterations over all resources managed by a manager.
void readConfig(KConfig *cfg=0)
Recreate Resource objects from configuration file.
Iterator for iterations over only active resources managed by a manager.
This class provides a resource which is managed in a general way.
void writeConfig(KConfig *cfg=0)
Write configuration of Resource objects to configuration file.
static Factory * self(const TQString &resourceFamily)
Returns the global resource factory.
void add(Resource *resource)
Add resource to manager.
ActiveIterator activeBegin()
Return Iterator on first active resource.
void addObserver(ManagerObserver< T > *observer)
Add observer for resource changes to manager.
This class provides a manager for resources of a specified family.
Class for loading resource plugins.