Split out streamwidget into it's own files.

Also correct the location of the argument default value specification (it should be in prototype not implementation)
This commit is contained in:
Colin Guthrie 2009-03-15 13:02:56 +00:00
parent f6af4f80b8
commit e1e452ac22
4 changed files with 105 additions and 79 deletions

View File

@ -27,7 +27,7 @@ desktop_DATA=$(desktop_in_files:.desktop.in=.desktop)
pavucontrol_SOURCES= \ pavucontrol_SOURCES= \
minimalstreamwidget.h minimalstreamwidget.cc \ minimalstreamwidget.h minimalstreamwidget.cc \
channelwidget.h channelwidget.cc \ channelwidget.h channelwidget.cc \
streamwidget.h \ streamwidget.h streamwidget.cc \
pavucontrol.cc i18n.h pavucontrol.cc i18n.h
pavucontrol_LDADD=$(AM_LDADD) $(GUILIBS_LIBS) $(PULSE_LIBS) pavucontrol_LDADD=$(AM_LDADD) $(GUILIBS_LIBS) $(PULSE_LIBS)

View File

@ -73,7 +73,6 @@ enum SourceType{
SOURCE_MONITOR, SOURCE_MONITOR,
}; };
class StreamWidget;
class MainWindow; class MainWindow;
class CardWidget : public Gtk::VBox { class CardWidget : public Gtk::VBox {
@ -386,82 +385,6 @@ void CardWidget::onProfileChange() {
} }
/*** StreamWidget ***/
StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
MinimalStreamWidget(cobject, x) {
x->get_widget("lockToggleButton", lockToggleButton);
x->get_widget("muteToggleButton", muteToggleButton);
muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onMuteToggleButton));
for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
channelWidgets[i] = NULL;
}
void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
channelMap = m;
for (int i = 0; i < m.channels; i++) {
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
cw->beepDevice = beepDevice;
cw->channel = i;
cw->can_decibel = can_decibel;
cw->streamWidget = this;
char text[64];
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
cw->channelLabel->set_markup(text);
channelsVBox->pack_start(*cw, false, false, 0);
}
lockToggleButton->set_sensitive(m.channels > 1);
}
void StreamWidget::setVolume(const pa_cvolume &v, bool force = false) {
g_assert(v.channels == channelMap.channels);
volume = v;
if (timeoutConnection.empty() || force) { /* do not update the volume when a volume change is still in flux */
for (int i = 0; i < volume.channels; i++)
channelWidgets[i]->setVolume(volume.values[i]);
}
}
void StreamWidget::updateChannelVolume(int channel, pa_volume_t v) {
pa_cvolume n;
g_assert(channel < volume.channels);
n = volume;
if (lockToggleButton->get_active()) {
for (int i = 0; i < n.channels; i++)
n.values[i] = v;
} else
n.values[channel] = v;
setVolume(n, true);
if (timeoutConnection.empty())
timeoutConnection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &StreamWidget::timeoutEvent), 100);
}
void StreamWidget::onMuteToggleButton() {
lockToggleButton->set_sensitive(!muteToggleButton->get_active());
for (int i = 0; i < channelMap.channels; i++)
channelWidgets[i]->set_sensitive(!muteToggleButton->get_active());
}
bool StreamWidget::timeoutEvent() {
executeVolumeUpdate();
return false;
}
void StreamWidget::executeVolumeUpdate() {
}
SinkWidget::SinkWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) : SinkWidget::SinkWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
StreamWidget(cobject, x), StreamWidget(cobject, x),
defaultMenuItem("_Default", true){ defaultMenuItem("_Default", true){

99
src/streamwidget.cc Normal file
View File

@ -0,0 +1,99 @@
/***
This file is part of pavucontrol.
Copyright 2006-2008 Lennart Poettering
Copyright 2009 Colin Guthrie
pavucontrol 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, either version 2 of the License, or
(at your option) any later version.
pavucontrol 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.
You should have received a copy of the GNU General Public License
along with pavucontrol. If not, see <http://www.gnu.org/licenses/>.
***/
#include "streamwidget.h"
#include "channelwidget.h"
/*** StreamWidget ***/
StreamWidget::StreamWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
MinimalStreamWidget(cobject, x) {
x->get_widget("lockToggleButton", lockToggleButton);
x->get_widget("muteToggleButton", muteToggleButton);
muteToggleButton->signal_clicked().connect(sigc::mem_fun(*this, &StreamWidget::onMuteToggleButton));
for (unsigned i = 0; i < PA_CHANNELS_MAX; i++)
channelWidgets[i] = NULL;
}
void StreamWidget::setChannelMap(const pa_channel_map &m, bool can_decibel) {
channelMap = m;
for (int i = 0; i < m.channels; i++) {
ChannelWidget *cw = channelWidgets[i] = ChannelWidget::create();
cw->beepDevice = beepDevice;
cw->channel = i;
cw->can_decibel = can_decibel;
cw->streamWidget = this;
char text[64];
snprintf(text, sizeof(text), "<b>%s</b>", pa_channel_position_to_pretty_string(m.map[i]));
cw->channelLabel->set_markup(text);
channelsVBox->pack_start(*cw, false, false, 0);
}
lockToggleButton->set_sensitive(m.channels > 1);
}
void StreamWidget::setVolume(const pa_cvolume &v, bool force) {
g_assert(v.channels == channelMap.channels);
volume = v;
if (timeoutConnection.empty() || force) { /* do not update the volume when a volume change is still in flux */
for (int i = 0; i < volume.channels; i++)
channelWidgets[i]->setVolume(volume.values[i]);
}
}
void StreamWidget::updateChannelVolume(int channel, pa_volume_t v) {
pa_cvolume n;
g_assert(channel < volume.channels);
n = volume;
if (lockToggleButton->get_active()) {
for (int i = 0; i < n.channels; i++)
n.values[i] = v;
} else
n.values[channel] = v;
setVolume(n, true);
if (timeoutConnection.empty())
timeoutConnection = Glib::signal_timeout().connect(sigc::mem_fun(*this, &StreamWidget::timeoutEvent), 100);
}
void StreamWidget::onMuteToggleButton() {
lockToggleButton->set_sensitive(!muteToggleButton->get_active());
for (int i = 0; i < channelMap.channels; i++)
channelWidgets[i]->set_sensitive(!muteToggleButton->get_active());
}
bool StreamWidget::timeoutEvent() {
executeVolumeUpdate();
return false;
}
void StreamWidget::executeVolumeUpdate() {
}

View File

@ -28,14 +28,18 @@
#include <gtkmm.h> #include <gtkmm.h>
#include <libglademm.h> #include <libglademm.h>
#include <pulse/pulseaudio.h>
#include "minimalstreamwidget.h" #include "minimalstreamwidget.h"
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 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); void setVolume(const pa_cvolume &volume, bool force = false);
virtual void updateChannelVolume(int channel, pa_volume_t v); virtual void updateChannelVolume(int channel, pa_volume_t v);
Gtk::ToggleButton *lockToggleButton, *muteToggleButton; Gtk::ToggleButton *lockToggleButton, *muteToggleButton;