From 5e8d83ca8e6f868585c7fe67a7ac9826352242d9 Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Tue, 14 Oct 2008 03:56:27 +0200 Subject: [PATCH] OTHER: Make 'Quit server on close' option work --- lib/xclient.cpp | 24 ++++++--------- lib/xclient.h | 1 + src/{main.cpp => application.cpp} | 51 ++++++++++++++++++++++++++++--- src/application.h | 38 +++++++++++++++++++++++ src/mainwindow/maindisplay.cpp | 14 --------- src/mainwindow/maindisplay.h | 2 +- src/settingsdialog.cpp | 4 +-- src/src.pri | 5 +-- 8 files changed, 102 insertions(+), 37 deletions(-) rename src/{main.cpp => application.cpp} (61%) create mode 100644 src/application.h diff --git a/lib/xclient.cpp b/lib/xclient.cpp index b754d13..145dc56 100644 --- a/lib/xclient.cpp +++ b/lib/xclient.cpp @@ -31,19 +31,6 @@ #include "xmmsqt4.h" #include "debug.h" -/* -XSettings::XSettings (QObject *parent) : QObject (parent) -{ -// * dummy * -} - -void -XSettings::change_settings () -{ - emit settingsChanged (); -} -*/ - QString XClient::stdToQ (const std::string &str) { @@ -94,6 +81,15 @@ void XClient::disconnect () emit disconnected (this); } +bool +XClient::quit () +{ + if (!m_client) + return false; + m_client->quit (); + return true; +} + bool XClient::connect (const char *ipcpath, const bool &sync, QWidget *parent) { @@ -137,10 +133,10 @@ try_again: } } + m_isconnected = true; // useing normal disconnect callback, if that causes problems, // an own method schould be created setDisconnectCallback (boost::bind (&XClient::disconnect, this)); - m_isconnected = true; emit gotConnection (this); return true; diff --git a/lib/xclient.h b/lib/xclient.h index 99a15f2..3a6c28b 100644 --- a/lib/xclient.h +++ b/lib/xclient.h @@ -93,6 +93,7 @@ class XClient : public QObject { public slots: void disconnect (); + bool quit (); protected: Xmms::Client *m_client; diff --git a/src/main.cpp b/src/application.cpp similarity index 61% rename from src/main.cpp rename to src/application.cpp index ab24f41..a816787 100644 --- a/src/main.cpp +++ b/src/application.cpp @@ -15,6 +15,8 @@ #include "XMMSHandler.h" +#include "application.h" + #include "mainwindow.h" #include "Skin.h" @@ -23,19 +25,60 @@ #endif #include +#include + +Application::Application (int &argc, char **argv) : QApplication (argc, argv) +{ + m_want_quit = false; + + //TODO: Change to XClient sometime later + XMMSHandler &client = XMMSHandler::getInstance (); + + connect (&client, SIGNAL(disconnected(XClient *)), + this, SLOT(handleDisconnected ())); +} + +void +Application::quit () +{ + // 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 (); + } +} + +void +Application::handleDisconnected () +{ + if (!m_want_quit) { + // 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"); + } + QApplication::quit (); +} int main (int argc, char **argv) { - QApplication app(argc, argv); + Application app(argc, argv); QCoreApplication::setOrganizationName("xmms2"); QCoreApplication::setOrganizationDomain("xmms.org"); QCoreApplication::setApplicationName("Promoe"); - //TODO: Change to XClient sometime later - XMMSHandler &client = XMMSHandler::getInstance (); - QSettings settings; #ifdef Q_OS_MACX diff --git a/src/application.h b/src/application.h new file mode 100644 index 0000000..a744995 --- /dev/null +++ b/src/application.h @@ -0,0 +1,38 @@ +/** + * This file is a part of Promoe, an XMMS2 Client. + * + * Copyright (C) 2005-2008 XMMS2 Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include + +class Application; +#if defined(qApp) +#undef qApp +#endif +#define qApp (static_cast(QCoreApplication::instance())) + +class Application : public QApplication +{ + Q_OBJECT + + public: + Application (int &argc, char **argv); + + public slots: + void quit (); + void handleDisconnected (); + + + private: + bool m_want_quit; +}; diff --git a/src/mainwindow/maindisplay.cpp b/src/mainwindow/maindisplay.cpp index 677f042..a5658e7 100644 --- a/src/mainwindow/maindisplay.cpp +++ b/src/mainwindow/maindisplay.cpp @@ -121,20 +121,6 @@ MainDisplay::MainDisplay (QWidget *parent) : SkinDisplay(parent) this, SLOT (setPlaytime (uint32_t))); setupServerConfig (); - - //TODO: move to better place - connect (&client, SIGNAL(disconnected(XClient *)), this, SLOT(handleDisconnected ())); -} - -void -MainDisplay::handleDisconnected () -{ - QMessageBox::critical( this, "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"); - qApp->quit (); } void diff --git a/src/mainwindow/maindisplay.h b/src/mainwindow/maindisplay.h index a6f883a..478e1c4 100644 --- a/src/mainwindow/maindisplay.h +++ b/src/mainwindow/maindisplay.h @@ -81,7 +81,7 @@ class MainDisplay : public SkinDisplay protected slots: void serverConfigChanged (QString key, QString value); void setRepeatAllEnabled (bool enabled); - void handleDisconnected (); + protected: void SetupPushButtons (void); void SetupToggleButtons (void); diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index 4af8402..4539ed2 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -328,10 +328,10 @@ SettingsTabMain::SettingsTabMain (QWidget *parent) : QWidget (parent) vbox->addWidget (c, 1); m_quitonclose = new QCheckBox (tr ("Quit XMMS2D when closing Promoe"), c); - if (s.contains ("promoe/quitonclose")) + if (!s.contains ("promoe/quitonclose")) s.setValue ("promoe/quitonclose", false); m_quitonclose->setCheckState (s.value ("promoe/quitonclose").toBool () ? Qt::Checked : Qt::Unchecked); - m_quitonclose->setEnabled (false); // FIXME: disabled for now, not working + //m_quitonclose->setEnabled (false); // FIXME: disabled for now, not working h->addWidget (m_quitonclose); c = new QWidget (dummy); diff --git a/src/src.pri b/src/src.pri index 30ff03e..01af089 100644 --- a/src/src.pri +++ b/src/src.pri @@ -4,7 +4,8 @@ include($$PWD/playlist/playlist.pri) include($$PWD/equalizer/equalizer.pri) include($$PWD/dialogs/dialogs.pri) -HEADERS += Skin.h \ +HEADERS += application.h \ + Skin.h \ timedisplay.h \ XMMSHandler.h \ SkinChooser.h \ @@ -14,7 +15,7 @@ HEADERS += Skin.h \ BrowseModel.h \ BrowseDialog.h -SOURCES += main.cpp \ +SOURCES += application.cpp \ timedisplay.cpp \ Skin.cpp \ XMMSHandler.cpp \