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:
|
|
68 hbox = gtk_hbox_new(FALSE, 6);
|
|
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));
|
9841
|
84 gtk_entry_set_visibility(GTK_ENTRY(entry),
|
|
85 !gaim_plugin_pref_get_masked(pref));
|
8713
|
86 g_signal_connect(G_OBJECT(entry), "changed",
|
|
87 G_CALLBACK(entry_cb),
|
|
88 (gpointer)pref_name);
|
|
89 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry);
|
|
90 gtk_widget_show(entry);
|
|
91 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
92
|
|
93 break;
|
|
94 }
|
|
95 }
|
|
96
|
|
97 static void
|
|
98 make_int_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) {
|
|
99 GtkWidget *gtk_label;
|
|
100 gchar *pref_name, *pref_label;
|
|
101 gint max, min;
|
|
102
|
|
103 pref_name = gaim_plugin_pref_get_name(pref);
|
|
104 pref_label = gaim_plugin_pref_get_label(pref);
|
|
105
|
|
106 switch(gaim_plugin_pref_get_type(pref)) {
|
|
107 case GAIM_PLUGIN_PREF_CHOICE:
|
|
108 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label,
|
9529
|
109 GAIM_PREF_INT, pref_name, gaim_plugin_pref_get_choices(pref));
|
8713
|
110 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5);
|
|
111
|
|
112 if(sg)
|
|
113 gtk_size_group_add_widget(sg, gtk_label);
|
|
114
|
|
115 break;
|
|
116 case GAIM_PLUGIN_PREF_NONE:
|
|
117 default:
|
|
118 gaim_plugin_pref_get_bounds(pref, &min, &max);
|
10414
|
119 gaim_gtk_prefs_labeled_spin_button(parent, pref_label,
|
9529
|
120 pref_name, min, max, sg);
|
8713
|
121 break;
|
|
122 }
|
|
123 }
|
|
124
|
9529
|
125
|
|
126 static void
|
|
127 make_info_pref(GtkWidget *parent, GaimPluginPref *pref) {
|
|
128 GtkWidget *gtk_label = gtk_label_new(gaim_plugin_pref_get_label(pref));
|
|
129 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0);
|
|
130 gtk_label_set_line_wrap(GTK_LABEL(gtk_label), TRUE);
|
|
131 gtk_box_pack_start(GTK_BOX(parent), gtk_label, FALSE, FALSE, 0);
|
|
132 gtk_widget_show(gtk_label);
|
|
133 }
|
|
134
|
|
135
|
8713
|
136 GtkWidget *
|
|
137 gaim_gtk_plugin_pref_create_frame(GaimPluginPrefFrame *frame) {
|
|
138 GaimPluginPref *pref;
|
|
139 GtkWidget *ret, *parent;
|
|
140 GtkSizeGroup *sg;
|
|
141 GList *pp;
|
|
142 gchar *name, *label;
|
|
143
|
|
144 g_return_val_if_fail(frame, NULL);
|
|
145
|
|
146 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
147
|
|
148 parent = ret = gtk_vbox_new(FALSE, 16);
|
|
149 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
|
|
150 gtk_widget_show(ret);
|
|
151
|
|
152 for(pp = gaim_plugin_pref_frame_get_prefs(frame);
|
|
153 pp != NULL;
|
|
154 pp = pp->next)
|
|
155 {
|
|
156 pref = (GaimPluginPref *)pp->data;
|
|
157
|
|
158 name = gaim_plugin_pref_get_name(pref);
|
|
159 label = gaim_plugin_pref_get_label(pref);
|
|
160
|
|
161 if(name == NULL) {
|
|
162 if(label == NULL)
|
|
163 continue;
|
9529
|
164
|
|
165 if(gaim_plugin_pref_get_type(pref) == GAIM_PLUGIN_PREF_INFO) {
|
|
166 make_info_pref(parent, pref);
|
|
167 } else {
|
|
168 parent = gaim_gtk_make_frame(ret, label);
|
|
169 gtk_widget_show(parent);
|
|
170 }
|
8713
|
171
|
|
172 continue;
|
|
173 }
|
|
174
|
|
175 switch(gaim_prefs_get_type(name)) {
|
|
176 case GAIM_PREF_BOOLEAN:
|
|
177 gaim_gtk_prefs_checkbox(label, name, parent);
|
|
178 break;
|
|
179 case GAIM_PREF_INT:
|
|
180 make_int_pref(parent, pref, sg);
|
|
181 break;
|
|
182 case GAIM_PREF_STRING:
|
|
183 make_string_pref(parent, pref, sg);
|
|
184 break;
|
|
185 default:
|
|
186 break;
|
|
187 }
|
|
188 }
|
|
189
|
|
190 return ret;
|
|
191 }
|