From 4927458e91e708213b0713dd4d3898dda6ec35c1 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 10 Aug 2004 13:04:04 +0000 Subject: Initial commit git-svn-id: file:///home/lennart/svn/public/paman/trunk@3 cdefa82f-4ce1-0310-97f5-ab6066f37c3c --- paman.cc | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 paman.cc (limited to 'paman.cc') diff --git a/paman.cc b/paman.cc new file mode 100644 index 0000000..1bde0ba --- /dev/null +++ b/paman.cc @@ -0,0 +1,101 @@ +#include + +#include +#include + +#include +#include +#include + +#include "paman.hh" +#include "SinkWindow.hh" +#include "MainWindow.hh" + +MainWindow *mainWindow = NULL; +ServerInfo *serverInfo = NULL; +struct pa_context *context = NULL; +struct pa_mainloop_api *mainloop_api = NULL; + +static void context_complete_callback(struct pa_context *c, int success, void *userdata) { + g_assert(c && mainWindow && !serverInfo); + + if (!success) { + mainWindow->showFailure(pa_strerror(pa_context_errno(c))); + //pa_context_free(context); /* Mrprmfmfl! */ + context = NULL; + mainWindow->connectButton->set_sensitive(true); + return; + } + + mainWindow->showSuccess("Connected"); + mainWindow->connectButton->set_sensitive(false); + serverInfo = new ServerInfo(*c); +} + +static void die_callback(struct pa_context *c, void *userdata) { + mainWindow->clearAllData(); + mainWindow->showFailure(pa_strerror(pa_context_errno(c))); + delete serverInfo; + serverInfo = NULL; + //pa_context_free(contetx); /* Mrprmfmfl! */ + context = NULL; + mainWindow->connectButton->set_sensitive(true); +} + +void create_connection() { + if (serverInfo) { + delete serverInfo; + serverInfo = NULL; + } + if (context) { + pa_context_free(context); + context = NULL; + } + + mainWindow->showSuccess("Connecting ..."); + context = pa_context_new(mainloop_api, "Polypaudio Manager"); + g_assert(context); + pa_context_set_die_callback(context, die_callback, NULL); + + if (pa_context_connect(context, NULL, context_complete_callback, NULL) < 0) { + context_complete_callback(context, 0, NULL); + return; + } + + mainWindow->connectButton->set_sensitive(false); +} + +int main(int argc, char *argv[]) { + struct pa_glib_mainloop *m; + + signal(SIGPIPE, SIG_IGN); + + Gtk::Main kit(argc, argv); + + mainWindow = MainWindow::create(); + g_assert(mainWindow); + + m = pa_glib_mainloop_new(g_main_context_default()); + g_assert(m); + mainloop_api = pa_glib_mainloop_get_api(m); + g_assert(mainloop_api); + + create_connection(); + + Gtk::Main::run(*mainWindow); + +quit: + if (serverInfo) + delete serverInfo; + + if (context) + pa_context_free(context); + + mainloop_api = NULL; + if (mainWindow) + delete mainWindow; + + pa_glib_mainloop_free(m); + + return 0; +} -- cgit