From 72f6cf7ca0d0baaef7fb0171e0d14cce50d1ef04 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 18 Aug 2004 01:01:12 +0000 Subject: add support for statwindow git-svn-id: file:///home/lennart/svn/public/paman/trunk@15 cdefa82f-4ce1-0310-97f5-ab6066f37c3c --- src/StatWindow.cc | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/StatWindow.cc (limited to 'src/StatWindow.cc') diff --git a/src/StatWindow.cc b/src/StatWindow.cc new file mode 100644 index 0000000..7adb752 --- /dev/null +++ b/src/StatWindow.cc @@ -0,0 +1,77 @@ +#include "paman.hh" +#include "StatWindow.hh" + +#define GLADE_NAME "statWindow" + +StatWindow::StatWindow(BaseObjectType* cobject, const Glib::RefPtr& refGlade) : + Gtk::Window(cobject), + totalLabel(NULL), + totalSizeLabel(NULL), + allocatedLabel(NULL), + allocatedSizeLabel(NULL), + closeButton(NULL), + refreshButton(NULL), + operation(NULL) { + + refGlade->get_widget("totalLabel", totalLabel); + refGlade->get_widget("totalSizeLabel", totalSizeLabel); + refGlade->get_widget("allocatedLabel", allocatedLabel); + refGlade->get_widget("allocatedSizeLabel", allocatedSizeLabel); + refGlade->get_widget("closeButton", closeButton); + refGlade->get_widget("refreshButton", refreshButton); + + closeButton->signal_clicked().connect(sigc::mem_fun(*this, &StatWindow::onCloseButton)); + refreshButton->signal_clicked().connect(sigc::mem_fun(*this, &StatWindow::onRefreshButton)); + + onRefreshButton(); +} + +StatWindow::~StatWindow() { + + if (operation) { + pa_operation_cancel(operation); + pa_operation_unref(operation); + } +} + +StatWindow* StatWindow::create() { + StatWindow *w = NULL; + Glib::RefPtr refXml = Gnome::Glade::Xml::create(GLADE_FILE, GLADE_NAME); + refXml->get_widget_derived(GLADE_NAME, w); + return w; +} + +void StatWindow::onCloseButton() { + hide(); +} + +static void stat_cb(struct pa_context *c, const struct pa_stat_info *i, void *userdata) { + char t[20]; + StatWindow *s = (struct StatWindow*) userdata; + + snprintf(t, sizeof(t), "%u", i->memblock_total); + s->totalLabel->set_text(t); + snprintf(t, sizeof(t), "%u bytes", i->memblock_total_size); + s->totalSizeLabel->set_text(t); + snprintf(t, sizeof(t), "%u", i->memblock_allocated); + s->allocatedLabel->set_text(t); + snprintf(t, sizeof(t), "%u bytes", i->memblock_allocated_size); + s->allocatedSizeLabel->set_text(t); + + pa_operation_unref(s->operation); + s->operation = NULL; +} + +void StatWindow::onRefreshButton() { + if (operation) + return; + + g_assert(context); + operation = pa_context_stat(context, stat_cb, this); +} + +void StatWindow::present() { + Gtk::Window::present(); + + onRefreshButton(); +} -- cgit