|
|
|
#include <QDir>
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QPluginLoader>
|
|
|
|
|
|
|
|
#include <odb/sqlite/database.hxx>
|
|
|
|
|
|
|
|
#include "core.h"
|
|
|
|
|
|
|
|
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" << "*.dll")) {
|
|
|
|
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
|
|
|
|
QObject *p = pluginLoader.instance();
|
|
|
|
|
|
|
|
if (p != NULL) {
|
|
|
|
IPlugin *plugin = qobject_cast<IPlugin*>(p);
|
|
|
|
if (plugin != NULL) {
|
|
|
|
plugin->init(pluginLoader.metaData());
|
|
|
|
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;
|
|
|
|
m_inTransaction = false;
|
|
|
|
}
|