Wire up all the new UI code.

This makes the default button work on sinks/sources, allows the drop
down to actually change the sink/source and removes the old menu code.

Some names and such are fixed in the glade file too.
This commit is contained in:
Colin Guthrie 2009-03-16 23:21:40 +00:00
parent 4c3acd35e5
commit 4bd94fa2b8
14 changed files with 67 additions and 237 deletions

View File

@ -245,7 +245,8 @@ void MainWindow::updateSink(const pa_sink_info &info) {
w->setVolume(info.volume); w->setVolume(info.volume);
w->muteToggleButton->set_active(info.mute); w->muteToggleButton->set_active(info.mute);
w->defaultMenuItem.set_active(w->name == defaultSinkName); w->defaultToggleButton->set_active(w->name == defaultSinkName);
w->defaultToggleButton->set_sensitive(w->name != defaultSinkName);
w->updating = false; w->updating = false;
@ -422,7 +423,8 @@ void MainWindow::updateSource(const pa_source_info &info) {
w->setVolume(info.volume); w->setVolume(info.volume);
w->muteToggleButton->set_active(info.mute); w->muteToggleButton->set_active(info.mute);
w->defaultMenuItem.set_active(w->name == defaultSourceName); w->defaultToggleButton->set_active(w->name == defaultSourceName);
w->defaultToggleButton->set_sensitive(w->name != defaultSourceName);
w->updating = false; w->updating = false;
@ -592,7 +594,9 @@ void MainWindow::updateServer(const pa_server_info &info) {
continue; continue;
w->updating = true; w->updating = true;
w->defaultMenuItem.set_active(w->name == defaultSinkName); w->defaultToggleButton->set_active(w->name == defaultSinkName);
w->defaultToggleButton->set_sensitive(w->name != defaultSinkName);
w->updating = false; w->updating = false;
} }
@ -603,7 +607,8 @@ void MainWindow::updateServer(const pa_server_info &info) {
continue; continue;
w->updating = true; w->updating = true;
w->defaultMenuItem.set_active(w->name == defaultSourceName); w->defaultToggleButton->set_active(w->name == defaultSourceName);
w->defaultToggleButton->set_sensitive(w->name != defaultSourceName);
w->updating = false; w->updating = false;
} }
} }

View File

@ -40,58 +40,9 @@ MinimalStreamWidget::MinimalStreamWidget(BaseObjectType* cobject, const Glib::Re
peakProgressBar.set_size_request(-1, 10); peakProgressBar.set_size_request(-1, 10);
channelsVBox->pack_end(peakProgressBar, false, false); channelsVBox->pack_end(peakProgressBar, false, false);
//menu.signal_deactivate().connect(sigc::mem_fun(*this, &MinimalStreamWidget::onMenuDeactivated));
peakProgressBar.hide(); peakProgressBar.hide();
} }
void MinimalStreamWidget::prepareMenu(void) {
}
void MinimalStreamWidget::onMenuDeactivated(void) {
//streamToggleButton->set_active(false);
}
void MinimalStreamWidget::popupMenuPosition(int& x, int& y, bool& push_in G_GNUC_UNUSED) {
/*
Gtk::Requisition r;
streamToggleButton->get_window()->get_origin(x, y);
r = menu.size_request();
// Align the right side of the menu with the right side of the togglebutton
x += streamToggleButton->get_allocation().get_x();
x += streamToggleButton->get_allocation().get_width();
x -= r.width;
// Align the top of the menu with the buttom of the togglebutton
y += streamToggleButton->get_allocation().get_y();
y += streamToggleButton->get_allocation().get_height();
*/
}
void MinimalStreamWidget::onStreamToggleButton(void) {
/*
if (streamToggleButton->get_active()) {
prepareMenu();
menu.popup(sigc::mem_fun(*this, &MinimalStreamWidget::popupMenuPosition), 0, gtk_get_current_event_time());
}
*/
}
bool MinimalStreamWidget::on_button_press_event (GdkEventButton* event) {
if (Gtk::VBox::on_button_press_event(event))
return TRUE;
if (event->type == GDK_BUTTON_PRESS && event->button == 3) {
prepareMenu();
menu.popup(0, event->time);
return TRUE;
}
return FALSE;
}
#define DECAY_STEP .04 #define DECAY_STEP .04
void MinimalStreamWidget::updatePeak(double v) { void MinimalStreamWidget::updatePeak(double v) {

View File

@ -29,29 +29,20 @@ public:
Gtk::VBox *channelsVBox; Gtk::VBox *channelsVBox;
Gtk::Label *nameLabel, *boldNameLabel; Gtk::Label *nameLabel, *boldNameLabel;
Gtk::Menu menu;
Gtk::Image *iconImage; Gtk::Image *iconImage;
Gtk::ProgressBar peakProgressBar; Gtk::ProgressBar peakProgressBar;
double lastPeak; double lastPeak;
bool updating; bool updating;
/**/void onStreamToggleButton();
/**/void onMenuDeactivated();
/**/void popupMenuPosition(int& x, int& y, bool& push_in);
virtual void onMuteToggleButton() = 0; virtual void onMuteToggleButton() = 0;
virtual void updateChannelVolume(int channel, pa_volume_t v) = 0; virtual void updateChannelVolume(int channel, pa_volume_t v) = 0;
virtual void prepareMenu(void);
bool volumeMeterEnabled; bool volumeMeterEnabled;
void enableVolumeMeter(); void enableVolumeMeter();
void updatePeak(double v); void updatePeak(double v);
Glib::ustring beepDevice; Glib::ustring beepDevice;
protected:
virtual bool on_button_press_event(GdkEventButton* event);
}; };
#endif #endif

