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 | |||
@@ -29,30 +29,35 @@ template class QPtrDict<QLibrary>; | |||
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 | /** |
@@ -73,32 +78,32 @@ public: | |||
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; |
@@ -130,48 +135,68 @@ private: | |||
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 | } |