Work in db backend.
This commit is contained in:
parent
202e5ab5c5
commit
fbf2d0912f
@ -218,7 +218,6 @@ set(APP_HEADERS
|
|||||||
|
|
||||||
# QtSingleApplication suite headers.
|
# QtSingleApplication suite headers.
|
||||||
src/qtsingleapplication/qtlocalpeer.h
|
src/qtsingleapplication/qtlocalpeer.h
|
||||||
src/qtsingleapplication/qtlockedfile.h
|
|
||||||
src/qtsingleapplication/qtsingleapplication.h
|
src/qtsingleapplication/qtsingleapplication.h
|
||||||
|
|
||||||
# GUI headers.
|
# GUI headers.
|
||||||
@ -277,7 +276,7 @@ set(APP_TRANSLATIONS_WO_QT
|
|||||||
localization/rssguard_cs.ts
|
localization/rssguard_cs.ts
|
||||||
)
|
)
|
||||||
|
|
||||||
set(APP_MISC
|
set(APP_TEXT
|
||||||
resources/text/CHANGELOG
|
resources/text/CHANGELOG
|
||||||
resources/text/COPYING_GNU_GPL
|
resources/text/COPYING_GNU_GPL
|
||||||
resources/text/COPYING_GNU_GPL_HTML
|
resources/text/COPYING_GNU_GPL_HTML
|
||||||
@ -379,6 +378,8 @@ if(WIN32)
|
|||||||
DESTINATION ./)
|
DESTINATION ./)
|
||||||
install(DIRECTORY resources/skins/base
|
install(DIRECTORY resources/skins/base
|
||||||
DESTINATION ./skins)
|
DESTINATION ./skins)
|
||||||
|
install(DIRECTORY resources/misc
|
||||||
|
DESTINATION ./)
|
||||||
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
||||||
DESTINATION ./
|
DESTINATION ./
|
||||||
RENAME ${APP_LOW_NAME}.png)
|
RENAME ${APP_LOW_NAME}.png)
|
||||||
@ -387,7 +388,7 @@ if(WIN32)
|
|||||||
RENAME ${APP_LOW_NAME}_plain.png)
|
RENAME ${APP_LOW_NAME}_plain.png)
|
||||||
install(FILES ${APP_QM}
|
install(FILES ${APP_QM}
|
||||||
DESTINATION ./l10n)
|
DESTINATION ./l10n)
|
||||||
install(FILES ${APP_MISC}
|
install(FILES ${APP_TEXT}
|
||||||
DESTINATION ./)
|
DESTINATION ./)
|
||||||
elseif(UNIX)
|
elseif(UNIX)
|
||||||
message(STATUS "[${APP_LOW_NAME}] You will probably install on Linux.")
|
message(STATUS "[${APP_LOW_NAME}] You will probably install on Linux.")
|
||||||
@ -399,6 +400,8 @@ elseif(UNIX)
|
|||||||
DESTINATION share/${APP_LOW_NAME}/)
|
DESTINATION share/${APP_LOW_NAME}/)
|
||||||
install(DIRECTORY resources/skins/base
|
install(DIRECTORY resources/skins/base
|
||||||
DESTINATION share/${APP_LOW_NAME}/skins)
|
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
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/${APP_LOW_NAME}.desktop
|
||||||
DESTINATION share/applications)
|
DESTINATION share/applications)
|
||||||
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
install(FILES resources/graphics/${APP_LOW_NAME}_128.png
|
||||||
@ -409,7 +412,7 @@ elseif(UNIX)
|
|||||||
RENAME ${APP_LOW_NAME}_plain.png)
|
RENAME ${APP_LOW_NAME}_plain.png)
|
||||||
install(FILES ${APP_QM}
|
install(FILES ${APP_QM}
|
||||||
DESTINATION share/${APP_LOW_NAME}/l10n)
|
DESTINATION share/${APP_LOW_NAME}/l10n)
|
||||||
install(FILES ${APP_MISC}
|
install(FILES ${APP_TEXT}
|
||||||
DESTINATION share/${APP_LOW_NAME}/information)
|
DESTINATION share/${APP_LOW_NAME}/information)
|
||||||
endif(WIN32)
|
endif(WIN32)
|
||||||
|
|
||||||
|
17
resources/misc/db_init.sql
Normal file
17
resources/misc/db_init.sql
Normal file
@ -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
|
||||||
|
);
|
@ -27,20 +27,8 @@ DatabaseFactory *DatabaseFactory::getInstance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DatabaseFactory::assemblyDatabaseFilePath() {
|
void DatabaseFactory::assemblyDatabaseFilePath() {
|
||||||
// Fill m_databasePath with correct path (portable or non-portable).
|
m_databasePath = QDir::homePath() + QDir::separator() + APP_LOW_H_NAME +
|
||||||
QString home_path = QDir::homePath() + QDir::separator() +
|
QDir::separator() + APP_DB_PATH;
|
||||||
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() {
|
QString DatabaseFactory::getDatabasePath() {
|
||||||
@ -50,7 +38,7 @@ QString DatabaseFactory::getDatabasePath() {
|
|||||||
QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
||||||
// Prepare file paths.
|
// Prepare file paths.
|
||||||
QDir db_path(getDatabasePath());
|
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.
|
// Check if database directory exists.
|
||||||
if (!db_path.exists()) {
|
if (!db_path.exists()) {
|
||||||
@ -67,18 +55,18 @@ QSqlDatabase DatabaseFactory::initialize(const QString &connection_name) {
|
|||||||
connection_name);
|
connection_name);
|
||||||
|
|
||||||
// Setup database file path.
|
// Setup database file path.
|
||||||
database.setDatabaseName(db_file.symLinkTarget());
|
database.setDatabaseName(db_file.fileName());
|
||||||
|
|
||||||
if (!database.open()) {
|
if (!database.open()) {
|
||||||
qFatal("Database was NOT opened. Delivered error message: '%s'",
|
qFatal("Database was NOT opened. Delivered error message: '%s'",
|
||||||
qPrintable(database.lastError().text()));
|
qPrintable(database.lastError().text()));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
database.exec("PRAGMA encoding = \"UTF-8\"");
|
||||||
database.exec("PRAGMA synchronous = OFF");
|
database.exec("PRAGMA synchronous = OFF");
|
||||||
database.exec("PRAGMA journal_mode = MEMORY");
|
database.exec("PRAGMA journal_mode = MEMORY");
|
||||||
database.exec("PRAGMA count_changes = OFF");
|
database.exec("PRAGMA count_changes = OFF");
|
||||||
database.exec("PRAGMA temp_store = MEMORY");
|
database.exec("PRAGMA temp_store = MEMORY");
|
||||||
//database.exec("PRAGMA foreign_keys = ON");
|
|
||||||
|
|
||||||
// Sample query which checks for existence of tables.
|
// Sample query which checks for existence of tables.
|
||||||
QSqlQuery q = database.exec("SELECT value FROM Information WHERE key = 'schema_version'");
|
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()) {
|
if (q.lastError().isValid()) {
|
||||||
qWarning("Error occurred. Database is not initialized. Initializing now.");
|
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);
|
file_init.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||||
|
|
||||||
QStringList statements = QString(file_init.readAll()).split("-- !\n");//--\n");
|
QStringList statements = QString(file_init.readAll()).split(APP_DB_INIT_SPLIT);
|
||||||
database.exec("begin transaction");
|
database.exec("BEGIN TRANSACTION");
|
||||||
|
|
||||||
foreach(QString i, statements) {
|
foreach(QString i, statements) {
|
||||||
q = database.exec(i);
|
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.");
|
qWarning("Database backend should be ready now.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
q.next();
|
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(connection_name),
|
||||||
qPrintable(QDir::toNativeSeparators(database.databaseName())));
|
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();
|
q.finish();
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,8 @@
|
|||||||
#define MAX_ZOOM_FACTOR 10.0
|
#define MAX_ZOOM_FACTOR 10.0
|
||||||
#define DATABASE_DRIVER "QSQLITE"
|
#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_PATH "data/database/local"
|
||||||
#define APP_DB_FILE "database.db"
|
#define APP_DB_FILE "database.db"
|
||||||
|
|
||||||
@ -55,6 +57,7 @@
|
|||||||
#define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins")
|
#define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins")
|
||||||
#define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information")
|
#define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information")
|
||||||
#define APP_THEME_PATH APP_PREFIX + QString("/share/rssguard/themes")
|
#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_HTML_PATH APP_PREFIX + QString("/share/rssguard/html")
|
||||||
#define APP_THEME_SYSTEM QString()
|
#define APP_THEME_SYSTEM QString()
|
||||||
#define APP_FLAGS_PATH APP_PREFIX + QString("/share/rssguard/flags")
|
#define APP_FLAGS_PATH APP_PREFIX + QString("/share/rssguard/flags")
|
||||||
@ -65,6 +68,7 @@
|
|||||||
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins")
|
#define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins")
|
||||||
#define APP_INFO_PATH QApplication::applicationDirPath()
|
#define APP_INFO_PATH QApplication::applicationDirPath()
|
||||||
#define APP_THEME_PATH QApplication::applicationDirPath() + QString("/themes")
|
#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_HTML_PATH QApplication::applicationDirPath() + QString("/html")
|
||||||
#define APP_THEME_SYSTEM "-"
|
#define APP_THEME_SYSTEM "-"
|
||||||
#define APP_FLAGS_PATH QApplication::applicationDirPath() + QString("/flags")
|
#define APP_FLAGS_PATH QApplication::applicationDirPath() + QString("/flags")
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <QTranslator>
|
#include <QTranslator>
|
||||||
|
|
||||||
|
#include "core/databasefactory.h"
|
||||||
#include "core/defs.h"
|
#include "core/defs.h"
|
||||||
#include "core/debugging.h"
|
#include "core/debugging.h"
|
||||||
#include "core/localization.h"
|
#include "core/localization.h"
|
||||||
@ -73,6 +74,8 @@ int main(int argc, char *argv[]) {
|
|||||||
IconThemeFactory::getInstance()->loadCurrentIconTheme(false);
|
IconThemeFactory::getInstance()->loadCurrentIconTheme(false);
|
||||||
SkinFactory::getInstance()->loadCurrentSkin();
|
SkinFactory::getInstance()->loadCurrentSkin();
|
||||||
|
|
||||||
|
DatabaseFactory::getInstance()->addConnection("abc");
|
||||||
|
|
||||||
// Load localization and setup locale before any widget is constructed.
|
// Load localization and setup locale before any widget is constructed.
|
||||||
LoadLocalization();
|
LoadLocalization();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user