From 1f9bb4bea5427c1bf236e8698855048ef35f3a81 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 11 Aug 2004 15:11:05 +0000 Subject: half work git-svn-id: file:///home/lennart/svn/public/paman/trunk@4 cdefa82f-4ce1-0310-97f5-ab6066f37c3c --- MainWindow.cc | 68 +++++--- MainWindow.hh | 11 +- ServerInfo.cc | 67 +++++++- ServerInfo.hh | 9 ++ paman.glade | 490 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 613 insertions(+), 32 deletions(-) diff --git a/MainWindow.cc b/MainWindow.cc index 5db98fc..2e39b82 100644 --- a/MainWindow.cc +++ b/MainWindow.cc @@ -40,8 +40,8 @@ MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtrget_widget("moduleOpenButton", moduleOpenButton); refGlade->get_widget("connectButton", connectButton); - deviceTreeModel = Gtk::TreeStore::create(deviceTreeModelColumns); - deviceTreeView->set_model(deviceTreeModel); + deviceTreeStore = Gtk::TreeStore::create(deviceTreeModelColumns); + deviceTreeView->set_model(deviceTreeStore); deviceTreeView->append_column("Name", deviceTreeModelColumns.name); deviceTreeView->append_column("Description", deviceTreeModelColumns.description); @@ -67,37 +67,60 @@ MainWindow* MainWindow::create() { return w; } -void MainWindow::updateInfo(const SinkInfo &i) { - Gtk::TreeModel::Row row = *(deviceTreeModel->append(sinkRow.children())); +void MainWindow::updateInfo(SinkInfo &i) { + if (!i.treePathValid) { + Gtk::TreeIter iter = deviceTreeStore.get_iter(sinkPath); + i.treePath = deviceTreeStore->append(iter.children()); + i.treePathValid = true; + } + Gtk::TreeRow row = *(Gtk::TreeIter(i.treePath)) row[deviceTreeModelColumns.name] = i.name; row[deviceTreeModelColumns.description] = i.description; row[deviceTreeModelColumns.index] = i.index; row[deviceTreeModelColumns.type] = ROW_TYPE_SINK; - Gtk::TreePath p(sinkRow); - deviceTreeView->expand_row(p, false); + deviceTreeView->expand_row(i.treePath, false); } -void MainWindow::updateInfo(const SourceInfo &i) { - Gtk::TreeModel::Row row = *(deviceTreeModel->append(sourceRow.children())); +void MainWindow::updateInfo(SourceInfo &i) { + if (!i.treePathValid) { + Gtk::TreeIter iter = sourcePath; + i.treePath = deviceTreeModel->append(iter.children()); + i.treePathValid = true; + } + Gtk::TreeRow row(Gtk::TreeIter(i.treePath)) row[deviceTreeModelColumns.name] = i.name; row[deviceTreeModelColumns.description] = i.description; row[deviceTreeModelColumns.index] = i.index; row[deviceTreeModelColumns.type] = ROW_TYPE_SOURCE; - Gtk::TreePath p(sourceRow); - deviceTreeView->expand_row(p, false); + deviceTreeView->expand_row(i.treePath, false); +} + +void MainWindow::removeInfo(SinkInfo &i) { + if (!i.treePathValid) + return; + + deviceTreeModel->erase(Gtk::TreeIter(i.treePath)); + i.treePathValid = false; +} + +void MainWindow::removeInfo(SourceInfo &i) { + if (!i.treePathValid) + return; + + deviceTreeModel->erase(Gtk::TreeIter(i.treePath)); + i.treePathValid = false; } void MainWindow::onDeviceTreeViewCursorChanged() { Gtk::TreeModel::Path p; Gtk::TreeViewColumn *c; deviceTreeView->get_cursor(p, c); - Gtk::TreeModel::Row row = *(deviceTreeModel->get_iter(p)); - deviceOpenButton->set_sensitive(row != sourceRow && row != sinkRow); + deviceOpenButton->set_sensitive(sourcePath != p && sinkPath != p); } void MainWindow::onDeviceTreeViewRowActivated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */) { @@ -133,17 +156,20 @@ void MainWindow::showFailure(const char *t) { } void MainWindow::clearAllData() { + Gtk::TreeIter i; deviceTreeModel->clear(); - sinkRow = *(deviceTreeModel->append()); - sinkRow[deviceTreeModelColumns.name] = "Sinks"; - sinkRow[deviceTreeModelColumns.index] = -1; - sinkRow[deviceTreeModelColumns.type] = ROW_TYPE_SINK_CATEGORY; - - sourceRow = *(deviceTreeModel->append()); - sourceRow[deviceTreeModelColumns.name] = "Sources"; - sourceRow[deviceTreeModelColumns.index] = -1; - sourceRow[deviceTreeModelColumns.type] = ROW_TYPE_SOURCE_CATEGORY; + i = deviceTreeModel->append(); + sinkPath = i; + *i[deviceTreeModelColumns.name] = "Sinks"; + *i[deviceTreeModelColumns.index] = -1; + *i[deviceTreeModelColumns.type] = ROW_TYPE_SINK_CATEGORY; + + i = deviceTreeModel->append(); + sourcePath = i; + *i[deviceTreeModelColumns.name] = "Sources"; + *i[deviceTreeModelColumns.index] = -1; + *i[deviceTreeModelColumns.type] = ROW_TYPE_SOURCE_CATEGORY; deviceOpenButton->set_sensitive(false); moduleOpenButton->set_sensitive(false); diff --git a/MainWindow.hh b/MainWindow.hh index 635e66d..d13dca3 100644 --- a/MainWindow.hh +++ b/MainWindow.hh @@ -47,14 +47,17 @@ protected: }; DeviceTreeModelColumns deviceTreeModelColumns; - Glib::RefPtr deviceTreeModel; + Glib::RefPtr deviceTreeStore; - Gtk::TreeModel::Row sinkRow, sourceRow; + Gtk::TreePath sinkPath, sourcePath; public: virtual void updateInfo(const struct pa_server_info &i); - virtual void updateInfo(const SinkInfo &i); - virtual void updateInfo(const SourceInfo &i); + virtual void updateInfo(SinkInfo &i); + virtual void updateInfo(SourceInfo &i); + + virtual void removeInfo(SinkInfo &i); + virtual void removeInfo(SourceInfo &i); virtual void onDeviceTreeViewCursorChanged(); virtual void onDeviceTreeViewRowActivated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */); diff --git a/ServerInfo.cc b/ServerInfo.cc index 763f150..ccda5b1 100644 --- a/ServerInfo.cc +++ b/ServerInfo.cc @@ -13,7 +13,8 @@ SinkInfo::SinkInfo(const struct pa_sink_info &i) : owner_module(i.owner_module), volume(i.volume), latency(i.latency), - sinkWindow(NULL) { + sinkWindow(NULL), + treePathValid(false) { } SinkInfo::~SinkInfo() { @@ -52,7 +53,8 @@ SourceInfo::SourceInfo(const struct pa_source_info &i) : sample_spec(i.sample_spec), owner_module(i.owner_module), monitor_of_sink(i.monitor_of_sink), - sourceWindow(NULL) { + sourceWindow(NULL), + treePathValid(false) { } SourceInfo::~SourceInfo() { @@ -95,21 +97,62 @@ static void server_info_callback(struct pa_context *c, const struct pa_server_in static void sink_info_callback(struct pa_context *c, const struct pa_sink_info *i, int is_last, void *userdata) { ServerInfo *si = (ServerInfo*) userdata; - if (!is_last) + if (!is_last && i) si->updateInfo(*i); } static void source_info_callback(struct pa_context *c, const struct pa_source_info *i, int is_last, void *userdata) { ServerInfo *si = (ServerInfo*) userdata; - if (!is_last) + if (!is_last && i) si->updateInfo(*i); } +static void subscribe_callback(struct pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata) { + ServerInfo *si = (ServerInfo*) userdata; + + fprintf(stderr, "EV: %u %u\n", t, index); + + switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { + case PA_SUBSCRIPTION_EVENT_SINK: + fprintf(stderr, "SINK EVENT\n"); + + if (t & PA_SUBSCRIPTION_EVENT_TYPE_MASK == PA_SUBSCRIPTION_EVENT_REMOVE) + si->removeSinkInfo(index); + else + pa_context_get_sink_info_by_index(c, index, sink_info_callback, si); + break; + case PA_SUBSCRIPTION_EVENT_SOURCE: + fprintf(stderr, "SOURCE EVENT\n"); + + if (t & PA_SUBSCRIPTION_EVENT_TYPE_MASK == PA_SUBSCRIPTION_EVENT_REMOVE) + si->removeSourceInfo(index); + else + pa_context_get_source_info_by_index(c, index, source_info_callback, si); + break; + case PA_SUBSCRIPTION_EVENT_MODULE: + fprintf(stderr, "MODULE EVENT\n"); + break; + case PA_SUBSCRIPTION_EVENT_CLIENT: + fprintf(stderr, "CLIENT EVENT\n"); + break; + case PA_SUBSCRIPTION_EVENT_SINK_INPUT: + fprintf(stderr, "SINK INPUT EVENT\n"); + break; + case PA_SUBSCRIPTION_EVENT_SOURCE_OUTPUT: + fprintf(stderr, "SOURCE OUTPUT EVENT\n"); + break; + default: + fprintf(stderr, "OTHER EVENT\n"); + break; + } +} + ServerInfo::ServerInfo(struct pa_context &c) : context(c) { pa_context_get_server_info(&c, server_info_callback, this); pa_context_get_sink_info_list(&c, sink_info_callback, this); pa_context_get_source_info_list(&c, source_info_callback, this); + pa_context_subscribe(&c, (enum pa_subscription_mask) (PA_SUBSCRIPTION_FACILITY_SINK|PA_SUBSCRIPTION_FACILITY_SOURCE|PA_SUBSCRIPTION_FACILITY_MODULE|PA_SUBSCRIPTION_FACILITY_SINK_INPUT|PA_SUBSCRIPTION_FACILITY_SOURCE_OUTPUT|PA_SUBSCRIPTION_FACILITY_CLIENT), subscribe_callback, this); } ServerInfo::~ServerInfo() { @@ -163,3 +206,19 @@ SourceInfo* ServerInfo::getSourceInfo(uint32_t index) { SinkInfo* ServerInfo::getSinkInfo(uint32_t index) { return sinks[index]; } + +void ServerInfo::removeSinkInfo(uint32_t index) { + SinkInfo *i; + if ((i = sinks[index])) { + sinks.erase(index); + delete i; + } +} + +void ServerInfo::removeSourceInfo(uint32_t index) { + SourceInfo *i; + if ((i = sources[index])) { + sources.erase(index); + delete i; + } +} diff --git a/ServerInfo.hh b/ServerInfo.hh index 6dea7a9..f6db437 100644 --- a/ServerInfo.hh +++ b/ServerInfo.hh @@ -31,6 +31,9 @@ public: uint32_t volume; uint32_t latency; + Gtk::TreePath treePath; + bool treePathValid; + SinkWindow *sinkWindow; }; @@ -48,6 +51,9 @@ public: uint32_t owner_module; uint32_t monitor_of_sink; + Gtk::TreePath treePath; + bool treePathValid; + SourceWindow *sourceWindow; }; @@ -64,6 +70,9 @@ public: SourceInfo* getSourceInfo(uint32_t index); SinkInfo* getSinkInfo(uint32_t index); + + void removeSinkInfo(uint32_t index); + void removeSourceInfo(uint32_t index); protected: std::map sinks; diff --git a/paman.glade b/paman.glade index 07eeb12..d95bc7c 100644 --- a/paman.glade +++ b/paman.glade @@ -10,8 +10,8 @@ GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False - 400 - 300 + 500 + 400 True False True @@ -61,7 +61,7 @@ True 5 2 - False + True 5 10 @@ -569,6 +569,149 @@ + + + 5 + True + False + 5 + + + + True + True + GTK_POLICY_AUTOMATIC + GTK_POLICY_AUTOMATIC + GTK_SHADOW_IN + GTK_CORNER_TOP_LEFT + + + + True + True + True + False + False + True + + + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_END + 0 + + + + True + False + True + True + GTK_RELIEF_NORMAL + True + + + + True + 0.5 + 0.5 + 0 + 0 + 0 + 0 + 0 + 0 + + + + True + False + 2 + + + + True + gtk-jump-to + 4 + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + _Open + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + + + + + + 0 + False + False + + + + + False + True + + + + + + True + _Clients + True + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + 5 @@ -1672,4 +1815,345 @@ + + True + window1 + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + False + False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST + + + + 5 + True + False + 5 + + + + True + True + True + True + GTK_POS_TOP + False + False + + + + 5 + True + 5 + 2 + False + 5 + 10 + + + + True + <b>Name:</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 0 + 1 + fill + + + + + + + True + <b>Autoloaded:</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 3 + 4 + fill + + + + + + + True + label4724 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 4 + 5 + fill + + + + + + + True + label4725 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 3 + 4 + fill + + + + + + + True + <b>Usage:</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 4 + 5 + fill + + + + + + + True + label4727 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 2 + 3 + fill + + + + + + + True + label4728 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 1 + 2 + fill + + + + + + + True + label4729 + False + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0.5 + 0 + 0 + + + 1 + 2 + 0 + 1 + fill + + + + + + + True + <b>Arguments:</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 1 + 2 + fill + + + + + + + True + <b>Index:</b> + False + True + GTK_JUSTIFY_LEFT + False + False + 1 + 0.5 + 0 + 0 + + + 0 + 1 + 2 + 3 + fill + + + + + + False + True + + + + + + True + Basic + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + tab + + + + + 0 + True + True + + + + + + True + GTK_BUTTONBOX_END + 0 + + + + True + True + True + gtk-close + True + GTK_RELIEF_NORMAL + True + + + + + 0 + False + False + + + + + + -- cgit