From 0fbedb384c704f677c3dc30ee452ffa1785ac3ff Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Thu, 9 Oct 2014 16:49:19 +0200 Subject: [PATCH] Work on exporting settings/db. --- CMakeLists.txt | 3 + src/gui/formbackupdatabasesettings.cpp | 63 +++++++++ src/gui/formbackupdatabasesettings.h | 47 +++++++ src/gui/formbackupdatabasesettings.ui | 176 +++++++++++++++++++++++++ src/gui/formmain.cpp | 43 +++--- src/gui/formmain.h | 2 + src/miscellaneous/databasefactory.cpp | 8 +- src/miscellaneous/iconfactory.h | 5 +- src/miscellaneous/iofactory.cpp | 8 +- src/miscellaneous/iofactory.h | 8 +- 10 files changed, 328 insertions(+), 35 deletions(-) create mode 100644 src/gui/formbackupdatabasesettings.cpp create mode 100644 src/gui/formbackupdatabasesettings.h create mode 100644 src/gui/formbackupdatabasesettings.ui diff --git a/CMakeLists.txt b/CMakeLists.txt index 88c7b9c78..0760262bb 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -353,6 +353,7 @@ set(APP_SOURCES src/gui/messagessearchlineedit.cpp src/gui/formimportexport.cpp src/gui/styleditemdelegatewithoutfocus.cpp + src/gui/formbackupdatabasesettings.cpp # DYNAMIC-SHORTCUTS sources. src/dynamic-shortcuts/shortcutcatcher.cpp @@ -438,6 +439,7 @@ set(APP_HEADERS src/gui/toolbareditor.h src/gui/messagessearchlineedit.h src/gui/formimportexport.h + src/gui/formbackupdatabasesettings.h # DYNAMIC-SHORTCUTS headers. src/dynamic-shortcuts/dynamicshortcutswidget.h @@ -483,6 +485,7 @@ set(APP_FORMS src/gui/formfeeddetails.ui src/gui/toolbareditor.ui src/gui/formimportexport.ui + src/gui/formbackupdatabasesettings.ui ) # APP translations. diff --git a/src/gui/formbackupdatabasesettings.cpp b/src/gui/formbackupdatabasesettings.cpp new file mode 100644 index 000000000..a7249d4cc --- /dev/null +++ b/src/gui/formbackupdatabasesettings.cpp @@ -0,0 +1,63 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#include "gui/formbackupdatabasesettings.h" + +#include "miscellaneous/application.h" +#include "miscellaneous/iconfactory.h" + +#include +#include +#include + + +FormBackupDatabaseSettings::FormBackupDatabaseSettings(QWidget *parent) : QDialog(parent), m_ui(new Ui::FormBackupDatabaseSettings) { + m_ui->setupUi(this); + m_ui->m_txtBackupName->lineEdit()->setPlaceholderText(tr("Common name for backup files")); + + setWindowIcon(qApp->icons()->fromTheme("document-export")); + setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint); + + connect(m_ui->m_checkBackupDatabase, SIGNAL(toggled(bool)), this, SLOT(checkOkButton())); + connect(m_ui->m_checkBackupSettings, SIGNAL(toggled(bool)), this, SLOT(checkOkButton())); + connect(m_ui->m_txtBackupName->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(checkBackupNames(QString))); + connect(m_ui->m_txtBackupName->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(checkOkButton())); + + checkOkButton(); + + m_ui->m_txtBackupName->lineEdit()->setText(QString(APP_LOW_NAME) + "_" + QDateTime::currentDateTime().toString("yyyyMMddHHmm")); +} + +FormBackupDatabaseSettings::~FormBackupDatabaseSettings() { + delete m_ui; +} + +void FormBackupDatabaseSettings::checkBackupNames(const QString &name) { + if (name.simplified().isEmpty()) { + m_ui->m_txtBackupName->setStatus(WidgetWithStatus::Error, tr("Backup name cannot be empty.")); + } + else { + m_ui->m_txtBackupName->setStatus(WidgetWithStatus::Ok, tr("Backup name looks okay.")); + } +} + +void FormBackupDatabaseSettings::checkOkButton() { + m_ui->m_buttonBox->button(QDialogButtonBox::Ok)->setDisabled(m_ui->m_txtBackupName->lineEdit()->text().simplified().isEmpty() || + m_ui->m_lblSelectFolder->label()->text().simplified().isEmpty() || + (!m_ui->m_checkBackupDatabase->isChecked() && + !m_ui->m_checkBackupSettings->isChecked())); +} diff --git a/src/gui/formbackupdatabasesettings.h b/src/gui/formbackupdatabasesettings.h new file mode 100644 index 000000000..a7e89ef17 --- /dev/null +++ b/src/gui/formbackupdatabasesettings.h @@ -0,0 +1,47 @@ +// This file is part of RSS Guard. +// +// Copyright (C) 2011-2014 by Martin Rotter +// +// RSS Guard is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// RSS Guard is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with RSS Guard. If not, see . + +#ifndef FORMBACKUPDATABASECONFIG_H +#define FORMBACKUPDATABASECONFIG_H + +#include + +#include "ui_formbackupdatabasesettings.h" + + +namespace Ui { + class FormBackupDatabaseSettings; +} + +class FormBackupDatabaseSettings : public QDialog { + Q_OBJECT + + public: + // Constructors and destructors + explicit FormBackupDatabaseSettings(QWidget *parent = 0); + virtual ~FormBackupDatabaseSettings(); + + + private slots: + void checkBackupNames(const QString &name); + void checkOkButton(); + + private: + Ui::FormBackupDatabaseSettings *m_ui; +}; + +#endif // FORMBACKUPDATABASECONFIG_H diff --git a/src/gui/formbackupdatabasesettings.ui b/src/gui/formbackupdatabasesettings.ui new file mode 100644 index 000000000..0e98b858c --- /dev/null +++ b/src/gui/formbackupdatabasesettings.ui @@ -0,0 +1,176 @@ + + + FormBackupDatabaseSettings + + + + 0 + 0 + 400 + 300 + + + + Backup database/settings + + + + + + + + + + + + &Select folder + + + + + + + Qt::RightToLeft + + + + + + + + + + Backup properties + + + + + + Items to backup + + + + + + + Database + + + true + + + + + + + Settings + + + true + + + + + + + Backup name + + + + + + + + + + + + + Operation results + + + + + + Qt::RightToLeft + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Close|QDialogButtonBox::Ok + + + + + + + + LabelWithStatus + QWidget +
labelwithstatus.h
+ 1 +
+ + LineEditWithStatus + QWidget +
lineeditwithstatus.h
+ 1 +
+
+ + + + m_buttonBox + accepted() + FormBackupDatabaseSettings + accept() + + + 199 + 283 + + + 199 + 149 + + + + + m_buttonBox + rejected() + FormBackupDatabaseSettings + accept() + + + 199 + 283 + + + 199 + 149 + + + + +
diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index 8dd50c950..063736717 100755 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -35,6 +35,7 @@ #include "gui/feedmessageviewer.h" #include "gui/formupdate.h" #include "gui/formimportexport.h" +#include "gui/formbackupdatabasesettings.h" #include #include @@ -334,6 +335,8 @@ void FormMain::createConnections() { // Menu "File" connections. connect(m_ui->m_actionExportFeeds, SIGNAL(triggered()), this, SLOT(exportFeeds())); connect(m_ui->m_actionImportFeeds, SIGNAL(triggered()), this, SLOT(importFeeds())); + connect(m_ui->m_actionBackupDatabaseSettings, SIGNAL(triggered()), this, SLOT(backupDatabaseSettings())); + connect(m_ui->m_actionRestoreDatabaseSettings, SIGNAL(triggered()), this, SLOT(restoreDatabaseSettings())); connect(m_ui->m_actionRestart, SIGNAL(triggered()), qApp, SLOT(restart())); connect(m_ui->m_actionQuit, SIGNAL(triggered()), qApp, SLOT(quit())); @@ -354,26 +357,16 @@ void FormMain::createConnections() { connect(m_ui->m_actionDisplayWiki, SIGNAL(triggered()), this, SLOT(showWiki())); // Menu "Web browser" connections. - connect(m_ui->m_tabWidget, SIGNAL(currentChanged(int)), - this, SLOT(loadWebBrowserMenu(int))); - connect(m_ui->m_actionCloseCurrentTab, SIGNAL(triggered()), - m_ui->m_tabWidget, SLOT(closeCurrentTab())); - connect(m_ui->m_actionAddBrowser, SIGNAL(triggered()), - m_ui->m_tabWidget, SLOT(addEmptyBrowser())); - connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()), - m_ui->m_tabWidget, SLOT(closeAllTabsExceptCurrent())); - connect(WebFactory::instance(), SIGNAL(imagesLoadingSwitched(bool)), - m_ui->m_actionWebAutoloadImages, SLOT(setChecked(bool))); - connect(WebFactory::instance(), SIGNAL(javascriptSwitched(bool)), - m_ui->m_actionWebEnableJavascript, SLOT(setChecked(bool))); - connect(WebFactory::instance(), SIGNAL(pluginsSwitched(bool)), - m_ui->m_actionWebEnableExternalPlugins, SLOT(setChecked(bool))); - connect(m_ui->m_actionWebAutoloadImages, SIGNAL(toggled(bool)), - WebFactory::instance(), SLOT(switchImages(bool))); - connect(m_ui->m_actionWebEnableExternalPlugins, SIGNAL(toggled(bool)), - WebFactory::instance(), SLOT(switchPlugins(bool))); - connect(m_ui->m_actionWebEnableJavascript, SIGNAL(toggled(bool)), - WebFactory::instance(), SLOT(switchJavascript(bool))); + connect(m_ui->m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(loadWebBrowserMenu(int))); + connect(m_ui->m_actionCloseCurrentTab, SIGNAL(triggered()), m_ui->m_tabWidget, SLOT(closeCurrentTab())); + connect(m_ui->m_actionAddBrowser, SIGNAL(triggered()), m_ui->m_tabWidget, SLOT(addEmptyBrowser())); + connect(m_ui->m_actionCloseAllTabs, SIGNAL(triggered()), m_ui->m_tabWidget, SLOT(closeAllTabsExceptCurrent())); + connect(WebFactory::instance(), SIGNAL(imagesLoadingSwitched(bool)), m_ui->m_actionWebAutoloadImages, SLOT(setChecked(bool))); + connect(WebFactory::instance(), SIGNAL(javascriptSwitched(bool)), m_ui->m_actionWebEnableJavascript, SLOT(setChecked(bool))); + connect(WebFactory::instance(), SIGNAL(pluginsSwitched(bool)), m_ui->m_actionWebEnableExternalPlugins, SLOT(setChecked(bool))); + connect(m_ui->m_actionWebAutoloadImages, SIGNAL(toggled(bool)), WebFactory::instance(), SLOT(switchImages(bool))); + connect(m_ui->m_actionWebEnableExternalPlugins, SIGNAL(toggled(bool)), WebFactory::instance(), SLOT(switchPlugins(bool))); + connect(m_ui->m_actionWebEnableJavascript, SIGNAL(toggled(bool)), WebFactory::instance(), SLOT(switchJavascript(bool))); } void FormMain::loadWebBrowserMenu(int index) { @@ -405,6 +398,16 @@ void FormMain::importFeeds() { delete form.data(); } +void FormMain::backupDatabaseSettings() { + QPointer form = new FormBackupDatabaseSettings(this); + form.data()->exec(); + delete form.data(); +} + +void FormMain::restoreDatabaseSettings() { + +} + void FormMain::changeEvent(QEvent *event) { switch (event->type()) { case QEvent::WindowStateChange: { diff --git a/src/gui/formmain.h b/src/gui/formmain.h index 79ec7daa2..eb728375b 100755 --- a/src/gui/formmain.h +++ b/src/gui/formmain.h @@ -97,6 +97,8 @@ class FormMain : public QMainWindow { // Displays various dialogs. void exportFeeds(); void importFeeds(); + void backupDatabaseSettings(); + void restoreDatabaseSettings(); void showSettings(); void showAbout(); void showUpdates(); diff --git a/src/miscellaneous/databasefactory.cpp b/src/miscellaneous/databasefactory.cpp index af9e1953f..f993ff7ae 100755 --- a/src/miscellaneous/databasefactory.cpp +++ b/src/miscellaneous/databasefactory.cpp @@ -124,7 +124,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeInMemoryDatabase() { if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { // Database initialization file not opened. HUGE problem. - qFatal("In-memory SQLite database initialization file '%s' from directory '%s' was not found. In-memory database is uninitialized.", + qFatal("In-memory SQLite database initialization file '%s' from folder '%s' was not found. In-memory database is uninitialized.", APP_DB_SQLITE_INIT, qPrintable(APP_MISC_PATH)); } @@ -188,7 +188,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c if (!db_path.exists()) { if (!db_path.mkpath(db_path.absolutePath())) { // Failure when create database file path. - qFatal("Directory '%s' for SQLite database file '%s' was NOT created." + qFatal("Folder '%s' for SQLite database file '%s' was NOT created." "This is HUGE problem.", qPrintable(db_path.absolutePath()), qPrintable(db_file.symLinkTarget())); @@ -228,7 +228,7 @@ QSqlDatabase DatabaseFactory::sqliteInitializeFileBasedDatabase(const QString &c if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { // Database initialization file not opened. HUGE problem. - qFatal("SQLite database initialization file '%s' from directory '%s' was not found. File-based database is uninitialized.", + qFatal("SQLite database initialization file '%s' from folder '%s' was not found. File-based database is uninitialized.", APP_DB_SQLITE_INIT, qPrintable(APP_MISC_PATH)); } @@ -413,7 +413,7 @@ QSqlDatabase DatabaseFactory::mysqlInitializeDatabase(const QString &connection_ if (!file_init.open(QIODevice::ReadOnly | QIODevice::Text)) { // Database initialization file not opened. HUGE problem. - qFatal("MySQL database initialization file '%s' from directory '%s' was not found. File-based database is uninitialized.", + qFatal("MySQL database initialization file '%s' from folder '%s' was not found. File-based database is uninitialized.", APP_DB_MYSQL_INIT, qPrintable(APP_MISC_PATH)); } diff --git a/src/miscellaneous/iconfactory.h b/src/miscellaneous/iconfactory.h index cdc6d5ca4..9bc613533 100755 --- a/src/miscellaneous/iconfactory.h +++ b/src/miscellaneous/iconfactory.h @@ -53,9 +53,8 @@ class IconFactory : public QObject { if (!m_cachedIcons.contains(name)) { // Icon is not cached yet. - m_cachedIcons.insert(name, QIcon(APP_THEME_PATH + QDir::separator() + - m_currentIconTheme + QDir::separator() + - name + APP_THEME_SUFFIX)); + m_cachedIcons.insert(name, + QIcon(APP_THEME_PATH + QDir::separator() + m_currentIconTheme + QDir::separator() + name + APP_THEME_SUFFIX)); } return m_cachedIcons.value(name); diff --git a/src/miscellaneous/iofactory.cpp b/src/miscellaneous/iofactory.cpp index 95cac144f..49ddc0c46 100755 --- a/src/miscellaneous/iofactory.cpp +++ b/src/miscellaneous/iofactory.cpp @@ -25,7 +25,7 @@ IOFactory::IOFactory() { } -bool IOFactory::removeDirectory(const QString& directory_name, +bool IOFactory::removeFolder(const QString& directory_name, const QStringList& exception_file_list, const QStringList& exception_folder_list) { bool result = true; @@ -37,7 +37,7 @@ bool IOFactory::removeDirectory(const QString& directory_name, QDir::Hidden | QDir::AllDirs | QDir::Files, QDir::DirsFirst)) { if (info.isDir()) { if (!exception_folder_list.contains(info.fileName())) { - result &= removeDirectory(info.absoluteFilePath(), exception_file_list, exception_folder_list); + result &= removeFolder(info.absoluteFilePath(), exception_file_list, exception_folder_list); } } else if (!exception_file_list.contains(info.fileName())) { @@ -59,7 +59,7 @@ bool IOFactory::removeDirectory(const QString& directory_name, return result; } -bool IOFactory::copyDirectory(QString source, QString destination) { +bool IOFactory::copyFolder(QString source, QString destination) { QDir dir_source(source); if (!dir_source.exists()) { @@ -75,7 +75,7 @@ bool IOFactory::copyDirectory(QString source, QString destination) { foreach (QString d, dir_source.entryList(QDir::Dirs | QDir::NoDotAndDotDot)) { QString dst_path = destination + QDir::separator() + d; dir_source.mkpath(dst_path); - copyDirectory(source + QDir::separator() + d, dst_path); + copyFolder(source + QDir::separator() + d, dst_path); } foreach (QString f, dir_source.entryList(QDir::Files)) { diff --git a/src/miscellaneous/iofactory.h b/src/miscellaneous/iofactory.h index d5ec2cf4f..3ec5bedf2 100755 --- a/src/miscellaneous/iofactory.h +++ b/src/miscellaneous/iofactory.h @@ -28,12 +28,12 @@ class IOFactory { public: // Copy whole directory recursively. // Destination path is created if it does not exist. - static bool copyDirectory(QString source, QString destination); + static bool copyFolder(QString source, QString destination); // Removes directory recursively and skips given folders/files. - static bool removeDirectory(const QString &directory_name, - const QStringList &exception_file_list = QStringList(), - const QStringList &exception_folder_list = QStringList()); + static bool removeFolder(const QString &directory_name, + const QStringList &exception_file_list = QStringList(), + const QStringList &exception_folder_list = QStringList()); }; #endif // IOFACTORY_H