| 1 /** |
|
| 2 * @file gtkpluginpref.c GTK+ Plugin preferences |
|
| 3 * @ingroup gtkui |
|
| 4 * |
|
| 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 "gtkimhtml.h" |
|
| 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 |
|
| 48 |
|
| 49 static void |
|
| 50 imhtml_cb(GtkTextBuffer *buffer, gpointer data) |
|
| 51 { |
|
| 52 char *pref; |
|
| 53 char *text; |
|
| 54 GtkIMHtml *imhtml = data; |
|
| 55 |
|
| 56 pref = g_object_get_data(G_OBJECT(imhtml), "pref-key"); |
|
| 57 g_return_if_fail(pref); |
|
| 58 |
|
| 59 text = gtk_imhtml_get_markup(imhtml); |
|
| 60 |
|
| 61 if (!text) |
|
| 62 text = ""; |
|
| 63 gaim_prefs_set_string(pref, text); |
|
| 64 g_free(text); |
|
| 65 } |
|
| 66 |
|
| 67 static void |
|
| 68 imhtml_format_cb(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons, gpointer data) |
|
| 69 { |
|
| 70 imhtml_cb(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml)), data); |
|
| 71 } |
|
| 72 |
|
| 73 static void |
|
| 74 make_string_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) { |
|
| 75 GtkWidget *box, *gtk_label, *entry; |
|
| 76 const gchar *pref_name; |
|
| 77 const gchar *pref_label; |
|
| 78 GaimStringFormatType format; |
|
| 79 |
|
| 80 pref_name = gaim_plugin_pref_get_name(pref); |
|
| 81 pref_label = gaim_plugin_pref_get_label(pref); |
|
| 82 format = gaim_plugin_pref_get_format_type(pref); |
|
| 83 |
|
| 84 switch(gaim_plugin_pref_get_type(pref)) { |
|
| 85 case GAIM_PLUGIN_PREF_CHOICE: |
|
| 86 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label, |
|
| 87 GAIM_PREF_STRING, pref_name, |
|
| 88 gaim_plugin_pref_get_choices(pref)); |
|
| 89 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
|
| 90 |
|
| 91 if(sg) |
|
| 92 gtk_size_group_add_widget(sg, gtk_label); |
|
| 93 |
|
| 94 break; |
|
| 95 case GAIM_PLUGIN_PREF_NONE: |
|
| 96 default: |
|
| 97 if (format == GAIM_STRING_FORMAT_TYPE_NONE) |
|
| 98 box = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
|
| 99 else |
|
| 100 box = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
|
| 101 |
|
| 102 gtk_widget_show(box); |
|
| 103 gtk_box_pack_start(GTK_BOX(parent), box, FALSE, FALSE, 0); |
|
| 104 |
|
| 105 gtk_label = gtk_label_new_with_mnemonic(pref_label); |
|
| 106 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
|
| 107 gtk_widget_show(gtk_label); |
|
| 108 gtk_box_pack_start(GTK_BOX(box), gtk_label, FALSE, FALSE, 0); |
|
| 109 |
|
| 110 if(sg) |
|
| 111 gtk_size_group_add_widget(sg, gtk_label); |
|
| 112 |
|
| 113 if (format == GAIM_STRING_FORMAT_TYPE_NONE) |
|
| 114 { |
|
| 115 entry = gtk_entry_new(); |
|
| 116 gtk_entry_set_text(GTK_ENTRY(entry), gaim_prefs_get_string(pref_name)); |
|
| 117 gtk_entry_set_max_length(GTK_ENTRY(entry), |
|
| 118 gaim_plugin_pref_get_max_length(pref)); |
|
| 119 if (gaim_plugin_pref_get_masked(pref)) |
|
| 120 { |
|
| 121 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE); |
|
| 122 gtk_entry_set_invisible_char(GTK_ENTRY(entry), GAIM_INVISIBLE_CHAR); |
|
| 123 } |
|
| 124 g_signal_connect(G_OBJECT(entry), "changed", |
|
| 125 G_CALLBACK(entry_cb), |
|
| 126 (gpointer)pref_name); |
|
| 127 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), entry); |
|
| 128 gtk_widget_show(entry); |
|
| 129 gtk_box_pack_start(GTK_BOX(box), entry, FALSE, FALSE, 0); |
|
| 130 } |
|
| 131 else |
|
| 132 { |
|
| 133 GtkWidget *hbox; |
|
| 134 GtkWidget *spacer; |
|
| 135 GtkWidget *imhtml; |
|
| 136 GtkWidget *toolbar; |
|
| 137 GtkWidget *frame; |
|
| 138 |
|
| 139 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE); |
|
| 140 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); |
|
| 141 gtk_widget_show(hbox); |
|
| 142 |
|
| 143 spacer = gtk_label_new(" "); |
|
| 144 gtk_box_pack_start(GTK_BOX(hbox), spacer, FALSE, FALSE, 0); |
|
| 145 gtk_widget_show(spacer); |
|
| 146 |
|
| 147 frame = gaim_gtk_create_imhtml(TRUE, &imhtml, &toolbar, NULL); |
|
| 148 if (!(format & GAIM_STRING_FORMAT_TYPE_HTML)) |
|
| 149 gtk_widget_destroy(toolbar); |
|
| 150 |
|
| 151 gtk_imhtml_append_text(GTK_IMHTML(imhtml), gaim_prefs_get_string(pref_name), |
|
| 152 (format & GAIM_STRING_FORMAT_TYPE_MULTILINE) ? 0 : GTK_IMHTML_NO_NEWLINE); |
|
| 153 gtk_label_set_mnemonic_widget(GTK_LABEL(gtk_label), imhtml); |
|
| 154 gtk_widget_show_all(frame); |
|
| 155 g_object_set_data(G_OBJECT(imhtml), "pref-key", (gpointer)pref_name); |
|
| 156 g_signal_connect(G_OBJECT(gtk_text_view_get_buffer(GTK_TEXT_VIEW(imhtml))), |
|
| 157 "changed", G_CALLBACK(imhtml_cb), imhtml); |
|
| 158 g_signal_connect(G_OBJECT(imhtml), |
|
| 159 "format_function_toggle", G_CALLBACK(imhtml_format_cb), imhtml); |
|
| 160 gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0); |
|
| 161 } |
|
| 162 |
|
| 163 break; |
|
| 164 } |
|
| 165 } |
|
| 166 |
|
| 167 static void |
|
| 168 make_int_pref(GtkWidget *parent, GaimPluginPref *pref, GtkSizeGroup *sg) { |
|
| 169 GtkWidget *gtk_label; |
|
| 170 const gchar *pref_name; |
|
| 171 const gchar *pref_label; |
|
| 172 gint max, min; |
|
| 173 |
|
| 174 pref_name = gaim_plugin_pref_get_name(pref); |
|
| 175 pref_label = gaim_plugin_pref_get_label(pref); |
|
| 176 |
|
| 177 switch(gaim_plugin_pref_get_type(pref)) { |
|
| 178 case GAIM_PLUGIN_PREF_CHOICE: |
|
| 179 gtk_label = gaim_gtk_prefs_dropdown_from_list(parent, pref_label, |
|
| 180 GAIM_PREF_INT, pref_name, gaim_plugin_pref_get_choices(pref)); |
|
| 181 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0.5); |
|
| 182 |
|
| 183 if(sg) |
|
| 184 gtk_size_group_add_widget(sg, gtk_label); |
|
| 185 |
|
| 186 break; |
|
| 187 case GAIM_PLUGIN_PREF_NONE: |
|
| 188 default: |
|
| 189 gaim_plugin_pref_get_bounds(pref, &min, &max); |
|
| 190 gaim_gtk_prefs_labeled_spin_button(parent, pref_label, |
|
| 191 pref_name, min, max, sg); |
|
| 192 break; |
|
| 193 } |
|
| 194 } |
|
| 195 |
|
| 196 |
|
| 197 static void |
|
| 198 make_info_pref(GtkWidget *parent, GaimPluginPref *pref) { |
|
| 199 GtkWidget *gtk_label = gtk_label_new(gaim_plugin_pref_get_label(pref)); |
|
| 200 gtk_misc_set_alignment(GTK_MISC(gtk_label), 0, 0); |
|
| 201 gtk_label_set_line_wrap(GTK_LABEL(gtk_label), TRUE); |
|
| 202 gtk_box_pack_start(GTK_BOX(parent), gtk_label, FALSE, FALSE, 0); |
|
| 203 gtk_widget_show(gtk_label); |
|
| 204 } |
|
| 205 |
|
| 206 |
|
| 207 GtkWidget * |
|
| 208 gaim_gtk_plugin_pref_create_frame(GaimPluginPrefFrame *frame) { |
|
| 209 GtkWidget *ret, *parent; |
|
| 210 GtkSizeGroup *sg; |
|
| 211 GList *pp; |
|
| 212 |
|
| 213 g_return_val_if_fail(frame, NULL); |
|
| 214 |
|
| 215 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL); |
|
| 216 |
|
| 217 parent = ret = gtk_vbox_new(FALSE, 16); |
|
| 218 gtk_container_set_border_width(GTK_CONTAINER(ret), GAIM_HIG_BORDER); |
|
| 219 gtk_widget_show(ret); |
|
| 220 |
|
| 221 for(pp = gaim_plugin_pref_frame_get_prefs(frame); |
|
| 222 pp != NULL; |
|
| 223 pp = pp->next) |
|
| 224 { |
|
| 225 GaimPluginPref *pref = (GaimPluginPref *)pp->data; |
|
| 226 |
|
| 227 const char *name = gaim_plugin_pref_get_name(pref); |
|
| 228 const char *label = gaim_plugin_pref_get_label(pref); |
|
| 229 |
|
| 230 if(name == NULL) { |
|
| 231 if(label == NULL) |
|
| 232 continue; |
|
| 233 |
|
| 234 if(gaim_plugin_pref_get_type(pref) == GAIM_PLUGIN_PREF_INFO) { |
|
| 235 make_info_pref(parent, pref); |
|
| 236 } else { |
|
| 237 parent = gaim_gtk_make_frame(ret, label); |
|
| 238 gtk_widget_show(parent); |
|
| 239 } |
|
| 240 |
|
| 241 continue; |
|
| 242 } |
|
| 243 |
|
| 244 switch(gaim_prefs_get_type(name)) { |
|
| 245 case GAIM_PREF_BOOLEAN: |
|
| 246 gaim_gtk_prefs_checkbox(label, name, parent); |
|
| 247 break; |
|
| 248 case GAIM_PREF_INT: |
|
| 249 make_int_pref(parent, pref, sg); |
|
| 250 break; |
|
| 251 case GAIM_PREF_STRING: |
|
| 252 make_string_pref(parent, pref, sg); |
|
| 253 break; |
|
| 254 default: |
|
| 255 break; |
|
| 256 } |
|
| 257 } |
|
| 258 |
|
| 259 return ret; |
|
| 260 } |
|