krita

kis_resourceserver.h

00001 /*
00002  *  kis_resourceserver.h - part of KImageShop
00003  *
00004  *  Copyright (c) 1999 Matthias Elter <elter@kde.org>
00005  *  Copyright (c) 2003 Patrick Julien <freak@codepimps.org>
00006  *  Copyright (c) 2005 Sven Langkamp <longamp@reallygood.de>
00007  *
00008  *  This program is free software; you can redistribute it and/or modify
00009  *  it under the terms of the GNU General Public License as published by
00010  *  the Free Software Foundation; either version 2 of the License, or
00011  *  (at your option) any later version.
00012  *
00013  *  This program is distributed in the hope that it will be useful,
00014  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  *  GNU General Public License for more details.
00017  *
00018  *  You should have received a copy of the GNU General Public License
00019  *  along with this program; if not, write to the Free Software
00020  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  */
00022 #ifndef KIS_RESOURCESERVER_H_
00023 #define KIS_RESOURCESERVER_H_
00024 
00025 #include <qstring.h>
00026 #include <qstringlist.h>
00027 
00028 #include "kis_generic_registry.h"
00029 
00030 class KisResource;
00031 
00032 class KisResourceServerBase : public QObject {
00033     Q_OBJECT
00034 public:
00035     KisResourceServerBase(QString type);
00036     virtual ~KisResourceServerBase();
00037 
00038     void loadResources(QStringList filenames);
00040     void addResource(KisResource* resource);
00041     QValueList<KisResource*> resources();
00042     QString type() { return m_type; };
00043 
00044 signals:
00045     void resourceAdded(KisResource*);
00046 
00047 protected:
00048     virtual KisResource* createResource( QString filename ) = 0;
00049 
00050 private:
00051     QValueList<KisResource*> m_resources;
00052     QString m_type;
00053 
00054     bool m_loaded;
00055 
00056 };
00057 
00058 
00059 template <class T> class KisResourceServer : public KisResourceServerBase {
00060     typedef KisResourceServerBase super;
00061 
00062 public:
00063     KisResourceServer(QString type) :super( type ) {}
00064     virtual ~KisResourceServer(){}
00065 
00066 private:
00067     KisResource* createResource( QString filename ){return new T(filename);}
00068 };
00069 
00070 
00071 
00072 
00073 class KisResourceServerRegistry : public KisGenericRegistry<KisResourceServerBase*>
00074 {
00075 
00076 public:
00077     virtual ~KisResourceServerRegistry();
00078 
00079     static KisResourceServerRegistry* instance();
00080 
00081 private:
00082     KisResourceServerRegistry();
00083      KisResourceServerRegistry(const KisResourceServerRegistry&);
00084      KisResourceServerRegistry operator=(const KisResourceServerRegistry&);
00085 
00086     static KisResourceServerRegistry *m_singleton;
00087 };
00088 
00089 
00090 #endif // KIS_RESOURCESERVER_H_
KDE Home | KDE Accessibility Home | Description of Access Keys