comparison plugins/gaimrc.c @ 10584:7de819b5ed68

[gaim-migrate @ 11988] Here you go Sean. Here's your interface to the gtkrc settings plugin. It's probably far from what you'd intended in a bunch of ways but it should do about what you want. Everyone feel free to tell me what they don't like about it. committer: Tailor Script <tailor@pidgin.im>
author Etan Reisner <pidgin@unreliablesource.net>
date Thu, 10 Feb 2005 06:35:32 +0000
parents
children a6b8a23b4d5f
comparison
equal deleted inserted replaced
10583:a4c6f8deac96 10584:7de819b5ed68
1 /**
2 * @file gaimrc.c Gaim gtk resource control plugin.
3 *
4 * Copyright (C) 2005 Etan Reisner <deryni@eden.rutgers.edu>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include "internal.h"
22 #include "gtkplugin.h"
23 #include "gtkprefs.h"
24 #include "gtkutils.h"
25 #include "version.h"
26
27 static guint pref_callback;
28
29 static const char *color_prefs[] = {
30 "/plugins/gtk/gaimrc/color/GtkWidget::cursor-color",
31 "/plugins/gtk/gaimrc/color/GtkWidget::secondary-cursor-color",
32 "/plugins/gtk/gaimrc/color/GtkIMHtml::hyperlink-color"
33 };
34 static const char *color_prefs_set[] = {
35 "/plugins/gtk/gaimrc/set/color/GtkWidget::cursor-color",
36 "/plugins/gtk/gaimrc/set/color/GtkWidget::secondary-cursor-color",
37 "/plugins/gtk/gaimrc/set/color/GtkIMHtml::hyperlink-color"
38 };
39 static const char *color_names[] = {
40 _("Cursor Color"),
41 _("Secondary Cursor Color"),
42 _("Hyperlink Color")
43 };
44 static GtkWidget *color_widgets[G_N_ELEMENTS(color_prefs)];
45
46 static const char *widget_size_prefs[] = {
47 "/plugins/gtk/gaimrc/size/GtkTreeView::expander_size"
48 };
49 static const char *widget_size_prefs_set[] = {
50 "/plugins/gtk/gaimrc/set/size/GtkTreeView::expander_size"
51 };
52 static const char *widget_size_names[] = {
53 _("GtkTreeView Expander Size")
54 };
55 static GtkWidget *widget_size_widgets[G_N_ELEMENTS(widget_size_prefs)];
56
57 static const char *font_prefs[] = {
58 "/plugins/gtk/gaimrc/font/*gaim_gtkconv_entry",
59 "/plugins/gtk/gaimrc/font/*gaim_gtkconv_imhtml",
60 "/plugins/gtk/gaimrc/font/*gaim_gtklog_imhtml",
61 "/plugins/gtk/gaimrc/font/*gaim_gtkrequest_imhtml",
62 "/plugins/gtk/gaimrc/font/*gaim_gtknotify_imhtml",
63 };
64 static const char *font_prefs_set[] = {
65 "/plugins/gtk/gaimrc/set/font/*gaim_gtkconv_entry",
66 "/plugins/gtk/gaimrc/set/font/*gaim_gtkconv_imhtml",
67 "/plugins/gtk/gaimrc/set/font/*gaim_gtklog_imhtml",
68 "/plugins/gtk/gaimrc/set/font/*gaim_gtkrequest_imhtml",
69 "/plugins/gtk/gaimrc/set/font/*gaim_gtknotify_imhtml",
70 };
71 static const char *font_names[] = {
72 _("Conversation Entry"),
73 _("Conversation History"),
74 _("Log Viewer"),
75 _("Request Dialog"),
76 _("Notify Dialog")
77 };
78 static GtkWidget *font_widgets[G_N_ELEMENTS(font_prefs)];
79
80 static void
81 gaimrc_make_changes()
82 {
83 int i;
84 GString *style_string = g_string_new("");
85 char *prefbase = NULL;
86
87 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name")) {
88 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name");
89 g_string_append_printf(style_string, "gtk-font-name = \"%s\"\n", pref);
90 }
91
92 if (gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name")) {
93 const char *pref = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-key-theme-name");
94 g_string_append_printf(style_string, "gtk-key-theme-name = \"%s\"\n", pref);
95 }
96
97 g_string_append(style_string, "style \"gaimrc_style\" {\n");
98
99 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) {
100 if (gaim_prefs_get_bool(color_prefs_set[i])) {
101 prefbase = g_path_get_basename(color_prefs[i]);
102 g_string_append_printf(style_string,
103 "%s = \"%s\"\n", prefbase,
104 gaim_prefs_get_string(color_prefs[i]));
105 g_free(prefbase);
106 }
107 }
108
109 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) {
110 if (gaim_prefs_get_bool(widget_size_prefs_set[i])) {
111 prefbase = g_path_get_basename(widget_size_prefs[i]);
112 g_string_append_printf(style_string,
113 "%s = \"%d\"\n", prefbase,
114 gaim_prefs_get_int(widget_size_prefs[i]));
115 g_free(prefbase);
116 }
117 }
118
119 g_string_append(style_string, "}");
120 g_string_append(style_string, "widget_class \"*\" style \"gaimrc_style\"\n");
121
122 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) {
123 if (gaim_prefs_get_bool(font_prefs_set[i])) {
124 prefbase = g_path_get_basename(font_prefs[i]);
125 g_string_append_printf(style_string,
126 "style \"%s_style\"\n"
127 "{font_name = \"%s\"}\n"
128 "widget \"%s\""
129 "style \"%s_style\"\n", prefbase,
130 gaim_prefs_get_string(font_prefs[i]),
131 prefbase, prefbase);
132 g_free(prefbase);
133 }
134 }
135
136 gtk_rc_parse_string(style_string->str);
137
138 g_string_free(style_string, TRUE);
139 }
140
141 static void
142 gaimrc_pref_changed_cb(const char *name, GaimPrefType type, gpointer value,
143 gpointer data)
144 {
145 GString *style_string = g_string_new("");
146 char *prefbase = NULL;
147
148 prefbase = g_path_get_basename(name);
149
150 if (strncmp(name, "/plugins/gtk/gaimrc/color", 25) == 0) {
151 g_string_printf(style_string,
152 "style \"gaimrc_style\" { %s = \"%s\" }"
153 "widget_class \"*\" style \"gaimrc_style\"",
154 prefbase, (char *)value);
155 } else if (strncmp(name, "/plugins/gtk/gaimrc/size", 24) == 0) {
156 g_string_printf(style_string,
157 "style \"gaimrc_style\" { %s = \"%d\" }"
158 "widget_class \"*\" style \"gaimrc_style\"",
159 prefbase, GPOINTER_TO_INT(value));
160 } else if (strncmp(name, "/plugins/gtk/gaimrc/font", 24) == 0) {
161 g_string_printf(style_string, "style \"%s_style\""
162 "{ font_name = \"%s\" } widget \"%s\""
163 "style \"%s_style\"",
164 prefbase, (char *)value, prefbase, prefbase);
165 } else if (strncmp(name, "/plugins/gtk/gaimrc/set", 23) == 0) {
166 if (value)
167 gaimrc_make_changes();
168 g_string_free(style_string, TRUE);
169
170 return;
171 } else {
172 g_string_printf(style_string, "%s = \"%s\"",
173 prefbase, (char *)value);
174 }
175 gtk_rc_parse_string(style_string->str);
176
177 g_string_free(style_string, TRUE);
178 g_free(prefbase);
179 }
180
181 static void
182 gaimrc_color_response(GtkDialog *color_dialog, gint response, gpointer data)
183 {
184 int subscript = GPOINTER_TO_INT(data);
185
186 if (response == GTK_RESPONSE_OK) {
187 GtkWidget *colorsel = GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel;
188 GdkColor color;
189 char colorstr[8];
190
191 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), &color);
192
193 g_snprintf(colorstr, sizeof(colorstr), "#%02X%02X%02X",
194 color.red/256, color.green/256, color.blue/256);
195
196 gaim_prefs_set_string(color_prefs[subscript], colorstr);
197 }
198 gtk_widget_destroy(GTK_WIDGET(color_dialog));
199 }
200
201 static void
202 gaimrc_set_color(GtkWidget *widget, gpointer data)
203 {
204 GtkWidget *color_dialog = NULL;
205 GdkColor color;
206 char title[128];
207 int subscript = GPOINTER_TO_INT(data);
208
209 g_snprintf(title, sizeof(title), _("Select Color for %s"),
210 color_names[GPOINTER_TO_INT(data)]);
211 color_dialog = gtk_color_selection_dialog_new(_("Select Color"));
212 g_signal_connect(G_OBJECT(color_dialog), "response",
213 G_CALLBACK(gaimrc_color_response), data);
214
215 if (gdk_color_parse(gaim_prefs_get_string(color_prefs[subscript]),
216 &color)) {
217 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(color_dialog)->colorsel), &color);
218 }
219
220 gtk_window_present(GTK_WINDOW(color_dialog));
221 }
222
223 static void
224 gaimrc_font_response(GtkDialog *font_dialog, gint response, gpointer data)
225 {
226 int subscript = GPOINTER_TO_INT(data);
227
228 if (response == GTK_RESPONSE_OK) {
229 char *fontname = NULL;
230
231 fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(font_dialog));
232
233 gaim_prefs_set_string(font_prefs[subscript], fontname);
234 g_free(fontname);
235 }
236 gtk_widget_destroy(GTK_WIDGET(font_dialog));
237 }
238
239 static void
240 gaimrc_set_font(GtkWidget *widget, gpointer data)
241 {
242 GtkWidget *font_dialog = NULL;
243 char title[128];
244 int subscript = GPOINTER_TO_INT(data);
245
246 g_snprintf(title, sizeof(title), _("Select Font for %s"),
247 font_names[subscript]);
248 font_dialog = gtk_font_selection_dialog_new(title);
249 g_signal_connect(G_OBJECT(font_dialog), "response",
250 G_CALLBACK(gaimrc_font_response), data);
251
252 /* TODO Figure out a way to test for the presence of a value in the
253 * actual pref
254 if (gaim_prefs_get_bool(font_prefs[subscript])) {
255 gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), gaim_prefs_get_string(font_prefs[subscript]));
256 }
257 */
258
259 gtk_window_present(GTK_WINDOW(font_dialog));
260 }
261
262 static void
263 gaimrc_font_response_special(GtkDialog *font_dialog, gint response,
264 gpointer data)
265 {
266 if (response == GTK_RESPONSE_OK) {
267 char *fontname = NULL;
268
269 fontname = gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(font_dialog));
270
271 gaim_prefs_set_string("/plugins/gtk/gaimrc/gtk-font-name",
272 fontname);
273 g_free(fontname);
274 }
275 gtk_widget_destroy(GTK_WIDGET(font_dialog));
276 }
277
278 static void
279 gaimrc_set_font_special(GtkWidget *widget, gpointer data)
280 {
281 GtkWidget *font_dialog = NULL;
282 const char *font = NULL;
283
284 font_dialog = gtk_font_selection_dialog_new(_("Select Interface Font"));
285 g_signal_connect(G_OBJECT(font_dialog), "response",
286 G_CALLBACK(gaimrc_font_response_special), NULL);
287
288 font = gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name");
289 /* TODO Figure out a way to test for the presence of a value in the
290 * actual pref
291 printf("font - %s.\n", font);
292 if (font != NULL && font != "") {
293 gtk_font_selection_set_font_name(GTK_FONT_SELECTION(GTK_FONT_SELECTION_DIALOG(font_dialog)->fontsel), gaim_prefs_get_string("/plugins/gtk/gaimrc/gtk-font-name"));
294 }
295 */
296
297 gtk_window_present(GTK_WINDOW(font_dialog));
298 }
299
300 static gboolean
301 gaimrc_plugin_load(GaimPlugin *plugin)
302 {
303 gaimrc_make_changes();
304
305 gaim_prefs_connect_callback(plugin, "/plugins/gtk/gaimrc",
306 gaimrc_pref_changed_cb, NULL);
307
308 return TRUE;
309 }
310
311 static gboolean
312 gaimrc_plugin_unload(GaimPlugin *plugin)
313 {
314 gaim_prefs_disconnect_callback(pref_callback);
315
316 return TRUE;
317 }
318
319 static GtkWidget *
320 gaimrc_get_config_frame(GaimPlugin *plugin)
321 {
322 GtkWidget *ret = NULL, *frame = NULL, *hbox = NULL;
323 /*
324 GtkWidget *check = NULL, *widget = NULL, *label = NULL;
325 */
326 GtkWidget *check = NULL, *widget = NULL;
327 GtkSizeGroup *sg = NULL;
328 /*
329 char sample[7] = "Sample";
330 */
331 int i;
332
333 ret = gtk_vbox_new(FALSE, 18);
334 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
335
336 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
337
338 frame = gaim_gtk_make_frame(ret, "General");
339 /* interface font */
340 hbox = gtk_hbox_new(FALSE, 18);
341 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0);
342
343 check = gaim_gtk_prefs_checkbox(_("Gtk interface font"),
344 "/plugins/gtk/gaimrc/set/gtk-font-name",
345 hbox);
346 gtk_size_group_add_widget(sg, check);
347
348 widget = gaim_pixbuf_button_from_stock("", GTK_STOCK_SELECT_FONT,
349 GAIM_BUTTON_HORIZONTAL);
350 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 0);
351 gtk_widget_set_sensitive(widget,
352 gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-font-name"));
353 g_signal_connect(G_OBJECT(check), "toggled",
354 G_CALLBACK(gaim_gtk_toggle_sensitive), widget);
355 g_signal_connect(G_OBJECT(widget), "clicked",
356 G_CALLBACK(gaimrc_set_font_special), NULL);
357
358 /* key theme name */
359 hbox = gtk_hbox_new(FALSE, 18);
360 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0);
361
362 check = gaim_gtk_prefs_checkbox(_("Gtk text shortcut theme"),
363 "/plugins/gtk/gaimrc/set/gtk-key-theme-name",
364 hbox);
365 gtk_size_group_add_widget(sg, check);
366
367 widget = gaim_gtk_prefs_labeled_entry(hbox, "",
368 "/plugins/gtk/gaimrc/gtk-key-theme-name",
369 NULL);
370 gtk_widget_set_sensitive(widget,
371 gaim_prefs_get_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name"));
372 g_signal_connect(G_OBJECT(check), "toggled",
373 G_CALLBACK(gaim_gtk_toggle_sensitive), widget);
374
375 frame = gaim_gtk_make_frame(ret, "Interface colors");
376 /* imhtml stuff */
377 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) {
378 hbox = gtk_hbox_new(FALSE, 18);
379 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0);
380
381 check = gaim_gtk_prefs_checkbox(_(color_names[i]),
382 color_prefs_set[i], hbox);
383 gtk_size_group_add_widget(sg, check);
384
385 color_widgets[i] = gaim_pixbuf_button_from_stock("", GTK_STOCK_SELECT_COLOR, GAIM_BUTTON_HORIZONTAL);
386 gtk_size_group_add_widget(sg, color_widgets[i]);
387 gtk_box_pack_start(GTK_BOX(hbox), color_widgets[i], FALSE,
388 FALSE, 0);
389 gtk_widget_set_sensitive(color_widgets[i],
390 gaim_prefs_get_bool(color_prefs_set[i]));
391 g_signal_connect(G_OBJECT(check), "toggled",
392 G_CALLBACK(gaim_gtk_toggle_sensitive),
393 color_widgets[i]);
394 g_signal_connect(G_OBJECT(color_widgets[i]), "clicked",
395 G_CALLBACK(gaimrc_set_color),
396 GINT_TO_POINTER(i));
397 }
398
399 frame = gaim_gtk_make_frame(ret, "Widget Sizes");
400 /* imhtml font stuff */
401 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) {
402 hbox = gtk_hbox_new(FALSE, 18);
403 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0);
404
405 check = gaim_gtk_prefs_checkbox(_(widget_size_names[i]),
406 widget_size_prefs_set[i], hbox);
407 gtk_size_group_add_widget(sg, check);
408
409 widget_size_widgets[i] = gaim_gtk_prefs_labeled_spin_button(hbox, "", widget_size_prefs[i], 0, 50, sg);
410 gtk_widget_set_sensitive(widget_size_widgets[i],
411 gaim_prefs_get_bool(widget_size_prefs_set[i]));
412 g_signal_connect(G_OBJECT(check), "toggled",
413 G_CALLBACK(gaim_gtk_toggle_sensitive),
414 widget_size_widgets[i]);
415 }
416
417 frame = gaim_gtk_make_frame(ret, "Fonts");
418 /* imhtml font stuff */
419 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) {
420 hbox = gtk_hbox_new(FALSE, 18);
421 gtk_box_pack_start(GTK_BOX(frame), hbox, FALSE, FALSE, 0);
422
423 check = gaim_gtk_prefs_checkbox(_(font_names[i]),
424 font_prefs_set[i], hbox);
425 gtk_size_group_add_widget(sg, check);
426
427 font_widgets[i] = gaim_pixbuf_button_from_stock("", GTK_STOCK_SELECT_FONT, GAIM_BUTTON_HORIZONTAL);
428 gtk_size_group_add_widget(sg, font_widgets[i]);
429 gtk_box_pack_start(GTK_BOX(hbox), font_widgets[i], FALSE,
430 FALSE, 0);
431 gtk_widget_set_sensitive(font_widgets[i],
432 gaim_prefs_get_bool(font_prefs_set[i]));
433 g_signal_connect(G_OBJECT(check), "toggled",
434 G_CALLBACK(gaim_gtk_toggle_sensitive),
435 font_widgets[i]);
436 g_signal_connect(G_OBJECT(font_widgets[i]), "clicked",
437 G_CALLBACK(gaimrc_set_font), GINT_TO_POINTER(i));
438 }
439
440 gtk_widget_show_all(ret);
441 return ret;
442 }
443
444 static GaimGtkPluginUiInfo gaimrc_ui_info =
445 {
446 gaimrc_get_config_frame
447 };
448
449 static GaimPluginInfo gaimrc_info =
450 {
451 GAIM_PLUGIN_MAGIC,
452 GAIM_MAJOR_VERSION,
453 GAIM_MINOR_VERSION,
454 GAIM_PLUGIN_STANDARD,
455 GAIM_GTK_PLUGIN_TYPE,
456 0,
457 NULL,
458 GAIM_PRIORITY_DEFAULT,
459 "gaimrc",
460 N_("Gaim GTK+ Theme Control"),
461 VERSION,
462 N_("Provides access to commonly used gtkrc settings."),
463 N_("Provides access to commonly used gtkrc settings."),
464 "Etan Reisner <deryni@eden.rutgers.edu>",
465 GAIM_WEBSITE,
466 gaimrc_plugin_load,
467 gaimrc_plugin_unload,
468 NULL,
469 &gaimrc_ui_info,
470 NULL,
471 NULL,
472 NULL
473 };
474
475 static void
476 gaimrc_init(GaimPlugin *plugin)
477 {
478 int i;
479
480 gaim_prefs_add_none("/plugins");
481 gaim_prefs_add_none("/plugins/gtk");
482 gaim_prefs_add_none("/plugins/gtk/gaimrc");
483 gaim_prefs_add_none("/plugins/gtk/gaimrc/set");
484
485 gaim_prefs_add_string("/plugins/gtk/gaimrc/gtk-font-name", "");
486 gaim_prefs_add_bool("/plugins/gtk/gaimrc/set/gtk-font-name", FALSE);
487
488 gaim_prefs_add_string("/plugins/gtk/gaimrc/gtk-key-theme-name", "");
489 gaim_prefs_add_bool("/plugins/gtk/gaimrc/set/gtk-key-theme-name", FALSE);
490
491 gaim_prefs_add_none("/plugins/gtk/gaimrc/color");
492 gaim_prefs_add_none("/plugins/gtk/gaimrc/set/color");
493 for (i = 0; i < G_N_ELEMENTS(color_prefs); i++) {
494 gaim_prefs_add_string(color_prefs[i], "");
495 gaim_prefs_add_bool(color_prefs_set[i], FALSE);
496 }
497
498 gaim_prefs_add_none("/plugins/gtk/gaimrc/size");
499 gaim_prefs_add_none("/plugins/gtk/gaimrc/set/size");
500 for (i = 0; i < G_N_ELEMENTS(widget_size_prefs); i++) {
501 gaim_prefs_add_int(widget_size_prefs[i], 0);
502 gaim_prefs_add_bool(widget_size_prefs_set[i], FALSE);
503 }
504
505 gaim_prefs_add_none("/plugins/gtk/gaimrc/font");
506 gaim_prefs_add_none("/plugins/gtk/gaimrc/set/font");
507 for (i = 0; i < G_N_ELEMENTS(font_prefs); i++) {
508 gaim_prefs_add_string(font_prefs[i], "");
509 gaim_prefs_add_bool(font_prefs_set[i], FALSE);
510 }
511 }
512
513 GAIM_INIT_PLUGIN(gaimrc, gaimrc_init, gaimrc_info)