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
|
|
34 #include "gtkpluginpref.h"
|
|
35 #include "gtkprefs.h"
|
|
36 #include "gtkutils.h"
|
|
37
|
|
38 static gboolean
|
|
39 entry_cb(GtkWidget *entry, gpointer data) {
|
|
40 char *pref = data;
|
|
41
|
|
42 gaim_prefs_set_string(pref, gtk_entry_get_text(GTK_ENTRY(entry)));
|
|
43
|
|
44 return FALSE;
|
|
45 }
|
|
46
|
|
47 static void
|
|
48 make_string_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) {
|
|
49 GtkWidget *hbox, *gtk_label, *entry;
|
|
50 gchar *pref_name, *pref_label;
|
|
51
|
|
52 pref_name = gaim_plugin_pref_get_name(pref);
|
|
53 pref_label = gaim_plugin_pref_get_label(pref);
|
|
54
|
|
55 switch(gaim_plugin_pref_get_type(pref)) {
|
|
56 case GAIM_PLUGIN_PREF_CHOICE:
|
|
57 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label,
|
|
58 GAIM_PREF_STRING, pref_name,
|
10414
|
59 gaim_plugin_pref_get_choices(pref));
|
8713
|
60 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5);
|
|
61
|
|
62 if(sg)
|
|
63 gtk_size_group_add_widget(sg, gtk_label);
|
|
64
|
|
65 break;
|
|
66 case GAIM_PLUGIN_PREF_NONE:
|
|
67 default:
|
11243
|
68 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE);
|
8713
|
69 gtk_widget_show(hbox);
|
|
70 gtk_box_pack_start(GTK_BOX(parent), hbox, FALSE, FALSE, 0);
|
|
71
|
|
72 gtk_label = gtk_label_new_with_mnemonic(pref_label);
|
|
73 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5);
|
|
74 gtk_widget_show(gtk_label);
|
|
75 gtk_box_pack_start(GTK_BOX(hbox), gtk_label, FALSE, FALSE, 0);
|
|
76
|
|
77 if(sg)
|
|
78 gtk_size_group_add_widget(sg, gtk_label);
|
|
79
|
|
80 entry = gtk_entry_new();
|
|
81 gtk_entry_set_text(GTK_ENTRY(entry), gaim_prefs_get_string(pref_name));
|
|
82 gtk_entry_set_max_length(GTK_ENTRY(entry),
|
|
83 gaim_plugin_pref_get_max_length(pref));
|
11986
|
84 if (gaim_plugin_pref_get_masked(pref))
|
|
85 {
|
|
86 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
|
|
87 gtk_entry_set_invisible_char(GTK_ENTRY(entry), GAIM_INVISIBLE_CHAR);
|
|
88 }
|
8713
|
89 g_signal_connect(G_OBJECT(entry), "changed",
|
|
90 G_CALLBACK(entry_cb),
|
|
91 (gpointer)pref_name);
|
|
92 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry);
|
|
93 gtk_widget_show(entry);
|
|
94 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
95
|
|
96 break;
|
|
97 }
|
|
98 }
|
|
99
|
|
100 static void
|
|
101 make_int_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) {
|
|
102 GtkWidget *gtk_label;
|
|
103 gchar *pref_name, *pref_label;
|
|
104 gint max, min;
|
|
105
|
|
106 pref_name = gaim_plugin_pref_get_name(pref);
|
|
107 pref_label = gaim_plugin_pref_get_label(pref);
|
|
108
|
|
109 switch(gaim_plugin_pref_get_type(pref)) {
|
|
110 case GAIM_PLUGIN_PREF_CHOICE:
|
|
111 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label,
|
9529
|
112 GAIM_PREF_INT, pref_name, gaim_plugin_pref_get_choices(pref));
|
8713
|
113 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5);
|
|
114
|
|
115 if(sg)
|
|
116 gtk_size_group_add_widget(sg, gtk_label);
|
|
117
|
|
118 break;
|
|
119 case GAIM_PLUGIN_PREF_NONE:
|
|
120 default:
|
|
121 gaim_plugin_pref_get_bounds(pref, &min, &max);
|
10414
|
122 gaim_gtk_prefs_labeled_spin_button(parent, pref_label,
|
9529
|
123 pref_name, min, max, sg);
|
8713
|
124 break;
|
|
125 }
|
|
126 }
|
|
127
|
9529
|
128
|
|
129 static void
|
|
130 make_info_pref(GtkWidget *parent, GaimPluginPref *pref) {
|
|
131 GtkWidget *gtk_label = gtk_label_new(gaim_plugin_pref_get_label(pref));
|
|
132 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0);
|
|
133 gtk_label_set_line_wrap(GTK_LABEL(gtk_label), TRUE);
|
|
134 gtk_box_pack_start(GTK_BOX(parent), gtk_label, FALSE, FALSE, 0);
|
|
135 gtk_widget_show(gtk_label);
|
|
136 }
|
|
137
|
|
138
|
8713
|
139 GtkWidget *
|
|
140 gaim_gtk_plugin_pref_create_frame(GaimPluginPrefFrame *frame) {
|
|
141 GaimPluginPref *pref;
|
|
142 GtkWidget *ret, *parent;
|
|
143 GtkSizeGroup *sg;
|
|
144 GList *pp;
|
|
145 gchar *name, *label;
|
|
146
|
|
147 g_return_val_if_fail(frame, NULL);
|
|
148
|
|
149 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
150
|
|
151 parent = ret = gtk_vbox_new(FALSE, 16);
|
11243
|
152 gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER);
|
8713
|
153 gtk_widget_show(ret);
|
|
154
|
|
155 for(pp = gaim_plugin_pref_frame_get_prefs(frame);
|
|
156 pp != NULL;
|
|
157 pp = pp->next)
|
|
158 {
|
|
159 pref = (GaimPluginPref *)pp->data;
|
|
160
|
|
161 name = gaim_plugin_pref_get_name(pref);
|
|
162 label = gaim_plugin_pref_get_label(pref);
|
|
163
|
|
164 if(name == NULL) {
|
|
165 if(label == NULL)
|
|
166 continue;
|
9529
|
167
|
|
168 if(gaim_plugin_pref_get_type(pref) == GAIM_PLUGIN_PREF_INFO) {
|
|
169 make_info_pref(parent, pref);
|
|
170 } else {
|
|
171 parent = gaim_gtk_make_frame(ret, label);
|
|
172 gtk_widget_show(parent);
|
|
173 }
|
8713
|
174
|
|
175 continue;
|
|
176 }
|
|
177
|
|
178 switch(gaim_prefs_get_type(name)) {
|
|
179 case GAIM_PREF_BOOLEAN:
|
|
180 gaim_gtk_prefs_checkbox(label, name, parent);
|
|
181 break;
|
|
182 case GAIM_PREF_INT:
|
|
183 make_int_pref(parent, pref, sg);
|
|
184 break;
|
|
185 case GAIM_PREF_STRING:
|
|
186 make_string_pref(parent, pref, sg);
|
|
187 break;
|
|
188 default:
|
|
189 break;
|
|
190 }
|
|
191 }
|
|
192
|
|
193 return ret;
|
|
194 }
|