View File

@ -786,11 +786,11 @@ Monitors</property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkToggleButton" id="defaultToggle"> <widget class="GtkToggleButton" id="defaultToggleButton">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="tooltip" translatable="yes">Open menu</property> <property name="tooltip" translatable="yes">Set as default</property>
<child> <child>
<widget class="GtkHBox" id="hbox2"> <widget class="GtkHBox" id="hbox2">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -30,15 +30,9 @@
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),
titleMenuItem(_("_Move Stream..."), true),
mpMainWindow(NULL) { mpMainWindow(NULL) {
directionLabel->set_label(_("<i>Playing on </i> ")); directionLabel->set_label(_("<i>Playing on </i> "));
add_events(Gdk::BUTTON_PRESS_MASK);
menu.append(titleMenuItem);
titleMenuItem.set_submenu(submenu);
} }
void SinkInputWidget::init(MainWindow* mainWindow) { void SinkInputWidget::init(MainWindow* mainWindow) {
@ -47,10 +41,6 @@ void SinkInputWidget::init(MainWindow* mainWindow) {
deviceCombo->pack_start(mpMainWindow->deviceColumns.name); deviceCombo->pack_start(mpMainWindow->deviceColumns.name);
} }
SinkInputWidget::~SinkInputWidget() {
clearMenu();
}
SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) { SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) {
SinkInputWidget* w; SinkInputWidget* w;
Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "streamWidget"); Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "streamWidget");
@ -61,7 +51,10 @@ SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) {
void SinkInputWidget::setSinkIndex(uint32_t idx) { void SinkInputWidget::setSinkIndex(uint32_t idx) {
mSinkIndex = idx; mSinkIndex = idx;
mSuppressDeviceChange = true;
deviceCombo->set_active(mpMainWindow->sinkTreeIndexes[idx]); deviceCombo->set_active(mpMainWindow->sinkTreeIndexes[idx]);
mSuppressDeviceChange = false;
} }
uint32_t SinkInputWidget::sinkIndex() { uint32_t SinkInputWidget::sinkIndex() {
@ -94,30 +87,6 @@ void SinkInputWidget::onMuteToggleButton() {
pa_operation_unref(o); pa_operation_unref(o);
} }
void SinkInputWidget::prepareMenu() {
clearMenu();
buildMenu();
}
void SinkInputWidget::clearMenu() {
while (!sinkMenuItems.empty()) {
std::map<uint32_t, SinkMenuItem*>::iterator i = sinkMenuItems.begin();
delete i->second;
sinkMenuItems.erase(i);
}
}
void SinkInputWidget::buildMenu() {
for (std::map<uint32_t, SinkWidget*>::iterator i = mpMainWindow->sinkWidgets.begin(); i != mpMainWindow->sinkWidgets.end(); ++i) {
SinkMenuItem *m;
sinkMenuItems[i->second->index] = m = new SinkMenuItem(this, i->second->description.c_str(), i->second->index, i->second->index == mSinkIndex);
submenu.append(m->menuItem);
}
menu.show_all();
}
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))) {
@ -129,21 +98,26 @@ void SinkInputWidget::onKill() {
} }
void SinkInputWidget::onDeviceChange() { void SinkInputWidget::onDeviceChange() {
} Gtk::TreeModel::iterator iter;
void SinkInputWidget::SinkMenuItem::onToggle() { if (updating || mSuppressDeviceChange)
if (widget->updating)
return; return;
if (!menuItem.get_active()) iter = deviceCombo->get_active();
return; if (iter)
{
Gtk::TreeModel::Row row = *iter;
if (row)
{
pa_operation* o;
uint32_t sink_index = row[mpMainWindow->deviceColumns.index];
pa_operation* o; if (!(o = pa_context_move_sink_input_by_index(get_context(), index, sink_index, NULL, NULL))) {
if (!(o = pa_context_move_sink_input_by_index(get_context(), widget->index, index, NULL, NULL))) { show_error(_("pa_context_move_sink_input_by_index() failed"));
show_error(_("pa_context_move_sink_input_by_index() failed")); return;
return; }
pa_operation_unref(o);
}
} }
pa_operation_unref(o);
} }

