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
This commit is contained in:
Thomas Frauendorfer 2008-02-01 05:16:32 +01:00
parent b10ef97cfc
commit a228d7a01b
14 changed files with 121 additions and 106 deletions

2
TODO
View file

@ -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 ()'

View file

@ -81,7 +81,9 @@ void XClient::disconnect ()
{
delete m_client;
m_client = NULL;
m_isconnected = false;
m_isconnected = false;
emit disconnected (this);
}
bool

View file

@ -94,7 +94,7 @@ class XClient : public QObject {
signals:
void gotConnection (XClient *);
void disconnected (XClient *);
protected:
Xmms::Client *m_client;

View file

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

View file

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

View file

@ -121,6 +121,3 @@ ToggleButton::setPixmaps(Skin *skin)
update();
}
ToggleButton::~ToggleButton ()
{
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -16,30 +16,13 @@
#ifndef __MAINWINDOW_H__
#define __MAINWINDOW_H__
class MainWindow;
#include "XMMSHandler.h"
#include <iostream>
#include <QMainWindow>
#include <QPixmap>
#include <QPainter>
#include <QWidget>
#include <QHash>
#include <QSettings>
#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;
};

View file

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

View file

@ -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 <QMainWindow>
#include <QMainWindow>
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;
};