OTHER: Rework the 'Quit server on close' option
Quit server on close is now implemented in a cleaner and easier understandable way. It also doesn't impact the application shutdown time any more.
This commit is contained in:
parent
5e8d83ca8e
commit
11b7e5e6e7
4 changed files with 30 additions and 32 deletions
|
@ -81,13 +81,21 @@ void XClient::disconnect ()
|
||||||
emit disconnected (this);
|
emit disconnected (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
void
|
||||||
XClient::quit ()
|
XClient::shutdownServer ()
|
||||||
{
|
{
|
||||||
if (!m_client)
|
if (!m_client)
|
||||||
return false;
|
return;
|
||||||
m_client->quit ();
|
m_client->quit ();
|
||||||
return true;
|
/* OnWrite is called here to make sure all pending messeages get sent
|
||||||
|
* to the server, even if an application is closing down.
|
||||||
|
* If this call is removed it can no longer be guaranted that the
|
||||||
|
* quit messeage is sent to the server
|
||||||
|
*/
|
||||||
|
XmmsQT4 *notifier = dynamic_cast<XmmsQT4 *>(&m_client->getMainLoop());
|
||||||
|
notifier->OnWrite ();
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
|
@ -93,7 +93,7 @@ class XClient : public QObject {
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void disconnect ();
|
void disconnect ();
|
||||||
bool quit ();
|
void shutdownServer ();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Xmms::Client *m_client;
|
Xmms::Client *m_client;
|
||||||
|
|
|
@ -29,44 +29,38 @@
|
||||||
|
|
||||||
Application::Application (int &argc, char **argv) : QApplication (argc, argv)
|
Application::Application (int &argc, char **argv) : QApplication (argc, argv)
|
||||||
{
|
{
|
||||||
m_want_quit = false;
|
|
||||||
|
|
||||||
//TODO: Change to XClient sometime later
|
//TODO: Change to XClient sometime later
|
||||||
XMMSHandler &client = XMMSHandler::getInstance ();
|
XMMSHandler &client = XMMSHandler::getInstance ();
|
||||||
|
|
||||||
|
connect (this, SIGNAL (aboutToQuit ()),
|
||||||
|
this, SLOT (cleanupHandler ()));
|
||||||
connect (&client, SIGNAL(disconnected(XClient *)),
|
connect (&client, SIGNAL(disconnected(XClient *)),
|
||||||
this, SLOT(handleDisconnected ()));
|
this, SLOT(handleDisconnected ()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Application::quit ()
|
Application::cleanupHandler ()
|
||||||
{
|
{
|
||||||
// quit for real in case something went wrong earlier
|
|
||||||
if (m_want_quit)
|
|
||||||
QApplication::quit ();
|
|
||||||
|
|
||||||
QSettings s;
|
QSettings s;
|
||||||
if (s.value ("promoe/quitonclose", false).toBool ()) {
|
if (s.value ("promoe/quitonclose", false).toBool ())
|
||||||
m_want_quit = true;
|
XMMSHandler::getInstance ().shutdownServer ();
|
||||||
if (!XMMSHandler::getInstance ().quit ()) {
|
|
||||||
QApplication::quit ();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
QApplication::quit ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Application::handleDisconnected ()
|
Application::handleDisconnected ()
|
||||||
{
|
{
|
||||||
if (!m_want_quit) {
|
// if the Application is about to quit, we no longer need to handle
|
||||||
|
// disconnects
|
||||||
|
if (closingDown ())
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: enable reconnect
|
// TODO: enable reconnect
|
||||||
QMessageBox::critical( NULL, "xmms2 daemon disconnected",
|
QMessageBox::critical( NULL, "xmms2 daemon disconnected",
|
||||||
"The xmms2 deamon has disconnected\n"
|
"The xmms2 deamon has disconnected\n"
|
||||||
"This could be because the server crashed\n"
|
"This could be because the server crashed\n"
|
||||||
"or because another client has shut down the sever.",
|
"or because another client has shut down the sever.",
|
||||||
"Quit Promoe");
|
"Quit Promoe");
|
||||||
}
|
|
||||||
QApplication::quit ();
|
QApplication::quit ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,6 @@ class Application : public QApplication
|
||||||
Application (int &argc, char **argv);
|
Application (int &argc, char **argv);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void quit ();
|
void cleanupHandler ();
|
||||||
void handleDisconnected ();
|
void handleDisconnected ();
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_want_quit;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue