Simplify handling of GG xfer auth queue.
[pidgin-git.git] / pidgin / gtkpluginpref.c
blobb40524ba29111e23b6d080cb5d2386a4ee1dbd02
1 /* pidgin
3 * Pidgin is the legal property of its developers, whose names are too numerous
4 * to list here. Please refer to the COPYRIGHT file distributed with this
5 * source distribution.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
21 #include <talkatu.h>
23 #ifdef HAVE_CONFIG_H
24 # include <config.h>
25 #endif
27 #include "debug.h"
28 #include "internal.h"
29 #include "pidgin.h"
30 #include "pluginpref.h"
31 #include "prefs.h"
33 #include "gtk3compat.h"
34 #include "gtkpluginpref.h"
35 #include "gtkprefs.h"
36 #include "gtkutils.h"
38 static gboolean
39 entry_cb(GtkWidget *entry, gpointer data) {
40 char *pref = data;
42 purple_prefs_set_string(pref, gtk_entry_get_text(GTK_ENTRY(entry)));
44 return FALSE;
48 static void
49 multiline_cb(GtkTextBuffer *buffer, gpointer data) {
50 gchar *pref = NULL, *text = NULL;
52 pref = g_object_get_data(G_OBJECT(buffer), "pref-key");
53 g_return_if_fail(pref);
55 text = talkatu_markup_get_html(buffer, NULL);
56 purple_prefs_set_string(pref, text);
57 g_free(text);
60 static void
61 make_string_pref(GtkWidget *parent, PurplePluginPref *pref, GtkSizeGroup *sg) {
62 GtkWidget *box, *gtk_label, *entry;
63 const gchar *pref_name;
64 const gchar *pref_label;
65 PurpleStringFormatType format;
67 pref_name = purple_plugin_pref_get_name(pref);
68 pref_label = purple_plugin_pref_get_label(pref);
69 format = purple_plugin_pref_get_format_type(pref);
71 switch(purple_plugin_pref_get_pref_type(pref)) {
72 case PURPLE_PLUGIN_PREF_CHOICE:
73 gtk_label = pidgin_prefs_dropdown_from_list(parent, pref_label,
74 PURPLE_PREF_STRING, pref_name,
75 purple_plugin_pref_get_choices(pref));
76 gtk_label_set_xalign(GTK_LABEL(gtk_label), 0);
78 if(sg)
79 gtk_size_group_add_widget(sg, gtk_label);
81 break;
82 case PURPLE_PLUGIN_PREF_NONE:
83 default:
84 if (format == PURPLE_STRING_FORMAT_TYPE_NONE)
86 entry = gtk_entry_new();
87 gtk_entry_set_text(GTK_ENTRY(entry), purple_prefs_get_string(pref_name));
88 gtk_entry_set_max_length(GTK_ENTRY(entry),
89 purple_plugin_pref_get_max_length(pref));
90 if (purple_plugin_pref_get_masked(pref))
92 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
94 g_signal_connect(G_OBJECT(entry), "changed",
95 G_CALLBACK(entry_cb),
96 (gpointer)pref_name);
97 pidgin_add_widget_to_vbox(GTK_BOX(parent), pref_label, sg, entry, TRUE, NULL);
99 else
101 GtkWidget *hbox;
102 GtkWidget *spacer;
103 GtkWidget *editor;
104 GtkWidget *view;
105 GtkTextBuffer *buffer;
107 box = gtk_box_new(GTK_ORIENTATION_VERTICAL, PIDGIN_HIG_BOX_SPACE);
109 gtk_widget_show(box);
110 gtk_box_pack_start(GTK_BOX(parent), box, FALSE, FALSE, 0);
112 gtk_label = gtk_label_new_with_mnemonic(pref_label);
113 gtk_label_set_xalign(GTK_LABEL(gtk_label), 0);
114 gtk_widget_show(gtk_label);
115 gtk_box_pack_start(GTK_BOX(box), gtk_label, FALSE, FALSE, 0);
117 if(sg)
118 gtk_size_group_add_widget(sg, gtk_label);
120 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, PIDGIN_HIG_BOX_SPACE);
121 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
122 gtk_widget_show(hbox);
124 spacer = gtk_label_new(" ");
125 gtk_box_pack_start(GTK_BOX(hbox), spacer, FALSE, FALSE, 0);
126 gtk_widget_show(spacer);
128 editor = talkatu_editor_new();
129 view = talkatu_editor_get_view(TALKATU_EDITOR(editor));
131 if ((format & PURPLE_STRING_FORMAT_TYPE_HTML) != 0) {
132 buffer = talkatu_html_buffer_new();
133 } else {
134 buffer = talkatu_buffer_new(NULL);
137 gtk_text_view_set_buffer(GTK_TEXT_VIEW(view), buffer);
139 if (format & PURPLE_STRING_FORMAT_TYPE_MULTILINE) {
140 gchar *tmp = purple_strreplace(purple_prefs_get_string(pref_name), "\n", "<br>");
141 talkatu_markup_set_html(TALKATU_BUFFER(buffer), tmp, -1);
142 g_free(tmp);
143 } else {
144 talkatu_markup_set_html(TALKATU_BUFFER(buffer), purple_prefs_get_string(pref_name), -1);
147 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), view);
148 gtk_widget_show_all(editor);
149 g_object_set_data(G_OBJECT(buffer), "pref-key", (gpointer)pref_name);
150 g_signal_connect(G_OBJECT(buffer), "changed",
151 G_CALLBACK(multiline_cb), NULL);
152 #warning fix this when talkatu has a solution
154 g_signal_connect(G_OBJECT(view), "format-toggled",
155 G_CALLBACK(multiline_cb), NULL);
157 gtk_box_pack_start(GTK_BOX(hbox), editor, TRUE, TRUE, 0);
160 break;
164 static void
165 make_int_pref(GtkWidget *parent, PurplePluginPref *pref, GtkSizeGroup *sg) {
166 GtkWidget *gtk_label;
167 const gchar *pref_name;
168 const gchar *pref_label;
169 gint max, min;
171 pref_name = purple_plugin_pref_get_name(pref);
172 pref_label = purple_plugin_pref_get_label(pref);
174 switch(purple_plugin_pref_get_pref_type(pref)) {
175 case PURPLE_PLUGIN_PREF_CHOICE:
176 gtk_label = pidgin_prefs_dropdown_from_list(parent, pref_label,
177 PURPLE_PREF_INT, pref_name, purple_plugin_pref_get_choices(pref));
178 gtk_label_set_xalign(GTK_LABEL(gtk_label), 0);
180 if(sg)
181 gtk_size_group_add_widget(sg, gtk_label);
183 break;
184 case PURPLE_PLUGIN_PREF_NONE:
185 default:
186 purple_plugin_pref_get_bounds(pref, &min, &max);
187 pidgin_prefs_labeled_spin_button(parent, pref_label,
188 pref_name, min, max, sg);
189 break;
194 static void
195 make_info_pref(GtkWidget *parent, PurplePluginPref *pref) {
196 GtkWidget *gtk_label = gtk_label_new(purple_plugin_pref_get_label(pref));
197 gtk_label_set_xalign(GTK_LABEL(gtk_label), 0);
198 gtk_label_set_yalign(GTK_LABEL(gtk_label), 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);
205 GtkWidget *
206 pidgin_plugin_pref_create_frame(PurplePluginPrefFrame *frame) {
207 GtkWidget *ret, *parent;
208 GtkSizeGroup *sg;
209 GList *pp;
211 g_return_val_if_fail(frame, NULL);
213 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
215 parent = ret = gtk_box_new(GTK_ORIENTATION_VERTICAL, 16);
216 gtk_widget_show(ret);
218 for(pp = purple_plugin_pref_frame_get_prefs(frame);
219 pp != NULL;
220 pp = pp->next)
222 PurplePluginPref *pref = (PurplePluginPref *)pp->data;
224 const char *name = purple_plugin_pref_get_name(pref);
225 const char *label = purple_plugin_pref_get_label(pref);
227 if(name == NULL) {
228 if(label == NULL)
229 continue;
231 if(purple_plugin_pref_get_pref_type(pref) == PURPLE_PLUGIN_PREF_INFO) {
232 make_info_pref(parent, pref);
233 } else {
234 parent = pidgin_make_frame(ret, label);
235 gtk_widget_show(parent);
238 continue;
241 switch(purple_prefs_get_pref_type(name)) {
242 case PURPLE_PREF_BOOLEAN:
243 pidgin_prefs_checkbox(label, name, parent);
244 break;
245 case PURPLE_PREF_INT:
246 make_int_pref(parent, pref, sg);
247 break;
248 case PURPLE_PREF_STRING:
249 make_string_pref(parent, pref, sg);
250 break;
251 default:
252 break;
256 g_object_unref(sg);
258 return ret;