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