Mercurial > pidgin
annotate finch/libgnt/gntstyle.c @ 18874:5dd1cfc53666
Make the menus a little more usable.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 11 Aug 2007 05:09:33 +0000 |
parents | dcb1d1af30a1 |
children | 9f7587b86b0d 8d9913d9fe5a |
rev | line source |
---|---|
18049
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
1 /** |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
2 * GNT - The GLib Ncurses Toolkit |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
3 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
4 * GNT is the legal property of its developers, whose names are too numerous |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
6 * source distribution. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
7 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
8 * This library is free software; you can redistribute it and/or modify |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
11 * (at your option) any later version. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
12 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
16 * GNU General Public License for more details. |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
17 * |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
19 * along with this program; if not, write to the Free Software |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
21 */ |
1cedd520cd18
Doxygen skeleton and license info for gnt files.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18045
diff
changeset
|
22 |
15817 | 23 #include "gntstyle.h" |
24 #include "gntcolors.h" | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
25 #include "gntws.h" |
15817 | 26 |
18045
08e93462f189
Update the irssi WM to allow tiling the conversation windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
27 #include <glib.h> |
15817 | 28 #include <ctype.h> |
17704
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
29 #include <glib/gprintf.h> |
18085
afd96f97c50a
Get rid of a little compile error
Mark Doliner <mark@kingant.net>
parents:
18069
diff
changeset
|
30 #include <stdlib.h> |
15817 | 31 #include <string.h> |
32 | |
17703
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
17698
diff
changeset
|
33 #define MAX_WORKSPACES 99 |
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
17698
diff
changeset
|
34 |
15817 | 35 #if GLIB_CHECK_VERSION(2,6,0) |
36 static GKeyFile *gkfile; | |
37 #endif | |
38 | |
39 static char * str_styles[GNT_STYLES]; | |
40 static int int_styles[GNT_STYLES]; | |
41 static int bool_styles[GNT_STYLES]; | |
42 | |
43 const char *gnt_style_get(GntStyle style) | |
44 { | |
45 return str_styles[style]; | |
46 } | |
47 | |
18317
8aff2d3d6820
Plug a memory leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18312
diff
changeset
|
48 char *gnt_style_get_from_name(const char *group, const char *key) |
18045
08e93462f189
Update the irssi WM to allow tiling the conversation windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
49 { |
18312
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
50 #if GLIB_CHECK_VERSION(2,6,0) |
18530
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
51 const char *prg = g_get_prgname(); |
18540
612bc00efe20
Typo fix. This bit of code must be cursed.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18530
diff
changeset
|
52 if ((group == NULL || *group == '\0') && prg && |
18530
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
53 g_key_file_has_group(gkfile, prg)) |
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
54 group = prg; |
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
55 if (!group) |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
56 group = "general"; |
18312
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
57 return g_key_file_get_value(gkfile, group, key, NULL); |
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
58 #endif |
18045
08e93462f189
Update the irssi WM to allow tiling the conversation windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
59 } |
08e93462f189
Update the irssi WM to allow tiling the conversation windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
60 |
15817 | 61 gboolean gnt_style_get_bool(GntStyle style, gboolean def) |
62 { | |
63 const char * str; | |
64 | |
65 if (bool_styles[style] != -1) | |
66 return bool_styles[style]; | |
67 | |
68 str = gnt_style_get(style); | |
69 | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
70 bool_styles[style] = str ? gnt_style_parse_bool(str) : def; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
71 return bool_styles[style]; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
72 } |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
73 |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
74 gboolean gnt_style_parse_bool(const char *str) |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
75 { |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
76 gboolean def = FALSE; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
77 int i; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
78 |
15817 | 79 if (str) |
80 { | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
81 if (g_ascii_strcasecmp(str, "false") == 0) |
15817 | 82 def = FALSE; |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
83 else if (g_ascii_strcasecmp(str, "true") == 0) |
15817 | 84 def = TRUE; |
85 else if (sscanf(str, "%d", &i) == 1) | |
86 { | |
87 if (i) | |
88 def = TRUE; | |
89 else | |
90 def = FALSE; | |
91 } | |
92 } | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
93 return def; |
15817 | 94 } |
95 | |
96 static void | |
97 refine(char *text) | |
98 { | |
99 char *s = text, *t = text; | |
100 | |
101 while (*s) | |
102 { | |
103 if (*s == '^' && *(s + 1) == '[') | |
104 { | |
105 *t = '\033'; /* escape */ | |
106 s++; | |
107 } | |
108 else if (*s == '\\') | |
109 { | |
110 if (*(s + 1) == '\0') | |
111 *t = ' '; | |
112 else | |
113 { | |
114 s++; | |
115 if (*s == 'r' || *s == 'n') | |
116 *t = '\r'; | |
117 else if (*s == 't') | |
118 *t = '\t'; | |
119 else | |
120 *t = *s; | |
121 } | |
122 } | |
123 else | |
124 *t = *s; | |
125 t++; | |
126 s++; | |
127 } | |
128 *t = '\0'; | |
129 } | |
130 | |
131 static char * | |
132 parse_key(const char *key) | |
133 { | |
134 return (char *)gnt_key_translate(key); | |
135 } | |
136 | |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
137 void gnt_style_read_workspaces(GntWM *wm) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
138 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
139 #if GLIB_CHECK_VERSION(2,6,0) |
17703
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
17698
diff
changeset
|
140 int i; |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
141 gchar *name; |
17704
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
142 gsize c; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
143 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
144 for (i = 1; i < MAX_WORKSPACES; ++i) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
145 int j; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
146 GntWS *ws; |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
147 gchar **titles; |
18581
dcb1d1af30a1
This could have resulted in buffer overflow if the user had 10 or more
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18540
diff
changeset
|
148 char group[32]; |
dcb1d1af30a1
This could have resulted in buffer overflow if the user had 10 or more
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18540
diff
changeset
|
149 g_snprintf(group, sizeof(group), "Workspace-%d", i); |
17704
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
150 name = g_key_file_get_value(gkfile, group, "name", NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
151 if (!name) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
152 return; |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
153 |
18076
da183b86a3ef
Update for the new api.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18069
diff
changeset
|
154 ws = gnt_ws_new(name); |
17704
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
155 gnt_wm_add_workspace(wm, ws); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
156 g_free(name); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
157 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
158 titles = g_key_file_get_string_list(gkfile, group, "window-names", &c, NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
159 if (titles) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
160 for (j = 0; j < c; ++j) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
161 g_hash_table_replace(wm->name_places, g_strdup(titles[j]), ws); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
162 g_strfreev(titles); |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
163 } |
17704
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
164 |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
165 titles = g_key_file_get_string_list(gkfile, group, "window-titles", &c, NULL); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
166 if (titles) { |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
167 for (j = 0; j < c; ++j) |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
168 g_hash_table_replace(wm->title_places, g_strdup(titles[j]), ws); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
169 g_strfreev(titles); |
5acee0788697
New windows can be placed on specific workspaces. They can be specified by the window name (e.g. conversation-window), or a substring in the window title. Title takes precedence.
Richard Nelson <wabz@pidgin.im>
parents:
17703
diff
changeset
|
170 } |
17698
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
171 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
172 #endif |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
173 } |
15817 | 174 void gnt_style_read_actions(GType type, GntBindableClass *klass) |
175 { | |
176 #if GLIB_CHECK_VERSION(2,6,0) | |
177 char *name; | |
178 GError *error = NULL; | |
179 | |
180 name = g_strdup_printf("%s::binding", g_type_name(type)); | |
181 | |
182 if (g_key_file_has_group(gkfile, name)) | |
183 { | |
184 gsize len = 0; | |
185 char **keys; | |
186 | |
187 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
188 if (error) | |
189 { | |
190 g_printerr("GntStyle: %s\n", error->message); | |
191 g_error_free(error); | |
192 g_free(name); | |
193 return; | |
194 } | |
195 | |
196 while (len--) | |
197 { | |
198 char *key, *action; | |
199 | |
200 key = g_strdup(keys[len]); | |
201 action = g_key_file_get_string(gkfile, name, keys[len], &error); | |
202 | |
203 if (error) | |
204 { | |
205 g_printerr("GntStyle: %s\n", error->message); | |
206 g_error_free(error); | |
207 error = NULL; | |
208 } | |
209 else | |
210 { | |
211 const char *keycode = parse_key(key); | |
212 if (keycode == NULL) { | |
213 g_printerr("GntStyle: Invalid key-binding %s\n", key); | |
214 } else { | |
215 gnt_bindable_register_binding(klass, action, keycode, NULL); | |
216 } | |
217 } | |
218 g_free(key); | |
219 g_free(action); | |
220 } | |
221 g_strfreev(keys); | |
222 } | |
223 g_free(name); | |
224 #endif | |
225 } | |
226 | |
227 void gnt_styles_get_keyremaps(GType type, GHashTable *hash) | |
228 { | |
229 #if GLIB_CHECK_VERSION(2,6,0) | |
230 char *name; | |
231 GError *error = NULL; | |
232 | |
233 name = g_strdup_printf("%s::remap", g_type_name(type)); | |
234 | |
235 if (g_key_file_has_group(gkfile, name)) | |
236 { | |
237 gsize len = 0; | |
238 char **keys; | |
239 | |
240 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
241 if (error) | |
242 { | |
243 g_printerr("GntStyle: %s\n", error->message); | |
244 g_error_free(error); | |
245 g_free(name); | |
246 return; | |
247 } | |
248 | |
249 while (len--) | |
250 { | |
251 char *key, *replace; | |
252 | |
253 key = g_strdup(keys[len]); | |
254 replace = g_key_file_get_string(gkfile, name, keys[len], &error); | |
255 | |
256 if (error) | |
257 { | |
258 g_printerr("GntStyle: %s\n", error->message); | |
259 g_error_free(error); | |
260 error = NULL; | |
261 g_free(key); | |
262 } | |
263 else | |
264 { | |
265 refine(key); | |
266 refine(replace); | |
267 g_hash_table_insert(hash, key, replace); | |
268 } | |
269 } | |
270 g_strfreev(keys); | |
271 } | |
272 | |
273 g_free(name); | |
274 #endif | |
275 } | |
276 | |
277 #if GLIB_CHECK_VERSION(2,6,0) | |
278 static void | |
279 read_general_style(GKeyFile *kfile) | |
280 { | |
281 GError *error = NULL; | |
282 gsize nkeys; | |
18362
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
283 const char *prgname = g_get_prgname(); |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
284 char **keys = NULL; |
15817 | 285 int i; |
286 struct | |
287 { | |
288 const char *style; | |
289 GntStyle en; | |
290 } styles[] = {{"shadow", GNT_STYLE_SHADOW}, | |
291 {"customcolor", GNT_STYLE_COLOR}, | |
292 {"mouse", GNT_STYLE_MOUSE}, | |
293 {"wm", GNT_STYLE_WM}, | |
294 {"remember_position", GNT_STYLE_REMPOS}, | |
295 {NULL, 0}}; | |
296 | |
18362
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
297 if (prgname && *prgname) |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
298 keys = g_key_file_get_keys(kfile, prgname, &nkeys, NULL); |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
299 |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
300 if (keys == NULL) { |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
301 prgname = "general"; |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
302 keys = g_key_file_get_keys(kfile, prgname, &nkeys, &error); |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
303 } |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
304 |
15817 | 305 if (error) |
306 { | |
307 g_printerr("GntStyle: %s\n", error->message); | |
308 g_error_free(error); | |
309 } | |
310 else | |
311 { | |
312 for (i = 0; styles[i].style; i++) | |
313 { | |
314 str_styles[styles[i].en] = | |
18362
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
315 g_key_file_get_string(kfile, prgname, styles[i].style, NULL); |
15817 | 316 } |
317 } | |
318 g_strfreev(keys); | |
319 } | |
320 #endif | |
321 | |
322 void gnt_style_read_configure_file(const char *filename) | |
323 { | |
324 #if GLIB_CHECK_VERSION(2,6,0) | |
325 GError *error = NULL; | |
326 gkfile = g_key_file_new(); | |
327 | |
18312
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
328 if (!g_key_file_load_from_file(gkfile, filename, |
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
329 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) |
15817 | 330 { |
331 g_printerr("GntStyle: %s\n", error->message); | |
332 g_error_free(error); | |
333 return; | |
334 } | |
335 gnt_colors_parse(gkfile); | |
336 read_general_style(gkfile); | |
337 #endif | |
338 } | |
339 | |
340 void gnt_init_styles() | |
341 { | |
342 int i; | |
343 for (i = 0; i < GNT_STYLES; i++) | |
344 { | |
345 str_styles[i] = NULL; | |
346 int_styles[i] = -1; | |
347 bool_styles[i] = -1; | |
348 } | |
349 } | |
350 | |
351 void gnt_uninit_styles() | |
352 { | |
353 int i; | |
354 for (i = 0; i < GNT_STYLES; i++) | |
355 g_free(str_styles[i]); | |
356 | |
357 #if GLIB_CHECK_VERSION(2,6,0) | |
358 g_key_file_free(gkfile); | |
359 #endif | |
360 } | |
361 |