1 /* Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
2 * Copyright (c) 2008-2009 Robert Ancell
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2, or (at your option)
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include <sys/types.h>
29 #include <sys/param.h>
31 #include <gconf/gconf-client.h>
37 #define EQUAL(a, b) (strlen(a)==strlen(b)) & !strcmp(a, b)
39 /* Various string values read/written as X resources. */
41 static GConfClient
*client
= NULL
;
45 get_resource(const char *key
)
47 char key_name
[MAXLINE
];
48 SNPRINTF(key_name
, MAXLINE
, "/apps/gcalctool/%s", key
);
49 return gconf_client_get_string(client
, key_name
, NULL
);
54 set_resource(const char *key
, const char *value
)
56 char key_name
[MAXLINE
];
57 SNPRINTF(key_name
, MAXLINE
, "/apps/gcalctool/%s", key
);
58 gconf_client_set_string(client
, key_name
, value
, NULL
);
63 set_int_resource(const char *key
, int value
)
65 char key_name
[MAXLINE
];
66 SNPRINTF(key_name
, MAXLINE
, "/apps/gcalctool/%s", key
);
67 gconf_client_set_int(client
, key_name
, value
, NULL
);
72 set_boolean_resource(const char *key
, int value
)
74 char key_name
[MAXLINE
];
75 SNPRINTF(key_name
, MAXLINE
, "/apps/gcalctool/%s", key
);
76 gconf_client_set_bool(client
, key_name
, value
, NULL
);
80 void set_enumerated_resource(const char *key
, const char *values
[], int value
)
82 set_resource(key
, values
[value
]);
87 get_int_resource(const char *key
, int *intval
)
89 char key_name
[MAXLINE
];
93 SNPRINTF(key_name
, MAXLINE
, "/apps/gcalctool/%s", key
);
94 v
= gconf_client_get_int(client
, key_name
, &error
);
104 get_boolean_resource(const char *key
, int *boolval
)
106 char key_name
[MAXLINE
];
107 GError
*error
= NULL
;
110 SNPRINTF(key_name
, MAXLINE
, "/apps/gcalctool/%s", key
);
111 v
= gconf_client_get_bool(client
, key_name
, &error
);
121 get_enumerated_resource(const char *key
, const char *values
[], int *value
)
124 int i
, retval
= FALSE
;
126 val
= get_resource(key
);
130 for (i
= 0; values
[i
]; i
++) {
131 if (strcmp(values
[i
], val
) == 0) {
143 /* Return the radix character. For most locales, this is a period.
144 * If nl_langinfo(RADIXCHAR) returns an empty string, return ",".
151 setlocale(LC_NUMERIC
, "");
152 if ((radix
= nl_langinfo(RADIXCHAR
)) != NULL
) {
153 radix
= g_locale_to_utf8(radix
, -1, NULL
, NULL
, NULL
);
156 if (radix
== NULL
|| radix
[0] == '\0') {
164 /* Return the thousands separator string. For most locales, this is a
172 setlocale(LC_NUMERIC
, "");
173 if ((tsep
= nl_langinfo(THOUSEP
)) != NULL
) {
174 tsep
= g_locale_to_utf8(tsep
, -1, NULL
, NULL
, NULL
);
195 assert(client
== NULL
);
196 client
= gconf_client_get_default();
197 gconf_client_add_dir(client
, "/apps/gcalctool", GCONF_CLIENT_PRELOAD_NONE
, NULL
);