summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2008-06-22 23:57:45 +0200
committerLennart Poettering <lennart@poettering.net>2008-06-22 23:57:45 +0200
commit0247e33ac2dfcf141577b36a875f01192d8199b7 (patch)
tree7c2d9761b8cbefe65a377c1eaf90da92d1bd21ad
parentb5489c8a0e3a259189dafdc9970ea66b6055e389 (diff)
add new tool canberra-gtk-play for playing arbitrary event sounds from the command line
-rw-r--r--configure.ac2
-rw-r--r--src/.gitignore1
-rw-r--r--src/Makefile.am12
-rw-r--r--src/canberra-gtk-play.c101
4 files changed, 115 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 225f54e..1e0efe8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -293,7 +293,7 @@ AC_ARG_ENABLE([gtk],
[gtk=auto])
if test "x${gtk}" != xno ; then
- PKG_CHECK_MODULES(GTK, [ gtk+-2.0 ],
+ PKG_CHECK_MODULES(GTK, [ gtk+-2.0 gthread-2.0 ],
[
HAVE_GTK=1
AC_DEFINE([HAVE_GTK], 1, [Have GTK?])
diff --git a/src/.gitignore b/src/.gitignore
index 1682019..e269eeb 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -1,3 +1,4 @@
+canberra-gtk-play
.libs
*.o
*.lo
diff --git a/src/Makefile.am b/src/Makefile.am
index b11b037..0f26587 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -180,6 +180,9 @@ include_HEADERS += \
gtkmodule_LTLIBRARIES = \
libcanberra-gtk-module.la
+bin_PROGRAMS = \
+ canberra-gtk-play
+
libcanberra_gtk_la_SOURCES = \
canberra-gtk.h \
canberra-gtk.c
@@ -202,6 +205,15 @@ libcanberra_gtk_module_la_LIBADD = \
libcanberra_gtk_module_la_LDFLAGS = \
-avoid-version -module -export-dynamic
+canberra_gtk_play_SOURCES = \
+ canberra-gtk-play.c
+canberra_gtk_play_LDADD = \
+ $(GTK_LIBS) \
+ libcanberra.la \
+ libcanberra-gtk.la
+canberra_gtk_play_CFLAGS = \
+ $(GTK_CFLAGS)
+
endif
test_canberra_SOURCES = \
diff --git a/src/canberra-gtk-play.c b/src/canberra-gtk-play.c
new file mode 100644
index 0000000..527a9f8
--- /dev/null
+++ b/src/canberra-gtk-play.c
@@ -0,0 +1,101 @@
+/***
+ This file is part of libcanberra.
+
+ Copyright 2008 Lennart Poettering
+
+ libcanberra is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 2.1 of the
+ License, or (at your option) any later version.
+
+ libcanberra is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with libcanberra. If not, If not, see
+ <http://www.gnu.org/licenses/>.
+***/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <canberra-gtk.h>
+#include <locale.h>
+
+static gboolean idle_quit(gpointer userdata) {
+ gtk_main_quit ();
+ return FALSE;
+}
+
+static void callback(ca_context *c, uint32_t id, int error, void *userdata) {
+ int *ret = userdata;
+
+ if (error < 0) {
+ g_printerr("Failed to play sound: %s\n", ca_strerror(error));
+ *ret = 1;
+ }
+
+ /* So, why don't we call gtk_main_quit() here directly? -- Because
+ * otherwise we might end up with a small race condition: this
+ * callback might get called before the main loop actually started
+ * running */
+ g_idle_add(idle_quit, NULL);
+}
+
+int main (int argc, char *argv[]) {
+ GOptionContext *oc;
+ ca_proplist *p;
+ static gchar *event_id = NULL, *event_description = NULL;
+ int ret = 0, r;
+
+ 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" },
+ { NULL, 0, 0, 0, NULL, NULL, NULL }
+ };
+
+ setlocale(LC_ALL, "");
+
+ g_type_init();
+ g_thread_init(NULL);
+
+ oc = g_option_context_new("- libcanberra-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);
+
+ gtk_init(&argc, &argv);
+
+ if (!event_id) {
+ g_printerr("No event id specified.\n");
+ return 1;
+ }
+
+ ca_context_change_props(ca_gtk_context_get(),
+ CA_PROP_APPLICATION_NAME, "canberra-gtk-play",
+ CA_PROP_APPLICATION_ID, "org.freedesktop.libcanberra.GtkPlay",
+ NULL);
+
+ ca_proplist_create(&p);
+ ca_proplist_sets(p, CA_PROP_EVENT_ID, event_id);
+
+ if (event_description)
+ ca_proplist_sets(p, CA_PROP_EVENT_DESCRIPTION, event_description);
+
+ r = ca_context_play_full(ca_gtk_context_get(), 1, p, callback, &ret);
+ ca_proplist_destroy(p);
+
+ if (r < 0) {
+ g_printerr("Failed to play sound: %s\n", ca_strerror(r));
+ return 1;
+ }
+
+ gtk_main();
+
+ return ret;
+}