1 /***************************************************************************
2  *                                                                         *
3  *   copyright : (C) 2007 The University of Toronto                        *
4  *                   netterfield@astro.utoronto.ca                         *
5  *                                                                         *
6  *   This program is free software; you can redistribute it and/or modify  *
7  *   it under the terms of the GNU General Public License as published by  *
8  *   the Free Software Foundation; either version 2 of the License, or     *
9  *   (at your option) any later version.                                   *
10  *                                                                         *
11  ***************************************************************************/
12 
13 #ifndef KST_DATA_SOURCE_PLUGIN_MANAGER_H
14 #define KST_DATA_SOURCE_PLUGIN_MANAGER_H
15 
16 
17 #include "dataplugin.h"
18 #include "sharedptr.h"
19 #include "datasource.h"
20 
21 #include <QSettings>
22 #include <QMap>
23 
24 
25 namespace Kst {
26 
27 class ObjectStore;
28 
29 
30 
31 class KSTCORE_EXPORT DataSourcePluginManager
32 {
33   public:
34 
35     static const QMap<QString, QString> urlMap();
36 
37     static void init();
38     static void cleanupForExit();
39     static void initPlugins();
40 
41     /** Returns a list of plugins found on the system. */
42     static QStringList pluginList();
43 
44     static QString pluginFileName(const QString& pluginName);
45 
46     static SharedPtr<DataSource> loadSource(ObjectStore *store, const QString& filename, const QString& type = QString());
47     //static SharedPtr<DataSource> loadSource(ObjectStore *store, QDomElement& e, bool updatesDisabled = false);
48     static SharedPtr<DataSource> findOrLoadSource(ObjectStore *store, const QString& filename, bool updatesDisabled = false);
49     static bool validSource(const QString& filename);
50 
51     static bool sourceHasConfigWidget(const QString& filename, const QString& type = QString());
52     static DataSourceConfigWidget *configWidgetForSource(const QString& filename, const QString& type = QString());
53 
54     static bool pluginHasConfigWidget(const QString& plugin);
55     static DataSourceConfigWidget *configWidgetForPlugin(const QString& plugin);
56 
57     //static QStringList matrixListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
58     static QStringList scalarListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
59     static QStringList stringListForSource(const QString& filename, const QString& type = QString(), QString *outType = 0L, bool *complete = 0L);
60     static QSettings& settingsObject();
61 
62 
63   private:
64     static QMap<QString,QString> url_map;
65     static QString obtainFile(const QString& source);
66 
67     struct PluginSortContainer {
68       SharedPtr<DataSourcePluginInterface> plugin;
69       int match;
70       int operator<(const PluginSortContainer& x) const;
71       int operator==(const PluginSortContainer& x) const;
72     };
73     static QList<PluginSortContainer> bestPluginsForSource(const QString& filename, const QString& type);
74     static DataSourcePtr findPluginFor(ObjectStore *store, const QString& filename, const QString& type, const QDomElement& e = QDomElement());
75 };
76 
77 }
78 
79 
80 #endif
81