Statistics
| Branch: | Revision:

gazetk / GazeTkHub / GazeTkLib / src / pluginloader.cpp @ 2eb54f9d

History | View | Annotate | Download (1.686 KB)

1
#include "pluginloader.h"
2

    
3
#include <QDebug>
4
#include <QDir>
5
#include <QPluginLoader>
6
#include <QApplication>
7

    
8
#include "gazetkinterfaces.h"
9

    
10
namespace gazetk
11
{
12

    
13
PluginLoader* PluginLoader::_instance = 0;
14

    
15
PluginLoader* PluginLoader::instance()
16
{
17
    if( _instance == 0 )
18
        _instance = new PluginLoader();
19

    
20
    return _instance;
21
}
22

    
23

    
24
PluginLoader::PluginLoader()
25
{
26

    
27
}
28

    
29
void PluginLoader::loadPlugins()
30
{
31
    qDebug() << "Loading available plugins...";
32
    // Handling plugins that are statically linked
33
    foreach (QObject *plugin, QPluginLoader::staticInstances())
34
        handlePlugin(plugin);
35

    
36
    // Handling dynamic plugins
37
    QDir pluginsDir = QDir(qApp->applicationDirPath());
38

    
39
#if defined(Q_OS_WIN)
40
    //if (pluginsDir.dirName().toLower() == "debug" || pluginsDir.dirName().toLower() == "release")
41
    //    pluginsDir.cdUp();
42
#elif defined(Q_OS_MAC)
43
    if (pluginsDir.dirName() == "MacOS") {
44
        pluginsDir.cdUp();
45
        pluginsDir.cdUp();
46
        pluginsDir.cdUp();
47
    }
48
#endif
49
    pluginsDir.cd("plugins");
50

    
51
    qDebug() << "   from directory " << pluginsDir.absolutePath();
52

    
53
    foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
54
            QPluginLoader loader(pluginsDir.absoluteFilePath(fileName));
55
            QObject *plugin = loader.instance();
56
            if (plugin) {
57
                handlePlugin(plugin);
58
                pluginFileNames += fileName;
59
                qDebug() << "    adding plugin: " << fileName;
60
            }
61
        }
62
}
63

    
64

    
65

    
66
void PluginLoader::handlePlugin(QObject *plugin)
67
{
68
    gazetk::PluginInterface *iPlugin = qobject_cast<gazetk::PluginInterface *>(plugin);
69
    if (iPlugin) // Found a plugin...
70
        return;
71
    return;
72
}
73

    
74

    
75

    
76
} // namespace gazetk