summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2007-08-06 17:37:42 +0000
committerLennart Poettering <lennart@poettering.net>2007-08-06 17:37:42 +0000
commitd533143649fa9180133bb0953b7083948c879ac6 (patch)
treefb9c1ca8a1b1d7388d0a766caeefdc8192fdb5ed
parentb4a4dce0150b35a003576dca26423ac97b438a23 (diff)
Handle parameters properly
git-svn-id: file:///home/lennart/svn/public/pavumeter/trunk@49 c62a5a7b-6fe3-0310-9d5a-afe6de46906b
-rw-r--r--src/vumeter.cc105
1 files changed, 55 insertions, 50 deletions
diff --git a/src/vumeter.cc b/src/vumeter.cc
index b39789c..8800cc2 100644
--- a/src/vumeter.cc
+++ b/src/vumeter.cc
@@ -511,61 +511,66 @@ static void context_state_callback(pa_context *c, void *) {
int main(int argc, char *argv[]) {
pa_glib_mainloop *m;
- bool record;
+ bool record = false;
signal(SIGPIPE, SIG_IGN);
- Glib::OptionGroup og("PulseAudio Volume Meter", "Control the volume of your PulseAudio Sound Server");
-
- Glib::OptionEntry oe;
- oe.set_long_name("record");
- oe.set_description("Show Record Levels");
- og.add_entry(oe, record);
-
- Glib::OptionContext oc;
- oc.set_main_group(og);
-
- Gtk::Main kit(argc, argv, oc);
-
- mode = record ? RECORD : PLAYBACK;
-
- g_message("Starting in %s mode.", mode == RECORD ? "record" : "playback");
+ try {
+ Glib::OptionGroup og("PulseAudio Volume Meter", "Control the volume of your PulseAudio Sound Server");
+
+ Glib::OptionEntry oe;
+ oe.set_long_name("record");
+ oe.set_description("Show Record Levels");
+ og.add_entry(oe, record);
+
+ Glib::OptionContext oc;
+ oc.set_main_group(og);
+
+ Gtk::Main kit(argc, argv, oc);
+
+ mode = record ? RECORD : PLAYBACK;
+
+ g_message("Starting in %s mode.", mode == RECORD ? "record" : "playback");
+
+ /* Rather ugly and incomplete */
+ if (argc > 1)
+ device_name = g_strdup(argv[1]) ;
+ else {
+ char *e;
+ if ((e = getenv(mode == RECORD ? "PULSE_SOURCE" : "PULSE_SINK")))
+ device_name = g_strdup(e);
+ }
+
+ if (device_name)
+ g_message("Using device '%s'", device_name);
+
+ m = pa_glib_mainloop_new(g_main_context_default());
+ g_assert(m);
+
+ context = pa_context_new(pa_glib_mainloop_get_api(m), "PulseAudio Volume Meter");
+ g_assert(context);
+
+ pa_context_set_state_callback(context, context_state_callback, NULL);
+ pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
+
+ Gtk::Main::run();
+
+ if (stream)
+ pa_stream_unref(stream);
+ if (context)
+ pa_context_unref(context);
+
+ if (mainWindow)
+ delete mainWindow;
+
+ if(device_name)
+ g_free(device_name);
+
+ pa_glib_mainloop_free(m);
- /* Rather ugly and incomplete */
- if (argc > 1)
- device_name = g_strdup(argv[1]) ;
- else {
- char *e;
- if ((e = getenv(mode == RECORD ? "PULSE_SOURCE" : "PULSE_SINK")))
- device_name = g_strdup(e);
+ } catch (Glib::OptionError) {
+ g_message("Bad parameter");
}
-
- if (device_name)
- g_message("Using device '%s'", device_name);
-
- m = pa_glib_mainloop_new(g_main_context_default());
- g_assert(m);
-
- context = pa_context_new(pa_glib_mainloop_get_api(m), "PulseAudio Volume Meter");
- g_assert(context);
-
- pa_context_set_state_callback(context, context_state_callback, NULL);
- pa_context_connect(context, NULL, PA_CONTEXT_NOAUTOSPAWN, NULL);
-
- Gtk::Main::run();
-
- if (stream)
- pa_stream_unref(stream);
- if (context)
- pa_context_unref(context);
-
- if (mainWindow)
- delete mainWindow;
-
- if(device_name)
- g_free(device_name);
-
- pa_glib_mainloop_free(m);
return 0;
}