From 20d646d48e05ff6fc4c75686dcf8b722dcabbb10 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Tue, 2 Sep 2008 23:52:23 +0300 Subject: Add --version and short form version for arguments --- src/canberra-gtk-play.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/canberra-gtk-play.c b/src/canberra-gtk-play.c index 0b68dd9..d1367bf 100644 --- a/src/canberra-gtk-play.c +++ b/src/canberra-gtk-play.c @@ -82,12 +82,14 @@ int main (int argc, char *argv[]) { GOptionContext *oc; static gchar *event_id = NULL, *event_description = NULL, *cache_control = NULL; int r; + static gboolean version = FALSE; static const GOptionEntry options[] = { - { "id", 0, 0, G_OPTION_ARG_STRING, &event_id, "Event sound identifier", "STRING" }, - { "description", 0, 0, G_OPTION_ARG_STRING, &event_description, "Event sound description", "STRING" }, - { "cache-control", 0, 0, G_OPTION_ARG_STRING, &cache_control, "Cache control (permanent, volatile, never)", "STRING" }, - { "loop", 0, 0, G_OPTION_ARG_INT, &n_loops, "Loop how many times (detault: 1)", "INTEGER" }, + { "id", 'i', 0, G_OPTION_ARG_STRING, &event_id, "Event sound identifier", "STRING" }, + { "description", 'd', 0, G_OPTION_ARG_STRING, &event_description, "Event sound description", "STRING" }, + { "cache-control", 'c', 0, G_OPTION_ARG_STRING, &cache_control, "Cache control (permanent, volatile, never)", "STRING" }, + { "loop", 'l', 0, G_OPTION_ARG_INT, &n_loops, "Loop how many times (detault: 1)", "INTEGER" }, + { "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Display version number and quit", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; @@ -96,12 +98,17 @@ int main (int argc, char *argv[]) { g_type_init(); g_thread_init(NULL); - oc = g_option_context_new("- libcanberra-gtk-play"); + oc = g_option_context_new("- canberra-gtk-play"); g_option_context_add_main_entries(oc, options, NULL); g_option_context_set_help_enabled(oc, TRUE); g_option_context_parse(oc, &argc, &argv, NULL); g_option_context_free(oc); + if (version) { + g_print("canberra-gtk-play from %s\n", PACKAGE_STRING); + return 0; + } + gtk_init(&argc, &argv); if (!event_id) { -- cgit From 529349e27fdb2c156b2a17943647ce2840f3ca66 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 3 Sep 2008 00:03:59 +0300 Subject: Support playing events with file specified --- src/canberra-gtk-play.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/canberra-gtk-play.c b/src/canberra-gtk-play.c index d1367bf..689a8f6 100644 --- a/src/canberra-gtk-play.c +++ b/src/canberra-gtk-play.c @@ -80,12 +80,13 @@ static void callback(ca_context *c, uint32_t id, int error, void *userdata) { int main (int argc, char *argv[]) { GOptionContext *oc; - static gchar *event_id = NULL, *event_description = NULL, *cache_control = NULL; + static gchar *event_id = NULL, *filename = NULL, *event_description = NULL, *cache_control = NULL; int r; static gboolean version = FALSE; static const GOptionEntry options[] = { { "id", 'i', 0, G_OPTION_ARG_STRING, &event_id, "Event sound identifier", "STRING" }, + { "file", 'f', 0, G_OPTION_ARG_STRING, &filename, "Play file", "PATH" }, { "description", 'd', 0, G_OPTION_ARG_STRING, &event_description, "Event sound description", "STRING" }, { "cache-control", 'c', 0, G_OPTION_ARG_STRING, &cache_control, "Cache control (permanent, volatile, never)", "STRING" }, { "loop", 'l', 0, G_OPTION_ARG_INT, &n_loops, "Loop how many times (detault: 1)", "INTEGER" }, @@ -100,6 +101,7 @@ int main (int argc, char *argv[]) { oc = g_option_context_new("- canberra-gtk-play"); g_option_context_add_main_entries(oc, options, NULL); + g_option_context_add_group(oc, gtk_get_option_group(TRUE)); g_option_context_set_help_enabled(oc, TRUE); g_option_context_parse(oc, &argc, &argv, NULL); g_option_context_free(oc); @@ -109,10 +111,8 @@ int main (int argc, char *argv[]) { return 0; } - gtk_init(&argc, &argv); - - if (!event_id) { - g_printerr("No event id specified.\n"); + if (!event_id && !filename) { + g_printerr("No event id or file specified.\n"); return 1; } @@ -122,7 +122,12 @@ int main (int argc, char *argv[]) { NULL); ca_proplist_create(&proplist); - ca_proplist_sets(proplist, CA_PROP_EVENT_ID, event_id); + + if (event_id) + ca_proplist_sets(proplist, CA_PROP_EVENT_ID, event_id); + + if (filename) + ca_proplist_sets(proplist, CA_PROP_MEDIA_FILENAME, filename); if (cache_control) ca_proplist_sets(proplist, CA_PROP_CANBERRA_CACHE_CONTROL, cache_control); -- cgit From 0248b74ccc0cda4a81c3573aa9702779fc21cd29 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Wed, 3 Sep 2008 00:12:27 +0300 Subject: Avoid crash if gtk-settings is NULL --- src/canberra-gtk.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/canberra-gtk.c b/src/canberra-gtk.c index 66a2b9a..d3be082 100644 --- a/src/canberra-gtk.c +++ b/src/canberra-gtk.c @@ -101,6 +101,8 @@ ca_context *ca_gtk_context_get(void) { s = gtk_settings_get_default(); + ca_return_val_if_fail(s, NULL); + if (g_object_class_find_property(G_OBJECT_GET_CLASS(s), "gtk-sound-theme-name")) { g_signal_connect(G_OBJECT(s), "notify::gtk-sound-theme-name", G_CALLBACK(sound_theme_name_changed), c); read_sound_theme_name(c, s); -- cgit From 6ac713466c207ce8253410d1598f5f37e509acc2 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Fri, 29 Aug 2008 23:05:12 +0300 Subject: Fix formatting for function calls --- src/gstreamer.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/gstreamer.c b/src/gstreamer.c index 59556a1..caa28a6 100644 --- a/src/gstreamer.c +++ b/src/gstreamer.c @@ -86,7 +86,7 @@ int driver_open(ca_context *c) { ca_return_val_if_fail(!PRIVATE(c), CA_ERROR_INVALID); ca_return_val_if_fail(!c->driver || ca_streq(c->driver, "gstreamer"), CA_ERROR_NODRIVER); - gst_init_check (NULL, NULL, &error); + gst_init_check(NULL, NULL, &error); if (error != NULL) { g_warning("gst_init: %s ", error->message); g_error_free(error); @@ -173,7 +173,7 @@ int driver_destroy(ca_context *c) { ca_free(p); - /* no gst_deinit (), see doc */ + /* no gst_deinit(), see doc */ return CA_SUCCESS; } @@ -292,22 +292,22 @@ static void on_pad_added(GstElement *element, GstPad *pad, gboolean arg1, gpoint GstPad *vpad; const char *type; - sinkelement = (GstElement *)data; + sinkelement = GST_ELEMENT(data); - caps = gst_pad_get_caps (pad); - if (gst_caps_is_empty (caps) || gst_caps_is_any (caps)) { - gst_caps_unref (caps); + caps = gst_pad_get_caps(pad); + if (gst_caps_is_empty(caps) || gst_caps_is_any(caps)) { + gst_caps_unref(caps); return; } - structure = gst_caps_get_structure (caps, 0); - type = gst_structure_get_name (structure); - if (g_str_has_prefix (type, "audio/x-raw") == TRUE) { - vpad = gst_element_get_pad (sinkelement, "sink"); - gst_pad_link (pad, vpad); - gst_object_unref (vpad); + structure = gst_caps_get_structure(caps, 0); + type = gst_structure_get_name(structure); + if (g_str_has_prefix(type, "audio/x-raw") == TRUE) { + vpad = gst_element_get_pad(sinkelement, "sink"); + gst_pad_link(pad, vpad); + gst_object_unref(vpad); } - gst_caps_unref (caps); + gst_caps_unref(caps); } int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_callback_t cb, void *userdata) { @@ -349,9 +349,9 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal goto fail; } - bin = gst_bin_new ("audiobin"); + bin = gst_bin_new("audiobin"); - g_signal_connect (decodebin, "new-decoded-pad", G_CALLBACK (on_pad_added), bin); + g_signal_connect(decodebin, "new-decoded-pad", G_CALLBACK (on_pad_added), bin); bus = gst_pipeline_get_bus(GST_PIPELINE (out->pipeline)); gst_bus_set_sync_handler(bus, bus_cb, out); @@ -369,15 +369,15 @@ int driver_play(ca_context *c, uint32_t id, ca_proplist *proplist, ca_finish_cal goto fail; } - gst_bin_add_many (GST_BIN (bin), audioconvert, audioresample, sink, NULL); - gst_element_link_many (audioconvert, audioresample, sink, NULL); + gst_bin_add_many(GST_BIN (bin), audioconvert, audioresample, sink, NULL); + gst_element_link_many(audioconvert, audioresample, sink, NULL); - audiopad = gst_element_get_pad (audioconvert, "sink"); - gst_element_add_pad (bin, gst_ghost_pad_new ("sink", audiopad)); + audiopad = gst_element_get_pad(audioconvert, "sink"); + gst_element_add_pad(bin, gst_ghost_pad_new("sink", audiopad)); - gst_object_unref (audiopad); + gst_object_unref(audiopad); - gst_bin_add (GST_BIN (out->pipeline), bin); + gst_bin_add(GST_BIN (out->pipeline), bin); decodebin = NULL; sink = NULL; -- cgit