Avogadro  1.1.0
/home/kitware/dashboards/avogadro/libavogadro/src/pluginmanager.h
00001 /**********************************************************************
00002   PluginManager - Class to handle dynamic loading/unloading of plugins
00003 
00004   Copyright (C) 2008 Donald Ephraim Curtis
00005   Copyright (C) 2008,2009 Tim Vandermeersch
00006   Copyright (C) 2008 Marcus D. Hanwell
00007 
00008   This file is part of the Avogadro molecular editor project.
00009   For more information, see <http://avogadro.openmolecules.net/>
00010 
00011   Avogadro is free software; you can redistribute it and/or modify
00012   it under the terms of the GNU General Public License as published by
00013   the Free Software Foundation; either version 2 of the License, or
00014   (at your option) any later version.
00015 
00016   Avogadro is distributed in the hope that it will be useful,
00017   but WITHOUT ANY WARRANTY; without even the implied warranty of
00018   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019   GNU General Public License for more details.
00020 
00021   You should have received a copy of the GNU General Public License
00022   along with this program; if not, write to the Free Software
00023   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024   02110-1301, USA.
00025  **********************************************************************/
00026 
00027 #ifndef PLUGINMANAGER_H
00028 #define PLUGINMANAGER_H
00029 
00030 #include <avogadro/global.h>
00031 #include <avogadro/plugin.h>
00032 
00033 #include <QStringList>
00034 
00035 class QDir;
00036 class QSettings;
00037 class QFileInfo;
00038 
00039 namespace Avogadro {
00040 
00041   class PluginFactory;
00042   class Tool;
00043   class Engine;
00044   class Extension;
00045   class Color;
00046   class PluginItemPrivate;
00047 
00048   class A_EXPORT PluginItem
00049   {
00050   public:
00051     PluginItem();
00052     //    PluginItem(int type, const QString &fileName, 
00053     //               const QString &filePath, PluginFactory *factory);
00054     PluginItem(const QString &name, const QString &identifier,
00055                const QString &description,
00056                Plugin::Type type, const QString &fileName, 
00057                const QString &filePath, PluginFactory *factory = 0, 
00058                bool enabled = true);
00059     ~PluginItem();
00060 
00064     int type() const;
00065 
00069     QString name() const;
00070 
00074     QString description() const;
00075 
00079     QString identifier() const;
00080 
00084     QString fileName() const;
00085 
00089     QString absoluteFilePath() const;
00090 
00094     bool isEnabled() const;
00095 
00096     PluginFactory *factory() const;
00097 
00101     void setType( Plugin::Type type );
00102 
00106     void setName( const QString &name );
00107 
00111     void setIdentifier( const QString &id );
00112 
00116     void setDescription( const QString &description );
00117 
00121     void setFileName( const QString &fileName );
00122 
00126     void setAbsoluteFilePath( const QString &filePath );
00127 
00131     void setEnabled( bool enable );
00132 
00133     void setFactory( PluginFactory *factory );
00134 
00135   private:
00136     PluginItemPrivate * const d;
00137   };
00138 
00139   class PluginManagerPrivate;
00140   class A_EXPORT PluginManager: public QObject
00141   {
00142   Q_OBJECT
00143 
00144   public:
00145     PluginManager(QObject *parent = 0);
00146     ~PluginManager();
00147 
00152     static PluginManager* instance();
00153 
00157     void setPluginPath(const QStringList& path);
00158 
00163     void setPluginPath(const QString& path);
00164 
00168     void addToPluginPath(const QStringList& path);
00169 
00174     void addToPluginPath(const QString& path);
00175 
00179     QStringList pluginPath() const;
00180 
00196     void loadFactories(const QString& dir = "");
00197 
00202     static void loadPluginList(const QDir &dir, const QStringList &plugins,
00203                                QSettings &settings);
00204 
00208     QList<PluginFactory *> factories( Plugin::Type type );
00209 
00213     PluginFactory *factory(const QString &id, Plugin::Type type);
00214 
00219     Extension *extension(const QString &id, QObject *parent = 0);
00220 
00225     Tool *tool(const QString &id, QObject *parent = 0);
00226 
00231     Color *color(const QString &id, QObject *parent = 0);
00232 
00237     Engine *engine(const QString &id, QObject *parent = 0);
00238 
00242     QList<QString> names(Plugin::Type type);
00243 
00247     QList<QString> identifiers(Plugin::Type type);
00248 
00252     QList<QString> descriptions(Plugin::Type type);
00253 
00257     QList<Extension *> extensions(QObject *parent=0);
00258 
00262     QList<Tool *> tools(QObject *parent=0);
00263 
00267     QList<Color *> colors(QObject *parent=0);
00268 
00272     void writeSettings(QSettings &settings);
00273     /*static void readSettings(QSettings &settings);*/
00274 
00278     QList<QString> toolScripts();
00279 
00283     QList<QString> engineScripts();
00284 
00288     QList<QString> extensionScripts();
00289 
00293     QList<PluginItem *> pluginItems(Plugin::Type);
00294 
00295   public Q_SLOTS:
00296     void reload();
00297 
00298   Q_SIGNALS:
00299     void reloadPlugins();
00300 
00301   private:
00302     PluginManagerPrivate * const d;
00303 
00308     static void loadPluginDir(const QString &directory, QSettings &settings);
00309     static void loadFactory(PluginFactory *factory, QFileInfo &fileInfo,
00310                             QSettings &settings);
00311     static QList<QString> scripts(const QString &type);
00312     static void initializeSearchDirs(QStringList &searchDirs);
00313   };
00314 
00315 }
00316 
00317 #endif