Mercurial > pidgin.yaz
comparison console/libgnt/gntstyle.c @ 14239:a0b1ab181316
[gaim-migrate @ 16921]
Allow remapping keys for widgets.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 20 Aug 2006 22:46:20 +0000 |
parents | bb38f32ab6aa |
children | ea5193c23171 |
comparison
equal
deleted
inserted
replaced
14238:f189327b9968 | 14239:a0b1ab181316 |
---|---|
1 #include "gntstyle.h" | 1 #include "gntstyle.h" |
2 #include "gntcolors.h" | 2 #include "gntcolors.h" |
3 | 3 |
4 #include <string.h> | 4 #include <string.h> |
5 | |
6 #if GLIB_CHECK_VERSION(2,6,0) | |
7 static GKeyFile *gkfile; | |
8 #endif | |
5 | 9 |
6 static char * str_styles[GNT_STYLES]; | 10 static char * str_styles[GNT_STYLES]; |
7 static int int_styles[GNT_STYLES]; | 11 static int int_styles[GNT_STYLES]; |
8 static int bool_styles[GNT_STYLES]; | 12 static int bool_styles[GNT_STYLES]; |
9 | 13 |
39 | 43 |
40 bool_styles[style] = def; | 44 bool_styles[style] = def; |
41 return bool_styles[style]; | 45 return bool_styles[style]; |
42 } | 46 } |
43 | 47 |
48 void refine(char *text) | |
49 { | |
50 char *s = text, *t = text; | |
51 | |
52 while (*s) | |
53 { | |
54 if (*s == '^' && *(s + 1) == '[') | |
55 { | |
56 *t = '\033'; /* escape */ | |
57 s++; | |
58 } | |
59 else if (*s == '\\') | |
60 { | |
61 if (*(s + 1) == '\0') | |
62 *t = ' '; | |
63 else | |
64 { | |
65 s++; | |
66 if (*s == 'r' || *s == 'n') | |
67 *t = '\r'; | |
68 else if (*s == 't') | |
69 *t = '\t'; | |
70 else | |
71 *t = *s; | |
72 } | |
73 } | |
74 else | |
75 *t = *s; | |
76 t++; | |
77 s++; | |
78 } | |
79 *t = '\0'; | |
80 } | |
81 | |
82 void gnt_styles_get_keyremaps(GType type, GHashTable *hash) | |
83 { | |
84 #if GLIB_CHECK_VERSION(2,6,0) | |
85 char *name; | |
86 GError *error = NULL; | |
87 | |
88 name = g_strdup_printf("%s::remap", g_type_name(type)); | |
89 | |
90 if (g_key_file_has_group(gkfile, name)) | |
91 { | |
92 unsigned int len = 0; | |
93 char **keys; | |
94 | |
95 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
96 if (error) | |
97 { | |
98 g_printerr("GntStyle: %s\n", error->message); | |
99 g_error_free(error); | |
100 return; | |
101 } | |
102 | |
103 while (len--) | |
104 { | |
105 char *key, *replace; | |
106 | |
107 key = g_strdup(keys[len]); | |
108 replace = g_key_file_get_string(gkfile, name, keys[len], &error); | |
109 | |
110 if (error) | |
111 { | |
112 g_printerr("GntStyle: %s\n", error->message); | |
113 g_error_free(error); | |
114 error = NULL; | |
115 g_free(key); | |
116 } | |
117 else | |
118 { | |
119 refine(key); | |
120 refine(replace); | |
121 g_hash_table_insert(hash, key, replace); | |
122 } | |
123 } | |
124 g_strfreev(keys); | |
125 } | |
126 | |
127 g_free(name); | |
128 #endif | |
129 } | |
130 | |
44 #if GLIB_CHECK_VERSION(2,6,0) | 131 #if GLIB_CHECK_VERSION(2,6,0) |
45 static void | 132 static void |
46 read_general_style(GKeyFile *kfile) | 133 read_general_style(GKeyFile *kfile) |
47 { | 134 { |
48 GError *error = NULL; | 135 GError *error = NULL; |
56 } styles[] = {{"shadow", GNT_STYLE_SHADOW}, | 143 } styles[] = {{"shadow", GNT_STYLE_SHADOW}, |
57 {NULL, 0}}; | 144 {NULL, 0}}; |
58 | 145 |
59 if (error) | 146 if (error) |
60 { | 147 { |
61 /* XXX: some error happened. */ | 148 g_printerr("GntStyle: %s\n", error->message); |
62 g_error_free(error); | 149 g_error_free(error); |
63 } | 150 } |
64 else | 151 else |
65 { | 152 { |
66 for (i = 0; styles[i].style; i++) | 153 for (i = 0; styles[i].style; i++) |
68 error = NULL; | 155 error = NULL; |
69 str_styles[styles[i].en] = | 156 str_styles[styles[i].en] = |
70 g_key_file_get_string(kfile, "general", styles[i].style, &error); | 157 g_key_file_get_string(kfile, "general", styles[i].style, &error); |
71 } | 158 } |
72 } | 159 } |
160 g_strfreev(keys); | |
73 } | 161 } |
74 #endif | 162 #endif |
75 | 163 |
76 void gnt_style_read_configure_file(const char *filename) | 164 void gnt_style_read_configure_file(const char *filename) |
77 { | 165 { |
78 #if GLIB_CHECK_VERSION(2,6,0) | 166 #if GLIB_CHECK_VERSION(2,6,0) |
79 GKeyFile *kfile = g_key_file_new(); | 167 gkfile = g_key_file_new(); |
80 GError *error = NULL; | 168 GError *error = NULL; |
81 | 169 |
82 if (!g_key_file_load_from_file(kfile, filename, G_KEY_FILE_NONE, &error)) | 170 if (!g_key_file_load_from_file(gkfile, filename, G_KEY_FILE_NONE, &error)) |
83 { | 171 { |
84 /* XXX: Print the error or something */ | 172 g_printerr("GntStyle: %s\n", error->message); |
85 g_error_free(error); | 173 g_error_free(error); |
86 return; | 174 return; |
87 } | 175 } |
88 gnt_colors_parse(kfile); | 176 gnt_colors_parse(gkfile); |
89 read_general_style(kfile); | 177 read_general_style(gkfile); |
90 | |
91 g_key_file_free(kfile); | |
92 #endif | 178 #endif |
93 } | 179 } |
94 | 180 |
95 void gnt_init_styles() | 181 void gnt_init_styles() |
96 { | 182 { |
106 void gnt_uninit_styles() | 192 void gnt_uninit_styles() |
107 { | 193 { |
108 int i; | 194 int i; |
109 for (i = 0; i < GNT_STYLES; i++) | 195 for (i = 0; i < GNT_STYLES; i++) |
110 g_free(str_styles[i]); | 196 g_free(str_styles[i]); |
111 } | 197 |
112 | 198 #if GLIB_CHECK_VERSION(2,6,0) |
199 g_key_file_free(gkfile); | |
200 #endif | |
201 } | |
202 |