diff --git a/lib/xclient.cpp b/lib/xclient.cpp index 145dc56..2b6f249 100644 --- a/lib/xclient.cpp +++ b/lib/xclient.cpp @@ -81,13 +81,21 @@ void XClient::disconnect () emit disconnected (this); } -bool -XClient::quit () +void +XClient::shutdownServer () { if (!m_client) - return false; + return; 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(&m_client->getMainLoop()); + notifier->OnWrite (); + + return; } bool diff --git a/lib/xclient.h b/lib/xclient.h index 3a6c28b..0720fd4 100644 --- a/lib/xclient.h +++ b/lib/xclient.h @@ -93,7 +93,7 @@ class XClient : public QObject { public slots: void disconnect (); - bool quit (); + void shutdownServer (); protected: Xmms::Client *m_client; diff --git a/src/application.cpp b/src/application.cpp index a816787..ba89c73 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -29,44 +29,38 @@ Application::Application (int &argc, char **argv) : QApplication (argc, argv) { - m_want_quit = false; - //TODO: Change to XClient sometime later XMMSHandler &client = XMMSHandler::getInstance (); + connect (this, SIGNAL (aboutToQuit ()), + this, SLOT (cleanupHandler ())); connect (&client, SIGNAL(disconnected(XClient *)), this, SLOT(handleDisconnected ())); + } void -Application::quit () +Application::cleanupHandler () { - // quit for real in case something went wrong earlier - if (m_want_quit) - QApplication::quit (); - QSettings s; - if (s.value ("promoe/quitonclose", false).toBool ()) { - m_want_quit = true; - if (!XMMSHandler::getInstance ().quit ()) { - QApplication::quit (); - } - } else { - QApplication::quit (); - } + if (s.value ("promoe/quitonclose", false).toBool ()) + XMMSHandler::getInstance ().shutdownServer (); } void 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 - QMessageBox::critical( NULL, "xmms2 daemon disconnected", - "The xmms2 deamon has disconnected\n" - "This could be because the server crashed\n" - "or because another client has shut down the sever.", - "Quit Promoe"); - } + QMessageBox::critical( NULL, "xmms2 daemon disconnected", + "The xmms2 deamon has disconnected\n" + "This could be because the server crashed\n" + "or because another client has shut down the sever.", + "Quit Promoe"); QApplication::quit (); } diff --git a/src/application.h b/src/application.h index a744995..303e2cd 100644 --- a/src/application.h +++ b/src/application.h @@ -29,10 +29,6 @@ class Application : public QApplication Application (int &argc, char **argv); public slots: - void quit (); + void cleanupHandler (); void handleDisconnected (); - - - private: - bool m_want_quit; };