You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1000 B
C++
52 lines
1000 B
C++
9 years ago
|
#include <QDir>
|
||
|
#include <QApplication>
|
||
|
#include <QPluginLoader>
|
||
|
|
||
|
#include "context.h"
|
||
|
#include "iplugin.h"
|
||
|
|
||
|
#include <odb/sqlite/database.hxx>
|
||
|
|
||
|
Context &Context::instance()
|
||
|
{
|
||
|
static Context ctx;
|
||
|
return ctx;
|
||
|
}
|
||
|
|
||
|
QList<IPlugin *> Context::plugins()
|
||
|
{
|
||
|
return m_plugins;
|
||
|
}
|
||
|
|
||
|
void Context::loadPlugins()
|
||
|
{
|
||
|
QDir pluginsDir(qApp->applicationDirPath() + "/../plugins");
|
||
|
|
||
|
foreach (QString fileName, pluginsDir.entryList(QStringList() << "*.so")) {
|
||
|
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
||
|
QObject *p = pluginLoader.instance();
|
||
|
|
||
|
if (p != NULL) {
|
||
|
IPlugin *plugin = qobject_cast<IPlugin*>(p);
|
||
|
if (plugin != NULL) {
|
||
|
plugin->init();
|
||
|
m_plugins.append(plugin);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Context::openDb(const QString &path)
|
||
|
{
|
||
|
if (m_db != NULL) {
|
||
|
delete m_db;
|
||
|
}
|
||
|
|
||
|
m_db = new odb::sqlite::database(path.toStdString());
|
||
|
}
|
||
|
|
||
|
Context::Context()
|
||
|
{
|
||
|
m_db = NULL;
|
||
|
}
|