comparison finch/libgnt/gntstyle.c @ 18295:464004cc58e4

propagate from branch 'im.pidgin.pidgin' (head 704b8c18f7c29f1fc8bfcf640275d2a9928ed03c) to branch 'org.maemo.garage.pidgin.smiley-install' (head 6a34c0d525ca3bb40837ac0334d8a353af0b0e34)
author Gabriel Schulhof <nix@go-nix.ca>
date Wed, 27 Jun 2007 21:43:18 +0000
parents 7e0bd339533c
children adcb44a07a2d 1cb69ea47a6e
comparison
equal deleted inserted replaced
17919:6c9c16275868 18295:464004cc58e4
1 /**
2 * GNT - The GLib Ncurses Toolkit
3 *
4 * GNT is the legal property of its developers, whose names are too numerous
5 * to list here. Please refer to the COPYRIGHT file distributed with this
6 * source distribution.
7 *
8 * This library is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
1 #include "gntstyle.h" 23 #include "gntstyle.h"
2 #include "gntcolors.h" 24 #include "gntcolors.h"
3 25 #include "gntws.h"
26
27 #include <glib.h>
4 #include <ctype.h> 28 #include <ctype.h>
29 #include <glib/gprintf.h>
30 #include <stdlib.h>
5 #include <string.h> 31 #include <string.h>
6 32
33 #define MAX_WORKSPACES 99
34
7 #if GLIB_CHECK_VERSION(2,6,0) 35 #if GLIB_CHECK_VERSION(2,6,0)
8 static GKeyFile *gkfile; 36 static GKeyFile *gkfile;
9 #endif 37 #endif
10 38
39 static GHashTable *unknowns;
11 static char * str_styles[GNT_STYLES]; 40 static char * str_styles[GNT_STYLES];
12 static int int_styles[GNT_STYLES]; 41 static int int_styles[GNT_STYLES];
13 static int bool_styles[GNT_STYLES]; 42 static int bool_styles[GNT_STYLES];
14 43
15 const char *gnt_style_get(GntStyle style) 44 const char *gnt_style_get(GntStyle style)
16 { 45 {
17 return str_styles[style]; 46 return str_styles[style];
47 }
48
49 const char *gnt_style_get_from_name(const char *name)
50 {
51 return g_hash_table_lookup(unknowns, name);
18 } 52 }
19 53
20 gboolean gnt_style_get_bool(GntStyle style, gboolean def) 54 gboolean gnt_style_get_bool(GntStyle style, gboolean def)
21 { 55 {
22 int i; 56 int i;
85 parse_key(const char *key) 119 parse_key(const char *key)
86 { 120 {
87 return (char *)gnt_key_translate(key); 121 return (char *)gnt_key_translate(key);
88 } 122 }
89 123
124 void gnt_style_read_workspaces(GntWM *wm)
125 {
126 #if GLIB_CHECK_VERSION(2,6,0)
127 int i;
128 gchar *name;
129 gsize c;
130
131 for (i = 1; i < MAX_WORKSPACES; ++i) {
132 int j;
133 GntWS *ws;
134 gchar **titles;
135 char *group = calloc(12, 1);
136 g_sprintf(group, "Workspace-%d", i);
137 name = g_key_file_get_value(gkfile, group, "name", NULL);
138 if (!name)
139 return;
140
141 ws = gnt_ws_new(name);
142 gnt_wm_add_workspace(wm, ws);
143 g_free(name);
144
145 titles = g_key_file_get_string_list(gkfile, group, "window-names", &c, NULL);
146 if (titles) {
147 for (j = 0; j < c; ++j)
148 g_hash_table_replace(wm->name_places, g_strdup(titles[j]), ws);
149 g_strfreev(titles);
150 }
151
152 titles = g_key_file_get_string_list(gkfile, group, "window-titles", &c, NULL);
153 if (titles) {
154 for (j = 0; j < c; ++j)
155 g_hash_table_replace(wm->title_places, g_strdup(titles[j]), ws);
156 g_strfreev(titles);
157 }
158 g_free(group);
159 }
160 #endif
161 }
90 void gnt_style_read_actions(GType type, GntBindableClass *klass) 162 void gnt_style_read_actions(GType type, GntBindableClass *klass)
91 { 163 {
92 #if GLIB_CHECK_VERSION(2,6,0) 164 #if GLIB_CHECK_VERSION(2,6,0)
93 char *name; 165 char *name;
94 GError *error = NULL; 166 GError *error = NULL;
219 for (i = 0; styles[i].style; i++) 291 for (i = 0; styles[i].style; i++)
220 { 292 {
221 str_styles[styles[i].en] = 293 str_styles[styles[i].en] =
222 g_key_file_get_string(kfile, "general", styles[i].style, NULL); 294 g_key_file_get_string(kfile, "general", styles[i].style, NULL);
223 } 295 }
296
297 for (i = 0; i < nkeys; i++)
298 g_hash_table_replace(unknowns, g_strdup(keys[i]),
299 g_strdup(g_key_file_get_string(kfile, "general", keys[i], NULL)));
224 } 300 }
225 g_strfreev(keys); 301 g_strfreev(keys);
226 } 302 }
227 #endif 303 #endif
228 304
229 void gnt_style_read_configure_file(const char *filename) 305 void gnt_style_read_configure_file(const char *filename)
230 { 306 {
231 #if GLIB_CHECK_VERSION(2,6,0) 307 #if GLIB_CHECK_VERSION(2,6,0)
232 GError *error = NULL; 308 GError *error = NULL;
233 gkfile = g_key_file_new(); 309 gkfile = g_key_file_new();
310 unknowns = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
234 311
235 if (!g_key_file_load_from_file(gkfile, filename, G_KEY_FILE_NONE, &error)) 312 if (!g_key_file_load_from_file(gkfile, filename, G_KEY_FILE_NONE, &error))
236 { 313 {
237 g_printerr("GntStyle: %s\n", error->message); 314 g_printerr("GntStyle: %s\n", error->message);
238 g_error_free(error); 315 g_error_free(error);
258 { 335 {
259 int i; 336 int i;
260 for (i = 0; i < GNT_STYLES; i++) 337 for (i = 0; i < GNT_STYLES; i++)
261 g_free(str_styles[i]); 338 g_free(str_styles[i]);
262 339
340 g_hash_table_destroy(unknowns);
263 #if GLIB_CHECK_VERSION(2,6,0) 341 #if GLIB_CHECK_VERSION(2,6,0)
264 g_key_file_free(gkfile); 342 g_key_file_free(gkfile);
265 #endif 343 #endif
266 } 344 }
267 345