3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
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.
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.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
25 #include "theme-manager.h"
28 #include "gtkblist-theme.h"
30 #include "gtkplugin.h"
32 #define PLUGIN_ID "gtk-theme-editor"
34 #include "themeedit-icon.h"
37 prop_type_is_color(PidginBlistTheme
*theme
, const char *prop
)
39 PidginBlistThemeClass
*klass
= PIDGIN_BLIST_THEME_GET_CLASS(theme
);
40 GParamSpec
*spec
= g_object_class_find_property(G_OBJECT_CLASS(klass
), prop
);
42 return G_IS_PARAM_SPEC_BOXED(spec
);
47 save_blist_theme(GtkWidget
*w
, GtkWidget
*window
)
50 gtk_widget_destroy(window
);
55 close_blist_theme(GtkWidget
*w
, GtkWidget
*window
)
57 gtk_widget_destroy(window
);
61 theme_color_selected(GtkDialog
*dialog
, gint response
, const char *prop
)
63 if (response
== GTK_RESPONSE_OK
) {
66 PidginBlistTheme
*theme
;
68 #if GTK_CHECK_VERSION(2,14,0)
70 gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog
));
72 colorsel
= GTK_COLOR_SELECTION_DIALOG(dialog
)->colorsel
;
74 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel
), &color
);
76 theme
= pidgin_blist_get_theme();
78 if (prop_type_is_color(theme
, prop
)) {
79 g_object_set(G_OBJECT(theme
), prop
, &color
, NULL
);
81 PidginThemeFont
*font
= NULL
;
82 g_object_get(G_OBJECT(theme
), prop
, &font
, NULL
);
84 font
= pidgin_theme_font_new(NULL
, &color
);
85 g_object_set(G_OBJECT(theme
), prop
, font
, NULL
);
86 pidgin_theme_font_free(font
);
88 pidgin_theme_font_set_color(font
, &color
);
91 pidgin_blist_set_theme(theme
);
94 gtk_widget_destroy(GTK_WIDGET(dialog
));
98 theme_font_face_selected(GtkWidget
*dialog
, gint response
, gpointer font
)
100 if (response
== GTK_RESPONSE_OK
|| response
== GTK_RESPONSE_APPLY
) {
101 const char *fontname
= gtk_font_selection_dialog_get_font_name(GTK_FONT_SELECTION_DIALOG(dialog
));
102 pidgin_theme_font_set_font_face(font
, fontname
);
103 pidgin_blist_refresh(purple_get_blist());
105 gtk_widget_destroy(dialog
);
109 theme_font_select_face(GtkWidget
*widget
, gpointer prop
)
112 PidginBlistTheme
*theme
;
113 PidginThemeFont
*font
= NULL
;
116 theme
= pidgin_blist_get_theme();
117 g_object_get(G_OBJECT(theme
), prop
, &font
, NULL
);
120 font
= pidgin_theme_font_new(NULL
, NULL
);
121 g_object_set(G_OBJECT(theme
), prop
, font
, NULL
);
122 pidgin_theme_font_free(font
);
123 g_object_get(G_OBJECT(theme
), prop
, &font
, NULL
);
126 face
= pidgin_theme_font_get_font_face(font
);
127 dialog
= gtk_font_selection_dialog_new(_("Select Font"));
129 gtk_font_selection_dialog_set_font_name(GTK_FONT_SELECTION_DIALOG(dialog
),
131 g_signal_connect(G_OBJECT(dialog
), "response", G_CALLBACK(theme_font_face_selected
),
133 gtk_widget_show_all(dialog
);
137 theme_color_select(GtkWidget
*widget
, gpointer prop
)
140 PidginBlistTheme
*theme
;
141 const GdkColor
*color
= NULL
;
143 theme
= pidgin_blist_get_theme();
145 if (prop_type_is_color(theme
, prop
)) {
146 g_object_get(G_OBJECT(theme
), prop
, &color
, NULL
);
148 PidginThemeFont
*pair
= NULL
;
149 g_object_get(G_OBJECT(theme
), prop
, &pair
, NULL
);
151 color
= pidgin_theme_font_get_color(pair
);
154 dialog
= gtk_color_selection_dialog_new(_("Select Color"));
155 #if GTK_CHECK_VERSION(2,14,0)
157 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(
158 gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(dialog
))),
162 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(GTK_COLOR_SELECTION_DIALOG(dialog
)->colorsel
),
165 g_signal_connect(G_OBJECT(dialog
), "response", G_CALLBACK(theme_color_selected
),
168 gtk_widget_show_all(dialog
);
172 pidgin_theme_create_color_selector(const char *text
, const char *blurb
, const char *prop
,
173 GtkSizeGroup
*sizegroup
)
176 GtkWidget
*hbox
, *label
;
178 hbox
= gtk_hbox_new(FALSE
, PIDGIN_HIG_CAT_SPACE
);
180 label
= gtk_label_new(_(text
));
181 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
182 gtk_size_group_add_widget(sizegroup
, label
);
183 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
184 #if GTK_CHECK_VERSION(2, 12, 0)
185 gtk_widget_set_tooltip_text(label
, blurb
);
188 color
= pidgin_pixbuf_button_from_stock("", GTK_STOCK_SELECT_COLOR
,
189 PIDGIN_BUTTON_HORIZONTAL
);
190 g_signal_connect(G_OBJECT(color
), "clicked", G_CALLBACK(theme_color_select
),
192 gtk_box_pack_start(GTK_BOX(hbox
), color
, FALSE
, FALSE
, 0);
198 pidgin_theme_create_font_selector(const char *text
, const char *blurb
, const char *prop
,
199 GtkSizeGroup
*sizegroup
)
201 GtkWidget
*color
, *font
;
202 GtkWidget
*hbox
, *label
;
204 hbox
= gtk_hbox_new(FALSE
, PIDGIN_HIG_CAT_SPACE
);
206 label
= gtk_label_new(_(text
));
207 gtk_misc_set_alignment(GTK_MISC(label
), 0, 0.5);
208 gtk_size_group_add_widget(sizegroup
, label
);
209 gtk_box_pack_start(GTK_BOX(hbox
), label
, FALSE
, FALSE
, 0);
210 #if GTK_CHECK_VERSION(2, 12, 0)
211 gtk_widget_set_tooltip_text(label
, blurb
);
214 font
= pidgin_pixbuf_button_from_stock("", GTK_STOCK_SELECT_FONT
,
215 PIDGIN_BUTTON_HORIZONTAL
);
216 g_signal_connect(G_OBJECT(font
), "clicked", G_CALLBACK(theme_font_select_face
),
218 gtk_box_pack_start(GTK_BOX(hbox
), font
, FALSE
, FALSE
, 0);
220 color
= pidgin_pixbuf_button_from_stock("", GTK_STOCK_SELECT_COLOR
,
221 PIDGIN_BUTTON_HORIZONTAL
);
222 g_signal_connect(G_OBJECT(color
), "clicked", G_CALLBACK(theme_color_select
),
224 gtk_box_pack_start(GTK_BOX(hbox
), color
, FALSE
, FALSE
, 0);
230 pidgin_blist_theme_edit(PurplePluginAction
*unused
)
235 PidginBlistTheme
*theme
;
240 const char *props
[12];
266 dialog
= pidgin_create_dialog(_("Pidgin Buddylist Theme Editor"), 0, "theme-editor-blist", FALSE
);
267 box
= pidgin_dialog_get_vbox_with_properties(GTK_DIALOG(dialog
), FALSE
, PIDGIN_HIG_BOX_SPACE
);
269 theme
= pidgin_blist_get_theme();
277 theme
= g_object_new(PIDGIN_TYPE_BLIST_THEME
, "type", "blist",
280 pidgin_blist_set_theme(theme
);
282 klass
= G_OBJECT_CLASS(PIDGIN_BLIST_THEME_GET_CLASS(theme
));
284 group
= gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL
);
285 for (i
= 0; sections
[i
].header
; i
++) {
290 vbox
= pidgin_make_frame(box
, _(sections
[i
].header
));
291 for (j
= 0; sections
[i
].props
[j
]; j
++) {
294 spec
= g_object_class_find_property(klass
, sections
[i
].props
[j
]);
295 label
= g_param_spec_get_nick(spec
);
296 blurb
= g_param_spec_get_blurb(spec
);
297 if (G_IS_PARAM_SPEC_BOXED(spec
)) {
298 hbox
= pidgin_theme_create_color_selector(label
, blurb
,
299 sections
[i
].props
[j
], group
);
300 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
302 hbox
= pidgin_theme_create_font_selector(label
, blurb
,
303 sections
[i
].props
[j
], group
);
304 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, FALSE
, 0);
309 gtk_dialog_set_has_separator(GTK_DIALOG(dialog
), TRUE
);
311 pidgin_dialog_add_button(GTK_DIALOG(dialog
), GTK_STOCK_SAVE
, G_CALLBACK(save_blist_theme
), dialog
);
313 pidgin_dialog_add_button(GTK_DIALOG(dialog
), GTK_STOCK_CLOSE
, G_CALLBACK(close_blist_theme
), dialog
);
315 gtk_widget_show_all(dialog
);
317 g_object_unref(group
);
321 plugin_load(PurplePlugin
*plugin
)
327 actions(PurplePlugin
*plugin
, gpointer context
)
330 PurplePluginAction
*act
= NULL
;
332 act
= purple_plugin_action_new(_("Edit Buddylist Theme"), pidgin_blist_theme_edit
);
333 l
= g_list_append(l
, act
);
334 act
= purple_plugin_action_new(_("Edit Icon Theme"), pidgin_icon_theme_edit
);
335 l
= g_list_append(l
, act
);
340 static PurplePluginInfo info
=
343 PURPLE_MAJOR_VERSION
,
344 PURPLE_MINOR_VERSION
,
345 PURPLE_PLUGIN_STANDARD
, /**< type */
346 PIDGIN_PLUGIN_TYPE
, /**< ui_requirement */
348 NULL
, /**< dependencies */
349 PURPLE_PRIORITY_DEFAULT
, /**< priority */
351 PLUGIN_ID
, /**< id */
352 N_("Pidgin Theme Editor"), /**< name */
353 DISPLAY_VERSION
, /**< version */
355 N_("Pidgin Theme Editor."),
357 N_("Pidgin Theme Editor"),
358 "Sadrul Habib Chowdhury <imadil@gmail.com>", /**< author */
359 PURPLE_WEBSITE
, /**< homepage */
361 plugin_load
, /**< load */
363 NULL
, /**< destroy */
365 NULL
, /**< ui_info */
366 NULL
, /**< extra_info */
378 init_plugin(PurplePlugin
*plugin
)
382 PURPLE_INIT_PLUGIN(themeeditor
, init_plugin
, info
)