annotate src/gtkutils.c @ 14134:4006d3dc2871

[gaim-migrate @ 16776] Fix segfault when using non-buddy-icon'ed accounts committer: Tailor Script <tailor@pidgin.im>
author Sean Egan <seanegan@gmail.com>
date Wed, 16 Aug 2006 01:32:12 +0000
parents 31d33e7bc0e6
children 5f656a0a82b7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
1 /**
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
2 * @file gtkutils.h GTK+ utility functions
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
3 * @ingroup gtkui
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
4 *
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 * gaim
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
6 *
8046
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7988
diff changeset
7 * Gaim is the legal property of its developers, whose names are too numerous
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7988
diff changeset
8 * to list here. Please refer to the COPYRIGHT file distributed with this
fa6395637e2c [gaim-migrate @ 8730]
Sean Egan <seanegan@gmail.com>
parents: 7988
diff changeset
9 * source distribution.
7060
9946001989a3 [gaim-migrate @ 7623]
Christian Hammond <chipx86@chipx86.com>
parents: 6846
diff changeset
10 *
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * This program is free software; you can redistribute it and/or modify
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * it under the terms of the GNU General Public License as published by
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * the Free Software Foundation; either version 2 of the License, or
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 * (at your option) any later version.
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 *
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * This program is distributed in the hope that it will be useful,
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 * GNU General Public License for more details.
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 *
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * You should have received a copy of the GNU General Public License
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 * along with this program; if not, write to the Free Software
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 */
9791
4a15962c344a [gaim-migrate @ 10659]
Mark Doliner <mark@kingant.net>
parents: 9767
diff changeset
25 #include "internal.h"
4a15962c344a [gaim-migrate @ 10659]
Mark Doliner <mark@kingant.net>
parents: 9767
diff changeset
26 #include "gtkgaim.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
27
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 #ifndef _WIN32
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
29 # include <X11/Xlib.h>
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30 #else
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
31 # ifdef small
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
32 # undef small
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
33 # endif
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 #endif /*_WIN32*/
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
35
7538
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
36 #ifdef USE_GTKSPELL
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
37 # include <gtkspell/gtkspell.h>
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
38 # ifdef _WIN32
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
39 # include "wspell.h"
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
40 # endif
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
41 #endif
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
42
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
43 #include <gdk/gdkkeysyms.h>
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
44
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
45 #include "conversation.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
46 #include "debug.h"
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
47 #include "desktopitem.h"
7078
acd2a66e59ed [gaim-migrate @ 7643]
Nathan Walp <nwalp@pidgin.im>
parents: 7060
diff changeset
48 #include "imgstore.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
49 #include "notify.h"
5548
80e4ba770f97 [gaim-migrate @ 5949]
Nathan Walp <nwalp@pidgin.im>
parents: 5530
diff changeset
50 #include "prefs.h"
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
51 #include "prpl.h"
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
52 #include "request.h"
6485
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
53 #include "signals.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
54 #include "util.h"
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
55
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
56 #include "gtkconv.h"
9709
4d05b6e9e9cd [gaim-migrate @ 10570]
Mark Doliner <mark@kingant.net>
parents: 9706
diff changeset
57 #include "gtkdialogs.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
58 #include "gtkimhtml.h"
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
59 #include "gtkimhtmltoolbar.h"
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
60 #include "gtkstock.h"
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
61 #include "gtkthemes.h"
5872
059d95c67cda [gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents: 5794
diff changeset
62 #include "gtkutils.h"
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
63
10850
fa06fda62868 [gaim-migrate @ 12522]
Mark Doliner <mark@kingant.net>
parents: 10681
diff changeset
64 static guint accels_save_timer = 0;
7420
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
65
8913
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
66 static gboolean
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
67 url_clicked_idle_cb(gpointer data)
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
68 {
10240
95ca0db2d01d [gaim-migrate @ 11377]
Herman Bloggs <hermanator12002@yahoo.com>
parents: 10229
diff changeset
69 gaim_notify_uri(NULL, data);
8913
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
70 g_free(data);
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
71 return FALSE;
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
72 }
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
73
6465
fb64cc87bc96 [gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents: 6430
diff changeset
74 static void
fb64cc87bc96 [gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents: 6430
diff changeset
75 url_clicked_cb(GtkWidget *w, const char *uri)
fb64cc87bc96 [gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents: 6430
diff changeset
76 {
8913
d729311f6352 [gaim-migrate @ 9683]
Luke Schierer <lschiere@pidgin.im>
parents: 8901
diff changeset
77 g_idle_add(url_clicked_idle_cb, g_strdup(uri));
6465
fb64cc87bc96 [gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents: 6430
diff changeset
78 }
fb64cc87bc96 [gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents: 6430
diff changeset
79
10871
6240d7fd5b2c [gaim-migrate @ 12558]
Mark Doliner <mark@kingant.net>
parents: 10850
diff changeset
80 static GtkIMHtmlFuncs gtkimhtml_cbs = {
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
81 (GtkIMHtmlGetImageFunc)gaim_imgstore_get,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
82 (GtkIMHtmlGetImageDataFunc)gaim_imgstore_get_data,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
83 (GtkIMHtmlGetImageSizeFunc)gaim_imgstore_get_size,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
84 (GtkIMHtmlGetImageFilenameFunc)gaim_imgstore_get_filename,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
85 gaim_imgstore_ref,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
86 gaim_imgstore_unref,
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
87 };
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
88
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 void
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
90 gaim_setup_imhtml(GtkWidget *imhtml)
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
91 {
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
92 g_return_if_fail(imhtml != NULL);
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
93 g_return_if_fail(GTK_IS_IMHTML(imhtml));
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
94
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
95 g_signal_connect(G_OBJECT(imhtml), "url_clicked",
6465
fb64cc87bc96 [gaim-migrate @ 6974]
Christian Hammond <chipx86@chipx86.com>
parents: 6430
diff changeset
96 G_CALLBACK(url_clicked_cb), NULL);
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
97
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
98 gaim_gtkthemes_smiley_themeize(imhtml);
8962
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
99
4ff4c34b7500 [gaim-migrate @ 9736]
Tim Ringenbach <marv@pidgin.im>
parents: 8940
diff changeset
100 gtk_imhtml_set_funcs(GTK_IMHTML(imhtml), &gtkimhtml_cbs);
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
101 }
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
102
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
103 GtkWidget *
13280
3de53fe8345f [gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents: 13202
diff changeset
104 gaim_gtk_create_imhtml(gboolean editable, GtkWidget **imhtml_ret, GtkWidget **toolbar_ret, GtkWidget **sw_ret)
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
105 {
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
106 GtkWidget *frame;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
107 GtkWidget *imhtml;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
108 GtkWidget *sep;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
109 GtkWidget *sw;
10177
82c1322c4b56 [gaim-migrate @ 11292]
Christian Hammond <chipx86@chipx86.com>
parents: 10175
diff changeset
110 GtkWidget *toolbar = NULL;
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
111 GtkWidget *vbox;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
112
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
113 frame = gtk_frame_new(NULL);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
114 gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
115
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
116 vbox = gtk_vbox_new(FALSE, 0);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
117 gtk_container_add(GTK_CONTAINER(frame), vbox);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
118 gtk_widget_show(vbox);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
119
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
120 if (editable) {
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
121 toolbar = gtk_imhtmltoolbar_new();
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
122 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
123 gtk_widget_show(toolbar);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
124
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
125 sep = gtk_hseparator_new();
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
126 gtk_box_pack_start(GTK_BOX(vbox), sep, FALSE, FALSE, 0);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
127 gtk_widget_show(sep);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
128 }
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
129
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
130 sw = gtk_scrolled_window_new(NULL, NULL);
13202
241c59e3906b [gaim-migrate @ 15565]
Mark Doliner <mark@kingant.net>
parents: 13113
diff changeset
131 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
241c59e3906b [gaim-migrate @ 15565]
Mark Doliner <mark@kingant.net>
parents: 13113
diff changeset
132 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
133 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
134 gtk_widget_show(sw);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
135
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
136 imhtml = gtk_imhtml_new(NULL, NULL);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
137 gtk_imhtml_set_editable(GTK_IMHTML(imhtml), editable);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
138 gtk_imhtml_set_format_functions(GTK_IMHTML(imhtml), GTK_IMHTML_ALL ^ GTK_IMHTML_IMAGE);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
139 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
12651
a74cb5952db4 [gaim-migrate @ 14992]
Mark Doliner <mark@kingant.net>
parents: 12595
diff changeset
140 #ifdef USE_GTKSPELL
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
141 if (editable && gaim_prefs_get_bool("/gaim/gtk/conversations/spellcheck"))
12067
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
142 gaim_gtk_setup_gtkspell(GTK_TEXT_VIEW(imhtml));
12651
a74cb5952db4 [gaim-migrate @ 14992]
Mark Doliner <mark@kingant.net>
parents: 12595
diff changeset
143 #endif
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
144 gtk_widget_show(imhtml);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
145
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
146 if (editable) {
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
147 gtk_imhtmltoolbar_attach(GTK_IMHTMLTOOLBAR(toolbar), imhtml);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
148 gtk_imhtmltoolbar_associate_smileys(GTK_IMHTMLTOOLBAR(toolbar), "default");
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
149 }
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
150 gaim_setup_imhtml(imhtml);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
151
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
152 gtk_container_add(GTK_CONTAINER(sw), imhtml);
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
153
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
154 if (imhtml_ret != NULL)
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
155 *imhtml_ret = imhtml;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
156
10181
5b33637b69fd [gaim-migrate @ 11296]
Mark Doliner <mark@kingant.net>
parents: 10177
diff changeset
157 if (editable && (toolbar_ret != NULL))
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
158 *toolbar_ret = toolbar;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
159
13280
3de53fe8345f [gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents: 13202
diff changeset
160 if (sw_ret != NULL)
3de53fe8345f [gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents: 13202
diff changeset
161 *sw_ret = sw;
3de53fe8345f [gaim-migrate @ 15646]
Richard Laager <rlaager@wiktel.com>
parents: 13202
diff changeset
162
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
163 return frame;
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
164 }
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
165
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
166 void
7751
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
167 gaim_gtk_set_sensitive_if_input(GtkWidget *entry, GtkWidget *dialog)
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
168 {
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
169 const char *text = gtk_entry_get_text(GTK_ENTRY(entry));
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
170 gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_OK,
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
171 (*text != '\0'));
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
172 }
d691cb95ee67 [gaim-migrate @ 8396]
Mark Doliner <mark@kingant.net>
parents: 7717
diff changeset
173
4359
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
174 void
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
175 gaim_gtk_toggle_sensitive(GtkWidget *widget, GtkWidget *to_toggle)
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
176 {
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
177 gboolean sensitivity;
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
178
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
179 if (to_toggle == NULL)
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
180 return;
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
181
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
182 sensitivity = GTK_WIDGET_IS_SENSITIVE(to_toggle);
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
183
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
184 gtk_widget_set_sensitive(to_toggle, !sensitivity);
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
185 }
5fb47ec9bfe4 [gaim-migrate @ 4625]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
186
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
187 void
10590
896efbdc74e2 [gaim-migrate @ 11995]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10566
diff changeset
188 gaim_gtk_toggle_sensitive_array(GtkWidget *w, GPtrArray *data)
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
189 {
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
190 gboolean sensitivity;
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
191 gpointer element;
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
192 int i;
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
193
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
194 for (i=0; i < data->len; i++) {
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
195 element = g_ptr_array_index(data,i);
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
196 if (element == NULL)
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
197 continue;
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
198
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
199 sensitivity = GTK_WIDGET_IS_SENSITIVE(element);
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
200
10175
53410b84336f [gaim-migrate @ 11290]
Mark Doliner <mark@kingant.net>
parents: 10061
diff changeset
201 gtk_widget_set_sensitive(element, !sensitivity);
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
202 }
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
203 }
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
204
8901
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
205 void
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
206 gaim_gtk_toggle_showhide(GtkWidget *widget, GtkWidget *to_toggle)
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
207 {
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
208 if (to_toggle == NULL)
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
209 return;
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
210
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
211 if (GTK_WIDGET_VISIBLE(to_toggle))
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
212 gtk_widget_hide(to_toggle);
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
213 else
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
214 gtk_widget_show(to_toggle);
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
215 }
c430e99bb147 [gaim-migrate @ 9670]
Mark Doliner <mark@kingant.net>
parents: 8881
diff changeset
216
4687
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
217 void gaim_separator(GtkWidget *menu)
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
218 {
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
219 GtkWidget *menuitem;
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
220
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
221 menuitem = gtk_separator_menu_item_new();
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
222 gtk_widget_show(menuitem);
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
223 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
283fb289c510 [gaim-migrate @ 4998]
Sean Egan <seanegan@gmail.com>
parents: 4398
diff changeset
224 }
5160
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
225
5162
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
226 GtkWidget *gaim_new_item(GtkWidget *menu, const char *str)
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
227 {
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
228 GtkWidget *menuitem;
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
229 GtkWidget *label;
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
230
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
231 menuitem = gtk_menu_item_new();
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
232 if (menu)
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
233 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
234 gtk_widget_show(menuitem);
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
235
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
236 label = gtk_label_new(str);
6371
8f94cce8faa5 [gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents: 6236
diff changeset
237 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
5162
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
238 gtk_label_set_pattern(GTK_LABEL(label), "_");
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
239 gtk_container_add(GTK_CONTAINER(menuitem), label);
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
240 gtk_widget_show(label);
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
241 /* FIXME: Go back and fix this
5162
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
242 gtk_widget_add_accelerator(menuitem, "activate", accel, str[0],
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
243 GDK_MOD1_MASK, GTK_ACCEL_LOCKED);
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
244 */
8137
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
245 gaim_set_accessible_label (menuitem, label);
5162
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
246 return menuitem;
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
247 }
b8eafeb874a1 [gaim-migrate @ 5526]
Mark Doliner <mark@kingant.net>
parents: 5160
diff changeset
248
5906
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
249 GtkWidget *gaim_new_check_item(GtkWidget *menu, const char *str,
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
250 GtkSignalFunc sf, gpointer data, gboolean checked)
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
251 {
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
252 GtkWidget *menuitem;
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
253 menuitem = gtk_check_menu_item_new_with_mnemonic(str);
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
254
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
255 if (menu)
5906
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
256 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
257
7299
2737c287f84d [gaim-migrate @ 7883]
Christian Hammond <chipx86@chipx86.com>
parents: 7118
diff changeset
258 gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), checked);
2737c287f84d [gaim-migrate @ 7883]
Christian Hammond <chipx86@chipx86.com>
parents: 7118
diff changeset
259
5906
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
260 if (sf)
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
261 g_signal_connect(G_OBJECT(menuitem), "activate", sf, data);
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
262
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
263 gtk_widget_show_all(menuitem);
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
264
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
265 return menuitem;
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
266 }
390d32a6b130 [gaim-migrate @ 6338]
Nathan Walp <nwalp@pidgin.im>
parents: 5880
diff changeset
267
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
268 GtkWidget *
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
269 gaim_pixbuf_toolbar_button_from_stock(const char *icon)
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
270 {
9706
d4634f26ef9b [gaim-migrate @ 10567]
Mark Doliner <mark@kingant.net>
parents: 9534
diff changeset
271 GtkWidget *button, *image, *bbox;
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
272
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
273 button = gtk_toggle_button_new();
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
274 gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
275
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
276 bbox = gtk_vbox_new(FALSE, 0);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
277
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
278 gtk_container_add (GTK_CONTAINER(button), bbox);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
279
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
280 image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
281 gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 0);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
282
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
283 gtk_widget_show_all(bbox);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
284
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
285 return button;
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
286 }
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
287
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
288 GtkWidget *
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
289 gaim_pixbuf_button_from_stock(const char *text, const char *icon,
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
290 GaimButtonOrientation style)
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
291 {
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
292 GtkWidget *button, *image, *label, *bbox, *ibox, *lbox = NULL;
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
293
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
294 button = gtk_button_new();
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
295
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
296 if (style == GAIM_BUTTON_HORIZONTAL) {
9750
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
297 bbox = gtk_hbox_new(FALSE, 0);
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
298 ibox = gtk_hbox_new(FALSE, 0);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
299 if (text)
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
300 lbox = gtk_hbox_new(FALSE, 0);
9750
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
301 } else {
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
302 bbox = gtk_vbox_new(FALSE, 0);
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
303 ibox = gtk_vbox_new(FALSE, 0);
10504
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
304 if (text)
1a97d5e88d12 [gaim-migrate @ 11796]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10483
diff changeset
305 lbox = gtk_vbox_new(FALSE, 0);
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
306 }
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
307
9750
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
308 gtk_container_add(GTK_CONTAINER(button), bbox);
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
309
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
310 if (icon) {
9750
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
311 gtk_box_pack_start_defaults(GTK_BOX(bbox), ibox);
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
312 image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_BUTTON);
9767
c31e64c2bd85 [gaim-migrate @ 10635]
Mark Doliner <mark@kingant.net>
parents: 9750
diff changeset
313 gtk_box_pack_end(GTK_BOX(ibox), image, FALSE, TRUE, 0);
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
314 }
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
315
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
316 if (text) {
9750
4f8476beabf5 [gaim-migrate @ 10617]
Mark Doliner <mark@kingant.net>
parents: 9749
diff changeset
317 gtk_box_pack_start_defaults(GTK_BOX(bbox), lbox);
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
318 label = gtk_label_new(NULL);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
319 gtk_label_set_text_with_mnemonic(GTK_LABEL(label), text);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
320 gtk_label_set_mnemonic_widget(GTK_LABEL(label), button);
9767
c31e64c2bd85 [gaim-migrate @ 10635]
Mark Doliner <mark@kingant.net>
parents: 9750
diff changeset
321 gtk_box_pack_start(GTK_BOX(lbox), label, FALSE, TRUE, 0);
8137
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
322 gaim_set_accessible_label (button, label);
6372
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
323 }
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
324
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
325 gtk_widget_show_all(bbox);
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
326
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
327 return button;
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
328 }
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
329
9dd4bb3cf1df [gaim-migrate @ 6877]
Christian Hammond <chipx86@chipx86.com>
parents: 6371
diff changeset
330
5160
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
331 GtkWidget *gaim_new_item_from_stock(GtkWidget *menu, const char *str, const char *icon, GtkSignalFunc sf, gpointer data, guint accel_key, guint accel_mods, char *mod)
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
332 {
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
333 GtkWidget *menuitem;
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
334 /*
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
335 GtkWidget *hbox;
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
336 GtkWidget *label;
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
337 */
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
338 GtkWidget *image;
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
339
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
340 if (icon == NULL)
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
341 menuitem = gtk_menu_item_new_with_mnemonic(str);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
342 else
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
343 menuitem = gtk_image_menu_item_new_with_mnemonic(str);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
344
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
345 if (menu)
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
346 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
347
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
348 if (sf)
5314
1f901484599d [gaim-migrate @ 5686]
Christian Hammond <chipx86@chipx86.com>
parents: 5162
diff changeset
349 g_signal_connect(G_OBJECT(menuitem), "activate", sf, data);
5160
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
350
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
351 if (icon != NULL) {
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
352 image = gtk_image_new_from_stock(icon, GTK_ICON_SIZE_MENU);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
353 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuitem), image);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
354 }
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
355 /* FIXME: this isn't right
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
356 if (mod) {
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
357 label = gtk_label_new(mod);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
358 gtk_box_pack_end(GTK_BOX(hbox), label, FALSE, FALSE, 2);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
359 gtk_widget_show(label);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
360 }
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
361 */
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
362 /*
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
363 if (accel_key) {
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
364 gtk_widget_add_accelerator(menuitem, "activate", accel, accel_key,
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
365 accel_mods, GTK_ACCEL_LOCKED);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
366 }
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
367 */
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
368
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
369 gtk_widget_show_all(menuitem);
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
370
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
371 return menuitem;
91ea5ef2278b [gaim-migrate @ 5524]
Mark Doliner <mark@kingant.net>
parents: 4859
diff changeset
372 }
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
373
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
374 GtkWidget *
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
375 gaim_gtk_make_frame(GtkWidget *parent, const char *title)
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
376 {
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
377 GtkWidget *vbox, *label, *hbox;
13099
913e06e4155c [gaim-migrate @ 15461]
Richard Laager <rlaager@wiktel.com>
parents: 13091
diff changeset
378 char *labeltitle;
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
379
11243
a511b77a368b [gaim-migrate @ 13408]
Mark Doliner <mark@kingant.net>
parents: 11135
diff changeset
380 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
381 gtk_box_pack_start(GTK_BOX(parent), vbox, FALSE, FALSE, 0);
5641
5e9babc828c4 [gaim-migrate @ 6054]
Christian Hammond <chipx86@chipx86.com>
parents: 5554
diff changeset
382 gtk_widget_show(vbox);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
383
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
384 label = gtk_label_new(NULL);
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
385
13099
913e06e4155c [gaim-migrate @ 15461]
Richard Laager <rlaager@wiktel.com>
parents: 13091
diff changeset
386 labeltitle = g_strdup_printf("<span weight=\"bold\">%s</span>", title);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
387 gtk_label_set_markup(GTK_LABEL(label), labeltitle);
13099
913e06e4155c [gaim-migrate @ 15461]
Richard Laager <rlaager@wiktel.com>
parents: 13091
diff changeset
388 g_free(labeltitle);
913e06e4155c [gaim-migrate @ 15461]
Richard Laager <rlaager@wiktel.com>
parents: 13091
diff changeset
389
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
390 gtk_misc_set_alignment(GTK_MISC(label), 0, 0);
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
391 gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
5641
5e9babc828c4 [gaim-migrate @ 6054]
Christian Hammond <chipx86@chipx86.com>
parents: 5554
diff changeset
392 gtk_widget_show(label);
8137
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
393 gaim_set_accessible_label (vbox, label);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
394
11243
a511b77a368b [gaim-migrate @ 13408]
Mark Doliner <mark@kingant.net>
parents: 11135
diff changeset
395 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
396 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
5641
5e9babc828c4 [gaim-migrate @ 6054]
Christian Hammond <chipx86@chipx86.com>
parents: 5554
diff changeset
397 gtk_widget_show(hbox);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
398
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
399 label = gtk_label_new(" ");
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
400 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
5641
5e9babc828c4 [gaim-migrate @ 6054]
Christian Hammond <chipx86@chipx86.com>
parents: 5554
diff changeset
401 gtk_widget_show(label);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
402
11243
a511b77a368b [gaim-migrate @ 13408]
Mark Doliner <mark@kingant.net>
parents: 11135
diff changeset
403 vbox = gtk_vbox_new(FALSE, GAIM_HIG_BOX_SPACE);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
404 gtk_box_pack_start(GTK_BOX(hbox), vbox, FALSE, FALSE, 0);
5641
5e9babc828c4 [gaim-migrate @ 6054]
Christian Hammond <chipx86@chipx86.com>
parents: 5554
diff changeset
405 gtk_widget_show(vbox);
5530
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
406
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
407 return vbox;
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
408 }
2c4c975620f0 [gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents: 5436
diff changeset
409
5647
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
410 static void
5794
5e93fc46d1af [gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents: 5746
diff changeset
411 protocol_menu_cb(GtkWidget *optmenu, GCallback cb)
5647
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
412 {
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
413 GtkWidget *menu;
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
414 GtkWidget *item;
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7943
diff changeset
415 const char *protocol;
5647
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
416 gpointer user_data;
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
417
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
418 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
419 item = gtk_menu_get_active(GTK_MENU(menu));
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
420
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7943
diff changeset
421 protocol = g_object_get_data(G_OBJECT(item), "protocol");
5647
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
422 user_data = (g_object_get_data(G_OBJECT(optmenu), "user_data"));
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
423
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
424 if (cb != NULL)
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7943
diff changeset
425 ((void (*)(GtkWidget *, const char *, gpointer))cb)(item, protocol,
5647
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
426 user_data);
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
427 }
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
428
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
429 GtkWidget *
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7943
diff changeset
430 gaim_gtk_protocol_option_menu_new(const char *id, GCallback cb,
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
431 gpointer user_data)
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
432 {
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
433 GaimPluginProtocolInfo *prpl_info;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
434 GaimPlugin *plugin;
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
435 GtkWidget *hbox;
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
436 GtkWidget *label;
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
437 GtkWidget *optmenu;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
438 GtkWidget *menu;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
439 GtkWidget *item;
5646
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
440 GtkWidget *image;
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
441 GdkPixbuf *pixbuf;
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
442 GdkPixbuf *scale;
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
443 GList *p;
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
444 GtkSizeGroup *sg;
5646
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
445 char *filename;
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
446 const char *proto_name;
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
447 char buf[256];
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
448 int i, selected_index = -1;
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
449
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
450 optmenu = gtk_option_menu_new();
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
451 gtk_widget_show(optmenu);
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
452
5647
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
453 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data);
6e551616d051 [gaim-migrate @ 6061]
Christian Hammond <chipx86@chipx86.com>
parents: 5646
diff changeset
454
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
455 menu = gtk_menu_new();
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
456 gtk_widget_show(menu);
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
457
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
458 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
459
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
460 for (p = gaim_plugins_get_protocols(), i = 0;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
461 p != NULL;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
462 p = p->next, i++) {
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
463
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
464 plugin = (GaimPlugin *)p->data;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
465 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
466
5646
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
467 /* Create the item. */
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
468 item = gtk_menu_item_new();
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
469
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
470 /* Create the hbox. */
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
471 hbox = gtk_hbox_new(FALSE, 4);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
472 gtk_container_add(GTK_CONTAINER(item), hbox);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
473 gtk_widget_show(hbox);
5646
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
474
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
475 /* Load the image. */
6430
5211873190ea [gaim-migrate @ 6938]
Sean Egan <seanegan@gmail.com>
parents: 6429
diff changeset
476 proto_name = prpl_info->list_icon(NULL, NULL);
5646
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
477 g_snprintf(buf, sizeof(buf), "%s.png", proto_name);
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
478
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
479 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
480 "default", buf, NULL);
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
481 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
482 g_free(filename);
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
483
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
484 if (pixbuf != NULL) {
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
485 /* Scale and insert the image */
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
486 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
487 GDK_INTERP_BILINEAR);
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
488 image = gtk_image_new_from_pixbuf(scale);
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
489
5646
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
490 g_object_unref(G_OBJECT(pixbuf));
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
491 g_object_unref(G_OBJECT(scale));
48c63ee49961 [gaim-migrate @ 6060]
Christian Hammond <chipx86@chipx86.com>
parents: 5644
diff changeset
492 }
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
493 else
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
494 image = gtk_image_new();
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
495
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
496 gtk_size_group_add_widget(sg, image);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
497
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
498 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
499 gtk_widget_show(image);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
500
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
501 /* Create the label. */
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
502 label = gtk_label_new(plugin->info->name);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
503 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
504 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
505 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
506 gtk_widget_show(label);
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
507
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7943
diff changeset
508 g_object_set_data(G_OBJECT(item), "protocol", plugin->info->id);
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
509
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
510 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
511 gtk_widget_show(item);
8137
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
512 gaim_set_accessible_label (item, label);
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
513
8218
4beaf6b35483 [gaim-migrate @ 8941]
Christian Hammond <chipx86@chipx86.com>
parents: 8215
diff changeset
514 if (id != NULL && !strcmp(plugin->info->id, id))
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
515 selected_index = i;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
516 }
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
517
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
518 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
519
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
520 if (selected_index != -1)
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
521 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index);
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
522
5688
e43e1b8dca8b [gaim-migrate @ 6109]
Christian Hammond <chipx86@chipx86.com>
parents: 5676
diff changeset
523 g_signal_connect(G_OBJECT(optmenu), "changed",
5794
5e93fc46d1af [gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents: 5746
diff changeset
524 G_CALLBACK(protocol_menu_cb), cb);
5688
e43e1b8dca8b [gaim-migrate @ 6109]
Christian Hammond <chipx86@chipx86.com>
parents: 5676
diff changeset
525
5649
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
526 g_object_unref(sg);
84221116b28e [gaim-migrate @ 6063]
Christian Hammond <chipx86@chipx86.com>
parents: 5647
diff changeset
527
5644
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
528 return optmenu;
213e999fa5cc [gaim-migrate @ 6058]
Christian Hammond <chipx86@chipx86.com>
parents: 5641
diff changeset
529 }
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
530
8940
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
531 GaimAccount *
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
532 gaim_gtk_account_option_menu_get_selected(GtkWidget *optmenu)
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
533 {
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
534 GtkWidget *menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
535 GtkWidget *item = gtk_menu_get_active(GTK_MENU(menu));
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
536 return g_object_get_data(G_OBJECT(item), "account");
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
537 }
b875f5d57b81 [gaim-migrate @ 9710]
Mark Doliner <mark@kingant.net>
parents: 8913
diff changeset
538
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
539 static void
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
540 account_menu_cb(GtkWidget *optmenu, GCallback cb)
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
541 {
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
542 GtkWidget *menu;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
543 GtkWidget *item;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
544 GaimAccount *account;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
545 gpointer user_data;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
546
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
547 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
548 item = gtk_menu_get_active(GTK_MENU(menu));
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
549
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
550 account = g_object_get_data(G_OBJECT(item), "account");
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
551 user_data = g_object_get_data(G_OBJECT(optmenu), "user_data");
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
552
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
553 if (cb != NULL)
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
554 ((void (*)(GtkWidget *, GaimAccount *, gpointer))cb)(item, account,
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
555 user_data);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
556 }
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
557
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
558 static void
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
559 create_account_menu(GtkWidget *optmenu, GaimAccount *default_account,
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
560 GaimFilterAccountFunc filter_func, gboolean show_all)
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
561 {
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
562 GaimAccount *account;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
563 GtkWidget *menu;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
564 GtkWidget *item;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
565 GtkWidget *image;
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
566 GtkWidget *hbox;
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
567 GtkWidget *label;
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
568 GdkPixbuf *pixbuf;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
569 GdkPixbuf *scale;
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
570 GList *list;
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
571 GList *p;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
572 GtkSizeGroup *sg;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
573 char *filename;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
574 const char *proto_name;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
575 char buf[256];
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
576 int i, selected_index = -1;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
577
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
578 if (show_all)
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
579 list = gaim_accounts_get_all();
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
580 else
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
581 list = gaim_connections_get_all();
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
582
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
583 menu = gtk_menu_new();
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
584 gtk_widget_show(menu);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
585
5880
1b85ff65be57 [gaim-migrate @ 6312]
Christian Hammond <chipx86@chipx86.com>
parents: 5879
diff changeset
586 sg = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
587
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
588 for (p = list, i = 0; p != NULL; p = p->next, i++) {
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
589 GaimPluginProtocolInfo *prpl_info = NULL;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
590 GaimPlugin *plugin;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
591
5879
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
592 if (show_all)
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
593 account = (GaimAccount *)p->data;
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
594 else {
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
595 GaimConnection *gc = (GaimConnection *)p->data;
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
596
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
597 account = gaim_connection_get_account(gc);
d58406d31a1a [gaim-migrate @ 6311]
Christian Hammond <chipx86@chipx86.com>
parents: 5877
diff changeset
598 }
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
599
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
600 if (filter_func && !filter_func(account)) {
8215
83830cb8467e [gaim-migrate @ 8938]
Nathan Walp <nwalp@pidgin.im>
parents: 8155
diff changeset
601 i--;
6646
b89d98f0bf79 [gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents: 6485
diff changeset
602 continue;
8215
83830cb8467e [gaim-migrate @ 8938]
Nathan Walp <nwalp@pidgin.im>
parents: 8155
diff changeset
603 }
6646
b89d98f0bf79 [gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents: 6485
diff changeset
604
7956
1b8261f374ea [gaim-migrate @ 8631]
Nathan Walp <nwalp@pidgin.im>
parents: 7943
diff changeset
605 plugin = gaim_find_prpl(gaim_account_get_protocol_id(account));
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
606
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
607 if (plugin != NULL)
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
608 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
609
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
610 /* Create the item. */
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
611 item = gtk_menu_item_new();
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
612
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
613 /* Create the hbox. */
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
614 hbox = gtk_hbox_new(FALSE, 4);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
615 gtk_container_add(GTK_CONTAINER(item), hbox);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
616 gtk_widget_show(hbox);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
617
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
618 /* Load the image. */
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
619 if (prpl_info != NULL) {
6430
5211873190ea [gaim-migrate @ 6938]
Sean Egan <seanegan@gmail.com>
parents: 6429
diff changeset
620 proto_name = prpl_info->list_icon(account, NULL);
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
621 g_snprintf(buf, sizeof(buf), "%s.png", proto_name);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
622
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
623 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
8155
77d1252b3803 [gaim-migrate @ 8867]
Christian Hammond <chipx86@chipx86.com>
parents: 8143
diff changeset
624 "default", buf, NULL);
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
625 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
626 g_free(filename);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
627
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
628 if (pixbuf != NULL) {
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
629 /* Scale and insert the image */
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
630 scale = gdk_pixbuf_scale_simple(pixbuf, 16, 16,
8155
77d1252b3803 [gaim-migrate @ 8867]
Christian Hammond <chipx86@chipx86.com>
parents: 8143
diff changeset
631 GDK_INTERP_BILINEAR);
77d1252b3803 [gaim-migrate @ 8867]
Christian Hammond <chipx86@chipx86.com>
parents: 8143
diff changeset
632
11251
ad9a61894d9b [gaim-migrate @ 13420]
Mark Doliner <mark@kingant.net>
parents: 11243
diff changeset
633 if (gaim_account_is_disconnected(account) && show_all &&
8215
83830cb8467e [gaim-migrate @ 8938]
Nathan Walp <nwalp@pidgin.im>
parents: 8155
diff changeset
634 gaim_connections_get_all())
8155
77d1252b3803 [gaim-migrate @ 8867]
Christian Hammond <chipx86@chipx86.com>
parents: 8143
diff changeset
635 gdk_pixbuf_saturate_and_pixelate(scale, scale, 0.0, FALSE);
77d1252b3803 [gaim-migrate @ 8867]
Christian Hammond <chipx86@chipx86.com>
parents: 8143
diff changeset
636
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
637 image = gtk_image_new_from_pixbuf(scale);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
638
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
639 g_object_unref(G_OBJECT(pixbuf));
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
640 g_object_unref(G_OBJECT(scale));
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
641 }
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
642 else
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
643 image = gtk_image_new();
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
644 }
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
645 else
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
646 image = gtk_image_new();
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
647
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
648 gtk_size_group_add_widget(sg, image);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
649
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
650 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
651 gtk_widget_show(image);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
652
11017
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
653 if (gaim_account_get_alias(account)) {
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
654 g_snprintf(buf, sizeof(buf), "%s (%s) (%s)",
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
655 gaim_account_get_username(account),
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
656 gaim_account_get_alias(account),
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
657 gaim_account_get_protocol_name(account));
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
658 } else {
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
659 g_snprintf(buf, sizeof(buf), "%s (%s)",
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
660 gaim_account_get_username(account),
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
661 gaim_account_get_protocol_name(account));
829ab6b71ffe [gaim-migrate @ 12886]
Etan Reisner <pidgin@unreliablesource.net>
parents: 10951
diff changeset
662 }
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
663
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
664 /* Create the label. */
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
665 label = gtk_label_new(buf);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
666 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
667 gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
668 gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
669 gtk_widget_show(label);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
670
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
671 g_object_set_data(G_OBJECT(item), "account", account);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
672
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
673 gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
674 gtk_widget_show(item);
8137
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
675 gaim_set_accessible_label (item, label);
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
676
5880
1b85ff65be57 [gaim-migrate @ 6312]
Christian Hammond <chipx86@chipx86.com>
parents: 5879
diff changeset
677 if (default_account != NULL && account == default_account)
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
678 selected_index = i;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
679 }
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
680
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
681 g_object_unref(sg);
5880
1b85ff65be57 [gaim-migrate @ 6312]
Christian Hammond <chipx86@chipx86.com>
parents: 5879
diff changeset
682
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
683 gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
684
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
685 /* Set the place we should be at. */
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
686 if (selected_index != -1)
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
687 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), selected_index);
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
688 }
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
689
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
690 static void
8134
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
691 regenerate_account_menu(GtkWidget *optmenu)
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
692 {
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
693 GtkWidget *menu;
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
694 GtkWidget *item;
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
695 gboolean show_all;
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
696 GaimAccount *account;
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
697 GaimFilterAccountFunc filter_func;
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
698
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
699 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
700 item = gtk_menu_get_active(GTK_MENU(menu));
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
701 account = g_object_get_data(G_OBJECT(item), "account");
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
702
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
703 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu),
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
704 "show_all"));
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
705
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
706 filter_func = g_object_get_data(G_OBJECT(optmenu),
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
707 "filter_func");
6646
b89d98f0bf79 [gaim-migrate @ 7171]
Christian Hammond <chipx86@chipx86.com>
parents: 6485
diff changeset
708
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
709 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu));
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
710
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
711 create_account_menu(optmenu, account, filter_func, show_all);
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
712 }
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
713
8134
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
714 static void
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
715 account_menu_sign_on_off_cb(GaimConnection *gc, GtkWidget *optmenu)
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
716 {
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
717 regenerate_account_menu(optmenu);
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
718 }
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
719
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
720 static void
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
721 account_menu_added_removed_cb(GaimAccount *account, GtkWidget *optmenu)
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
722 {
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
723 regenerate_account_menu(optmenu);
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
724 }
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
725
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
726 static gboolean
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
727 account_menu_destroyed_cb(GtkWidget *optmenu, GdkEvent *event,
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
728 void *user_data)
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
729 {
6485
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
730 gaim_signals_disconnect_by_handle(optmenu);
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
731
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
732 return FALSE;
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
733 }
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
734
9910
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
735 void
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
736 gaim_gtk_account_option_menu_set_selected(GtkWidget *optmenu, GaimAccount *account)
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
737 {
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
738 GtkWidget *menu;
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
739 GtkWidget *item;
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
740 gboolean show_all;
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
741 GaimAccount *curaccount;
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
742 GaimFilterAccountFunc filter_func;
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
743
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
744 menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
745 item = gtk_menu_get_active(GTK_MENU(menu));
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
746 curaccount = g_object_get_data(G_OBJECT(item), "account");
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
747
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
748 if (account == curaccount)
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
749 return;
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
750
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
751 show_all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(optmenu),
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
752 "show_all"));
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
753
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
754 filter_func = g_object_get_data(G_OBJECT(optmenu),
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
755 "filter_func");
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
756
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
757 gtk_option_menu_remove_menu(GTK_OPTION_MENU(optmenu));
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
758
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
759 create_account_menu(optmenu, account, filter_func, show_all);
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
760 }
0cb20555b3ab [gaim-migrate @ 10802]
Luke Schierer <lschiere@pidgin.im>
parents: 9899
diff changeset
761
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
762 GtkWidget *
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
763 gaim_gtk_account_option_menu_new(GaimAccount *default_account,
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
764 gboolean show_all, GCallback cb,
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
765 GaimFilterAccountFunc filter_func,
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
766 gpointer user_data)
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
767 {
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
768 GtkWidget *optmenu;
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
769
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
770 /* Create the option menu */
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
771 optmenu = gtk_option_menu_new();
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
772 gtk_widget_show(optmenu);
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
773
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
774 g_signal_connect(G_OBJECT(optmenu), "destroy",
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
775 G_CALLBACK(account_menu_destroyed_cb), NULL);
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
776
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
777 /* Register the gaim sign on/off event callbacks. */
6485
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
778 gaim_signal_connect(gaim_connections_get_handle(), "signed-on",
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
779 optmenu, GAIM_CALLBACK(account_menu_sign_on_off_cb),
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
780 optmenu);
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
781 gaim_signal_connect(gaim_connections_get_handle(), "signed-off",
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
782 optmenu, GAIM_CALLBACK(account_menu_sign_on_off_cb),
70d5122bc3ff [gaim-migrate @ 6999]
Christian Hammond <chipx86@chipx86.com>
parents: 6465
diff changeset
783 optmenu);
8134
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
784 gaim_signal_connect(gaim_accounts_get_handle(), "account-added",
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
785 optmenu, GAIM_CALLBACK(account_menu_added_removed_cb),
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
786 optmenu);
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
787 gaim_signal_connect(gaim_accounts_get_handle(), "account-removed",
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
788 optmenu, GAIM_CALLBACK(account_menu_added_removed_cb),
ea3eb461efc0 [gaim-migrate @ 8839]
Nathan Walp <nwalp@pidgin.im>
parents: 8061
diff changeset
789 optmenu);
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
790
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
791 /* Set some data. */
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
792 g_object_set_data(G_OBJECT(optmenu), "user_data", user_data);
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
793 g_object_set_data(G_OBJECT(optmenu), "show_all", GINT_TO_POINTER(show_all));
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
794 g_object_set_data(G_OBJECT(optmenu), "filter_func",
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
795 filter_func);
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
796
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
797 /* Create and set the actual menu. */
8289
e39ea2b4f6cd [gaim-migrate @ 9013]
Christian Hammond <chipx86@chipx86.com>
parents: 8247
diff changeset
798 create_account_menu(optmenu, default_account, filter_func, show_all);
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
799
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
800 /* And now the last callback. */
5877
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
801 g_signal_connect(G_OBJECT(optmenu), "changed",
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
802 G_CALLBACK(account_menu_cb), cb);
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
803
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
804 return optmenu;
f336fc0a7b8b [gaim-migrate @ 6309]
Christian Hammond <chipx86@chipx86.com>
parents: 5872
diff changeset
805 }
5943
a4f2aba0848d [gaim-migrate @ 6384]
Christian Hammond <chipx86@chipx86.com>
parents: 5906
diff changeset
806
6391
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
807 gboolean
4b2d8d7d0118 [gaim-migrate @ 6896]
Christian Hammond <chipx86@chipx86.com>
parents: 6372
diff changeset
808 gaim_gtk_check_if_dir(const char *path, GtkFileSelection *filesel)
5966
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
809 {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
810 char *dirname;
5966
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
811
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
812 if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
5966
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
813 /* append a / if needed */
9534
6f0c90000bb5 [gaim-migrate @ 10362]
Mark Doliner <mark@kingant.net>
parents: 9497
diff changeset
814 if (path[strlen(path) - 1] != G_DIR_SEPARATOR) {
6f0c90000bb5 [gaim-migrate @ 10362]
Mark Doliner <mark@kingant.net>
parents: 9497
diff changeset
815 dirname = g_strconcat(path, G_DIR_SEPARATOR_S, NULL);
5966
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
816 } else {
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
817 dirname = g_strdup(path);
5966
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
818 }
5967
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
819 gtk_file_selection_set_filename(filesel, dirname);
156953fe3e14 [gaim-migrate @ 6414]
Mark Doliner <mark@kingant.net>
parents: 5966
diff changeset
820 g_free(dirname);
5966
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
821 return TRUE;
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
822 }
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
823
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
824 return FALSE;
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
825 }
5fb6bd688a5b [gaim-migrate @ 6413]
Mark Doliner <mark@kingant.net>
parents: 5959
diff changeset
826
12067
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
827 void
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
828 gaim_gtk_setup_gtkspell(GtkTextView *textview)
12061
29dc8fc0dd6c [gaim-migrate @ 14356]
Richard Laager <rlaager@wiktel.com>
parents: 11878
diff changeset
829 {
12067
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
830 #ifdef USE_GTKSPELL
7538
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
831 GError *error = NULL;
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
832 char *locale = NULL;
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
833
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
834 g_return_if_fail(textview != NULL);
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
835 g_return_if_fail(GTK_IS_TEXT_VIEW(textview));
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
836
12067
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
837 if (gtkspell_new_attach(textview, locale, &error) == NULL && error)
7538
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
838 {
12067
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
839 gaim_debug_warning("gtkspell", "Failed to setup GtkSpell: %s\n",
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
840 error->message);
7538
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
841 g_error_free(error);
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
842 }
12067
e859c1663a27 [gaim-migrate @ 14362]
Richard Laager <rlaager@wiktel.com>
parents: 12063
diff changeset
843 #endif /* USE_GTKSPELL */
7538
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
844 }
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
845
357eb1c39b72 [gaim-migrate @ 8151]
Christian Hammond <chipx86@chipx86.com>
parents: 7420
diff changeset
846 void
7420
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
847 gaim_gtk_save_accels_cb(GtkAccelGroup *accel_group, guint arg1,
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
848 GdkModifierType arg2, GClosure *arg3,
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
849 gpointer data)
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
850 {
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
851 gaim_debug(GAIM_DEBUG_MISC, "accels", "accel changed, scheduling save.\n");
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
852
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
853 if (!accels_save_timer)
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
854 accels_save_timer = g_timeout_add(5000, gaim_gtk_save_accels, NULL);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
855 }
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
856
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
857 gboolean
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
858 gaim_gtk_save_accels(gpointer data)
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
859 {
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
860 char *filename = NULL;
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
861
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
862 filename = g_build_filename(gaim_user_dir(), G_DIR_SEPARATOR_S,
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
863 "accels", NULL);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
864 gaim_debug(GAIM_DEBUG_MISC, "accels", "saving accels to %s\n", filename);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
865 gtk_accel_map_save(filename);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
866 g_free(filename);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
867
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
868 accels_save_timer = 0;
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
869 return FALSE;
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
870 }
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
871
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
872 void
12322
c7ae1fd0827d [gaim-migrate @ 14626]
Richard Laager <rlaager@wiktel.com>
parents: 12114
diff changeset
873 gaim_gtk_load_accels()
7420
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
874 {
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
875 char *filename = NULL;
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
876
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
877 filename = g_build_filename(gaim_user_dir(), G_DIR_SEPARATOR_S,
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
878 "accels", NULL);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
879 gtk_accel_map_load(filename);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
880 g_free(filename);
53c86d59f20b [gaim-migrate @ 8022]
Luke Schierer <lschiere@pidgin.im>
parents: 7299
diff changeset
881 }
7712
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
882
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
883 gboolean
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
884 gaim_gtk_parse_x_im_contact(const char *msg, gboolean all_accounts,
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
885 GaimAccount **ret_account, char **ret_protocol,
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
886 char **ret_username, char **ret_alias)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
887 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
888 char *protocol = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
889 char *username = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
890 char *alias = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
891 char *str;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
892 char *c, *s;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
893 gboolean valid;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
894
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
895 g_return_val_if_fail(msg != NULL, FALSE);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
896 g_return_val_if_fail(ret_protocol != NULL, FALSE);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
897 g_return_val_if_fail(ret_username != NULL, FALSE);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
898
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
899 s = str = g_strdup(msg);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
900
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
901 while (*s != '\r' && *s != '\n' && *s != '\0')
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
902 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
903 char *key, *value;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
904
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
905 key = s;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
906
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
907 /* Grab the key */
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
908 while (*s != '\r' && *s != '\n' && *s != '\0' && *s != ' ')
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
909 s++;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
910
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
911 if (*s == '\r') s++;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
912
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
913 if (*s == '\n')
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
914 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
915 s++;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
916 continue;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
917 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
918
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
919 if (*s != '\0') *s++ = '\0';
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
920
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
921 /* Clear past any whitespace */
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
922 while (*s != '\0' && *s == ' ')
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
923 s++;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
924
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
925 /* Now let's grab until the end of the line. */
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
926 value = s;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
927
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
928 while (*s != '\r' && *s != '\n' && *s != '\0')
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
929 s++;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
930
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
931 if (*s == '\r') *s++ = '\0';
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
932 if (*s == '\n') *s++ = '\0';
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
933
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
934 if ((c = strchr(key, ':')) != NULL)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
935 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
936 if (!g_ascii_strcasecmp(key, "X-IM-Username:"))
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
937 username = g_strdup(value);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
938 else if (!g_ascii_strcasecmp(key, "X-IM-Protocol:"))
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
939 protocol = g_strdup(value);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
940 else if (!g_ascii_strcasecmp(key, "X-IM-Alias:"))
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
941 alias = g_strdup(value);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
942 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
943 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
944
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
945 if (username != NULL && protocol != NULL)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
946 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
947 valid = TRUE;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
948
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
949 *ret_username = username;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
950 *ret_protocol = protocol;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
951
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
952 if (ret_alias != NULL)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
953 *ret_alias = alias;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
954
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
955 /* Check for a compatible account. */
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
956 if (ret_account != NULL)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
957 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
958 GList *list;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
959 GaimAccount *account = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
960 GList *l;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
961 const char *protoname;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
962
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
963 if (all_accounts)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
964 list = gaim_accounts_get_all();
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
965 else
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
966 list = gaim_connections_get_all();
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
967
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
968 for (l = list; l != NULL; l = l->next)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
969 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
970 GaimConnection *gc;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
971 GaimPluginProtocolInfo *prpl_info = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
972 GaimPlugin *plugin;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
973
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
974 if (all_accounts)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
975 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
976 account = (GaimAccount *)l->data;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
977
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
978 plugin = gaim_plugins_find_with_id(
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
979 gaim_account_get_protocol_id(account));
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
980
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
981 if (plugin == NULL)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
982 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
983 account = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
984
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
985 continue;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
986 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
987
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
988 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
989 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
990 else
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
991 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
992 gc = (GaimConnection *)l->data;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
993 account = gaim_connection_get_account(gc);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
994
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
995 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
996 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
997
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
998 protoname = prpl_info->list_icon(account, NULL);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
999
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1000 if (!strcmp(protoname, protocol))
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1001 break;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1002
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1003 account = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1004 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1005
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1006 /* Special case for AIM and ICQ */
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1007 if (account == NULL && (!strcmp(protocol, "aim") ||
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1008 !strcmp(protocol, "icq")))
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1009 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1010 for (l = list; l != NULL; l = l->next)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1011 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1012 GaimConnection *gc;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1013 GaimPluginProtocolInfo *prpl_info = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1014 GaimPlugin *plugin;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1015
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1016 if (all_accounts)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1017 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1018 account = (GaimAccount *)l->data;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1019
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1020 plugin = gaim_plugins_find_with_id(
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1021 gaim_account_get_protocol_id(account));
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1022
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1023 if (plugin == NULL)
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1024 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1025 account = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1026
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1027 continue;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1028 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1029
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1030 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1031 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1032 else
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1033 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1034 gc = (GaimConnection *)l->data;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1035 account = gaim_connection_get_account(gc);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1036
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1037 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1038 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1039
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1040 protoname = prpl_info->list_icon(account, NULL);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1041
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1042 if (!strcmp(protoname, "aim") || !strcmp(protoname, "icq"))
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1043 break;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1044
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1045 account = NULL;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1046 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1047 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1048
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1049 *ret_account = account;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1050 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1051 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1052 else
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1053 {
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1054 valid = FALSE;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1055
14035
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13781
diff changeset
1056 g_free(username);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13781
diff changeset
1057 g_free(protocol);
8bda65b88e49 [gaim-migrate @ 16638]
Mark Doliner <mark@kingant.net>
parents: 13781
diff changeset
1058 g_free(alias);
7712
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1059 }
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1060
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1061 g_free(str);
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1062
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1063 return valid;
2823111061ba [gaim-migrate @ 8357]
Christian Hammond <chipx86@chipx86.com>
parents: 7538
diff changeset
1064 }
8137
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1065
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1066 void
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1067 gaim_set_accessible_label (GtkWidget *w, GtkWidget *l)
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1068 {
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1069 AtkObject *acc, *label;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1070 AtkObject *rel_obj[1];
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1071 AtkRelationSet *set;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1072 AtkRelation *relation;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1073 const gchar *label_text;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1074 const gchar *existing_name;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1075
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1076 acc = gtk_widget_get_accessible (w);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1077 label = gtk_widget_get_accessible (l);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1078
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1079 /* If this object has no name, set it's name with the label text */
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1080 existing_name = atk_object_get_name (acc);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1081 if (!existing_name) {
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1082 label_text = gtk_label_get_text (GTK_LABEL(l));
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1083 if (label_text)
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1084 atk_object_set_name (acc, label_text);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1085 }
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1086
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1087 /* Create the labeled-by relation */
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1088 set = atk_object_ref_relation_set (acc);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1089 rel_obj[0] = label;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1090 relation = atk_relation_new (rel_obj, 1, ATK_RELATION_LABELLED_BY);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1091 atk_relation_set_add (set, relation);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1092 g_object_unref (relation);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1093
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1094 /* Create the label-for relation */
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1095 set = atk_object_ref_relation_set (label);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1096 rel_obj[0] = acc;
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1097 relation = atk_relation_new (rel_obj, 1, ATK_RELATION_LABEL_FOR);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1098 atk_relation_set_add (set, relation);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1099 g_object_unref (relation);
4971193f761d [gaim-migrate @ 8842]
Mark Doliner <mark@kingant.net>
parents: 8134
diff changeset
1100 }
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1101
8247
4a6448907382 [gaim-migrate @ 8970]
Nathan Walp <nwalp@pidgin.im>
parents: 8218
diff changeset
1102 #if GTK_CHECK_VERSION(2,2,0)
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1103 static void
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1104 gaim_gtk_menu_position_func(GtkMenu *menu,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1105 gint *x,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1106 gint *y,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1107 gboolean *push_in,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1108 gpointer data)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1109 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1110 GtkWidget *widget;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1111 GtkRequisition requisition;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1112 GdkScreen *screen;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1113 GdkRectangle monitor;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1114 gint monitor_num;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1115 gint space_left, space_right, space_above, space_below;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1116 gint needed_width;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1117 gint needed_height;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1118 gint xthickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1119 gint ythickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1120 gboolean rtl;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1121
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1122 g_return_if_fail(GTK_IS_MENU(menu));
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1123
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1124 widget = GTK_WIDGET(menu);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1125 screen = gtk_widget_get_screen(widget);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1126 xthickness = widget->style->xthickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1127 ythickness = widget->style->ythickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1128 rtl = (gtk_widget_get_direction(widget) == GTK_TEXT_DIR_RTL);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1129
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1130 /*
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1131 * We need the requisition to figure out the right place to
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1132 * popup the menu. In fact, we always need to ask here, since
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1133 * if a size_request was queued while we weren't popped up,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1134 * the requisition won't have been recomputed yet.
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1135 */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1136 gtk_widget_size_request (widget, &requisition);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1137
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1138 monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1139
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1140 push_in = FALSE;
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
1141
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1142 /*
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1143 * The placement of popup menus horizontally works like this (with
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1144 * RTL in parentheses)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1145 *
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1146 * - If there is enough room to the right (left) of the mouse cursor,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1147 * position the menu there.
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
1148 *
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
1149 * - Otherwise, if if there is enough room to the left (right) of the
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1150 * mouse cursor, position the menu there.
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
1151 *
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1152 * - Otherwise if the menu is smaller than the monitor, position it
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1153 * on the side of the mouse cursor that has the most space available
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1154 *
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1155 * - Otherwise (if there is simply not enough room for the menu on the
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1156 * monitor), position it as far left (right) as possible.
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1157 *
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1158 * Positioning in the vertical direction is similar: first try below
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1159 * mouse cursor, then above.
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1160 */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1161 gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1162
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1163 space_left = *x - monitor.x;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1164 space_right = monitor.x + monitor.width - *x - 1;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1165 space_above = *y - monitor.y;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1166 space_below = monitor.y + monitor.height - *y - 1;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1167
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1168 /* position horizontally */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1169
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1170 /* the amount of space we need to position the menu. Note the
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
1171 * menu is offset "xthickness" pixels
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1172 */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1173 needed_width = requisition.width - xthickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1174
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1175 if (needed_width <= space_left ||
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1176 needed_width <= space_right)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1177 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1178 if ((rtl && needed_width <= space_left) ||
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1179 (!rtl && needed_width > space_right))
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1180 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1181 /* position left */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1182 *x = *x + xthickness - requisition.width + 1;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1183 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1184 else
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1185 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1186 /* position right */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1187 *x = *x - xthickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1188 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1189
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1190 /* x is clamped on-screen further down */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1191 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1192 else if (requisition.width <= monitor.width)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1193 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1194 /* the menu is too big to fit on either side of the mouse
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1195 * cursor, but smaller than the monitor. Position it on
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1196 * the side that has the most space
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1197 */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1198 if (space_left > space_right)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1199 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1200 /* left justify */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1201 *x = monitor.x;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1202 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1203 else
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1204 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1205 /* right justify */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1206 *x = monitor.x + monitor.width - requisition.width;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1207 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1208 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1209 else /* menu is simply too big for the monitor */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1210 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1211 if (rtl)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1212 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1213 /* right justify */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1214 *x = monitor.x + monitor.width - requisition.width;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1215 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1216 else
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1217 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1218 /* left justify */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1219 *x = monitor.x;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1220 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1221 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1222
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1223 /* Position vertically. The algorithm is the same as above, but
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1224 * simpler because we don't have to take RTL into account.
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1225 */
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1226 needed_height = requisition.height - ythickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1227
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1228 if (needed_height <= space_above ||
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1229 needed_height <= space_below)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1230 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1231 if (needed_height <= space_below)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1232 *y = *y - ythickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1233 else
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1234 *y = *y + ythickness - requisition.height + 1;
11525
b47708f46a38 [gaim-migrate @ 13773]
Tim Ringenbach <marv@pidgin.im>
parents: 11338
diff changeset
1235
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1236 *y = CLAMP (*y, monitor.y,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1237 monitor.y + monitor.height - requisition.height);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1238 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1239 else if (needed_height > space_below && needed_height > space_above)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1240 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1241 if (space_below >= space_above)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1242 *y = monitor.y + monitor.height - requisition.height;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1243 else
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1244 *y = monitor.y;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1245 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1246 else
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1247 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1248 *y = monitor.y;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1249 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1250 }
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1251
8247
4a6448907382 [gaim-migrate @ 8970]
Nathan Walp <nwalp@pidgin.im>
parents: 8218
diff changeset
1252 #endif
4a6448907382 [gaim-migrate @ 8970]
Nathan Walp <nwalp@pidgin.im>
parents: 8218
diff changeset
1253
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1254 void
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1255 gaim_gtk_treeview_popup_menu_position_func(GtkMenu *menu,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1256 gint *x,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1257 gint *y,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1258 gboolean *push_in,
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1259 gpointer data)
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1260 {
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1261 GtkWidget *widget = GTK_WIDGET(data);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1262 GtkTreeView *tv = GTK_TREE_VIEW(data);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1263 GtkTreePath *path;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1264 GtkTreeViewColumn *col;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1265 GdkRectangle rect;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1266 gint ythickness = GTK_WIDGET(menu)->style->ythickness;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1267
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1268 gdk_window_get_origin (widget->window, x, y);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1269 gtk_tree_view_get_cursor (tv, &path, &col);
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1270 gtk_tree_view_get_cell_area (tv, path, col, &rect);
8218
4beaf6b35483 [gaim-migrate @ 8941]
Christian Hammond <chipx86@chipx86.com>
parents: 8215
diff changeset
1271
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1272 *x += rect.x+rect.width;
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1273 *y += rect.y+rect.height+ythickness;
8247
4a6448907382 [gaim-migrate @ 8970]
Nathan Walp <nwalp@pidgin.im>
parents: 8218
diff changeset
1274 #if GTK_CHECK_VERSION(2,2,0)
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1275 gaim_gtk_menu_position_func (menu, x, y, push_in, data);
8247
4a6448907382 [gaim-migrate @ 8970]
Nathan Walp <nwalp@pidgin.im>
parents: 8218
diff changeset
1276 #endif
8143
8633dc570442 [gaim-migrate @ 8851]
Mark Doliner <mark@kingant.net>
parents: 8137
diff changeset
1277 }
10061
83eb12b1f1a1 [gaim-migrate @ 11033]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9910
diff changeset
1278
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1279 enum {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1280 DND_FILE_TRANSFER,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1281 DND_IM_IMAGE,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1282 DND_BUDDY_ICON
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1283 };
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1284
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1285 typedef struct {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1286 char *filename;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1287 GaimAccount *account;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1288 char *who;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1289 } _DndData;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1290
10850
fa06fda62868 [gaim-migrate @ 12522]
Mark Doliner <mark@kingant.net>
parents: 10681
diff changeset
1291 static void dnd_image_ok_callback(_DndData *data, int choice)
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1292 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1293 char *filedata;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1294 size_t size;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1295 GError *err = NULL;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1296 GaimConversation *conv;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1297 GaimGtkConversation *gtkconv;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1298 GtkTextIter iter;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1299 int id;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1300 switch (choice) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1301 case DND_BUDDY_ICON:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1302 if (!g_file_get_contents(data->filename, &filedata, &size,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1303 &err)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1304 char *str;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1305
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1306 str = g_strdup_printf(_("The following error has occurred loading %s: %s"), data->filename, err->message);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1307 gaim_notify_error(NULL, NULL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1308 _("Failed to load image"),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1309 str);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1310
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1311 g_error_free(err);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1312 g_free(str);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1313
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1314 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1315 }
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1316
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1317 gaim_buddy_icons_set_for_user(data->account, data->who, filedata, size);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1318 g_free(filedata);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1319 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1320 case DND_FILE_TRANSFER:
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1321 serv_send_file(gaim_account_get_connection(data->account), data->who, data->filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1322 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1323 case DND_IM_IMAGE:
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 11251
diff changeset
1324 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, data->account, data->who);
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1325 gtkconv = GAIM_GTK_CONVERSATION(conv);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1326
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1327 if (!g_file_get_contents(data->filename, &filedata, &size,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1328 &err)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1329 char *str;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1330
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1331 str = g_strdup_printf(_("The following error has occurred loading %s: %s"), data->filename, err->message);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1332 gaim_notify_error(NULL, NULL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1333 _("Failed to load image"),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1334 str);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1335
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1336 g_error_free(err);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1337 g_free(str);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1338
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1339 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1340 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1341 id = gaim_imgstore_add(filedata, size, data->filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1342 g_free(filedata);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1343
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1344 gtk_text_buffer_get_iter_at_mark(GTK_IMHTML(gtkconv->entry)->text_buffer, &iter,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1345 gtk_text_buffer_get_insert(GTK_IMHTML(gtkconv->entry)->text_buffer));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1346 gtk_imhtml_insert_image_at_iter(GTK_IMHTML(gtkconv->entry), id, &iter);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1347 gaim_imgstore_unref(id);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1348
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1349 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1350 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1351 free(data->filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1352 free(data->who);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1353 free(data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1354 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1355
10850
fa06fda62868 [gaim-migrate @ 12522]
Mark Doliner <mark@kingant.net>
parents: 10681
diff changeset
1356 static void dnd_image_cancel_callback(_DndData *data, int choice)
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1357 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1358 free(data->filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1359 free(data->who);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1360 free(data);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1361 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1362
11110
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1363 static void dnd_set_icon_ok_cb(_DndData *data)
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1364 {
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1365 dnd_image_ok_callback(data, DND_BUDDY_ICON);
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1366 }
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1367
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1368 static void dnd_set_icon_cancel_cb(_DndData *data)
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1369 {
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1370 free(data->filename);
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1371 free(data->who);
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1372 free(data);
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1373 }
f7ce10cad83d [gaim-migrate @ 13162]
Richard Laager <rlaager@wiktel.com>
parents: 11017
diff changeset
1374
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1375 void
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1376 gaim_dnd_file_manage(GtkSelectionData *sd, GaimAccount *account, const char *who)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1377 {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1378 GList *tmp;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1379 GdkPixbuf *pb;
11135
f2755f58a7da [gaim-migrate @ 13196]
Mark Doliner <mark@kingant.net>
parents: 11110
diff changeset
1380 GList *files = gaim_uri_list_extract_filenames((const gchar *)sd->data);
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1381 GaimConnection *gc = gaim_account_get_connection(account);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1382 GaimPluginProtocolInfo *prpl_info = NULL;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1383 gboolean file_send_ok = FALSE;
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1384 #ifndef _WIN32
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1385 GaimDesktopItem *item;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1386 #endif
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1387
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1388 g_return_if_fail(account != NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1389 g_return_if_fail(who != NULL);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1390
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1391 for(tmp = files; tmp != NULL ; tmp = g_list_next(tmp)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1392 gchar *filename = tmp->data;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1393 gchar *basename = g_path_get_basename(filename);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1394
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1395 /* Set the default action: don't send anything */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1396 file_send_ok = FALSE;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1397
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1398 /* XXX - Make ft API support creating a transfer with more than one file */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1399 if (!g_file_test(filename, G_FILE_TEST_EXISTS)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1400 continue;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1401 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1402
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1403 /* XXX - make ft api suupport sending a directory */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1404 /* Are we dealing with a directory? */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1405 if (g_file_test(filename, G_FILE_TEST_IS_DIR)) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1406 char *str;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1407
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1408 str = g_strdup_printf(_("Cannot send folder %s."), basename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1409 gaim_notify_error(NULL, NULL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1410 str,_("Gaim cannot transfer a folder. You will need to send the files within individually"));
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1411
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1412 g_free(str);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1413
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1414 continue;
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1415 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1416
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1417 /* Are we dealing with an image? */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1418 pb = gdk_pixbuf_new_from_file(filename, NULL);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1419 if (pb) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1420 _DndData *data = g_malloc(sizeof(_DndData));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1421 gboolean ft = FALSE, im = FALSE;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1422
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1423 data->who = g_strdup(who);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1424 data->filename = g_strdup(filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1425 data->account = account;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1426
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1427 if (gc)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1428 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(gc->prpl);
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10335
diff changeset
1429
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1430 if (prpl_info && prpl_info->options & OPT_PROTO_IM_IMAGE)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1431 im = TRUE;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1432
10348
64bc206c7473 [gaim-migrate @ 11562]
Mark Doliner <mark@kingant.net>
parents: 10335
diff changeset
1433 if (prpl_info && prpl_info->can_receive_file)
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1434 ft = prpl_info->can_receive_file(gc, who);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1435
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1436 if (im && ft)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1437 gaim_request_choice(NULL, NULL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1438 _("You have dragged an image"),
10951
84d8279259c9 [gaim-migrate @ 12751]
Mark Doliner <mark@kingant.net>
parents: 10871
diff changeset
1439 _("You can send this image as a file transfer, "
84d8279259c9 [gaim-migrate @ 12751]
Mark Doliner <mark@kingant.net>
parents: 10871
diff changeset
1440 "embed it into this message, or use it as the buddy icon for this user."),
13100
b0cbc4a3675d [gaim-migrate @ 15462]
Richard Laager <rlaager@wiktel.com>
parents: 13099
diff changeset
1441 DND_FILE_TRANSFER, "OK", (GCallback)dnd_image_ok_callback,
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1442 "Cancel", (GCallback)dnd_image_cancel_callback, data,
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1443 _("Set as buddy icon"), DND_BUDDY_ICON,
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1444 _("Send image file"), DND_FILE_TRANSFER,
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1445 _("Insert in message"), DND_IM_IMAGE, NULL);
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1446 else if (!(im || ft))
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1447 gaim_request_yes_no(NULL, NULL, _("You have dragged an image"),
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1448 _("Would you like to set it as the buddy icon for this user?"),
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1449 0, data, (GCallback)dnd_set_icon_ok_cb, (GCallback)dnd_set_icon_cancel_cb);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1450 else
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1451 gaim_request_choice(NULL, NULL,
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1452 _("You have dragged an image"),
10951
84d8279259c9 [gaim-migrate @ 12751]
Mark Doliner <mark@kingant.net>
parents: 10871
diff changeset
1453 ft ? _("You can send this image as a file transfer or "
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1454 "embed it into this message, or use it as the buddy icon for this user.") :
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1455 _("You can insert this image into this message, or use it as the buddy icon for this user"),
13100
b0cbc4a3675d [gaim-migrate @ 15462]
Richard Laager <rlaager@wiktel.com>
parents: 13099
diff changeset
1456 ft ? DND_FILE_TRANSFER : DND_IM_IMAGE, "OK", (GCallback)dnd_image_ok_callback,
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1457 "Cancel", (GCallback)dnd_image_cancel_callback, data,
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1458 _("Set as buddy icon"), DND_BUDDY_ICON,
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1459 ft ? _("Send image file") : _("Insert in message"), ft ? DND_FILE_TRANSFER : DND_IM_IMAGE, NULL);
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1460 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1461 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1462
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1463 #ifndef _WIN32
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1464 /* Are we trying to send a .desktop file? */
11780
8cb75ba77f9d [gaim-migrate @ 14071]
Stu Tomlinson <stu@nosnilmot.com>
parents: 11638
diff changeset
1465 else if (gaim_str_has_suffix(basename, ".desktop") && (item = gaim_desktop_item_new_from_file(filename))) {
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1466 GaimDesktopItemType dtype;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1467 char key[64];
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1468 const char *itemname = NULL;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1469
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1470 #if GTK_CHECK_VERSION(2,6,0)
10679
dbdf6618cc49 [gaim-migrate @ 12225]
Nathan Walp <nwalp@pidgin.im>
parents: 10590
diff changeset
1471 const char * const *langs;
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1472 int i;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1473 langs = g_get_language_names();
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1474 for (i = 0; langs[i]; i++) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1475 g_snprintf(key, sizeof(key), "Name[%s]", langs[i]);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1476 itemname = gaim_desktop_item_get_string(item, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1477 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1478 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1479 #else
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1480 const char *lang = g_getenv("LANG");
10681
d29fae081061 [gaim-migrate @ 12227]
Mark Doliner <mark@kingant.net>
parents: 10679
diff changeset
1481 char *dot;
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1482 dot = strchr(lang, '.');
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1483 if (dot)
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1484 *dot = '\0';
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1485 g_snprintf(key, sizeof(key), "Name[%s]", lang);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1486 itemname = gaim_desktop_item_get_string(item, key);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1487 #endif
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1488 if (!itemname)
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1489 itemname = gaim_desktop_item_get_string(item, "Name");
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1490
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1491 dtype = gaim_desktop_item_get_entry_type(item);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1492 switch (dtype) {
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1493 GaimConversation *conv;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1494 GaimGtkConversation *gtkconv;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1495
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1496 case GAIM_DESKTOP_ITEM_TYPE_LINK:
11338
17142948653e [gaim-migrate @ 13551]
Mark Doliner <mark@kingant.net>
parents: 11251
diff changeset
1497 conv = gaim_conversation_new(GAIM_CONV_TYPE_IM, account, who);
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1498 gtkconv = GAIM_GTK_CONVERSATION(conv);
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1499 gtk_imhtml_insert_link(GTK_IMHTML(gtkconv->entry),
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1500 gtk_text_buffer_get_insert(GTK_IMHTML(gtkconv->entry)->text_buffer),
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1501 gaim_desktop_item_get_string(item, "URL"), itemname);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1502 break;
10335
20e750dd21a0 [gaim-migrate @ 11542]
Mark Doliner <mark@kingant.net>
parents: 10240
diff changeset
1503 default:
10229
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1504 /* I don't know if we really want to do anything here. Most of the desktop item types are crap like
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1505 * "MIME Type" (I have no clue how that would be a desktop item) and "Comment"... nothing we can really
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1506 * send. The only logical one is "Application," but do we really want to send a binary and nothing else?
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1507 * Probably not. I'll just give an error and return. */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1508 /* The original patch sent the icon used by the launcher. That's probably wrong */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1509 gaim_notify_error(NULL, NULL, _("Cannot send launcher"), _("You dragged a desktop launcher. "
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1510 "Most likely you wanted to send whatever this launcher points to instead of this launcher"
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1511 " itself."));
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1512 break;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1513 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1514 gaim_desktop_item_unref(item);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1515 return;
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1516 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1517 #endif /* _WIN32 */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1518
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1519 /* Everything is fine, let's send */
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1520 serv_send_file(gc, who, filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1521 g_free(filename);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1522 }
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1523 g_list_free(files);
9aa0b6d11bbf [gaim-migrate @ 11364]
Sean Egan <seanegan@gmail.com>
parents: 10209
diff changeset
1524 }
10483
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1525
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1526 void gaim_gtk_buddy_icon_get_scale_size(GdkPixbuf *buf, GaimBuddyIconSpec *spec, int *width, int *height)
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1527 {
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1528 *width = gdk_pixbuf_get_width(buf);
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1529 *height = gdk_pixbuf_get_height(buf);
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1530
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1531 gaim_buddy_icon_get_scale_size(spec, width, height);
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1532
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1533 /* and now for some arbitrary sanity checks */
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1534 if(*width > 100)
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1535 *width = 100;
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1536 if(*height > 100)
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1537 *height = 100;
748aa3c6de36 [gaim-migrate @ 11773]
Nathan Walp <nwalp@pidgin.im>
parents: 10348
diff changeset
1538 }
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1539
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1540 GdkPixbuf *
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1541 gaim_gtk_create_prpl_icon(GaimAccount *account, double scale_factor)
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1542 {
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1543 GaimPlugin *prpl;
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1544 GaimPluginProtocolInfo *prpl_info;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1545 const char *protoname = NULL;
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1546 char buf[256]; /* TODO: We should use a define for max file length */
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1547 char *filename = NULL;
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1548 GdkPixbuf *pixbuf, *scaled;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1549
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1550 g_return_val_if_fail(account != NULL, NULL);
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1551
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1552 prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1553 if (prpl == NULL)
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1554 return NULL;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1555
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1556 prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1557 if (prpl_info->list_icon == NULL)
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1558 return NULL;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1559
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1560 protoname = prpl_info->list_icon(account, NULL);
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1561 if (protoname == NULL)
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1562 return NULL;
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1563
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1564 /*
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1565 * Status icons will be themeable too, and then it will look up
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1566 * protoname from the theme
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1567 */
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1568 g_snprintf(buf, sizeof(buf), "%s.png", protoname);
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1569
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1570 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1571 "default", buf, NULL);
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1572 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1573 g_free(filename);
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1574
13109
079f7a452e3a [gaim-migrate @ 15471]
Mark Doliner <mark@kingant.net>
parents: 13102
diff changeset
1575 scaled = gdk_pixbuf_scale_simple(pixbuf, 32*scale_factor,
079f7a452e3a [gaim-migrate @ 15471]
Mark Doliner <mark@kingant.net>
parents: 13102
diff changeset
1576 32*scale_factor, GDK_INTERP_BILINEAR);
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1577 g_object_unref(pixbuf);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1578
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1579 return scaled;
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1580 }
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1581
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1582 static GdkPixbuf *
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1583 overlay_status_onto_icon(GdkPixbuf *pixbuf, GaimStatusPrimitive primitive)
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1584 {
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1585 const char *type_name;
13113
7a05525e4197 [gaim-migrate @ 15475]
Richard Laager <rlaager@wiktel.com>
parents: 13109
diff changeset
1586 char basename[256];
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1587 char *filename;
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1588 GdkPixbuf *emblem;
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1589
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1590 type_name = gaim_primitive_get_id_from_type(primitive);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1591
13113
7a05525e4197 [gaim-migrate @ 15475]
Richard Laager <rlaager@wiktel.com>
parents: 13109
diff changeset
1592 g_snprintf(basename, sizeof(basename), "%s.png", type_name);
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1593 filename = g_build_filename(DATADIR, "pixmaps", "gaim", "status",
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1594 "default", basename, NULL);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1595 emblem = gdk_pixbuf_new_from_file(filename, NULL);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1596 g_free(filename);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1597
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1598 if (emblem != NULL) {
13091
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1599 int width, height, emblem_width, emblem_height;
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1600 int new_emblem_width, new_emblem_height;
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1601
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1602 width = gdk_pixbuf_get_width(pixbuf);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1603 height = gdk_pixbuf_get_height(pixbuf);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1604 emblem_width = gdk_pixbuf_get_width(emblem);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1605 emblem_height = gdk_pixbuf_get_height(emblem);
13091
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1606
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1607 /*
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1608 * Figure out how big to make the emblem. Normally the emblem
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1609 * will have half the width of the pixbuf. But we don't make
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1610 * an emblem any smaller than 10 pixels because it becomes
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1611 * unrecognizable, unless the width of the pixbuf is less than
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1612 * 10 pixels, in which case we make the emblem width the same
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1613 * as the pixbuf width.
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1614 */
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1615 new_emblem_width = MAX(width / 2, MIN(width, 10));
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1616 new_emblem_height = MAX(height / 2, MIN(height, 10));
7aea8de78463 [gaim-migrate @ 15453]
Mark Doliner <mark@kingant.net>
parents: 13090
diff changeset
1617
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1618 /* Overlay emblem onto the bottom right corner of pixbuf */
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1619 gdk_pixbuf_composite(emblem, pixbuf,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1620 width - new_emblem_width, height - new_emblem_height,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1621 new_emblem_width, new_emblem_height,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1622 width - new_emblem_width, height - new_emblem_height,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1623 (double)new_emblem_width / (double)emblem_width,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1624 (double)new_emblem_height / (double)emblem_height,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1625 GDK_INTERP_BILINEAR,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1626 255);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1627 g_object_unref(emblem);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1628 }
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1629
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1630 return pixbuf;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1631 }
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1632
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1633 GdkPixbuf *
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1634 gaim_gtk_create_prpl_icon_with_status(GaimAccount *account, GaimStatusType *status_type, double scale_factor)
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1635 {
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1636 GdkPixbuf *pixbuf;
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1637
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1638 pixbuf = gaim_gtk_create_prpl_icon(account, scale_factor);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1639 if (pixbuf == NULL)
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1640 return NULL;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1641
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1642 /*
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1643 * TODO: Let the prpl pick the emblem on a per status basis,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1644 * and only use the primitive as a fallback?
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1645 */
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1646
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1647 return overlay_status_onto_icon(pixbuf,
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1648 gaim_status_type_get_primitive(status_type));
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1649 }
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1650
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1651 GdkPixbuf *
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1652 gaim_gtk_create_gaim_icon_with_status(GaimStatusPrimitive primitive, double scale_factor)
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1653 {
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1654 gchar *filename;
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1655 GdkPixbuf *orig, *pixbuf;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1656
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1657 filename = g_build_filename(DATADIR, "pixmaps", "gaim.png", NULL);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1658 orig = gdk_pixbuf_new_from_file(filename, NULL);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1659 g_free(filename);
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1660 if (orig == NULL)
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1661 return NULL;
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1662
13109
079f7a452e3a [gaim-migrate @ 15471]
Mark Doliner <mark@kingant.net>
parents: 13102
diff changeset
1663 pixbuf = gdk_pixbuf_scale_simple(orig, 32*scale_factor,
079f7a452e3a [gaim-migrate @ 15471]
Mark Doliner <mark@kingant.net>
parents: 13102
diff changeset
1664 32*scale_factor, GDK_INTERP_BILINEAR);
13090
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1665 g_object_unref(G_OBJECT(orig));
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1666
0aa231ebbfd5 [gaim-migrate @ 15452]
Mark Doliner <mark@kingant.net>
parents: 13080
diff changeset
1667 return overlay_status_onto_icon(pixbuf, primitive);
12080
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1668 }
3b52d94437f3 [gaim-migrate @ 14377]
Mark Doliner <mark@kingant.net>
parents: 12067
diff changeset
1669
12919
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1670 static void
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1671 menu_action_cb(GtkMenuItem *item, gpointer object)
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1672 {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1673 gpointer data;
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1674 void (*callback)(gpointer, gpointer);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1675
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1676 callback = g_object_get_data(G_OBJECT(item), "gaimcallback");
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1677 data = g_object_get_data(G_OBJECT(item), "gaimcallbackdata");
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1678
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1679 if (callback)
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1680 callback(object, data);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1681 }
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1682
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1683 void
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1684 gaim_gtk_append_menu_action(GtkWidget *menu, GaimMenuAction *act,
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1685 gpointer object)
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1686 {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1687 if (act == NULL) {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1688 gaim_separator(menu);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1689 } else {
13781
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1690 GtkWidget *menuitem;
12919
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1691
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1692 if (act->children == NULL) {
13781
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1693 menuitem = gtk_menu_item_new_with_mnemonic(act->label);
12919
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1694
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1695 if (act->callback != NULL) {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1696 g_object_set_data(G_OBJECT(menuitem),
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1697 "gaimcallback",
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1698 act->callback);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1699 g_object_set_data(G_OBJECT(menuitem),
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1700 "gaimcallbackdata",
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1701 act->data);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1702 g_signal_connect(G_OBJECT(menuitem), "activate",
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1703 G_CALLBACK(menu_action_cb),
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1704 object);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1705 } else {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1706 gtk_widget_set_sensitive(menuitem, FALSE);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1707 }
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1708
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1709 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1710 } else {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1711 GList *l = NULL;
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1712 GtkWidget *submenu = NULL;
13781
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1713 GtkAccelGroup *group;
12919
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1714
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1715 menuitem = gtk_menu_item_new_with_mnemonic(act->label);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1716 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1717
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1718 submenu = gtk_menu_new();
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1719 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), submenu);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1720
13781
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1721 group = gtk_menu_get_accel_group(GTK_MENU(menu));
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1722 if (group) {
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1723 char *path = g_strdup_printf("%s/%s", GTK_MENU_ITEM(menuitem)->accel_path, act->label);
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1724 gtk_menu_set_accel_path(GTK_MENU(submenu), path);
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1725 g_free(path);
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1726 gtk_menu_set_accel_group(GTK_MENU(submenu), group);
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1727 }
743e38a3182b [gaim-migrate @ 16193]
Richard Laager <rlaager@wiktel.com>
parents: 13469
diff changeset
1728
12919
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1729 for (l = act->children; l; l = l->next) {
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1730 GaimMenuAction *act = (GaimMenuAction *)l->data;
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1731
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1732 gaim_gtk_append_menu_action(submenu, act, object);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1733 }
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1734 g_list_free(act->children);
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1735 act->children = NULL;
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1736 }
13102
5828d42e8684 [gaim-migrate @ 15464]
Richard Laager <rlaager@wiktel.com>
parents: 13101
diff changeset
1737 gaim_menu_action_free(act);
12919
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1738 }
248b8b39c671 [gaim-migrate @ 15272]
Etan Reisner <pidgin@unreliablesource.net>
parents: 12905
diff changeset
1739 }
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1740
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1741 #if GTK_CHECK_VERSION(2,3,0)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1742 # define NEW_STYLE_COMPLETION
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1743 #endif
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1744
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1745 #ifndef NEW_STYLE_COMPLETION
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1746 typedef struct
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1747 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1748 GCompletion *completion;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1749
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1750 gboolean completion_started;
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
1751 gboolean all;
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1752
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1753 } GaimGtkCompletionData;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1754 #endif
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1755
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1756 #ifndef NEW_STYLE_COMPLETION
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1757 static gboolean
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1758 completion_entry_event(GtkEditable *entry, GdkEventKey *event,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1759 GaimGtkCompletionData *data)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1760 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1761 int pos, end_pos;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1762
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1763 if (event->type == GDK_KEY_PRESS && event->keyval == GDK_Tab)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1764 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1765 gtk_editable_get_selection_bounds(entry, &pos, &end_pos);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1766
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1767 if (data->completion_started &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1768 pos != end_pos && pos > 1 &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1769 end_pos == strlen(gtk_entry_get_text(GTK_ENTRY(entry))))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1770 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1771 gtk_editable_select_region(entry, 0, 0);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1772 gtk_editable_set_position(entry, -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1773
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1774 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1775 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1776 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1777 else if (event->type == GDK_KEY_PRESS && event->length > 0)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1778 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1779 char *prefix, *nprefix;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1780
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1781 gtk_editable_get_selection_bounds(entry, &pos, &end_pos);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1782
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1783 if (data->completion_started &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1784 pos != end_pos && pos > 1 &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1785 end_pos == strlen(gtk_entry_get_text(GTK_ENTRY(entry))))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1786 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1787 char *temp;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1788
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1789 temp = gtk_editable_get_chars(entry, 0, pos);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1790 prefix = g_strconcat(temp, event->string, NULL);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1791 g_free(temp);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1792 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1793 else if (pos == end_pos && pos > 1 &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1794 end_pos == strlen(gtk_entry_get_text(GTK_ENTRY(entry))))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1795 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1796 prefix = g_strconcat(gtk_entry_get_text(GTK_ENTRY(entry)),
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1797 event->string, NULL);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1798 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1799 else
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1800 return FALSE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1801
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1802 pos = strlen(prefix);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1803 nprefix = NULL;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1804
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1805 g_completion_complete(data->completion, prefix, &nprefix);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1806
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1807 if (nprefix != NULL)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1808 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1809 gtk_entry_set_text(GTK_ENTRY(entry), nprefix);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1810 gtk_editable_set_position(entry, pos);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1811 gtk_editable_select_region(entry, pos, -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1812
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1813 data->completion_started = TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1814
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1815 g_free(nprefix);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1816 g_free(prefix);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1817
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1818 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1819 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1820
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1821 g_free(prefix);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1822 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1823
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1824 return FALSE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1825 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1826
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1827 static void
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1828 destroy_completion_data(GtkWidget *w, GaimGtkCompletionData *data)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1829 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1830 g_list_foreach(data->completion->items, (GFunc)g_free, NULL);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1831 g_completion_free(data->completion);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1832
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1833 g_free(data);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1834 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1835 #endif /* !NEW_STYLE_COMPLETION */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1836
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1837 #ifdef NEW_STYLE_COMPLETION
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1838 static gboolean screenname_completion_match_func(GtkEntryCompletion *completion,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1839 const gchar *key, GtkTreeIter *iter, gpointer user_data)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1840 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1841 GtkTreeModel *model;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1842 GValue val1;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1843 GValue val2;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1844 const char *tmp;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1845
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1846 model = gtk_entry_completion_get_model (completion);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1847
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1848 val1.g_type = 0;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1849 gtk_tree_model_get_value(model, iter, 2, &val1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1850 tmp = g_value_get_string(&val1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1851 if (tmp != NULL && gaim_str_has_prefix(tmp, key))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1852 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1853 g_value_unset(&val1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1854 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1855 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1856 g_value_unset(&val1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1857
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1858 val2.g_type = 0;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1859 gtk_tree_model_get_value(model, iter, 3, &val2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1860 tmp = g_value_get_string(&val2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1861 if (tmp != NULL && gaim_str_has_prefix(tmp, key))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1862 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1863 g_value_unset(&val2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1864 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1865 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1866 g_value_unset(&val2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1867
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1868 return FALSE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1869 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1870
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1871 static gboolean screenname_completion_match_selected_cb(GtkEntryCompletion *completion,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1872 GtkTreeModel *model, GtkTreeIter *iter, gpointer *user_data)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1873 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1874 GValue val;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1875 GtkWidget *optmenu = user_data[1];
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1876 GaimAccount *account;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1877
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1878 val.g_type = 0;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1879 gtk_tree_model_get_value(model, iter, 1, &val);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1880 gtk_entry_set_text(GTK_ENTRY(user_data[0]), g_value_get_string(&val));
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1881 g_value_unset(&val);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1882
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1883 gtk_tree_model_get_value(model, iter, 4, &val);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1884 account = g_value_get_pointer(&val);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1885 g_value_unset(&val);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1886
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1887 if (account == NULL)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1888 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1889
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1890 if (optmenu != NULL) {
13371
1299f8f51b07 [gaim-migrate @ 15744]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13366
diff changeset
1891 GList *items;
1299f8f51b07 [gaim-migrate @ 15744]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13366
diff changeset
1892 guint index = 0;
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1893 gaim_gtk_account_option_menu_set_selected(optmenu, account);
13371
1299f8f51b07 [gaim-migrate @ 15744]
Daniel Atallah <daniel.atallah@gmail.com>
parents: 13366
diff changeset
1894 items = GTK_MENU_SHELL(gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu)))->children;
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1895
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1896 do {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1897 if (account == g_object_get_data(G_OBJECT(items->data), "account")) {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1898 /* Set the account in the GUI. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1899 gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), index);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1900 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1901 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1902 index++;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1903 } while ((items = items->next) != NULL);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1904 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1905
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1906 return TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1907 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1908
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1909 static void
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1910 add_screenname_autocomplete_entry(GtkListStore *store, const char *buddy_alias, const char *contact_alias,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1911 const GaimAccount *account, const char *screenname)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1912 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1913 GtkTreeIter iter;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1914 gboolean completion_added = FALSE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1915 gchar *normalized_screenname;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1916 gchar *tmp;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1917
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1918 tmp = g_utf8_normalize(screenname, -1, G_NORMALIZE_DEFAULT);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1919 normalized_screenname = g_utf8_casefold(tmp, -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1920 g_free(tmp);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1921
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1922 /* There's no sense listing things like: 'xxx "xxx"'
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1923 when the screenname and buddy alias match. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1924 if (buddy_alias && strcmp(buddy_alias, screenname)) {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1925 char *completion_entry = g_strdup_printf("%s \"%s\"", screenname, buddy_alias);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1926 char *tmp2 = g_utf8_normalize(buddy_alias, -1, G_NORMALIZE_DEFAULT);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1927
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1928 tmp = g_utf8_casefold(tmp2, -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1929 g_free(tmp2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1930
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1931 gtk_list_store_append(store, &iter);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1932 gtk_list_store_set(store, &iter,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1933 0, completion_entry,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1934 1, screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1935 2, normalized_screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1936 3, tmp,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1937 4, account,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1938 -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1939 g_free(completion_entry);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1940 g_free(tmp);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1941 completion_added = TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1942 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1943
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1944 /* There's no sense listing things like: 'xxx "xxx"'
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1945 when the screenname and contact alias match. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1946 if (contact_alias && strcmp(contact_alias, screenname)) {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1947 /* We don't want duplicates when the contact and buddy alias match. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1948 if (!buddy_alias || strcmp(contact_alias, buddy_alias)) {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1949 char *completion_entry = g_strdup_printf("%s \"%s\"",
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1950 screenname, contact_alias);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1951 char *tmp2 = g_utf8_normalize(contact_alias, -1, G_NORMALIZE_DEFAULT);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1952
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1953 tmp = g_utf8_casefold(tmp2, -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1954 g_free(tmp2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1955
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1956 gtk_list_store_append(store, &iter);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1957 gtk_list_store_set(store, &iter,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1958 0, completion_entry,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1959 1, screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1960 2, normalized_screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1961 3, tmp,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1962 4, account,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1963 -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1964 g_free(completion_entry);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1965 g_free(tmp);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1966 completion_added = TRUE;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1967 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1968 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1969
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1970 if (completion_added == FALSE) {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1971 /* Add the buddy's screenname. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1972 gtk_list_store_append(store, &iter);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1973 gtk_list_store_set(store, &iter,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1974 0, screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1975 1, screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1976 2, normalized_screenname,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1977 3, NULL,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1978 4, account,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1979 -1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1980 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1981
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1982 g_free(normalized_screenname);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1983 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1984 #endif /* NEW_STYLE_COMPLETION */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1985
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1986 static void get_log_set_name(GaimLogSet *set, gpointer value, gpointer **set_hash_data)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1987 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1988 /* 1. Don't show buddies because we will have gotten them already.
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1989 * 2. Only show those with non-NULL accounts that are currently connected.
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1990 * 3. The boxes that use this autocomplete code handle only IMs. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1991 if (!set->buddy &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1992 (GPOINTER_TO_INT(set_hash_data[1]) ||
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1993 (set->account != NULL && gaim_account_is_connected(set->account))) &&
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1994 set->type == GAIM_LOG_IM) {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1995 #ifdef NEW_STYLE_COMPLETION
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1996 add_screenname_autocomplete_entry((GtkListStore *)set_hash_data[0],
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1997 NULL, NULL, set->account, set->name);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1998 #else
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
1999 GList **items = ((GList **)set_hash_data[0]);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2000 /* Steal the name for the GCompletion. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2001 *items = g_list_append(*items, set->name);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2002 set->name = set->normalized_name = NULL;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2003 #endif /* NEW_STYLE_COMPLETION */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2004 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2005 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2006
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2007 #ifdef NEW_STYLE_COMPLETION
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2008 static void
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2009 add_completion_list(GtkListStore *store)
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2010 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2011 GaimBlistNode *gnode, *cnode, *bnode;
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2012 gboolean all = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(store), "screenname-all"));
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2013 GHashTable *sets;
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2014 gpointer set_hash_data[] = {store, GINT_TO_POINTER(all)};
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2015
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2016 gtk_list_store_clear(store);
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2017
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2018 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2019 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2020 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2021 continue;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2022
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2023 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2024 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2025 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2026 continue;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2027
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2028 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next)
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2029 {
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2030 GaimBuddy *buddy = (GaimBuddy *)bnode;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2031
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2032 if (!all && !gaim_account_is_connected(buddy->account))
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2033 continue;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2034
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2035 add_screenname_autocomplete_entry(store,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2036 ((GaimContact *)cnode)->alias,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2037 gaim_buddy_get_contact_alias(buddy),
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2038 buddy->account,
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2039 buddy->name
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2040 );
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2041 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2042 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2043 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2044
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2045 sets = gaim_log_get_log_sets();
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2046 g_hash_table_foreach(sets, (GHFunc)get_log_set_name, &set_hash_data);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2047 g_hash_table_destroy(sets);
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2048 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2049 #else
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2050 static void
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2051 add_completion_list(GaimGtkCompletionData *data)
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2052 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2053 GaimBlistNode *gnode, *cnode, *bnode;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2054 GCompletion *completion;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2055 GList *item = g_list_append(NULL, NULL);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2056 GHashTable *sets;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2057 gpointer set_hash_data[2];
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2058
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2059 completion = data->completion;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2060
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2061 g_list_foreach(completion->items, (GFunc)g_free, NULL);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2062 g_completion_clear_items(completion);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2063
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2064 for (gnode = gaim_get_blist()->root; gnode != NULL; gnode = gnode->next)
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2065 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2066 if (!GAIM_BLIST_NODE_IS_GROUP(gnode))
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2067 continue;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2068
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2069 for (cnode = gnode->child; cnode != NULL; cnode = cnode->next)
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2070 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2071 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode))
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2072 continue;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2073
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2074 for (bnode = cnode->child; bnode != NULL; bnode = bnode->next)
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2075 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2076 GaimBuddy *buddy = (GaimBuddy *)bnode;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2077
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2078 if (!data->all && !gaim_account_is_connected(buddy->account))
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2079 continue;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2080
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2081 item->data = g_strdup(buddy->name);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2082 g_completion_add_items(data->completion, item);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2083 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2084 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2085 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2086 g_list_free(item);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2087
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2088 sets = gaim_log_get_log_sets();
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2089 item = NULL;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2090 set_hash_data[0] = &item;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2091 set_hash_data[1] = GINT_TO_POINTER(data->all);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2092 g_hash_table_foreach(sets, (GHFunc)get_log_set_name, &set_hash_data);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2093 g_hash_table_destroy(sets);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2094 g_completion_add_items(data->completion, item);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2095 g_list_free(item);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2096 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2097 #endif
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2098
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2099 static void
13366
0758db6d46ac [gaim-migrate @ 15739]
Richard Laager <rlaager@wiktel.com>
parents: 13365
diff changeset
2100 screenname_autocomplete_destroyed_cb(GtkWidget *widget, gpointer data)
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2101 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2102 gaim_signals_disconnect_by_handle(widget);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2103 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2104
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2105 static void
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2106 repopulate_autocomplete(gpointer something, gpointer data)
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2107 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2108 add_completion_list(data);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2109 }
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2110
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2111 void
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2112 gaim_gtk_setup_screenname_autocomplete(GtkWidget *entry, GtkWidget *accountopt, gboolean all)
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2113 {
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2114 gpointer cb_data = NULL;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2115
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2116 #ifdef NEW_STYLE_COMPLETION
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2117 /* Store the displayed completion value, the screenname, the UTF-8 normalized & casefolded screenname,
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2118 * the UTF-8 normalized & casefolded value for comparison, and the account. */
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2119 GtkListStore *store = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2120
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2121 GtkEntryCompletion *completion;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2122 gpointer *data;
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2123
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2124 g_object_set_data(G_OBJECT(store), "screenname-all", GINT_TO_POINTER(all));
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2125 add_completion_list(store);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2126
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2127 cb_data = store;
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2128
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2129 /* Sort the completion list by screenname. */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2130 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2131 1, GTK_SORT_ASCENDING);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2132
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2133 completion = gtk_entry_completion_new();
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2134 gtk_entry_completion_set_match_func(completion, screenname_completion_match_func, NULL, NULL);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2135
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2136 data = g_new0(gpointer, 2);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2137 data[0] = entry;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2138 data[1] = accountopt;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2139 g_signal_connect(G_OBJECT(completion), "match-selected",
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2140 G_CALLBACK(screenname_completion_match_selected_cb), data);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2141
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2142 gtk_entry_set_completion(GTK_ENTRY(entry), completion);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2143 g_object_unref(completion);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2144
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2145 gtk_entry_completion_set_model(completion, GTK_TREE_MODEL(store));
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2146 g_object_unref(store);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2147
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2148 gtk_entry_completion_set_text_column(completion, 0);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2149
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2150 #else /* !NEW_STYLE_COMPLETION */
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2151 GaimGtkCompletionData *data;
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2152
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2153 data = g_new0(GaimGtkCompletionData, 1);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2154
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2155 data->completion = g_completion_new(NULL);
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2156 data->all = all;
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2157
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2158 g_completion_set_compare(data->completion, g_ascii_strncasecmp);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2159
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2160 add_completion_list(data);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2161 cb_data = data;
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2162
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2163 g_signal_connect(G_OBJECT(entry), "event",
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2164 G_CALLBACK(completion_entry_event), data);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2165 g_signal_connect(G_OBJECT(entry), "destroy",
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2166 G_CALLBACK(destroy_completion_data), data);
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2167
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2168 #endif /* !NEW_STYLE_COMPLETION */
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2169
13365
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2170 if (!all)
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2171 {
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2172 gaim_signal_connect(gaim_connections_get_handle(), "signed-on", entry,
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2173 GAIM_CALLBACK(repopulate_autocomplete), cb_data);
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2174 gaim_signal_connect(gaim_connections_get_handle(), "signed-off", entry,
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2175 GAIM_CALLBACK(repopulate_autocomplete), cb_data);
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2176 }
143233089386 [gaim-migrate @ 15738]
Richard Laager <rlaager@wiktel.com>
parents: 13364
diff changeset
2177
13364
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2178 gaim_signal_connect(gaim_accounts_get_handle(), "account-added", entry,
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2179 GAIM_CALLBACK(repopulate_autocomplete), cb_data);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2180 gaim_signal_connect(gaim_accounts_get_handle(), "account-removed", entry,
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2181 GAIM_CALLBACK(repopulate_autocomplete), cb_data);
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2182
3b7abce487f5 [gaim-migrate @ 15737]
Richard Laager <rlaager@wiktel.com>
parents: 13360
diff changeset
2183 g_signal_connect(G_OBJECT(entry), "destroy", G_CALLBACK(screenname_autocomplete_destroyed_cb), NULL);
13360
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2184 }
2e6dda9f9159 [gaim-migrate @ 15733]
Richard Laager <rlaager@wiktel.com>
parents: 13280
diff changeset
2185
13434
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2186 void gaim_gtk_set_cursor(GtkWidget *widget, GdkCursorType cursor_type)
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2187 {
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2188 GdkCursor *cursor;
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2189
13469
689f652480f7 [gaim-migrate @ 15845]
Richard Laager <rlaager@wiktel.com>
parents: 13434
diff changeset
2190 g_return_if_fail(widget != NULL);
689f652480f7 [gaim-migrate @ 15845]
Richard Laager <rlaager@wiktel.com>
parents: 13434
diff changeset
2191 if (widget->window == NULL)
13434
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2192 return;
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2193
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2194 cursor = gdk_cursor_new(GDK_WATCH);
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2195 gdk_window_set_cursor(widget->window, cursor);
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2196 gdk_cursor_unref(cursor);
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2197
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2198 #if GTK_CHECK_VERSION(2,4,0)
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2199 gdk_display_flush(gdk_drawable_get_display(GDK_DRAWABLE(widget->window)));
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2200 #else
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2201 gdk_flush();
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2202 #endif
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2203 }
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2204
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2205 void gaim_gtk_clear_cursor(GtkWidget *widget)
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2206 {
13469
689f652480f7 [gaim-migrate @ 15845]
Richard Laager <rlaager@wiktel.com>
parents: 13434
diff changeset
2207 g_return_if_fail(widget != NULL);
689f652480f7 [gaim-migrate @ 15845]
Richard Laager <rlaager@wiktel.com>
parents: 13434
diff changeset
2208 if (widget->window == NULL)
13434
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2209 return;
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2210
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2211 gdk_window_set_cursor(widget->window, NULL);
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2212 }
ffd724befbf8 [gaim-migrate @ 15809]
Richard Laager <rlaager@wiktel.com>
parents: 13371
diff changeset
2213
14133
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2214 struct _icon_chooser {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2215 GtkWidget *icon_filesel;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2216 GtkWidget *icon_preview;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2217 GtkWidget *icon_text;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2218
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2219 void (*callback)(const char*,gpointer);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2220 gpointer data;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2221 };
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2222
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2223 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2224 static void
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2225 icon_filesel_delete_cb(GtkWidget *w, struct _icon_chooser *dialog)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2226 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2227 if (dialog->icon_filesel != NULL)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2228 gtk_widget_destroy(dialog->icon_filesel);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2229
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2230 if (dialog->callback)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2231 dialog->callback(NULL, data);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2232
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2233 g_free(dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2234 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2235 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2236
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2237
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2238
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2239 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2240 static void
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2241 icon_filesel_choose_cb(GtkWidget *widget, gint response, struct _icon_chooser *dialog)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2242 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2243 char *filename, *current_folder;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2244
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2245 if (response != GTK_RESPONSE_ACCEPT) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2246 if (response == GTK_RESPONSE_CANCEL) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2247 gtk_widget_destroy(dialog->icon_filesel);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2248 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2249 dialog->icon_filesel = NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2250 if (dialog->callback)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2251 dialog->callback(NULL, dialog->data);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2252 g_free(dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2253 return;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2254 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2255
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2256 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->icon_filesel));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2257 current_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog->icon_filesel));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2258 if (current_folder != NULL) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2259 gaim_prefs_set_string("/gaim/gtk/filelocations/last_icon_folder", current_folder);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2260 g_free(current_folder);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2261 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2262
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2263 #else /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2264 static void
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2265 icon_filesel_choose_cb(GtkWidget *w, AccountPrefsDialog *dialog)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2266 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2267 char *filename, *current_folder;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2268
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2269 filename = g_strdup(gtk_file_selection_get_filename(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2270 GTK_FILE_SELECTION(dialog->icon_filesel)));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2271
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2272 /* If they typed in a directory, change there */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2273 if (gaim_gtk_check_if_dir(filename,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2274 GTK_FILE_SELECTION(dialog->icon_filesel)))
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2275 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2276 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2277 return;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2278 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2279
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2280 current_folder = g_path_get_dirname(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2281 if (current_folder != NULL) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2282 gaim_prefs_set_string("/gaim/gtk/filelocations/last_icon_folder", current_folder);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2283 g_free(current_folder);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2284 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2285
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2286 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2287 if (dialog->callback)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2288 dialog->callback(filename, dialog->data);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2289 gtk_widget_destroy(dialog->icon_filesel);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2290 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2291 g_free(dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2292 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2293
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2294
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2295 static void
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2296 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2297 icon_preview_change_cb(GtkFileChooser *widget, struct _icon_chooser *dialog)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2298 #else /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2299 icon_preview_change_cb(GtkTreeSelection *sel, struct _icon_chooser *dialog)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2300 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2301 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2302 GdkPixbuf *pixbuf, *scale;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2303 int height, width;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2304 char *basename, *markup, *size;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2305 struct stat st;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2306 char *filename;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2307
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2308 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2309 filename = gtk_file_chooser_get_preview_filename(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2310 GTK_FILE_CHOOSER(dialog->icon_filesel));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2311 #else /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2312 filename = g_strdup(gtk_file_selection_get_filename(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2313 GTK_FILE_SELECTION(dialog->icon_filesel)));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2314 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2315
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2316 if (!filename || g_stat(filename, &st))
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2317 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2318 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2319 return;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2320 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2321
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2322 pixbuf = gdk_pixbuf_new_from_file(filename, NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2323 if (!pixbuf) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2324 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->icon_preview), NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2325 gtk_label_set_markup(GTK_LABEL(dialog->icon_text), "");
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2326 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2327 gtk_file_chooser_set_preview_widget_active(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2328 GTK_FILE_CHOOSER(dialog->icon_filesel), FALSE);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2329 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2330 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2331 return;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2332 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2333
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2334 width = gdk_pixbuf_get_width(pixbuf);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2335 height = gdk_pixbuf_get_height(pixbuf);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2336 basename = g_path_get_basename(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2337 size = gaim_str_size_to_units(st.st_size);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2338 markup = g_strdup_printf(_("<b>File:</b> %s\n"
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2339 "<b>File size:</b> %s\n"
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2340 "<b>Image size:</b> %dx%d"),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2341 basename, size, width, height);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2342
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2343 scale = gdk_pixbuf_scale_simple(pixbuf, width * 50 / height,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2344 50, GDK_INTERP_BILINEAR);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2345 gtk_image_set_from_pixbuf(GTK_IMAGE(dialog->icon_preview), scale);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2346 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2347 gtk_file_chooser_set_preview_widget_active(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2348 GTK_FILE_CHOOSER(dialog->icon_filesel), TRUE);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2349 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2350 gtk_label_set_markup(GTK_LABEL(dialog->icon_text), markup);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2351
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2352 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2353 g_object_unref(G_OBJECT(scale));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2354 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2355 g_free(basename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2356 g_free(size);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2357 g_free(markup);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2358 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2359
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2360
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2361 GtkWidget *gaim_gtk_buddy_icon_chooser_new(GtkWindow *parent, void(*callback)(const char*,gpointer), gpointer data) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2362 struct _icon_chooser *dialog = g_new0(struct _icon_chooser, 1);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2363
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2364 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2365 GtkWidget *hbox;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2366 GtkWidget *tv;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2367 GtkTreeSelection *sel;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2368
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2369 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2370 const char *current_folder;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2371
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2372 dialog->callback = callback;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2373 dialog->data = data;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2374
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2375 if (dialog->icon_filesel != NULL) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2376 gtk_window_present(GTK_WINDOW(dialog->icon_filesel));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2377 return NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2378 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2379
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2380 current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_icon_folder");
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2381 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2382
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2383 dialog->icon_filesel = gtk_file_chooser_dialog_new(_("Buddy Icon"),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2384 parent,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2385 GTK_FILE_CHOOSER_ACTION_OPEN,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2386 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2387 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2388 NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2389 gtk_dialog_set_default_response(GTK_DIALOG(dialog->icon_filesel), GTK_RESPONSE_ACCEPT);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2390 if ((current_folder != NULL) && (*current_folder != '\0'))
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2391 gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog->icon_filesel),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2392 current_folder);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2393
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2394 dialog->icon_preview = gtk_image_new();
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2395 dialog->icon_text = gtk_label_new(NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2396 gtk_widget_set_size_request(GTK_WIDGET(dialog->icon_preview), -1, 50);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2397 gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog->icon_filesel),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2398 GTK_WIDGET(dialog->icon_preview));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2399 g_signal_connect(G_OBJECT(dialog->icon_filesel), "update-preview",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2400 G_CALLBACK(icon_preview_change_cb), dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2401 g_signal_connect(G_OBJECT(dialog->icon_filesel), "response",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2402 G_CALLBACK(icon_filesel_choose_cb), dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2403 icon_preview_change_cb(NULL, dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2404 #else /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2405 dialog->icon_filesel = gtk_file_selection_new(_("Buddy Icon"));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2406 dialog->icon_preview = gtk_image_new();
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2407 dialog->icon_text = gtk_label_new(NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2408 if ((current_folder != NULL) && (*current_folder != '\0'))
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2409 gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog->icon_filesel),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2410 current_folder);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2411
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2412 gtk_widget_set_size_request(GTK_WIDGET(dialog->icon_preview), -1, 50);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2413 hbox = gtk_hbox_new(FALSE, GAIM_HIG_BOX_SPACE);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2414 gtk_box_pack_start(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2415 GTK_BOX(GTK_FILE_SELECTION(dialog->icon_filesel)->main_vbox),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2416 hbox, FALSE, FALSE, 0);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2417 gtk_box_pack_end(GTK_BOX(hbox), dialog->icon_preview,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2418 FALSE, FALSE, 0);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2419 gtk_box_pack_end(GTK_BOX(hbox), dialog->icon_text, FALSE, FALSE, 0);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2420
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2421 tv = GTK_FILE_SELECTION(dialog->icon_filesel)->file_list;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2422 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(tv));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2423
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2424 g_signal_connect(G_OBJECT(sel), "changed",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2425 G_CALLBACK(icon_preview_change_cb), dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2426 g_signal_connect(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2427 G_OBJECT(GTK_FILE_SELECTION(dialog->icon_filesel)->ok_button),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2428 "clicked",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2429 G_CALLBACK(icon_filesel_choose_cb), dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2430 g_signal_connect(
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2431 G_OBJECT(GTK_FILE_SELECTION(dialog->icon_filesel)->cancel_button),
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2432 "clicked",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2433 G_CALLBACK(icon_filesel_delete_cb), dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2434 g_signal_connect(G_OBJECT(dialog->icon_filesel), "destroy",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2435 G_CALLBACK(icon_filesel_delete_cb), dialog);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2436 #endif /* FILECHOOSER */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2437 return dialog->icon_filesel;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2438 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2439
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2440
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2441 #if GTK_CHECK_VERSION(2,2,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2442 static gboolean
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2443 str_array_match(char **a, char **b)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2444 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2445 int i, j;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2446
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2447 if (!a || !b)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2448 return FALSE;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2449 for (i = 0; a[i] != NULL; i++)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2450 for (j = 0; b[j] != NULL; j++)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2451 if (!g_ascii_strcasecmp(a[i], b[j]))
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2452 return TRUE;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2453 return FALSE;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2454 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2455 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2456
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2457 char*
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2458 gaim_gtk_convert_buddy_icon(GaimPlugin *plugin, const char *path)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2459 {
14134
4006d3dc2871 [gaim-migrate @ 16776]
Sean Egan <seanegan@gmail.com>
parents: 14133
diff changeset
2460 g_return_val_if_fail(GAIM_PLUGIN_PROTOCOL_INFO(plugin)->icon_spec.format != NULL, NULL);
4006d3dc2871 [gaim-migrate @ 16776]
Sean Egan <seanegan@gmail.com>
parents: 14133
diff changeset
2461
14133
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2462 #if GTK_CHECK_VERSION(2,2,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2463 int width, height;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2464 char **pixbuf_formats = NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2465 GdkPixbufFormat *format;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2466 GdkPixbuf *pixbuf;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2467 GaimPluginProtocolInfo *prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(plugin);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2468 char **prpl_formats = g_strsplit (prpl_info->icon_spec.format,",",0);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2469 #if !GTK_CHECK_VERSION(2,4,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2470 GdkPixbufLoader *loader;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2471 FILE *file;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2472 struct stat st;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2473 void *data = NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2474 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2475 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2476 const char *dirname = gaim_buddy_icons_get_cache_dir();
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2477 char *random = g_strdup_printf("%x", g_random_int());
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2478 char *filename = g_build_filename(dirname, random, NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2479
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2480 if (!g_file_test(dirname, G_FILE_TEST_IS_DIR)) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2481 gaim_debug_info("buddyicon", "Creating icon cache directory.\n");
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2482
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2483 if (g_mkdir(dirname, S_IRUSR | S_IWUSR | S_IXUSR) < 0) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2484 gaim_debug_error("buddyicon",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2485 "Unable to create directory %s: %s\n",
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2486 dirname, strerror(errno));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2487 #if GTK_CHECK_VERSION(2,2,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2488 g_strfreev(prpl_formats);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2489 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2490 g_free(random);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2491 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2492 return NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2493 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2494 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2495
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2496 #if GTK_CHECK_VERSION(2,2,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2497 #if GTK_CHECK_VERSION(2,4,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2498 format = gdk_pixbuf_get_file_info (path, &width, &height);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2499 #else
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2500 loader = gdk_pixbuf_loader_new();
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2501 if (!g_stat(path, &st) && (file = g_fopen(path, "rb")) != NULL) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2502 data = g_malloc(st.st_size);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2503 fread(data, 1, st.st_size, file);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2504 fclose(file);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2505 gdk_pixbuf_loader_write(loader, data, st.st_size, NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2506 g_free(data);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2507 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2508 gdk_pixbuf_loader_close(loader, NULL);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2509 pixbuf = gdk_pixbuf_loader_get_pixbuf(loader);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2510 width = gdk_pixbuf_get_width(pixbuf);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2511 height = gdk_pixbuf_get_height(pixbuf);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2512 format = gdk_pixbuf_loader_get_format(loader);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2513 g_object_unref(G_OBJECT(loader));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2514 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2515 pixbuf_formats = gdk_pixbuf_format_get_extensions(format);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2516
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2517 if (str_array_match(pixbuf_formats, prpl_formats) && /* This is an acceptable format AND */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2518 (!(prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) || /* The prpl doesn't scale before it sends OR */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2519 (prpl_info->icon_spec.min_width <= width &&
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2520 prpl_info->icon_spec.max_width >= width &&
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2521 prpl_info->icon_spec.min_height <= height &&
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2522 prpl_info->icon_spec.max_height >= height))) /* The icon is the correct size */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2523 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2524 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2525 gchar *contents;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2526 gsize length;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2527 FILE *image;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2528
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2529 #if GTK_CHECK_VERSION(2,2,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2530 g_strfreev(prpl_formats);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2531 g_strfreev(pixbuf_formats);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2532 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2533
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2534 /* Copy the image to the cache folder as "filename". */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2535
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2536 if (!g_file_get_contents(path, &contents, &length, NULL) ||
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2537 (image = g_fopen(filename, "wb")) == NULL)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2538 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2539 g_free(random);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2540 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2541 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2542 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2543 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2544 return NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2545 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2546
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2547 if (fwrite(contents, 1, length, image) != length)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2548 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2549 fclose(image);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2550 g_unlink(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2551
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2552 g_free(random);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2553 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2554 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2555 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2556 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2557 return NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2558 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2559 fclose(image);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2560
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2561 #if GTK_CHECK_VERSION(2,2,0) && !GTK_CHECK_VERSION(2,4,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2562 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2563 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2564
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2565 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2566 return random;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2567 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2568 #if GTK_CHECK_VERSION(2,2,0)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2569 else
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2570 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2571 int i;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2572 GError *error = NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2573 GdkPixbuf *scale;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2574 pixbuf = gdk_pixbuf_new_from_file(path, &error);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2575 g_strfreev(pixbuf_formats);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2576 if (!error && (prpl_info->icon_spec.scale_rules & GAIM_ICON_SCALE_SEND) &&
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2577 (width < prpl_info->icon_spec.min_width ||
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2578 width > prpl_info->icon_spec.max_width ||
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2579 height < prpl_info->icon_spec.min_height ||
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2580 height > prpl_info->icon_spec.max_height))
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2581 {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2582 int new_width = width;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2583 int new_height = height;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2584
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2585 if(new_width > prpl_info->icon_spec.max_width)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2586 new_width = prpl_info->icon_spec.max_width;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2587 else if(new_width < prpl_info->icon_spec.min_width)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2588 new_width = prpl_info->icon_spec.min_width;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2589 if(new_height > prpl_info->icon_spec.max_height)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2590 new_height = prpl_info->icon_spec.max_height;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2591 else if(new_height < prpl_info->icon_spec.min_height)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2592 new_height = prpl_info->icon_spec.min_height;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2593
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2594 /* preserve aspect ratio */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2595 if ((double)height * (double)new_width >
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2596 (double)width * (double)new_height) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2597 new_width = 0.5 + (double)width * (double)new_height / (double)height;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2598 } else {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2599 new_height = 0.5 + (double)height * (double)new_width / (double)width;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2600 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2601
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2602 scale = gdk_pixbuf_scale_simple (pixbuf, new_width, new_height,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2603 GDK_INTERP_HYPER);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2604 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2605 pixbuf = scale;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2606 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2607 if (error) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2608 g_free(random);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2609 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2610 gaim_debug_error("buddyicon", "Could not open icon for conversion: %s\n", error->message);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2611 g_error_free(error);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2612 g_strfreev(prpl_formats);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2613 return NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2614 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2615
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2616 for (i = 0; prpl_formats[i]; i++) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2617 gaim_debug_info("buddyicon", "Converting buddy icon to %s as %s\n", prpl_formats[i], filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2618 /* The gdk-pixbuf documentation is wrong. gdk_pixbuf_save returns TRUE if it was successful,
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2619 * FALSE if an error was set. */
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2620 if (gdk_pixbuf_save (pixbuf, filename, prpl_formats[i], &error, NULL) == TRUE)
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2621 break;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2622 gaim_debug_warning("buddyicon", "Could not convert to %s: %s\n", prpl_formats[i], error->message);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2623 g_error_free(error);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2624 error = NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2625 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2626 g_strfreev(prpl_formats);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2627 if (!error) {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2628 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2629 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2630 return random;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2631 } else {
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2632 gaim_debug_error("buddyicon", "Could not convert icon to usable format: %s\n", error->message);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2633 g_error_free(error);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2634 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2635 g_free(random);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2636 g_free(filename);
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2637 g_object_unref(G_OBJECT(pixbuf));
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2638 }
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2639 return NULL;
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2640 #endif
31d33e7bc0e6 [gaim-migrate @ 16775]
Sean Egan <seanegan@gmail.com>
parents: 14035
diff changeset
2641 }