Diffstat (limited to 'libopie2/opiecore/opluginloader.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiecore/opluginloader.h | 191 |
1 files changed, 191 insertions, 0 deletions
diff --git a/libopie2/opiecore/opluginloader.h b/libopie2/opiecore/opluginloader.h new file mode 100644 index 0000000..a7df4a8 --- a/dev/null +++ b/libopie2/opiecore/opluginloader.h | |||
@@ -0,0 +1,191 @@ | |||
1 | /* | ||
2 | * LGPLv2 or later | ||
3 | * zecke@handhelds.org | ||
4 | */ | ||
5 | #ifndef ODP_CORE_OPLUGIN_LOADER_H | ||
6 | #define ODP_CORE_OPLUGIN_LOADER_H | ||
7 | |||
8 | #include <qpe/qlibrary.h> | ||
9 | |||
10 | #include <qstringlist.h> | ||
11 | |||
12 | namespace Opie { | ||
13 | namespace Core { | ||
14 | class OConfig; | ||
15 | namespace Internal { | ||
16 | class OPluginLibraryHolder; | ||
17 | } | ||
18 | |||
19 | template class QPtrDict<QLibrary>; | ||
20 | |||
21 | /** | ||
22 | * \brief A small item representing the Plugin Information | ||
23 | * This class contains the information about a Plugin. It contains | ||
24 | * a translated name if available to the system, a config key, | ||
25 | * and the path location. | ||
26 | * | ||
27 | * @since 1.2 | ||
28 | * | ||
29 | */ | ||
30 | class OPluginItem { | ||
31 | public: | ||
32 | typedef QValueList<OPluginItem> List; | ||
33 | OPluginItem(); | ||
34 | OPluginItem( const QString& name, const QCString& confopt, const QString& path, int pos = -1 ); | ||
35 | ~OPluginItem(); | ||
36 | |||
37 | bool operator==( const OPluginItem& )const; | ||
38 | bool operator!=( const OPluginItem& )const; | ||
39 | |||
40 | |||
41 | QString name()const; | ||
42 | QCString configKey()const; | ||
43 | QString path()const; | ||
44 | int position()const; | ||
45 | |||
46 | void setName( const QString& ); | ||
47 | void setConfigKey( const QCString& ); | ||
48 | void setPath( const QString& ); | ||
49 | void setPosition( int ); | ||
50 | |||
51 | private: | ||
52 | QString m_name; | ||
53 | QCString m_conf; | ||
54 | QString m_path; | ||
55 | int m_pos; | ||
56 | struct Private; | ||
57 | Private *d; | ||
58 | }; | ||
59 | |||
60 | /** | ||
61 | * \brief A generic class to easily load and manage plugins | ||
62 | * | ||
63 | * This is the generic non sepcialised loader for plugins. Normally | ||
64 | * you would prefer using the OPluginLoader directly. This class | ||
65 | * exists to minimize the application binary size due the usage | ||
66 | * of templates in the specialized API | ||
67 | * | ||
68 | * @since 1.2 | ||
69 | * @see OPluginLoader | ||
70 | */ | ||
71 | class OGenericPluginLoader { | ||
72 | public: | ||
73 | typedef OPluginItem::List List; | ||
74 | OGenericPluginLoader( const QString &name, bool isSorted = false ); | ||
75 | virtual ~OGenericPluginLoader(); | ||
76 | |||
77 | void setAutoDelete( bool ); | ||
78 | bool autoDelete()const; | ||
79 | void clear(); | ||
80 | |||
81 | |||
82 | bool isInSafeMode()const; | ||
83 | |||
84 | |||
85 | List allAvailable(bool sorted = FALSE)const; | ||
86 | List filtered(bool sorted = FALSE)const; | ||
87 | |||
88 | |||
89 | virtual QUnknownInterface* load( const OPluginItem& item, const QUuid& ); | ||
90 | virtual void unload( QUnknownInterface* ); | ||
91 | |||
92 | protected: | ||
93 | virtual void readConfig(); | ||
94 | virtual List plugins( const QString& dir, bool sorted, bool disabled )const; | ||
95 | void setPluginDirs( const QStringList& ); | ||
96 | void setPluginDir( const QString& ); | ||
97 | bool &isSafeMode()const; | ||
98 | bool &isSorted()const; | ||
99 | void readConfig()const; | ||
100 | void setSafeMode(bool b = false); | ||
101 | |||
102 | private: | ||
103 | QString languageList(); | ||
104 | void installTranslators(const QString& type); | ||
105 | QString m_dir; | ||
106 | QStringList m_plugDirs; | ||
107 | QStringList m_languages; | ||
108 | bool m_autoDelete : 1; | ||
109 | bool m_isSafeMode : 1; | ||
110 | bool m_readConfig : 1; | ||
111 | bool m_isSorted : 1; | ||
112 | QPtrDict<QLibrary> m_library; | ||
113 | |||
114 | struct Private; | ||
115 | Private* d; | ||
116 | }; | ||
117 | |||
118 | /** | ||
119 | * \brief The class to load your QCOM+ plugins | ||
120 | * | ||
121 | * This class takes care of activation and even the order | ||
122 | * if you need it. It is normally good to place a .directory file | ||
123 | * into your plugin directory if you need order of activation. | ||
124 | * | ||
125 | * You'll create the OPluginLoader and then use it to load the filtered | ||
126 | * plugins. | ||
127 | * | ||
128 | * There is also a GUI for the configuration and a Manager to write the | ||
129 | * mentioned .directory file | ||
130 | * | ||
131 | * On crash the safe mode is activated for the next run. You can then decide | ||
132 | * if you want to load plugins or come up with the Configuration on | ||
133 | * next start yourself then. | ||
134 | * | ||
135 | * @since 1.2 | ||
136 | */ | ||
137 | class OPluginLoader : public OGenericPluginLoader { | ||
138 | public: | ||
139 | OPluginLoader( const QString& name, bool sorted = false ); | ||
140 | ~OPluginLoader(); | ||
141 | |||
142 | temlate<class IFace> | ||
143 | IFace* load( const QString& name, const QUuid& ); | ||
144 | temlate<class IFace> | ||
145 | IFace* load( const OPluginItem& item, const QUuid& ); | ||
146 | }; | ||
147 | |||
148 | /** | ||
149 | * \brief A class to manager order and activation of plugins | ||
150 | * | ||
151 | * Manage order and activation. This is used by the Opie::Ui::OPluginConfig | ||
152 | * This class controls the activation and order of plugins depending | ||
153 | * on the OPluginLoader you supply. | ||
154 | * | ||
155 | * @see OPluginConfig | ||
156 | * | ||
157 | */ | ||
158 | class OPluginManager { | ||
159 | public: | ||
160 | OPluginManager( OGenericPluginLoader* , const QString& name); | ||
161 | OPluginManager( OConfig* conf, const QString&, | ||
162 | const QCString& group, const OPluginItem::List& ); | ||
163 | ~OPluginManager(); | ||
164 | |||
165 | QString name(); | ||
166 | void setName( const QString& ); | ||
167 | |||
168 | void setPosition( const OPluginItem& ); | ||
169 | void enable( const OPluginItem& ); | ||
170 | void disable( const OPluginItem& ); | ||
171 | void setEnabled( const OPluginItem&, bool = true); | ||
172 | |||
173 | void load(); | ||
174 | void save(); | ||
175 | }; | ||
176 | |||
177 | template<class IFace> | ||
178 | IFace* OPluginLoader::load( const QString& name, const QUuid& uid ) { | ||
179 | return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) ); | ||
180 | } | ||
181 | |||
182 | template<class IFace> | ||
183 | IFace* OPluginLoader::load( const OPluginItem& item, const QUuid& uid ) { | ||
184 | return static_cast<IFace*>( OGenericPluginLoader::load( item, uid ) ); | ||
185 | } | ||
186 | |||
187 | } | ||
188 | } | ||
189 | |||
190 | |||
191 | #endif | ||