Restructure the class inheritance a bit.

This just shuffles around the streamwidget a bit. The RoleWidget child class is the
exception, so try and gear things around SinkInput/SourceOutput widgets more to
save repeating the same code too much.
This commit is contained in:
Colin Guthrie 2009-06-28 16:38:39 +01:00
parent ac052e1a30
commit f1a23af603
8 changed files with 39 additions and 52 deletions

View File

@ -43,6 +43,10 @@ RoleWidget* RoleWidget::create() {
return w; return w;
} }
bool RoleWidget::onContextTriggerEvent(GdkEventButton*) {
return false;
}
void RoleWidget::onMuteToggleButton() { void RoleWidget::onMuteToggleButton() {
StreamWidget::onMuteToggleButton(); StreamWidget::onMuteToggleButton();

View File

@ -35,6 +35,7 @@ public:
virtual void onMuteToggleButton(); virtual void onMuteToggleButton();
virtual void executeVolumeUpdate(); virtual void executeVolumeUpdate();
virtual bool onContextTriggerEvent(GdkEventButton*);
}; };
#endif #endif

View File

@ -29,21 +29,13 @@
#include "i18n.h" #include "i18n.h"
SinkInputWidget::SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : SinkInputWidget::SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
StreamWidget(cobject, x), StreamWidget(cobject, x) {
mpMainWindow(NULL) {
gchar *txt; gchar *txt;
directionLabel->set_label(txt = g_markup_printf_escaped("<i>%s</i>", _("on"))); directionLabel->set_label(txt = g_markup_printf_escaped("<i>%s</i>", _("on")));
g_free(txt); g_free(txt);
terminate.set_label(_("Terminate Playback")); terminate.set_label(_("Terminate Playback"));
terminate.signal_activate().connect(sigc::mem_fun(*this, &SinkInputWidget::onKill));
contextMenu.append(terminate);
contextMenu.show_all();
}
void SinkInputWidget::init(MainWindow* mainWindow) {
mpMainWindow = mainWindow;
} }
SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) { SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) {
@ -99,15 +91,6 @@ void SinkInputWidget::onMuteToggleButton() {
pa_operation_unref(o); pa_operation_unref(o);
} }
bool SinkInputWidget::onContextTriggerEvent(GdkEventButton* event) {
if (GDK_BUTTON_PRESS == event->type && 3 == event->button) {
contextMenu.popup(event->button, event->time);
return true;
}
return false;
}
void SinkInputWidget::onKill() { void SinkInputWidget::onKill() {
pa_operation* o; pa_operation* o;
if (!(o = pa_context_kill_sink_input(get_context(), index, NULL, NULL))) { if (!(o = pa_context_kill_sink_input(get_context(), index, NULL, NULL))) {

View File

@ -33,8 +33,6 @@ public:
static SinkInputWidget* create(MainWindow* mainWindow); static SinkInputWidget* create(MainWindow* mainWindow);
~SinkInputWidget(void); ~SinkInputWidget(void);
void init(MainWindow* mainWindow);
SinkInputType type; SinkInputType type;
uint32_t index, clientIndex; uint32_t index, clientIndex;
@ -42,17 +40,12 @@ public:
uint32_t sinkIndex(); uint32_t sinkIndex();
virtual void executeVolumeUpdate(); virtual void executeVolumeUpdate();
virtual void onDeviceChangePopup(); virtual void onDeviceChangePopup();
virtual bool onContextTriggerEvent(GdkEventButton*);
virtual void onMuteToggleButton(); virtual void onMuteToggleButton();
virtual void onKill(); virtual void onKill();
private: private:
MainWindow *mpMainWindow;
uint32_t mSinkIndex; uint32_t mSinkIndex;
Gtk::Menu contextMenu;
Gtk::MenuItem terminate;
void clearMenu(); void clearMenu();
void buildMenu(); void buildMenu();

View File

@ -29,21 +29,13 @@
#include "i18n.h" #include "i18n.h"
SourceOutputWidget::SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : SourceOutputWidget::SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
StreamWidget(cobject, x), StreamWidget(cobject, x) {
mpMainWindow(NULL) {
gchar *txt; gchar *txt;
directionLabel->set_label(txt = g_markup_printf_escaped("<i>%s</i>", _("from"))); directionLabel->set_label(txt = g_markup_printf_escaped("<i>%s</i>", _("from")));
g_free(txt); g_free(txt);
terminate.set_label(_("Terminate Recording")); terminate.set_label(_("Terminate Recording"));
terminate.signal_activate().connect(sigc::mem_fun(*this, &SourceOutputWidget::onKill));
contextMenu.append(terminate);
contextMenu.show_all();
}
void SourceOutputWidget::init(MainWindow* mainWindow) {
mpMainWindow = mainWindow;
} }
SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) { SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) {
@ -73,15 +65,6 @@ uint32_t SourceOutputWidget::sourceIndex() {
return mSourceIndex; return mSourceIndex;
} }
bool SourceOutputWidget::onContextTriggerEvent(GdkEventButton* event) {
if (GDK_BUTTON_PRESS == event->type && 3 == event->button) {
contextMenu.popup(event->button, event->time);
return true;
}
return false;
}
void SourceOutputWidget::onKill() { void SourceOutputWidget::onKill() {
pa_operation* o; pa_operation* o;
if (!(o = pa_context_kill_source_output(get_context(), index, NULL, NULL))) { if (!(o = pa_context_kill_source_output(get_context(), index, NULL, NULL))) {

View File

@ -33,24 +33,17 @@ public:
static SourceOutputWidget* create(MainWindow* mainWindow); static SourceOutputWidget* create(MainWindow* mainWindow);
~SourceOutputWidget(void); ~SourceOutputWidget(void);
void init(MainWindow* mainWindow);
SourceOutputType type; SourceOutputType type;
uint32_t index, clientIndex; uint32_t index, clientIndex;
void setSourceIndex(uint32_t idx); void setSourceIndex(uint32_t idx);
uint32_t sourceIndex(); uint32_t sourceIndex();
virtual void onDeviceChangePopup(); virtual void onDeviceChangePopup();
virtual bool onContextTriggerEvent(GdkEventButton*);
virtual void onKill(); virtual void onKill();
private: private:
MainWindow *mpMainWindow;
uint32_t mSourceIndex; uint32_t mSourceIndex;
Gtk::Menu contextMenu;
Gtk::MenuItem terminate;
void clearMenu(); void clearMenu();
void buildMenu(); void buildMenu();

View File

@ -23,11 +23,15 @@
#endif #endif
#include "streamwidget.h" #include "streamwidget.h"
#include "mainwindow.h"
#include "channelwidget.h" #include "channelwidget.h"
#include "i18n.h"
/*** StreamWidget ***/ /*** StreamWidget ***/
StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
MinimalStreamWidget(cobject, x) { MinimalStreamWidget(cobject, x),
mpMainWindow(NULL) {
x->get_widget("lockToggleButton", lockToggleButton); x->get_widget("lockToggleButton", lockToggleButton);
x->get_widget("muteToggleButton", muteToggleButton); x->get_widget("muteToggleButton", muteToggleButton);
@ -38,12 +42,25 @@ StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Gl
muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onMuteToggleButton)); muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onMuteToggleButton));
deviceButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onDeviceChangePopup)); deviceButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onDeviceChangePopup));
terminate.set_label(_("Terminate"));
terminate.signal_activate().connect(sigc::mem_fun(*this, &StreamWidget::onKill));
contextMenu.append(terminate);
contextMenu.show_all();
for (unsigned i = 0; i < PA_CHANNELS_MAX; i++) for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
channelWidgets[i] = NULL; channelWidgets[i] = NULL;
} }
bool StreamWidget::onContextTriggerEvent(GdkEventButton*) { void StreamWidget::init(MainWindow* mainWindow) {
mpMainWindow = mainWindow;
}
bool StreamWidget::onContextTriggerEvent(GdkEventButton* event) {
if (GDK_BUTTON_PRESS == event->type && 3 == event->button) {
contextMenu.popup(event->button, event->time);
return true;
}
return false; return false;
} }
@ -111,3 +128,6 @@ void StreamWidget::executeVolumeUpdate() {
void StreamWidget::onDeviceChangePopup() { void StreamWidget::onDeviceChangePopup() {
} }
void StreamWidget::onKill() {
}

View File

@ -25,11 +25,13 @@
#include "minimalstreamwidget.h" #include "minimalstreamwidget.h"
class MainWindow;
class ChannelWidget; class ChannelWidget;
class StreamWidget : public MinimalStreamWidget { class StreamWidget : public MinimalStreamWidget {
public: public:
StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x); StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x);
void init(MainWindow* mainWindow);
void setChannelMap(const pa_channel_map &m, bool can_decibel); void setChannelMap(const pa_channel_map &m, bool can_decibel);
void setVolume(const pa_cvolume &volume, bool force = false); void setVolume(const pa_cvolume &volume, bool force = false);
@ -53,6 +55,14 @@ public:
bool timeoutEvent(); bool timeoutEvent();
virtual void executeVolumeUpdate(); virtual void executeVolumeUpdate();
virtual void onKill();
protected:
MainWindow* mpMainWindow;
Gtk::Menu contextMenu;
Gtk::MenuItem terminate;
}; };
#endif #endif