Simplify handling of GG xfer auth queue.
[pidgin-git.git] / pidgin / gtkprefs.c
blobb423916dadd3642234b4946a6a5a2f10a2674806
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
22 #include <talkatu.h>
24 #include "internal.h"
25 #include "glibcompat.h"
26 #include "pidgin.h"
28 #include "debug.h"
29 #include "http.h"
30 #include "nat-pmp.h"
31 #include "notify.h"
32 #include "prefs.h"
33 #include "proxy.h"
34 #include "protocol.h"
35 #include "request.h"
36 #include "savedstatuses.h"
37 #include "sound.h"
38 #include "sound-theme.h"
39 #include "stun.h"
40 #include "theme-manager.h"
41 #include "upnp.h"
42 #include "util.h"
43 #include "network.h"
44 #include "keyring.h"
46 #include "gtkblist.h"
47 #include "gtkconv.h"
48 #include "gtkdialogs.h"
49 #include "gtkprefs.h"
50 #include "gtksavedstatuses.h"
51 #include "gtksmiley-theme.h"
52 #include "gtksound.h"
53 #include "gtkstatus-icon-theme.h"
54 #include "gtkutils.h"
55 #include "pidgindebug.h"
56 #include "pidginstock.h"
57 #ifdef USE_VV
58 #include "media-gst.h"
59 #include <gst/video/videooverlay.h>
60 #ifdef GDK_WINDOWING_WIN32
61 #include <gdk/gdkwin32.h>
62 #endif
63 #ifdef GDK_WINDOWING_X11
64 #include <gdk/gdkx.h>
65 #endif
66 #ifdef GDK_WINDOWING_QUARTZ
67 #include <gdk/gdkquartz.h>
68 #endif
69 #endif
70 #include <libsoup/soup.h>
72 #include "gtk3compat.h"
74 #define PREFS_OPTIMAL_ICON_SIZE 32
76 /* 25MB */
77 #define PREFS_MAX_DOWNLOADED_THEME_SIZE 26214400
79 struct theme_info {
80 gchar *type;
81 gchar *extension;
82 gchar *original_name;
85 typedef struct _PidginPrefCombo PidginPrefCombo;
87 typedef void (*PidginPrefsBindDropdownCallback)(GtkComboBox *combo_box,
88 PidginPrefCombo *combo);
90 struct _PidginPrefCombo {
91 GtkWidget *combo;
92 PurplePrefType type;
93 const gchar *key;
94 union {
95 const char *string;
96 int integer;
97 gboolean boolean;
98 } value;
99 gint previously_active;
100 gint current_active;
101 PidginPrefsBindDropdownCallback cb;
104 struct _PidginPrefsWindow {
105 GtkDialog parent;
107 /* Stack */
108 GtkWidget *stack;
110 /* Interface page */
111 struct {
112 PidginPrefCombo docklet;
113 struct {
114 PidginPrefCombo hide_new;
115 } im;
116 struct {
117 GtkWidget *minimize_new_convs;
118 } win32;
119 struct {
120 GtkWidget *tabs;
121 GtkWidget *tabs_vbox;
122 GtkWidget *close_on_tabs;
123 PidginPrefCombo tab_side;
124 PidginPrefCombo placement;
125 } conversations;
126 } iface;
128 /* Browser page */
129 struct {
130 GtkWidget *page;
131 GtkWidget *stack;
132 /* GNOME version */
133 GtkWidget *gnome_not_found;
134 GtkWidget *gnome_program;
135 gchar *gnome_program_path;
136 /* Non-GNOME version */
137 PidginPrefCombo browser;
138 GtkWidget *place_hbox;
139 PidginPrefCombo place;
140 GtkWidget *manual_command_hbox;
141 GtkWidget *manual_command;
142 } browser;
144 /* Conversations page */
145 struct {
146 PidginPrefCombo notification_chat;
147 GtkWidget *show_incoming_formatting;
148 struct {
149 GtkWidget *close_immediately;
150 GtkWidget *show_buddy_icons;
151 GtkWidget *animate_buddy_icons;
152 GtkWidget *send_typing;
153 } im;
154 GtkWidget *spellcheck;
155 GtkWidget *use_smooth_scrolling;
156 struct {
157 GtkWidget *blink_im;
158 } win32;
159 GtkWidget *resize_custom_smileys;
160 GtkWidget *custom_smileys_size;
161 GtkWidget *minimum_entry_lines;
162 GtkTextBuffer *format_buffer;
163 GtkWidget *format_view;
164 /* Win32 specific frame */
165 GtkWidget *font_frame;
166 GtkWidget *use_theme_font;
167 GtkWidget *custom_font_hbox;
168 GtkWidget *custom_font;
169 } conversations;
171 /* Logging page */
172 struct {
173 PidginPrefCombo format;
174 GtkWidget *log_ims;
175 GtkWidget *log_chats;
176 GtkWidget *log_system;
177 } logging;
179 /* Network page */
180 struct {
181 GtkWidget *stun_server;
182 GtkWidget *auto_ip;
183 GtkWidget *public_ip;
184 GtkWidget *public_ip_hbox;
185 GtkWidget *map_ports;
186 GtkWidget *ports_range_use;
187 GtkWidget *ports_range_hbox;
188 GtkWidget *ports_range_start;
189 GtkWidget *ports_range_end;
190 GtkWidget *turn_server;
191 GtkWidget *turn_port_udp;
192 GtkWidget *turn_port_tcp;
193 GtkWidget *turn_username;
194 GtkWidget *turn_password;
195 } network;
197 /* Proxy page */
198 struct {
199 GtkWidget *stack;
200 /* GNOME version */
201 GtkWidget *gnome_not_found;
202 GtkWidget *gnome_program;
203 gchar *gnome_program_path;
204 /* Non-GNOME version */
205 GtkWidget *socks4_remotedns;
206 PidginPrefCombo type;
207 GtkWidget *options;
208 GtkWidget *host;
209 GtkWidget *port;
210 GtkWidget *username;
211 GtkWidget *password;
212 } proxy;
214 /* Keyrings page */
215 struct {
216 PidginPrefCombo active;
217 GtkWidget *vbox;
218 PurpleRequestFields *settings;
219 GtkWidget *settings_box;
220 GtkWidget *apply;
221 } keyring;
223 /* Sounds page */
224 struct {
225 PidginPrefCombo method;
226 GtkWidget *method_vbox;
227 GtkWidget *command;
228 GtkWidget *command_hbox;
229 GtkWidget *mute;
230 GtkWidget *conv_focus;
231 PidginPrefCombo while_status;
232 struct {
233 GtkWidget *view;
234 GtkListStore *store;
235 } event;
236 GtkWidget *entry;
237 } sound;
239 /* Away page */
240 struct {
241 PidginPrefCombo idle_reporting;
242 GtkWidget *mins_before_away;
243 GtkWidget *idle_hbox;
244 GtkWidget *away_when_idle;
245 PidginPrefCombo auto_reply;
246 GtkWidget *startup_current_status;
247 GtkWidget *startup_hbox;
248 GtkWidget *startup_label;
249 } away;
251 /* Themes page */
252 struct {
253 SoupSession *session;
254 GtkWidget *blist;
255 GtkWidget *status;
256 GtkWidget *sound;
257 GtkWidget *smiley;
258 } theme;
260 #ifdef USE_VV
261 /* Voice/Video page */
262 struct {
263 struct {
264 PidginPrefCombo input;
265 PidginPrefCombo output;
266 GtkWidget *level;
267 GtkWidget *threshold;
268 GtkWidget *volume;
269 GtkWidget *test;
270 GstElement *pipeline;
271 } voice;
273 struct {
274 PidginPrefCombo input;
275 PidginPrefCombo output;
276 GtkWidget *drawing_area;
277 GtkWidget *test;
278 GstElement *pipeline;
279 } video;
280 } vv;
281 #endif
284 /* Main dialog */
285 static PidginPrefsWindow *prefs = NULL;
287 /* Themes page */
288 static GtkWidget *prefs_sound_themes_combo_box;
289 static GtkWidget *prefs_blist_themes_combo_box;
290 static GtkWidget *prefs_status_themes_combo_box;
291 static GtkWidget *prefs_smiley_themes_combo_box;
293 /* Sound theme specific */
294 static int sound_row_sel = 0;
295 static gboolean prefs_sound_themes_loading;
297 /* These exist outside the lifetime of the prefs dialog */
298 static GtkListStore *prefs_sound_themes;
299 static GtkListStore *prefs_blist_themes;
300 static GtkListStore *prefs_status_icon_themes;
301 static GtkListStore *prefs_smiley_themes;
304 * PROTOTYPES
306 G_DEFINE_TYPE(PidginPrefsWindow, pidgin_prefs_window, GTK_TYPE_DIALOG);
307 static void delete_prefs(GtkWidget *, void *);
309 static void
310 update_spin_value(GtkWidget *w, GtkWidget *spin)
312 const char *key = g_object_get_data(G_OBJECT(spin), "val");
313 int value;
315 value = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
317 purple_prefs_set_int(key, value);
320 GtkWidget *
321 pidgin_prefs_labeled_spin_button(GtkWidget *box, const gchar *title,
322 const char *key, int min, int max, GtkSizeGroup *sg)
324 GtkWidget *spin;
325 GtkAdjustment *adjust;
326 int val;
328 val = purple_prefs_get_int(key);
330 adjust = GTK_ADJUSTMENT(gtk_adjustment_new(val, min, max, 1, 1, 0));
331 spin = gtk_spin_button_new(adjust, 1, 0);
332 g_object_set_data(G_OBJECT(spin), "val", (char *)key);
333 if (max < 10000)
334 gtk_widget_set_size_request(spin, 50, -1);
335 else
336 gtk_widget_set_size_request(spin, 60, -1);
337 g_signal_connect(G_OBJECT(adjust), "value-changed",
338 G_CALLBACK(update_spin_value), GTK_WIDGET(spin));
339 gtk_widget_show(spin);
341 return pidgin_add_widget_to_vbox(GTK_BOX(box), title, sg, spin, FALSE, NULL);
344 static void
345 pidgin_prefs_bind_spin_button(const char *key, GtkWidget *spin)
347 GtkAdjustment *adjust;
348 int val;
350 val = purple_prefs_get_int(key);
352 adjust = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(spin));
353 gtk_adjustment_set_value(adjust, val);
354 g_object_set_data(G_OBJECT(spin), "val", (char *)key);
355 g_signal_connect(G_OBJECT(adjust), "value-changed",
356 G_CALLBACK(update_spin_value), GTK_WIDGET(spin));
359 static void
360 entry_set(GtkEntry *entry, gpointer data)
362 const char *key = (const char*)data;
364 purple_prefs_set_string(key, gtk_entry_get_text(entry));
367 GtkWidget *
368 pidgin_prefs_labeled_entry(GtkWidget *page, const gchar *title,
369 const char *key, GtkSizeGroup *sg)
371 GtkWidget *entry;
372 const gchar *value;
374 value = purple_prefs_get_string(key);
376 entry = gtk_entry_new();
377 gtk_entry_set_text(GTK_ENTRY(entry), value);
378 g_signal_connect(G_OBJECT(entry), "changed",
379 G_CALLBACK(entry_set), (char*)key);
380 gtk_widget_show(entry);
382 return pidgin_add_widget_to_vbox(GTK_BOX(page), title, sg, entry, TRUE, NULL);
385 static void
386 pidgin_prefs_bind_entry(const char *key, GtkWidget *entry)
388 const gchar *value;
390 value = purple_prefs_get_string(key);
392 gtk_entry_set_text(GTK_ENTRY(entry), value);
393 g_signal_connect(G_OBJECT(entry), "changed", G_CALLBACK(entry_set),
394 (char*)key);
397 GtkWidget *
398 pidgin_prefs_labeled_password(GtkWidget *page, const gchar *title,
399 const char *key, GtkSizeGroup *sg)
401 GtkWidget *entry;
402 const gchar *value;
404 value = purple_prefs_get_string(key);
406 entry = gtk_entry_new();
407 gtk_entry_set_visibility(GTK_ENTRY(entry), FALSE);
408 gtk_entry_set_text(GTK_ENTRY(entry), value);
409 g_signal_connect(G_OBJECT(entry), "changed",
410 G_CALLBACK(entry_set), (char*)key);
411 gtk_widget_show(entry);
413 return pidgin_add_widget_to_vbox(GTK_BOX(page), title, sg, entry, TRUE, NULL);
416 /* TODO: Maybe move this up somewheres... */
417 enum {
418 PREF_DROPDOWN_TEXT,
419 PREF_DROPDOWN_VALUE,
420 PREF_DROPDOWN_COUNT
423 typedef struct
425 PurplePrefType type;
426 union {
427 const char *string;
428 int integer;
429 gboolean boolean;
430 } value;
431 } PidginPrefValue;
433 typedef void (*PidginPrefsDropdownCallback)(GtkComboBox *combo_box,
434 PidginPrefValue value);
436 static void
437 dropdown_set(GtkComboBox *combo_box, gpointer _cb)
439 PidginPrefsDropdownCallback cb = _cb;
440 GtkTreeIter iter;
441 GtkTreeModel *tree_model;
442 PidginPrefValue active;
444 tree_model = gtk_combo_box_get_model(combo_box);
445 if (!gtk_combo_box_get_active_iter(combo_box, &iter))
446 return;
447 active.type = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(combo_box),
448 "type"));
450 g_object_set_data(G_OBJECT(combo_box), "previously_active",
451 g_object_get_data(G_OBJECT(combo_box), "current_active"));
452 g_object_set_data(G_OBJECT(combo_box), "current_active",
453 GINT_TO_POINTER(gtk_combo_box_get_active(combo_box)));
455 if (active.type == PURPLE_PREF_INT) {
456 gtk_tree_model_get(tree_model, &iter, PREF_DROPDOWN_VALUE,
457 &active.value.integer, -1);
459 else if (active.type == PURPLE_PREF_STRING) {
460 gtk_tree_model_get(tree_model, &iter, PREF_DROPDOWN_VALUE,
461 &active.value.string, -1);
463 else if (active.type == PURPLE_PREF_BOOLEAN) {
464 gtk_tree_model_get(tree_model, &iter, PREF_DROPDOWN_VALUE,
465 &active.value.boolean, -1);
468 cb(combo_box, active);
471 static void
472 pidgin_prefs_bind_dropdown_revert_active(PidginPrefCombo *combo)
474 g_return_if_fail(combo != NULL);
476 combo->current_active = combo->previously_active;
478 gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo),
479 combo->previously_active);
482 static GtkWidget *
483 pidgin_prefs_dropdown_from_list_with_cb(GtkWidget *box, const gchar *title,
484 GtkComboBox **dropdown_out, GList *menuitems,
485 PidginPrefValue initial, PidginPrefsDropdownCallback cb)
487 GtkWidget *dropdown;
488 GtkWidget *label = NULL;
489 gchar *text;
490 GtkListStore *store = NULL;
491 GtkTreeIter iter;
492 GtkTreeIter active;
493 GtkCellRenderer *renderer;
494 gpointer current_active;
496 g_return_val_if_fail(menuitems != NULL, NULL);
498 if (initial.type == PURPLE_PREF_INT) {
499 store = gtk_list_store_new(PREF_DROPDOWN_COUNT, G_TYPE_STRING, G_TYPE_INT);
500 } else if (initial.type == PURPLE_PREF_STRING) {
501 store = gtk_list_store_new(PREF_DROPDOWN_COUNT, G_TYPE_STRING, G_TYPE_STRING);
502 } else if (initial.type == PURPLE_PREF_BOOLEAN) {
503 store = gtk_list_store_new(PREF_DROPDOWN_COUNT, G_TYPE_STRING, G_TYPE_BOOLEAN);
504 } else {
505 g_warn_if_reached();
506 return NULL;
509 dropdown = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
510 if (dropdown_out != NULL)
511 *dropdown_out = GTK_COMBO_BOX(dropdown);
512 g_object_set_data(G_OBJECT(dropdown), "type", GINT_TO_POINTER(initial.type));
514 while (menuitems != NULL && (text = (char *)menuitems->data) != NULL) {
515 int int_value = 0;
516 const char *str_value = NULL;
517 gboolean bool_value = FALSE;
519 menuitems = g_list_next(menuitems);
520 g_return_val_if_fail(menuitems != NULL, NULL);
522 gtk_list_store_append(store, &iter);
523 gtk_list_store_set(store, &iter,
524 PREF_DROPDOWN_TEXT, text,
525 -1);
527 if (initial.type == PURPLE_PREF_INT) {
528 int_value = GPOINTER_TO_INT(menuitems->data);
529 gtk_list_store_set(store, &iter,
530 PREF_DROPDOWN_VALUE, int_value,
531 -1);
533 else if (initial.type == PURPLE_PREF_STRING) {
534 str_value = (const char *)menuitems->data;
535 gtk_list_store_set(store, &iter,
536 PREF_DROPDOWN_VALUE, str_value,
537 -1);
539 else if (initial.type == PURPLE_PREF_BOOLEAN) {
540 bool_value = (gboolean)GPOINTER_TO_INT(menuitems->data);
541 gtk_list_store_set(store, &iter,
542 PREF_DROPDOWN_VALUE, bool_value,
543 -1);
546 if ((initial.type == PURPLE_PREF_INT &&
547 initial.value.integer == int_value) ||
548 (initial.type == PURPLE_PREF_STRING &&
549 purple_strequal(initial.value.string, str_value)) ||
550 (initial.type == PURPLE_PREF_BOOLEAN &&
551 (initial.value.boolean == bool_value))) {
553 active = iter;
556 menuitems = g_list_next(menuitems);
559 renderer = gtk_cell_renderer_text_new();
560 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(dropdown), renderer, TRUE);
561 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(dropdown), renderer,
562 "text", 0,
563 NULL);
565 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(dropdown), &active);
566 current_active = GINT_TO_POINTER(gtk_combo_box_get_active(GTK_COMBO_BOX(
567 dropdown)));
568 g_object_set_data(G_OBJECT(dropdown), "current_active", current_active);
569 g_object_set_data(G_OBJECT(dropdown), "previously_active", current_active);
571 g_signal_connect(G_OBJECT(dropdown), "changed",
572 G_CALLBACK(dropdown_set), cb);
574 pidgin_add_widget_to_vbox(GTK_BOX(box), title, NULL, dropdown, FALSE, &label);
576 return label;
579 static void
580 pidgin_prefs_dropdown_from_list_cb(GtkComboBox *combo_box,
581 PidginPrefValue value)
583 const char *key;
585 key = g_object_get_data(G_OBJECT(combo_box), "key");
587 if (value.type == PURPLE_PREF_INT) {
588 purple_prefs_set_int(key, value.value.integer);
589 } else if (value.type == PURPLE_PREF_STRING) {
590 purple_prefs_set_string(key, value.value.string);
591 } else if (value.type == PURPLE_PREF_BOOLEAN) {
592 purple_prefs_set_bool(key, value.value.boolean);
593 } else {
594 g_return_if_reached();
598 GtkWidget *
599 pidgin_prefs_dropdown_from_list(GtkWidget *box, const gchar *title,
600 PurplePrefType type, const char *key, GList *menuitems)
602 PidginPrefValue initial;
603 GtkComboBox *dropdown = NULL;
604 GtkWidget *label;
606 initial.type = type;
607 if (type == PURPLE_PREF_INT) {
608 initial.value.integer = purple_prefs_get_int(key);
609 } else if (type == PURPLE_PREF_STRING) {
610 initial.value.string = purple_prefs_get_string(key);
611 } else if (type == PURPLE_PREF_BOOLEAN) {
612 initial.value.boolean = purple_prefs_get_bool(key);
613 } else {
614 g_return_val_if_reached(NULL);
617 label = pidgin_prefs_dropdown_from_list_with_cb(box, title, &dropdown,
618 menuitems, initial, pidgin_prefs_dropdown_from_list_cb);
620 g_object_set_data(G_OBJECT(dropdown), "key", (gpointer)key);
622 return label;
625 GtkWidget *
626 pidgin_prefs_dropdown(GtkWidget *box, const gchar *title, PurplePrefType type,
627 const char *key, ...)
629 va_list ap;
630 GList *menuitems = NULL;
631 GtkWidget *dropdown = NULL;
632 char *name;
633 int int_value;
634 const char *str_value;
636 g_return_val_if_fail(type == PURPLE_PREF_BOOLEAN || type == PURPLE_PREF_INT ||
637 type == PURPLE_PREF_STRING, NULL);
639 va_start(ap, key);
640 while ((name = va_arg(ap, char *)) != NULL) {
642 menuitems = g_list_prepend(menuitems, name);
644 if (type == PURPLE_PREF_INT || type == PURPLE_PREF_BOOLEAN) {
645 int_value = va_arg(ap, int);
646 menuitems = g_list_prepend(menuitems, GINT_TO_POINTER(int_value));
648 else {
649 str_value = va_arg(ap, const char *);
650 menuitems = g_list_prepend(menuitems, (char *)str_value);
653 va_end(ap);
655 g_return_val_if_fail(menuitems != NULL, NULL);
657 menuitems = g_list_reverse(menuitems);
659 dropdown = pidgin_prefs_dropdown_from_list(box, title, type, key,
660 menuitems);
662 g_list_free(menuitems);
664 return dropdown;
667 static void
668 pidgin_prefs_bind_dropdown_from_list_cb(GtkComboBox *combo_box,
669 PidginPrefCombo *combo)
671 if (combo->type == PURPLE_PREF_INT) {
672 purple_prefs_set_int(combo->key, combo->value.integer);
673 } else if (combo->type == PURPLE_PREF_STRING) {
674 purple_prefs_set_string(combo->key, combo->value.string);
675 } else if (combo->type == PURPLE_PREF_BOOLEAN) {
676 purple_prefs_set_bool(combo->key, combo->value.boolean);
677 } else {
678 g_return_if_reached();
682 static void
683 bind_dropdown_set(GtkComboBox *combo_box, gpointer data)
685 PidginPrefCombo *combo = data;
686 GtkTreeIter iter;
687 GtkTreeModel *tree_model;
689 tree_model = gtk_combo_box_get_model(combo_box);
690 if (!gtk_combo_box_get_active_iter(combo_box, &iter))
691 return;
693 combo->previously_active = combo->current_active;
694 combo->current_active = gtk_combo_box_get_active(combo_box);
696 if (combo->type == PURPLE_PREF_INT) {
697 gtk_tree_model_get(tree_model, &iter, PREF_DROPDOWN_VALUE,
698 &combo->value.integer, -1);
700 else if (combo->type == PURPLE_PREF_STRING) {
701 gtk_tree_model_get(tree_model, &iter, PREF_DROPDOWN_VALUE,
702 &combo->value.string, -1);
704 else if (combo->type == PURPLE_PREF_BOOLEAN) {
705 gtk_tree_model_get(tree_model, &iter, PREF_DROPDOWN_VALUE,
706 &combo->value.boolean, -1);
709 combo->cb(combo_box, combo);
712 static void
713 pidgin_prefs_bind_dropdown_from_list(PidginPrefCombo *combo, GList *menuitems)
715 gchar *text;
716 GtkListStore *store = NULL;
717 GtkTreeIter iter;
718 GtkTreeIter active;
720 g_return_if_fail(menuitems != NULL);
722 if (combo->type == PURPLE_PREF_INT) {
723 combo->value.integer = purple_prefs_get_int(combo->key);
724 } else if (combo->type == PURPLE_PREF_STRING) {
725 combo->value.string = purple_prefs_get_string(combo->key);
726 } else if (combo->type == PURPLE_PREF_BOOLEAN) {
727 combo->value.boolean = purple_prefs_get_bool(combo->key);
728 } else {
729 g_return_if_reached();
732 store = GTK_LIST_STORE(
733 gtk_combo_box_get_model(GTK_COMBO_BOX(combo->combo)));
735 while (menuitems != NULL && (text = (char *)menuitems->data) != NULL) {
736 int int_value = 0;
737 const char *str_value = NULL;
738 gboolean bool_value = FALSE;
740 menuitems = g_list_next(menuitems);
741 g_return_if_fail(menuitems != NULL);
743 gtk_list_store_append(store, &iter);
744 gtk_list_store_set(store, &iter,
745 PREF_DROPDOWN_TEXT, text,
746 -1);
748 if (combo->type == PURPLE_PREF_INT) {
749 int_value = GPOINTER_TO_INT(menuitems->data);
750 gtk_list_store_set(store, &iter,
751 PREF_DROPDOWN_VALUE, int_value,
752 -1);
754 else if (combo->type == PURPLE_PREF_STRING) {
755 str_value = (const char *)menuitems->data;
756 gtk_list_store_set(store, &iter,
757 PREF_DROPDOWN_VALUE, str_value,
758 -1);
760 else if (combo->type == PURPLE_PREF_BOOLEAN) {
761 bool_value = (gboolean)GPOINTER_TO_INT(menuitems->data);
762 gtk_list_store_set(store, &iter,
763 PREF_DROPDOWN_VALUE, bool_value,
764 -1);
767 if ((combo->type == PURPLE_PREF_INT &&
768 combo->value.integer == int_value) ||
769 (combo->type == PURPLE_PREF_STRING &&
770 purple_strequal(combo->value.string, str_value)) ||
771 (combo->type == PURPLE_PREF_BOOLEAN &&
772 (combo->value.boolean == bool_value))) {
774 active = iter;
777 menuitems = g_list_next(menuitems);
780 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo->combo), &active);
781 combo->current_active = gtk_combo_box_get_active(
782 GTK_COMBO_BOX(combo->combo));
783 combo->previously_active = combo->current_active;
785 combo->cb = pidgin_prefs_bind_dropdown_from_list_cb;
786 g_signal_connect(G_OBJECT(combo->combo), "changed",
787 G_CALLBACK(bind_dropdown_set), combo);
790 static void
791 pidgin_prefs_bind_dropdown(PidginPrefCombo *combo)
793 GtkTreeModel *store = NULL;
794 GtkTreeIter iter;
795 GtkTreeIter active;
797 if (combo->type == PURPLE_PREF_INT) {
798 combo->value.integer = purple_prefs_get_int(combo->key);
799 } else if (combo->type == PURPLE_PREF_STRING) {
800 combo->value.string = purple_prefs_get_string(combo->key);
801 } else if (combo->type == PURPLE_PREF_BOOLEAN) {
802 combo->value.boolean = purple_prefs_get_bool(combo->key);
803 } else {
804 g_return_if_reached();
807 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo->combo));
809 if (!gtk_tree_model_get_iter_first(store, &iter)) {
810 g_return_if_reached();
813 do {
814 int int_value = 0;
815 const char *str_value = NULL;
816 gboolean bool_value = FALSE;
818 if (combo->type == PURPLE_PREF_INT) {
819 gtk_tree_model_get(store, &iter,
820 PREF_DROPDOWN_VALUE, &int_value,
821 -1);
822 if (combo->value.integer == int_value) {
823 active = iter;
824 break;
827 else if (combo->type == PURPLE_PREF_STRING) {
828 gtk_tree_model_get(store, &iter,
829 PREF_DROPDOWN_VALUE, &str_value,
830 -1);
831 if (purple_strequal(combo->value.string, str_value)) {
832 active = iter;
833 break;
836 else if (combo->type == PURPLE_PREF_BOOLEAN) {
837 gtk_tree_model_get(store, &iter,
838 PREF_DROPDOWN_VALUE, &bool_value,
839 -1);
840 if (combo->value.boolean == bool_value) {
841 active = iter;
842 break;
845 } while (gtk_tree_model_iter_next(store, &iter));
847 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo->combo), &active);
849 combo->current_active = gtk_combo_box_get_active(
850 GTK_COMBO_BOX(combo->combo));
851 combo->previously_active = combo->current_active;
853 combo->cb = pidgin_prefs_bind_dropdown_from_list_cb;
854 g_signal_connect(G_OBJECT(combo->combo), "changed",
855 G_CALLBACK(bind_dropdown_set), combo);
858 static void
859 set_bool_pref(GtkWidget *w, const char *key)
861 purple_prefs_set_bool(key,
862 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)));
865 GtkWidget *
866 pidgin_prefs_checkbox(const char *text, const char *key, GtkWidget *page)
868 GtkWidget *button;
870 button = gtk_check_button_new_with_mnemonic(text);
871 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
872 purple_prefs_get_bool(key));
874 gtk_box_pack_start(GTK_BOX(page), button, FALSE, FALSE, 0);
876 g_signal_connect(G_OBJECT(button), "clicked",
877 G_CALLBACK(set_bool_pref), (char *)key);
879 gtk_widget_show(button);
881 return button;
884 static void
885 pidgin_prefs_bind_checkbox(const char *key, GtkWidget *button)
887 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
888 purple_prefs_get_bool(key));
889 g_signal_connect(G_OBJECT(button), "toggled",
890 G_CALLBACK(set_bool_pref), (char *)key);
893 static void keyring_page_cleanup(PidginPrefsWindow *win);
895 static void
896 delete_prefs(GtkWidget *asdf, void *gdsa)
898 /* Close any "select sound" request dialogs */
899 purple_request_close_with_handle(prefs);
901 purple_notify_close_with_handle(prefs);
903 g_clear_object(&prefs->theme.session);
905 /* Unregister callbacks. */
906 purple_prefs_disconnect_by_handle(prefs);
908 /* NULL-ify globals */
909 sound_row_sel = 0;
910 prefs_sound_themes_loading = FALSE;
912 prefs_sound_themes_combo_box = NULL;
913 prefs_blist_themes_combo_box = NULL;
914 prefs_status_themes_combo_box = NULL;
915 prefs_smiley_themes_combo_box = NULL;
917 keyring_page_cleanup(prefs);
919 g_free(prefs->proxy.gnome_program_path);
920 g_free(prefs->browser.gnome_program_path);
921 prefs = NULL;
924 static gchar *
925 get_theme_markup(const char *name, gboolean custom, const char *author,
926 const char *description)
929 return g_strdup_printf("<b>%s</b>%s%s%s%s\n<span foreground='dim grey'>%s</span>",
930 name, custom ? " " : "", custom ? _("(Custom)") : "",
931 author != NULL ? " - " : "", author != NULL ? author : "",
932 description != NULL ? description : "");
935 static void
936 smileys_refresh_theme_list(void)
938 GList *it;
939 GtkTreeIter iter;
940 gchar *description;
942 description = get_theme_markup(_("none"), FALSE, _("Penguin Pimps"),
943 _("Selecting this disables graphical emoticons."));
944 gtk_list_store_append(prefs_smiley_themes, &iter);
945 gtk_list_store_set(prefs_smiley_themes, &iter,
946 0, NULL, 1, description, 2, "none", -1);
947 g_free(description);
949 for (it = pidgin_smiley_theme_get_all(); it; it = g_list_next(it)) {
950 PidginSmileyTheme *theme = it->data;
952 description = get_theme_markup(
953 _(pidgin_smiley_theme_get_name(theme)), FALSE,
954 _(pidgin_smiley_theme_get_author(theme)),
955 _(pidgin_smiley_theme_get_description(theme)));
957 gtk_list_store_append(prefs_smiley_themes, &iter);
958 gtk_list_store_set(prefs_smiley_themes, &iter,
959 0, pidgin_smiley_theme_get_icon(theme),
960 1, description,
961 2, pidgin_smiley_theme_get_name(theme),
962 -1);
964 g_free(description);
968 /* Rebuild the markup for the sound theme selection for "(Custom)" themes */
969 static void
970 pref_sound_generate_markup(void)
972 gboolean print_custom, customized;
973 const gchar *author, *description, *current_theme;
974 gchar *name, *markup;
975 PurpleSoundTheme *theme;
976 GtkTreeIter iter;
978 customized = pidgin_sound_is_customized();
979 current_theme = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme");
981 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(prefs_sound_themes), &iter)) {
982 do {
983 gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &iter, 2, &name, -1);
985 print_custom = customized && name && purple_strequal(current_theme, name);
987 if (!name || *name == '\0') {
988 g_free(name);
989 name = g_strdup(_("Default"));
990 author = _("Penguin Pimps");
991 description = _("The default Pidgin sound theme");
992 } else {
993 theme = PURPLE_SOUND_THEME(purple_theme_manager_find_theme(name, "sound"));
994 author = purple_theme_get_author(PURPLE_THEME(theme));
995 description = purple_theme_get_description(PURPLE_THEME(theme));
998 markup = get_theme_markup(name, print_custom, author, description);
1000 gtk_list_store_set(prefs_sound_themes, &iter, 1, markup, -1);
1002 g_free(name);
1003 g_free(markup);
1005 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(prefs_sound_themes), &iter));
1009 /* adds the themes to the theme list from the manager so they can be displayed in prefs */
1010 static void
1011 prefs_themes_sort(PurpleTheme *theme)
1013 GdkPixbuf *pixbuf = NULL;
1014 GtkTreeIter iter;
1015 gchar *image_full = NULL, *markup;
1016 const gchar *name, *author, *description;
1018 if (PURPLE_IS_SOUND_THEME(theme)){
1020 image_full = purple_theme_get_image_full(theme);
1021 if (image_full != NULL){
1022 pixbuf = pidgin_pixbuf_new_from_file_at_scale(image_full, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE);
1023 g_free(image_full);
1024 } else
1025 pixbuf = NULL;
1027 gtk_list_store_append(prefs_sound_themes, &iter);
1028 gtk_list_store_set(prefs_sound_themes, &iter, 0, pixbuf, 2, purple_theme_get_name(theme), -1);
1030 if (pixbuf != NULL)
1031 g_object_unref(G_OBJECT(pixbuf));
1033 } else if (PIDGIN_IS_BLIST_THEME(theme) || PIDGIN_IS_STATUS_ICON_THEME(theme)){
1034 GtkListStore *store;
1036 if (PIDGIN_IS_BLIST_THEME(theme))
1037 store = prefs_blist_themes;
1038 else
1039 store = prefs_status_icon_themes;
1041 image_full = purple_theme_get_image_full(theme);
1042 if (image_full != NULL){
1043 pixbuf = pidgin_pixbuf_new_from_file_at_scale(image_full, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE);
1044 g_free(image_full);
1045 } else
1046 pixbuf = NULL;
1048 name = purple_theme_get_name(theme);
1049 author = purple_theme_get_author(theme);
1050 description = purple_theme_get_description(theme);
1052 markup = get_theme_markup(name, FALSE, author, description);
1054 gtk_list_store_append(store, &iter);
1055 gtk_list_store_set(store, &iter, 0, pixbuf, 1, markup, 2, name, -1);
1057 g_free(markup);
1058 if (pixbuf != NULL)
1059 g_object_unref(G_OBJECT(pixbuf));
1064 static void
1065 prefs_set_active_theme_combo(GtkWidget *combo_box, GtkListStore *store, const gchar *current_theme)
1067 GtkTreeIter iter;
1068 gchar *theme = NULL;
1069 gboolean unset = TRUE;
1071 if (current_theme && *current_theme && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) {
1072 do {
1073 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, 2, &theme, -1);
1075 if (purple_strequal(current_theme, theme)) {
1076 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo_box), &iter);
1077 unset = FALSE;
1080 g_free(theme);
1081 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
1084 if (unset)
1085 gtk_combo_box_set_active(GTK_COMBO_BOX(combo_box), 0);
1088 static void
1089 prefs_themes_refresh(void)
1091 GdkPixbuf *pixbuf = NULL;
1092 gchar *tmp;
1093 GtkTreeIter iter;
1095 prefs_sound_themes_loading = TRUE;
1096 /* refresh the list of themes in the manager */
1097 purple_theme_manager_refresh();
1099 tmp = g_build_filename(PURPLE_DATADIR, "icons", "hicolor", "32x32",
1100 "apps", "im.pidgin.Pidgin3.png", NULL);
1101 pixbuf = pidgin_pixbuf_new_from_file_at_scale(tmp, PREFS_OPTIMAL_ICON_SIZE, PREFS_OPTIMAL_ICON_SIZE, TRUE);
1102 g_free(tmp);
1104 /* sound themes */
1105 gtk_list_store_clear(prefs_sound_themes);
1106 gtk_list_store_append(prefs_sound_themes, &iter);
1107 gtk_list_store_set(prefs_sound_themes, &iter, 0, pixbuf, 2, "", -1);
1109 /* blist themes */
1110 gtk_list_store_clear(prefs_blist_themes);
1111 gtk_list_store_append(prefs_blist_themes, &iter);
1112 tmp = get_theme_markup(_("Default"), FALSE, _("Penguin Pimps"),
1113 _("The default Pidgin buddy list theme"));
1114 gtk_list_store_set(prefs_blist_themes, &iter, 0, pixbuf, 1, tmp, 2, "", -1);
1115 g_free(tmp);
1117 /* status icon themes */
1118 gtk_list_store_clear(prefs_status_icon_themes);
1119 gtk_list_store_append(prefs_status_icon_themes, &iter);
1120 tmp = get_theme_markup(_("Default"), FALSE, _("Penguin Pimps"),
1121 _("The default Pidgin status icon theme"));
1122 gtk_list_store_set(prefs_status_icon_themes, &iter, 0, pixbuf, 1, tmp, 2, "", -1);
1123 g_free(tmp);
1124 if (pixbuf)
1125 g_object_unref(G_OBJECT(pixbuf));
1127 /* smiley themes */
1128 gtk_list_store_clear(prefs_smiley_themes);
1130 purple_theme_manager_for_each_theme(prefs_themes_sort);
1131 pref_sound_generate_markup();
1132 smileys_refresh_theme_list();
1134 /* set active */
1135 prefs_set_active_theme_combo(prefs_sound_themes_combo_box, prefs_sound_themes, purple_prefs_get_string(PIDGIN_PREFS_ROOT "/sound/theme"));
1136 prefs_set_active_theme_combo(prefs_blist_themes_combo_box, prefs_blist_themes, purple_prefs_get_string(PIDGIN_PREFS_ROOT "/blist/theme"));
1137 prefs_set_active_theme_combo(prefs_status_themes_combo_box, prefs_status_icon_themes, purple_prefs_get_string(PIDGIN_PREFS_ROOT "/status/icon-theme"));
1138 prefs_set_active_theme_combo(prefs_smiley_themes_combo_box, prefs_smiley_themes, purple_prefs_get_string(PIDGIN_PREFS_ROOT "/smileys/theme"));
1139 prefs_sound_themes_loading = FALSE;
1142 /* init all the theme variables so that the themes can be sorted later and used by pref pages */
1143 static void
1144 prefs_themes_init(void)
1146 prefs_sound_themes = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
1148 prefs_blist_themes = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
1150 prefs_status_icon_themes = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
1152 prefs_smiley_themes = gtk_list_store_new(3, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_STRING);
1156 * prefs_theme_find_theme:
1157 * @path: A directory containing a theme. The theme could be at the
1158 * top level of this directory or in any subdirectory thereof.
1159 * @type: The type of theme to load. The loader for this theme type
1160 * will be used and this loader will determine what constitutes a
1161 * "theme."
1163 * Attempt to load the given directory as a theme. If we are unable to
1164 * open the path as a theme then we recurse into path and attempt to
1165 * load each subdirectory that we encounter.
1167 * Returns: A new reference to a #PurpleTheme.
1169 static PurpleTheme *
1170 prefs_theme_find_theme(const gchar *path, const gchar *type)
1172 PurpleTheme *theme = purple_theme_manager_load_theme(path, type);
1173 GDir *dir = g_dir_open(path, 0, NULL);
1174 const gchar *next;
1176 while (!PURPLE_IS_THEME(theme) && (next = g_dir_read_name(dir))) {
1177 gchar *next_path = g_build_filename(path, next, NULL);
1179 if (g_file_test(next_path, G_FILE_TEST_IS_DIR))
1180 theme = prefs_theme_find_theme(next_path, type);
1182 g_free(next_path);
1185 g_dir_close(dir);
1187 return theme;
1190 /* Eww. Seriously ewww. But thanks, grim! This is taken from guifications2 */
1191 static gboolean
1192 purple_theme_file_copy(const gchar *source, const gchar *destination)
1194 FILE *src, *dest;
1195 gint chr = EOF;
1197 if(!(src = g_fopen(source, "rb")))
1198 return FALSE;
1199 if(!(dest = g_fopen(destination, "wb"))) {
1200 fclose(src);
1201 return FALSE;
1204 while((chr = fgetc(src)) != EOF) {
1205 fputc(chr, dest);
1208 fclose(dest);
1209 fclose(src);
1211 return TRUE;
1214 static void
1215 free_theme_info(struct theme_info *info)
1217 if (info != NULL) {
1218 g_free(info->type);
1219 g_free(info->extension);
1220 g_free(info->original_name);
1221 g_free(info);
1225 /* installs a theme, info is freed by function */
1226 static void
1227 theme_install_theme(char *path, struct theme_info *info)
1229 gchar *destdir;
1230 const char *tail;
1231 gboolean is_smiley_theme, is_archive;
1232 PurpleTheme *theme = NULL;
1234 if (info == NULL)
1235 return;
1237 /* check the extension */
1238 tail = info->extension ? info->extension : strrchr(path, '.');
1240 if (!tail) {
1241 free_theme_info(info);
1242 return;
1245 is_archive = !g_ascii_strcasecmp(tail, ".gz") || !g_ascii_strcasecmp(tail, ".tgz");
1247 /* Just to be safe */
1248 g_strchomp(path);
1250 if ((is_smiley_theme = purple_strequal(info->type, "smiley")))
1251 destdir = g_build_filename(purple_data_dir(), "smileys", NULL);
1252 else
1253 destdir = g_build_filename(purple_data_dir(), "themes", "temp", NULL);
1255 /* We'll check this just to make sure. This also lets us do something different on
1256 * other platforms, if need be */
1257 if (is_archive) {
1258 #ifndef _WIN32
1259 gchar *path_escaped = g_shell_quote(path);
1260 gchar *destdir_escaped = g_shell_quote(destdir);
1261 gchar *command;
1263 if (!g_file_test(destdir, G_FILE_TEST_IS_DIR))
1264 purple_build_dir(destdir, S_IRUSR | S_IWUSR | S_IXUSR);
1266 command = g_strdup_printf("tar > /dev/null xzf %s -C %s", path_escaped, destdir_escaped);
1267 g_free(path_escaped);
1268 g_free(destdir_escaped);
1270 /* Fire! */
1271 if (system(command)) {
1272 purple_notify_error(NULL, NULL, _("Theme failed to unpack."), NULL, NULL);
1273 g_free(command);
1274 g_free(destdir);
1275 free_theme_info(info);
1276 return;
1278 g_free(command);
1279 #else
1280 if (!winpidgin_gz_untar(path, destdir)) {
1281 purple_notify_error(NULL, NULL, _("Theme failed to unpack."), NULL, NULL);
1282 g_free(destdir);
1283 free_theme_info(info);
1284 return;
1286 #endif
1289 if (is_smiley_theme) {
1290 /* just extract the folder to the smiley directory */
1291 prefs_themes_refresh();
1293 } else if (is_archive) {
1294 theme = prefs_theme_find_theme(destdir, info->type);
1296 if (PURPLE_IS_THEME(theme)) {
1297 /* create the location for the theme */
1298 gchar *theme_dest = g_build_filename(purple_data_dir(), "themes",
1299 purple_theme_get_name(theme),
1300 "purple", info->type, NULL);
1302 if (!g_file_test(theme_dest, G_FILE_TEST_IS_DIR))
1303 purple_build_dir(theme_dest, S_IRUSR | S_IWUSR | S_IXUSR);
1305 g_free(theme_dest);
1306 theme_dest = g_build_filename(purple_data_dir(), "themes",
1307 purple_theme_get_name(theme),
1308 "purple", info->type, NULL);
1310 /* move the entire directory to new location */
1311 if (g_rename(purple_theme_get_dir(theme), theme_dest)) {
1312 purple_debug_error("gtkprefs", "Error renaming %s to %s: "
1313 "%s\n", purple_theme_get_dir(theme), theme_dest,
1314 g_strerror(errno));
1317 g_free(theme_dest);
1318 if (g_remove(destdir) != 0) {
1319 purple_debug_error("gtkprefs",
1320 "couldn't remove temp (dest) path\n");
1322 g_object_unref(theme);
1324 prefs_themes_refresh();
1326 } else {
1327 /* something was wrong with the theme archive */
1328 g_unlink(destdir);
1329 purple_notify_error(NULL, NULL, _("Theme failed to load."), NULL, NULL);
1332 } else { /* just a single file so copy it to a new temp directory and attempt to load it*/
1333 gchar *temp_path, *temp_file;
1335 temp_path = g_build_filename(purple_data_dir(), "themes", "temp",
1336 "sub_folder", NULL);
1338 if (info->original_name != NULL) {
1339 /* name was changed from the original (probably a dnd) change it back before loading */
1340 temp_file = g_build_filename(temp_path, info->original_name, NULL);
1342 } else {
1343 gchar *source_name = g_path_get_basename(path);
1344 temp_file = g_build_filename(temp_path, source_name, NULL);
1345 g_free(source_name);
1348 if (!g_file_test(temp_path, G_FILE_TEST_IS_DIR))
1349 purple_build_dir(temp_path, S_IRUSR | S_IWUSR | S_IXUSR);
1351 if (purple_theme_file_copy(path, temp_file)) {
1352 /* find the theme, could be in subfolder */
1353 theme = prefs_theme_find_theme(temp_path, info->type);
1355 if (PURPLE_IS_THEME(theme)) {
1356 gchar *theme_dest =
1357 g_build_filename(purple_data_dir(), "themes",
1358 purple_theme_get_name(theme), "purple",
1359 info->type, NULL);
1361 if(!g_file_test(theme_dest, G_FILE_TEST_IS_DIR))
1362 purple_build_dir(theme_dest, S_IRUSR | S_IWUSR | S_IXUSR);
1364 if (g_rename(purple_theme_get_dir(theme), theme_dest)) {
1365 purple_debug_error("gtkprefs", "Error renaming %s to %s: "
1366 "%s\n", purple_theme_get_dir(theme), theme_dest,
1367 g_strerror(errno));
1370 g_free(theme_dest);
1371 g_object_unref(theme);
1373 prefs_themes_refresh();
1374 } else {
1375 if (g_remove(temp_path) != 0) {
1376 purple_debug_error("gtkprefs",
1377 "couldn't remove temp path");
1379 purple_notify_error(NULL, NULL, _("Theme failed to load."), NULL, NULL);
1381 } else {
1382 purple_notify_error(NULL, NULL, _("Theme failed to copy."), NULL, NULL);
1385 g_free(temp_file);
1386 g_free(temp_path);
1389 g_free(destdir);
1390 free_theme_info(info);
1393 static void
1394 theme_got_url(G_GNUC_UNUSED SoupSession *session, SoupMessage *msg,
1395 gpointer _info)
1397 struct theme_info *info = _info;
1398 FILE *f;
1399 gchar *path;
1400 size_t wc;
1402 if (!SOUP_STATUS_IS_SUCCESSFUL(msg->status_code)) {
1403 free_theme_info(info);
1404 return;
1407 f = purple_mkstemp(&path, TRUE);
1408 wc = fwrite(msg->response_body->data, msg->response_body->length, 1, f);
1409 if (wc != 1) {
1410 purple_debug_warning("theme_got_url", "Unable to write theme data.\n");
1411 fclose(f);
1412 g_unlink(path);
1413 g_free(path);
1414 free_theme_info(info);
1415 return;
1417 fclose(f);
1419 theme_install_theme(path, info);
1421 g_unlink(path);
1422 g_free(path);
1425 static void
1426 theme_dnd_recv(GtkWidget *widget, GdkDragContext *dc, guint x, guint y,
1427 GtkSelectionData *sd, guint info, guint t, gpointer user_data)
1429 gchar *name = g_strchomp((gchar *)gtk_selection_data_get_data(sd));
1431 if ((gtk_selection_data_get_length(sd) >= 0)
1432 && (gtk_selection_data_get_format(sd) == 8)) {
1433 /* Well, it looks like the drag event was cool.
1434 * Let's do something with it */
1435 gchar *temp;
1436 struct theme_info *info = g_new0(struct theme_info, 1);
1437 info->type = g_strdup((gchar *)user_data);
1438 info->extension = g_strdup(g_strrstr(name,"."));
1439 temp = g_strrstr(name, "/");
1440 info->original_name = temp ? g_strdup(++temp) : NULL;
1442 if (!g_ascii_strncasecmp(name, "file://", 7)) {
1443 GError *converr = NULL;
1444 gchar *tmp;
1445 /* It looks like we're dealing with a local file. Let's
1446 * just untar it in the right place */
1447 if(!(tmp = g_filename_from_uri(name, NULL, &converr))) {
1448 purple_debug(PURPLE_DEBUG_ERROR, "theme dnd", "%s\n",
1449 (converr ? converr->message :
1450 "g_filename_from_uri error"));
1451 free_theme_info(info);
1452 return;
1454 theme_install_theme(tmp, info);
1455 g_free(tmp);
1456 } else if (!g_ascii_strncasecmp(name, "http://", 7) ||
1457 !g_ascii_strncasecmp(name, "https://", 8)) {
1458 /* Oo, a web drag and drop. This is where things
1459 * will start to get interesting */
1460 SoupMessage *msg;
1462 if (prefs->theme.session == NULL) {
1463 prefs->theme.session = soup_session_new();
1466 soup_session_abort(prefs->theme.session);
1468 msg = soup_message_new("GET", name);
1469 // purple_http_request_set_max_len(msg, PREFS_MAX_DOWNLOADED_THEME_SIZE);
1470 soup_session_queue_message(prefs->theme.session, msg, theme_got_url,
1471 info);
1472 } else
1473 free_theme_info(info);
1475 gtk_drag_finish(dc, TRUE, FALSE, t);
1478 gtk_drag_finish(dc, FALSE, FALSE, t);
1481 /* builds a theme combo box from a list store with colums: icon preview, markup, theme name */
1482 static void
1483 prefs_build_theme_combo_box(GtkWidget *combo_box, GtkListStore *store,
1484 const char *current_theme, const char *type)
1486 GtkTargetEntry te[3] = {
1487 {"text/plain", 0, 0},
1488 {"text/uri-list", 0, 1},
1489 {"STRING", 0, 2}
1492 g_return_if_fail(store != NULL && current_theme != NULL);
1494 gtk_combo_box_set_model(GTK_COMBO_BOX(combo_box),
1495 GTK_TREE_MODEL(store));
1497 gtk_drag_dest_set(combo_box, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP, te,
1498 sizeof(te) / sizeof(GtkTargetEntry) , GDK_ACTION_COPY | GDK_ACTION_MOVE);
1500 g_signal_connect(G_OBJECT(combo_box), "drag_data_received", G_CALLBACK(theme_dnd_recv), (gpointer) type);
1503 /* sets the current sound theme */
1504 static void
1505 prefs_set_sound_theme_cb(GtkComboBox *combo_box, gpointer user_data)
1507 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(user_data);
1508 gint i;
1509 gchar *pref;
1510 gchar *new_theme;
1511 GtkTreeIter new_iter;
1513 if(gtk_combo_box_get_active_iter(combo_box, &new_iter) && !prefs_sound_themes_loading) {
1515 gtk_tree_model_get(GTK_TREE_MODEL(prefs_sound_themes), &new_iter, 2, &new_theme, -1);
1517 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/sound/theme", new_theme);
1519 /* New theme removes all customization */
1520 for(i = 0; i < PURPLE_NUM_SOUNDS; i++){
1521 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
1522 pidgin_sound_get_event_option(i));
1523 purple_prefs_set_path(pref, "");
1524 g_free(pref);
1527 /* gets rid of the "(Custom)" from the last selection */
1528 pref_sound_generate_markup();
1530 gtk_entry_set_text(GTK_ENTRY(win->sound.entry), _("(default)"));
1532 g_free(new_theme);
1536 /* sets the current smiley theme */
1537 static void
1538 prefs_set_smiley_theme_cb(GtkComboBox *combo_box, gpointer user_data)
1540 gchar *new_theme;
1541 GtkTreeIter new_iter;
1543 if (gtk_combo_box_get_active_iter(combo_box, &new_iter)) {
1545 gtk_tree_model_get(GTK_TREE_MODEL(prefs_smiley_themes), &new_iter, 2, &new_theme, -1);
1547 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/smileys/theme", new_theme);
1549 g_free(new_theme);
1554 /* Does same as normal sort, except "none" is sorted first */
1555 static gint pidgin_sort_smileys (GtkTreeModel *model,
1556 GtkTreeIter *a,
1557 GtkTreeIter *b,
1558 gpointer userdata)
1560 gint ret = 0;
1561 gchar *name1 = NULL, *name2 = NULL;
1563 gtk_tree_model_get(model, a, 2, &name1, -1);
1564 gtk_tree_model_get(model, b, 2, &name2, -1);
1566 if (name1 == NULL || name2 == NULL) {
1567 if (!(name1 == NULL && name2 == NULL))
1568 ret = (name1 == NULL) ? -1: 1;
1569 } else if (!g_ascii_strcasecmp(name1, "none")) {
1570 if (!g_utf8_collate(name1, name2))
1571 ret = 0;
1572 else
1573 /* Sort name1 first */
1574 ret = -1;
1575 } else if (!g_ascii_strcasecmp(name2, "none")) {
1576 /* Sort name2 first */
1577 ret = 1;
1578 } else {
1579 /* Neither string is "none", default to normal sort */
1580 ret = purple_utf8_strcasecmp(name1, name2);
1583 g_free(name1);
1584 g_free(name2);
1586 return ret;
1589 /* sets the current buddy list theme */
1590 static void
1591 prefs_set_blist_theme_cb(GtkComboBox *combo_box, gpointer user_data)
1593 PidginBlistTheme *theme = NULL;
1594 GtkTreeIter iter;
1595 gchar *name = NULL;
1597 if(gtk_combo_box_get_active_iter(combo_box, &iter)) {
1599 gtk_tree_model_get(GTK_TREE_MODEL(prefs_blist_themes), &iter, 2, &name, -1);
1601 if(!name || *name)
1602 theme = PIDGIN_BLIST_THEME(purple_theme_manager_find_theme(name, "blist"));
1604 g_free(name);
1606 pidgin_blist_set_theme(theme);
1610 /* sets the current icon theme */
1611 static void
1612 prefs_set_status_icon_theme_cb(GtkComboBox *combo_box, gpointer user_data)
1614 PidginStatusIconTheme *theme = NULL;
1615 GtkTreeIter iter;
1616 gchar *name = NULL;
1618 if(gtk_combo_box_get_active_iter(combo_box, &iter)) {
1620 gtk_tree_model_get(GTK_TREE_MODEL(prefs_status_icon_themes), &iter, 2, &name, -1);
1622 if(!name || *name)
1623 theme = PIDGIN_STATUS_ICON_THEME(purple_theme_manager_find_theme(name, "status-icon"));
1625 g_free(name);
1627 pidgin_stock_load_status_icon_theme(theme);
1628 pidgin_blist_refresh(purple_blist_get_default());
1632 static void
1633 bind_theme_page(PidginPrefsWindow *win)
1635 /* Buddy List Themes */
1636 prefs_build_theme_combo_box(win->theme.blist, prefs_blist_themes,
1637 PIDGIN_PREFS_ROOT "/blist/theme", "blist");
1638 prefs_blist_themes_combo_box = win->theme.blist;
1640 /* Status Icon Themes */
1641 prefs_build_theme_combo_box(win->theme.status, prefs_status_icon_themes,
1642 PIDGIN_PREFS_ROOT "/status/icon-theme",
1643 "icon");
1644 prefs_status_themes_combo_box = win->theme.status;
1646 /* Sound Themes */
1647 prefs_build_theme_combo_box(win->theme.sound, prefs_sound_themes,
1648 PIDGIN_PREFS_ROOT "/sound/theme", "sound");
1649 prefs_sound_themes_combo_box = win->theme.sound;
1651 /* Smiley Themes */
1652 prefs_build_theme_combo_box(win->theme.smiley, prefs_smiley_themes,
1653 PIDGIN_PREFS_ROOT "/smileys/theme",
1654 "smiley");
1655 prefs_smiley_themes_combo_box = win->theme.smiley;
1657 /* Custom sort so "none" theme is at top of list */
1658 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(prefs_smiley_themes),
1659 2, pidgin_sort_smileys, NULL, NULL);
1660 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(prefs_smiley_themes),
1661 2, GTK_SORT_ASCENDING);
1664 static void
1665 formatting_toggle_cb(TalkatuActionGroup *ag, GAction *action, const gchar *name, gpointer data)
1667 gboolean activated = talkatu_action_group_get_action_activated(ag, name);
1668 if(g_ascii_strcasecmp(TALKATU_ACTION_FORMAT_BOLD, name) != 0) {
1669 purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_bold",
1670 activated);
1671 } else if(g_ascii_strcasecmp(TALKATU_ACTION_FORMAT_ITALIC, name) != 0) {
1672 purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_italic",
1673 activated);
1674 } else if(g_ascii_strcasecmp(TALKATU_ACTION_FORMAT_UNDERLINE, name) != 0) {
1675 purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_underline",
1676 activated);
1677 } else if(g_ascii_strcasecmp(TALKATU_ACTION_FORMAT_STRIKETHROUGH, name) != 0) {
1678 purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/conversations/send_strike",
1679 activated);
1683 static void
1684 bind_interface_page(PidginPrefsWindow *win)
1686 GList *names = NULL;
1688 /* System Tray */
1689 win->iface.docklet.type = PURPLE_PREF_STRING;
1690 win->iface.docklet.key = PIDGIN_PREFS_ROOT "/docklet/show";
1691 pidgin_prefs_bind_dropdown(&win->iface.docklet);
1693 win->iface.im.hide_new.type = PURPLE_PREF_STRING;
1694 win->iface.im.hide_new.key = PIDGIN_PREFS_ROOT "/conversations/im/hide_new";
1695 pidgin_prefs_bind_dropdown(&win->iface.im.hide_new);
1697 #ifdef _WIN32
1698 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/win32/minimize_new_convs",
1699 win->iface.win32.minimize_new_convs);
1700 #else
1701 gtk_widget_hide(win->iface.win32.minimize_new_convs);
1702 #endif
1704 /* All the tab options! */
1705 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/tabs",
1706 win->iface.conversations.tabs);
1709 * Connect a signal to the above preference. When conversations are not
1710 * shown in a tabbed window then all tabbing options should be disabled.
1712 g_object_bind_property(win->iface.conversations.tabs, "active",
1713 win->iface.conversations.tabs_vbox, "sensitive",
1714 G_BINDING_SYNC_CREATE);
1716 pidgin_prefs_bind_checkbox(
1717 PIDGIN_PREFS_ROOT "/conversations/close_on_tabs",
1718 win->iface.conversations.close_on_tabs);
1720 win->iface.conversations.tab_side.type = PURPLE_PREF_INT;
1721 win->iface.conversations.tab_side.key = PIDGIN_PREFS_ROOT "/conversations/tab_side";
1722 pidgin_prefs_bind_dropdown(&win->iface.conversations.tab_side);
1724 win->iface.conversations.placement.type = PURPLE_PREF_STRING;
1725 win->iface.conversations.placement.key = PIDGIN_PREFS_ROOT "/conversations/placement";
1726 names = pidgin_conv_placement_get_options();
1727 pidgin_prefs_bind_dropdown_from_list(
1728 &win->iface.conversations.placement,
1729 names);
1730 g_list_free(names);
1733 /* This is also Win32-specific, but must be visible for Glade binding. */
1734 static void
1735 apply_custom_font(GtkWidget *unused, PidginPrefsWindow *win)
1737 PangoFontDescription *desc = NULL;
1738 if (!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/conversations/use_theme_font")) {
1739 const char *font = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/custom_font");
1740 desc = pango_font_description_from_string(font);
1743 gtk_widget_override_font(win->conversations.format_view, desc);
1744 if (desc)
1745 pango_font_description_free(desc);
1749 static void
1750 pidgin_custom_font_set(GtkWidget *font_button, PidginPrefsWindow *win)
1753 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/conversations/custom_font",
1754 gtk_font_chooser_get_font(GTK_FONT_CHOOSER(font_button)));
1756 apply_custom_font(font_button, win);
1759 static void
1760 bind_conv_page(PidginPrefsWindow *win)
1762 GSimpleActionGroup *ag = NULL;
1764 win->conversations.notification_chat.type = PURPLE_PREF_INT;
1765 win->conversations.notification_chat.key = PIDGIN_PREFS_ROOT "/conversations/notification_chat";
1766 pidgin_prefs_bind_dropdown(&win->conversations.notification_chat);
1768 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting",
1769 win->conversations.show_incoming_formatting);
1770 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/im/close_immediately",
1771 win->conversations.im.close_immediately);
1773 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/im/show_buddy_icons",
1774 win->conversations.im.show_buddy_icons);
1775 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/im/animate_buddy_icons",
1776 win->conversations.im.animate_buddy_icons);
1777 g_object_bind_property(win->conversations.im.show_buddy_icons, "active",
1778 win->conversations.im.animate_buddy_icons, "sensitive",
1779 G_BINDING_SYNC_CREATE);
1781 pidgin_prefs_bind_checkbox("/purple/conversations/im/send_typing",
1782 win->conversations.im.send_typing);
1783 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/spellcheck",
1784 win->conversations.spellcheck);
1786 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/conversations/use_smooth_scrolling",
1787 win->conversations.use_smooth_scrolling);
1789 #ifdef _WIN32
1790 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/win32/blink_im",
1791 win->conversations.win32.blink_im);
1792 #else
1793 gtk_widget_hide(win->conversations.win32.blink_im);
1794 #endif
1796 #if 0
1797 /* TODO: it's not implemented */
1798 pidgin_prefs_bind_checkbox(
1799 PIDGIN_PREFS_ROOT "/conversations/resize_custom_smileys",
1800 win->conversations.resize_custom_smileys);
1802 pidgin_prefs_bind_spin_button(
1803 PIDGIN_PREFS_ROOT "/conversations/custom_smileys_size",
1804 win->conversations.custom_smileys_size);
1806 g_object_bind_property(win->conversations.resize_custom_smileys, "active",
1807 win->conversations.custom_smileys_size, "sensitive",
1808 G_BINDING_SYNC_CREATE);
1809 #endif
1811 pidgin_prefs_bind_spin_button(
1812 PIDGIN_PREFS_ROOT "/conversations/minimum_entry_lines",
1813 win->conversations.minimum_entry_lines);
1815 #ifdef _WIN32
1817 const char *font_name;
1818 gtk_widget_show(win->conversations.font_frame);
1820 pidgin_prefs_bind_checkbox(
1821 PIDGIN_PREFS_ROOT "/conversations/use_theme_font",
1822 win->conversations.use_theme_font);
1824 font_name = purple_prefs_get_string(PIDGIN_PREFS_ROOT "/conversations/custom_font");
1825 if (font_name != NULL && *font_name != '\0') {
1826 gtk_font_chooser_set_font(
1827 GTK_FONT_CHOOSER(win->conversations.custom_font),
1828 font_name);
1831 g_object_bind_property(win->conversations.use_theme_font, "active",
1832 win->conversations.custom_font_hbox, "sensitive",
1833 G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
1835 #endif
1837 ag = talkatu_buffer_get_action_group(TALKATU_BUFFER(win->conversations.format_buffer));
1838 g_signal_connect_after(G_OBJECT(ag), "action-activated",
1839 G_CALLBACK(formatting_toggle_cb), NULL);
1842 static void
1843 network_ip_changed(GtkEntry *entry, gpointer data)
1845 const gchar *text = gtk_entry_get_text(entry);
1846 GtkStyleContext *context = gtk_widget_get_style_context(GTK_WIDGET(entry));
1848 if (text && *text) {
1849 if (g_hostname_is_ip_address(text)) {
1850 purple_network_set_public_ip(text);
1851 gtk_style_context_add_class(context, "good-ip");
1852 gtk_style_context_remove_class(context, "bad-ip");
1853 } else {
1854 gtk_style_context_add_class(context, "bad-ip");
1855 gtk_style_context_remove_class(context, "good-ip");
1858 } else {
1859 purple_network_set_public_ip("");
1860 gtk_style_context_remove_class(context, "bad-ip");
1861 gtk_style_context_remove_class(context, "good-ip");
1865 static gboolean
1866 network_stun_server_changed_cb(GtkWidget *widget,
1867 GdkEventFocus *event, gpointer data)
1869 GtkEntry *entry = GTK_ENTRY(widget);
1870 purple_prefs_set_string("/purple/network/stun_server",
1871 gtk_entry_get_text(entry));
1872 purple_network_set_stun_server(gtk_entry_get_text(entry));
1874 return FALSE;
1877 static gboolean
1878 network_turn_server_changed_cb(GtkWidget *widget,
1879 GdkEventFocus *event, gpointer data)
1881 GtkEntry *entry = GTK_ENTRY(widget);
1882 purple_prefs_set_string("/purple/network/turn_server",
1883 gtk_entry_get_text(entry));
1884 purple_network_set_turn_server(gtk_entry_get_text(entry));
1886 return FALSE;
1889 static void
1890 proxy_changed_cb(const char *name, PurplePrefType type,
1891 gconstpointer value, gpointer data)
1893 PidginPrefsWindow *win = data;
1894 const char *proxy = value;
1896 if (!purple_strequal(proxy, "none") && !purple_strequal(proxy, "envvar"))
1897 gtk_widget_show_all(win->proxy.options);
1898 else
1899 gtk_widget_hide(win->proxy.options);
1902 static void
1903 proxy_print_option(GtkWidget *entry, PidginPrefsWindow *win)
1905 if (entry == win->proxy.host) {
1906 purple_prefs_set_string("/purple/proxy/host",
1907 gtk_entry_get_text(GTK_ENTRY(entry)));
1908 } else if (entry == win->proxy.port) {
1909 purple_prefs_set_int("/purple/proxy/port",
1910 gtk_spin_button_get_value_as_int(
1911 GTK_SPIN_BUTTON(entry)));
1912 } else if (entry == win->proxy.username) {
1913 purple_prefs_set_string("/purple/proxy/username",
1914 gtk_entry_get_text(GTK_ENTRY(entry)));
1915 } else if (entry == win->proxy.password) {
1916 purple_prefs_set_string("/purple/proxy/password",
1917 gtk_entry_get_text(GTK_ENTRY(entry)));
1921 static void
1922 proxy_button_clicked_cb(GtkWidget *button, PidginPrefsWindow *win)
1924 GError *err = NULL;
1926 if (g_spawn_command_line_async(win->proxy.gnome_program_path, &err))
1927 return;
1929 purple_notify_error(NULL, NULL, _("Cannot start proxy configuration program."), err->message, NULL);
1930 g_error_free(err);
1933 static void
1934 browser_button_clicked_cb(GtkWidget *button, PidginPrefsWindow *win)
1936 GError *err = NULL;
1938 if (g_spawn_command_line_async(win->browser.gnome_program_path, &err))
1939 return;
1941 purple_notify_error(NULL, NULL, _("Cannot start browser configuration program."), err->message, NULL);
1942 g_error_free(err);
1945 static void
1946 auto_ip_button_clicked_cb(GtkWidget *button, gpointer null)
1948 const char *ip;
1949 PurpleStunNatDiscovery *stun;
1950 char *auto_ip_text;
1952 /* purple_network_get_my_ip will return the IP that was set by the user with
1953 purple_network_set_public_ip, so make a lookup for the auto-detected IP
1954 ourselves. */
1956 if (purple_prefs_get_bool("/purple/network/auto_ip")) {
1957 /* Check if STUN discovery was already done */
1958 stun = purple_stun_discover(NULL);
1959 if ((stun != NULL) && (stun->status == PURPLE_STUN_STATUS_DISCOVERED)) {
1960 ip = stun->publicip;
1961 } else {
1962 /* Attempt to get the IP from a NAT device using UPnP */
1963 ip = purple_upnp_get_public_ip();
1964 if (ip == NULL) {
1965 /* Attempt to get the IP from a NAT device using NAT-PMP */
1966 ip = purple_pmp_get_public_ip();
1967 if (ip == NULL) {
1968 /* Just fetch the IP of the local system */
1969 ip = purple_network_get_local_system_ip(-1);
1974 else
1975 ip = _("Disabled");
1977 auto_ip_text = g_strdup_printf(_("Use _automatically detected IP address: %s"), ip);
1978 gtk_button_set_label(GTK_BUTTON(button), auto_ip_text);
1979 g_free(auto_ip_text);
1982 static void
1983 bind_network_page(PidginPrefsWindow *win)
1985 GtkStyleContext *context;
1986 GtkCssProvider *ip_css;
1987 const gchar ip_style[] =
1988 ".bad-ip {"
1989 "color: @error_fg_color;"
1990 "text-shadow: 0 1px @error_text_shadow;"
1991 "background-image: none;"
1992 "background-color: @error_bg_color;"
1994 ".good-ip {"
1995 "color: @question_fg_color;"
1996 "text-shadow: 0 1px @question_text_shadow;"
1997 "background-image: none;"
1998 "background-color: @success_color;"
1999 "}";
2001 gtk_entry_set_text(GTK_ENTRY(win->network.stun_server),
2002 purple_prefs_get_string("/purple/network/stun_server"));
2004 pidgin_prefs_bind_checkbox("/purple/network/auto_ip",
2005 win->network.auto_ip);
2006 auto_ip_button_clicked_cb(win->network.auto_ip, NULL); /* Update label */
2008 gtk_entry_set_text(GTK_ENTRY(win->network.public_ip),
2009 purple_network_get_public_ip());
2011 ip_css = gtk_css_provider_new();
2012 gtk_css_provider_load_from_data(ip_css, ip_style, -1, NULL);
2013 context = gtk_widget_get_style_context(win->network.public_ip);
2014 gtk_style_context_add_provider(context,
2015 GTK_STYLE_PROVIDER(ip_css),
2016 GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
2018 g_object_bind_property(win->network.auto_ip, "active",
2019 win->network.public_ip_hbox, "sensitive",
2020 G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
2022 pidgin_prefs_bind_checkbox("/purple/network/map_ports",
2023 win->network.map_ports);
2025 pidgin_prefs_bind_checkbox("/purple/network/ports_range_use",
2026 win->network.ports_range_use);
2027 g_object_bind_property(win->network.ports_range_use, "active",
2028 win->network.ports_range_hbox, "sensitive",
2029 G_BINDING_SYNC_CREATE);
2031 pidgin_prefs_bind_spin_button("/purple/network/ports_range_start",
2032 win->network.ports_range_start);
2033 pidgin_prefs_bind_spin_button("/purple/network/ports_range_end",
2034 win->network.ports_range_end);
2036 /* TURN server */
2037 gtk_entry_set_text(GTK_ENTRY(win->network.turn_server),
2038 purple_prefs_get_string("/purple/network/turn_server"));
2040 pidgin_prefs_bind_spin_button("/purple/network/turn_port",
2041 win->network.turn_port_udp);
2043 pidgin_prefs_bind_spin_button("/purple/network/turn_port_tcp",
2044 win->network.turn_port_tcp);
2046 pidgin_prefs_bind_entry("/purple/network/turn_username",
2047 win->network.turn_username);
2048 pidgin_prefs_bind_entry("/purple/network/turn_password",
2049 win->network.turn_password);
2052 static gboolean
2053 manual_browser_set(GtkWidget *entry, GdkEventFocus *event, gpointer data)
2055 const char *program = gtk_entry_get_text(GTK_ENTRY(entry));
2057 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/browsers/manual_command", program);
2059 /* carry on normally */
2060 return FALSE;
2063 #ifndef _WIN32
2064 static GList *
2065 get_available_browsers(void)
2067 struct browser {
2068 char *name;
2069 char *command;
2072 /* Sorted reverse alphabetically */
2073 static const struct browser possible_browsers[] = {
2074 {N_("Seamonkey"), "seamonkey"},
2075 {N_("Opera"), "opera"},
2076 {N_("Mozilla"), "mozilla"},
2077 {N_("Konqueror"), "kfmclient"},
2078 {N_("Google Chrome"), "google-chrome"},
2079 /* Do not move the line below. Code below expects gnome-open to be in
2080 * this list immediately after xdg-open! */
2081 {N_("Desktop Default"), "xdg-open"},
2082 {N_("GNOME Default"), "gnome-open"},
2083 {N_("Galeon"), "galeon"},
2084 {N_("Firefox"), "firefox"},
2085 {N_("Firebird"), "mozilla-firebird"},
2086 {N_("Epiphany"), "epiphany"},
2087 /* Translators: please do not translate "chromium-browser" here! */
2088 {N_("Chromium (chromium-browser)"), "chromium-browser"},
2089 /* Translators: please do not translate "chrome" here! */
2090 {N_("Chromium (chrome)"), "chrome"}
2092 static const int num_possible_browsers = G_N_ELEMENTS(possible_browsers);
2094 GList *browsers = NULL;
2095 int i = 0;
2096 char *browser_setting = (char *)purple_prefs_get_string(PIDGIN_PREFS_ROOT "/browsers/browser");
2098 browsers = g_list_prepend(browsers, (gpointer)"custom");
2099 browsers = g_list_prepend(browsers, (gpointer)_("Manual"));
2101 for (i = 0; i < num_possible_browsers; i++) {
2102 if (purple_program_is_valid(possible_browsers[i].command)) {
2103 browsers = g_list_prepend(browsers,
2104 possible_browsers[i].command);
2105 browsers = g_list_prepend(browsers, (gpointer)_(possible_browsers[i].name));
2106 if(browser_setting && purple_strequal(possible_browsers[i].command, browser_setting))
2107 browser_setting = NULL;
2108 /* If xdg-open is valid, prefer it over gnome-open and skip forward */
2109 if(purple_strequal(possible_browsers[i].command, "xdg-open")) {
2110 if (purple_strequal("gnome-open", browser_setting)) {
2111 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/browsers/browser", possible_browsers[i].command);
2112 browser_setting = NULL;
2114 i++;
2119 if(browser_setting)
2120 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/browsers/browser", "custom");
2122 return browsers;
2125 static void
2126 browser_changed1_cb(const char *name, PurplePrefType type,
2127 gconstpointer value, gpointer data)
2129 GtkWidget *hbox = data;
2130 const char *browser = value;
2132 gtk_widget_set_sensitive(hbox, !purple_strequal(browser, "custom"));
2135 static void
2136 browser_changed2_cb(const char *name, PurplePrefType type,
2137 gconstpointer value, gpointer data)
2139 GtkWidget *hbox = data;
2140 const char *browser = value;
2142 gtk_widget_set_sensitive(hbox, purple_strequal(browser, "custom"));
2144 #endif /* _WIN32 */
2146 static void
2147 bind_browser_page(PidginPrefsWindow *win)
2149 #ifdef _WIN32
2150 /* We use the registered default browser in windows */
2151 gtk_widget_hide(win->browser.page);
2152 return;
2153 #else
2154 /* if the user is running Mac OS X, hide the browsers tab */
2155 if (purple_running_osx()) {
2156 gtk_widget_hide(win->browser.page);
2157 } else if (purple_running_gnome()) {
2158 gchar *path;
2160 gtk_stack_set_visible_child_name(GTK_STACK(win->browser.stack),
2161 "gnome");
2163 path = g_find_program_in_path("gnome-control-center");
2164 if (path != NULL) {
2165 gchar *tmp = g_strdup_printf("%s info", path);
2166 g_free(path);
2167 path = tmp;
2168 } else {
2169 path = g_find_program_in_path("gnome-default-applications-properties");
2172 win->browser.gnome_program_path = path;
2173 gtk_widget_set_visible(win->browser.gnome_not_found,
2174 path == NULL);
2175 gtk_widget_set_visible(win->browser.gnome_program,
2176 path != NULL);
2177 } else {
2178 GList *browsers = NULL;
2180 gtk_stack_set_visible_child_name(GTK_STACK(win->browser.stack),
2181 "nongnome");
2183 win->browser.browser.type = PURPLE_PREF_STRING;
2184 win->browser.browser.key = PIDGIN_PREFS_ROOT "/browsers/browser";
2185 browsers = get_available_browsers();
2186 pidgin_prefs_bind_dropdown_from_list(
2187 &win->browser.browser,
2188 browsers);
2189 g_list_free(browsers);
2191 win->browser.place.type = PURPLE_PREF_INT;
2192 win->browser.place.key = PIDGIN_PREFS_ROOT "/browsers/place";
2193 pidgin_prefs_bind_dropdown(&win->browser.place);
2195 purple_prefs_connect_callback(prefs,
2196 PIDGIN_PREFS_ROOT "/browsers/browser",
2197 browser_changed1_cb,
2198 win->browser.place_hbox);
2200 gtk_entry_set_text(GTK_ENTRY(win->browser.manual_command),
2201 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/browsers/manual_command"));
2202 purple_prefs_connect_callback(prefs,
2203 PIDGIN_PREFS_ROOT "/browsers/browser",
2204 browser_changed2_cb,
2205 win->browser.manual_command_hbox);
2207 if (purple_strequal(
2208 purple_prefs_get_string(
2209 PIDGIN_PREFS_ROOT "/browsers/browser"),
2210 "custom")) {
2211 gtk_widget_set_sensitive(win->browser.place_hbox,
2212 FALSE);
2213 } else {
2214 gtk_widget_set_sensitive(win->browser.manual_command_hbox,
2215 FALSE);
2218 #endif /* _WIN32 */
2221 static void
2222 bind_proxy_page(PidginPrefsWindow *win)
2224 PurpleProxyInfo *proxy_info;
2226 if(purple_running_gnome()) {
2227 gchar *path = NULL;
2229 gtk_stack_set_visible_child_name(GTK_STACK(win->proxy.stack),
2230 "gnome");
2232 path = g_find_program_in_path("gnome-network-properties");
2233 if (path == NULL)
2234 path = g_find_program_in_path("gnome-network-preferences");
2235 if (path == NULL) {
2236 path = g_find_program_in_path("gnome-control-center");
2237 if (path != NULL) {
2238 char *tmp = g_strdup_printf("%s network", path);
2239 g_free(path);
2240 path = tmp;
2244 win->proxy.gnome_program_path = path;
2245 gtk_widget_set_visible(win->proxy.gnome_not_found,
2246 path == NULL);
2247 gtk_widget_set_visible(win->proxy.gnome_program,
2248 path != NULL);
2249 } else {
2250 gtk_stack_set_visible_child_name(GTK_STACK(win->proxy.stack),
2251 "nongnome");
2253 /* This is a global option that affects SOCKS4 usage even with
2254 * account-specific proxy settings */
2255 pidgin_prefs_bind_checkbox("/purple/proxy/socks4_remotedns",
2256 win->proxy.socks4_remotedns);
2258 win->proxy.type.type = PURPLE_PREF_STRING;
2259 win->proxy.type.key = "/purple/proxy/type";
2260 pidgin_prefs_bind_dropdown(&win->proxy.type);
2261 proxy_info = purple_global_proxy_get_info();
2263 purple_prefs_connect_callback(prefs, "/purple/proxy/type",
2264 proxy_changed_cb, win);
2266 if (proxy_info != NULL) {
2267 if (purple_proxy_info_get_host(proxy_info)) {
2268 gtk_entry_set_text(GTK_ENTRY(win->proxy.host),
2269 purple_proxy_info_get_host(proxy_info));
2272 if (purple_proxy_info_get_port(proxy_info) != 0) {
2273 gtk_spin_button_set_value(
2274 GTK_SPIN_BUTTON(win->proxy.port),
2275 purple_proxy_info_get_port(proxy_info));
2278 if (purple_proxy_info_get_username(proxy_info) != NULL) {
2279 gtk_entry_set_text(GTK_ENTRY(win->proxy.username),
2280 purple_proxy_info_get_username(proxy_info));
2283 if (purple_proxy_info_get_password(proxy_info) != NULL) {
2284 gtk_entry_set_text(GTK_ENTRY(win->proxy.password),
2285 purple_proxy_info_get_password(proxy_info));
2289 proxy_changed_cb("/purple/proxy/type", PURPLE_PREF_STRING,
2290 purple_prefs_get_string("/purple/proxy/type"),
2291 win);
2295 static void
2296 bind_logging_page(PidginPrefsWindow *win)
2298 GList *names;
2300 win->logging.format.type = PURPLE_PREF_STRING;
2301 win->logging.format.key = "/purple/logging/format";
2302 names = purple_log_logger_get_options();
2303 pidgin_prefs_bind_dropdown_from_list(&win->logging.format, names);
2304 g_list_free(names);
2306 pidgin_prefs_bind_checkbox("/purple/logging/log_ims",
2307 win->logging.log_ims);
2308 pidgin_prefs_bind_checkbox("/purple/logging/log_chats",
2309 win->logging.log_chats);
2310 pidgin_prefs_bind_checkbox("/purple/logging/log_system",
2311 win->logging.log_system);
2314 /*** keyring page *******************************************************/
2316 static void
2317 keyring_page_settings_changed(GtkWidget *widget, gpointer _setting)
2319 PurpleRequestField *setting = _setting;
2320 PurpleRequestFieldType field_type;
2322 gtk_widget_set_sensitive(prefs->keyring.apply, TRUE);
2324 field_type = purple_request_field_get_field_type(setting);
2326 if (field_type == PURPLE_REQUEST_FIELD_BOOLEAN) {
2327 purple_request_field_bool_set_value(setting,
2328 gtk_toggle_button_get_active(
2329 GTK_TOGGLE_BUTTON(widget)));
2330 } else if (field_type == PURPLE_REQUEST_FIELD_STRING) {
2331 purple_request_field_string_set_value(setting,
2332 gtk_entry_get_text(GTK_ENTRY(widget)));
2333 } else if (field_type == PURPLE_REQUEST_FIELD_INTEGER) {
2334 purple_request_field_int_set_value(setting,
2335 gtk_spin_button_get_value_as_int(
2336 GTK_SPIN_BUTTON(widget)));
2337 } else
2338 g_return_if_reached();
2341 static void
2342 keyring_page_add_settings_field(GtkBox *vbox, PurpleRequestField *setting,
2343 GtkSizeGroup *sg)
2345 GtkWidget *widget;
2346 PurpleRequestFieldType field_type;
2347 const gchar *label;
2349 label = purple_request_field_get_label(setting);
2351 field_type = purple_request_field_get_field_type(setting);
2352 if (field_type == PURPLE_REQUEST_FIELD_BOOLEAN) {
2353 widget = gtk_check_button_new_with_label(label);
2354 label = NULL;
2355 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
2356 purple_request_field_bool_get_value(setting));
2357 g_signal_connect(G_OBJECT(widget), "toggled",
2358 G_CALLBACK(keyring_page_settings_changed), setting);
2359 } else if (field_type == PURPLE_REQUEST_FIELD_STRING) {
2360 widget = gtk_entry_new();
2361 gtk_entry_set_text(GTK_ENTRY(widget),
2362 purple_request_field_string_get_value(setting));
2363 if (purple_request_field_string_is_masked(setting))
2364 gtk_entry_set_visibility(GTK_ENTRY(widget), FALSE);
2365 g_signal_connect(G_OBJECT(widget), "changed",
2366 G_CALLBACK(keyring_page_settings_changed), setting);
2367 } else if (field_type == PURPLE_REQUEST_FIELD_INTEGER) {
2368 widget = gtk_spin_button_new_with_range(
2369 purple_request_field_int_get_lower_bound(setting),
2370 purple_request_field_int_get_upper_bound(setting), 1);
2371 gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),
2372 purple_request_field_int_get_value(setting));
2373 g_signal_connect(G_OBJECT(widget), "value-changed",
2374 G_CALLBACK(keyring_page_settings_changed), setting);
2375 } else {
2376 purple_debug_error("gtkprefs", "Unsupported field type\n");
2377 return;
2380 pidgin_add_widget_to_vbox(vbox, label, sg, widget, FALSE, NULL);
2383 /* XXX: it could be available for all plugins, not keyrings only */
2384 static void
2385 keyring_page_add_settings(PidginPrefsWindow *win)
2387 GtkWidget *box;
2388 GList *it, *groups;
2389 GtkSizeGroup *sg;
2391 box = gtk_box_new(GTK_ORIENTATION_VERTICAL, PIDGIN_HIG_BOX_SPACE);
2392 gtk_box_pack_start(GTK_BOX(win->keyring.vbox), box, FALSE, FALSE, 0);
2394 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2396 groups = purple_request_fields_get_groups(win->keyring.settings);
2397 for (it = g_list_first(groups); it != NULL; it = g_list_next(it)) {
2398 GList *it2, *fields;
2399 GtkBox *vbox;
2400 PurpleRequestFieldGroup *group;
2401 const gchar *group_title;
2403 group = it->data;
2404 group_title = purple_request_field_group_get_title(group);
2405 if (group_title) {
2406 vbox = GTK_BOX(pidgin_make_frame(box, group_title));
2407 } else {
2408 vbox = GTK_BOX(box);
2411 fields = purple_request_field_group_get_fields(group);
2412 for (it2 = g_list_first(fields); it2 != NULL;
2413 it2 = g_list_next(it2)) {
2414 keyring_page_add_settings_field(vbox, it2->data, sg);
2418 g_object_unref(sg);
2420 win->keyring.settings_box = box;
2423 static void
2424 keyring_page_settings_apply(GtkButton *button, gpointer data)
2426 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
2428 if (!purple_keyring_apply_settings(win, win->keyring.settings)) {
2429 return;
2432 gtk_widget_set_sensitive(win->keyring.apply, FALSE);
2435 static void
2436 keyring_page_update_settings(PidginPrefsWindow *win)
2438 g_clear_pointer(&win->keyring.settings, purple_request_fields_destroy);
2439 win->keyring.settings = purple_keyring_read_settings();
2440 if (!win->keyring.settings) {
2441 return;
2444 keyring_page_add_settings(win);
2446 win->keyring.apply = gtk_button_new_with_mnemonic(_("_Apply"));
2447 gtk_box_pack_start(GTK_BOX(win->keyring.settings_box),
2448 win->keyring.apply, FALSE, FALSE, 1);
2449 gtk_widget_set_sensitive(win->keyring.apply, FALSE);
2450 g_signal_connect(G_OBJECT(win->keyring.apply), "clicked",
2451 G_CALLBACK(keyring_page_settings_apply), win);
2453 gtk_widget_show_all(win->keyring.settings_box);
2456 static void
2457 keyring_page_pref_set_inuse(GError *error, G_GNUC_UNUSED gpointer unused)
2459 PurpleKeyring *in_use = purple_keyring_get_inuse();
2461 if (prefs == NULL) {
2462 purple_debug_info("gtkprefs", "pref window already closed\n");
2463 return;
2466 gtk_widget_set_sensitive(GTK_WIDGET(prefs->keyring.active.combo), TRUE);
2468 if (error != NULL) {
2469 pidgin_prefs_bind_dropdown_revert_active(
2470 &prefs->keyring.active);
2471 purple_notify_error(NULL, _("Keyring"),
2472 _("Failed to set new keyring"), error->message, NULL);
2473 return;
2476 g_return_if_fail(in_use != NULL);
2477 purple_prefs_set_string("/purple/keyring/active",
2478 purple_keyring_get_id(in_use));
2480 keyring_page_update_settings(prefs);
2483 static void
2484 keyring_page_pref_changed(GtkComboBox *combo_box, PidginPrefCombo *combo)
2486 const char *keyring_id;
2487 PurpleKeyring *keyring;
2489 g_return_if_fail(combo_box != NULL);
2491 keyring_id = combo->value.string;
2492 keyring = purple_keyring_find_keyring_by_id(keyring_id);
2493 if (keyring == NULL) {
2494 pidgin_prefs_bind_dropdown_revert_active(combo);
2495 purple_notify_error(NULL, _("Keyring"),
2496 _("Selected keyring is disabled"), NULL, NULL);
2497 return;
2500 gtk_widget_set_sensitive(GTK_WIDGET(combo_box), FALSE);
2502 g_clear_pointer(&prefs->keyring.settings_box, gtk_widget_destroy);
2503 g_clear_pointer(&prefs->keyring.settings,
2504 purple_request_fields_destroy);
2506 purple_keyring_set_inuse(keyring, FALSE, keyring_page_pref_set_inuse,
2507 NULL);
2510 static void
2511 keyring_page_cleanup(PidginPrefsWindow *win)
2513 g_clear_pointer(&win->keyring.settings, purple_request_fields_destroy);
2516 static void
2517 bind_keyring_page(PidginPrefsWindow *win)
2519 GList *names;
2521 /* Keyring selection */
2522 names = purple_keyring_get_options();
2523 win->keyring.active.type = PURPLE_PREF_STRING;
2524 win->keyring.active.key = "/purple/keyring/active";
2525 pidgin_prefs_bind_dropdown_from_list(&win->keyring.active, names);
2526 /* Override the usual callback to defer changing the pref. */
2527 win->keyring.active.cb = keyring_page_pref_changed;
2528 g_list_free(names);
2530 keyring_page_update_settings(win);
2533 /*** keyring page - end *************************************************/
2535 static gboolean
2536 sound_method_filter(GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
2538 gboolean any = FALSE;
2539 gboolean gstreamer = FALSE;
2540 gboolean win32 = FALSE;
2542 gtk_tree_model_get(model, iter, 2, &any, 3, &gstreamer, 4, &win32, -1);
2544 if (any) {
2545 return TRUE;
2548 if (gstreamer) {
2549 #ifdef USE_GSTREAMER
2550 #ifdef _WIN32
2551 return win32;
2552 #else
2553 return !win32;
2554 #endif
2555 #else
2556 return FALSE;
2557 #endif
2560 #ifdef _WIN32
2561 return win32;
2562 #else
2563 return !win32;
2564 #endif
2567 static gint
2568 sound_cmd_yeah(GtkEntry *entry, gpointer d)
2570 purple_prefs_set_path(PIDGIN_PREFS_ROOT "/sound/command",
2571 gtk_entry_get_text(GTK_ENTRY(entry)));
2572 return TRUE;
2575 static void
2576 sound_changed1_cb(const char *name, PurplePrefType type,
2577 gconstpointer value, gpointer data)
2579 GtkWidget *hbox = data;
2580 const char *method = value;
2582 gtk_widget_set_sensitive(hbox, purple_strequal(method, "custom"));
2585 static void
2586 sound_changed2_cb(const char *name, PurplePrefType type,
2587 gconstpointer value, gpointer data)
2589 GtkWidget *vbox = data;
2590 const char *method = value;
2592 gtk_widget_set_sensitive(vbox, !purple_strequal(method, "none"));
2596 static void
2597 event_toggled(GtkCellRendererToggle *cell, gchar *pth, gpointer data)
2599 GtkTreeModel *model = (GtkTreeModel *)data;
2600 GtkTreeIter iter;
2601 GtkTreePath *path = gtk_tree_path_new_from_string(pth);
2602 char *pref;
2604 gtk_tree_model_get_iter (model, &iter, path);
2605 gtk_tree_model_get (model, &iter,
2606 2, &pref,
2607 -1);
2609 purple_prefs_set_bool(pref, !gtk_cell_renderer_toggle_get_active(cell));
2610 g_free(pref);
2612 gtk_list_store_set(GTK_LIST_STORE (model), &iter,
2613 0, !gtk_cell_renderer_toggle_get_active(cell),
2614 -1);
2616 gtk_tree_path_free(path);
2619 static void
2620 test_sound(GtkWidget *button, gpointer i_am_NULL)
2622 char *pref;
2623 gboolean temp_enabled;
2624 gboolean temp_mute;
2626 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/enabled/%s",
2627 pidgin_sound_get_event_option(sound_row_sel));
2629 temp_enabled = purple_prefs_get_bool(pref);
2630 temp_mute = purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/sound/mute");
2632 if (!temp_enabled) purple_prefs_set_bool(pref, TRUE);
2633 if (temp_mute) purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/sound/mute", FALSE);
2635 purple_sound_play_event(sound_row_sel, NULL);
2637 if (!temp_enabled) purple_prefs_set_bool(pref, FALSE);
2638 if (temp_mute) purple_prefs_set_bool(PIDGIN_PREFS_ROOT "/sound/mute", TRUE);
2640 g_free(pref);
2644 * Resets a sound file back to default.
2646 static void
2647 reset_sound(GtkWidget *button, gpointer data)
2649 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
2650 gchar *pref;
2652 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
2653 pidgin_sound_get_event_option(sound_row_sel));
2654 purple_prefs_set_path(pref, "");
2655 g_free(pref);
2657 gtk_entry_set_text(GTK_ENTRY(win->sound.entry), _("(default)"));
2659 pref_sound_generate_markup();
2662 static void
2663 sound_chosen_cb(void *user_data, const char *filename)
2665 gchar *pref;
2666 int sound;
2668 sound = GPOINTER_TO_INT(user_data);
2670 /* Set it -- and forget it */
2671 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
2672 pidgin_sound_get_event_option(sound));
2673 purple_prefs_set_path(pref, filename);
2674 g_free(pref);
2677 * If the sound we just changed is still the currently selected
2678 * sound, then update the box showing the file name.
2680 if (sound == sound_row_sel)
2681 gtk_entry_set_text(GTK_ENTRY(prefs->sound.entry), filename);
2683 pref_sound_generate_markup();
2686 static void
2687 select_sound(GtkWidget *button, gpointer being_NULL_is_fun)
2689 gchar *pref;
2690 const char *filename;
2692 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
2693 pidgin_sound_get_event_option(sound_row_sel));
2694 filename = purple_prefs_get_path(pref);
2695 g_free(pref);
2697 if (*filename == '\0')
2698 filename = NULL;
2700 purple_request_file(prefs, _("Sound Selection"), filename, FALSE,
2701 G_CALLBACK(sound_chosen_cb), NULL, NULL,
2702 GINT_TO_POINTER(sound_row_sel));
2705 static void
2706 prefs_sound_sel(GtkTreeSelection *sel, gpointer data)
2708 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
2709 GtkTreeModel *model;
2710 GtkTreeIter iter;
2711 GValue val;
2712 const char *file;
2713 char *pref;
2715 if (! gtk_tree_selection_get_selected (sel, &model, &iter))
2716 return;
2718 val.g_type = 0;
2719 gtk_tree_model_get_value (model, &iter, 3, &val);
2720 sound_row_sel = g_value_get_uint(&val);
2722 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
2723 pidgin_sound_get_event_option(sound_row_sel));
2724 file = purple_prefs_get_path(pref);
2725 g_free(pref);
2726 if (win->sound.entry) {
2727 gtk_entry_set_text(GTK_ENTRY(win->sound.entry),
2728 (file && *file != '\0') ? file
2729 : _("(default)"));
2731 g_value_unset (&val);
2733 pref_sound_generate_markup();
2736 static void
2737 bind_sound_page(PidginPrefsWindow *win)
2739 GtkTreeModel *model;
2740 GtkTreeSelection *sel;
2741 GtkTreePath *path;
2742 int j;
2743 const char *file;
2744 char *pref;
2745 const char *cmd;
2747 win->sound.method.type = PURPLE_PREF_STRING;
2748 win->sound.method.key = PIDGIN_PREFS_ROOT "/sound/method";
2749 pidgin_prefs_bind_dropdown(&win->sound.method);
2750 model = gtk_combo_box_get_model(GTK_COMBO_BOX(win->sound.method.combo));
2751 gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(model), sound_method_filter, NULL, NULL);
2752 gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(model));
2754 gtk_widget_set_sensitive(
2755 win->sound.method_vbox,
2756 !purple_strequal(purple_prefs_get_string(PIDGIN_PREFS_ROOT
2757 "/sound/method"),
2758 "none"));
2759 purple_prefs_connect_callback(prefs, PIDGIN_PREFS_ROOT "/sound/method",
2760 sound_changed2_cb,
2761 win->sound.method_vbox);
2763 gtk_widget_set_sensitive(
2764 win->sound.command_hbox,
2765 purple_strequal(purple_prefs_get_string(PIDGIN_PREFS_ROOT
2766 "/sound/method"),
2767 "custom"));
2768 purple_prefs_connect_callback(prefs, PIDGIN_PREFS_ROOT "/sound/method",
2769 sound_changed1_cb,
2770 win->sound.command_hbox);
2772 cmd = purple_prefs_get_path(PIDGIN_PREFS_ROOT "/sound/command");
2773 if (cmd) {
2774 gtk_entry_set_text(GTK_ENTRY(win->sound.command), cmd);
2777 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/sound/mute",
2778 win->sound.mute);
2780 pidgin_prefs_bind_checkbox(PIDGIN_PREFS_ROOT "/sound/conv_focus",
2781 win->sound.conv_focus);
2783 win->sound.while_status.type = PURPLE_PREF_INT;
2784 win->sound.while_status.key = "/purple/sound/while_status";
2785 pidgin_prefs_bind_dropdown(&win->sound.while_status);
2787 /* SOUND SELECTION */
2788 for (j=0; j < PURPLE_NUM_SOUNDS; j++) {
2789 char *pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/enabled/%s",
2790 pidgin_sound_get_event_option(j));
2791 const char *label = pidgin_sound_get_event_label(j);
2792 GtkTreeIter iter;
2794 if (label == NULL) {
2795 g_free(pref);
2796 continue;
2799 gtk_list_store_append(win->sound.event.store, &iter);
2800 gtk_list_store_set(win->sound.event.store, &iter,
2801 0, purple_prefs_get_bool(pref),
2802 1, _(label),
2803 2, pref,
2804 3, j,
2805 -1);
2806 g_free(pref);
2809 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(win->sound.event.view));
2810 path = gtk_tree_path_new_first();
2811 gtk_tree_selection_select_path(sel, path);
2812 gtk_tree_path_free(path);
2814 pref = g_strdup_printf(PIDGIN_PREFS_ROOT "/sound/file/%s",
2815 pidgin_sound_get_event_option(0));
2816 file = purple_prefs_get_path(pref);
2817 g_free(pref);
2818 gtk_entry_set_text(GTK_ENTRY(win->sound.entry),
2819 (file && *file != '\0') ? file : _("(default)"));
2823 static void
2824 set_idle_away(PurpleSavedStatus *status)
2826 purple_prefs_set_int("/purple/savedstatus/idleaway", purple_savedstatus_get_creation_time(status));
2829 static void
2830 set_startupstatus(PurpleSavedStatus *status)
2832 purple_prefs_set_int("/purple/savedstatus/startup", purple_savedstatus_get_creation_time(status));
2835 static void
2836 bind_away_page(PidginPrefsWindow *win)
2838 GtkWidget *menu;
2840 /* Idle stuff */
2841 win->away.idle_reporting.type = PURPLE_PREF_STRING;
2842 win->away.idle_reporting.key = "/purple/away/idle_reporting";
2843 pidgin_prefs_bind_dropdown(&win->away.idle_reporting);
2845 pidgin_prefs_bind_spin_button("/purple/away/mins_before_away",
2846 win->away.mins_before_away);
2848 pidgin_prefs_bind_checkbox("/purple/away/away_when_idle",
2849 win->away.away_when_idle);
2851 /* TODO: Show something useful if we don't have any saved statuses. */
2852 menu = pidgin_status_menu(purple_savedstatus_get_idleaway(), G_CALLBACK(set_idle_away));
2853 gtk_widget_show_all(menu);
2854 gtk_box_pack_start(GTK_BOX(win->away.idle_hbox), menu, FALSE, FALSE, 0);
2856 g_object_bind_property(win->away.away_when_idle, "active",
2857 menu, "sensitive",
2858 G_BINDING_SYNC_CREATE);
2860 /* Away stuff */
2861 win->away.auto_reply.type = PURPLE_PREF_STRING;
2862 win->away.auto_reply.key = "/purple/away/auto_reply";
2863 pidgin_prefs_bind_dropdown(&win->away.auto_reply);
2865 /* Signon status stuff */
2866 pidgin_prefs_bind_checkbox("/purple/savedstatus/startup_current_status",
2867 win->away.startup_current_status);
2869 /* TODO: Show something useful if we don't have any saved statuses. */
2870 menu = pidgin_status_menu(purple_savedstatus_get_startup(), G_CALLBACK(set_startupstatus));
2871 gtk_widget_show_all(menu);
2872 gtk_box_pack_start(GTK_BOX(win->away.startup_hbox), menu, FALSE, FALSE, 0);
2873 gtk_label_set_mnemonic_widget(GTK_LABEL(win->away.startup_label), menu);
2874 pidgin_set_accessible_label(menu, GTK_LABEL(win->away.startup_label));
2875 g_object_bind_property(win->away.startup_current_status, "active",
2876 win->away.startup_hbox, "sensitive",
2877 G_BINDING_SYNC_CREATE|G_BINDING_INVERT_BOOLEAN);
2880 #ifdef USE_VV
2881 static GList *
2882 get_vv_device_menuitems(PurpleMediaElementType type)
2884 GList *result = NULL;
2885 GList *i;
2887 i = purple_media_manager_enumerate_elements(purple_media_manager_get(),
2888 type);
2889 for (; i; i = g_list_delete_link(i, i)) {
2890 PurpleMediaElementInfo *info = i->data;
2892 result = g_list_append(result,
2893 purple_media_element_info_get_name(info));
2894 result = g_list_append(result,
2895 purple_media_element_info_get_id(info));
2896 g_object_unref(info);
2899 return result;
2902 static GstElement *
2903 create_test_element(PurpleMediaElementType type)
2905 PurpleMediaElementInfo *element_info;
2907 element_info = purple_media_manager_get_active_element(purple_media_manager_get(), type);
2909 g_return_val_if_fail(element_info, NULL);
2911 return purple_media_element_info_call_create(element_info,
2912 NULL, NULL, NULL);
2915 static void
2916 vv_test_switch_page_cb(GtkStack *stack, G_GNUC_UNUSED GParamSpec *pspec,
2917 gpointer data)
2919 PidginPrefsWindow *win = data;
2921 if (!g_str_equal(gtk_stack_get_visible_child_name(stack), "vv")) {
2922 /* Disable any running test pipelines. */
2923 gtk_toggle_button_set_active(
2924 GTK_TOGGLE_BUTTON(win->vv.voice.test), FALSE);
2925 gtk_toggle_button_set_active(
2926 GTK_TOGGLE_BUTTON(win->vv.video.test), FALSE);
2930 static GstElement *
2931 create_voice_pipeline(void)
2933 GstElement *pipeline;
2934 GstElement *src, *sink;
2935 GstElement *volume;
2936 GstElement *level;
2937 GstElement *valve;
2939 pipeline = gst_pipeline_new("voicetest");
2941 src = create_test_element(PURPLE_MEDIA_ELEMENT_AUDIO | PURPLE_MEDIA_ELEMENT_SRC);
2942 sink = create_test_element(PURPLE_MEDIA_ELEMENT_AUDIO | PURPLE_MEDIA_ELEMENT_SINK);
2943 volume = gst_element_factory_make("volume", "volume");
2944 level = gst_element_factory_make("level", "level");
2945 valve = gst_element_factory_make("valve", "valve");
2947 gst_bin_add_many(GST_BIN(pipeline), src, volume, level, valve, sink, NULL);
2948 gst_element_link_many(src, volume, level, valve, sink, NULL);
2950 purple_debug_info("gtkprefs", "create_voice_pipeline: setting pipeline "
2951 "state to GST_STATE_PLAYING - it may hang here on win32\n");
2952 gst_element_set_state(GST_ELEMENT(pipeline), GST_STATE_PLAYING);
2953 purple_debug_info("gtkprefs", "create_voice_pipeline: state is set\n");
2955 return pipeline;
2958 static void
2959 on_volume_change_cb(GtkWidget *w, gdouble value, gpointer data)
2961 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
2962 GstElement *volume;
2964 if (!win->vv.voice.pipeline) {
2965 return;
2968 volume = gst_bin_get_by_name(GST_BIN(win->vv.voice.pipeline), "volume");
2969 g_object_set(volume, "volume",
2970 gtk_scale_button_get_value(GTK_SCALE_BUTTON(w)) * 10.0, NULL);
2973 static gdouble
2974 gst_msg_db_to_percent(GstMessage *msg, gchar *value_name)
2976 const GValue *list;
2977 const GValue *value;
2978 gdouble value_db;
2979 gdouble percent;
2981 list = gst_structure_get_value(gst_message_get_structure(msg), value_name);
2982 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
2983 value = g_value_array_get_nth(g_value_get_boxed(list), 0);
2984 G_GNUC_END_IGNORE_DEPRECATIONS
2985 value_db = g_value_get_double(value);
2986 percent = pow(10, value_db / 20);
2987 return (percent > 1.0) ? 1.0 : percent;
2990 static gboolean
2991 gst_bus_cb(GstBus *bus, GstMessage *msg, gpointer data)
2993 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
2995 if (GST_MESSAGE_TYPE(msg) == GST_MESSAGE_ELEMENT &&
2996 gst_structure_has_name(gst_message_get_structure(msg), "level")) {
2998 GstElement *src = GST_ELEMENT(GST_MESSAGE_SRC(msg));
2999 gchar *name = gst_element_get_name(src);
3001 if (purple_strequal(name, "level")) {
3002 gdouble percent;
3003 gdouble threshold;
3004 GstElement *valve;
3006 percent = gst_msg_db_to_percent(msg, "rms");
3007 gtk_progress_bar_set_fraction(
3008 GTK_PROGRESS_BAR(win->vv.voice.level), percent);
3010 percent = gst_msg_db_to_percent(msg, "decay");
3011 threshold = gtk_range_get_value(GTK_RANGE(
3012 win->vv.voice.threshold)) /
3013 100.0;
3014 valve = gst_bin_get_by_name(GST_BIN(GST_ELEMENT_PARENT(src)), "valve");
3015 g_object_set(valve, "drop", (percent < threshold), NULL);
3016 g_object_set(win->vv.voice.level, "text",
3017 (percent < threshold) ? _("DROP") : " ",
3018 NULL);
3021 g_free(name);
3024 return TRUE;
3027 static void
3028 voice_test_destroy_cb(GtkWidget *w, gpointer data)
3030 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
3032 if (!win->vv.voice.pipeline) {
3033 return;
3036 gst_element_set_state(win->vv.voice.pipeline, GST_STATE_NULL);
3037 g_clear_pointer(&win->vv.voice.pipeline, gst_object_unref);
3040 static void
3041 enable_voice_test(PidginPrefsWindow *win)
3043 GstBus *bus;
3045 win->vv.voice.pipeline = create_voice_pipeline();
3046 bus = gst_pipeline_get_bus(GST_PIPELINE(win->vv.voice.pipeline));
3047 gst_bus_add_signal_watch(bus);
3048 g_signal_connect(bus, "message", G_CALLBACK(gst_bus_cb), win);
3049 gst_object_unref(bus);
3052 static void
3053 toggle_voice_test_cb(GtkToggleButton *test, gpointer data)
3055 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
3057 if (gtk_toggle_button_get_active(test)) {
3058 gtk_widget_set_sensitive(win->vv.voice.level, TRUE);
3059 enable_voice_test(win);
3061 g_signal_connect(win->vv.voice.volume, "value-changed",
3062 G_CALLBACK(on_volume_change_cb), win);
3063 g_signal_connect(test, "destroy",
3064 G_CALLBACK(voice_test_destroy_cb), win);
3065 } else {
3066 gtk_progress_bar_set_fraction(
3067 GTK_PROGRESS_BAR(win->vv.voice.level), 0.0);
3068 gtk_widget_set_sensitive(win->vv.voice.level, FALSE);
3069 g_object_disconnect(win->vv.voice.volume,
3070 "any-signal::value-changed",
3071 G_CALLBACK(on_volume_change_cb), win, NULL);
3072 g_object_disconnect(test, "any-signal::destroy",
3073 G_CALLBACK(voice_test_destroy_cb), win,
3074 NULL);
3075 voice_test_destroy_cb(NULL, win);
3079 static void
3080 volume_changed_cb(GtkScaleButton *button, gdouble value, gpointer data)
3082 purple_prefs_set_int("/purple/media/audio/volume/input", value * 100);
3085 static void
3086 threshold_value_changed_cb(GtkScale *scale, GtkWidget *label)
3088 int value;
3089 char *tmp;
3091 value = (int)gtk_range_get_value(GTK_RANGE(scale));
3092 tmp = g_strdup_printf(_("Silence threshold: %d%%"), value);
3093 gtk_label_set_label(GTK_LABEL(label), tmp);
3094 g_free(tmp);
3096 purple_prefs_set_int("/purple/media/audio/silence_threshold", value);
3099 static void
3100 bind_voice_test(PidginPrefsWindow *win, GtkBuilder *builder)
3102 GObject *test;
3103 GObject *label;
3104 GObject *volume;
3105 GObject *threshold;
3106 char *tmp;
3108 volume = gtk_builder_get_object(builder, "vv.voice.volume");
3109 win->vv.voice.volume = GTK_WIDGET(volume);
3110 gtk_scale_button_set_value(GTK_SCALE_BUTTON(volume),
3111 purple_prefs_get_int("/purple/media/audio/volume/input") / 100.0);
3112 g_signal_connect(volume, "value-changed",
3113 G_CALLBACK(volume_changed_cb), NULL);
3115 label = gtk_builder_get_object(builder, "vv.voice.threshold_label");
3116 tmp = g_strdup_printf(_("Silence threshold: %d%%"),
3117 purple_prefs_get_int("/purple/media/audio/silence_threshold"));
3118 gtk_label_set_text(GTK_LABEL(label), tmp);
3119 g_free(tmp);
3121 threshold = gtk_builder_get_object(builder, "vv.voice.threshold");
3122 win->vv.voice.threshold = GTK_WIDGET(threshold);
3123 gtk_range_set_value(GTK_RANGE(threshold),
3124 purple_prefs_get_int("/purple/media/audio/silence_threshold"));
3125 g_signal_connect(threshold, "value-changed",
3126 G_CALLBACK(threshold_value_changed_cb), label);
3128 win->vv.voice.level =
3129 GTK_WIDGET(gtk_builder_get_object(builder, "vv.voice.level"));
3131 test = gtk_builder_get_object(builder, "vv.voice.test");
3132 g_signal_connect(test, "toggled",
3133 G_CALLBACK(toggle_voice_test_cb), win);
3134 win->vv.voice.test = GTK_WIDGET(test);
3137 static GstElement *
3138 create_video_pipeline(void)
3140 GstElement *pipeline;
3141 GstElement *src, *sink;
3142 GstElement *videoconvert;
3143 GstElement *videoscale;
3145 pipeline = gst_pipeline_new("videotest");
3146 src = create_test_element(PURPLE_MEDIA_ELEMENT_VIDEO | PURPLE_MEDIA_ELEMENT_SRC);
3147 sink = create_test_element(PURPLE_MEDIA_ELEMENT_VIDEO | PURPLE_MEDIA_ELEMENT_SINK);
3148 videoconvert = gst_element_factory_make("videoconvert", NULL);
3149 videoscale = gst_element_factory_make("videoscale", NULL);
3151 g_object_set_data(G_OBJECT(pipeline), "sink", sink);
3153 gst_bin_add_many(GST_BIN(pipeline), src, videoconvert, videoscale, sink,
3154 NULL);
3155 gst_element_link_many(src, videoconvert, videoscale, sink, NULL);
3157 return pipeline;
3160 static void
3161 video_test_destroy_cb(GtkWidget *w, gpointer data)
3163 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
3165 if (!win->vv.video.pipeline) {
3166 return;
3169 gst_element_set_state(win->vv.video.pipeline, GST_STATE_NULL);
3170 g_clear_pointer(&win->vv.video.pipeline, gst_object_unref);
3173 static void
3174 window_id_cb(GstBus *bus, GstMessage *msg, gulong window_id)
3176 if (GST_MESSAGE_TYPE(msg) != GST_MESSAGE_ELEMENT ||
3177 !gst_is_video_overlay_prepare_window_handle_message(msg)) {
3178 return;
3181 g_signal_handlers_disconnect_matched(bus,
3182 G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA,
3183 0, 0, NULL, window_id_cb,
3184 (gpointer)window_id);
3186 gst_video_overlay_set_window_handle(GST_VIDEO_OVERLAY(GST_MESSAGE_SRC(msg)),
3187 window_id);
3190 static void
3191 enable_video_test(PidginPrefsWindow *win)
3193 GstBus *bus;
3194 GdkWindow *window = gtk_widget_get_window(win->vv.video.drawing_area);
3195 gulong window_id = 0;
3197 #ifdef GDK_WINDOWING_WIN32
3198 if (GDK_IS_WIN32_WINDOW(window))
3199 window_id = GPOINTER_TO_UINT(GDK_WINDOW_HWND(window));
3200 else
3201 #endif
3202 #ifdef GDK_WINDOWING_X11
3203 if (GDK_IS_X11_WINDOW(window))
3204 window_id = gdk_x11_window_get_xid(window);
3205 else
3206 #endif
3207 #ifdef GDK_WINDOWING_QUARTZ
3208 if (GDK_IS_QUARTZ_WINDOW(window))
3209 window_id = (gulong)gdk_quartz_window_get_nsview(window);
3210 else
3211 #endif
3212 g_warning("Unsupported GDK backend");
3213 #if !(defined(GDK_WINDOWING_WIN32) \
3214 || defined(GDK_WINDOWING_X11) \
3215 || defined(GDK_WINDOWING_QUARTZ))
3216 # error "Unsupported GDK windowing system"
3217 #endif
3219 win->vv.video.pipeline = create_video_pipeline();
3220 bus = gst_pipeline_get_bus(GST_PIPELINE(win->vv.video.pipeline));
3221 gst_bus_set_sync_handler(bus, gst_bus_sync_signal_handler, NULL, NULL);
3222 g_signal_connect(bus, "sync-message::element",
3223 G_CALLBACK(window_id_cb), (gpointer)window_id);
3224 gst_object_unref(bus);
3226 gst_element_set_state(GST_ELEMENT(win->vv.video.pipeline),
3227 GST_STATE_PLAYING);
3230 static void
3231 toggle_video_test_cb(GtkToggleButton *test, gpointer data)
3233 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
3235 if (gtk_toggle_button_get_active(test)) {
3236 enable_video_test(win);
3237 g_signal_connect(test, "destroy",
3238 G_CALLBACK(video_test_destroy_cb), win);
3239 } else {
3240 g_object_disconnect(test, "any-signal::destroy",
3241 G_CALLBACK(video_test_destroy_cb), win,
3242 NULL);
3243 video_test_destroy_cb(NULL, win);
3247 static void
3248 bind_video_test(PidginPrefsWindow *win, GtkBuilder *builder)
3250 GtkWidget *video;
3251 GObject *test;
3252 GdkRGBA color = {0.0, 0.0, 0.0, 1.0};
3254 win->vv.video.drawing_area = video = GTK_WIDGET(
3255 gtk_builder_get_object(builder, "vv.video.test_area"));
3256 gtk_widget_override_background_color(video, GTK_STATE_FLAG_NORMAL,
3257 &color);
3259 /* In order to enable client shadow decorations, GtkDialog from GTK+ 3.0
3260 * uses ARGB visual which by default gets inherited by its child
3261 * widgets. XVideo adaptors on the other hand often support just depth
3262 * 24 and rendering video through xvimagesink onto a widget inside a
3263 * GtkDialog then results in no visible output.
3265 * This ensures the default system visual of the drawing area doesn't
3266 * get overridden by the widget's parent.
3268 gtk_widget_set_visual(video, gdk_screen_get_system_visual(
3269 gtk_widget_get_screen(video)));
3271 test = gtk_builder_get_object(builder, "vv.video.test");
3272 g_signal_connect(test, "toggled",
3273 G_CALLBACK(toggle_video_test_cb), win);
3274 win->vv.video.test = GTK_WIDGET(test);
3277 static void
3278 vv_device_changed_cb(const gchar *name, PurplePrefType type,
3279 gconstpointer value, gpointer data)
3281 PidginPrefsWindow *win = PIDGIN_PREFS_WINDOW(data);
3283 PurpleMediaManager *manager;
3284 PurpleMediaElementInfo *info;
3286 manager = purple_media_manager_get();
3287 info = purple_media_manager_get_element_info(manager, value);
3288 purple_media_manager_set_active_element(manager, info);
3290 /* Refresh test viewers */
3291 if (strstr(name, "audio") && win->vv.voice.pipeline) {
3292 voice_test_destroy_cb(NULL, win);
3293 enable_voice_test(win);
3294 } else if (strstr(name, "video") && win->vv.video.pipeline) {
3295 video_test_destroy_cb(NULL, win);
3296 enable_video_test(win);
3300 static const char *
3301 purple_media_type_to_preference_key(PurpleMediaElementType type)
3303 if (type & PURPLE_MEDIA_ELEMENT_AUDIO) {
3304 if (type & PURPLE_MEDIA_ELEMENT_SRC) {
3305 return PIDGIN_PREFS_ROOT "/vvconfig/audio/src/device";
3306 } else if (type & PURPLE_MEDIA_ELEMENT_SINK) {
3307 return PIDGIN_PREFS_ROOT "/vvconfig/audio/sink/device";
3309 } else if (type & PURPLE_MEDIA_ELEMENT_VIDEO) {
3310 if (type & PURPLE_MEDIA_ELEMENT_SRC) {
3311 return PIDGIN_PREFS_ROOT "/vvconfig/video/src/device";
3312 } else if (type & PURPLE_MEDIA_ELEMENT_SINK) {
3313 return PIDGIN_PREFS_ROOT "/vvconfig/video/sink/device";
3317 return NULL;
3320 static void
3321 bind_vv_dropdown(PidginPrefCombo *combo, PurpleMediaElementType element_type)
3323 const gchar *preference_key;
3324 GList *devices;
3326 preference_key = purple_media_type_to_preference_key(element_type);
3327 devices = get_vv_device_menuitems(element_type);
3329 if (g_list_find_custom(devices, purple_prefs_get_string(preference_key),
3330 (GCompareFunc)strcmp) == NULL)
3332 GList *next = g_list_next(devices);
3333 if (next)
3334 purple_prefs_set_string(preference_key, next->data);
3337 combo->type = PURPLE_PREF_STRING;
3338 combo->key = preference_key;
3339 pidgin_prefs_bind_dropdown_from_list(combo, devices);
3340 g_list_free_full(devices, g_free);
3343 static void
3344 bind_vv_frame(PidginPrefsWindow *win, PidginPrefCombo *combo,
3345 PurpleMediaElementType type)
3347 bind_vv_dropdown(combo, type);
3349 purple_prefs_connect_callback(combo->combo,
3350 purple_media_type_to_preference_key(type),
3351 vv_device_changed_cb, win);
3352 g_signal_connect_swapped(combo->combo, "destroy",
3353 G_CALLBACK(purple_prefs_disconnect_by_handle),
3354 combo->combo);
3356 g_object_set_data(G_OBJECT(combo->combo), "vv_media_type",
3357 (gpointer)type);
3358 g_object_set_data(G_OBJECT(combo->combo), "vv_combo", combo);
3361 static void
3362 device_list_changed_cb(PurpleMediaManager *manager, GtkWidget *widget)
3364 PidginPrefCombo *combo;
3365 PurpleMediaElementType media_type;
3366 GtkTreeModel *model;
3368 combo = g_object_get_data(G_OBJECT(widget), "vv_combo");
3369 media_type = (PurpleMediaElementType)g_object_get_data(G_OBJECT(widget),
3370 "vv_media_type");
3372 /* Unbind original connections so we can repopulate the combo box. */
3373 g_object_disconnect(combo->combo, "any-signal::changed",
3374 G_CALLBACK(bind_dropdown_set), combo, NULL);
3375 model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo->combo));
3376 gtk_list_store_clear(GTK_LIST_STORE(model));
3378 bind_vv_dropdown(combo, media_type);
3381 static GtkWidget *
3382 vv_page(PidginPrefsWindow *win)
3384 GtkBuilder *builder;
3385 GtkWidget *ret;
3386 PurpleMediaManager *manager;
3388 builder = gtk_builder_new_from_resource("/im/pidgin/Pidgin/Prefs/vv.ui");
3389 gtk_builder_set_translation_domain(builder, PACKAGE);
3391 ret = GTK_WIDGET(gtk_builder_get_object(builder, "vv.page"));
3393 manager = purple_media_manager_get();
3395 win->vv.voice.input.combo = GTK_WIDGET(
3396 gtk_builder_get_object(builder, "vv.voice.input.combo"));
3397 bind_vv_frame(win, &win->vv.voice.input,
3398 PURPLE_MEDIA_ELEMENT_AUDIO | PURPLE_MEDIA_ELEMENT_SRC);
3399 g_signal_connect_object(manager, "elements-changed::audiosrc",
3400 G_CALLBACK(device_list_changed_cb),
3401 win->vv.voice.input.combo, 0);
3403 win->vv.voice.output.combo = GTK_WIDGET(
3404 gtk_builder_get_object(builder, "vv.voice.output.combo"));
3405 bind_vv_frame(win, &win->vv.voice.output,
3406 PURPLE_MEDIA_ELEMENT_AUDIO | PURPLE_MEDIA_ELEMENT_SINK);
3407 g_signal_connect_object(manager, "elements-changed::audiosink",
3408 G_CALLBACK(device_list_changed_cb),
3409 win->vv.voice.output.combo, 0);
3411 bind_voice_test(win, builder);
3413 win->vv.video.input.combo = GTK_WIDGET(
3414 gtk_builder_get_object(builder, "vv.video.input.combo"));
3415 bind_vv_frame(win, &win->vv.video.input,
3416 PURPLE_MEDIA_ELEMENT_VIDEO | PURPLE_MEDIA_ELEMENT_SRC);
3417 g_signal_connect_object(manager, "elements-changed::videosrc",
3418 G_CALLBACK(device_list_changed_cb),
3419 win->vv.video.input.combo, 0);
3421 win->vv.video.output.combo = GTK_WIDGET(
3422 gtk_builder_get_object(builder, "vv.video.output.combo"));
3423 bind_vv_frame(win, &win->vv.video.output,
3424 PURPLE_MEDIA_ELEMENT_VIDEO | PURPLE_MEDIA_ELEMENT_SINK);
3425 g_signal_connect_object(manager, "elements-changed::videosink",
3426 G_CALLBACK(device_list_changed_cb),
3427 win->vv.video.output.combo, 0);
3429 bind_video_test(win, builder);
3431 g_signal_connect(win->stack, "notify::visible-child",
3432 G_CALLBACK(vv_test_switch_page_cb), win);
3434 g_object_ref(ret);
3435 g_object_unref(builder);
3437 return ret;
3439 #endif
3441 static void
3442 prefs_stack_init(PidginPrefsWindow *win)
3444 #ifdef USE_VV
3445 GtkStack *stack = GTK_STACK(win->stack);
3446 GtkWidget *vv;
3447 #endif
3449 bind_interface_page(win);
3450 bind_browser_page(win);
3451 bind_conv_page(win);
3452 bind_logging_page(win);
3453 bind_network_page(win);
3454 bind_proxy_page(win);
3455 bind_keyring_page(win);
3456 bind_sound_page(win);
3457 bind_away_page(win);
3458 bind_theme_page(win);
3459 #ifdef USE_VV
3460 vv = vv_page(win);
3461 gtk_container_add_with_properties(GTK_CONTAINER(stack), vv, "name",
3462 "vv", "title", _("Voice/Video"),
3463 NULL);
3464 g_object_unref(vv);
3465 #endif
3468 static void
3469 pidgin_prefs_window_class_init(PidginPrefsWindowClass *klass)
3471 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
3473 gtk_widget_class_set_template_from_resource(
3474 widget_class,
3475 "/im/pidgin/Pidgin/Prefs/prefs.ui"
3478 /* Main window */
3479 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3480 stack);
3481 gtk_widget_class_bind_template_callback(widget_class, delete_prefs);
3483 /* Interface page */
3484 gtk_widget_class_bind_template_child(
3485 widget_class, PidginPrefsWindow,
3486 iface.docklet.combo);
3487 gtk_widget_class_bind_template_child(
3488 widget_class, PidginPrefsWindow,
3489 iface.im.hide_new.combo);
3490 gtk_widget_class_bind_template_child(
3491 widget_class, PidginPrefsWindow,
3492 iface.win32.minimize_new_convs);
3493 gtk_widget_class_bind_template_child(
3494 widget_class, PidginPrefsWindow,
3495 iface.conversations.tabs);
3496 gtk_widget_class_bind_template_child(
3497 widget_class, PidginPrefsWindow,
3498 iface.conversations.tabs_vbox);
3499 gtk_widget_class_bind_template_child(
3500 widget_class, PidginPrefsWindow,
3501 iface.conversations.close_on_tabs);
3502 gtk_widget_class_bind_template_child(
3503 widget_class, PidginPrefsWindow,
3504 iface.conversations.tab_side.combo);
3505 gtk_widget_class_bind_template_child(
3506 widget_class, PidginPrefsWindow,
3507 iface.conversations.placement.combo);
3509 /* Browser page */
3510 gtk_widget_class_bind_template_child(
3511 widget_class, PidginPrefsWindow, browser.page);
3512 gtk_widget_class_bind_template_child(
3513 widget_class, PidginPrefsWindow, browser.stack);
3514 gtk_widget_class_bind_template_child(
3515 widget_class, PidginPrefsWindow, browser.gnome_not_found);
3516 gtk_widget_class_bind_template_child(
3517 widget_class, PidginPrefsWindow, browser.gnome_program);
3518 gtk_widget_class_bind_template_child(
3519 widget_class, PidginPrefsWindow, browser.browser.combo);
3520 gtk_widget_class_bind_template_child(
3521 widget_class, PidginPrefsWindow, browser.place_hbox);
3522 gtk_widget_class_bind_template_child(
3523 widget_class, PidginPrefsWindow, browser.place.combo);
3524 gtk_widget_class_bind_template_child(
3525 widget_class, PidginPrefsWindow, browser.manual_command_hbox);
3526 gtk_widget_class_bind_template_child(
3527 widget_class, PidginPrefsWindow, browser.manual_command);
3528 gtk_widget_class_bind_template_callback(widget_class,
3529 browser_button_clicked_cb);
3530 gtk_widget_class_bind_template_callback(widget_class,
3531 manual_browser_set);
3533 /* Conversations page */
3534 gtk_widget_class_bind_template_child(
3535 widget_class, PidginPrefsWindow,
3536 conversations.notification_chat.combo);
3537 gtk_widget_class_bind_template_child(
3538 widget_class, PidginPrefsWindow,
3539 conversations.show_incoming_formatting);
3540 gtk_widget_class_bind_template_child(
3541 widget_class, PidginPrefsWindow,
3542 conversations.im.close_immediately);
3543 gtk_widget_class_bind_template_child(
3544 widget_class, PidginPrefsWindow,
3545 conversations.im.show_buddy_icons);
3546 gtk_widget_class_bind_template_child(
3547 widget_class, PidginPrefsWindow,
3548 conversations.im.animate_buddy_icons);
3549 gtk_widget_class_bind_template_child(
3550 widget_class, PidginPrefsWindow,
3551 conversations.im.send_typing);
3552 gtk_widget_class_bind_template_child(
3553 widget_class, PidginPrefsWindow,
3554 conversations.spellcheck);
3555 gtk_widget_class_bind_template_child(
3556 widget_class, PidginPrefsWindow,
3557 conversations.use_smooth_scrolling);
3558 gtk_widget_class_bind_template_child(
3559 widget_class, PidginPrefsWindow,
3560 conversations.win32.blink_im);
3561 gtk_widget_class_bind_template_child(
3562 widget_class, PidginPrefsWindow,
3563 conversations.resize_custom_smileys);
3564 gtk_widget_class_bind_template_child(
3565 widget_class, PidginPrefsWindow,
3566 conversations.custom_smileys_size);
3567 gtk_widget_class_bind_template_child(
3568 widget_class, PidginPrefsWindow,
3569 conversations.minimum_entry_lines);
3570 gtk_widget_class_bind_template_child(
3571 widget_class, PidginPrefsWindow,
3572 conversations.format_buffer);
3573 gtk_widget_class_bind_template_child(
3574 widget_class, PidginPrefsWindow,
3575 conversations.format_view);
3576 #ifdef WIN32
3577 gtk_widget_class_bind_template_child(
3578 widget_class, PidginPrefsWindow,
3579 conversations.font_frame);
3580 gtk_widget_class_bind_template_child(
3581 widget_class, PidginPrefsWindow,
3582 conversations.use_theme_font);
3583 gtk_widget_class_bind_template_child(
3584 widget_class, PidginPrefsWindow,
3585 conversations.custom_font_hbox);
3586 gtk_widget_class_bind_template_child(
3587 widget_class, PidginPrefsWindow,
3588 conversations.custom_font);
3589 #endif
3590 /* Even though Win32-specific, must be bound to avoid Glade warnings. */
3591 gtk_widget_class_bind_template_callback(widget_class,
3592 apply_custom_font);
3593 gtk_widget_class_bind_template_callback(widget_class,
3594 pidgin_custom_font_set);
3596 /* Logging page */
3597 gtk_widget_class_bind_template_child(
3598 widget_class, PidginPrefsWindow, logging.format.combo);
3599 gtk_widget_class_bind_template_child(
3600 widget_class, PidginPrefsWindow, logging.log_ims);
3601 gtk_widget_class_bind_template_child(
3602 widget_class, PidginPrefsWindow, logging.log_chats);
3603 gtk_widget_class_bind_template_child(
3604 widget_class, PidginPrefsWindow, logging.log_system);
3606 /* Network page */
3607 gtk_widget_class_bind_template_child(
3608 widget_class, PidginPrefsWindow, network.stun_server);
3609 gtk_widget_class_bind_template_child(
3610 widget_class, PidginPrefsWindow, network.auto_ip);
3611 gtk_widget_class_bind_template_child(
3612 widget_class, PidginPrefsWindow, network.public_ip);
3613 gtk_widget_class_bind_template_child(
3614 widget_class, PidginPrefsWindow,
3615 network.public_ip_hbox);
3616 gtk_widget_class_bind_template_child(
3617 widget_class, PidginPrefsWindow, network.map_ports);
3618 gtk_widget_class_bind_template_child(
3619 widget_class, PidginPrefsWindow,
3620 network.ports_range_use);
3621 gtk_widget_class_bind_template_child(
3622 widget_class, PidginPrefsWindow,
3623 network.ports_range_hbox);
3624 gtk_widget_class_bind_template_child(
3625 widget_class, PidginPrefsWindow,
3626 network.ports_range_start);
3627 gtk_widget_class_bind_template_child(
3628 widget_class, PidginPrefsWindow,
3629 network.ports_range_end);
3630 gtk_widget_class_bind_template_child(
3631 widget_class, PidginPrefsWindow, network.turn_server);
3632 gtk_widget_class_bind_template_child(
3633 widget_class, PidginPrefsWindow,
3634 network.turn_port_udp);
3635 gtk_widget_class_bind_template_child(
3636 widget_class, PidginPrefsWindow,
3637 network.turn_port_tcp);
3638 gtk_widget_class_bind_template_child(
3639 widget_class, PidginPrefsWindow,
3640 network.turn_username);
3641 gtk_widget_class_bind_template_child(
3642 widget_class, PidginPrefsWindow,
3643 network.turn_password);
3644 gtk_widget_class_bind_template_callback(widget_class,
3645 network_stun_server_changed_cb);
3646 gtk_widget_class_bind_template_callback(widget_class,
3647 auto_ip_button_clicked_cb);
3648 gtk_widget_class_bind_template_callback(widget_class,
3649 network_ip_changed);
3650 gtk_widget_class_bind_template_callback(widget_class,
3651 network_turn_server_changed_cb);
3653 /* Proxy page */
3654 gtk_widget_class_bind_template_child(
3655 widget_class, PidginPrefsWindow, proxy.stack);
3656 gtk_widget_class_bind_template_child(
3657 widget_class, PidginPrefsWindow, proxy.gnome_not_found);
3658 gtk_widget_class_bind_template_child(
3659 widget_class, PidginPrefsWindow, proxy.gnome_program);
3660 gtk_widget_class_bind_template_child(
3661 widget_class, PidginPrefsWindow,
3662 proxy.socks4_remotedns);
3663 gtk_widget_class_bind_template_child(
3664 widget_class, PidginPrefsWindow, proxy.type.combo);
3665 gtk_widget_class_bind_template_child(
3666 widget_class, PidginPrefsWindow, proxy.options);
3667 gtk_widget_class_bind_template_child(
3668 widget_class, PidginPrefsWindow, proxy.host);
3669 gtk_widget_class_bind_template_child(
3670 widget_class, PidginPrefsWindow, proxy.port);
3671 gtk_widget_class_bind_template_child(
3672 widget_class, PidginPrefsWindow, proxy.username);
3673 gtk_widget_class_bind_template_child(
3674 widget_class, PidginPrefsWindow, proxy.password);
3675 gtk_widget_class_bind_template_callback(widget_class,
3676 proxy_button_clicked_cb);
3677 gtk_widget_class_bind_template_callback(widget_class,
3678 proxy_print_option);
3680 /* Keyrings page */
3681 gtk_widget_class_bind_template_child(
3682 widget_class, PidginPrefsWindow, keyring.active.combo);
3683 gtk_widget_class_bind_template_child(
3684 widget_class, PidginPrefsWindow, keyring.vbox);
3686 /* Sounds page */
3687 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3688 sound.method.combo);
3689 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3690 sound.method_vbox);
3691 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3692 sound.command);
3693 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3694 sound.command_hbox);
3695 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3696 sound.mute);
3697 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3698 sound.conv_focus);
3699 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3700 sound.while_status.combo);
3701 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3702 sound.event.view);
3703 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3704 sound.event.store);
3705 gtk_widget_class_bind_template_child(widget_class, PidginPrefsWindow,
3706 sound.entry);
3707 gtk_widget_class_bind_template_callback(widget_class, sound_cmd_yeah);
3708 gtk_widget_class_bind_template_callback(widget_class, prefs_sound_sel);
3709 gtk_widget_class_bind_template_callback(widget_class, event_toggled);
3710 gtk_widget_class_bind_template_callback(widget_class, select_sound);
3711 gtk_widget_class_bind_template_callback(widget_class, test_sound);
3712 gtk_widget_class_bind_template_callback(widget_class, reset_sound);
3714 /* Away page */
3715 gtk_widget_class_bind_template_child(
3716 widget_class, PidginPrefsWindow,
3717 away.idle_reporting.combo);
3718 gtk_widget_class_bind_template_child(
3719 widget_class, PidginPrefsWindow,
3720 away.mins_before_away);
3721 gtk_widget_class_bind_template_child(
3722 widget_class, PidginPrefsWindow, away.away_when_idle);
3723 gtk_widget_class_bind_template_child(
3724 widget_class, PidginPrefsWindow, away.idle_hbox);
3725 gtk_widget_class_bind_template_child(
3726 widget_class, PidginPrefsWindow,
3727 away.auto_reply.combo);
3728 gtk_widget_class_bind_template_child(
3729 widget_class, PidginPrefsWindow,
3730 away.startup_current_status);
3731 gtk_widget_class_bind_template_child(
3732 widget_class, PidginPrefsWindow, away.startup_hbox);
3733 gtk_widget_class_bind_template_child(
3734 widget_class, PidginPrefsWindow, away.startup_label);
3736 /* Themes page */
3737 gtk_widget_class_bind_template_child(
3738 widget_class, PidginPrefsWindow, theme.blist);
3739 gtk_widget_class_bind_template_child(
3740 widget_class, PidginPrefsWindow, theme.status);
3741 gtk_widget_class_bind_template_child(
3742 widget_class, PidginPrefsWindow, theme.sound);
3743 gtk_widget_class_bind_template_child(
3744 widget_class, PidginPrefsWindow, theme.smiley);
3745 gtk_widget_class_bind_template_callback(widget_class,
3746 prefs_set_blist_theme_cb);
3747 gtk_widget_class_bind_template_callback(widget_class,
3748 prefs_set_status_icon_theme_cb);
3749 gtk_widget_class_bind_template_callback(widget_class,
3750 prefs_set_sound_theme_cb);
3751 gtk_widget_class_bind_template_callback(widget_class,
3752 prefs_set_smiley_theme_cb);
3755 static void
3756 pidgin_prefs_window_init(PidginPrefsWindow *win)
3758 /* copy the preferences to tmp values...
3759 * I liked "take affect immediately" Oh well :-( */
3760 /* (that should have been "effect," right?) */
3762 /* Back to instant-apply! I win! BU-HAHAHA! */
3764 /* Create the window */
3765 gtk_widget_init_template(GTK_WIDGET(win));
3767 prefs_stack_init(win);
3769 /* Refresh the list of themes before showing the preferences window */
3770 prefs_themes_refresh();
3773 void
3774 pidgin_prefs_show(void)
3776 if (prefs == NULL) {
3777 prefs = PIDGIN_PREFS_WINDOW(g_object_new(
3778 pidgin_prefs_window_get_type(), NULL));
3781 gtk_window_present(GTK_WINDOW(prefs));
3784 static void
3785 smiley_theme_pref_cb(const char *name, PurplePrefType type,
3786 gconstpointer value, gpointer data)
3788 const gchar *theme_name = value;
3789 GList *themes, *it;
3791 if (purple_strequal(theme_name, "none")) {
3792 purple_smiley_theme_set_current(NULL);
3793 return;
3796 /* XXX: could be cached when initializing prefs view */
3797 themes = pidgin_smiley_theme_get_all();
3799 for (it = themes; it; it = g_list_next(it)) {
3800 PidginSmileyTheme *theme = it->data;
3802 if (!purple_strequal(pidgin_smiley_theme_get_name(theme), theme_name))
3803 continue;
3805 purple_smiley_theme_set_current(PURPLE_SMILEY_THEME(theme));
3809 void
3810 pidgin_prefs_init(void)
3812 purple_prefs_add_none(PIDGIN_PREFS_ROOT "");
3813 purple_prefs_add_none("/plugins/gtk");
3815 #ifndef _WIN32
3816 /* Browsers */
3817 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/browsers");
3818 purple_prefs_add_int(PIDGIN_PREFS_ROOT "/browsers/place", PIDGIN_BROWSER_DEFAULT);
3819 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/browsers/manual_command", "");
3820 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/browsers/browser", "xdg-open");
3821 #endif
3823 /* Plugins */
3824 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/plugins");
3825 purple_prefs_add_path_list(PIDGIN_PREFS_ROOT "/plugins/loaded", NULL);
3827 /* File locations */
3828 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/filelocations");
3829 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/filelocations/last_save_folder", "");
3830 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/filelocations/last_open_folder", "");
3831 purple_prefs_add_path(PIDGIN_PREFS_ROOT "/filelocations/last_icon_folder", "");
3833 /* Themes */
3834 prefs_themes_init();
3836 /* Smiley Themes */
3837 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/smileys");
3838 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/smileys/theme", "Default");
3840 /* Smiley Callbacks */
3841 purple_prefs_connect_callback(&prefs, PIDGIN_PREFS_ROOT "/smileys/theme",
3842 smiley_theme_pref_cb, NULL);
3844 #ifdef USE_VV
3845 /* Voice/Video */
3846 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig");
3847 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/audio");
3848 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/audio/src");
3849 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/vvconfig/audio/src/device", "");
3850 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/audio/sink");
3851 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/vvconfig/audio/sink/device", "");
3852 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/video");
3853 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/video/src");
3854 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/vvconfig/video/src/device", "");
3855 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/video");
3856 purple_prefs_add_none(PIDGIN_PREFS_ROOT "/vvconfig/video/sink");
3857 purple_prefs_add_string(PIDGIN_PREFS_ROOT "/vvconfig/video/sink/device", "");
3858 #endif
3860 pidgin_prefs_update_old();
3863 void
3864 pidgin_prefs_update_old(void)
3866 /* Rename some old prefs */
3867 purple_prefs_rename(PIDGIN_PREFS_ROOT "/logging/log_ims", "/purple/logging/log_ims");
3868 purple_prefs_rename(PIDGIN_PREFS_ROOT "/logging/log_chats", "/purple/logging/log_chats");
3869 purple_prefs_rename("/purple/conversations/placement",
3870 PIDGIN_PREFS_ROOT "/conversations/placement");
3872 purple_prefs_rename(PIDGIN_PREFS_ROOT "/conversations/im/raise_on_events", "/plugins/gtk/X11/notify/method_raise");
3874 purple_prefs_rename_boolean_toggle(PIDGIN_PREFS_ROOT "/conversations/ignore_colors",
3875 PIDGIN_PREFS_ROOT "/conversations/show_incoming_formatting");
3878 * This path pref changed to a string, so migrate. I know this will
3879 * break things for and confuse users that use multiple versions with
3880 * the same config directory, but I'm not inclined to want to deal with
3881 * that at the moment. -- rekkanoryo
3883 if (purple_prefs_exists(PIDGIN_PREFS_ROOT "/browsers/command") &&
3884 purple_prefs_get_pref_type(PIDGIN_PREFS_ROOT "/browsers/command") ==
3885 PURPLE_PREF_PATH)
3887 const char *str = purple_prefs_get_path(
3888 PIDGIN_PREFS_ROOT "/browsers/command");
3889 purple_prefs_set_string(
3890 PIDGIN_PREFS_ROOT "/browsers/manual_command", str);
3891 purple_prefs_remove(PIDGIN_PREFS_ROOT "/browsers/command");
3894 /* Remove some no-longer-used prefs */
3895 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/auto_expand_contacts");
3896 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/button_style");
3897 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/grey_idle_buddies");
3898 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/raise_on_events");
3899 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/show_group_count");
3900 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/show_warning_level");
3901 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/tooltip_delay");
3902 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/x");
3903 purple_prefs_remove(PIDGIN_PREFS_ROOT "/blist/y");
3904 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/button_type");
3905 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/ctrl_enter_sends");
3906 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/enter_sends");
3907 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/escape_closes");
3908 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/html_shortcuts");
3909 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/icons_on_tabs");
3910 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/send_formatting");
3911 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/show_smileys");
3912 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/show_urls_as_links");
3913 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/smiley_shortcuts");
3914 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/use_custom_bgcolor");
3915 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/use_custom_fgcolor");
3916 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/use_custom_font");
3917 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/use_custom_size");
3918 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/chat/old_tab_complete");
3919 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/chat/tab_completion");
3920 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/im/hide_on_send");
3921 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/chat/color_nicks");
3922 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/chat/raise_on_events");
3923 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/ignore_fonts");
3924 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/ignore_font_sizes");
3925 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/passthrough_unknown_commands");
3926 purple_prefs_remove(PIDGIN_PREFS_ROOT "/debug/timestamps");
3927 purple_prefs_remove(PIDGIN_PREFS_ROOT "/idle");
3928 purple_prefs_remove(PIDGIN_PREFS_ROOT "/logging/individual_logs");
3929 purple_prefs_remove(PIDGIN_PREFS_ROOT "/sound/signon");
3930 purple_prefs_remove(PIDGIN_PREFS_ROOT "/sound/silent_signon");
3932 /* Convert old queuing prefs to hide_new 3-way pref. */
3933 if (purple_prefs_exists("/plugins/gtk/docklet/queue_messages") &&
3934 purple_prefs_get_bool("/plugins/gtk/docklet/queue_messages"))
3936 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/conversations/im/hide_new", "always");
3938 else if (purple_prefs_exists(PIDGIN_PREFS_ROOT "/away/queue_messages") &&
3939 purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/away/queue_messages"))
3941 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/conversations/im/hide_new", "away");
3943 purple_prefs_remove(PIDGIN_PREFS_ROOT "/away/queue_messages");
3944 purple_prefs_remove(PIDGIN_PREFS_ROOT "/away");
3945 purple_prefs_remove("/plugins/gtk/docklet/queue_messages");
3947 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/chat/default_width");
3948 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/chat/default_height");
3949 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/im/default_width");
3950 purple_prefs_remove(PIDGIN_PREFS_ROOT "/conversations/im/default_height");
3951 purple_prefs_rename(PIDGIN_PREFS_ROOT "/conversations/x",
3952 PIDGIN_PREFS_ROOT "/conversations/im/x");
3953 purple_prefs_rename(PIDGIN_PREFS_ROOT "/conversations/y",
3954 PIDGIN_PREFS_ROOT "/conversations/im/y");
3956 /* Fixup vvconfig plugin prefs */
3957 if (purple_prefs_exists("/plugins/core/vvconfig/audio/src/device")) {
3958 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/vvconfig/audio/src/device",
3959 purple_prefs_get_string("/plugins/core/vvconfig/audio/src/device"));
3961 if (purple_prefs_exists("/plugins/core/vvconfig/audio/sink/device")) {
3962 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/vvconfig/audio/sink/device",
3963 purple_prefs_get_string("/plugins/core/vvconfig/audio/sink/device"));
3965 if (purple_prefs_exists("/plugins/core/vvconfig/video/src/device")) {
3966 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/vvconfig/video/src/device",
3967 purple_prefs_get_string("/plugins/core/vvconfig/video/src/device"));
3969 if (purple_prefs_exists("/plugins/gtk/vvconfig/video/sink/device")) {
3970 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/vvconfig/video/sink/device",
3971 purple_prefs_get_string("/plugins/gtk/vvconfig/video/sink/device"));
3974 purple_prefs_remove("/plugins/core/vvconfig");
3975 purple_prefs_remove("/plugins/gtk/vvconfig");
3977 purple_prefs_remove(PIDGIN_PREFS_ROOT "/vvconfig/audio/src/plugin");
3978 purple_prefs_remove(PIDGIN_PREFS_ROOT "/vvconfig/audio/sink/plugin");
3979 purple_prefs_remove(PIDGIN_PREFS_ROOT "/vvconfig/video/src/plugin");
3980 purple_prefs_remove(PIDGIN_PREFS_ROOT "/vvconfig/video/sink/plugin");
3982 #ifndef _WIN32
3983 /* Added in 3.0.0. */
3984 if (purple_prefs_get_int(PIDGIN_PREFS_ROOT "/browsers/place") == 1) {
3985 /* If the "open link in" pref is set to the old value for "existing
3986 window" then change it to "default." */
3987 purple_prefs_set_int(PIDGIN_PREFS_ROOT "/browsers/place",
3988 PIDGIN_BROWSER_DEFAULT);
3991 /* Added in 3.0.0. */
3992 if (g_str_equal(
3993 purple_prefs_get_string(PIDGIN_PREFS_ROOT "/browsers/browser"),
3994 "netscape")) {
3995 purple_prefs_set_string(PIDGIN_PREFS_ROOT "/browsers/browser", "xdg-open");
3997 #endif /* !_WIN32 */