]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-ui-utils.c
Get the icon name from the account object directly
[empathy.git] / libempathy-gtk / empathy-ui-utils.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2002-2007 Imendio AB
4  * Copyright (C) 2007-2008 Collabora Ltd.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public
17  * License along with this program; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA  02110-1301  USA
20  *
21  * Authors: Mikael Hallendal <micke@imendio.com>
22  *          Richard Hult <richard@imendio.com>
23  *          Martyn Russell <martyn@imendio.com>
24  *          Xavier Claessens <xclaesse@gmail.com>
25  *          Jonny Lamb <jonny.lamb@collabora.co.uk>
26  *
27  *          Part of this file is copied from GtkSourceView (gtksourceiter.c):
28  *          Paolo Maggi
29  *          Jeroen Zwartepoorte
30  */
31
32 #include <config.h>
33
34 #include <string.h>
35 #include <X11/Xatom.h>
36 #include <gdk/gdkx.h>
37 #include <glib/gi18n-lib.h>
38 #include <gtk/gtk.h>
39 #include <gio/gio.h>
40
41 #include <libmissioncontrol/mc-profile.h>
42
43 #include "empathy-ui-utils.h"
44 #include "empathy-images.h"
45 #include "empathy-conf.h"
46
47 #define DEBUG_FLAG EMPATHY_DEBUG_OTHER
48 #include <libempathy/empathy-debug.h>
49 #include <libempathy/empathy-utils.h>
50 #include <libempathy/empathy-dispatcher.h>
51 #include <libempathy/empathy-idle.h>
52 #include <libempathy/empathy-ft-factory.h>
53
54 #define SCHEMES "(https?|s?ftps?|nntp|news|javascript|about|ghelp|apt|telnet|"\
55                 "file|webcal|mailto)"
56 #define BODY "([^\\ \\n]+)"
57 #define END_BODY "([^\\ \\n]*[^,;\?><()\\ \"\\.\\n])"
58 #define URI_REGEX "("SCHEMES"://"END_BODY")" \
59                   "|((mailto:)?"BODY"@"BODY"\\."END_BODY")"\
60                   "|((www|ftp)\\."END_BODY")"
61
62 void
63 empathy_gtk_init (void)
64 {
65         static gboolean initialized = FALSE;
66
67         if (initialized)
68                 return;
69
70         empathy_init ();
71         gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
72                                            PKGDATADIR G_DIR_SEPARATOR_S "icons");
73
74         initialized = TRUE;
75 }
76
77 GRegex *
78 empathy_uri_regex_dup_singleton (void)
79 {
80         static GRegex *uri_regex = NULL;
81
82         /* We intentionally leak the regex so it's not recomputed */
83         if (!uri_regex) {
84                 uri_regex = g_regex_new (URI_REGEX, 0, 0, NULL);
85         }
86
87         return g_regex_ref (uri_regex);
88 }
89
90 static GtkBuilder *
91 builder_get_file_valist (const gchar *filename,
92                          const gchar *first_object,
93                          va_list      args)
94 {
95         GtkBuilder  *gui;
96         const gchar *name;
97         GObject    **object_ptr;
98         GError      *error = NULL;
99
100         DEBUG ("Loading file %s", filename);
101
102         gui = gtk_builder_new ();
103         if (!gtk_builder_add_from_file (gui, filename, &error)) {
104                 g_critical ("GtkBuilder Error: %s", error->message);
105                 g_clear_error (&error);
106                 g_object_unref (gui);
107                 return NULL;
108         }
109
110         for (name = first_object; name; name = va_arg (args, const gchar *)) {
111                 object_ptr = va_arg (args, GObject**);
112
113                 *object_ptr = gtk_builder_get_object (gui, name);
114
115                 if (!*object_ptr) {
116                         g_warning ("File is missing object '%s'.", name);
117                         continue;
118                 }
119         }
120
121         return gui;
122 }
123
124 GtkBuilder *
125 empathy_builder_get_file (const gchar *filename,
126                           const gchar *first_object,
127                           ...)
128 {
129         GtkBuilder *gui;
130         va_list     args;
131
132         va_start (args, first_object);
133         gui = builder_get_file_valist (filename, first_object, args);
134         va_end (args);
135
136         return gui;
137 }
138
139 void
140 empathy_builder_connect (GtkBuilder *gui,
141                          gpointer    user_data,
142                          gchar      *first_object,
143                          ...)
144 {
145         va_list      args;
146         const gchar *name;
147         const gchar *signal;
148         GObject     *object;
149         GCallback    callback;
150
151         va_start (args, first_object);
152         for (name = first_object; name; name = va_arg (args, const gchar *)) {
153                 signal = va_arg (args, const gchar *);
154                 callback = va_arg (args, GCallback);
155
156                 object = gtk_builder_get_object (gui, name);
157                 if (!object) {
158                         g_warning ("File is missing object '%s'.", name);
159                         continue;
160                 }
161
162                 g_signal_connect (object, signal, callback, user_data);
163         }
164
165         va_end (args);
166 }
167
168 GtkWidget *
169 empathy_builder_unref_and_keep_widget (GtkBuilder *gui,
170                                        GtkWidget  *widget)
171 {
172         /* On construction gui sinks the initial reference to widget. When gui
173          * is finalized it will drop its ref to widget. We take our own ref to
174          * prevent widget being finalised. The widget is forced to have a
175          * floating reference, like when it was initially unowned so that it can
176          * be used like any other GtkWidget. */
177
178         g_object_ref (widget);
179         g_object_force_floating (G_OBJECT (widget));
180         g_object_unref (gui);
181
182         return widget;
183 }
184
185 const gchar *
186 empathy_icon_name_for_presence (TpConnectionPresenceType presence)
187 {
188         switch (presence) {
189         case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
190                 return EMPATHY_IMAGE_AVAILABLE;
191         case TP_CONNECTION_PRESENCE_TYPE_BUSY:
192                 return EMPATHY_IMAGE_BUSY;
193         case TP_CONNECTION_PRESENCE_TYPE_AWAY:
194                 return EMPATHY_IMAGE_AWAY;
195         case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
196                 return EMPATHY_IMAGE_EXT_AWAY;
197         case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
198                 return EMPATHY_IMAGE_HIDDEN;
199         case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
200         case TP_CONNECTION_PRESENCE_TYPE_ERROR:
201         case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
202                 return EMPATHY_IMAGE_OFFLINE;
203         case TP_CONNECTION_PRESENCE_TYPE_UNSET:
204                 return NULL;
205         }
206
207         return NULL;
208 }
209
210 const gchar *
211 empathy_icon_name_for_contact (EmpathyContact *contact)
212 {
213         TpConnectionPresenceType presence;
214
215         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact),
216                               EMPATHY_IMAGE_OFFLINE);
217
218         presence = empathy_contact_get_presence (contact);
219         return empathy_icon_name_for_presence (presence);
220 }
221
222 GdkPixbuf *
223 empathy_pixbuf_from_data (gchar *data,
224                           gsize  data_size)
225 {
226         return empathy_pixbuf_from_data_and_mime (data, data_size, NULL);
227 }
228
229 GdkPixbuf *
230 empathy_pixbuf_from_data_and_mime (gchar  *data,
231                                    gsize   data_size,
232                                    gchar **mime_type)
233 {
234         GdkPixbufLoader *loader;
235         GdkPixbufFormat *format;
236         GdkPixbuf       *pixbuf = NULL;
237         gchar          **mime_types;
238         GError          *error = NULL;
239
240         if (!data) {
241                 return NULL;
242         }
243
244         loader = gdk_pixbuf_loader_new ();
245         if (!gdk_pixbuf_loader_write (loader, data, data_size, &error)) {
246                 DEBUG ("Failed to write to pixbuf loader: %s",
247                         error ? error->message : "No error given");
248                 goto out;
249         }
250         if (!gdk_pixbuf_loader_close (loader, &error)) {
251                 DEBUG ("Failed to close pixbuf loader: %s",
252                         error ? error->message : "No error given");
253                 goto out;
254         }
255
256         pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
257         if (pixbuf) {
258                 g_object_ref (pixbuf);
259
260                 if (mime_type != NULL) {
261                         format = gdk_pixbuf_loader_get_format (loader);
262                         mime_types = gdk_pixbuf_format_get_mime_types (format);
263
264                         *mime_type = g_strdup (*mime_types);
265                         if (mime_types[1] != NULL) {
266                                 DEBUG ("Loader supports more than one mime "
267                                         "type! Picking the first one, %s",
268                                         *mime_type);
269                         }
270                         g_strfreev (mime_types);
271                 }
272         }
273
274 out:
275         g_clear_error (&error);
276         g_object_unref (loader);
277
278         return pixbuf;
279 }
280
281 struct SizeData {
282         gint     width;
283         gint     height;
284         gboolean preserve_aspect_ratio;
285 };
286
287 static void
288 pixbuf_from_avatar_size_prepared_cb (GdkPixbufLoader *loader,
289                                      int              width,
290                                      int              height,
291                                      struct SizeData *data)
292 {
293         g_return_if_fail (width > 0 && height > 0);
294
295         if (data->preserve_aspect_ratio && (data->width > 0 || data->height > 0)) {
296                 if (width < data->width && height < data->height) {
297                         width = width;
298                         height = height;
299                 }
300
301                 if (data->width < 0) {
302                         width = width * (double) data->height / (gdouble) height;
303                         height = data->height;
304                 } else if (data->height < 0) {
305                         height = height * (double) data->width / (double) width;
306                         width = data->width;
307                 } else if ((double) height * (double) data->width >
308                            (double) width * (double) data->height) {
309                         width = 0.5 + (double) width * (double) data->height / (double) height;
310                         height = data->height;
311                 } else {
312                         height = 0.5 + (double) height * (double) data->width / (double) width;
313                         width = data->width;
314                 }
315         } else {
316                 if (data->width > 0) {
317                         width = data->width;
318                 }
319
320                 if (data->height > 0) {
321                         height = data->height;
322                 }
323         }
324
325         gdk_pixbuf_loader_set_size (loader, width, height);
326 }
327
328 static void
329 empathy_avatar_pixbuf_roundify (GdkPixbuf *pixbuf)
330 {
331         gint width, height, rowstride;
332         guchar *pixels;
333
334         width = gdk_pixbuf_get_width (pixbuf);
335         height = gdk_pixbuf_get_height (pixbuf);
336         rowstride = gdk_pixbuf_get_rowstride (pixbuf);
337         pixels = gdk_pixbuf_get_pixels (pixbuf);
338
339         if (width < 6 || height < 6) {
340                 return;
341         }
342
343         /* Top left */
344         pixels[3] = 0;
345         pixels[7] = 0x80;
346         pixels[11] = 0xC0;
347         pixels[rowstride + 3] = 0x80;
348         pixels[rowstride * 2 + 3] = 0xC0;
349
350         /* Top right */
351         pixels[width * 4 - 1] = 0;
352         pixels[width * 4 - 5] = 0x80;
353         pixels[width * 4 - 9] = 0xC0;
354         pixels[rowstride + (width * 4) - 1] = 0x80;
355         pixels[(2 * rowstride) + (width * 4) - 1] = 0xC0;
356
357         /* Bottom left */
358         pixels[(height - 1) * rowstride + 3] = 0;
359         pixels[(height - 1) * rowstride + 7] = 0x80;
360         pixels[(height - 1) * rowstride + 11] = 0xC0;
361         pixels[(height - 2) * rowstride + 3] = 0x80;
362         pixels[(height - 3) * rowstride + 3] = 0xC0;
363
364         /* Bottom right */
365         pixels[height * rowstride - 1] = 0;
366         pixels[(height - 1) * rowstride - 1] = 0x80;
367         pixels[(height - 2) * rowstride - 1] = 0xC0;
368         pixels[height * rowstride - 5] = 0x80;
369         pixels[height * rowstride - 9] = 0xC0;
370 }
371
372 static gboolean
373 empathy_gdk_pixbuf_is_opaque (GdkPixbuf *pixbuf)
374 {
375         gint width, height, rowstride, i;
376         guchar *pixels;
377         guchar *row;
378
379         width = gdk_pixbuf_get_width (pixbuf);
380         height = gdk_pixbuf_get_height (pixbuf);
381         rowstride = gdk_pixbuf_get_rowstride (pixbuf);
382         pixels = gdk_pixbuf_get_pixels (pixbuf);
383
384         row = pixels;
385         for (i = 3; i < rowstride; i+=4) {
386                 if (row[i] < 0xfe) {
387                         return FALSE;
388                 }
389         }
390
391         for (i = 1; i < height - 1; i++) {
392                 row = pixels + (i*rowstride);
393                 if (row[3] < 0xfe || row[rowstride-1] < 0xfe) {
394                         return FALSE;
395                 }
396         }
397
398         row = pixels + ((height-1) * rowstride);
399         for (i = 3; i < rowstride; i+=4) {
400                 if (row[i] < 0xfe) {
401                         return FALSE;
402                 }
403         }
404
405         return TRUE;
406 }
407
408 GdkPixbuf *
409 empathy_pixbuf_from_avatar_scaled (EmpathyAvatar *avatar,
410                                   gint          width,
411                                   gint          height)
412 {
413         GdkPixbuf        *pixbuf;
414         GdkPixbufLoader  *loader;
415         struct SizeData   data;
416         GError           *error = NULL;
417
418         if (!avatar) {
419                 return NULL;
420         }
421
422         data.width = width;
423         data.height = height;
424         data.preserve_aspect_ratio = TRUE;
425
426         loader = gdk_pixbuf_loader_new ();
427
428         g_signal_connect (loader, "size-prepared",
429                           G_CALLBACK (pixbuf_from_avatar_size_prepared_cb),
430                           &data);
431
432         if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) {
433                 g_warning ("Couldn't write avatar image:%p with "
434                            "length:%" G_GSIZE_FORMAT " to pixbuf loader: %s",
435                            avatar->data, avatar->len, error->message);
436                 g_error_free (error);
437                 return NULL;
438         }
439
440         gdk_pixbuf_loader_close (loader, NULL);
441
442         pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
443         if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
444                 GdkPixbuf *rounded_pixbuf;
445
446                 rounded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
447                                                  gdk_pixbuf_get_width (pixbuf),
448                                                  gdk_pixbuf_get_height (pixbuf));
449                 gdk_pixbuf_copy_area (pixbuf, 0, 0,
450                                       gdk_pixbuf_get_width (pixbuf),
451                                       gdk_pixbuf_get_height (pixbuf),
452                                       rounded_pixbuf,
453                                       0, 0);
454                 pixbuf = rounded_pixbuf;
455         } else {
456                 g_object_ref (pixbuf);
457         }
458
459         if (empathy_gdk_pixbuf_is_opaque (pixbuf)) {
460                 empathy_avatar_pixbuf_roundify (pixbuf);
461         }
462
463         g_object_unref (loader);
464
465         return pixbuf;
466 }
467
468 GdkPixbuf *
469 empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact *contact,
470                                           gint           width,
471                                           gint           height)
472 {
473         EmpathyAvatar *avatar;
474
475         g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
476
477         avatar = empathy_contact_get_avatar (contact);
478
479         return empathy_pixbuf_from_avatar_scaled (avatar, width, height);
480 }
481
482 GdkPixbuf *
483 empathy_pixbuf_scale_down_if_necessary (GdkPixbuf *pixbuf, gint max_size)
484 {
485         gint      width, height;
486         gdouble   factor;
487
488         width = gdk_pixbuf_get_width (pixbuf);
489         height = gdk_pixbuf_get_height (pixbuf);
490
491         if (width > 0 && (width > max_size || height > max_size)) {
492                 factor = (gdouble) max_size / MAX (width, height);
493
494                 width = width * factor;
495                 height = height * factor;
496
497                 return gdk_pixbuf_scale_simple (pixbuf,
498                                                 width, height,
499                                                 GDK_INTERP_HYPER);
500         }
501
502         return g_object_ref (pixbuf);
503 }
504
505 GdkPixbuf *
506 empathy_pixbuf_from_icon_name_sized (const gchar *icon_name,
507                                      gint size)
508 {
509         GtkIconTheme *theme;
510         GdkPixbuf *pixbuf;
511         GError *error = NULL;
512
513         if (!icon_name) {
514                 return NULL;
515         }
516
517         theme = gtk_icon_theme_get_default ();
518
519         pixbuf = gtk_icon_theme_load_icon (theme,
520                                            icon_name,
521                                            size,
522                                            0,
523                                            &error);
524         if (error) {
525                 DEBUG ("Error loading icon: %s", error->message);
526                 g_clear_error (&error);
527         }
528
529         return pixbuf;
530 }
531
532 GdkPixbuf *
533 empathy_pixbuf_from_icon_name (const gchar *icon_name,
534                                GtkIconSize  icon_size)
535 {
536         gint  w, h;
537         gint  size = 48;
538
539         if (!icon_name) {
540                 return NULL;
541         }
542
543         if (gtk_icon_size_lookup (icon_size, &w, &h)) {
544                 size = (w + h) / 2;
545         }
546
547         return empathy_pixbuf_from_icon_name_sized (icon_name, size);
548 }
549
550 gchar *
551 empathy_filename_from_icon_name (const gchar *icon_name,
552                                  GtkIconSize  icon_size)
553 {
554         GtkIconTheme *icon_theme;
555         GtkIconInfo  *icon_info;
556         gint          w, h;
557         gint          size = 48;
558         gchar        *ret;
559
560         icon_theme = gtk_icon_theme_get_default ();
561
562         if (gtk_icon_size_lookup (icon_size, &w, &h)) {
563                 size = (w + h) / 2;
564         }
565
566         icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name, size, 0);
567         ret = g_strdup (gtk_icon_info_get_filename (icon_info));
568         gtk_icon_info_free (icon_info);
569
570         return ret;
571 }
572
573 /* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
574  * that to make it easier to apply changes from the original code.
575  */
576 #define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
577
578 /* this function acts like g_utf8_offset_to_pointer() except that if it finds a
579  * decomposable character it consumes the decomposition length from the given
580  * offset.  So it's useful when the offset was calculated for the normalized
581  * version of str, but we need a pointer to str itself. */
582 static const gchar *
583 pointer_from_offset_skipping_decomp (const gchar *str, gint offset)
584 {
585         gchar *casefold, *normal;
586         const gchar *p, *q;
587
588         p = str;
589         while (offset > 0)
590         {
591                 q = g_utf8_next_char (p);
592                 casefold = g_utf8_casefold (p, q - p);
593                 normal = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
594                 offset -= g_utf8_strlen (normal, -1);
595                 g_free (casefold);
596                 g_free (normal);
597                 p = q;
598         }
599         return p;
600 }
601
602 static const gchar *
603 g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
604 {
605         gsize needle_len;
606         gsize haystack_len;
607         const gchar *ret = NULL;
608         gchar *p;
609         gchar *casefold;
610         gchar *caseless_haystack;
611         gint i;
612
613         g_return_val_if_fail (haystack != NULL, NULL);
614         g_return_val_if_fail (needle != NULL, NULL);
615
616         casefold = g_utf8_casefold (haystack, -1);
617         caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
618         g_free (casefold);
619
620         needle_len = g_utf8_strlen (needle, -1);
621         haystack_len = g_utf8_strlen (caseless_haystack, -1);
622
623         if (needle_len == 0)
624         {
625                 ret = (gchar *) haystack;
626                 goto finally_1;
627         }
628
629         if (haystack_len < needle_len)
630         {
631                 ret = NULL;
632                 goto finally_1;
633         }
634
635         p = (gchar *) caseless_haystack;
636         needle_len = strlen (needle);
637         i = 0;
638
639         while (*p)
640         {
641                 if ((strncmp (p, needle, needle_len) == 0))
642                 {
643                         ret = pointer_from_offset_skipping_decomp (haystack, i);
644                         goto finally_1;
645                 }
646
647                 p = g_utf8_next_char (p);
648                 i++;
649         }
650
651 finally_1:
652         g_free (caseless_haystack);
653
654         return ret;
655 }
656
657 static gboolean
658 g_utf8_caselessnmatch (const char *s1, const char *s2,
659                        gssize n1, gssize n2)
660 {
661         gchar *casefold;
662         gchar *normalized_s1;
663         gchar *normalized_s2;
664         gint len_s1;
665         gint len_s2;
666         gboolean ret = FALSE;
667
668         g_return_val_if_fail (s1 != NULL, FALSE);
669         g_return_val_if_fail (s2 != NULL, FALSE);
670         g_return_val_if_fail (n1 > 0, FALSE);
671         g_return_val_if_fail (n2 > 0, FALSE);
672
673         casefold = g_utf8_casefold (s1, n1);
674         normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
675         g_free (casefold);
676
677         casefold = g_utf8_casefold (s2, n2);
678         normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
679         g_free (casefold);
680
681         len_s1 = strlen (normalized_s1);
682         len_s2 = strlen (normalized_s2);
683
684         if (len_s1 < len_s2)
685                 goto finally_2;
686
687         ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0);
688
689 finally_2:
690         g_free (normalized_s1);
691         g_free (normalized_s2);
692
693         return ret;
694 }
695
696 static void
697 forward_chars_with_skipping (GtkTextIter *iter,
698                              gint         count,
699                              gboolean     skip_invisible,
700                              gboolean     skip_nontext,
701                              gboolean     skip_decomp)
702 {
703         gint i;
704
705         g_return_if_fail (count >= 0);
706
707         i = count;
708
709         while (i > 0)
710         {
711                 gboolean ignored = FALSE;
712
713                 /* minimal workaround to avoid the infinite loop of bug #168247.
714                  * It doesn't fix the problemjust the symptom...
715                  */
716                 if (gtk_text_iter_is_end (iter))
717                         return;
718
719                 if (skip_nontext && gtk_text_iter_get_char (iter) == GTK_TEXT_UNKNOWN_CHAR)
720                         ignored = TRUE;
721
722                 if (!ignored && skip_invisible &&
723                     /* _gtk_text_btree_char_is_invisible (iter)*/ FALSE)
724                         ignored = TRUE;
725
726                 if (!ignored && skip_decomp)
727                 {
728                         /* being UTF8 correct sucks; this accounts for extra
729                            offsets coming from canonical decompositions of
730                            UTF8 characters (e.g. accented characters) which
731                            g_utf8_normalize () performs */
732                         gchar *normal;
733                         gchar buffer[6];
734                         gint buffer_len;
735
736                         buffer_len = g_unichar_to_utf8 (gtk_text_iter_get_char (iter), buffer);
737                         normal = g_utf8_normalize (buffer, buffer_len, G_NORMALIZE_NFD);
738                         i -= (g_utf8_strlen (normal, -1) - 1);
739                         g_free (normal);
740                 }
741
742                 gtk_text_iter_forward_char (iter);
743
744                 if (!ignored)
745                         --i;
746         }
747 }
748
749 static gboolean
750 lines_match (const GtkTextIter *start,
751              const gchar      **lines,
752              gboolean           visible_only,
753              gboolean           slice,
754              GtkTextIter       *match_start,
755              GtkTextIter       *match_end)
756 {
757         GtkTextIter next;
758         gchar *line_text;
759         const gchar *found;
760         gint offset;
761
762         if (*lines == NULL || **lines == '\0')
763         {
764                 if (match_start)
765                         *match_start = *start;
766                 if (match_end)
767                         *match_end = *start;
768                 return TRUE;
769         }
770
771         next = *start;
772         gtk_text_iter_forward_line (&next);
773
774         /* No more text in buffer, but *lines is nonempty */
775         if (gtk_text_iter_equal (start, &next))
776                 return FALSE;
777
778         if (slice)
779         {
780                 if (visible_only)
781                         line_text = gtk_text_iter_get_visible_slice (start, &next);
782                 else
783                         line_text = gtk_text_iter_get_slice (start, &next);
784         }
785         else
786         {
787                 if (visible_only)
788                         line_text = gtk_text_iter_get_visible_text (start, &next);
789                 else
790                         line_text = gtk_text_iter_get_text (start, &next);
791         }
792
793         if (match_start) /* if this is the first line we're matching */
794         {
795                 found = g_utf8_strcasestr (line_text, *lines);
796         }
797         else
798         {
799                 /* If it's not the first line, we have to match from the
800                  * start of the line.
801                  */
802                 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
803                                            strlen (*lines)))
804                         found = line_text;
805                 else
806                         found = NULL;
807         }
808
809         if (found == NULL)
810         {
811                 g_free (line_text);
812                 return FALSE;
813         }
814
815         /* Get offset to start of search string */
816         offset = g_utf8_strlen (line_text, found - line_text);
817
818         next = *start;
819
820         /* If match start needs to be returned, set it to the
821          * start of the search string.
822          */
823         forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
824         if (match_start)
825         {
826                 *match_start = next;
827         }
828
829         /* Go to end of search string */
830         forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
831
832         g_free (line_text);
833
834         ++lines;
835
836         if (match_end)
837                 *match_end = next;
838
839         /* pass NULL for match_start, since we don't need to find the
840          * start again.
841          */
842         return lines_match (&next, lines, visible_only, slice, NULL, match_end);
843 }
844
845 /* strsplit () that retains the delimiter as part of the string. */
846 static gchar **
847 strbreakup (const char *string,
848             const char *delimiter,
849             gint        max_tokens)
850 {
851         GSList *string_list = NULL, *slist;
852         gchar **str_array, *s, *casefold, *new_string;
853         guint i, n = 1;
854
855         g_return_val_if_fail (string != NULL, NULL);
856         g_return_val_if_fail (delimiter != NULL, NULL);
857
858         if (max_tokens < 1)
859                 max_tokens = G_MAXINT;
860
861         s = strstr (string, delimiter);
862         if (s)
863         {
864                 guint delimiter_len = strlen (delimiter);
865
866                 do
867                 {
868                         guint len;
869
870                         len = s - string + delimiter_len;
871                         new_string = g_new (gchar, len + 1);
872                         strncpy (new_string, string, len);
873                         new_string[len] = 0;
874                         casefold = g_utf8_casefold (new_string, -1);
875                         g_free (new_string);
876                         new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
877                         g_free (casefold);
878                         string_list = g_slist_prepend (string_list, new_string);
879                         n++;
880                         string = s + delimiter_len;
881                         s = strstr (string, delimiter);
882                 } while (--max_tokens && s);
883         }
884
885         if (*string)
886         {
887                 n++;
888                 casefold = g_utf8_casefold (string, -1);
889                 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
890                 g_free (casefold);
891                 string_list = g_slist_prepend (string_list, new_string);
892         }
893
894         str_array = g_new (gchar*, n);
895
896         i = n - 1;
897
898         str_array[i--] = NULL;
899         for (slist = string_list; slist; slist = slist->next)
900                 str_array[i--] = slist->data;
901
902         g_slist_free (string_list);
903
904         return str_array;
905 }
906
907 gboolean
908 empathy_text_iter_forward_search (const GtkTextIter   *iter,
909                                  const gchar         *str,
910                                  GtkTextIter         *match_start,
911                                  GtkTextIter         *match_end,
912                                  const GtkTextIter   *limit)
913 {
914         gchar **lines = NULL;
915         GtkTextIter match;
916         gboolean retval = FALSE;
917         GtkTextIter search;
918         gboolean visible_only;
919         gboolean slice;
920
921         g_return_val_if_fail (iter != NULL, FALSE);
922         g_return_val_if_fail (str != NULL, FALSE);
923
924         if (limit && gtk_text_iter_compare (iter, limit) >= 0)
925                 return FALSE;
926
927         if (*str == '\0') {
928                 /* If we can move one char, return the empty string there */
929                 match = *iter;
930
931                 if (gtk_text_iter_forward_char (&match)) {
932                         if (limit && gtk_text_iter_equal (&match, limit)) {
933                                 return FALSE;
934                         }
935
936                         if (match_start) {
937                                 *match_start = match;
938                         }
939                         if (match_end) {
940                                 *match_end = match;
941                         }
942                         return TRUE;
943                 } else {
944                         return FALSE;
945                 }
946         }
947
948         visible_only = TRUE;
949         slice = FALSE;
950
951         /* locate all lines */
952         lines = strbreakup (str, "\n", -1);
953
954         search = *iter;
955
956         do {
957                 /* This loop has an inefficient worst-case, where
958                  * gtk_text_iter_get_text () is called repeatedly on
959                  * a single line.
960                  */
961                 GtkTextIter end;
962
963                 if (limit && gtk_text_iter_compare (&search, limit) >= 0) {
964                         break;
965                 }
966
967                 if (lines_match (&search, (const gchar**)lines,
968                                  visible_only, slice, &match, &end)) {
969                         if (limit == NULL ||
970                             (limit && gtk_text_iter_compare (&end, limit) <= 0)) {
971                                 retval = TRUE;
972
973                                 if (match_start) {
974                                         *match_start = match;
975                                 }
976                                 if (match_end) {
977                                         *match_end = end;
978                                 }
979                         }
980                         break;
981                 }
982         } while (gtk_text_iter_forward_line (&search));
983
984         g_strfreev ((gchar **) lines);
985
986         return retval;
987 }
988
989 static const gchar *
990 g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
991 {
992         gsize needle_len;
993         gsize haystack_len;
994         const gchar *ret = NULL;
995         gchar *p;
996         gchar *casefold;
997         gchar *caseless_haystack;
998         gint i;
999
1000         g_return_val_if_fail (haystack != NULL, NULL);
1001         g_return_val_if_fail (needle != NULL, NULL);
1002
1003         casefold = g_utf8_casefold (haystack, -1);
1004         caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
1005         g_free (casefold);
1006
1007         needle_len = g_utf8_strlen (needle, -1);
1008         haystack_len = g_utf8_strlen (caseless_haystack, -1);
1009
1010         if (needle_len == 0)
1011         {
1012                 ret = (gchar *) haystack;
1013                 goto finally_1;
1014         }
1015
1016         if (haystack_len < needle_len)
1017         {
1018                 ret = NULL;
1019                 goto finally_1;
1020         }
1021
1022         i = haystack_len - needle_len;
1023         p = g_utf8_offset_to_pointer (caseless_haystack, i);
1024         needle_len = strlen (needle);
1025
1026         while (p >= caseless_haystack)
1027         {
1028                 if (strncmp (p, needle, needle_len) == 0)
1029                 {
1030                         ret = pointer_from_offset_skipping_decomp (haystack, i);
1031                         goto finally_1;
1032                 }
1033
1034                 p = g_utf8_prev_char (p);
1035                 i--;
1036         }
1037
1038 finally_1:
1039         g_free (caseless_haystack);
1040
1041         return ret;
1042 }
1043
1044 static gboolean
1045 backward_lines_match (const GtkTextIter *start,
1046                       const gchar      **lines,
1047                       gboolean           visible_only,
1048                       gboolean           slice,
1049                       GtkTextIter       *match_start,
1050                       GtkTextIter       *match_end)
1051 {
1052         GtkTextIter line, next;
1053         gchar *line_text;
1054         const gchar *found;
1055         gint offset;
1056
1057         if (*lines == NULL || **lines == '\0')
1058         {
1059                 if (match_start)
1060                         *match_start = *start;
1061                 if (match_end)
1062                         *match_end = *start;
1063                 return TRUE;
1064         }
1065
1066         line = next = *start;
1067         if (gtk_text_iter_get_line_offset (&next) == 0)
1068         {
1069                 if (!gtk_text_iter_backward_line (&next))
1070                         return FALSE;
1071         }
1072         else
1073                 gtk_text_iter_set_line_offset (&next, 0);
1074
1075         if (slice)
1076         {
1077                 if (visible_only)
1078                         line_text = gtk_text_iter_get_visible_slice (&next, &line);
1079                 else
1080                         line_text = gtk_text_iter_get_slice (&next, &line);
1081         }
1082         else
1083         {
1084                 if (visible_only)
1085                         line_text = gtk_text_iter_get_visible_text (&next, &line);
1086                 else
1087                         line_text = gtk_text_iter_get_text (&next, &line);
1088         }
1089
1090         if (match_start) /* if this is the first line we're matching */
1091         {
1092                 found = g_utf8_strrcasestr (line_text, *lines);
1093         }
1094         else
1095         {
1096                 /* If it's not the first line, we have to match from the
1097                  * start of the line.
1098                  */
1099                 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
1100                                            strlen (*lines)))
1101                         found = line_text;
1102                 else
1103                         found = NULL;
1104         }
1105
1106         if (found == NULL)
1107         {
1108                 g_free (line_text);
1109                 return FALSE;
1110         }
1111
1112         /* Get offset to start of search string */
1113         offset = g_utf8_strlen (line_text, found - line_text);
1114
1115         forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
1116
1117         /* If match start needs to be returned, set it to the
1118          * start of the search string.
1119          */
1120         if (match_start)
1121         {
1122                 *match_start = next;
1123         }
1124
1125         /* Go to end of search string */
1126         forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
1127
1128         g_free (line_text);
1129
1130         ++lines;
1131
1132         if (match_end)
1133                 *match_end = next;
1134
1135         /* try to match the rest of the lines forward, passing NULL
1136          * for match_start so lines_match will try to match the entire
1137          * line */
1138         return lines_match (&next, lines, visible_only,
1139                             slice, NULL, match_end);
1140 }
1141
1142 gboolean
1143 empathy_text_iter_backward_search (const GtkTextIter   *iter,
1144                                   const gchar         *str,
1145                                   GtkTextIter         *match_start,
1146                                   GtkTextIter         *match_end,
1147                                   const GtkTextIter   *limit)
1148 {
1149         gchar **lines = NULL;
1150         GtkTextIter match;
1151         gboolean retval = FALSE;
1152         GtkTextIter search;
1153         gboolean visible_only;
1154         gboolean slice;
1155
1156         g_return_val_if_fail (iter != NULL, FALSE);
1157         g_return_val_if_fail (str != NULL, FALSE);
1158
1159         if (limit && gtk_text_iter_compare (iter, limit) <= 0)
1160                 return FALSE;
1161
1162         if (*str == '\0')
1163         {
1164                 /* If we can move one char, return the empty string there */
1165                 match = *iter;
1166
1167                 if (gtk_text_iter_backward_char (&match))
1168                 {
1169                         if (limit && gtk_text_iter_equal (&match, limit))
1170                                 return FALSE;
1171
1172                         if (match_start)
1173                                 *match_start = match;
1174                         if (match_end)
1175                                 *match_end = match;
1176                         return TRUE;
1177                 }
1178                 else
1179                 {
1180                         return FALSE;
1181                 }
1182         }
1183
1184         visible_only = TRUE;
1185         slice = TRUE;
1186
1187         /* locate all lines */
1188         lines = strbreakup (str, "\n", -1);
1189
1190         search = *iter;
1191
1192         while (TRUE)
1193         {
1194                 /* This loop has an inefficient worst-case, where
1195                  * gtk_text_iter_get_text () is called repeatedly on
1196                  * a single line.
1197                  */
1198                 GtkTextIter end;
1199
1200                 if (limit && gtk_text_iter_compare (&search, limit) <= 0)
1201                         break;
1202
1203                 if (backward_lines_match (&search, (const gchar**)lines,
1204                                           visible_only, slice, &match, &end))
1205                 {
1206                         if (limit == NULL || (limit &&
1207                                               gtk_text_iter_compare (&end, limit) > 0))
1208                         {
1209                                 retval = TRUE;
1210
1211                                 if (match_start)
1212                                         *match_start = match;
1213                                 if (match_end)
1214                                         *match_end = end;
1215                         }
1216                         break;
1217                 }
1218
1219                 if (gtk_text_iter_get_line_offset (&search) == 0)
1220                 {
1221                         if (!gtk_text_iter_backward_line (&search))
1222                                 break;
1223                 }
1224                 else
1225                 {
1226                         gtk_text_iter_set_line_offset (&search, 0);
1227                 }
1228         }
1229
1230         g_strfreev ((gchar **) lines);
1231
1232         return retval;
1233 }
1234
1235 gboolean
1236 empathy_window_get_is_visible (GtkWindow *window)
1237 {
1238         GdkWindowState  state;
1239         GdkWindow      *gdk_window;
1240
1241         g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1242
1243         gdk_window = GTK_WIDGET (window)->window;
1244         if (!gdk_window) {
1245                 return FALSE;
1246         }
1247
1248         state = gdk_window_get_state (gdk_window);
1249         if (state & (GDK_WINDOW_STATE_WITHDRAWN | GDK_WINDOW_STATE_ICONIFIED)) {
1250                 return FALSE;
1251         }
1252
1253         return TRUE;
1254 }
1255
1256 void
1257 empathy_window_iconify (GtkWindow *window, GtkStatusIcon *status_icon)
1258 {
1259         GdkRectangle  icon_location;
1260         gulong        data[4];
1261         Display      *dpy;
1262         GdkWindow    *gdk_window;
1263
1264         gtk_status_icon_get_geometry (status_icon, NULL, &icon_location, NULL);
1265         gdk_window = GTK_WIDGET (window)->window;
1266         dpy = gdk_x11_drawable_get_xdisplay (gdk_window);
1267
1268         data[0] = icon_location.x;
1269         data[1] = icon_location.y;
1270         data[2] = icon_location.width;
1271         data[3] = icon_location.height;
1272
1273         XChangeProperty (dpy,
1274                          GDK_WINDOW_XID (gdk_window),
1275                          gdk_x11_get_xatom_by_name_for_display (gdk_drawable_get_display (gdk_window),
1276                          "_NET_WM_ICON_GEOMETRY"),
1277                          XA_CARDINAL, 32, PropModeReplace,
1278                          (guchar *)&data, 4);
1279
1280         gtk_window_set_skip_taskbar_hint (window, TRUE);
1281         gtk_window_iconify (window);
1282 }
1283
1284 /* Takes care of moving the window to the current workspace. */
1285 void
1286 empathy_window_present (GtkWindow *window,
1287                         gboolean   steal_focus)
1288 {
1289         guint32 timestamp;
1290
1291         g_return_if_fail (GTK_IS_WINDOW (window));
1292
1293         /* There are three cases: hidden, visible, visible on another
1294          * workspace.
1295          */
1296
1297         if (!empathy_window_get_is_visible (window)) {
1298                 /* Hide it so present brings it to the current workspace. */
1299                 gtk_widget_hide (GTK_WIDGET (window));
1300         }
1301
1302         timestamp = gtk_get_current_event_time ();
1303         gtk_window_present_with_time (window, timestamp);
1304         gtk_window_set_skip_taskbar_hint (window, FALSE);
1305         /* FIXME: This shouldn't be required as gtk_window_present's doc says
1306          *        it deiconify automatically. */
1307         gtk_window_deiconify (window);
1308 }
1309
1310 GtkWindow *
1311 empathy_get_toplevel_window (GtkWidget *widget)
1312 {
1313         GtkWidget *toplevel;
1314
1315         g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1316
1317         toplevel = gtk_widget_get_toplevel (widget);
1318         if (GTK_IS_WINDOW (toplevel) &&
1319             GTK_WIDGET_TOPLEVEL (toplevel)) {
1320                 return GTK_WINDOW (toplevel);
1321         }
1322
1323         return NULL;
1324 }
1325
1326 /* The URL opening code can't handle schemeless strings, so we try to be
1327  * smart and add http if there is no scheme or doesn't look like a mail
1328  * address. This should work in most cases, and let us click on strings
1329  * like "www.gnome.org".
1330  */
1331 static gchar *
1332 fixup_url (const gchar *url)
1333 {
1334         if (g_str_has_prefix (url, "ghelp:") ||
1335             g_str_has_prefix (url, "mailto:") ||
1336             strstr (url, ":/")) {
1337                 return NULL;
1338         }
1339
1340         if (strstr (url, "@")) {
1341                 return g_strdup_printf ("mailto:%s", url);
1342         }
1343
1344         return g_strdup_printf ("http://%s", url);
1345 }
1346
1347 void
1348 empathy_url_show (GtkWidget *parent,
1349                   const char *url)
1350 {
1351         gchar  *real_url;
1352         GError *error = NULL;
1353
1354         real_url = fixup_url (url);
1355         if (real_url) {
1356                 url = real_url;
1357         }
1358
1359         gtk_show_uri (gtk_widget_get_screen (parent), url,
1360                       gtk_get_current_event_time (), &error);
1361
1362         if (error) {
1363                 GtkWidget *dialog;
1364
1365                 dialog = gtk_message_dialog_new (NULL, 0,
1366                                                  GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE,
1367                                                  _("Unable to open URI"));
1368                 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
1369                                                           "%s", error->message);
1370
1371                 g_signal_connect (dialog, "response",
1372                                   G_CALLBACK (gtk_widget_destroy),
1373                                   NULL);
1374                 gtk_window_present (GTK_WINDOW (dialog));
1375
1376                 g_clear_error (&error);
1377         }
1378
1379         g_free (real_url);
1380 }
1381
1382 static void
1383 link_button_hook (GtkLinkButton *button,
1384                   const gchar *link,
1385                   gpointer user_data)
1386 {
1387         empathy_url_show (GTK_WIDGET (button), link);
1388 }
1389
1390 GtkWidget *
1391 empathy_link_button_new (const gchar *url,
1392                         const gchar *title)
1393 {
1394         static gboolean hook = FALSE;
1395
1396         if (!hook) {
1397                 hook = TRUE;
1398                 gtk_link_button_set_uri_hook (link_button_hook, NULL, NULL);
1399         }
1400
1401         return gtk_link_button_new_with_label (url, title);
1402 }
1403
1404 void
1405 empathy_toggle_button_set_state_quietly (GtkWidget *widget,
1406                                         GCallback  callback,
1407                                         gpointer   user_data,
1408                                         gboolean   active)
1409 {
1410         g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
1411
1412         g_signal_handlers_block_by_func (widget, callback, user_data);
1413         g_object_set (widget, "active", active, NULL);
1414         g_signal_handlers_unblock_by_func (widget, callback, user_data);
1415 }
1416
1417 static void
1418 file_manager_send_file_response_cb (GtkDialog      *widget,
1419                                     gint            response_id,
1420                                     EmpathyContact *contact)
1421 {
1422         EmpathyFTFactory *factory;
1423         GFile *file;
1424         gchar *uri;
1425         GtkRecentManager *manager;
1426
1427         if (response_id == GTK_RESPONSE_OK) {
1428                 file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (widget));
1429                 uri = g_file_get_uri (file);
1430
1431                 factory = empathy_ft_factory_dup_singleton ();
1432
1433                 empathy_ft_factory_new_transfer_outgoing (factory, contact,
1434                                                           file);
1435
1436                 manager = gtk_recent_manager_get_default ();
1437                 gtk_recent_manager_add_item (manager, uri);
1438
1439                 g_free (uri);
1440                 g_object_unref (factory);
1441                 g_object_unref (file);
1442         }
1443
1444         gtk_widget_destroy (GTK_WIDGET (widget));
1445 }
1446
1447 void
1448 empathy_send_file_with_file_chooser (EmpathyContact *contact)
1449 {
1450         GtkWidget               *widget;
1451         GtkWidget               *button;
1452
1453         g_return_if_fail (EMPATHY_IS_CONTACT (contact));
1454
1455         DEBUG ("Creating selection file chooser");
1456
1457         widget = gtk_file_chooser_dialog_new (_("Select a file"),
1458                                               NULL,
1459                                               GTK_FILE_CHOOSER_ACTION_OPEN,
1460                                               GTK_STOCK_CANCEL,
1461                                               GTK_RESPONSE_CANCEL,
1462                                               NULL);
1463
1464         /* send button */
1465         button = gtk_button_new_with_mnemonic (_("_Send"));
1466         gtk_button_set_image (GTK_BUTTON (button),
1467                 gtk_image_new_from_icon_name (EMPATHY_IMAGE_DOCUMENT_SEND,
1468                                               GTK_ICON_SIZE_BUTTON));
1469         gtk_widget_show (button);
1470         gtk_dialog_add_action_widget (GTK_DIALOG (widget), button,
1471                                       GTK_RESPONSE_OK);
1472         GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
1473         gtk_dialog_set_default_response (GTK_DIALOG (widget),
1474                                          GTK_RESPONSE_OK);
1475
1476         g_signal_connect (widget, "response",
1477                           G_CALLBACK (file_manager_send_file_response_cb),
1478                           contact);
1479
1480         gtk_widget_show (widget);
1481 }
1482
1483 static void
1484 file_manager_receive_file_response_cb (GtkDialog *dialog,
1485                                        GtkResponseType response,
1486                                        EmpathyFTHandler *handler)
1487 {
1488         EmpathyFTFactory *factory;
1489         GFile *file;
1490
1491         if (response == GTK_RESPONSE_OK) {
1492                 factory = empathy_ft_factory_dup_singleton ();
1493                 file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
1494
1495                 empathy_ft_factory_set_destination_for_incoming_handler
1496                         (factory, handler, file);
1497
1498                 g_object_unref (factory);
1499                 g_object_unref (file);
1500         } else {
1501                 /* unref the handler, as we dismissed the file chooser,
1502                  * and refused the transfer.
1503                  */
1504                 g_object_unref (handler);
1505         }
1506
1507         gtk_widget_destroy (GTK_WIDGET (dialog));
1508 }
1509
1510 void
1511 empathy_receive_file_with_file_chooser (EmpathyFTHandler *handler)
1512 {
1513         GtkWidget *widget;
1514
1515         widget = gtk_file_chooser_dialog_new (_("Select a destination"),
1516                                               NULL,
1517                                               GTK_FILE_CHOOSER_ACTION_SAVE,
1518                                               GTK_STOCK_CANCEL,
1519                                               GTK_RESPONSE_CANCEL,
1520                                               GTK_STOCK_SAVE,
1521                                               GTK_RESPONSE_OK,
1522                                               NULL);
1523         gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (widget),
1524                 empathy_ft_handler_get_filename (handler));
1525         gtk_file_chooser_set_do_overwrite_confirmation
1526                 (GTK_FILE_CHOOSER (widget), TRUE);
1527
1528         g_signal_connect (widget, "response",
1529                 G_CALLBACK (file_manager_receive_file_response_cb), handler);
1530
1531         gtk_widget_show (widget);
1532 }