diff --git a/application/mainwindow.cpp b/application/mainwindow.cpp index 8b4c6fc..05adcbd 100644 --- a/application/mainwindow.cpp +++ b/application/mainwindow.cpp @@ -37,6 +37,7 @@ MainWindow::~MainWindow() void MainWindow::on_actionExit_triggered() { this->close(); + Context::instance().destroy(); } void MainWindow::openPlugin() diff --git a/core/context.cpp b/core/context.cpp index b03cdd0..2660622 100644 --- a/core/context.cpp +++ b/core/context.cpp @@ -55,21 +55,50 @@ void Context::loadPlugins() } } } + + QString dbPath = m_settings->value("db/path", "").toString(); + if (!dbPath.isEmpty()) + { + openDb(dbPath); + } } void Context::openDb(const QString &path) { if (m_db != NULL) { delete m_db; + m_dbOpened = false; } checkDb(path); m_db = new odb::sqlite::database(path.toStdString()); + m_settings->setValue("db/path", path); + m_dbOpened = true; +} + +void Context::destroy() +{ + if (m_db != NULL) + { + delete m_db; + m_db = NULL; + m_dbOpened = false; + } + + delete m_settings; + + foreach (IPlugin *plugin, m_plugins) + { + delete plugin; + } + m_plugins.clear(); } Context::Context() { m_db = NULL; + m_settings = new QSettings("itsolved.cz", "prodejna"); + m_dbOpened = false; } void Context::checkDb(const QString &path) diff --git a/core/context.h b/core/context.h index 2840708..993af5f 100644 --- a/core/context.h +++ b/core/context.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "define.h" #include "core_global.h" @@ -24,11 +25,16 @@ public: void loadPlugins(); void openDb(const QString &path); odb::database *db() { return m_db; } + QSettings *settings() { return m_settings; } + bool dbOpened() { return m_dbOpened; } + void destroy(); private: Context(); QList m_plugins; odb::database *m_db; + QSettings *m_settings; + bool m_dbOpened; QStringList m_solved;