kresources
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 ) );
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 );
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;
Iterator begin()
Return Iterator on first resource.
This class provides a manager for resources of a specified family.
This class provides a resource which is managed in a general way.
Resource * resource(const QString &type, const KConfigGroup &group)
Returns a pointer to a resource object or a null pointer if resource type doesn't exist.
QStringList typeNames() const
Returns a list of all available resource types.
void add(Resource *resource)
Add resource to manager.
QString typeDescription(const QString &type) const
Returns the description for a special type.
T * standardResource()
Return standard resource.
ActiveIterator activeBegin()
Return Iterator on first active resource.
void setStandardResource(T *resource)
Set standard resource.
ActiveIterator activeEnd()
Return Iterator indicating end of active resource list.
T * createResource(const QString &type)
Creates a new resource of type type with default settings.
Observer class for Manager class.
Iterator for iterations over all resources managed by a manager.
void change(T *resource)
Call this to notify manager about changes of the configuration of the given resource.
void readConfig(KConfig *cfg=0)
Recreate Resource objects from configuration file.
QStringList resourceNames() const
Returns a list of the names of the resources managed by the Manager for this family.
void remove(Resource *resource)
Remove resource from manager.
QString typeName(const QString &type) const
Returns the name for a special type.
virtual QString resourceName() const
Returns the name of resource.
Manager(const QString &family)
Create manager for given resource family.
void writeConfig(KConfig *cfg=0)
Write configuration of Resource objects to configuration file.
QStringList resourceTypeNames() const
Returns a list of the names of all available resource types.
static Factory * self(const QString &resourceFamily)
Returns the global resource factory.
Iterator for iterations over only active resources managed by a manager.
QStringList resourceTypeDescriptions() const
Return list of descriptions of all available resource types.
Iterator end()
Return Iterator indicating end of resource list.
void setActive(Resource *resource, bool active)
Set active state of resource.
void addObserver(ManagerObserver< T > *observer)
Add observer for resource changes to manager.
void removeObserver(ManagerObserver< T > *observer)
Remove Observer for resource changes from manager.
bool isEmpty() const
Return true, if manager doesn't hold any resources.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Jul 28 2020 00:00:00 by
doxygen 1.8.18 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.