Set the mainwindow pointer via an init() method rather than directly via public member variable.

This allows us to perform other general initialisation task (such as setting the tree model on the device combo)
This commit is contained in:
Colin Guthrie 2009-03-16 20:18:01 +00:00
parent 7b7a12f1d2
commit d617c39a08
5 changed files with 36 additions and 16 deletions

View File

@ -469,12 +469,11 @@ void MainWindow::updateSinkInput(const pa_sink_input_info &info) {
if (sinkInputWidgets.count(info.index))
w = sinkInputWidgets[info.index];
else {
sinkInputWidgets[info.index] = w = SinkInputWidget::create();
sinkInputWidgets[info.index] = w = SinkInputWidget::create(this);
w->setChannelMap(info.channel_map, true);
streamsVBox->pack_start(*w, false, false, 0);
w->index = info.index;
w->clientIndex = info.client;
w->mainWindow = this;
is_new = true;
if (pa_context_get_server_protocol_version(get_context()) >= 13)
@ -521,11 +520,10 @@ void MainWindow::updateSourceOutput(const pa_source_output_info &info) {
if (sourceOutputWidgets.count(info.index))
w = sourceOutputWidgets[info.index];
else {
sourceOutputWidgets[info.index] = w = SourceOutputWidget::create();
sourceOutputWidgets[info.index] = w = SourceOutputWidget::create(this);
recsVBox->pack_start(*w, false, false, 0);
w->index = info.index;
w->clientIndex = info.client;
w->mainWindow = this;
}
w->updating = true;

View File

@ -30,9 +30,9 @@
SinkInputWidget::SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
StreamWidget(cobject, x),
mainWindow(NULL),
titleMenuItem(_("_Move Stream..."), true),
killMenuItem(_("_Terminate Stream"), true) {
killMenuItem(_("_Terminate Stream"), true),
mpMainWindow(NULL) {
directionLabel->set_label(_("<i>Playing on </i> "));
@ -45,14 +45,20 @@ SinkInputWidget::SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gno
killMenuItem.signal_activate().connect(sigc::mem_fun(*this, &SinkInputWidget::onKill));
}
void SinkInputWidget::init(MainWindow* mainWindow) {
mpMainWindow = mainWindow;
deviceCombo->set_model(mpMainWindow->sinkTree);
}
SinkInputWidget::~SinkInputWidget() {
clearMenu();
}
SinkInputWidget* SinkInputWidget::create() {
SinkInputWidget* SinkInputWidget::create(MainWindow* mainWindow) {
SinkInputWidget* w;
Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "streamWidget");
x->get_widget_derived("streamWidget", w);
w->init(mainWindow);
return w;
}
@ -97,7 +103,7 @@ void SinkInputWidget::clearMenu() {
}
void SinkInputWidget::buildMenu() {
for (std::map<uint32_t, SinkWidget*>::iterator i = mainWindow->sinkWidgets.begin(); i != mainWindow->sinkWidgets.end(); ++i) {
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 == sinkIndex);
submenu.append(m->menuItem);

View File

@ -30,9 +30,11 @@ class MainWindow;
class SinkInputWidget : public StreamWidget {
public:
SinkInputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x);
static SinkInputWidget* create();
static SinkInputWidget* create(MainWindow* mainWindow);
virtual ~SinkInputWidget();
void init(MainWindow* mainWindow);
SinkInputType type;
uint32_t index, clientIndex, sinkIndex;
@ -42,7 +44,6 @@ public:
virtual void onKill();
virtual void prepareMenu();
MainWindow *mainWindow;
Gtk::Menu submenu;
Gtk::MenuItem titleMenuItem, killMenuItem;
@ -66,6 +67,10 @@ public:
void clearMenu();
void buildMenu();
private:
MainWindow *mpMainWindow;
};
#endif

View File

@ -30,9 +30,9 @@
SourceOutputWidget::SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x) :
StreamWidget(cobject, x),
mainWindow(NULL),
titleMenuItem(_("_Move Stream..."), true),
killMenuItem(_("_Terminate Stream"), true) {
killMenuItem(_("_Terminate Stream"), true),
mpMainWindow(NULL) {
directionLabel->set_label(_("<i>Recording from </i> "));
@ -45,14 +45,20 @@ SourceOutputWidget::SourceOutputWidget(BaseObjectType* cobject, const Glib::RefP
killMenuItem.signal_activate().connect(sigc::mem_fun(*this, &SourceOutputWidget::onKill));
}
void SourceOutputWidget::init(MainWindow* mainWindow) {
mpMainWindow = mainWindow;
deviceCombo->set_model(mpMainWindow->sourceTree);
}
SourceOutputWidget::~SourceOutputWidget() {
clearMenu();
}
SourceOutputWidget* SourceOutputWidget::create() {
SourceOutputWidget* SourceOutputWidget::create(MainWindow* mainWindow) {
SourceOutputWidget* w;
Glib::RefPtr<Gnome::Glade::Xml> x = Gnome::Glade::Xml::create(GLADE_FILE, "streamWidget");
x->get_widget_derived("streamWidget", w);
w->init(mainWindow);
return w;
}
@ -76,7 +82,7 @@ void SourceOutputWidget::clearMenu() {
}
void SourceOutputWidget::buildMenu() {
for (std::map<uint32_t, SourceWidget*>::iterator i = mainWindow->sourceWidgets.begin(); i != mainWindow->sourceWidgets.end(); ++i) {
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 == sourceIndex);
submenu.append(m->menuItem);

View File

@ -30,16 +30,17 @@ class MainWindow;
class SourceOutputWidget : public StreamWidget {
public:
SourceOutputWidget(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& x);
static SourceOutputWidget* create();
static SourceOutputWidget* create(MainWindow* mainWindow);
virtual ~SourceOutputWidget();
void init(MainWindow* mainWindow);
SourceOutputType type;
uint32_t index, clientIndex, sourceIndex;
virtual void onDeviceChange();
virtual void onKill();
MainWindow *mainWindow;
Gtk::Menu submenu;
Gtk::MenuItem titleMenuItem, killMenuItem;
@ -64,6 +65,10 @@ public:
void clearMenu();
void buildMenu();
virtual void prepareMenu();
private:
MainWindow *mpMainWindow;
};
#endif