aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-02-17 21:46:20 -0600
committerTed Gould <ted@gould.cx>2011-02-17 21:46:20 -0600
commitb376a0aeaecd0928f3222e36aad7f3faea1fffa7 (patch)
tree9df622534aa334536dac3638d1d98295206ca027
parentb30759981718e0806418a55c6ea128127d1343d4 (diff)
downloadlibdbusmenu-b376a0aeaecd0928f3222e36aad7f3faea1fffa7.tar.gz
libdbusmenu-b376a0aeaecd0928f3222e36aad7f3faea1fffa7.tar.bz2
libdbusmenu-b376a0aeaecd0928f3222e36aad7f3faea1fffa7.zip
Adding code to determine the default text direction
-rw-r--r--libdbusmenu-glib/server.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c
index 9784c1d..a1f805e 100644
--- a/libdbusmenu-glib/server.c
+++ b/libdbusmenu-glib/server.c
@@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see
#include "config.h"
#endif
+#include <glib/gi18n.h>
#include <gio/gio.h>
#include "menuitem-private.h"
@@ -55,6 +56,8 @@ struct _DbusmenuServerPrivate
GDBusConnection * bus;
GCancellable * bus_lookup;
guint dbus_registration;
+
+ DbusmenuTextDirection text_direction;
};
#define DBUSMENU_SERVER_GET_PRIVATE(o) (DBUSMENU_SERVER(o)->priv)
@@ -123,6 +126,7 @@ static void get_property (GObject * obj,
guint id,
GValue * value,
GParamSpec * pspec);
+static void default_text_direction (DbusmenuServer * server);
static void register_object (DbusmenuServer * server);
static void bus_got_cb (GObject * obj,
GAsyncResult * result,
@@ -351,6 +355,8 @@ dbusmenu_server_init (DbusmenuServer *self)
priv->bus_lookup = NULL;
priv->dbus_registration = 0;
+ default_text_direction(self);
+
return;
}
@@ -480,6 +486,49 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec)
return;
}
+/* Determines the default text direction */
+static void
+default_text_direction (DbusmenuServer * server)
+{
+ DbusmenuTextDirection dir = DBUSMENU_TEXT_DIRECTION_NONE;
+ DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server);
+
+ const gchar * env = g_getenv("DBUSMENU_TEXT_DIRECTION");
+ if (env != NULL) {
+ if (g_strcmp0(env, "ltr") == 0) {
+ dir = DBUSMENU_TEXT_DIRECTION_LTR;
+ } else if (g_strcmp0(env, "rtl") == 0) {
+ dir = DBUSMENU_TEXT_DIRECTION_RTL;
+ } else {
+ g_warning("Value of 'DBUSMENU_TEXT_DIRECTION' is '%s' which is not one of 'rtl' or 'ltr'", env);
+ }
+ }
+
+ if (dir == DBUSMENU_TEXT_DIRECTION_NONE) {
+ /* TRANSLATORS: This is the direction of the text and can
+ either be the value 'ltr' for left-to-right text (English)
+ or 'rtl' for right-to-left (Arabic). */
+ const gchar * default_dir = C_("default text direction", "ltr");
+
+ if (g_strcmp0(default_dir, "ltr") == 0) {
+ dir = DBUSMENU_TEXT_DIRECTION_LTR;
+ } else if (g_strcmp0(default_dir, "rtl") == 0) {
+ dir = DBUSMENU_TEXT_DIRECTION_RTL;
+ } else {
+ g_warning("Translation has an invalid value '%s' for default text direction. Defaulting to left-to-right.", default_dir);
+ dir = DBUSMENU_TEXT_DIRECTION_LTR;
+ }
+ }
+
+ /* Shouldn't happen, but incase future patches make a mistake
+ this'll catch them */
+ g_return_if_fail(dir != DBUSMENU_TEXT_DIRECTION_NONE);
+
+ priv->text_direction = dir;
+
+ return;
+}
+
/* Register the object on the dbus bus */
static void
register_object (DbusmenuServer * server)