Mercurial > pidgin.yaz
annotate finch/libgnt/gntstyle.c @ 21174:6e0c99e134c2
Fix the win32 build for the file synchronization changes. Hopefully this will fix some of the occasional issues that people have had on Windows with their files getting corrupted on power failure or something.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Fri, 09 Nov 2007 01:39:51 +0000 |
parents | 9b2376dde204 |
children | b65f1bff6412 |
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 |
19680
44b4e8bd759b
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
19381
diff
changeset
|
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
18049
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 |
15818 | 23 #include "gntstyle.h" |
24 #include "gntcolors.h" | |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
25 #include "gntws.h" |
15818 | 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> |
15818 | 28 #include <ctype.h> |
18085
afd96f97c50a
Get rid of a little compile error
Mark Doliner <mark@kingant.net>
parents:
18069
diff
changeset
|
29 #include <stdlib.h> |
15818 | 30 #include <string.h> |
31 | |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16414
diff
changeset
|
32 #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:
16414
diff
changeset
|
33 |
15818 | 34 #if GLIB_CHECK_VERSION(2,6,0) |
35 static GKeyFile *gkfile; | |
36 #endif | |
37 | |
38 static char * str_styles[GNT_STYLES]; | |
39 static int int_styles[GNT_STYLES]; | |
40 static int bool_styles[GNT_STYLES]; | |
41 | |
42 const char *gnt_style_get(GntStyle style) | |
43 { | |
44 return str_styles[style]; | |
45 } | |
46 | |
18317
8aff2d3d6820
Plug a memory leak.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18312
diff
changeset
|
47 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
|
48 { |
18312
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
49 #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
|
50 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
|
51 if ((group == NULL || *group == '\0') && prg && |
18530
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
52 g_key_file_has_group(gkfile, prg)) |
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
53 group = prg; |
fbca9cd907a1
I think this is the intended behaviour
Richard Nelson <wabz@pidgin.im>
parents:
18509
diff
changeset
|
54 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
|
55 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
|
56 return g_key_file_get_value(gkfile, group, key, NULL); |
19381
8d9913d9fe5a
Get rid of compile warnings on older glib.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18581
diff
changeset
|
57 #else |
8d9913d9fe5a
Get rid of compile warnings on older glib.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18581
diff
changeset
|
58 return NULL; |
18312
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
59 #endif |
18045
08e93462f189
Update the irssi WM to allow tiling the conversation windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
60 } |
08e93462f189
Update the irssi WM to allow tiling the conversation windows.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15964
diff
changeset
|
61 |
15818 | 62 gboolean gnt_style_get_bool(GntStyle style, gboolean def) |
63 { | |
64 const char * str; | |
65 | |
66 if (bool_styles[style] != -1) | |
67 return bool_styles[style]; | |
68 | |
69 str = gnt_style_get(style); | |
70 | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
71 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
|
72 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
|
73 } |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
74 |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
75 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
|
76 { |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
77 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
|
78 int i; |
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
79 |
15818 | 80 if (str) |
81 { | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
82 if (g_ascii_strcasecmp(str, "false") == 0) |
15818 | 83 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
|
84 else if (g_ascii_strcasecmp(str, "true") == 0) |
15818 | 85 def = TRUE; |
86 else if (sscanf(str, "%d", &i) == 1) | |
87 { | |
88 if (i) | |
89 def = TRUE; | |
90 else | |
91 def = FALSE; | |
92 } | |
93 } | |
18506
9f029b7208f1
Allow one-line high buttons. Specify 'small-button = true' under 'general',
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18362
diff
changeset
|
94 return def; |
15818 | 95 } |
96 | |
19381
8d9913d9fe5a
Get rid of compile warnings on older glib.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18581
diff
changeset
|
97 #if GLIB_CHECK_VERSION(2,6,0) |
15818 | 98 static void |
99 refine(char *text) | |
100 { | |
101 char *s = text, *t = text; | |
102 | |
103 while (*s) | |
104 { | |
105 if (*s == '^' && *(s + 1) == '[') | |
106 { | |
107 *t = '\033'; /* escape */ | |
108 s++; | |
109 } | |
110 else if (*s == '\\') | |
111 { | |
112 if (*(s + 1) == '\0') | |
113 *t = ' '; | |
114 else | |
115 { | |
116 s++; | |
117 if (*s == 'r' || *s == 'n') | |
118 *t = '\r'; | |
119 else if (*s == 't') | |
120 *t = '\t'; | |
121 else | |
122 *t = *s; | |
123 } | |
124 } | |
125 else | |
126 *t = *s; | |
127 t++; | |
128 s++; | |
129 } | |
130 *t = '\0'; | |
131 } | |
132 | |
133 static char * | |
134 parse_key(const char *key) | |
135 { | |
136 return (char *)gnt_key_translate(key); | |
137 } | |
19381
8d9913d9fe5a
Get rid of compile warnings on older glib.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18581
diff
changeset
|
138 #endif |
15818 | 139 |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
140 void gnt_style_read_workspaces(GntWM *wm) |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
141 { |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
142 #if GLIB_CHECK_VERSION(2,6,0) |
16472
4ea517cb7ceb
Show an activity message when a window in the non-current workspace is flagged urgent
Richard Nelson <wabz@pidgin.im>
parents:
16414
diff
changeset
|
143 int i; |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
144 gchar *name; |
16473
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:
16472
diff
changeset
|
145 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:
16472
diff
changeset
|
146 |
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:
16472
diff
changeset
|
147 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:
16472
diff
changeset
|
148 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:
16472
diff
changeset
|
149 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:
16472
diff
changeset
|
150 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
|
151 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
|
152 g_snprintf(group, sizeof(group), "Workspace-%d", i); |
16473
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:
16472
diff
changeset
|
153 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:
16472
diff
changeset
|
154 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:
16472
diff
changeset
|
155 return; |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
156 |
18076
da183b86a3ef
Update for the new api.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18069
diff
changeset
|
157 ws = gnt_ws_new(name); |
16473
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:
16472
diff
changeset
|
158 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:
16472
diff
changeset
|
159 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:
16472
diff
changeset
|
160 |
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:
16472
diff
changeset
|
161 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:
16472
diff
changeset
|
162 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:
16472
diff
changeset
|
163 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:
16472
diff
changeset
|
164 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:
16472
diff
changeset
|
165 g_strfreev(titles); |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
166 } |
16473
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:
16472
diff
changeset
|
167 |
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:
16472
diff
changeset
|
168 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:
16472
diff
changeset
|
169 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:
16472
diff
changeset
|
170 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:
16472
diff
changeset
|
171 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:
16472
diff
changeset
|
172 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:
16472
diff
changeset
|
173 } |
16414
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
174 } |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
175 #endif |
56d2ae9cbb5c
Initial workspace support. refs #51
Richard Nelson <wabz@pidgin.im>
parents:
15964
diff
changeset
|
176 } |
15818 | 177 void gnt_style_read_actions(GType type, GntBindableClass *klass) |
178 { | |
179 #if GLIB_CHECK_VERSION(2,6,0) | |
180 char *name; | |
181 GError *error = NULL; | |
182 | |
183 name = g_strdup_printf("%s::binding", g_type_name(type)); | |
184 | |
185 if (g_key_file_has_group(gkfile, name)) | |
186 { | |
187 gsize len = 0; | |
188 char **keys; | |
189 | |
190 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
191 if (error) | |
192 { | |
193 g_printerr("GntStyle: %s\n", error->message); | |
194 g_error_free(error); | |
195 g_free(name); | |
196 return; | |
197 } | |
198 | |
199 while (len--) | |
200 { | |
201 char *key, *action; | |
202 | |
203 key = g_strdup(keys[len]); | |
204 action = g_key_file_get_string(gkfile, name, keys[len], &error); | |
205 | |
206 if (error) | |
207 { | |
208 g_printerr("GntStyle: %s\n", error->message); | |
209 g_error_free(error); | |
210 error = NULL; | |
211 } | |
212 else | |
213 { | |
214 const char *keycode = parse_key(key); | |
215 if (keycode == NULL) { | |
216 g_printerr("GntStyle: Invalid key-binding %s\n", key); | |
217 } else { | |
218 gnt_bindable_register_binding(klass, action, keycode, NULL); | |
219 } | |
220 } | |
221 g_free(key); | |
222 g_free(action); | |
223 } | |
224 g_strfreev(keys); | |
225 } | |
226 g_free(name); | |
227 #endif | |
228 } | |
229 | |
230 void gnt_styles_get_keyremaps(GType type, GHashTable *hash) | |
231 { | |
232 #if GLIB_CHECK_VERSION(2,6,0) | |
233 char *name; | |
234 GError *error = NULL; | |
235 | |
236 name = g_strdup_printf("%s::remap", g_type_name(type)); | |
237 | |
238 if (g_key_file_has_group(gkfile, name)) | |
239 { | |
240 gsize len = 0; | |
241 char **keys; | |
242 | |
243 keys = g_key_file_get_keys(gkfile, name, &len, &error); | |
244 if (error) | |
245 { | |
246 g_printerr("GntStyle: %s\n", error->message); | |
247 g_error_free(error); | |
248 g_free(name); | |
249 return; | |
250 } | |
251 | |
252 while (len--) | |
253 { | |
254 char *key, *replace; | |
255 | |
256 key = g_strdup(keys[len]); | |
257 replace = g_key_file_get_string(gkfile, name, keys[len], &error); | |
258 | |
259 if (error) | |
260 { | |
261 g_printerr("GntStyle: %s\n", error->message); | |
262 g_error_free(error); | |
263 error = NULL; | |
264 g_free(key); | |
265 } | |
266 else | |
267 { | |
268 refine(key); | |
269 refine(replace); | |
270 g_hash_table_insert(hash, key, replace); | |
271 } | |
272 } | |
273 g_strfreev(keys); | |
274 } | |
275 | |
276 g_free(name); | |
277 #endif | |
278 } | |
279 | |
280 #if GLIB_CHECK_VERSION(2,6,0) | |
281 static void | |
282 read_general_style(GKeyFile *kfile) | |
283 { | |
284 GError *error = NULL; | |
285 gsize nkeys; | |
18362
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
286 const char *prgname = g_get_prgname(); |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
287 char **keys = NULL; |
15818 | 288 int i; |
289 struct | |
290 { | |
291 const char *style; | |
292 GntStyle en; | |
293 } styles[] = {{"shadow", GNT_STYLE_SHADOW}, | |
294 {"customcolor", GNT_STYLE_COLOR}, | |
295 {"mouse", GNT_STYLE_MOUSE}, | |
296 {"wm", GNT_STYLE_WM}, | |
297 {"remember_position", GNT_STYLE_REMPOS}, | |
298 {NULL, 0}}; | |
299 | |
18362
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
300 if (prgname && *prgname) |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
301 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
|
302 |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
303 if (keys == NULL) { |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
304 prgname = "general"; |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
305 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
|
306 } |
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
307 |
15818 | 308 if (error) |
309 { | |
310 g_printerr("GntStyle: %s\n", error->message); | |
311 g_error_free(error); | |
312 } | |
313 else | |
314 { | |
315 for (i = 0; styles[i].style; i++) | |
316 { | |
317 str_styles[styles[i].en] = | |
18362
65ed0916d3bc
Allowing specifying different styles for different applications.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18317
diff
changeset
|
318 g_key_file_get_string(kfile, prgname, styles[i].style, NULL); |
15818 | 319 } |
320 } | |
321 g_strfreev(keys); | |
322 } | |
323 #endif | |
324 | |
325 void gnt_style_read_configure_file(const char *filename) | |
326 { | |
327 #if GLIB_CHECK_VERSION(2,6,0) | |
328 GError *error = NULL; | |
329 gkfile = g_key_file_new(); | |
330 | |
18312
adcb44a07a2d
This is a more flexible way of getting random settings from .gntrc.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
18091
diff
changeset
|
331 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
|
332 G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS, &error)) |
15818 | 333 { |
334 g_printerr("GntStyle: %s\n", error->message); | |
335 g_error_free(error); | |
336 return; | |
337 } | |
338 gnt_colors_parse(gkfile); | |
339 read_general_style(gkfile); | |
340 #endif | |
341 } | |
342 | |
343 void gnt_init_styles() | |
344 { | |
345 int i; | |
346 for (i = 0; i < GNT_STYLES; i++) | |
347 { | |
348 str_styles[i] = NULL; | |
349 int_styles[i] = -1; | |
350 bool_styles[i] = -1; | |
351 } | |
352 } | |
353 | |
354 void gnt_uninit_styles() | |
355 { | |
356 int i; | |
357 for (i = 0; i < GNT_STYLES; i++) | |
358 g_free(str_styles[i]); | |
359 | |
360 #if GLIB_CHECK_VERSION(2,6,0) | |
361 g_key_file_free(gkfile); | |
362 #endif | |
363 } | |
364 |