From a228d7a01b3eb1b397cf4d3db6965edc5c22ae3f Mon Sep 17 00:00:00 2001 From: Thomas Frauendorfer Date: Fri, 1 Feb 2008 05:16:32 +0100 Subject: [PATCH] rework PlaylistWindow: move handling of visibilitychanges into Playlistwindow and rely on signals and slots to get rid of MainWindow::togglePL(). cleaned up some unnecessary includes --- TODO | 2 ++ lib/xclient.cpp | 4 ++- lib/xclient.h | 2 +- lib/xsettings.cpp | 56 +++++++++++++++++++++++++++------ lib/xsettings.h | 13 +++++--- src/Button.cpp | 3 -- src/Button.h | 2 +- src/main.cpp | 16 ---------- src/mainwindow/maindisplay.cpp | 14 +++------ src/mainwindow/maindisplay.h | 1 - src/mainwindow/mainwindow.cpp | 48 +++++++++++----------------- src/mainwindow/mainwindow.h | 23 ++------------ src/playlist/playlistwindow.cpp | 25 +++++++++++---- src/playlist/playlistwindow.h | 18 ++++++++--- 14 files changed, 121 insertions(+), 106 deletions(-) diff --git a/TODO b/TODO index ceaa19b..3725759 100644 --- a/TODO +++ b/TODO @@ -24,3 +24,5 @@ Todo: * Textbox * redraw text in textbox when switching skin. * figure out something smart on osx. +* xclient: + * connect disconnected callback, so that it emits 'disconnected ()' diff --git a/lib/xclient.cpp b/lib/xclient.cpp index f1a44fe..a0f73bc 100644 --- a/lib/xclient.cpp +++ b/lib/xclient.cpp @@ -81,7 +81,9 @@ void XClient::disconnect () { delete m_client; m_client = NULL; - m_isconnected = false; + m_isconnected = false; + + emit disconnected (this); } bool diff --git a/lib/xclient.h b/lib/xclient.h index ef34b3e..d3e93c9 100644 --- a/lib/xclient.h +++ b/lib/xclient.h @@ -94,7 +94,7 @@ class XClient : public QObject { signals: void gotConnection (XClient *); - + void disconnected (XClient *); protected: Xmms::Client *m_client; diff --git a/lib/xsettings.cpp b/lib/xsettings.cpp index b0fb508..1067684 100644 --- a/lib/xsettings.cpp +++ b/lib/xsettings.cpp @@ -1,7 +1,7 @@ /** * This file is a part of Promoe, an XMMS2 Client * - * Copyright (C) 2007 Thomas Frauendorfer + * Copyright (C) 2007,2008 Thomas Frauendorfer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,42 +22,59 @@ XSettings::XSettings (QObject *parent, XClient *client) : QObject (parent) { - connect (client, SIGNAL(gotConnection (XClient *)), - this, SLOT (got_connection (XClient *))); + connect (client, SIGNAL (gotConnection (XClient *)), + this, SLOT (on_connect (XClient *))); + + connect (client, SIGNAL (disconnected (XClient *)), + this, SLOT (on_disconnect (XClient *))); if (client->isConnected ()) { - got_connection (client); + on_connect (client); } } QString XSettings::value_get (QString key) { - /* local cache should be identical to serverside config */ + /* if XSettings is ready, the local cache should be in sync with the + * serverside settings, otherwise the cache is empty */ + if (!m_ready) { + return QString (); + } return m_config_cache.value (key); } -void +bool XSettings::value_set (QString key, QString val) { /* Only send change request to server here * update of local cache will be done through handle_config_value_changed */ + if (!m_client->isConnected ()) { + return false; + } m_client->config ()->valueSet (key.toStdString (), val.toStdString ()); + + return true; } -void +bool XSettings::value_register (QString key, QString defval) { + if (!m_client->isConnected ()) { + return false; + } m_client->config ()->valueRegister (key.toStdString (), defval.toStdString ()); + + return true; } void -XSettings::got_connection (XClient *client) +XSettings::on_connect (XClient *client) { client->config ()->valueList () - (Xmms::bind (&XSettings::handle_config_value_changed, this)); + (Xmms::bind (&XSettings::handle_config_value, this)); client->config ()->broadcastValueChanged () (Xmms::bind (&XSettings::handle_config_value_changed, this)); @@ -65,6 +82,27 @@ XSettings::got_connection (XClient *client) m_client = client; } +void +XSettings::on_disconnect (XClient *client) +{ + /* We don't emit any signals here, as every class must be able to + * react on the configChanged signal, which will be fired for every + * configvalue on reonnect + */ + m_ready = false; + m_config_cache.clear (); +} + +bool +XSettings::handle_config_value (const Xmms::Dict &value) +{ + bool ok = handle_config_value_changed (value); + if (ok) { + m_ready = true; + } + return ok; +} + bool XSettings::handle_config_value_changed (const Xmms::Dict &value) { diff --git a/lib/xsettings.h b/lib/xsettings.h index bce8058..892514e 100644 --- a/lib/xsettings.h +++ b/lib/xsettings.h @@ -1,7 +1,7 @@ /** * This file is a part of Promoe, an XMMS2 Client * - * Copyright (C) 2007 Thomas Frauendorfer + * Copyright (C) 2007,2008 Thomas Frauendorfer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,18 +32,23 @@ class XSettings : public QObject XSettings (QObject *parent, XClient *client); QString value_get (QString key); - void value_set (QString key, QString value); - void value_register (QString key, QString defval); + bool value_set (QString key, QString value); + bool value_register (QString key, QString defval); + + bool isReady (void) {return m_ready;} signals: void configChanged(QString key, QString value); public slots: - void got_connection(XClient *); + void on_connect (XClient *); + void on_disconnect (XClient *); private: + bool handle_config_value (const Xmms::Dict &value); bool handle_config_value_changed (const Xmms::Dict &value); + bool m_ready; QHash < QString, QString > m_config_cache; XClient *m_client; }; diff --git a/src/Button.cpp b/src/Button.cpp index 329674f..90a05fa 100644 --- a/src/Button.cpp +++ b/src/Button.cpp @@ -121,6 +121,3 @@ ToggleButton::setPixmaps(Skin *skin) update(); } -ToggleButton::~ToggleButton () -{ -} diff --git a/src/Button.h b/src/Button.h index b92287b..4907459 100644 --- a/src/Button.h +++ b/src/Button.h @@ -43,7 +43,7 @@ class ToggleButton : public PixmapButton Q_OBJECT public: ToggleButton (QWidget *parent, uint, uint, uint, uint); - ~ToggleButton (); + ~ToggleButton () {} public slots: void setPixmaps(Skin *skin); diff --git a/src/main.cpp b/src/main.cpp index 1091c92..33e41dc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -49,7 +49,6 @@ main (int argc, char **argv) MainWindow *mw = new MainWindow (NULL); - PlaylistWindow *playlistwin = new PlaylistWindow (mw); EqualizerWindow *eqwin = new EqualizerWindow (mw); /* @@ -65,23 +64,8 @@ main (int argc, char **argv) Skin::getInstance()->setSkin (settings.value("skin/path").toString ()); mw->show (); - mw->setPL (playlistwin); mw->setEQ (eqwin); - if (!settings.contains ("playlist/pos")) - settings.setValue ("playlist/pos", QPoint (mw->pos().x(), - mw->pos().y()+mw->size().height())); - playlistwin->move (settings.value("playlist/pos").toPoint ()); - - if (!settings.contains ("playlist/hidden")) - settings.setValue ("playlist/hidden", true); - - if (settings.value("playlist/hidden").toBool ()) - playlistwin->hide (); - else - playlistwin->show (); - - if (!settings.contains ("equalizer/pos")) settings.setValue ("equalizer/pos", QPoint (mw->pos().x(), mw->pos().y()+mw->size().height())); diff --git a/src/mainwindow/maindisplay.cpp b/src/mainwindow/maindisplay.cpp index e2e5e84..aab36de 100644 --- a/src/mainwindow/maindisplay.cpp +++ b/src/mainwindow/maindisplay.cpp @@ -219,10 +219,12 @@ MainDisplay::SetupToggleButtons (void) m_pls = new ToggleButton (this, Skin::PLS_ON_0, Skin::PLS_ON_1, Skin::PLS_OFF_0, Skin::PLS_OFF_1); m_pls->move(242, 58); - if (!s.value ("playlist/hidden").toBool ()) - m_pls->toggle (); + m_pls->setChecked (m_mw->getPL ()->isVisible ()); + connect (m_pls, SIGNAL (toggled (bool)), + m_mw->getPL (), SLOT (setVisible (bool))); + connect (m_mw->getPL (), SIGNAL (visibilityChanged (bool)), + m_pls, SLOT (setChecked (bool))); - connect (m_pls, SIGNAL(clicked()), this, SLOT(togglePL())); m_eq = new ToggleButton (this, Skin::EQ_ON_0, Skin::EQ_ON_1, Skin::EQ_OFF_0, Skin::EQ_OFF_1); @@ -244,12 +246,6 @@ MainDisplay::SetupToggleButtons (void) m_repeat->setEnabled(false); // FIXME: Disabled button for now, not yet implemented } -void -MainDisplay::togglePL (void) -{ - m_mw->togglePL(false); -} - void MainDisplay::toggleEQ (void) { diff --git a/src/mainwindow/maindisplay.h b/src/mainwindow/maindisplay.h index 9c3e7e1..be82876 100644 --- a/src/mainwindow/maindisplay.h +++ b/src/mainwindow/maindisplay.h @@ -87,7 +87,6 @@ class MainDisplay : public SkinDisplay void setStatus (Xmms::Playback::Status status); void setPlaytime (uint32_t time); void setMediainfo (const Xmms::PropDict &); - void togglePL(void); void toggleEQ(void); void toggleTime(void); void updateVolume (uint volume); diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index ada3d28..1c0df79 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -32,7 +32,7 @@ MainWindow::MainWindow (QWidget *parent) : QMainWindow (parent) { - QSettings settings; + QSettings s; setWindowFlags(Qt::FramelessWindowHint); setGeometry(100, 100, 275, 116); @@ -40,11 +40,25 @@ MainWindow::MainWindow (QWidget *parent) : QMainWindow (parent) setWindowIcon (QIcon (":icon.png")); #endif - if (!settings.contains ("mainwindow/shaded")) + if (!s.contains ("mainwindow/shaded")) setShaded (true); else setShaded (!isShaded ()); + /* + * Setup PlaylistWindow + */ + m_playlistwin = new PlaylistWindow (this); + if (!s.contains ("playlist/pos")) { + s.setValue ("playlist/pos", QPoint (pos().x(), + pos().y()+size().height())); + } + m_playlistwin->move (s.value("playlist/pos").toPoint ()); + // FIXME: this should be done in PlaylistWindow. + // But promoe segfaults if done so + m_playlistwin->setVisible (s.value("playlist/visible", + false).toBool ()); + /* * The MainDisplay is the mainwindow non-shaded mode */ @@ -60,12 +74,10 @@ MainWindow::MainWindow (QWidget *parent) : QMainWindow (parent) switchDisplay (); - m_playlistwin = NULL; + if (!s.contains ("mainwindow/pos")) + s.setValue ("mainwindow/pos", QPoint (100, 100)); - if (!settings.contains ("mainwindow/pos")) - settings.setValue ("mainwindow/pos", QPoint (100, 100)); - - move (settings.value("mainwindow/pos").toPoint ()); + move (s.value("mainwindow/pos").toPoint ()); } MainWindow::~MainWindow () @@ -107,28 +119,6 @@ MainWindow::moveEvent (QMoveEvent *event) s.setValue ("mainwindow/pos", pos ()); } -void -MainWindow::togglePL (bool UpdateButton) -{ - QSettings s; - - if(UpdateButton) - { - getMD()->GetPls()->toggle(); - } - - - if (s.value ("playlist/hidden").toBool ()) { - m_playlistwin->move (s.value("playlist/pos").toPoint ()); - m_playlistwin->show (); - s.setValue ("playlist/hidden", false); - } else { - m_playlistwin->hide (); - s.setValue ("playlist/hidden", true); - } -} - - void MainWindow::toggleEQ (bool UpdateButton) { diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 5f2c1af..2f78579 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -16,30 +16,13 @@ #ifndef __MAINWINDOW_H__ #define __MAINWINDOW_H__ -class MainWindow; - #include "XMMSHandler.h" -#include - #include -#include -#include -#include -#include #include -#include "xmmsqt4.h" +class QWidget; -/* -#include "Skin.h" -#include "MainDisplay.h" -#include "ShadedDisplay.h" -#include "Playlist.h" -*/ - -class XmmsQT4; -class Skin; class MainDisplay; class ShadedDisplay; class PlaylistWindow; @@ -56,13 +39,11 @@ class MainWindow : public QMainWindow ShadedDisplay *getSD () { return m_shaded; } PlaylistWindow *getPL () { return m_playlistwin; } - void setPL (PlaylistWindow *p) { m_playlistwin = p; } void setEQ (EqualizerWindow *e) { m_equalizer = e; } void raisePL (void); void moveEvent (QMoveEvent *event); - void togglePL (bool UpdateButton); void toggleEQ (bool UpdateButton); bool isTimemodeReverse(void) { QSettings s; return s.value("MainWindow/timemodereverse").toBool(); } void setTimemodeReverse(bool b) { QSettings s; return s.setValue("MainWindow/timemodereverse",b); } @@ -75,8 +56,8 @@ class MainWindow : public QMainWindow void setShaded (bool b) { QSettings s; return s.setValue("MainWindow/shaded", b); } MainDisplay *m_display; ShadedDisplay *m_shaded; - PlaylistWindow *m_playlistwin; EqualizerWindow *m_equalizer; + PlaylistWindow *m_playlistwin; }; diff --git a/src/playlist/playlistwindow.cpp b/src/playlist/playlistwindow.cpp index e7479b4..b18912d 100644 --- a/src/playlist/playlistwindow.cpp +++ b/src/playlist/playlistwindow.cpp @@ -2,7 +2,7 @@ * This file is a part of Prome, an XMMS2 Client. * * Copyright (C) 2005-2007 XMMS2 Team - * Copyright (C) 2007 Thomas Frauendorfer + * Copyright (C) 2008 Thomas Frauendorfer * * 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 @@ -43,7 +43,7 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent) if (!s.contains ("size")) { s.setValue ("size", QSize (275, 350)); } - resize (s.value("size").toSize ()); + resize (s.value ("size").toSize ()); m_playlist = new PlaylistWidget (this); setCentralWidget (m_playlist); @@ -54,7 +54,7 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent) m_shadebtn->move(size().width() - 21, 3); m_closebtn = new Button (this, Skin::PLS_CLOSE_BTN_0, Skin::PLS_CLOSE_BTN_1, true); - connect (m_closebtn, SIGNAL (clicked()), this, SLOT (togglePL ())); + connect (m_closebtn, SIGNAL (clicked()), this, SLOT (hide ())); m_closebtn->move(size().width() - 11, 3); if (!s.contains ("shaded")) @@ -70,12 +70,25 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent) //setSizeIncrement (25, 29); } -void -PlaylistWindow::togglePL (void) +void +PlaylistWindow::hideEvent (QHideEvent *event) { - m_mw->togglePL(true); + QSettings s; + s.setValue ("playlist/visible", false); + + emit visibilityChanged (false); } +void +PlaylistWindow::showEvent (QShowEvent *event) +{ + QSettings s; + s.setValue ("playlist/visible", true); + + emit visibilityChanged (true); +} + + void PlaylistWindow::switchDisplay (void) { diff --git a/src/playlist/playlistwindow.h b/src/playlist/playlistwindow.h index f0a522e..d8f277a 100644 --- a/src/playlist/playlistwindow.h +++ b/src/playlist/playlistwindow.h @@ -2,6 +2,7 @@ * This file is a part of Prome, an XMMS2 Client. * * Copyright (C) 2005-2007 XMMS2 Team + * Copyright (C) 2008 Thomas Frauendorfer * * 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 @@ -17,12 +18,14 @@ #define _PLAYLISTWINDOW_ // Qt classes - #include +#include class QEvent; class QMouseEvent; class QMoveEvent; class QResizeEvent; +class QHideEvent; +class QShowEvent; // our own classes class Button; @@ -39,6 +42,15 @@ class PlaylistWindow : public QMainWindow { void setActive (bool); + signals: + void visibilityChanged(bool visible); + + public slots: + void switchDisplay (void); + + protected slots: + void hideEvent (QHideEvent *event); + void showEvent (QShowEvent *event); void mousePressEvent (QMouseEvent *event); void mouseMoveEvent (QMouseEvent *event); void enterEvent (QEvent *event); @@ -46,9 +58,6 @@ class PlaylistWindow : public QMainWindow { void moveEvent (QMoveEvent *event); void resizeEvent (QResizeEvent *event); - public slots: - void switchDisplay (void); - void togglePL (void); private: PlaylistWidget *m_playlist; @@ -59,7 +68,6 @@ class PlaylistWindow : public QMainWindow { Button *m_shadebtn; Button *m_closebtn; - uint getOffset (void); MainWindow *m_mw; };