diff --git a/resources/binaries b/resources/binaries index 1bb36a305..aea118796 160000 --- a/resources/binaries +++ b/resources/binaries @@ -1 +1 @@ -Subproject commit 1bb36a305e8a23de1e4f3609d8fc4dfeb85ba6fe +Subproject commit aea11879635d0d6b029a7f6d49d1f31dd95b3c05 diff --git a/src/gui/dialogs/formmain.cpp b/src/gui/dialogs/formmain.cpp index f3ae6801b..5a1aee3db 100755 --- a/src/gui/dialogs/formmain.cpp +++ b/src/gui/dialogs/formmain.cpp @@ -132,6 +132,7 @@ QList FormMain::allActions() const { actions << m_ui->m_actionDownloadManager; actions << m_ui->m_actionRestoreDatabaseSettings; actions << m_ui->m_actionBackupDatabaseSettings; + actions << m_ui->m_actionRestart; actions << m_ui->m_actionQuit; actions << m_ui->m_actionFullscreen; actions << m_ui->m_actionAboutGuard; @@ -449,6 +450,7 @@ void FormMain::setupIcons() { m_ui->m_actionDownloadManager->setIcon(icon_theme_factory->fromTheme(QSL("emblem-downloads"))); m_ui->m_actionSettings->setIcon(icon_theme_factory->fromTheme(QSL("document-properties"))); m_ui->m_actionQuit->setIcon(icon_theme_factory->fromTheme(QSL("application-exit"))); + m_ui->m_actionRestart->setIcon(icon_theme_factory->fromTheme(QSL("view-refresh"))); m_ui->m_actionAboutGuard->setIcon(icon_theme_factory->fromTheme(QSL("help-about"))); m_ui->m_actionCheckForUpdates->setIcon(icon_theme_factory->fromTheme(QSL("system-upgrade"))); m_ui->m_actionCleanupDatabase->setIcon(icon_theme_factory->fromTheme(QSL("edit-clear"))); @@ -595,6 +597,7 @@ void FormMain::createConnections() { connect(m_ui->m_actionRestoreDatabaseSettings, &QAction::triggered, this, &FormMain::restoreDatabaseSettings); connect(m_ui->m_actionQuit, &QAction::triggered, qApp, &Application::quit); connect(m_ui->m_actionServiceAdd, &QAction::triggered, this, &FormMain::showAddAccountDialog); + connect(m_ui->m_actionRestart, &QAction::triggered, qApp, &Application::restart); // Menu "View" connections. connect(m_ui->m_actionFullscreen, &QAction::toggled, this, &FormMain::switchFullscreenMode); @@ -711,6 +714,10 @@ void FormMain::backupDatabaseSettings() { void FormMain::restoreDatabaseSettings() { QScopedPointer form(new FormRestoreDatabaseSettings(this)); form->exec(); + + if (form->shouldRestart()) { + qApp->restart(); + } } void FormMain::changeEvent(QEvent *event) { diff --git a/src/gui/dialogs/formmain.ui b/src/gui/dialogs/formmain.ui index afa0d2d4f..29ec6f2da 100755 --- a/src/gui/dialogs/formmain.ui +++ b/src/gui/dialogs/formmain.ui @@ -55,6 +55,7 @@ + @@ -533,6 +534,14 @@ + + + &Restart + + + + + &Restore database/settings diff --git a/src/gui/dialogs/formrestoredatabasesettings.cpp b/src/gui/dialogs/formrestoredatabasesettings.cpp index 202a4739c..1a7dd096d 100755 --- a/src/gui/dialogs/formrestoredatabasesettings.cpp +++ b/src/gui/dialogs/formrestoredatabasesettings.cpp @@ -26,18 +26,23 @@ FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget *parent) - : QDialog(parent), m_ui(new Ui::FormRestoreDatabaseSettings) { + : QDialog(parent), m_ui(new Ui::FormRestoreDatabaseSettings), m_shouldRestart(false) { m_ui->setupUi(this); + m_btnRestart = m_ui->m_buttonBox->addButton(tr("Restart"), QDialogButtonBox::ActionRole); m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet.")); setWindowIcon(qApp->icons()->fromTheme(QSL("document-import"))); setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint); - connect(m_ui->m_btnSelectFolder, &QPushButton::clicked, this, &FormRestoreDatabaseSettings::selectFolderWithGui); - connect(m_ui->m_groupDatabase, &QGroupBox::toggled, this, &FormRestoreDatabaseSettings::checkOkButton); - connect(m_ui->m_groupSettings, &QGroupBox::toggled, this, &FormRestoreDatabaseSettings::checkOkButton); - connect(m_ui->m_buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &FormRestoreDatabaseSettings::performRestoration); + connect(m_btnRestart, &QPushButton::clicked, this, [=]() { + m_shouldRestart = true; + close(); + }); + 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())); + connect(m_ui->m_buttonBox->button(QDialogButtonBox::Ok), SIGNAL(clicked()), this, SLOT(performRestoration())); selectFolder(qApp->getDocumentsFolderPath()); } @@ -58,6 +63,7 @@ void FormRestoreDatabaseSettings::performRestoration() { 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.")); } @@ -68,6 +74,7 @@ void FormRestoreDatabaseSettings::performRestoration() { } 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/dialogs/formrestoredatabasesettings.h b/src/gui/dialogs/formrestoredatabasesettings.h index 62b0b9ec0..4e511a3e7 100755 --- a/src/gui/dialogs/formrestoredatabasesettings.h +++ b/src/gui/dialogs/formrestoredatabasesettings.h @@ -31,6 +31,10 @@ class FormRestoreDatabaseSettings : public QDialog { explicit FormRestoreDatabaseSettings(QWidget *parent = 0); virtual ~FormRestoreDatabaseSettings(); + bool shouldRestart() const { + return m_shouldRestart; + } + private slots: void performRestoration(); void checkOkButton(); @@ -39,6 +43,9 @@ class FormRestoreDatabaseSettings : public QDialog { private: QScopedPointer m_ui; + QPushButton *m_btnRestart; + + bool m_shouldRestart; }; #endif // FORMRESTOREDATABASESETTINGS_H diff --git a/src/gui/dialogs/formsettings.cpp b/src/gui/dialogs/formsettings.cpp index 36c1d81d2..c98892706 100755 --- a/src/gui/dialogs/formsettings.cpp +++ b/src/gui/dialogs/formsettings.cpp @@ -89,14 +89,18 @@ void FormSettings::applySettings() { if (!panels_for_restart.isEmpty()) { const QStringList changed_settings_description = panels_for_restart.replaceInStrings(QRegExp(QSL("^")), QString::fromUtf8(" • ")); - MessageBox::show(this, - QMessageBox::Question, - tr("Critical settings were changed"), - tr("Some critical settings were changed and will be applied after the application gets restarted." - "\n\nYou have to restart manually."), - QString(), - tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))), - QMessageBox::Ok, QMessageBox::Ok); + const QMessageBox::StandardButton clicked_button = MessageBox::show(this, + QMessageBox::Question, + tr("Critical settings were changed"), + tr("Some critical settings were changed and will be applied after the application gets restarted. " + "\n\nYou have to restart manually."), + tr("Do you want to restart now?"), + tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + if (clicked_button == QMessageBox::Yes) { + qApp->restart(); + } } m_btnApply->setEnabled(false); diff --git a/src/miscellaneous/application.cpp b/src/miscellaneous/application.cpp index 4b7a21dd1..c94c7f13e 100755 --- a/src/miscellaneous/application.cpp +++ b/src/miscellaneous/application.cpp @@ -47,7 +47,7 @@ Application::Application(const QString &id, int &argc, char **argv) m_feedReader(nullptr), m_updateFeedsLock(nullptr), m_userActions(QList()), m_mainForm(nullptr), m_trayIcon(nullptr), m_settings(nullptr), m_system(nullptr), m_skins(nullptr), - m_localization(nullptr), m_icons(nullptr), m_database(nullptr), m_downloadManager(nullptr) { + m_localization(nullptr), m_icons(nullptr), m_database(nullptr), m_downloadManager(nullptr), m_shouldRestart(false) { connect(this, &Application::aboutToQuit, this, &Application::onAboutToQuit); connect(this, &Application::commitDataRequest, this, &Application::onCommitData); connect(this, &Application::saveStateRequest, this, &Application::onSaveState); @@ -391,6 +391,26 @@ void Application::onAboutToQuit() { // that some critical action can be processed right now. qDebug("Close lock timed-out."); } + + // Now, we can check if application should just quit or restart itself. + if (m_shouldRestart) { + finish(); + qDebug("Killing local peer connection to allow another instance to start."); + + // TODO: Start RSS Guard with sleep before it cross-platform way if possible. + // sleep 5 && "". + if (QProcess::startDetached(QString("\"") + QDir::toNativeSeparators(applicationFilePath()) + QString("\""))) { + qDebug("New application instance was started."); + } + else { + qWarning("New application instance was not started successfully."); + } + } +} + +void Application::restart() { + m_shouldRestart = true; + quit(); } #if defined(USE_WEBENGINE) diff --git a/src/miscellaneous/application.h b/src/miscellaneous/application.h index 3928fcfd9..8edc9723e 100755 --- a/src/miscellaneous/application.h +++ b/src/miscellaneous/application.h @@ -116,6 +116,9 @@ class Application : public QtSingleApplication { } public slots: + // Restarts the application. + void restart(); + // Processes incoming message from another RSS Guard instance. void processExecutionMessage(const QString &message); @@ -163,6 +166,7 @@ class Application : public QtSingleApplication { IconFactory *m_icons; DatabaseFactory *m_database; DownloadManager *m_downloadManager; + bool m_shouldRestart; }; #endif // APPLICATION_H