summaryrefslogtreecommitdiff
path: root/obt
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2007-07-26 21:40:47 -0400
committerDana Jansens <danakj@orodu.net>2008-01-20 01:36:55 -0500
commit2f0e73cf9d20154c5c84b6ea90e658cf44a6f0c4 (patch)
treead0ba99bffac6c951ab749af13460e8e5751a510 /obt
parent275fdf8c2a0d5c7d8f395b3269e644939e016696 (diff)
add functions for setting locale strings (on top of existing functions for setting utf8 strings). they are untested though! wonder if they work?
Diffstat (limited to 'obt')
-rw-r--r--obt/prop.c43
-rw-r--r--obt/prop.h14
2 files changed, 46 insertions, 11 deletions
diff --git a/obt/prop.c b/obt/prop.c
index 0895cfe0..bdbde53b 100644
--- a/obt/prop.c
+++ b/obt/prop.c
@@ -318,7 +318,7 @@ gboolean obt_prop_get_strings_locale(Window win, Atom prop, gchar ***ret)
gchar *raw, *p;
guint num, i, count = 0;
- if (get_all(win, prop, obt_prop_atom(OBT_PROP_STRING), 8,
+ if (get_all(win, prop, OBT_PROP_ATOM(STRING), 8,
(guchar**)&raw, &num))
{
p = raw;
@@ -350,7 +350,7 @@ gboolean obt_prop_get_string_utf8(Window win, Atom prop, gchar **ret)
gchar *str;
guint num;
- if (get_all(win, prop, obt_prop_atom(OBT_PROP_UTF8), 8,
+ if (get_all(win, prop, OBT_PROP_ATOM(UTF8), 8,
(guchar**)&raw, &num))
{
str = g_strndup(raw, num); /* grab the first string from the list */
@@ -370,7 +370,7 @@ gboolean obt_prop_get_strings_utf8(Window win, Atom prop, gchar ***ret)
gchar *raw, *p;
guint num, i, count = 0;
- if (get_all(win, prop, obt_prop_atom(OBT_PROP_UTF8), 8,
+ if (get_all(win, prop, OBT_PROP_ATOM(UTF8), 8,
(guchar**)&raw, &num))
{
p = raw;
@@ -408,16 +408,47 @@ void obt_prop_set_array32(Window win, Atom prop, Atom type, gulong *val,
(guchar*)val, num);
}
+void obt_prop_set_string_locale(Window win, Atom prop, const gchar *val)
+{
+ const gchar *s[2] = { val, NULL };
+ obt_prop_set_strings_locale(win, prop, s);
+}
+
+void obt_prop_set_strings_locale(Window win, Atom prop,
+ const gchar **strs)
+{
+ gint i, count;
+ gchar **lstrs;
+ XTextProperty tprop;
+
+ /* count the strings in strs, and convert them to the locale format */
+ for (count = 0; strs[count]; ++count);
+ lstrs = g_new0(char*, count);
+ for (i = 0; i < count; ++i) {
+ lstrs[i] = g_locale_from_utf8(strs[i], -1, NULL, NULL, NULL);
+ if (!lstrs[i]) {
+ lstrs[i] = g_strdup(""); /* make it an empty string */
+ g_warning("Unable to translate string '%s' from UTF8 to locale "
+ "format", strs[i]);
+ }
+ }
+
+
+ XStringListToTextProperty(lstrs, count, &tprop);
+ XSetTextProperty(obt_display, win, &tprop, prop);
+ XFree(tprop.value);
+}
+
void obt_prop_set_string_utf8(Window win, Atom prop, const gchar *val)
{
- XChangeProperty(obt_display, win, prop, obt_prop_atom(OBT_PROP_UTF8), 8,
+ XChangeProperty(obt_display, win, prop, OBT_PROP_ATOM(UTF8), 8,
PropModeReplace, (const guchar*)val, strlen(val));
}
-void obt_prop_set_strings_utf8(Window win, Atom prop, gchar **strs)
+void obt_prop_set_strings_utf8(Window win, Atom prop, const gchar **strs)
{
GString *str;
- gchar **s;
+ const gchar **s;
str = g_string_sized_new(0);
for (s = strs; *s; ++s) {
diff --git a/obt/prop.h b/obt/prop.h
index d11a7355..0ccde376 100644
--- a/obt/prop.h
+++ b/obt/prop.h
@@ -225,8 +225,12 @@ gboolean obt_prop_get_strings_utf8(Window win, Atom prop, gchar ***ret);
void obt_prop_set32(Window win, Atom prop, Atom type, gulong val);
void obt_prop_set_array32(Window win, Atom prop, Atom type, gulong *val,
guint num);
+void obt_prop_set_string_locale(Window win, Atom prop, const gchar *val);
void obt_prop_set_string_utf8(Window win, Atom prop, const gchar *val);
-void obt_prop_set_strings_utf8(Window win, Atom prop, gchar **strs);
+void obt_prop_set_strings_locale(Window win, Atom prop,
+ const gchar **strs);
+void obt_prop_set_strings_utf8(Window win, Atom prop,
+ const gchar **strs);
void obt_prop_erase(Window win, Atom prop);
@@ -254,10 +258,10 @@ void obt_prop_message_to(Window to, Window about, Atom messagetype,
#define OBT_PROP_SETA32(win, prop, type, val, num) \
(obt_prop_set_array32(win, OBT_PROP_ATOM(prop), OBT_PROP_ATOM(type), \
val, num))
-#define OBT_PROP_SETS(win, prop, val) \
- (obt_prop_set_string_utf8(win, OBT_PROP_ATOM(prop), val))
-#define OBT_PROP_SETSS(win, prop, strs) \
- (obt_prop_set_strings_utf8(win, OBT_PROP_ATOM(prop), strs))
+#define OBT_PROP_SETS(win, prop, type, val) \
+ (obt_prop_set_string_##type(win, OBT_PROP_ATOM(prop), val))
+#define OBT_PROP_SETSS(win, prop, type, strs) \
+ (obt_prop_set_strings_##type(win, OBT_PROP_ATOM(prop), strs))
#define OBT_PROP_ERASE(win, prop) (obt_prop_erase(win, OBT_PROP_ATOM(prop)))