[glib/wip/locale-monitor: 1/4] gio: Add GLocaleMonitor class
- From: Rodrigo Moya <rodrigo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/locale-monitor: 1/4] gio: Add GLocaleMonitor class
- Date: Tue, 21 Jun 2011 14:17:00 +0000 (UTC)
commit 32eea11cf4eac0106354a90e0263b61d06ce913b
Author: Rodrigo Moya <rodrigo gnome-db org>
Date: Tue Jun 21 14:13:52 2011 +0200
gio: Add GLocaleMonitor class
gio/Makefile.am | 2 +
gio/gio.h | 1 +
gio/glocalemonitor.c | 145 ++++++++++++++++++++++++++++++++++++++
gio/glocalemonitor.h | 45 ++++++++++++
gobject/gmarshal.c | 6 --
gobject/gmarshal.h | 187 --------------------------------------------------
6 files changed, 193 insertions(+), 193 deletions(-)
---
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 2ef3c9b..1a3c52e 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -332,6 +332,7 @@ libgio_2_0_la_SOURCES = \
gioscheduler.c \
giostream.c \
gloadableicon.c \
+ glocalemonitor.c \
gmount.c \
gmemoryinputstream.c \
gmemoryoutputstream.c \
@@ -496,6 +497,7 @@ gio_headers = \
gioscheduler.h \
giostream.h \
gloadableicon.h \
+ glocalemonitor.c \
gmount.h \
gmemoryinputstream.h \
gmemoryoutputstream.h \
diff --git a/gio/gio.h b/gio/gio.h
index 2958059..96aae49 100644
--- a/gio/gio.h
+++ b/gio/gio.h
@@ -85,6 +85,7 @@
#include <gio/gioscheduler.h>
#include <gio/giostream.h>
#include <gio/gloadableicon.h>
+#include <gio/glocalemonitor.h>
#include <gio/gmemoryinputstream.h>
#include <gio/gmemoryoutputstream.h>
#include <gio/gmount.h>
diff --git a/gio/glocalemonitor.c b/gio/glocalemonitor.c
new file mode 100644
index 0000000..4081943
--- /dev/null
+++ b/gio/glocalemonitor.c
@@ -0,0 +1,145 @@
+/*
+ * Copyright  2011 Rodrigo Moya
+ *
+ * This program 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 of the licence 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ *
+ * Authors: Rodrigo Moya <rodrigo gnome org>
+ */
+
+#include "glocalemonitor.h"
+
+/**
+ * SECTION:glocalemonitor
+ * @title GLocaleMonitor
+ * @short_description: Monitor locale settings
+ *
+ * #GLocaleMonitor is a utility class to monitor the locale settings for
+ * changes (ie: in response to the user manually changing the locale).
+ *
+ * You must use this class in order for your program to notice changes to
+ * the locale settings (language, numbers and dates formats, etc). It works
+ * by monitoring the settings stored under org.gnome.system.locale. When any
+ * of the settings are changed, the "changed" signal is emitted, so that
+ * applications can listen to this signal and change the language of the
+ * messages shown in the application or the format of the dates
+ * and numbers being displayed in the application UI.
+ *
+ * When displaying formatted numbers, you should use the printf-style
+ * formatting in functions like printf, #g_strdup_printf, etc. For dates,
+ * use #g_date_strftime and/or #g_date_time_format_string with the correct
+ * string format used to represent dates and times with the current locale.
+ */
+
+/**
+ * GLocaleMonitor:
+ *
+ * This is an opaque structure type.
+ **/
+
+typedef GObjectClass GLocaleMonitorClass;
+
+struct _GLocaleMonitor
+{
+ GObject parent;
+
+ GSettings *locale_settings;
+};
+
+G_DEFINE_TYPE(GLocaleMonitor, g_locale_monitor, G_TYPE_OBJECT)
+
+static guint g_locale_monitor_changed_signal;
+
+static void
+g_locale_monitor_finalize (GObject *object)
+{
+ g_assert_not_reached ();
+}
+
+static void
+locale_settings_changed (GSettings *settings,
+ const gchar *key,
+ gpointer user_data)
+{
+ GLocaleMonitor = G_LOCALE_MONITOR (user_data);
+
+ if (g_str_is_equal (key, "region"))
+ {
+ /* FIXME: call setlocale here? */
+ g_signal_emit (monitor, g_locale_monitor_changed_signal, 0);
+ }
+}
+
+static void
+g_locale_monitor_init (GLocaleMonitor *monitor)
+{
+ monitor->settings = g_settings_new ("org.gnome.system.locale");
+ g_signal_connect (G_OBJECT (monitor->settings), "changed",
+ G_CALLBACK (locale_settings_changed), monitor);
+}
+
+static void
+g_locale_monitor_class_init (GLocaleMonitorClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = g_locale_monitor_finalize;
+
+ /**
+ * GLocaleMonitor::changed
+ * @monitor: the #GLocaleMonitor
+ *
+ * Indicates that the locale settings have changed.
+ *
+ **/
+ g_locale_monitor_changed_signal =
+ g_signal_new ("changed", G_TYPE_LOCALE_MONITOR,
+ G_SIGNAL_RUN_FIRST, 0, NULL, NULL,
+ g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
+}
+
+/**
+ * g_locale_monitor_get:
+ *
+ * Gets the singleton instance of the #GLocaleMonitor class, creating
+ * it if required.
+ *
+ * You should call #g_object_unref() on the result when you no longer
+ * need it. Be aware, though, that this will not destroy the instance,
+ * so if you connected to the changed signal, you are required to
+ * disconnect from it for yourself.
+ *
+ * There is only one instance of #LocaleMonitor and it dispatches its
+ * signals via the default #GMainContext. There is no way to create an
+ * instance that will dispatch signals using a different context.
+ *
+ * Returns: a reference to the #GLocaleMonitor.
+ */
+GLocaleMonitor *
+g_locale_monitor_get (void)
+{
+ static gsize instance;
+
+ if (g_once_init_enter (&instance))
+ {
+ GLocaleMonitor *monitor;
+
+ monitor = g_object_new (G_TYPE_LOCALE_MONITOR, NULL);
+
+ g_once_init_leave (&instance, (gsize) monitor);
+ }
+
+ return g_object_ref ((void *) instance);
+}
diff --git a/gio/glocalemonitor.h b/gio/glocalemonitor.h
new file mode 100644
index 0000000..ad40bda
--- /dev/null
+++ b/gio/glocalemonitor.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright  2011 Rodrigo Moya
+ *
+ * This program 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 of the licence 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser 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.
+ *
+ * Authors: Rodrigo Moya <rodrigo gnome org>
+ */
+
+#if !defined (__GIO_GIO_H_INSIDE__) && !defined (GIO_COMPILATION)
+#error "Only <gio/gio.h> can be included directly."
+#endif
+
+#ifndef __G_LOCALE_MONITOR_H__
+#define __G_LOCALE_MONITOR_H__
+
+#include "gactiongroup.h"
+
+G_BEGIN_DECLS
+
+#define G_TYPE_LOCALE_MONITOR (g_locale_monitor_get_type ())
+#define G_LOCALE_MONITOR(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), G_TYPE_LOCALE_MONITOR, GLocaleMonitor))
+#define G_IS_LOCALE_MONITOR(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), G_TYPE_LOCALE_MONITOR))
+
+typedef struct _GLocaleMonitor GLocaleMonitor;
+typedef struct _GLocaleMonitorClass GLocaleMonitorClass;
+
+GType g_locale_monitor_get_type (void) G_GNUC_CONST;
+GLocaleMonitor *g_locale_monitor_get (void);
+
+G_END_DECLS
+
+#endif /* __G_LOCALE_MONITOR_H__ */
diff --git a/gobject/gmarshal.c b/gobject/gmarshal.c
index bc53b5d..48047d8 100644
--- a/gobject/gmarshal.c
+++ b/gobject/gmarshal.c
@@ -1,10 +1,4 @@
-#include "config.h"
-
-#include "gobject.h"
-#include "genums.h"
-#include "gboxed.h"
-#include "gvaluetypes.h"
#ifdef G_ENABLE_DEBUG
#define g_marshal_value_peek_boolean(v) g_value_get_boolean (v)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]