diff --git a/CMakeLists.txt b/CMakeLists.txt index 13e388609..b687b236e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -218,7 +218,6 @@ set(APP_HEADERS # QtSingleApplication suite headers. src/qtsingleapplication/qtlocalpeer.h - src/qtsingleapplication/qtlockedfile.h src/qtsingleapplication/qtsingleapplication.h # GUI headers. @@ -277,7 +276,7 @@ set(APP_TRANSLATIONS_WO_QT localization/rssguard_cs.ts ) -set(APP_MISC +set(APP_TEXT resources/text/CHANGELOG resources/text/COPYING_GNU_GPL resources/text/COPYING_GNU_GPL_HTML @@ -379,6 +378,8 @@ if(WIN32) DESTINATION ./) install(DIRECTORY resources/skins/base DESTINATION ./skins) + install(DIRECTORY resources/misc + DESTINATION ./) install(FILES resources/graphics/${APP_LOW_NAME}_128.png DESTINATION ./ RENAME ${APP_LOW_NAME}.png) @@ -387,7 +388,7 @@ if(WIN32) RENAME ${APP_LOW_NAME}_plain.png) install(FILES ${APP_QM} DESTINATION ./l10n) - install(FILES ${APP_MISC} + install(FILES ${APP_TEXT} DESTINATION ./) elseif(UNIX) message(STATUS "[${APP_LOW_NAME}] You will probably install on Linux.") @@ -399,6 +400,8 @@ elseif(UNIX) DESTINATION share/${APP_LOW_NAME}/) install(DIRECTORY resources/skins/base DESTINATION share/${APP_LOW_NAME}/skins) + install(DIRECTORY resources/misc + DESTINATION share/${APP_LOW_NAME}/) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/${APP_LOW_NAME}.desktop DESTINATION share/applications) install(FILES resources/graphics/${APP_LOW_NAME}_128.png @@ -409,7 +412,7 @@ elseif(UNIX) RENAME ${APP_LOW_NAME}_plain.png) install(FILES ${APP_QM} DESTINATION share/${APP_LOW_NAME}/l10n) - install(FILES ${APP_MISC} + install(FILES ${APP_TEXT} DESTINATION share/${APP_LOW_NAME}/information) endif(WIN32) diff --git a/resources/misc/db_init.sql b/resources/misc/db_init.sql new file mode 100644 index 000000000..2e21266fe --- /dev/null +++ b/resources/misc/db_init.sql @@ -0,0 +1,17 @@ +DROP TABLE IF EXISTS Information; +-- ! +CREATE TABLE IF NOT EXISTS Information ( + key TEXT PRIMARY KEY, + value TEXT NOT NULL +); +-- ! +INSERT INTO Information VALUES ('schema_version', '0.0.1'); +-- ! +DROP TABLE IF EXISTS Categories; +-- ! +CREATE TABLE IF NOT EXISTS Categories ( + id INTEGER PRIMARY KEY, + title TEXT NOT NULL UNIQUE CHECK(title != ''), + description TEXT + icon BLOB +); \ No newline at end of file diff --git a/src/core/databasefactory.cpp b/src/core/databasefactory.cpp index 426db45e2..6d22270c9 100644 --- a/src/core/databasefactory.cpp +++ b/src/core/databasefactory.cpp @@ -27,20 +27,8 @@ DatabaseFactory *DatabaseFactory::getInstance() { } void DatabaseFactory::assemblyDatabaseFilePath() { - // 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; - } + m_databasePath = QDir::homePath() + QDir::separator() + APP_LOW_H_NAME + + QDir::separator() + APP_DB_PATH; } QString DatabaseFactory::getDatabasePath() { @@ -50,7 +38,7 @@ QString DatabaseFactory::getDatabasePath() { QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { // Prepare file paths. QDir db_path(getDatabasePath()); - QFile db_file(db_path.absoluteFilePath("database.db")); + QFile db_file(db_path.absoluteFilePath(APP_DB_FILE)); // Check if database directory exists. if (!db_path.exists()) { @@ -67,18 +55,18 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { connection_name); // Setup database file path. - database.setDatabaseName(db_file.symLinkTarget()); + database.setDatabaseName(db_file.fileName()); if (!database.open()) { qFatal("Database was NOT opened. Delivered error message: '%s'", qPrintable(database.lastError().text())); } else { + database.exec("PRAGMA encoding = \"UTF-8\""); database.exec("PRAGMA synchronous = OFF"); database.exec("PRAGMA journal_mode = MEMORY"); database.exec("PRAGMA count_changes = OFF"); database.exec("PRAGMA temp_store = MEMORY"); - //database.exec("PRAGMA foreign_keys = ON"); // Sample query which checks for existence of tables. QSqlQuery q = database.exec("SELECT value FROM Information WHERE key = 'schema_version'"); @@ -86,11 +74,11 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { if (q.lastError().isValid()) { qWarning("Error occurred. Database is not initialized. Initializing now."); - QFile file_init(":/database/init.sql"); + QFile file_init(APP_MISC_PATH + QDir::separator() + APP_DB_INIT_FILE); file_init.open(QIODevice::ReadOnly | QIODevice::Text); - QStringList statements = QString(file_init.readAll()).split("-- !\n");//--\n"); - database.exec("begin transaction"); + QStringList statements = QString(file_init.readAll()).split(APP_DB_INIT_SPLIT); + database.exec("BEGIN TRANSACTION"); foreach(QString i, statements) { q = database.exec(i); @@ -101,15 +89,15 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) { } } - database.exec("commit"); + database.exec("COMMIT"); qWarning("Database backend should be ready now."); } else { q.next(); - qDebug("Database connection '%s' to file %s seems to be loaded.", + qDebug("Database connection '%s' to file '%s' seems to be established.", qPrintable(connection_name), qPrintable(QDir::toNativeSeparators(database.databaseName()))); - qDebug("Database has version %s.", qPrintable(q.value(0).toString())); + qDebug("Database has version '%s'.", qPrintable(q.value(0).toString())); } q.finish(); } diff --git a/src/core/defs.h.in b/src/core/defs.h.in index 4bc086293..9cf333d3e 100644 --- a/src/core/defs.h.in +++ b/src/core/defs.h.in @@ -30,6 +30,8 @@ #define MAX_ZOOM_FACTOR 10.0 #define DATABASE_DRIVER "QSQLITE" +#define APP_DB_INIT_FILE "db_init.sql" +#define APP_DB_INIT_SPLIT "-- !\n" #define APP_DB_PATH "data/database/local" #define APP_DB_FILE "database.db" @@ -55,6 +57,7 @@ #define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins") #define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information") #define APP_THEME_PATH APP_PREFIX + QString("/share/rssguard/themes") +#define APP_MISC_PATH APP_PREFIX + QString("/share/rssguard/misc") #define APP_HTML_PATH APP_PREFIX + QString("/share/rssguard/html") #define APP_THEME_SYSTEM QString() #define APP_FLAGS_PATH APP_PREFIX + QString("/share/rssguard/flags") @@ -65,6 +68,7 @@ #define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins") #define APP_INFO_PATH QApplication::applicationDirPath() #define APP_THEME_PATH QApplication::applicationDirPath() + QString("/themes") +#define APP_MISC_PATH QApplication::applicationDirPath() + QString("/misc") #define APP_HTML_PATH QApplication::applicationDirPath() + QString("/html") #define APP_THEME_SYSTEM "-" #define APP_FLAGS_PATH QApplication::applicationDirPath() + QString("/flags") diff --git a/src/main.cpp b/src/main.cpp index 484b7cb1d..4b46622c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,6 +5,7 @@ #include +#include "core/databasefactory.h" #include "core/defs.h" #include "core/debugging.h" #include "core/localization.h" @@ -73,6 +74,8 @@ int main(int argc, char *argv[]) { IconThemeFactory::getInstance()->loadCurrentIconTheme(false); SkinFactory::getInstance()->loadCurrentSkin(); + DatabaseFactory::getInstance()->addConnection("abc"); + // Load localization and setup locale before any widget is constructed. LoadLocalization();