OTHER: Make 'Quit server on close' option work

This commit is contained in:
Thomas Frauendorfer 2008-10-14 03:56:27 +02:00
parent ef687a9375
commit 5e8d83ca8e
8 changed files with 102 additions and 37 deletions

View file

@ -15,6 +15,8 @@
#include "XMMSHandler.h"
#include "application.h"
#include "mainwindow.h"
#include "Skin.h"
@ -23,19 +25,60 @@
#endif
#include <QSettings>
#include <QMessageBox>
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

38
src/application.h Normal file
View file

@ -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 <QApplication>
class Application;
#if defined(qApp)
#undef qApp
#endif
#define qApp (static_cast<Application *>(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;
};

View file

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

View file

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

View file

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

View file

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