Skip to content

Commit

Permalink
App now can be safely restarted, fixed #61.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinrotter committed Sep 28, 2014
1 parent 3d5feeb commit 5a6870e
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions resources/text/CHANGELOG
Expand Up @@ -13,6 +13,7 @@ Fixed:

Added:
<ul>
<li>Application can now be safely restarted from within main menu.</li>
<li>HTTP request for feed files now contains special "Accept" header.</li>
<li>Recycle bin with ability to trash or restore the whole bin or individual messages.</li>
<li>MySQL backend now allows to defragment/optimize RSS Guard database.</li>
Expand Down
3 changes: 3 additions & 0 deletions src/gui/formmain.cpp
Expand Up @@ -87,6 +87,7 @@ QList<QAction*> FormMain::allActions() {
actions << m_ui->m_actionSettings;
actions << m_ui->m_actionImportFeeds;
actions << m_ui->m_actionExportFeeds;
actions << m_ui->m_actionRestart;
actions << m_ui->m_actionQuit;
actions << m_ui->m_actionFullscreen;
actions << m_ui->m_actionAboutGuard;
Expand Down Expand Up @@ -202,6 +203,7 @@ void FormMain::setupIcons() {
// Setup icons of this main window.
m_ui->m_actionSettings->setIcon(icon_theme_factory->fromTheme("application-settings"));
m_ui->m_actionQuit->setIcon(icon_theme_factory->fromTheme("application-exit"));
m_ui->m_actionRestart->setIcon(icon_theme_factory->fromTheme("go-refresh"));
m_ui->m_actionAboutGuard->setIcon(icon_theme_factory->fromTheme("application-about"));
m_ui->m_actionCheckForUpdates->setIcon(icon_theme_factory->fromTheme("check-for-updates"));
m_ui->m_actionDefragmentDatabase->setIcon(icon_theme_factory->fromTheme("defragment-database"));
Expand Down Expand Up @@ -328,6 +330,7 @@ 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_actionRestart, SIGNAL(triggered()), qApp, SLOT(restart()));
connect(m_ui->m_actionQuit, SIGNAL(triggered()), qApp, SLOT(quit()));

// Menu "View" connections.
Expand Down
6 changes: 6 additions & 0 deletions src/gui/formmain.ui
Expand Up @@ -58,6 +58,7 @@
<addaction name="m_actionImportFeeds"/>
<addaction name="m_actionExportFeeds"/>
<addaction name="separator"/>
<addaction name="m_actionRestart"/>
<addaction name="m_actionQuit"/>
</widget>
<widget class="QMenu" name="m_menuHelp">
Expand Down Expand Up @@ -609,6 +610,11 @@
<string>Restore &amp;selected messages</string>
</property>
</action>
<action name="m_actionRestart">
<property name="text">
<string>&amp;Restart</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
26 changes: 25 additions & 1 deletion src/miscellaneous/application.cpp
Expand Up @@ -32,7 +32,7 @@ Application::Application(const QString &id, int &argc, char **argv)
: QtSingleApplication(id, argc, argv),
m_closeLock(NULL), m_userActions(QList<QAction*>()), m_mainForm(NULL),
m_trayIcon(NULL), m_settings(NULL), m_system(NULL), m_skins(NULL),
m_localization(NULL), m_icons(NULL), m_database(NULL) {
m_localization(NULL), m_icons(NULL), m_database(NULL), m_shouldRestart(false) {
connect(this, SIGNAL(aboutToQuit()), this, SLOT(onAboutToQuit()));
connect(this, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(onCommitData(QSessionManager&)));
connect(this, SIGNAL(saveStateRequest(QSessionManager&)), this, SLOT(onSaveState(QSessionManager&)));
Expand Down Expand Up @@ -159,4 +159,28 @@ 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) {
// TODO: Disable qtsinglepplication.
// TODO: Start new instance.
if (QProcess::startDetached(applicationFilePath())) {
finish();
qWarning("New application instance was not started successfully.");
}
}
}

bool Application::shouldRestart() const {
return m_shouldRestart;
}

void Application::setShouldRestart(bool shouldRestart) {
m_shouldRestart = shouldRestart;
}

void Application::restart() {
m_shouldRestart = true;
quit();
}

8 changes: 7 additions & 1 deletion src/miscellaneous/application.h
@@ -1,4 +1,4 @@
// This file is part of RSS Guard.
// This file is part of RSS Guard.
//
// Copyright (C) 2011-2014 by Martin Rotter <rotter.martinos@gmail.com>
//
Expand Down Expand Up @@ -144,7 +144,12 @@ class Application : public QtSingleApplication {
return static_cast<Application*>(QCoreApplication::instance());
}

bool shouldRestart() const;
void setShouldRestart(bool shouldRestart);

public slots:
void restart();

// Processes incoming message from another RSS Guard instance.
void processExecutionMessage(const QString &message);

Expand Down Expand Up @@ -177,6 +182,7 @@ class Application : public QtSingleApplication {
Localization *m_localization;
IconFactory *m_icons;
DatabaseFactory *m_database;
bool m_shouldRestart;
};

#endif // APPLICATION_H
4 changes: 4 additions & 0 deletions src/qtsingleapplication/qtsingleapplication.cpp
Expand Up @@ -329,6 +329,10 @@ void QtSingleApplication::activateWindow()
}
}

void QtSingleApplication::finish()
{
delete peer; peer = 0;
}

/*!
\fn void QtSingleApplication::messageReceived(const QString& message)
Expand Down
1 change: 1 addition & 0 deletions src/qtsingleapplication/qtsingleapplication.h
Expand Up @@ -90,6 +90,7 @@ class QT_QTSINGLEAPPLICATION_EXPORT QtSingleApplication : public QApplication
public Q_SLOTS:
bool sendMessage(const QString &message, int timeout = 5000);
void activateWindow();
void finish();


Q_SIGNALS:
Expand Down

0 comments on commit 5a6870e

Please sign in to comment.