#include #include #include #include "paman.hh" #include "MainWindow.hh" #define GLADE_NAME "mainWindow" enum { ROW_TYPE_SINK_CATEGORY, ROW_TYPE_SOURCE_CATEGORY, ROW_TYPE_SINK, ROW_TYPE_SOURCE, }; MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr& refGlade) : Gtk::Window(cobject), statusLabel(NULL), serverNameLabel(NULL), serverVersionLabel(NULL), defaultSampleTypeLabel(NULL), userNameLabel(NULL), hostNameLabel(NULL), deviceOpenButton(NULL), moduleOpenButton(NULL), connectButton(NULL), deviceTreeView(NULL), moduleTreeView(NULL) { refGlade->get_widget("statusLabel", statusLabel); refGlade->get_widget("serverNameLabel", serverNameLabel); refGlade->get_widget("serverVersionLabel", serverVersionLabel); refGlade->get_widget("defaultSampleTypeLabel", defaultSampleTypeLabel); refGlade->get_widget("hostNameLabel", hostNameLabel); refGlade->get_widget("userNameLabel", userNameLabel); refGlade->get_widget("deviceTreeView", deviceTreeView); refGlade->get_widget("moduleTreeView", moduleTreeView); refGlade->get_widget("deviceOpenButton", deviceOpenButton); refGlade->get_widget("moduleOpenButton", moduleOpenButton); refGlade->get_widget("connectButton", connectButton); deviceTreeStore = Gtk::TreeStore::create(deviceTreeModelColumns); deviceTreeView->set_model(deviceTreeStore); deviceTreeView->append_column("Name", deviceTreeModelColumns.name); deviceTreeView->append_column("Description", deviceTreeModelColumns.description); deviceTreeView->signal_row_activated().connect(sigc::mem_fun(*this, &MainWindow::onDeviceTreeViewRowActivated)); deviceTreeView->signal_cursor_changed().connect(sigc::mem_fun(*this, &MainWindow::onDeviceTreeViewCursorChanged)); connectButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onConnectButton)); deviceOpenButton->signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::onDeviceOpenButton)); statusLabel->set_text("Connecting ..."); clearAllData(); } MainWindow::~MainWindow() { } MainWindow* MainWindow::create() { MainWindow *w; Glib::RefPtr refXml = Gnome::Glade::Xml::create(GLADE_FILE, GLADE_NAME); refXml->get_widget_derived(GLADE_NAME, w); return w; } 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; deviceTreeView->expand_row(i.treePath, false); } 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; 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); deviceOpenButton->set_sensitive(sourcePath != p && sinkPath != p); } void MainWindow::onDeviceTreeViewRowActivated(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* /* column */) { Gtk::TreeModel::Row row = *(deviceTreeModel->get_iter(path)); if (!serverInfo) return; if (row[deviceTreeModelColumns.type] == ROW_TYPE_SINK) serverInfo->showSinkWindow(row[deviceTreeModelColumns.index]); else if (row[deviceTreeModelColumns.type] == ROW_TYPE_SOURCE) serverInfo->showSourceWindow(row[deviceTreeModelColumns.index]); } void MainWindow::updateInfo(const struct pa_server_info &i) { char t[PA_SAMPLE_SNPRINT_MAX_LENGTH]; serverNameLabel->set_text(i.server_name); serverVersionLabel->set_text(i.server_version); pa_sample_snprint(t, sizeof(t), &i.sample_spec); defaultSampleTypeLabel->set_text(t); hostNameLabel->set_text(i.host_name); userNameLabel->set_text(i.user_name); } void MainWindow::showSuccess(const char *t) { statusLabel->set_text(t); } void MainWindow::showFailure(const char *t) { char s[256]; snprintf(s, sizeof(s), "Failure: %s", t); statusLabel->set_markup(s); } void MainWindow::clearAllData() { Gtk::TreeIter i; deviceTreeModel->clear(); 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); serverNameLabel->set_markup("n/a"); serverVersionLabel->set_markup("n/a"); defaultSampleTypeLabel->set_markup("n/a"); hostNameLabel->set_markup("n/a"); userNameLabel->set_markup("n/a"); } void MainWindow::onDeviceOpenButton() { Gtk::TreeModel::Path p; Gtk::TreeViewColumn *c; deviceTreeView->get_cursor(p, c); Gtk::TreeModel::Row row = *(deviceTreeModel->get_iter(p)); if (!serverInfo) return; if (row[deviceTreeModelColumns.type] == ROW_TYPE_SINK) serverInfo->showSinkWindow(row[deviceTreeModelColumns.index]); else if (row[deviceTreeModelColumns.type] == ROW_TYPE_SOURCE) serverInfo->showSourceWindow(row[deviceTreeModelColumns.index]); } void MainWindow::onConnectButton() { create_connection(); }