]> icculus.org git repositories - dana/obconf.git/blob - src/appearance.c
Polish translation for ObConf (Fix bug 5371)
[dana/obconf.git] / src / appearance.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
2
3    appearance.c for ObConf, the configuration tool for Openbox
4    Copyright (c) 2003-2007   Dana Jansens
5    Copyright (c) 2003        Tim Riley
6
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    See the COPYING file for a copy of the GNU General Public License.
18 */
19
20 #include "main.h"
21 #include "tree.h"
22 #include "preview_update.h"
23
24 static gboolean mapping = FALSE;
25
26 static RrFont *read_font(GtkFontButton *w, const gchar *place, gboolean def);
27 static RrFont *write_font(GtkFontButton *w, const gchar *place);
28
29 void appearance_setup_tab()
30 {
31     GtkWidget *w;
32     gchar *layout;
33     RrFont *f;
34
35     mapping = TRUE;
36
37     w = get_widget("window_border");
38     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
39                                  tree_get_bool("theme/keepBorder", TRUE));
40
41     w = get_widget("animate_iconify");
42     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w),
43                                  tree_get_bool("theme/animateIconify", TRUE));
44
45     w = get_widget("title_layout");
46     layout = tree_get_string("theme/titleLayout", "NLIMC");
47     gtk_entry_set_text(GTK_ENTRY(w), layout);
48     preview_update_set_title_layout(layout);
49     g_free(layout);
50
51     w = get_widget("font_active");
52     f = read_font(GTK_FONT_BUTTON(w), "ActiveWindow", TRUE);
53     preview_update_set_active_font(f);
54
55     w = get_widget("font_inactive");
56     f = read_font(GTK_FONT_BUTTON(w), "InactiveWindow", TRUE);
57     preview_update_set_inactive_font(f);
58
59     w = get_widget("font_menu_header");
60     f = read_font(GTK_FONT_BUTTON(w), "MenuHeader", TRUE);
61     preview_update_set_menu_header_font(f);
62
63     w = get_widget("font_menu_item");
64     f = read_font(GTK_FONT_BUTTON(w), "MenuItem", TRUE);
65     preview_update_set_menu_item_font(f);
66
67     w = get_widget("font_active_display");
68     if (!(f = read_font(GTK_FONT_BUTTON(w), "ActiveOnScreenDisplay", FALSE))) {
69         f = read_font(GTK_FONT_BUTTON(w), "OnScreenDisplay", TRUE);
70         tree_delete_node("theme/font:place=OnScreenDisplay");
71     }
72     preview_update_set_osd_active_font(f);
73
74     w = get_widget("font_inactive_display");
75     f = read_font(GTK_FONT_BUTTON(w), "InactiveOnScreenDisplay", TRUE);
76     preview_update_set_osd_inactive_font(f);
77
78     mapping = FALSE;
79 }
80
81 void on_window_border_toggled(GtkToggleButton *w, gpointer data)
82 {
83     gboolean b;
84
85     if (mapping) return;
86
87     b = gtk_toggle_button_get_active(w);
88     tree_set_bool("theme/keepBorder", b);
89 }
90
91 void on_animate_iconify_toggled(GtkToggleButton *w, gpointer data)
92 {
93     gboolean b;
94
95     if (mapping) return;
96
97     b = gtk_toggle_button_get_active(w);
98     tree_set_bool("theme/animateIconify", b);
99 }
100
101 void on_title_layout_changed(GtkEntry *w, gpointer data)
102 {
103     gchar *layout;
104     gchar *it, *it2;
105     gboolean n, d, s, l, i, m, c;
106
107     if (mapping) return;
108
109     layout = g_strdup(gtk_entry_get_text(w));
110
111     n = d = s = l = i = m = c = FALSE;
112
113     for (it = layout; *it; ++it) {
114         gboolean *b;
115
116         switch (*it) {
117         case 'N':
118         case 'n':
119             b = &n;
120             break;
121         case 'd':
122         case 'D':
123             b = &d;
124             break;
125         case 's':
126         case 'S':
127             b = &s;
128             break;
129         case 'l':
130         case 'L':
131             b = &l;
132             break;
133         case 'i':
134         case 'I':
135             b = &i;
136             break;
137         case 'm':
138         case 'M':
139             b = &m;
140             break;
141         case 'c':
142         case 'C':
143             b = &c;
144             break;
145         default:
146             b = NULL;
147             break;
148         }
149
150         if (!b || *b) {
151             /* drop the letter */
152             for (it2 = it; *it2; ++it2)
153                 *it2 = *(it2+1);
154         } else {
155             *it = toupper(*it);
156             *b = TRUE;
157         }
158     }
159
160     gtk_entry_set_text(w, layout);
161     tree_set_string("theme/titleLayout", layout);
162     preview_update_set_title_layout(layout);
163
164     g_free(layout);
165 }
166
167 void on_font_active_font_set(GtkFontButton *w, gpointer data)
168 {
169     if (mapping) return;
170
171     preview_update_set_active_font(write_font(w, "ActiveWindow"));
172 }
173
174 void on_font_inactive_font_set(GtkFontButton *w, gpointer data)
175 {
176     if (mapping) return;
177
178     preview_update_set_inactive_font(write_font(w, "InactiveWindow"));
179 }
180
181 void on_font_menu_header_font_set(GtkFontButton *w, gpointer data)
182 {
183     if (mapping) return;
184
185     preview_update_set_menu_header_font(write_font(w, "MenuHeader"));
186 }
187
188 void on_font_menu_item_font_set(GtkFontButton *w, gpointer data)
189 {
190     if (mapping) return;
191
192     preview_update_set_menu_item_font(write_font(w, "MenuItem"));
193 }
194
195 void on_font_active_display_font_set(GtkFontButton *w, gpointer data)
196 {
197     if (mapping) return;
198
199     preview_update_set_osd_active_font(write_font(w, "ActiveOnScreenDisplay"));
200 }
201
202 void on_font_inactive_display_font_set(GtkFontButton *w, gpointer data)
203 {
204     if (mapping) return;
205
206     preview_update_set_osd_inactive_font
207         (write_font(w, "InactiveOnScreenDisplay"));
208 }
209
210 static RrFont *read_font(GtkFontButton *w, const gchar *place,
211                          gboolean use_default)
212 {
213     RrFont *font;
214     gchar *fontstring, *node;
215     gchar *name, **names;
216     gchar *size;
217     gchar *weight;
218     gchar *slant;
219
220     RrFontWeight rr_weight = RR_FONTWEIGHT_NORMAL;
221     RrFontSlant rr_slant = RR_FONTSLANT_NORMAL;
222
223     mapping = TRUE;
224
225     node = g_strdup_printf("theme/font:place=%s/name", place);
226     name = tree_get_string(node, use_default ? "Sans" : NULL);
227     g_free(node);
228
229     if (name[0] == '\0') {
230         g_free(name);
231         return NULL;
232     }
233
234     node = g_strdup_printf("theme/font:place=%s/size", place);
235     size = tree_get_string(node, "8");
236     g_free(node);
237
238     node = g_strdup_printf("theme/font:place=%s/weight", place);
239     weight = tree_get_string(node, "");
240     g_free(node);
241
242     node = g_strdup_printf("theme/font:place=%s/slant", place);
243     slant = tree_get_string(node, "");
244     g_free(node);
245
246     /* get only the first font in the string */
247     names = g_strsplit(name, ",", 0);
248     g_free(name);
249     name = g_strdup(names[0]);
250     g_strfreev(names);
251
252     /* don't use "normal" in the gtk string */
253     if (!g_ascii_strcasecmp(weight, "normal")) {
254         g_free(weight); weight = g_strdup("");
255     }
256     if (!g_ascii_strcasecmp(slant, "normal")) {
257         g_free(slant); slant = g_strdup("");
258     }
259
260     fontstring = g_strdup_printf("%s %s %s %s", name, weight, slant, size);
261     gtk_font_button_set_font_name(w, fontstring);
262
263     if (!g_ascii_strcasecmp(weight, "Bold")) rr_weight = RR_FONTWEIGHT_BOLD;
264     if (!g_ascii_strcasecmp(slant, "Italic")) rr_slant = RR_FONTSLANT_ITALIC;
265     if (!g_ascii_strcasecmp(slant, "Oblique")) rr_slant = RR_FONTSLANT_OBLIQUE;
266
267     font = RrFontOpen(rrinst, name, atoi(size), rr_weight, rr_slant);
268     g_free(fontstring);
269     g_free(slant);
270     g_free(weight);
271     g_free(size);
272     g_free(name);
273
274     mapping = FALSE;
275
276     return font;
277 }
278
279 static RrFont *write_font(GtkFontButton *w, const gchar *place)
280 {
281     gchar *c;
282     gchar *font, *node;
283     const gchar *size = NULL;
284     const gchar *bold = NULL;
285     const gchar *italic = NULL;
286
287     RrFontWeight weight = RR_FONTWEIGHT_NORMAL;
288     RrFontSlant slant = RR_FONTSLANT_NORMAL;
289
290     if (mapping) return;
291
292     font = g_strdup(gtk_font_button_get_font_name(w));
293     while ((c = strrchr(font, ' '))) {
294         if (!bold && !italic && !size && atoi(c+1))
295             size = c+1;
296         else if (!bold && !italic && !g_ascii_strcasecmp(c+1, "italic"))
297             italic = c+1;
298         else if (!bold && !g_ascii_strcasecmp(c+1, "bold"))
299             bold = c+1;
300         else
301             break;
302         *c = '\0';
303     }
304     if (!bold) bold = "Normal";
305     if (!italic) italic = "Normal";
306
307     node = g_strdup_printf("theme/font:place=%s/name", place);
308     tree_set_string(node, font);
309     g_free(node);
310
311     node = g_strdup_printf("theme/font:place=%s/size", place);
312     tree_set_string(node, size);
313     g_free(node);
314
315     node = g_strdup_printf("theme/font:place=%s/weight", place);
316     tree_set_string(node, bold);
317     g_free(node);
318
319     node = g_strdup_printf("theme/font:place=%s/slant", place);
320     tree_set_string(node, italic);
321     g_free(node);
322
323     if (!g_ascii_strcasecmp(bold, "Bold")) weight = RR_FONTWEIGHT_BOLD;
324     if (!g_ascii_strcasecmp(italic, "Italic")) slant = RR_FONTSLANT_ITALIC;
325     if (!g_ascii_strcasecmp(italic, "Oblique")) slant = RR_FONTSLANT_OBLIQUE;
326
327     return RrFontOpen(rrinst, font, atoi(size), weight, slant);
328
329     g_free(font);
330
331 }