Merge branch 'master' into macOS_fixes

This commit is contained in:
Peter Hedlund 2017-06-22 19:19:05 -07:00
commit f743792447
7 changed files with 72 additions and 14 deletions

View File

@ -132,6 +132,7 @@ QList<QAction*> 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<FormRestoreDatabaseSettings> form(new FormRestoreDatabaseSettings(this));
form->exec();
if (form->shouldRestart()) {
qApp->restart();
}
}
void FormMain::changeEvent(QEvent *event) {

View File

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

View File

@ -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) ||

View File

@ -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<Ui::FormRestoreDatabaseSettings> m_ui;
QPushButton *m_btnRestart;
bool m_shouldRestart;
};
#endif // FORMRESTOREDATABASESETTINGS_H

View File

@ -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);

View File

@ -47,7 +47,7 @@ Application::Application(const QString &id, int &argc, char **argv)
m_feedReader(nullptr),
m_updateFeedsLock(nullptr), m_userActions(QList<QAction*>()), 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 && "<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)

View File

@ -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