From c3e99dd86c97c58019571fa012c85f40fda8a80f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 9 Mar 2007 19:44:30 +0000 Subject: [PATCH] sys/sunaudio/: Actually translate sunaudio mixer track labels instead of just marking the strings as translatable (#3... Original commit message from CVS: * sys/sunaudio/gstsunaudio.c: (plugin_init): * sys/sunaudio/gstsunaudiomixertrack.c: (gst_sunaudiomixer_track_new): Actually translate sunaudio mixer track labels instead of just marking the strings as translatable (#377306); clean up weird label string mapping code that serves no apparent purpose. Also set the 'untranslated-label' property when creating mixer tracks if the GstMixerTrack base class supports this. * tests/check/Makefile.am: * tests/check/elements/.cvsignore: * tests/check/elements/sunaudio.c: (GST_START_TEST), (sunaudio_suite): Very minimalistic unit test for sunaudiomixer element (compiles, but not actually tested on a system where sunaudiomixer is available). --- ChangeLog | 18 +++++++ sys/sunaudio/gstsunaudio.c | 1 + sys/sunaudio/gstsunaudiomixertrack.c | 51 ++++++++----------- tests/check/Makefile.am | 14 ++++++ tests/check/elements/.gitignore | 2 +- tests/check/elements/sunaudio.c | 95 ++++++++++++++++++++++++++++++++++++ 6 files changed, 148 insertions(+), 33 deletions(-) create mode 100644 tests/check/elements/sunaudio.c diff --git a/ChangeLog b/ChangeLog index 8098866..0dd2d2c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2007-03-09 Tim-Philipp Müller + + * sys/sunaudio/gstsunaudio.c: (plugin_init): + * sys/sunaudio/gstsunaudiomixertrack.c: + (gst_sunaudiomixer_track_new): + Actually translate sunaudio mixer track labels instead of just + marking the strings as translatable (#377306); clean up weird + label string mapping code that serves no apparent purpose. Also + set the 'untranslated-label' property when creating mixer tracks + if the GstMixerTrack base class supports this. + + * tests/check/Makefile.am: + * tests/check/elements/.cvsignore: + * tests/check/elements/sunaudio.c: (GST_START_TEST), + (sunaudio_suite): + Very minimalistic unit test for sunaudiomixer element (compiles, but not + actually tested on a system where sunaudiomixer is available). + 2007-03-09 Jan Schmidt * tests/check/Makefile.am: diff --git a/sys/sunaudio/gstsunaudio.c b/sys/sunaudio/gstsunaudio.c index bdf3371..b06bf15 100644 --- a/sys/sunaudio/gstsunaudio.c +++ b/sys/sunaudio/gstsunaudio.c @@ -49,6 +49,7 @@ plugin_init (GstPlugin * plugin) #ifdef ENABLE_NLS setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); #endif /* ENABLE_NLS */ return TRUE; diff --git a/sys/sunaudio/gstsunaudiomixertrack.c b/sys/sunaudio/gstsunaudiomixertrack.c index 87883ae..e108695 100644 --- a/sys/sunaudio/gstsunaudiomixertrack.c +++ b/sys/sunaudio/gstsunaudiomixertrack.c @@ -57,48 +57,35 @@ gst_sunaudiomixer_track_init (GstSunAudioMixerTrack * track) track->track_num = 0; } -static const gchar **labels = NULL; - -static void -fill_labels (void) -{ - int i; - struct - { - gchar *given, *wanted; - } - cases[] = { - { - "Vol ", N_("Volume")} - , { - "Gain ", N_("Gain")} - , { - "Mon ", N_("Monitor")} - , { - NULL, NULL} - }; - - labels = g_malloc (sizeof (gchar *) * MIXER_DEVICES); - - for (i = 0; i < MIXER_DEVICES; i++) { - labels[i] = g_strdup (cases[i].wanted); - } -} - GstMixerTrack * gst_sunaudiomixer_track_new (GstSunAudioTrackType track_num, gint max_chans, gint flags) { + const gchar *labels[] = { N_("Volume"), N_("Gain"), N_("Monitor") }; + GstSunAudioMixerTrack *sunaudiotrack; GstMixerTrack *track; + GObjectClass *klass; + const gchar *untranslated_label; gint volume; - if (!labels) - fill_labels (); + if ((guint) track_num < G_N_ELEMENTS (labels)) + untranslated_label = labels[track_num]; + else + untranslated_label = NULL; + + /* FIXME: remove this check once we depend on -base >= 0.10.12.1 */ + klass = G_OBJECT_CLASS (g_type_class_ref (GST_TYPE_SUNAUDIO_MIXER_TRACK)); + if (g_object_class_find_property (klass, "untranslated-label")) { + sunaudiotrack = g_object_new (GST_TYPE_SUNAUDIO_MIXER_TRACK, + "untranslated-label", untranslated_label, NULL); + } else { + sunaudiotrack = g_object_new (GST_TYPE_SUNAUDIO_MIXER_TRACK, NULL); + } + g_type_class_unref (klass); - sunaudiotrack = g_object_new (GST_TYPE_SUNAUDIO_MIXER_TRACK, NULL); track = GST_MIXER_TRACK (sunaudiotrack); - track->label = g_strdup (labels[track_num]); + track->label = g_strdup (_(untranslated_label)); track->num_channels = max_chans; track->flags = flags; track->min_volume = 0; diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index b4404ad..fbd9e13 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -26,6 +26,12 @@ else check_annodex = endif +if USE_SUNAUDIO +check_sunaudio = elements/sunaudio +else +check_sunaudio = +endif + if USE_TAGLIB check_taglib = \ elements/id3v2mux \ @@ -47,6 +53,7 @@ check_PROGRAMS = \ elements/matroskamux \ elements/icydemux \ elements/videofilter \ + $(check_sunaudio) \ $(check_taglib) VALGRIND_TO_FIX = @@ -76,3 +83,10 @@ elements_audiopanorama_CFLAGS = \ elements_cmmldec_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) elements_cmmlenc_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) + +elements_sunaudio_CFLAGS = \ + $(GST_PLUGINS_BASE_CFLAGS) \ + $(AM_CFLAGS) +elements_sunaudio_LDADD = \ + $(GST_PLUGINS_BASE_LIBS) -lgstinterfaces-@GST_MAJORMINOR@ \ + $(LDADD) diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore index de1a7f1..5a0a624 100644 --- a/tests/check/elements/.gitignore +++ b/tests/check/elements/.gitignore @@ -13,5 +13,5 @@ id3v2mux apev2mux audiopanorama videofilter - +sunaudio autodetect diff --git a/tests/check/elements/sunaudio.c b/tests/check/elements/sunaudio.c new file mode 100644 index 0000000..30b569a --- /dev/null +++ b/tests/check/elements/sunaudio.c @@ -0,0 +1,95 @@ +/* GStreamer unit tests for the sun audio elements + * + * Copyright (C) 2007 Tim-Philipp Müller + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include +#include +#include +#include + +GST_START_TEST (test_sun_audio_mixer_track) +{ + GstStateChangeReturn state_ret; + GstElement *mixer; + GList *tracks, *l; + + mixer = gst_element_factory_make ("sunaudiomixer", "sunaudiomixer"); + fail_unless (mixer != NULL, "Failed to create 'sunaudiomixer' element!"); + + state_ret = gst_element_set_state (mixer, GST_STATE_READY); + if (state_ret != GST_STATE_CHANGE_SUCCESS) { + gst_object_unref (mixer); + return; + } + + GST_LOG ("opened sunaudiomixer"); + fail_unless (GST_IS_MIXER (mixer), "is not a GstMixer?!"); + + tracks = (GList *) gst_mixer_list_tracks (GST_MIXER (mixer)); + for (l = tracks; l != NULL; l = l->next) { + GObjectClass *klass; + GstMixerTrack *track; + gchar *ulabel = NULL, *label = NULL; + + track = GST_MIXER_TRACK (l->data); + + g_object_get (track, "label", &label, NULL); + fail_unless (label == NULL || g_utf8_validate (label, -1, NULL)); + + /* FIXME: remove this check once we depend on -base >= 0.10.12.1 */ + klass = G_OBJECT_GET_CLASS (track); + if (g_object_class_find_property (klass, "untranslated-label")) { + g_object_get (track, "untranslated-label", &ulabel, NULL); + } + + if (ulabel != NULL) { + gchar *p; + + for (p = ulabel; p != NULL && *p != '\0'; ++p) { + fail_unless (g_ascii_isprint (*p), + "untranslated label '%s' not printable ASCII", ulabel); + } + } + GST_DEBUG ("%s: %s", GST_STR_NULL (ulabel), GST_STR_NULL (label)); + g_free (label); + g_free (ulabel); + } + + fail_unless_equals_int (gst_element_set_state (mixer, GST_STATE_NULL), + GST_STATE_CHANGE_SUCCESS); + + gst_object_unref (mixer); +} + +GST_END_TEST; + + +static Suite * +sunaudio_suite (void) +{ + Suite *s = suite_create ("sunaudio"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_sun_audio_mixer_track); + + return s; +} + +GST_CHECK_MAIN (sunaudio) -- 2.7.4