diff --git a/src/core/databasefactory.cpp b/src/core/databasefactory.cpp index 4ff85d082..426db45e2 100644 --- a/src/core/databasefactory.cpp +++ b/src/core/databasefactory.cpp @@ -4,6 +4,7 @@ #include #include +#include "core/defs.h" #include "core/databasefactory.h" @@ -26,7 +27,20 @@ DatabaseFactory *DatabaseFactory::getInstance() { } void DatabaseFactory::assemblyDatabaseFilePath() { - // TODO: Fill m_databasePath with correct path (portable or non-portable). + // Fill m_databasePath with correct path (portable or non-portable). + QString home_path = QDir::homePath() + QDir::separator() + + APP_LOW_H_NAME; + QString home_path_file = home_path + QDir::separator() + + APP_DB_PATH + QDir::separator() + APP_DB_FILE; + QString app_path = qApp->applicationDirPath(); + QString app_path_file = app_path + QDir::separator() + APP_DB_FILE; + + if (QFile(app_path_file).exists()) { + m_databasePath = app_path_file; + } + else { + m_databasePath = home_path_file; + } } QString DatabaseFactory::getDatabasePath() { @@ -49,14 +63,15 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { } // Folders are created. Create new QSQLDatabase object. - QSqlDatabase database = QSqlDatabase::addDatabase("QSQLITE", connection_name); + QSqlDatabase database = QSqlDatabase::addDatabase(DATABASE_DRIVER, + connection_name); // Setup database file path. database.setDatabaseName(db_file.symLinkTarget()); if (!database.open()) { qFatal("Database was NOT opened. Delivered error message: '%s'", - qPrintable(database.lastError().databaseText())); + qPrintable(database.lastError().text())); } else { database.exec("PRAGMA synchronous = OFF"); @@ -65,7 +80,8 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { database.exec("PRAGMA temp_store = MEMORY"); //database.exec("PRAGMA foreign_keys = ON"); - QSqlQuery q = database.exec("SELECT value FROM rssg_information WHERE key = 'schema_version'"); + // Sample query which checks for existence of tables. + QSqlQuery q = database.exec("SELECT value FROM Information WHERE key = 'schema_version'"); if (q.lastError().isValid()) { qWarning("Error occurred. Database is not initialized. Initializing now."); @@ -102,13 +118,13 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { } QSqlDatabase DatabaseFactory::addConnection(const QString &connection_name) { - QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", connection_name); - if (!m_initialized) { + // Initialize database file and return connection if it is not + // initialized yet. return initialize(connection_name); } else { - return QSqlDatabase::addDatabase("QSQLITE", connection_name); + return QSqlDatabase::addDatabase(DATABASE_DRIVER, connection_name); } } diff --git a/src/core/defs.h.in b/src/core/defs.h.in index 13598b4fc..4bc086293 100644 --- a/src/core/defs.h.in +++ b/src/core/defs.h.in @@ -27,9 +27,14 @@ #endif #define TEXT_TITLE_LIMIT 30 +#define MAX_ZOOM_FACTOR 10.0 +#define DATABASE_DRIVER "QSQLITE" + +#define APP_DB_PATH "data/database/local" +#define APP_DB_FILE "database.db" #define APP_CFG_PATH "data/config" -#define APP_CFG_WEB_PATH "data/web" +#define APP_CFG_WEB_PATH "data/database/web" #define APP_CFG_FILE "config.ini" #define APP_CFG_GUI "gui" #define APP_CFG_GEN "main" @@ -38,7 +43,6 @@ #define APP_CFG_BROWSER "browser" #define APP_HTML_MARKUP "styled_pattern.html" -#define APP_DB_PATH "data/storage/database.db" #define APP_PREFIX "@CMAKE_INSTALL_PREFIX@" #define APP_REVISION "@APP_REVISION@" diff --git a/src/gui/basewebview.cpp b/src/gui/basewebview.cpp index 06a097d4d..f0e99ff1a 100644 --- a/src/gui/basewebview.cpp +++ b/src/gui/basewebview.cpp @@ -226,14 +226,38 @@ void BaseWebView::paintEvent(QPaintEvent *event) { style()->drawControl(QStyle::CE_ShapedFrame, &style_option, &painter, this); } -void BaseWebView::increaseWebPageZoom() { - setZoomFactor(zoomFactor() + 0.1); +bool BaseWebView::increaseWebPageZoom() { + qreal new_factor = zoomFactor() + 0.1; + + if (new_factor >= 0.0 && new_factor <= MAX_ZOOM_FACTOR) { + setZoomFactor(new_factor); + return true; + } + else { + return false; + } } -void BaseWebView::decreaseWebPageZoom() { - setZoomFactor(zoomFactor() - 0.1); +bool BaseWebView::decreaseWebPageZoom() { + qreal new_factor = zoomFactor() - 0.1; + + if (new_factor >= 0.0 && new_factor <= MAX_ZOOM_FACTOR) { + setZoomFactor(new_factor); + return true; + } + else { + return false; + } } -void BaseWebView::resetWebPageZoom() { - setZoomFactor(1.0); +bool BaseWebView::resetWebPageZoom() { + qreal new_factor = 1.0; + + if (new_factor != zoomFactor()) { + setZoomFactor(new_factor); + return true; + } + else { + return false; + } } diff --git a/src/gui/basewebview.h b/src/gui/basewebview.h index 561c8d118..b2bb1cab1 100644 --- a/src/gui/basewebview.h +++ b/src/gui/basewebview.h @@ -27,9 +27,9 @@ class BaseWebView : public QWebView { void newTabRequested(); public slots: - void increaseWebPageZoom(); - void decreaseWebPageZoom(); - void resetWebPageZoom(); + bool increaseWebPageZoom(); + bool decreaseWebPageZoom(); + bool resetWebPageZoom(); protected slots: // Executes if loading of any page is done. diff --git a/src/gui/formmain.ui b/src/gui/formmain.ui index 637e5267a..c9aebd148 100644 --- a/src/gui/formmain.ui +++ b/src/gui/formmain.ui @@ -15,6 +15,18 @@ + + 0 + + + 0 + + + 0 + + + 0 + diff --git a/src/gui/tabbar.cpp b/src/gui/tabbar.cpp index e86a03cbb..d5ab62ac6 100644 --- a/src/gui/tabbar.cpp +++ b/src/gui/tabbar.cpp @@ -12,6 +12,7 @@ TabBar::TabBar(QWidget *parent) : QTabBar(parent) { } TabBar::~TabBar() { + qDebug("Destroying TabBar instance."); } void TabBar::setTabType(int index, const TabBar::TabType &type) {