diff --git a/resources/text/CHANGELOG b/resources/text/CHANGELOG
index 39824a7c3..ea257a5c0 100644
--- a/resources/text/CHANGELOG
+++ b/resources/text/CHANGELOG
@@ -3,11 +3,12 @@
Fixed:
-- Fixed #76, #75, #82, #79, #85.
+- Fixed #76, #75, #82, #79, #85 #78
Added:
+- Settings/database can now experimentally be exported/imported.
- Added Swedish localization (thanks to Åke Engelbrektson).
diff --git a/src/definitions/definitions.h.in b/src/definitions/definitions.h.in
index 10fd5e483..cf1abcb89 100755
--- a/src/definitions/definitions.h.in
+++ b/src/definitions/definitions.h.in
@@ -75,7 +75,9 @@
#define FEEDS_VIEW_INDENTATION 10
#define ACCEPT_HEADER_FOR_FEED_DOWNLOADER "application/atom+xml,application/xml;q=0.9,text/xml;q=0.8,*/*;q=0.7"
+#define BACKUP_NAME_SETTINGS "config"
#define BACKUP_SUFFIX_SETTINGS ".ini.backup"
+#define BACKUP_NAME_DATABASE "database"
#define BACKUP_SUFFIX_DATABASE ".db.backup"
#define APP_DB_MYSQL_DRIVER "QMYSQL"
diff --git a/src/gui/formrestoredatabasesettings.cpp b/src/gui/formrestoredatabasesettings.cpp
index e87d968b3..7c8f3916c 100644
--- a/src/gui/formrestoredatabasesettings.cpp
+++ b/src/gui/formrestoredatabasesettings.cpp
@@ -17,6 +17,8 @@
#include "gui/formrestoredatabasesettings.h"
+#include "gui/messagebox.h"
+#include "gui/formmain.h"
#include "miscellaneous/iconfactory.h"
#include "QFileDialog"
@@ -26,11 +28,13 @@ FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget *parent)
: QDialog(parent), m_ui(new Ui::FormRestoreDatabaseSettings) {
m_ui->setupUi(this);
+ m_btnRestart = m_ui->m_buttonBox->addButton(tr("Restart"), QDialogButtonBox::ApplyRole);
+ m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
+
setWindowIcon(qApp->icons()->fromTheme("document-import"));
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
- m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
-
+ connect(m_btnRestart, SIGNAL(clicked()), qApp, SLOT(restart()));
connect(m_ui->m_btnSelectFolder, SIGNAL(clicked()), this, SLOT(selectFolder()));
connect(m_ui->m_groupDatabase, SIGNAL(toggled(bool)), this, SLOT(checkOkButton()));
connect(m_ui->m_groupSettings, SIGNAL(toggled(bool)), this, SLOT(checkOkButton()));
@@ -44,10 +48,28 @@ FormRestoreDatabaseSettings::~FormRestoreDatabaseSettings() {
}
void FormRestoreDatabaseSettings::performRestoration() {
- // TODO: Pokračovat
+ m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
+
+ if (qApp->restoreDatabaseSettings(m_ui->m_groupDatabase->isChecked(),
+ m_ui->m_groupSettings->isChecked(),
+ m_ui->m_listDatabase->currentRow() >= 0 ?
+ m_ui->m_listDatabase->currentItem()->data(Qt::UserRole).toString() :
+ QString(),
+ m_ui->m_listSettings->currentRow() >= 0 ?
+ m_ui->m_listSettings->currentItem()->data(Qt::UserRole).toString() :
+ QString())) {
+ m_btnRestart->setEnabled(true);
+ m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, tr("Restoration was initiated. Restart to proceed."),
+ tr("You need to restart application for restoration process to finish."));
+ }
+ else {
+ m_ui->m_lblResult->setStatus(WidgetWithStatus::Error, tr("Restoration was not initiated successfully."),
+ tr("Database and/or settings were not copied to restoration folder successully."));
+ }
}
void FormRestoreDatabaseSettings::checkOkButton() {
+ m_btnRestart->setEnabled(false);
m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_ui->m_lblSelectFolder->label()->text().isEmpty() &&
((m_ui->m_groupDatabase->isChecked() &&
m_ui->m_listDatabase->currentRow() >= 0) ||
diff --git a/src/gui/formrestoredatabasesettings.h b/src/gui/formrestoredatabasesettings.h
index b7f6048b3..a5710a338 100644
--- a/src/gui/formrestoredatabasesettings.h
+++ b/src/gui/formrestoredatabasesettings.h
@@ -42,6 +42,7 @@ class FormRestoreDatabaseSettings : public QDialog {
private:
Ui::FormRestoreDatabaseSettings *m_ui;
+ QPushButton *m_btnRestart;
};
#endif // FORMRESTOREDATABASESETTINGS_H
diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp
index ff582f5d3..853d33a56 100755
--- a/src/miscellaneous/application.cpp
+++ b/src/miscellaneous/application.cpp
@@ -85,6 +85,21 @@ bool Application::backupDatabaseSettings(bool backup_database, bool backup_setti
return final_result;
}
+bool Application::restoreDatabaseSettings(bool restore_database, bool restore_settings,
+ const QString &source_database_file_path, const QString &source_settings_file_path) {
+ bool result = true;
+
+ if (restore_database) {
+ result &= qApp->database()->initiateRestoration(source_database_file_path);
+ }
+
+ if (restore_settings) {
+ result &= qApp->settings()->initiateRestoration(source_settings_file_path);
+ }
+
+ return result;
+}
+
void Application::processExecutionMessage(const QString &message) {
qDebug("Received '%s' execution message from another application instance.", qPrintable(message));
diff --git a/src/miscellaneous/application.h b/src/miscellaneous/application.h
index 35e92e2be..3cc6786c0 100755
--- a/src/miscellaneous/application.h
+++ b/src/miscellaneous/application.h
@@ -146,6 +146,9 @@ class Application : public QtSingleApplication {
}
bool backupDatabaseSettings(bool backup_database, bool backup_settings, const QString &target_path, const QString &backup_name);
+ bool restoreDatabaseSettings(bool restore_database, bool restore_settings,
+ const QString &source_database_file_path = QString(),
+ const QString &source_settings_file_path = QString());
// Access to application tray icon. Always use this in cooperation with
// SystemTrayIcon::isSystemTrayActivated().
diff --git a/src/miscellaneous/databasefactory.cpp b/src/miscellaneous/databasefactory.cpp
index 4a13fd596..b456edbdb 100755
--- a/src/miscellaneous/databasefactory.cpp
+++ b/src/miscellaneous/databasefactory.cpp
@@ -17,6 +17,7 @@
#include "miscellaneous/databasefactory.h"
+#include "miscellaneous/iofactory.h"
#include "miscellaneous/application.h"
#include
@@ -80,6 +81,41 @@ QString DatabaseFactory::mysqlInterpretErrorCode(MySQLError error_code) {
}
}
+bool DatabaseFactory::initiateRestoration(const QString &database_backup_file_path) {
+ switch (m_activeDatabaseDriver) {
+ case SQLITE:
+ case SQLITE_MEMORY:
+ return IOFactory::copyFile(database_backup_file_path,
+ m_sqliteDatabaseFilePath + QDir::separator() +
+ BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE);
+
+ default:
+ return false;
+ }
+}
+
+void DatabaseFactory::finishRestoration() {
+ // TODO: Finish restoration.
+ if (m_activeDatabaseDriver != SQLITE && m_activeDatabaseDriver != SQLITE_MEMORY) {
+ return;
+ }
+
+ QString backup_database_file = m_sqliteDatabaseFilePath + QDir::separator() + BACKUP_NAME_DATABASE + BACKUP_SUFFIX_DATABASE;
+
+ if (QFile::exists(backup_database_file)) {
+ qWarning("Backup database file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_database_file)));
+
+ if (IOFactory::copyFile(backup_database_file,
+ m_sqliteDatabaseFilePath + QDir::separator() + APP_DB_SQLITE_FILE)) {
+ QFile::remove(backup_database_file);
+ qDebug("Database file was restored successully.");
+ }
+ else {
+ qCritical("Database file was NOT restored due to error when copying the file.");
+ }
+ }
+}
+
void DatabaseFactory::sqliteAssemblyDatabaseFilePath() {
if (qApp->settings()->type() == Settings::Portable) {
m_sqliteDatabaseFilePath = qApp->applicationDirPath() + QDir::separator() + QString(APP_DB_SQLITE_PATH);
@@ -178,6 +214,8 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() {
}
QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &connection_name) {
+ finishRestoration();
+
// Prepare file paths.
QDir db_path(m_sqliteDatabaseFilePath);
QFile db_file(db_path.absoluteFilePath(APP_DB_SQLITE_FILE));
diff --git a/src/miscellaneous/databasefactory.h b/src/miscellaneous/databasefactory.h
index 60b02e95f..d5bd0b7ed 100755
--- a/src/miscellaneous/databasefactory.h
+++ b/src/miscellaneous/databasefactory.h
@@ -77,6 +77,11 @@ class DatabaseFactory : public QObject {
// Returns identification of currently active database driver.
UsedDriver activeDatabaseDriver() const;
+ // Copies selected backup database (file) to active database path.
+ bool initiateRestoration(const QString &database_backup_file_path);
+
+ void finishRestoration();
+
//
// SQLITE stuff.
//
diff --git a/src/miscellaneous/settings.cpp b/src/miscellaneous/settings.cpp
index dea44e4a6..1ebbb0a82 100755
--- a/src/miscellaneous/settings.cpp
+++ b/src/miscellaneous/settings.cpp
@@ -18,6 +18,7 @@
#include "miscellaneous/settings.h"
#include "miscellaneous/application.h"
+#include "miscellaneous/iofactory.h"
#include
#include
@@ -42,6 +43,29 @@ QSettings::Status Settings::checkSettings() {
return status();
}
+bool Settings::initiateRestoration(const QString &settings_backup_file_path) {
+ return IOFactory::copyFile(settings_backup_file_path,
+ QFileInfo(fileName()).absolutePath() + QDir::separator() +
+ BACKUP_NAME_SETTINGS + BACKUP_SUFFIX_SETTINGS);
+}
+
+void Settings::finishRestoration(const QString &desired_settings_file_path) {
+ QString backup_settings_file = QFileInfo(desired_settings_file_path).absolutePath() + QDir::separator() +
+ BACKUP_NAME_SETTINGS + BACKUP_SUFFIX_SETTINGS;
+
+ if (QFile::exists(backup_settings_file)) {
+ qWarning("Backup settings file '%s' was detected. Restoring it.", qPrintable(QDir::toNativeSeparators(backup_settings_file)));
+
+ if (IOFactory::copyFile(backup_settings_file, desired_settings_file_path)) {
+ QFile::remove(backup_settings_file);
+ qDebug("Settings file was restored successully.");
+ }
+ else {
+ qCritical("Settings file was NOT restored due to error when copying the file.");
+ }
+ }
+}
+
Settings *Settings::setupSettings(QObject *parent) {
Settings *new_settings;
@@ -63,6 +87,8 @@ Settings *Settings::setupSettings(QObject *parent) {
// Check if portable settings are available.
if (will_we_use_portable_settings) {
+ finishRestoration(app_path_file);
+
// Portable settings are available, use them.
new_settings = new Settings(app_path_file, QSettings::IniFormat, Settings::Portable, parent);
@@ -74,6 +100,8 @@ Settings *Settings::setupSettings(QObject *parent) {
qDebug("Initializing settings in '%s' (portable way).", qPrintable(QDir::toNativeSeparators(app_path_file)));
}
else {
+ finishRestoration(home_path_file);
+
// Portable settings are NOT available, store them in
// user's home directory.
new_settings = new Settings(home_path_file, QSettings::IniFormat, Settings::NonPortable, parent);
diff --git a/src/miscellaneous/settings.h b/src/miscellaneous/settings.h
index 6111a495e..12fef4141 100755
--- a/src/miscellaneous/settings.h
+++ b/src/miscellaneous/settings.h
@@ -53,12 +53,16 @@ class Settings : public QSettings {
// Synchronizes settings.
QSettings::Status checkSettings();
+ bool initiateRestoration(const QString &settings_backup_file_path);
+
+ static void finishRestoration(const QString &desired_settings_file_path);
+
// Creates settings file in correct location.
static Settings *setupSettings(QObject *parent);
private:
// Constructor.
- explicit Settings(const QString & file_name, Format format, const Type &type, QObject *parent = 0);
+ explicit Settings(const QString &file_name, Format format, const Type &type, QObject *parent = 0);
Type m_initializationStatus;
};