Mercurial > pidgin
annotate src/gtkpluginpref.c @ 12806:ebef62bc831a
[gaim-migrate @ 15153]
Sadrul fixed the docklet-wouldn't-stop-blinking bug I was hitting after his last patch. Thanks, Sadrul.
committer: Tailor Script <tailor@pidgin.im>
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Tue, 10 Jan 2006 05:41:20 +0000 |
parents | 4e3dde2b2641 |
children | a0a4b44239e8 |
rev | line source |
---|---|
8713 | 1 /** |
10297 | 2 * @file gtkpluginpref.c GTK+ Plugin preferences |
3 * @ingroup gtkui | |
4 * | |
8713 | 5 * gaim |
6 * | |
7 * Gaim 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 | |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
34 #include "gtkimhtml.h" |
8713 | 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 gaim_prefs_set_string(pref, gtk_entry_get_text(GTK_ENTRY(entry))); | |
44 | |
45 return FALSE; | |
46 } | |
47 | |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
48 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
49 static void |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
50 imhtml_cb(GtkTextBuffer *buffer, gpointer data) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
51 { |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
52 char *pref; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
53 char *text; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
54 GtkIMHtml *imhtml = data; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
55 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
56 pref = g_object_get_data(G_OBJECT(imhtml), "pref-key"); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
57 g_return_if_fail(pref); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
58 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
59 text = gtk_imhtml_get_markup(imhtml); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
60 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
61 if (!text) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
62 text = ""; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
63 gaim_prefs_set_string(pref, text); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
64 g_free(text); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
65 } |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
66 |
8713 | 67 static void |
12794
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
68 imhtml_format_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, gpointer data) |
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
69 { |
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
70 imhtml_cb(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)), data); |
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
71 } |
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
72 |
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
73 static void |
8713 | 74 make_string_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) { |
75 GtkWidget *hbox, *gtk_label, *entry; | |
76 gchar *pref_name, *pref_label; | |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
77 GaimStringFormatType format; |
8713 | 78 |
79 pref_name = gaim_plugin_pref_get_name(pref); | |
80 pref_label = gaim_plugin_pref_get_label(pref); | |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
81 format = gaim_plugin_pref_get_format_type(pref); |
8713 | 82 |
83 switch(gaim_plugin_pref_get_type(pref)) { | |
84 case GAIM_PLUGIN_PREF_CHOICE: | |
85 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label, | |
86 GAIM_PREF_STRING, pref_name, | |
10414 | 87 gaim_plugin_pref_get_choices(pref)); |
8713 | 88 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
89 | |
90 if(sg) | |
91 gtk_size_group_add_widget(sg, gtk_label); | |
92 | |
93 break; | |
94 case GAIM_PLUGIN_PREF_NONE: | |
95 default: | |
11243 | 96 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
8713 | 97 gtk_widget_show(hbox); |
98 gtk_box_pack_start(GTK_BOX(parent), hbox, FALSE, FALSE, 0); | |
99 | |
100 gtk_label = gtk_label_new_with_mnemonic(pref_label); | |
101 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); | |
102 gtk_widget_show(gtk_label); | |
103 gtk_box_pack_start(GTK_BOX(hbox), gtk_label, FALSE, FALSE, 0); | |
104 | |
105 if(sg) | |
106 gtk_size_group_add_widget(sg, gtk_label); | |
107 | |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
108 if (format == GAIM_STRING_FORMAT_TYPE_NONE) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
109 { |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
110 entry = gtk_entry_new(); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
111 gtk_entry_set_text(GTK_ENTRY(entry), gaim_prefs_get_string(pref_name)); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
112 gtk_entry_set_max_length(GTK_ENTRY(entry), |
8713 | 113 gaim_plugin_pref_get_max_length(pref)); |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
114 if (gaim_plugin_pref_get_masked(pref)) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
115 { |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
116 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
117 gtk_entry_set_invisible_char(GTK_ENTRY(entry), GAIM_INVISIBLE_CHAR); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
118 } |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
119 g_signal_connect(G_OBJECT(entry), "changed", |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
120 G_CALLBACK(entry_cb), |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
121 (gpointer)pref_name); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
122 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
123 gtk_widget_show(entry); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
124 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
125 } |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
126 else |
11986 | 127 { |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
128 GtkWidget *imhtml, *toolbar, *frame; |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
129 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
130 frame = gaim_gtk_create_imhtml(TRUE, &imhtml, &toolbar); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
131 if (!(format & GAIM_STRING_FORMAT_TYPE_HTML)) |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
132 gtk_widget_destroy(toolbar); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
133 |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
134 gtk_imhtml_append_text(GTK_IMHTML(imhtml), gaim_prefs_get_string(pref_name), |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
135 (format & GAIM_STRING_FORMAT_TYPE_MULTILINE) ? 0 : GTK_IMHTML_NO_NEWLINE); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
136 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), imhtml); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
137 gtk_widget_show_all(frame); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
138 g_object_set_data(G_OBJECT(imhtml), "pref-key", pref_name); |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
139 g_signal_connect(G_OBJECT(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml))), |
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
140 "changed", G_CALLBACK(imhtml_cb), imhtml); |
12794
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
141 g_signal_connect(G_OBJECT(imhtml), |
4e3dde2b2641
[gaim-migrate @ 15141]
Richard Laager <rlaager@wiktel.com>
parents:
12712
diff
changeset
|
142 "format_function_toggle", G_CALLBACK(imhtml_format_cb), imhtml); |
12712
8ae981f2c9cb
[gaim-migrate @ 15056]
Richard Laager <rlaager@wiktel.com>
parents:
11986
diff
changeset
|
143 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0); |
11986 | 144 } |
8713 | 145 |
146 break; | |
147 } | |
148 } | |
149 | |
150 static void | |
151 make_int_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) { | |
152 GtkWidget *gtk_label; | |
153 gchar *pref_name, *pref_label; | |
154 gint max, min; | |
155 | |
156 pref_name = gaim_plugin_pref_get_name(pref); | |
157 pref_label = gaim_plugin_pref_get_label(pref); | |
158 | |
159 switch(gaim_plugin_pref_get_type(pref)) { | |
160 case GAIM_PLUGIN_PREF_CHOICE: | |
161 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label, | |
9529 | 162 GAIM_PREF_INT, pref_name, gaim_plugin_pref_get_choices(pref)); |
8713 | 163 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
164 | |
165 if(sg) | |
166 gtk_size_group_add_widget(sg, gtk_label); | |
167 | |
168 break; | |
169 case GAIM_PLUGIN_PREF_NONE: | |
170 default: | |
171 gaim_plugin_pref_get_bounds(pref, &min, &max); | |
10414 | 172 gaim_gtk_prefs_labeled_spin_button(parent, pref_label, |
9529 | 173 pref_name, min, max, sg); |
8713 | 174 break; |
175 } | |
176 } | |
177 | |
9529 | 178 |
179 static void | |
180 make_info_pref(GtkWidget *parent, GaimPluginPref *pref) { | |
181 GtkWidget *gtk_label = gtk_label_new(gaim_plugin_pref_get_label(pref)); | |
182 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0); | |
183 gtk_label_set_line_wrap(GTK_LABEL(gtk_label), TRUE); | |
184 gtk_box_pack_start(GTK_BOX(parent), gtk_label, FALSE, FALSE, 0); | |
185 gtk_widget_show(gtk_label); | |
186 } | |
187 | |
188 | |
8713 | 189 GtkWidget * |
190 gaim_gtk_plugin_pref_create_frame(GaimPluginPrefFrame *frame) { | |
191 GaimPluginPref *pref; | |
192 GtkWidget *ret, *parent; | |
193 GtkSizeGroup *sg; | |
194 GList *pp; | |
195 gchar *name, *label; | |
196 | |
197 g_return_val_if_fail(frame, NULL); | |
198 | |
199 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); | |
200 | |
201 parent = ret = gtk_vbox_new(FALSE, 16); | |
11243 | 202 gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER); |
8713 | 203 gtk_widget_show(ret); |
204 | |
205 for(pp = gaim_plugin_pref_frame_get_prefs(frame); | |
206 pp != NULL; | |
207 pp = pp->next) | |
208 { | |
209 pref = (GaimPluginPref *)pp->data; | |
210 | |
211 name = gaim_plugin_pref_get_name(pref); | |
212 label = gaim_plugin_pref_get_label(pref); | |
213 | |
214 if(name == NULL) { | |
215 if(label == NULL) | |
216 continue; | |
9529 | 217 |
218 if(gaim_plugin_pref_get_type(pref) == GAIM_PLUGIN_PREF_INFO) { | |
219 make_info_pref(parent, pref); | |
220 } else { | |
221 parent = gaim_gtk_make_frame(ret, label); | |
222 gtk_widget_show(parent); | |
223 } | |
8713 | 224 |
225 continue; | |
226 } | |
227 | |
228 switch(gaim_prefs_get_type(name)) { | |
229 case GAIM_PREF_BOOLEAN: | |
230 gaim_gtk_prefs_checkbox(label, name, parent); | |
231 break; | |
232 case GAIM_PREF_INT: | |
233 make_int_pref(parent, pref, sg); | |
234 break; | |
235 case GAIM_PREF_STRING: | |
236 make_string_pref(parent, pref, sg); | |
237 break; | |
238 default: | |
239 break; | |
240 } | |
241 } | |
242 | |
243 return ret; | |
244 } |