#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); deviceTreeModel = Gtk::TreeStore::create(deviceTreeModelColumns); deviceTreeView->set_model(deviceTreeModel); 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(const SinkInfo &i) { Gtk::TreeModel::Row row = *(deviceTreeModel->append(sinkRow.children())); 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); } void MainWindow::updateInfo(const SourceInfo &i) { Gtk::TreeModel::Row row = *(deviceTreeModel->append(sourceRow.children())); 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); } 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); } 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() { 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; 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(); }