resource.h

00001 /*
00002     This file is part of libkresources
00003 
00004     Copyright (c) 2001-2003 Cornelius Schumacher <schumacher@kde.org>
00005     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 #ifndef KRESOURCES_RESOURCE_H
00023 #define KRESOURCES_RESOURCE_H
00024 
00025 #include <qmutex.h>
00026 #include <qvaluelist.h>
00027 #include <qwidget.h>
00028 
00029 #include <klibloader.h>
00030 
00031 class KConfig;
00032 
00033 namespace KRES {
00034 
00035 class ConfigWidget;
00036 
00255 class KRESOURCES_EXPORT Resource : public QObject
00256 {
00257     friend class Factory;
00258     friend class ManagerImpl;
00259 
00260     Q_OBJECT
00261   public:
00262     typedef QValueList<Resource *> List;
00263 
00269     Resource( const KConfig *config );
00270 
00274     virtual ~Resource();
00275 
00282     virtual void writeConfig( KConfig *config );
00283 
00293     bool open();
00294 
00301     void close();
00302 
00306     bool isOpen() const;
00307 
00314     QString identifier() const;
00315 
00319     QString type() const;
00320 
00325     virtual void setReadOnly( bool value );
00326 
00330     virtual bool readOnly() const;
00331 
00336     virtual void setResourceName( const QString &name );
00337 
00341     virtual QString resourceName() const;
00342 
00346     void setActive( bool active );
00347 
00351     bool isActive() const;
00352 
00356     virtual void dump() const;
00357 
00358   protected:
00368     virtual bool doOpen() { return true; }
00369 
00374     virtual void doClose() {}
00375 
00376     void setIdentifier( const QString &identifier );
00377     void setType( const QString &type );
00378 
00379   private:
00380     class ResourcePrivate;
00381     ResourcePrivate *d;
00382 };
00383 
00384 class KRESOURCES_EXPORT PluginFactoryBase : public KLibFactory
00385 {
00386   public:
00387     virtual Resource *resource( const KConfig *config ) = 0;
00388 
00389     virtual ConfigWidget *configWidget( QWidget *parent ) = 0;
00390 
00391   protected:
00392     virtual QObject* createObject( QObject *parent, const char *name, const char *className,
00393                                    const QStringList & args)
00394     {
00395       Q_UNUSED(parent);
00396       Q_UNUSED(name);
00397       Q_UNUSED(className);
00398       Q_UNUSED(args);
00399       return 0;
00400     }
00401 };
00402 
00403 template<class TR,class TC>
00404 class PluginFactory : public PluginFactoryBase
00405 {
00406   public:
00407     Resource *resource( const KConfig *config )
00408     {
00409       return new TR( config );
00410     }
00411 
00412     ConfigWidget *configWidget( QWidget *parent )
00413     {
00414       return new TC( parent );
00415     }
00416 };
00417 
00418 }
00419 
00420 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys