Subversion Repositories Scribus

Rev

Rev 12566 | Rev 19986 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
1549 subik 7
#ifndef _PLUGIN_MANAGER_
8
#define _PLUGIN_MANAGER_
9
 
10223 cbradney 10
#include <QObject>
11
#include <QString>
12
#include <QMap>
2969 craig 13
 
10859 cbradney 14
class QEvent;
15
 
2969 craig 16
#include "scribusapi.h"
1549 subik 17
 
5975 cbradney 18
class ScribusDoc;
5243 cbradney 19
class ScribusMainWindow;
3207 craig 20
class ScPlugin;
21
class ScActionPlugin;
22
class ScPersistentPlugin;
3246 craig 23
class PrefsContext;
17501 craig 24
class StoryEditor;
3207 craig 25
 
4448 subik 26
/**
27
 * \brief PluginManager handles plugin loading, unloading, and running.
28
                   *
29
                   * It contains methods and attributes for plugin running and its settings
30
                   * and returning values.
31
                   *
32
                   * Derived from Franz's ScribusMainWindow stuff (petr vanek)
33
                   *
34
 */
2969 craig 35
class SCRIBUS_API PluginManager : public QObject
1549 subik 36
{
2629 craig 37
 
1549 subik 38
        Q_OBJECT
39
 
40
public:
2629 craig 41
 
1549 subik 42
        PluginManager();
43
        ~PluginManager();
2629 craig 44
 
3994 subik 45
        /*! \brief Static methods for loading, unloading plugins and resolving symbols
46
         These methods are platform independent, but each platform uses a different
47
         implementation. */
2629 craig 48
        static void* loadDLL( QString plugin );
49
        static void* resolveSym( void* plugin, const char* sym );
50
        static void  unloadDLL( void* plugin );
51
 
5243 cbradney 52
        /*! \brief Initalization of all plugins. It's called at scribus start.
3994 subik 53
         *
5496 subik 54
         * Walk through all plugins, try to init them and try to re-load failed
55
         * ones then. See initPlugin for more info.
56
         * Reload uses a "brute force" method - Repeat until there is something
57
         * to load again. It's not elegant I know. But there are no additional
58
         * dependancy relations addons (XML config, plugin classes change etc.).
3207 craig 59
         */
1549 subik 60
        void initPlugs();
7126 subik 61
 
62
        /*! \brief Called at after initPlugs to hook the loaded plugin into the GUI.
5243 cbradney 63
         * Run in main window startup
64
         */
65
        bool setupPluginActions(ScribusMainWindow*);
17501 craig 66
 
67
        /*! \brief Called at after initPlugs to hook the loaded plugin into the GUI.
68
         * Run in SE startup
69
         */
70
        bool setupPluginActions(StoryEditor *sew);
2629 craig 71
 
12566 cbradney 72
        /*! \brief Called when the last doc is closed
73
         */
74
        void enableOnlyStartupPluginActions(ScribusMainWindow*);
75
        /*! \brief Called when the last doc is closed
76
         */
77
        void enablePluginActionsForSelection(ScribusMainWindow*);
7126 subik 78
 
3207 craig 79
        /*! \brief Checks if is the plugin is in the plugin map, is loaded, and is enabled.
80
         *
81
         * \param pluginName name of plugin to get
82
         * \param includeDisabled return true if a plugin is loaded but not enabled
1552 subik 83
         * \return bool
84
         */
8552 subik 85
        bool DLLexists(QString pluginName, bool includeDisabled = false) const;
2629 craig 86
 
3214 craig 87
        /*! \brief Returns a pointer to the requested plugin, or 0 if not found.
88
         *
89
         * If includeDisabled is true, plugins that are loaded but not enabled
90
         * are returned. If it is false, 0 is returned if the requested plugin
91
         * is loaded but not enabled.
92
         */
8552 subik 93
        ScPlugin* getPlugin(const QString & pluginName, bool includeDisabled) const;
2629 craig 94
 
1552 subik 95
        /*! \brief Shutdowns all plugins. Called at scribus quit */
3207 craig 96
        void cleanupPlugins();
2629 craig 97
 
3207 craig 98
        /** \brief Saves pluginManager preferences */
99
        void savePreferences();
100
 
101
        /*! \brief Return file extension used for shared libs on this platform */
8552 subik 102
        static QString platformDllExtension();
3207 craig 103
 
10402 jghali 104
        /*! \brief Return file extension used for shared libs on this platform */
105
        static int platformDllSearchFlags();
106
 
3994 subik 107
        /*! \brief Return a pointer to this instance.
12071 subik 108
         \note for now, returns a reference to (*ScMW->pluginManager); should
3994 subik 109
         probably be turned into a singleton later. */
3207 craig 110
        static PluginManager & instance();
1549 subik 111
 
3994 subik 112
        /*! \brief Return the path to the file for the named plugin.
113
        An invalid plugin name is an error.*/
8910 jghali 114
        const QString getPluginPath(const QString & pluginName) const;
1549 subik 115
 
3994 subik 116
        /*! \brief Whether the given plug-in will be enabled on start-up.
117
        Usable as an lvalue. An invalid plugin name is an error. */
8552 subik 118
        bool & enableOnStartup(const QString & pluginName);
3994 subik 119
 
120
        /*! \brief Whether the given plugin is currently enabled */
8552 subik 121
        bool enabled(const QString & pluginName);
1665 craig 122
 
3214 craig 123
        /** \brief Return a list of plugin names currently known.
124
         *
125
         * If includeNotLoaded is true, names are returned for plug-ins that are
126
         * not loaded (ie we have no ScPlugin instance for them).
127
         *
3383 craig 128
         * \param includeDisabled  Should the names of plugins that are loaded, but
129
         *                         disabled, be returned?
130
         * \param inherits         Only return plugins that inherit from this parent
131
         *                         (the text name of the type - uses QMetaObject).
132
         * \return A list of internal plugin names suitable for use with getPlugin etc.
133
         *
134
         * \sa getPluginNamesT
135
         * \sa getPlugin
3214 craig 136
         */
8552 subik 137
        QStringList pluginNames(bool includeDisabled = false,
3383 craig 138
                                                                         const char* inherits = 0) const;
10859 cbradney 139
 
140
        virtual void changeEvent(QEvent *e);
3207 craig 141
 
1549 subik 142
public slots:
2629 craig 143
 
2187 cbradney 144
        void languageChange();
1549 subik 145
 
3207 craig 146
protected:
2223 cbradney 147
 
3213 craig 148
        /**
149
         * \brief PluginData is structure for plugin related informations.
150
         * \param pluginFile path to the share library (with name).
151
         * \param pluginName internal name of plug-in, used for prefix to dlsym() names
152
         * \param pluginDLL reference to plug-in data for dynamic loading
153
         * \param plugin is the pointer to the plugin instance
154
         * \param enableOnStartup enable or disable plugin at app start-up
155
         * \param enabled has the plug-in been set up and activated (gui connected, setup called, etc)?
156
         *
157
         * Note that there are some constraints on this structure.
158
         * enabled == true depends on:
159
         *     plugin != 0 which depends on:
160
         *         pluginDLL != 0
161
         *
162
         * In other words, a plugin cannot be enabled unless we have an ScPlugin
163
         * instance for it. We can't have an ScPlugin instance for a plugin unless
164
         * it's linked.
165
         */
166
        struct PluginData
167
        {
168
                QString pluginFile; // Datei;
8552 subik 169
                QString pluginName;
3213 craig 170
                void* pluginDLL;
171
                ScPlugin* plugin;
172
                bool enableOnStartup;
173
                bool enabled;
174
        };
175
 
5496 subik 176
        /*! \brief Init one plugin.
177
         * This method loadDLL(...)'s each plug-in, creates a Plugin instance for
178
         * them, stores a PluginData for the plugin, sets up the plug-in's
179
         * actions, and connects them to any required signals.
180
         * It doesn't ask plug-ins to do any time-consuming setup.
181
         * It's called by initPlugs.
182
        \param fileName a filename of the plugin without path
183
        \retval int 0 init failed, 1 loaded.
184
         */
185
        int initPlugin(const QString fileName);
186
 
3213 craig 187
        /*! \brief Reads available info and fills PluginData structure */
188
        bool loadPlugin(PluginData & pluginData);
189
 
3994 subik 190
        /*! \brief Determines the plugin name from the file name and returns it. */
8552 subik 191
        static QString getPluginName(QString fileName);
3207 craig 192
 
3994 subik 193
        /*! \brief Called by loadPlugin to hook the loaded plugin into the GUI,
194
        call its setup routine, etc. Not responsible for creating
195
        the ScPlugin instance or loading the plugin. */
3207 craig 196
        void enablePlugin(PluginData &);
197
 
3994 subik 198
        /*! \brief Called by finalizePlug when shutting down a plug-in. Unhooks
199
         the plug-in from the GUI, calls its cleanup routine, etc.
200
         DOES NOT destroy the ScPlugin instance or unload the plugin. */
3207 craig 201
        void disablePlugin(PluginData & pda);
202
 
3994 subik 203
        /*! \brief Runs plugin's languageChange() method, and returns main menu item text if one exists */
3207 craig 204
        QString callDLLForNewLanguage(const PluginData & pluginData);
205
 
206
        /*! \brief Shuts down one plug-in. The DLL may not be unloaded, but
207
         *         it is cleaned up and its ScPlugin instance is destroyed.
208
         *         The plug-in is marked unloaded in the map.
4645 subik 209
         *  \param pda plugin data
3207 craig 210
         */
211
        void finalizePlug(PluginData & pda);
212
 
1552 subik 213
        /** \brief Configuration structure */
214
        PrefsContext* prefs;
2629 craig 215
 
3994 subik 216
        /*! \brief Mapping of plugin names to plugin info structures. */
8552 subik 217
        typedef QMap<QString,PluginData> PluginMap;
3213 craig 218
 
3207 craig 219
        /*! \brief Plugin mapping.
3213 craig 220
         * Each plugin has its record key() -> PluginData
221
         */
3207 craig 222
        PluginMap pluginMap;
1549 subik 223
};
224
 
225
#endif