[gnome-session] Export locale categories through D-Bus
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] Export locale categories through D-Bus
- Date: Wed, 7 Nov 2012 11:51:09 +0000 (UTC)
commit a696ccb00acf6bdcd168c23db2cc4e33bb1455e0
Author: Bastien Nocera <hadess hadess net>
Date: Wed Oct 10 11:03:04 2012 +0200
Export locale categories through D-Bus
Add GetLocale() function for System Settings to lookup the value
of a particular locale setting, such as the session language.
https://bugzilla.gnome.org/show_bug.cgi?id=685863
gnome-session/gsm-manager.c | 51 ++++++++++++++++++++++++++++
gnome-session/gsm-manager.h | 4 ++
gnome-session/org.gnome.SessionManager.xml | 18 ++++++++++
3 files changed, 73 insertions(+), 0 deletions(-)
---
diff --git a/gnome-session/gsm-manager.c b/gnome-session/gsm-manager.c
index 192c81d..3effdbf 100644
--- a/gnome-session/gsm-manager.c
+++ b/gnome-session/gsm-manager.c
@@ -28,6 +28,7 @@
#include <unistd.h>
#include <string.h>
#include <signal.h>
+#include <locale.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -2799,6 +2800,56 @@ gsm_manager_setenv (GsmManager *manager,
return TRUE;
}
+static gboolean
+is_valid_category (int category)
+{
+ int categories[] = {
+ LC_CTYPE,
+ LC_NUMERIC,
+ LC_TIME,
+ LC_COLLATE,
+ LC_MONETARY,
+ LC_MESSAGES,
+ LC_ALL,
+ LC_PAPER,
+ LC_NAME,
+ LC_ADDRESS,
+ LC_TELEPHONE,
+ LC_MEASUREMENT,
+ LC_IDENTIFICATION
+ };
+ guint i;
+
+ for (i = 0; i < G_N_ELEMENTS(categories); i++)
+ if (categories[i] == category)
+ return TRUE;
+
+ return FALSE;
+}
+
+gboolean
+gsm_manager_get_locale (GsmManager *manager,
+ int category,
+ const char **value,
+ GError **error)
+{
+ g_return_val_if_fail (GSM_IS_MANAGER (manager), FALSE);
+
+ if (!is_valid_category (category)) {
+ g_set_error (error,
+ GSM_MANAGER_ERROR,
+ GSM_MANAGER_ERROR_INVALID_OPTION,
+ "GetLocale doesn't support locale category '%d'", category);
+ return FALSE;
+ }
+
+ *value = g_strdup (setlocale (category, NULL));
+ if (*value == NULL)
+ *value = g_strdup ("");
+
+ return TRUE;
+}
+
gboolean
gsm_manager_initialization_error (GsmManager *manager,
const char *message,
diff --git a/gnome-session/gsm-manager.h b/gnome-session/gsm-manager.h
index 175c0ab..666d1d5 100644
--- a/gnome-session/gsm-manager.h
+++ b/gnome-session/gsm-manager.h
@@ -177,6 +177,10 @@ gboolean gsm_manager_setenv (GsmManager *
const char *variable,
const char *value,
GError **error);
+gboolean gsm_manager_get_locale (GsmManager *manager,
+ int category,
+ const char **value,
+ GError **error);
gboolean gsm_manager_initialization_error (GsmManager *manager,
const char *message,
gboolean fatal,
diff --git a/gnome-session/org.gnome.SessionManager.xml b/gnome-session/org.gnome.SessionManager.xml
index 8ed6bda..d07a488 100644
--- a/gnome-session/org.gnome.SessionManager.xml
+++ b/gnome-session/org.gnome.SessionManager.xml
@@ -23,6 +23,24 @@
</doc:doc>
</method>
+ <method name="GetLocale">
+ <arg name="category" type="i" direction="in">
+ <doc:doc>
+ <doc:summary>The locale category</doc:summary>
+ </doc:doc>
+ </arg>
+ <arg name="value" type="s" direction="out">
+ <doc:doc>
+ <doc:summary>The value</doc:summary>
+ </doc:doc>
+ </arg>
+ <doc:doc>
+ <doc:description>
+ <doc:para>Reads the current state of the specific locale category.</doc:para>
+ </doc:description>
+ </doc:doc>
+ </method>
+
<method name="InitializationError">
<arg name="message" type="s" direction="in">
<doc:doc>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]