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;
95 T *operator*() {
return static_cast<T *
>( *mIt ); }
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();
168 T *operator*() {
return static_cast<T *
>( *mIt ); }
171 do { mIt++; }
while ( checkActive() );
176 do { mIt++; }
while ( checkActive() );
181 do { mIt--; }
while ( checkActive() );
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 )
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 )
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.
QStringList resourceTypeNames() const
Returns a list of the names of all available resource types.
void setActive(Resource *resource, bool active)
Set active state of resource.
T * standardResource()
Return standard resource.
QStringList resourceTypeDescriptions() const
Return list of descriptions of all available resource types.
Iterator end()
Return Iterator indicating end of resource list.
Manager(const QString &family)
Create manager for given resource family.
void removeObserver(ManagerObserver< T > *observer)
Remove Observer for resource changes from manager.
T * createResource(const QString &type)
Creates a new resource of type type with default settings.
ActiveIterator activeEnd()
Return Iterator indicating end of active resource list.
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.
This file is part of the KDE resource framework and defines the Factory class.
void writeConfig(KConfig *cfg=0)
Write configuration of Resource objects to configuration file.
QStringList resourceNames() const
Returns a list of the names of the resources managed by the Manager for this family.
virtual QString resourceName() const
Returns the name of resource.
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.
A class for loading resource plugins.
bool isEmpty() const
Return true, if manager doesn't hold any resources.