changeset 36710:92159376ad91

Localize decimal mark. This is usually handled by the locale the user has set, but since we don't set the locale for the GUI to avoid problems with MPlayer which requires a "C" locale, we end up with a decimal point. Add MSGTR_GUI_DecimalMark in order to still allow localized numbers.
author ib
date Fri, 07 Feb 2014 20:28:01 +0000
parents d1aef1876187
children 518549e08426
files gui/dialog/tools.c help/help_mp-de.h help/help_mp-en.h
diffstat 3 files changed, 37 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/gui/dialog/tools.c	Fri Feb 07 19:52:17 2014 +0000
+++ b/gui/dialog/tools.c	Fri Feb 07 20:28:01 2014 +0000
@@ -22,6 +22,39 @@
 
 #include "tools.h"
 
+#include "help_mp.h"
+
+/**
+ * @brief Perform a localization of the decimal mark.
+ *
+ * @param scale object which received the signal
+ * @param value value to format
+ * @param user_data user data set when the signal handler was connected
+ *
+ * @return allocated string representing value
+ *
+ * @note This function is necessary, because we have to run in the "C" locale.
+ */
+static gchar *scale_format_value (GtkScale *scale, gdouble value, gpointer user_data)
+{
+  gchar *val, *p, *dm = MSGTR_GUI_DecimalMark;
+
+  (void) user_data;
+
+  val = g_strdup_printf("%0.*f", gtk_scale_get_digits(scale), value);
+
+  p = val;
+
+  while (p && *p && *dm)
+  {
+    if (*p == '.') *p = *dm;
+
+    p++;
+  }
+
+  return val;
+}
+
 GtkWidget * gtkAddDialogFrame( GtkWidget * parent )
 {
  GtkWidget * frame;
@@ -152,6 +185,7 @@
  if ( parent ) gtk_box_pack_start( GTK_BOX( parent ),HS,TRUE,TRUE,0 );
  gtk_scale_set_value_pos( GTK_SCALE( HS ),GTK_POS_RIGHT );
  gtk_scale_set_digits( GTK_SCALE( HS ),digit );
+ if (digit > 0) gtk_signal_connect(GTK_OBJECT(HS), "format-value", GTK_SIGNAL_FUNC(scale_format_value), NULL);
  return HS;
 }
 
@@ -164,6 +198,7 @@
 // gtk_scale_set_value_pos( GTK_SCALE( VS ),GTK_POS_RIGHT );
  if ( digit == -1 ) gtk_scale_set_draw_value( GTK_SCALE( VS ),FALSE );
   else gtk_scale_set_digits( GTK_SCALE( VS ),digit );
+ if (digit > 0) gtk_signal_connect(GTK_OBJECT(VS), "format-value", GTK_SIGNAL_FUNC(scale_format_value), NULL);
  return VS;
 }
 
--- a/help/help_mp-de.h	Fri Feb 07 19:52:17 2014 +0000
+++ b/help/help_mp-de.h	Fri Feb 07 20:28:01 2014 +0000
@@ -825,6 +825,7 @@
 #define MSGTR_GUI_CpShiftJis "Japanisch (SHIFT-JIS)"
 #define MSGTR_GUI_CpUnicode "Unicode"
 #define MSGTR_GUI_CpUTF8 "UTF-8"
+#define MSGTR_GUI_DecimalMark ","
 #define MSGTR_GUI__Default_ "(Standard)"
 #define MSGTR_GUI_DefaultSetting "Standardeinstellung"
 #define MSGTR_GUI_Delay "Verzögerung"
--- a/help/help_mp-en.h	Fri Feb 07 19:52:17 2014 +0000
+++ b/help/help_mp-en.h	Fri Feb 07 20:28:01 2014 +0000
@@ -624,6 +624,7 @@
 #define MSGTR_GUI_CpShiftJis "Japanese (SHIFT-JIS)"
 #define MSGTR_GUI_CpUnicode "Unicode"
 #define MSGTR_GUI_CpUTF8 "UTF-8"
+#define MSGTR_GUI_DecimalMark "."
 #define MSGTR_GUI__Default_ "(Default)"
 #define MSGTR_GUI_DefaultSetting "Default setting"
 #define MSGTR_GUI_Delay "Delay"