| |
1 /** |
| |
2 * @file gtkpluginpref.c GTK+ Plugin preferences |
| |
3 * @ingroup gtkui |
| |
4 * |
| |
5 * pidgin |
| |
6 * |
| |
7 * Pidgin is the legal property of its developers, whose names are too numerous |
| |
8 * to list here. Please refer to the COPYRIGHT file distributed with this |
| |
9 * source distribution. |
| |
10 * |
| |
11 * This program is free software; you can redistribute it and/or modify |
| |
12 * it under the terms of the GNU General Public License as published by |
| |
13 * the Free Software Foundation; either version 2 of the License, or |
| |
14 * (at your option) any later version. |
| |
15 * |
| |
16 * This program is distributed in the hope that it will be useful, |
| |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| |
19 * GNU General Public License for more details. |
| |
20 * |
| |
21 * You should have received a copy of the GNU General Public License |
| |
22 * along with this program; if not, write to the Free Software |
| |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| |
24 */ |
| |
25 #ifdef HAVE_CONFIG_H |
| |
26 # include <config.h> |
| |
27 #endif |
| |
28 |
| |
29 #include "debug.h" |
| |
30 #include "internal.h" |
| |
31 #include "pluginpref.h" |
| |
32 #include "prefs.h" |
| |
33 |
| |
34 #include "gtkimhtml.h" |
| |
35 #include "gtkpluginpref.h" |
| |
36 #include "gtkprefs.h" |
| |
37 #include "gtkutils.h" |
| |
38 |
| |
39 static gboolean |
| |
40 entry_cb(GtkWidget *entry, gpointer data) { |
| |
41 char *pref = data; |
| |
42 |
| |
43 purple_prefs_set_string(pref, gtk_entry_get_text(GTK_ENTRY(entry))); |
| |
44 |
| |
45 return FALSE; |
| |
46 } |
| |
47 |
| |
48 |
| |
49 static void |
| |
50 imhtml_cb(GtkTextBuffer *buffer, gpointer data) |
| |
51 { |
| |
52 char *pref; |
| |
53 char *text; |
| |
54 GtkIMHtml *imhtml = data; |
| |
55 |
| |
56 pref = g_object_get_data(G_OBJECT(imhtml), "pref-key"); |
| |
57 g_return_if_fail(pref); |
| |
58 |
| |
59 text = gtk_imhtml_get_markup(imhtml); |
| |
60 purple_prefs_set_string(pref, text); |
| |
61 g_free(text); |
| |
62 } |
| |
63 |
| |
64 static void |
| |
65 imhtml_format_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, gpointer data) |
| |
66 { |
| |
67 imhtml_cb(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)), data); |
| |
68 } |
| |
69 |
| |
70 static void |
| |
71 make_string_pref(GtkWidget *parent, PurplePluginPref *pref, GtkSizeGroup *sg) { |
| |
72 GtkWidget *box, *gtk_label, *entry; |
| |
73 const gchar *pref_name; |
| |
74 const gchar *pref_label; |
| |
75 PurpleStringFormatType format; |
| |
76 |
| |
77 pref_name = purple_plugin_pref_get_name(pref); |
| |
78 pref_label = purple_plugin_pref_get_label(pref); |
| |
79 format = purple_plugin_pref_get_format_type(pref); |
| |
80 |
| |
81 switch(purple_plugin_pref_get_type(pref)) { |
| |
82 case PURPLE_PLUGIN_PREF_CHOICE: |
| |
83 gtk_label = pidgin_prefs_dropdown_from_list(parent, pref_label, |
| |
84 PURPLE_PREF_STRING, pref_name, |
| |
85 purple_plugin_pref_get_choices(pref)); |
| |
86 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
| |
87 |
| |
88 if(sg) |
| |
89 gtk_size_group_add_widget(sg, gtk_label); |
| |
90 |
| |
91 break; |
| |
92 case PURPLE_PLUGIN_PREF_NONE: |
| |
93 default: |
| |
94 if (format == PURPLE_STRING_FORMAT_TYPE_NONE) |
| |
95 box = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); |
| |
96 else |
| |
97 box = gtk_vbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); |
| |
98 |
| |
99 gtk_widget_show(box); |
| |
100 gtk_box_pack_start(GTK_BOX(parent), box, FALSE, FALSE, 0); |
| |
101 |
| |
102 gtk_label = gtk_label_new_with_mnemonic(pref_label); |
| |
103 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
| |
104 gtk_widget_show(gtk_label); |
| |
105 gtk_box_pack_start(GTK_BOX(box), gtk_label, FALSE, FALSE, 0); |
| |
106 |
| |
107 if(sg) |
| |
108 gtk_size_group_add_widget(sg, gtk_label); |
| |
109 |
| |
110 if (format == PURPLE_STRING_FORMAT_TYPE_NONE) |
| |
111 { |
| |
112 entry = gtk_entry_new(); |
| |
113 gtk_entry_set_text(GTK_ENTRY(entry), purple_prefs_get_string(pref_name)); |
| |
114 gtk_entry_set_max_length(GTK_ENTRY(entry), |
| |
115 purple_plugin_pref_get_max_length(pref)); |
| |
116 if (purple_plugin_pref_get_masked(pref)) |
| |
117 { |
| |
118 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); |
| |
119 if (gtk_entry_get_invisible_char(GTK_ENTRY(entry)) == '*') |
| |
120 gtk_entry_set_invisible_char(GTK_ENTRY(entry), PIDGIN_INVISIBLE_CHAR); |
| |
121 } |
| |
122 g_signal_connect(G_OBJECT(entry), "changed", |
| |
123 G_CALLBACK(entry_cb), |
| |
124 (gpointer)pref_name); |
| |
125 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry); |
| |
126 gtk_widget_show(entry); |
| |
127 gtk_box_pack_start(GTK_BOX(box), entry, FALSE, FALSE, 0); |
| |
128 } |
| |
129 else |
| |
130 { |
| |
131 GtkWidget *hbox; |
| |
132 GtkWidget *spacer; |
| |
133 GtkWidget *imhtml; |
| |
134 GtkWidget *toolbar; |
| |
135 GtkWidget *frame; |
| |
136 |
| |
137 hbox = gtk_hbox_new(FALSE, PIDGIN_HIG_BOX_SPACE); |
| |
138 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
| |
139 gtk_widget_show(hbox); |
| |
140 |
| |
141 spacer = gtk_label_new(" "); |
| |
142 gtk_box_pack_start(GTK_BOX(hbox), spacer, FALSE, FALSE, 0); |
| |
143 gtk_widget_show(spacer); |
| |
144 |
| |
145 frame = pidgin_create_imhtml(TRUE, &imhtml, &toolbar, NULL); |
| |
146 if (!(format & PURPLE_STRING_FORMAT_TYPE_HTML)) |
| |
147 gtk_widget_destroy(toolbar); |
| |
148 |
| |
149 gtk_imhtml_append_text(GTK_IMHTML(imhtml), purple_prefs_get_string(pref_name), |
| |
150 (format & PURPLE_STRING_FORMAT_TYPE_MULTILINE) ? 0 : GTK_IMHTML_NO_NEWLINE); |
| |
151 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), imhtml); |
| |
152 gtk_widget_show_all(frame); |
| |
153 g_object_set_data(G_OBJECT(imhtml), "pref-key", (gpointer)pref_name); |
| |
154 g_signal_connect(G_OBJECT(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml))), |
| |
155 "changed", G_CALLBACK(imhtml_cb), imhtml); |
| |
156 g_signal_connect(G_OBJECT(imhtml), |
| |
157 "format_function_toggle", G_CALLBACK(imhtml_format_cb), imhtml); |
| |
158 gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); |
| |
159 } |
| |
160 |
| |
161 break; |
| |
162 } |
| |
163 } |
| |
164 |
| |
165 static void |
| |
166 make_int_pref(GtkWidget *parent, PurplePluginPref *pref, GtkSizeGroup *sg) { |
| |
167 GtkWidget *gtk_label; |
| |
168 const gchar *pref_name; |
| |
169 const gchar *pref_label; |
| |
170 gint max, min; |
| |
171 |
| |
172 pref_name = purple_plugin_pref_get_name(pref); |
| |
173 pref_label = purple_plugin_pref_get_label(pref); |
| |
174 |
| |
175 switch(purple_plugin_pref_get_type(pref)) { |
| |
176 case PURPLE_PLUGIN_PREF_CHOICE: |
| |
177 gtk_label = pidgin_prefs_dropdown_from_list(parent, pref_label, |
| |
178 PURPLE_PREF_INT, pref_name, purple_plugin_pref_get_choices(pref)); |
| |
179 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
| |
180 |
| |
181 if(sg) |
| |
182 gtk_size_group_add_widget(sg, gtk_label); |
| |
183 |
| |
184 break; |
| |
185 case PURPLE_PLUGIN_PREF_NONE: |
| |
186 default: |
| |
187 purple_plugin_pref_get_bounds(pref, &min, &max); |
| |
188 pidgin_prefs_labeled_spin_button(parent, pref_label, |
| |
189 pref_name, min, max, sg); |
| |
190 break; |
| |
191 } |
| |
192 } |
| |
193 |
| |
194 |
| |
195 static void |
| |
196 make_info_pref(GtkWidget *parent, PurplePluginPref *pref) { |
| |
197 GtkWidget *gtk_label = gtk_label_new(purple_plugin_pref_get_label(pref)); |
| |
198 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0); |
| |
199 gtk_label_set_line_wrap(GTK_LABEL(gtk_label), TRUE); |
| |
200 gtk_box_pack_start(GTK_BOX(parent), gtk_label, FALSE, FALSE, 0); |
| |
201 gtk_widget_show(gtk_label); |
| |
202 } |
| |
203 |
| |
204 |
| |
205 GtkWidget * |
| |
206 pidgin_plugin_pref_create_frame(PurplePluginPrefFrame *frame) { |
| |
207 GtkWidget *ret, *parent; |
| |
208 GtkSizeGroup *sg; |
| |
209 GList *pp; |
| |
210 |
| |
211 g_return_val_if_fail(frame, NULL); |
| |
212 |
| |
213 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
| |
214 |
| |
215 parent = ret = gtk_vbox_new(FALSE, 16); |
| |
216 gtk_container_set_border_width(GTK_CONTAINER(ret), PIDGIN_HIG_BORDER); |
| |
217 gtk_widget_show(ret); |
| |
218 |
| |
219 for(pp = purple_plugin_pref_frame_get_prefs(frame); |
| |
220 pp != NULL; |
| |
221 pp = pp->next) |
| |
222 { |
| |
223 PurplePluginPref *pref = (PurplePluginPref *)pp->data; |
| |
224 |
| |
225 const char *name = purple_plugin_pref_get_name(pref); |
| |
226 const char *label = purple_plugin_pref_get_label(pref); |
| |
227 |
| |
228 if(name == NULL) { |
| |
229 if(label == NULL) |
| |
230 continue; |
| |
231 |
| |
232 if(purple_plugin_pref_get_type(pref) == PURPLE_PLUGIN_PREF_INFO) { |
| |
233 make_info_pref(parent, pref); |
| |
234 } else { |
| |
235 parent = pidgin_make_frame(ret, label); |
| |
236 gtk_widget_show(parent); |
| |
237 } |
| |
238 |
| |
239 continue; |
| |
240 } |
| |
241 |
| |
242 switch(purple_prefs_get_type(name)) { |
| |
243 case PURPLE_PREF_BOOLEAN: |
| |
244 pidgin_prefs_checkbox(label, name, parent); |
| |
245 break; |
| |
246 case PURPLE_PREF_INT: |
| |
247 make_int_pref(parent, pref, sg); |
| |
248 break; |
| |
249 case PURPLE_PREF_STRING: |
| |
250 make_string_pref(parent, pref, sg); |
| |
251 break; |
| |
252 default: |
| |
253 break; |
| |
254 } |
| |
255 } |
| |
256 |
| |
257 return ret; |
| |
258 } |