This commit is contained in:
Martin Rotter 2017-06-19 11:46:24 +02:00
parent a159d8cf62
commit 12175edba9
8 changed files with 73 additions and 15 deletions

@ -1 +1 @@
Subproject commit 1bb36a305e8a23de1e4f3609d8fc4dfeb85ba6fe Subproject commit aea11879635d0d6b029a7f6d49d1f31dd95b3c05

View file

@ -132,6 +132,7 @@ QList<QAction*> FormMain::allActions() const {
actions << m_ui->m_actionDownloadManager; actions << m_ui->m_actionDownloadManager;
actions << m_ui->m_actionRestoreDatabaseSettings; actions << m_ui->m_actionRestoreDatabaseSettings;
actions << m_ui->m_actionBackupDatabaseSettings; actions << m_ui->m_actionBackupDatabaseSettings;
actions << m_ui->m_actionRestart;
actions << m_ui->m_actionQuit; actions << m_ui->m_actionQuit;
actions << m_ui->m_actionFullscreen; actions << m_ui->m_actionFullscreen;
actions << m_ui->m_actionAboutGuard; 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_actionDownloadManager->setIcon(icon_theme_factory->fromTheme(QSL("emblem-downloads")));
m_ui->m_actionSettings->setIcon(icon_theme_factory->fromTheme(QSL("document-properties"))); 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_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_actionAboutGuard->setIcon(icon_theme_factory->fromTheme(QSL("help-about")));
m_ui->m_actionCheckForUpdates->setIcon(icon_theme_factory->fromTheme(QSL("system-upgrade"))); m_ui->m_actionCheckForUpdates->setIcon(icon_theme_factory->fromTheme(QSL("system-upgrade")));
m_ui->m_actionCleanupDatabase->setIcon(icon_theme_factory->fromTheme(QSL("edit-clear"))); 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_actionRestoreDatabaseSettings, &QAction::triggered, this, &FormMain::restoreDatabaseSettings);
connect(m_ui->m_actionQuit, &QAction::triggered, qApp, &Application::quit); connect(m_ui->m_actionQuit, &QAction::triggered, qApp, &Application::quit);
connect(m_ui->m_actionServiceAdd, &QAction::triggered, this, &FormMain::showAddAccountDialog); connect(m_ui->m_actionServiceAdd, &QAction::triggered, this, &FormMain::showAddAccountDialog);
connect(m_ui->m_actionRestart, &QAction::triggered, qApp, &Application::restart);
// Menu "View" connections. // Menu "View" connections.
connect(m_ui->m_actionFullscreen, &QAction::toggled, this, &FormMain::switchFullscreenMode); connect(m_ui->m_actionFullscreen, &QAction::toggled, this, &FormMain::switchFullscreenMode);
@ -711,6 +714,10 @@ void FormMain::backupDatabaseSettings() {
void FormMain::restoreDatabaseSettings() { void FormMain::restoreDatabaseSettings() {
QScopedPointer<FormRestoreDatabaseSettings> form(new FormRestoreDatabaseSettings(this)); QScopedPointer<FormRestoreDatabaseSettings> form(new FormRestoreDatabaseSettings(this));
form->exec(); form->exec();
if (form->shouldRestart()) {
qApp->restart();
}
} }
void FormMain::changeEvent(QEvent *event) { void FormMain::changeEvent(QEvent *event) {

View file

@ -55,6 +55,7 @@
<addaction name="m_actionRestoreDatabaseSettings"/> <addaction name="m_actionRestoreDatabaseSettings"/>
<addaction name="m_actionBackupDatabaseSettings"/> <addaction name="m_actionBackupDatabaseSettings"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="m_actionRestart"/>
<addaction name="m_actionQuit"/> <addaction name="m_actionQuit"/>
</widget> </widget>
<widget class="QMenu" name="m_menuHelp"> <widget class="QMenu" name="m_menuHelp">
@ -533,6 +534,14 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
</action> </action>
<action name="m_actionRestart">
<property name="text">
<string>&amp;Restart</string>
</property>
<property name="shortcut">
<string notr="true"/>
</property>
</action>
<action name="m_actionRestoreDatabaseSettings"> <action name="m_actionRestoreDatabaseSettings">
<property name="text"> <property name="text">
<string>&amp;Restore database/settings</string> <string>&amp;Restore database/settings</string>

View file

@ -26,18 +26,23 @@
FormRestoreDatabaseSettings::FormRestoreDatabaseSettings(QWidget *parent) 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_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.")); m_ui->m_lblResult->setStatus(WidgetWithStatus::Warning, tr("No operation executed yet."), tr("No operation executed yet."));
setWindowIcon(qApp->icons()->fromTheme(QSL("document-import"))); setWindowIcon(qApp->icons()->fromTheme(QSL("document-import")));
setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint); setWindowFlags(Qt::MSWindowsFixedSizeDialogHint | Qt::Dialog | Qt::WindowSystemMenuHint);
connect(m_ui->m_btnSelectFolder, &QPushButton::clicked, this, &FormRestoreDatabaseSettings::selectFolderWithGui); connect(m_btnRestart, &QPushButton::clicked, this, [=]() {
connect(m_ui->m_groupDatabase, &QGroupBox::toggled, this, &FormRestoreDatabaseSettings::checkOkButton); m_shouldRestart = true;
connect(m_ui->m_groupSettings, &QGroupBox::toggled, this, &FormRestoreDatabaseSettings::checkOkButton); close();
connect(m_ui->m_buttonBox->button(QDialogButtonBox::Ok), &QPushButton::clicked, this, &FormRestoreDatabaseSettings::performRestoration); });
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()); selectFolder(qApp->getDocumentsFolderPath());
} }
@ -58,6 +63,7 @@ void FormRestoreDatabaseSettings::performRestoration() {
m_ui->m_listSettings->currentRow() >= 0 ? m_ui->m_listSettings->currentRow() >= 0 ?
m_ui->m_listSettings->currentItem()->data(Qt::UserRole).toString() : m_ui->m_listSettings->currentItem()->data(Qt::UserRole).toString() :
QString()); QString());
m_btnRestart->setEnabled(true);
m_ui->m_lblResult->setStatus(WidgetWithStatus::Ok, tr("Restoration was initiated. Restart to proceed."), 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.")); tr("You need to restart application for restoration process to finish."));
} }
@ -68,6 +74,7 @@ void FormRestoreDatabaseSettings::performRestoration() {
} }
void FormRestoreDatabaseSettings::checkOkButton() { 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_buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!m_ui->m_lblSelectFolder->label()->text().isEmpty() &&
((m_ui->m_groupDatabase->isChecked() && ((m_ui->m_groupDatabase->isChecked() &&
m_ui->m_listDatabase->currentRow() >= 0) || m_ui->m_listDatabase->currentRow() >= 0) ||

View file

@ -31,6 +31,10 @@ class FormRestoreDatabaseSettings : public QDialog {
explicit FormRestoreDatabaseSettings(QWidget *parent = 0); explicit FormRestoreDatabaseSettings(QWidget *parent = 0);
virtual ~FormRestoreDatabaseSettings(); virtual ~FormRestoreDatabaseSettings();
bool shouldRestart() const {
return m_shouldRestart;
}
private slots: private slots:
void performRestoration(); void performRestoration();
void checkOkButton(); void checkOkButton();
@ -39,6 +43,9 @@ class FormRestoreDatabaseSettings : public QDialog {
private: private:
QScopedPointer<Ui::FormRestoreDatabaseSettings> m_ui; QScopedPointer<Ui::FormRestoreDatabaseSettings> m_ui;
QPushButton *m_btnRestart;
bool m_shouldRestart;
}; };
#endif // FORMRESTOREDATABASESETTINGS_H #endif // FORMRESTOREDATABASESETTINGS_H

View file

@ -89,14 +89,18 @@ void FormSettings::applySettings() {
if (!panels_for_restart.isEmpty()) { if (!panels_for_restart.isEmpty()) {
const QStringList changed_settings_description = panels_for_restart.replaceInStrings(QRegExp(QSL("^")), QString::fromUtf8("")); const QStringList changed_settings_description = panels_for_restart.replaceInStrings(QRegExp(QSL("^")), QString::fromUtf8(""));
MessageBox::show(this, const QMessageBox::StandardButton clicked_button = MessageBox::show(this,
QMessageBox::Question, QMessageBox::Question,
tr("Critical settings were changed"), tr("Critical settings were changed"),
tr("Some critical settings were changed and will be applied after the application gets restarted." tr("Some critical settings were changed and will be applied after the application gets restarted. "
"\n\nYou have to restart manually."), "\n\nYou have to restart manually."),
QString(), tr("Do you want to restart now?"),
tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))), tr("Changed categories of settings:\n%1.").arg(changed_settings_description .join(QSL(",\n"))),
QMessageBox::Ok, QMessageBox::Ok); QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if (clicked_button == QMessageBox::Yes) {
qApp->restart();
}
} }
m_btnApply->setEnabled(false); m_btnApply->setEnabled(false);

View file

@ -47,7 +47,7 @@ Application::Application(const QString &id, int &argc, char **argv)
m_feedReader(nullptr), m_feedReader(nullptr),
m_updateFeedsLock(nullptr), m_userActions(QList<QAction*>()), m_mainForm(nullptr), m_updateFeedsLock(nullptr), m_userActions(QList<QAction*>()), m_mainForm(nullptr),
m_trayIcon(nullptr), m_settings(nullptr), m_system(nullptr), m_skins(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::aboutToQuit, this, &Application::onAboutToQuit);
connect(this, &Application::commitDataRequest, this, &Application::onCommitData); connect(this, &Application::commitDataRequest, this, &Application::onCommitData);
connect(this, &Application::saveStateRequest, this, &Application::onSaveState); connect(this, &Application::saveStateRequest, this, &Application::onSaveState);
@ -391,6 +391,26 @@ void Application::onAboutToQuit() {
// that some critical action can be processed right now. // that some critical action can be processed right now.
qDebug("Close lock timed-out."); 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 && "<rssguard-start>".
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) #if defined(USE_WEBENGINE)

View file

@ -116,6 +116,9 @@ class Application : public QtSingleApplication {
} }
public slots: public slots:
// Restarts the application.
void restart();
// Processes incoming message from another RSS Guard instance. // Processes incoming message from another RSS Guard instance.
void processExecutionMessage(const QString &message); void processExecutionMessage(const QString &message);
@ -163,6 +166,7 @@ class Application : public QtSingleApplication {
IconFactory *m_icons; IconFactory *m_icons;
DatabaseFactory *m_database; DatabaseFactory *m_database;
DownloadManager *m_downloadManager; DownloadManager *m_downloadManager;
bool m_shouldRestart;
}; };
#endif // APPLICATION_H #endif // APPLICATION_H