chalk

kis_resourceserver.h
1/*
2 * kis_resourceserver.h - part of KImageShop
3 *
4 * Copyright (c) 1999 Matthias Elter <elter@kde.org>
5 * Copyright (c) 2003 Patrick Julien <freak@codepimps.org>
6 * Copyright (c) 2005 Sven Langkamp <longamp@reallygood.de>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22#ifndef KIS_RESOURCESERVER_H_
23#define KIS_RESOURCESERVER_H_
24
25#include <tqstring.h>
26#include <tqstringlist.h>
27
28#include "kis_generic_registry.h"
29
30class KisResource;
31
32class KisResourceServerBase : public TQObject {
33 TQ_OBJECT
34
35public:
36 KisResourceServerBase(TQString type);
37 virtual ~KisResourceServerBase();
38
39 void loadResources(TQStringList filenames);
41 void addResource(KisResource* resource);
42 TQValueList<KisResource*> resources();
43 TQString type() { return m_type; };
44
45signals:
46 void resourceAdded(KisResource*);
47
48protected:
49 virtual KisResource* createResource( TQString filename ) = 0;
50
51private:
52 TQValueList<KisResource*> m_resources;
53 TQString m_type;
54
55 bool m_loaded;
56
57};
58
59
60template <class T> class KisResourceServer : public KisResourceServerBase {
61 typedef KisResourceServerBase super;
62
63public:
64 KisResourceServer(TQString type) :super( type ) {}
65 virtual ~KisResourceServer(){}
66
67private:
68 KisResource* createResource( TQString filename ){return new T(filename);}
69};
70
71
72
73
74class KisResourceServerRegistry : public KisGenericRegistry<KisResourceServerBase*>
75{
76
77public:
78 virtual ~KisResourceServerRegistry();
79
80 static KisResourceServerRegistry* instance();
81
82private:
83 KisResourceServerRegistry();
84 KisResourceServerRegistry(const KisResourceServerRegistry&);
85 KisResourceServerRegistry operator=(const KisResourceServerRegistry&);
86
87 static KisResourceServerRegistry *m_singleton;
88};
89
90
91#endif // KIS_RESOURCESERVER_H_
Base class for registry objects in Chalk.
The KisResource class provides a representation of Chalk image resources.