View File

@ -31,7 +31,6 @@ class SinkInputWidget : public StreamWidget {
public: public:
SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x); SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x);
static SinkInputWidget* create(MainWindow* mainWindow); static SinkInputWidget* create(MainWindow* mainWindow);
virtual ~SinkInputWidget();
void init(MainWindow* mainWindow); void init(MainWindow* mainWindow);
@ -44,31 +43,6 @@ public:
virtual void onDeviceChange(); virtual void onDeviceChange();
virtual void onMuteToggleButton(); virtual void onMuteToggleButton();
virtual void onKill(); virtual void onKill();
virtual void prepareMenu();
Gtk::Menu submenu;
Gtk::MenuItem titleMenuItem;
struct SinkMenuItem {
SinkMenuItem(SinkInputWidget *w, const char *label, uint32_t i, bool active) :
widget(w),
menuItem(label),
index(i) {
menuItem.set_active(active);
menuItem.set_draw_as_radio(true);
menuItem.signal_toggled().connect(sigc::mem_fun(*this, &SinkMenuItem::onToggle));
}
SinkInputWidget *widget;
Gtk::CheckMenuItem menuItem;
uint32_t index;
void onToggle();
};
std::map<uint32_t, SinkMenuItem*> sinkMenuItems;
void clearMenu();
void buildMenu();
private: private:
MainWindow *mpMainWindow; MainWindow *mpMainWindow;

View File

