diff --git a/kabc/errorhandler.h b/kabc/errorhandler.h index 64863ed75..4e2220fcd 100644 --- a/kabc/errorhandler.h +++ b/kabc/errorhandler.h @@ -1,83 +1,85 @@ /* This file is part of libkabc. Copyright (c) 2002 Tobias Koenig Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KABC_ERRORHANDLER_H #define KABC_ERRORHANDLER_H #include #include class QWidget; namespace KABC { /** Abstract class that provides displaying of error messages. We need this to make libkabc gui independent on the one side and provide user friendly error messages on the other side. Use @p ConsoleErrorHandler or @p GuiErrorHandler in your application or provide your own ErrorHandler. */ class KABC_EXPORT ErrorHandler { public: + virtual ~ErrorHandler(){}; /** Show error message. */ virtual void error( const QString &msg ) = 0; }; /** This class prints the error messages to stderr via kdError(). */ class KABC_EXPORT ConsoleErrorHandler : public ErrorHandler { public: + virtual ~ConsoleErrorHandler(){}; virtual void error( const QString &msg ); }; /** This class shows messages boxes for every error message. */ class KABC_EXPORT GuiErrorHandler : public ErrorHandler { public: /** Create error handler. \param parent Widget which is used as parent for the error dialogs. */ GuiErrorHandler( QWidget *parent = 0 ); - + virtual ~GuiErrorHandler(){}; virtual void error( const QString &msg ); private: QWidget *mParent; class Private; Private *d; }; } #endif diff --git a/kabc/sortmode.h b/kabc/sortmode.h index ed41371eb..122bd8649 100644 --- a/kabc/sortmode.h +++ b/kabc/sortmode.h @@ -1,112 +1,113 @@ /* This file is part of libkabc. Copyright (c) 2004 Tobias Koenig This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KABC_SORTMODE_H #define KABC_SORTMODE_H #include #include namespace KABC { /** @short Sort method for sorting an addressee list. This interface should be reimplemented by classes which shall act as SortModes for KABC::AddresseeList. */ class KABC_EXPORT SortMode { public: + virtual ~SortMode(){}; /** Reimplement this method and return whether the first contact is 'smaller' than the second. */ virtual bool lesser( const KABC::Addressee &first, const KABC::Addressee &second ) const = 0; }; class KABC_EXPORT NameSortMode : public SortMode { public: enum NameType { FormattedName, FamilyName, GivenName }; /** Constructor. Creates a NameSortMethod with FormattedName as name type set. */ NameSortMode(); - + virtual ~NameSortMode(){}; /** Constructor. Creates a NameSortMethod with the specified name type. @param type The name type. */ NameSortMode( NameType type, bool ascending = true ); /** Returns whether the first contact is 'smaller' then the second. */ virtual bool lesser( const KABC::Addressee&, const KABC::Addressee& ) const; private: NameType mNameType; bool mAscendingOrder; class NameSortModePrivate; NameSortModePrivate *d; }; class KABC_EXPORT FieldSortMode : public SortMode { public: /** Constructor. Creates a FieldSortMethod with the specified field. @param field The field. */ FieldSortMode( KABC::Field *field, bool ascending = true ); - + virtual ~FieldSortMode(){}; /** Returns whether the first contact is 'smaller' then the second. */ virtual bool lesser( const KABC::Addressee&, const KABC::Addressee& ) const; private: KABC::Field *mField; bool mAscendingOrder; class FieldSortModePrivate; FieldSortModePrivate *d; }; } #endif diff --git a/kresources/manager.h b/kresources/manager.h index e0e775a59..5d0b5707b 100644 --- a/kresources/manager.h +++ b/kresources/manager.h @@ -1,422 +1,424 @@ /* This file is part of libkresources. Copyright (c) 2002 Tobias Koenig Copyright (c) 2002 Jan-Pascal van Best Copyright (c) 2003 Cornelius Schumacher This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KRESOURCES_MANAGER_H #define KRESOURCES_MANAGER_H #include #include #include #include #include namespace KRES { class Resource; /** Observer class for Manager class. For getting notified about changes of Resources managed by a Manager object implement this Observer interface and add an object of this implementation to the Manager using addObserver(). The resourceAdded(), resourceModified() and resourceDeleted() functions of your implementation will be called whenever resources managed by the Manager object are added, modified or deleted. */ template class ManagerObserver { public: + virtual ~ManagerObserver(){}; virtual void resourceAdded( T *resource ) = 0; virtual void resourceModified( T *resource ) = 0; virtual void resourceDeleted( T *resource ) = 0; }; /** @internal */ class ManagerNotifier { public: + virtual ~ManagerNotifier(){}; virtual void notifyResourceAdded( Resource *resource ) = 0; virtual void notifyResourceModified( Resource *resource ) = 0; virtual void notifyResourceDeleted( Resource *resource ) = 0; }; /** This class provides a manager for resources of a specified family. It takes care of loading and saving resource configurations and provides access to the resources and their attributes. External changes in the resource configuration are notified by the ManagerObserver interface. If your application needs to be notified about resource configuration changes, you have to subclass ManagerObserver and add it to the Manager by addObserver(). Since KDE 3.4 it's required to supply your application with a *.desktop file for each resource family you introduce. The ServiceType should be of KResources/Manager. */ template class Manager : private ManagerNotifier { public: /** Iterator for iterations over all resources managed by a manager. */ class Iterator { friend class Manager; public: Iterator() {}; Iterator( const Iterator &it ) { mIt = it.mIt; } T *operator*() { return static_cast( *mIt ); } Iterator &operator++() { mIt++; return *this; } Iterator &operator++( int ) { mIt++; return *this; } Iterator &operator--() { mIt--; return *this; } Iterator &operator--( int ) { mIt--; return *this; } bool operator==( const Iterator &it ) { return mIt == it.mIt; } bool operator!=( const Iterator &it ) { return mIt != it.mIt; } private: Resource::List::Iterator mIt; }; /** Return Iterator on first resource. If there is no resource returns end(). */ Iterator begin() { Iterator it; it.mIt = mImpl->resourceList()->begin(); return it; } /** Return Iterator indicating end of resource list. */ Iterator end() { Iterator it; it.mIt = mImpl->resourceList()->end(); return it; } /** Iterator for iterations over only active resources managed by a manager. */ class ActiveIterator { friend class Manager; public: ActiveIterator() : mList( 0 ) {}; ActiveIterator( const ActiveIterator &it ) { mIt = it.mIt; mList = it.mList; } T *operator*() { return static_cast( *mIt ); } ActiveIterator &operator++() { do { mIt++; } while ( checkActive() ); return *this; } ActiveIterator &operator++( int ) { do { mIt++; } while ( checkActive() ); return *this; } ActiveIterator &operator--() { do { mIt--; } while ( checkActive() ); return *this; } ActiveIterator &operator--( int ) { do { mIt--; } while ( checkActive() ); return *this; } bool operator==( const ActiveIterator &it ) { return mIt == it.mIt; } bool operator!=( const ActiveIterator &it ) { return mIt != it.mIt; } private: /** Check if iterator needs to be advanced once more. */ bool checkActive() { if ( !mList || mIt == mList->end() ) return false; return !(*mIt)->isActive(); } Resource::List::Iterator mIt; Resource::List *mList; }; /** Return Iterator on first active resource. If there is no active resource returns end(). */ ActiveIterator activeBegin() { ActiveIterator it; it.mIt = mImpl->resourceList()->begin(); it.mList = mImpl->resourceList(); if ( it.mIt != mImpl->resourceList()->end() ) { if ( !(*it)->isActive() ) it++; } return it; } /** Return Iterator indicating end of active resource list. */ ActiveIterator activeEnd() { ActiveIterator it; it.mIt = mImpl->resourceList()->end(); it.mList = mImpl->resourceList(); return it; } /** Return true, if manager doesn't hold any resources. If there are resources return false. */ bool isEmpty() const { return mImpl->resourceList()->isEmpty(); } /** Create manager for given resource family. The family argument is used as identifier for loading and saving resource configurations. */ Manager( const QString &family ) { mFactory = Factory::self( family ); // The managerimpl will use the same Factory object as the manager // because of the Factory::self() pattern mImpl = new ManagerImpl( this, family ); mObservers.setAutoDelete( false ); } virtual ~Manager() { delete mImpl; } /** Recreate Resource objects from configuration file. If cfg is 0, read standard configuration file determined by family name. */ void readConfig( KConfig *cfg = 0 ) { mImpl->readConfig( cfg ); } /** Write configuration of Resource objects to configuration file. If cfg is 0, write to standard configuration file determined by family name. */ void writeConfig( KConfig *cfg = 0 ) { mImpl->writeConfig( cfg ); } /** Add resource to manager. This passes ownership of the Resource object to the manager. */ void add( Resource *resource ) { if ( resource ) mImpl->add( resource ); } /** Remove resource from manager. This deletes the Resource object. */ void remove( Resource *resource ) { if ( resource ) mImpl->remove( resource ); } /** Call this to notify manager about changes of the configuration of the given resource. */ void change( T *resource ) { mImpl->change( resource ); } /** Return standard resource. */ T *standardResource() { return static_cast( mImpl->standardResource() ); } /** Set standard resource. */ void setStandardResource( T *resource ) { if ( resource ) mImpl->setStandardResource( resource ); } /** Set active state of resource. */ void setActive( Resource *resource, bool active ) { if ( resource ) mImpl->setActive( resource, active ); } /** Returns a list of the names of the resources managed by the Manager for this family. */ QStringList resourceNames() const { return mImpl->resourceNames(); } /** Creates a new resource of type @p type with default settings. The resource is not added to the manager, the application has to do that. Returns a pointer to a resource object or a null pointer if resource type doesn't exist. @param type The type of the resource, one of those returned by resourceTypeNames() */ T *createResource( const QString& type ) { return dynamic_cast( mFactory->resource( type, 0 ) ); } /** Returns a list of the names of all available resource types. */ QStringList resourceTypeNames() const { return mFactory->typeNames(); } /** Return list of descriptions of all available resource types. */ QStringList resourceTypeDescriptions() const { QStringList typeDescs; QStringList types = mFactory->typeNames(); for ( QStringList::ConstIterator it = types.begin(); it != types.end(); ++it ) { QString desc = mFactory->typeName( *it ); if ( !mFactory->typeDescription( *it ).isEmpty() ) desc += " (" + mFactory->typeDescription( *it ) + ")"; typeDescs.append( desc ); } return typeDescs; } /** Add observer for resource changes to manager. See ManagerObserver. The Manager does not take ownership of the Observer object. */ void addObserver( ManagerObserver *observer ) { mObservers.append( observer ); } /** Remove Observer for resource changes from manager. See ManagerObserver. The Observer is not deleted by the Manager after being removed. */ void removeObserver( ManagerObserver *observer ) { mObservers.remove( observer ); } private: /** Implementation of the ManagerNotifier interface. */ void notifyResourceAdded( Resource *res ) { kdDebug(5650) << "Manager::resourceAdded " << res->resourceName() << endl; T *resource = dynamic_cast( res ); if ( resource ) { ManagerObserver *observer; for ( observer = mObservers.first(); observer; observer = mObservers.next() ) observer->resourceAdded( resource ); } } /** Implementation of the ManagerNotifier interface. */ void notifyResourceModified( Resource *res ) { kdDebug(5650) << "Manager::resourceModified " << res->resourceName() << endl; T *resource = dynamic_cast( res ); if ( resource ) { ManagerObserver *observer; for ( observer = mObservers.first(); observer; observer = mObservers.next() ) observer->resourceModified( resource ); } } /** Implementation of the ManagerNotifier interface. */ void notifyResourceDeleted( Resource *res ) { kdDebug(5650) << "Manager::resourceDeleted " << res->resourceName() << endl; T *resource = dynamic_cast( res ); if ( resource ) { ManagerObserver *observer; for ( observer = mObservers.first(); observer; observer = mObservers.next() ) { kdDebug(5650) << "Notifying a observer to Manager..." << endl; observer->resourceDeleted( resource ); } } } private: ManagerImpl *mImpl; Factory *mFactory; Q3PtrList > mObservers; }; } #endif