mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 02:32:11 +01:00
gio: Add GLocaleMonitor class
This commit is contained in:
parent
f6ed357101
commit
32eea11cf4
@ -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 \
|
||||
|
@ -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>
|
||||
|
145
gio/glocalemonitor.c
Normal file
145
gio/glocalemonitor.c
Normal file
@ -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);
|
||||
}
|
45
gio/glocalemonitor.h
Normal file
45
gio/glocalemonitor.h
Normal file
@ -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__ */
|
@ -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)
|
||||
|
@ -1,187 +0,0 @@
|
||||
/* Note: This file is no longer generated. See the comment in gmarshal.list */
|
||||
#ifndef __G_MARSHAL_H__
|
||||
#define __G_MARSHAL_H__
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/* VOID:VOID (./gmarshal.list:6) */
|
||||
extern void g_cclosure_marshal_VOID__VOID (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:BOOLEAN (./gmarshal.list:7) */
|
||||
extern void g_cclosure_marshal_VOID__BOOLEAN (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:CHAR (./gmarshal.list:8) */
|
||||
extern void g_cclosure_marshal_VOID__CHAR (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:UCHAR (./gmarshal.list:9) */
|
||||
extern void g_cclosure_marshal_VOID__UCHAR (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:INT (./gmarshal.list:10) */
|
||||
extern void g_cclosure_marshal_VOID__INT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:UINT (./gmarshal.list:11) */
|
||||
extern void g_cclosure_marshal_VOID__UINT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:LONG (./gmarshal.list:12) */
|
||||
extern void g_cclosure_marshal_VOID__LONG (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:ULONG (./gmarshal.list:13) */
|
||||
extern void g_cclosure_marshal_VOID__ULONG (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:ENUM (./gmarshal.list:14) */
|
||||
extern void g_cclosure_marshal_VOID__ENUM (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:FLAGS (./gmarshal.list:15) */
|
||||
extern void g_cclosure_marshal_VOID__FLAGS (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:FLOAT (./gmarshal.list:16) */
|
||||
extern void g_cclosure_marshal_VOID__FLOAT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:DOUBLE (./gmarshal.list:17) */
|
||||
extern void g_cclosure_marshal_VOID__DOUBLE (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:STRING (./gmarshal.list:18) */
|
||||
extern void g_cclosure_marshal_VOID__STRING (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:PARAM (./gmarshal.list:19) */
|
||||
extern void g_cclosure_marshal_VOID__PARAM (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:BOXED (./gmarshal.list:20) */
|
||||
extern void g_cclosure_marshal_VOID__BOXED (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:POINTER (./gmarshal.list:21) */
|
||||
extern void g_cclosure_marshal_VOID__POINTER (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:OBJECT (./gmarshal.list:22) */
|
||||
extern void g_cclosure_marshal_VOID__OBJECT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:VARIANT (./gmarshal.list:23) */
|
||||
extern void g_cclosure_marshal_VOID__VARIANT (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* VOID:UINT,POINTER (./gmarshal.list:26) */
|
||||
extern void g_cclosure_marshal_VOID__UINT_POINTER (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* BOOL:FLAGS (./gmarshal.list:27) */
|
||||
extern void g_cclosure_marshal_BOOLEAN__FLAGS (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
#define g_cclosure_marshal_BOOL__FLAGS g_cclosure_marshal_BOOLEAN__FLAGS
|
||||
|
||||
/* STRING:OBJECT,POINTER (./gmarshal.list:28) */
|
||||
extern void g_cclosure_marshal_STRING__OBJECT_POINTER (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
|
||||
/* BOOL:BOXED,BOXED (./gmarshal.list:29) */
|
||||
extern void g_cclosure_marshal_BOOLEAN__BOXED_BOXED (GClosure *closure,
|
||||
GValue *return_value,
|
||||
guint n_param_values,
|
||||
const GValue *param_values,
|
||||
gpointer invocation_hint,
|
||||
gpointer marshal_data);
|
||||
#define g_cclosure_marshal_BOOL__BOXED_BOXED g_cclosure_marshal_BOOLEAN__BOXED_BOXED
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __G_MARSHAL_H__ */
|
Loading…
x
Reference in New Issue
Block a user