diff options
author | Lennart Poettering <lennart@poettering.net> | 2004-08-10 13:04:04 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2004-08-10 13:04:04 +0000 |
commit | 4927458e91e708213b0713dd4d3898dda6ec35c1 (patch) | |
tree | e409fdc5d69f9858a737af0ad3ac9687e9994da5 /paman.cc | |
parent | fcd2f9f953fa3e97503c170208ff4c391f1a09ce (diff) |
Initial commit
git-svn-id: file:///home/lennart/svn/public/paman/trunk@3 cdefa82f-4ce1-0310-97f5-ab6066f37c3c
Diffstat (limited to 'paman.cc')
-rw-r--r-- | paman.cc | 101 |
1 files changed, 101 insertions, 0 deletions
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 <signal.h> + +#include <gtkmm.h> +#include <libglademm.h> + +#include <polyp/polyplib.h> +#include <polyp/glib-mainloop.h> +#include <polyp/polyplib-error.h> + +#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; +} |