@ -27,15 +27,7 @@
#include "i18n.h" #include "i18n.h"
SinkWidget::SinkWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : SinkWidget::SinkWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
DeviceWidget(cobject, x), DeviceWidget(cobject, x) {
defaultMenuItem("_Default", true){
add_events(Gdk::BUTTON_PRESS_MASK);
defaultMenuItem.set_active(false);
defaultMenuItem.signal_toggled().connect(sigc::mem_fun(*this, &SinkWidget::onDefaultToggle));
menu.append(defaultMenuItem);
menu.show_all();
} }
SinkWidget* SinkWidget::create() { SinkWidget* SinkWidget::create() {
@ -71,9 +63,11 @@ void SinkWidget::onMuteToggleButton() {
pa_operation_unref(o); pa_operation_unref(o);
} }
void SinkWidget::onDefaultToggle() { void SinkWidget::onDefaultToggleButton() {
pa_operation* o; pa_operation* o;
DeviceWidget::onDefaultToggleButton();
if (updating) if (updating)
return; return;

View File

@ -36,11 +36,9 @@ public:
uint32_t index, monitor_index, card_index; uint32_t index, monitor_index, card_index;
bool can_decibel; bool can_decibel;
Gtk::CheckMenuItem defaultMenuItem;
virtual void onMuteToggleButton(); virtual void onMuteToggleButton();
virtual void executeVolumeUpdate(); virtual void executeVolumeUpdate();
virtual void onDefaultToggle(); virtual void onDefaultToggleButton();
}; };
#endif #endif

View File

@ -30,15 +30,9 @@
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),
titleMenuItem(_("_Move Stream..."), true),
mpMainWindow(NULL) { mpMainWindow(NULL) {
directionLabel->set_label(_("<i>Recording from </i> ")); directionLabel->set_label(_("<i>Recording from </i> "));
add_events(Gdk::BUTTON_PRESS_MASK);
menu.append(titleMenuItem);
titleMenuItem.set_submenu(submenu);
} }
void SourceOutputWidget::init(MainWindow* mainWindow) { void SourceOutputWidget::init(MainWindow* mainWindow) {
@ -47,10 +41,6 @@ void SourceOutputWidget::init(MainWindow* mainWindow) {
deviceCombo->pack_start(mpMainWindow->deviceColumns.name); deviceCombo->pack_start(mpMainWindow->deviceColumns.name);
} }
SourceOutputWidget::~SourceOutputWidget() {
clearMenu();
}
SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) { SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) {
SourceOutputWidget* w; SourceOutputWidget* w;
Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "streamWidget"); Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "streamWidget");
@ -61,7 +51,10 @@ SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) {
void SourceOutputWidget::setSourceIndex(uint32_t idx) { void SourceOutputWidget::setSourceIndex(uint32_t idx) {
mSourceIndex = idx; mSourceIndex = idx;
mSuppressDeviceChange = true;
deviceCombo->set_active(mpMainWindow->sourceTreeIndexes[idx]); deviceCombo->set_active(mpMainWindow->sourceTreeIndexes[idx]);
mSuppressDeviceChange = false;
} }
uint32_t SourceOutputWidget::sourceIndex() { uint32_t SourceOutputWidget::sourceIndex() {
@ -78,46 +71,27 @@ void SourceOutputWidget::onKill() {
pa_operation_unref(o); pa_operation_unref(o);
} }
void SourceOutputWidget::clearMenu() {
while (!sourceMenuItems.empty()) {
std::map<uint32_t, SourceMenuItem*>::iterator i = sourceMenuItems.begin();
delete i->second;
sourceMenuItems.erase(i);
}
}
void SourceOutputWidget::buildMenu() {
for (std::map<uint32_t, SourceWidget*>::iterator i = mpMainWindow->sourceWidgets.begin(); i != mpMainWindow->sourceWidgets.end(); ++i) {
SourceMenuItem *m;
sourceMenuItems[i->second->index] = m = new SourceMenuItem(this, i->second->description.c_str(), i->second->index, i->second->index == mSourceIndex);
submenu.append(m->menuItem);
}
menu.show_all();
}
void SourceOutputWidget::prepareMenu(void) {
clearMenu();
buildMenu();
}
void SourceOutputWidget::onDeviceChange() { void SourceOutputWidget::onDeviceChange() {
} Gtk::TreeModel::iterator iter;
void SourceOutputWidget::SourceMenuItem::onToggle() { if (updating || mSuppressDeviceChange)
if (widget->updating)
return; return;
if (!menuItem.get_active()) iter = deviceCombo->get_active();
return; if (iter)
{
Gtk::TreeModel::Row row = *iter;
if (row)
{
pa_operation* o;
uint32_t source_index = row[mpMainWindow->deviceColumns.index];
pa_operation* o; if (!(o = pa_context_move_source_output_by_index(get_context(), source_index, index, NULL, NULL))) {
if (!(o = pa_context_move_source_output_by_index(get_context(), widget->index, index, NULL, NULL))) { show_error(_("pa_context_move_source_output_by_index() failed"));
show_error(_("pa_context_move_source_output_by_index() failed")); return;
return; }
pa_operation_unref(o);
}
} }
pa_operation_unref(o);
} }

View File

@ -31,7 +31,6 @@ class SourceOutputWidget : public StreamWidget {
public: public:
SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x); SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x);
static SourceOutputWidget* create(MainWindow* mainWindow); static SourceOutputWidget* create(MainWindow* mainWindow);
virtual ~SourceOutputWidget();
void init(MainWindow* mainWindow); void init(MainWindow* mainWindow);
@ -43,31 +42,6 @@ public:
virtual void onDeviceChange(); virtual void onDeviceChange();
virtual void onKill(); virtual void onKill();
Gtk::Menu submenu;
Gtk::MenuItem titleMenuItem;
struct SourceMenuItem {
SourceMenuItem(SourceOutputWidget *w, const char *label, uint32_t i, bool active) :
widget(w),
menuItem(label),
index(i) {
menuItem.set_active(active);
menuItem.set_draw_as_radio(true);
menuItem.signal_toggled().connect(sigc::mem_fun(*this, &SourceMenuItem::onToggle));
}
SourceOutputWidget *widget;
Gtk::CheckMenuItem menuItem;
uint32_t index;
void onToggle();
};
std::map<uint32_t, SourceMenuItem*> sourceMenuItems;
void clearMenu();
void buildMenu();
virtual void prepareMenu();
private: private:
MainWindow *mpMainWindow; MainWindow *mpMainWindow;
uint32_t mSourceIndex; uint32_t mSourceIndex;

View File

@ -27,15 +27,7 @@
#include "i18n.h" #include "i18n.h"
SourceWidget::SourceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : SourceWidget::SourceWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
DeviceWidget(cobject, x), DeviceWidget(cobject, x) {
defaultMenuItem(_("_Default"), true){
add_events(Gdk::BUTTON_PRESS_MASK);
defaultMenuItem.set_active(false);
defaultMenuItem.signal_toggled().connect(sigc::mem_fun(*this, &SourceWidget::onDefaultToggle));
menu.append(defaultMenuItem);
menu.show_all();
} }
SourceWidget* SourceWidget::create() { SourceWidget* SourceWidget::create() {
@ -71,9 +63,11 @@ void SourceWidget::onMuteToggleButton() {
pa_operation_unref(o); pa_operation_unref(o);
} }
void SourceWidget::onDefaultToggle() { void SourceWidget::onDefaultToggleButton() {
pa_operation* o; pa_operation* o;
DeviceWidget::onDefaultToggleButton();
if (updating) if (updating)
return; return;

View File

@ -36,11 +36,9 @@ public:
uint32_t index, card_index; uint32_t index, card_index;
bool can_decibel; bool can_decibel;
Gtk::CheckMenuItem defaultMenuItem;
virtual void onMuteToggleButton(); virtual void onMuteToggleButton();
virtual void executeVolumeUpdate(); virtual void executeVolumeUpdate();
virtual void onDefaultToggle(); virtual void onDefaultToggleButton();
}; };
#endif #endif

View File

@ -27,7 +27,8 @@
/*** 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),
mSuppressDeviceChange(false) {
x->get_widget("lockToggleButton", lockToggleButton); x->get_widget("lockToggleButton", lockToggleButton);
x->get_widget("muteToggleButton", muteToggleButton); x->get_widget("muteToggleButton", muteToggleButton);

View File

@ -45,9 +45,9 @@ public:
ChannelWidget *channelWidgets[PA_CHANNELS_MAX]; ChannelWidget *channelWidgets[PA_CHANNELS_MAX];
virtual void onKill();
virtual void onDeviceChange() = 0;
virtual void onMuteToggleButton(); virtual void onMuteToggleButton();
virtual void onDeviceChange() = 0;
virtual void onKill();
sigc::connection timeoutConnection; sigc::connection timeoutConnection;
@ -59,6 +59,8 @@ public:
protected: protected:
Gtk::ComboBox *deviceCombo; Gtk::ComboBox *deviceCombo;
bool mSuppressDeviceChange;
}; };
#endif #endif