8713
|
1 /**
|
|
2 * gaim
|
|
3 *
|
|
4 * Gaim is the legal property of its developers, whose names are too numerous
|
|
5 * to list here. Please refer to the COPYRIGHT file distributed with this
|
|
6 * source distribution.
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22 #ifdef HAVE_CONFIG_H
|
|
23 # include <config.h>
|
|
24 #endif
|
|
25
|
|
26 #include <glib.h>
|
|
27 #include <gtk/gtk.h>
|
|
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,
|
|
59 gaim_plugin_pref_get_choices(pref));
|
|
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));
|
|
84 g_signal_connect(G_OBJECT(entry), "changed",
|
|
85 G_CALLBACK(entry_cb),
|
|
86 (gpointer)pref_name);
|
|
87 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry);
|
|
88 gtk_widget_show(entry);
|
|
89 gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
90
|
|
91 break;
|
|
92 }
|
|
93 }
|
|
94
|
|
95 static void
|
|
96 make_int_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) {
|
|
97 GtkWidget *gtk_label;
|
|
98 gchar *pref_name, *pref_label;
|
|
99 gint max, min;
|
|
100
|
|
101 pref_name = gaim_plugin_pref_get_name(pref);
|
|
102 pref_label = gaim_plugin_pref_get_label(pref);
|
|
103
|
|
104 switch(gaim_plugin_pref_get_type(pref)) {
|
|
105 case GAIM_PLUGIN_PREF_CHOICE:
|
|
106 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label,
|
9529
|
107 GAIM_PREF_INT, pref_name, gaim_plugin_pref_get_choices(pref));
|
8713
|
108 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5);
|
|
109
|
|
110 if(sg)
|
|
111 gtk_size_group_add_widget(sg, gtk_label);
|
|
112
|
|
113 break;
|
|
114 case GAIM_PLUGIN_PREF_NONE:
|
|
115 default:
|
|
116 gaim_plugin_pref_get_bounds(pref, &min, &max);
|
|
117 gaim_gtk_prefs_labeled_spin_button(parent, pref_label,
|
9529
|
118 pref_name, min, max, sg);
|
8713
|
119 break;
|
|
120 }
|
|
121 }
|
|
122
|
9529
|
123
|
|
124 static void
|
|
125 make_info_pref(GtkWidget *parent, GaimPluginPref *pref) {
|
|
126 GtkWidget *gtk_label = gtk_label_new(gaim_plugin_pref_get_label(pref));
|
|
127 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0);
|
|
128 gtk_label_set_line_wrap(GTK_LABEL(gtk_label), TRUE);
|
|
129 gtk_box_pack_start(GTK_BOX(parent), gtk_label, FALSE, FALSE, 0);
|
|
130 gtk_widget_show(gtk_label);
|
|
131 }
|
|
132
|
|
133
|
8713
|
134 GtkWidget *
|
|
135 gaim_gtk_plugin_pref_create_frame(GaimPluginPrefFrame *frame) {
|
|
136 GaimPluginPref *pref;
|
|
137 GtkWidget *ret, *parent;
|
|
138 GtkSizeGroup *sg;
|
|
139 GList *pp;
|
|
140 gchar *name, *label;
|
|
141
|
|
142 g_return_val_if_fail(frame, NULL);
|
|
143
|
|
144 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
|
|
145
|
|
146 parent = ret = gtk_vbox_new(FALSE, 16);
|
|
147 gtk_container_set_border_width(GTK_CONTAINER(ret), 12);
|
|
148 gtk_widget_show(ret);
|
|
149
|
|
150 for(pp = gaim_plugin_pref_frame_get_prefs(frame);
|
|
151 pp != NULL;
|
|
152 pp = pp->next)
|
|
153 {
|
|
154 pref = (GaimPluginPref *)pp->data;
|
|
155
|
|
156 name = gaim_plugin_pref_get_name(pref);
|
|
157 label = gaim_plugin_pref_get_label(pref);
|
|
158
|
|
159 if(name == NULL) {
|
|
160 if(label == NULL)
|
|
161 continue;
|
9529
|
162
|
|
163 if(gaim_plugin_pref_get_type(pref) == GAIM_PLUGIN_PREF_INFO) {
|
|
164 make_info_pref(parent, pref);
|
|
165 } else {
|
|
166 parent = gaim_gtk_make_frame(ret, label);
|
|
167 gtk_widget_show(parent);
|
|
168 }
|
8713
|
169
|
|
170 continue;
|
|
171 }
|
|
172
|
|
173 switch(gaim_prefs_get_type(name)) {
|
|
174 case GAIM_PREF_BOOLEAN:
|
|
175 gaim_gtk_prefs_checkbox(label, name, parent);
|
|
176 break;
|
|
177 case GAIM_PREF_INT:
|
|
178 make_int_pref(parent, pref, sg);
|
|
179 break;
|
|
180 case GAIM_PREF_STRING:
|
|
181 make_string_pref(parent, pref, sg);
|
|
182 break;
|
|
183 default:
|
|
184 break;
|
|
185 }
|
|
186 }
|
|
187
|
|
188 return ret;
|
|
189 }
|