1 | /* |
2 | This file is part of libkresources. |
3 | |
4 | Copyright (c) 2002 Tobias Koenig <tokoe@kde.org> |
5 | Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org> |
6 | Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> |
7 | |
8 | This library is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU Library General Public |
10 | License as published by the Free Software Foundation; either |
11 | version 2 of the License, or (at your option) any later version. |
12 | |
13 | This library 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 GNU |
16 | Library General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Library General Public License |
19 | along with this library; see the file COPYING.LIB. If not, write to |
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
21 | Boston, MA 02110-1301, USA. |
22 | */ |
23 | /** |
24 | @file |
25 | This file is part of the KDE resource framework and defines the |
26 | Factory class. |
27 | |
28 | @author Tobias Koenig |
29 | @author Jan-Pascal van Best |
30 | @author Cornelius Schumacher |
31 | */ |
32 | |
33 | #ifndef KRESOURCES_FACTORY_H |
34 | #define KRESOURCES_FACTORY_H |
35 | |
36 | #include <QtCore/QMap> |
37 | #include <QtCore/QString> |
38 | |
39 | #include <kconfig.h> |
40 | #include <kservice.h> |
41 | |
42 | #include "resource.h" |
43 | #include "configwidget.h" |
44 | |
45 | namespace KRES { |
46 | |
47 | /** |
48 | @brief |
49 | A class for loading resource plugins. |
50 | |
51 | Use this class if you need resources with special |
52 | settings, otherwise use KRES::Manager::createResource() |
53 | to get resources with the default settings. |
54 | |
55 | Example: |
56 | |
57 | \code |
58 | KRES::Factory *factory = KRES::Factory::self( "contact" ); |
59 | |
60 | // to allow a transparent configuration of resources, we have |
61 | // to use a kconfig object. |
62 | KConfig config; |
63 | KConfigGroup group( &config, "General" ); |
64 | group.writePathEntry( "FileName", "/home/foobar/test.vcf" );// resource dependent |
65 | group.writeEntry( "FileFormat", "vcard" ); // resource dependent |
66 | |
67 | KRES::Resource *res = factory->resource( "file", group ); |
68 | |
69 | // do something with resource |
70 | |
71 | \endcode |
72 | */ |
73 | class KRESOURCES_DEPRECATED_EXPORT Factory |
74 | { |
75 | public: |
76 | |
77 | /** |
78 | Returns the global resource factory. |
79 | */ |
80 | static Factory *self( const QString &resourceFamily ); |
81 | |
82 | ~Factory(); |
83 | |
84 | /** |
85 | Returns the config widget for the given resource type, |
86 | or a null pointer if resource type doesn't exist. |
87 | |
88 | @param type The type of the resource, returned by typeNames() |
89 | @param parent The parent widget |
90 | */ |
91 | ConfigWidget *configWidget( const QString &type, QWidget *parent = 0 ); |
92 | |
93 | /** |
94 | * Reload the configuration. This reloads the plugin type map. |
95 | * Useful to call after resources have been added or removed. |
96 | * @since 4.2 |
97 | */ |
98 | void reloadConfig(); |
99 | |
100 | /** |
101 | Returns a pointer to a resource object or a null pointer |
102 | if resource type doesn't exist. |
103 | |
104 | @param type The type of the resource, returned by typeNames() |
105 | @param config The configuration group where the resource should |
106 | get its settings from. |
107 | */ |
108 | Resource *resource( const QString &type, const KConfigGroup &group ); |
109 | |
110 | /** |
111 | Creates and returns a resource object with default values, |
112 | or a null pointer if resource type doesn't exist. |
113 | |
114 | @param type The type of the resource, returned by typeNames() |
115 | */ |
116 | Resource *resource( const QString &type ); |
117 | |
118 | /** |
119 | |
120 | Returns a list of all available resource types. |
121 | */ |
122 | QStringList typeNames() const; |
123 | |
124 | /** |
125 | Returns the name for a special type. |
126 | */ |
127 | QString typeName( const QString &type ) const; |
128 | |
129 | /** |
130 | Returns the description for a special type. |
131 | */ |
132 | QString typeDescription( const QString &type ) const; |
133 | |
134 | protected: |
135 | Factory( const QString &resourceFamily ); |
136 | |
137 | private: |
138 | class Private; |
139 | Private *const d; |
140 | }; |
141 | |
142 | } |
143 | #endif |
144 | |