1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2002-2007 Imendio AB
4 * Copyright (C) 2007 Collabora Ltd.
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.
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.
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
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>
26 * Part of this file is copied from GtkSourceView (gtksourceiter.c):
32 #include <X11/Xatom.h>
34 #include <glib/gi18n.h>
36 #include <glade/glade.h>
37 #include <libgnomevfs/gnome-vfs-utils.h>
39 #include <libmissioncontrol/mc-profile.h>
41 #include <libempathy/empathy-debug.h>
43 #include "empathy-ui-utils.h"
44 #include "empathy-images.h"
46 #define DEBUG_DOMAIN "UiUtils"
51 gboolean preserve_aspect_ratio;
55 get_glade_file (const gchar *filename,
58 const gchar *first_required_widget,
64 GtkWidget **widget_ptr;
66 path = g_build_filename (DATADIR, "empathy", filename, NULL);
67 gui = glade_xml_new (path, root, domain);
71 g_warning ("Couldn't find necessary glade file '%s'", filename);
75 for (name = first_required_widget; name; name = va_arg (args, char *)) {
76 widget_ptr = va_arg (args, void *);
78 *widget_ptr = glade_xml_get_widget (gui, name);
81 g_warning ("Glade file '%s' is missing widget '%s'.",
91 empathy_glade_get_file_simple (const gchar *filename,
94 const gchar *first_required_widget, ...)
99 va_start (args, first_required_widget);
101 gui = get_glade_file (filename,
104 first_required_widget,
113 g_object_unref (gui);
117 empathy_glade_get_file (const gchar *filename,
120 const gchar *first_required_widget, ...)
125 va_start (args, first_required_widget);
127 gui = get_glade_file (filename,
130 first_required_widget,
143 empathy_glade_connect (GladeXML *gui,
145 gchar *first_widget, ...)
153 va_start (args, first_widget);
155 for (name = first_widget; name; name = va_arg (args, char *)) {
156 signal = va_arg (args, void *);
157 callback = va_arg (args, void *);
159 widget = glade_xml_get_widget (gui, name);
161 g_warning ("Glade file is missing widget '%s', aborting",
166 g_signal_connect (widget,
168 G_CALLBACK (callback),
176 empathy_glade_setup_size_group (GladeXML *gui,
177 GtkSizeGroupMode mode,
178 gchar *first_widget, ...)
182 GtkSizeGroup *size_group;
185 va_start (args, first_widget);
187 size_group = gtk_size_group_new (mode);
189 for (name = first_widget; name; name = va_arg (args, char *)) {
190 widget = glade_xml_get_widget (gui, name);
192 g_warning ("Glade file is missing widget '%s'", name);
196 gtk_size_group_add_widget (size_group, widget);
199 g_object_unref (size_group);
205 empathy_pixbuf_from_icon_name (const gchar *icon_name,
206 GtkIconSize icon_size)
209 GdkPixbuf *pixbuf = NULL;
210 GError *error = NULL;
214 theme = gtk_icon_theme_get_default ();
216 if (gtk_icon_size_lookup (icon_size, &w, &h)) {
220 pixbuf = gtk_icon_theme_load_icon (theme,
226 empathy_debug (DEBUG_DOMAIN, "Error loading icon: %s", error->message);
227 g_clear_error (&error);
234 empathy_icon_name_from_account (McAccount *account)
238 profile = mc_account_get_profile (account);
240 return mc_profile_get_icon_name (profile);
244 empathy_icon_name_for_presence_state (McPresence state)
247 case MC_PRESENCE_AVAILABLE:
248 return EMPATHY_IMAGE_AVAILABLE;
249 case MC_PRESENCE_DO_NOT_DISTURB:
250 return EMPATHY_IMAGE_BUSY;
251 case MC_PRESENCE_AWAY:
252 return EMPATHY_IMAGE_AWAY;
253 case MC_PRESENCE_EXTENDED_AWAY:
254 return EMPATHY_IMAGE_EXT_AWAY;
255 case MC_PRESENCE_HIDDEN:
256 return EMPATHY_IMAGE_HIDDEN;
257 case MC_PRESENCE_OFFLINE:
258 case MC_PRESENCE_UNSET:
259 return EMPATHY_IMAGE_OFFLINE;
261 g_assert_not_reached ();
268 empathy_icon_name_for_presence (EmpathyPresence *presence)
272 g_return_val_if_fail (EMPATHY_IS_PRESENCE (presence),
273 EMPATHY_IMAGE_OFFLINE);
275 state = empathy_presence_get_state (presence);
277 return empathy_icon_name_for_presence_state (state);
281 empathy_icon_name_for_contact (EmpathyContact *contact)
283 EmpathyPresence *presence;
285 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact),
286 EMPATHY_IMAGE_OFFLINE);
288 presence = empathy_contact_get_presence (contact);
290 return empathy_icon_name_for_presence (presence);
293 return EMPATHY_IMAGE_UNKNOWN;
297 pixbuf_from_avatar_size_prepared_cb (GdkPixbufLoader *loader,
300 struct SizeData *data)
302 g_return_if_fail (width > 0 && height > 0);
304 if (data->preserve_aspect_ratio && (data->width > 0 || data->height > 0)) {
305 if (width < data->width && height < data->height) {
310 if (data->width < 0) {
311 width = width * (double) data->height / (gdouble) height;
312 height = data->height;
313 } else if (data->height < 0) {
314 height = height * (double) data->width / (double) width;
316 } else if ((double) height * (double) data->width >
317 (double) width * (double) data->height) {
318 width = 0.5 + (double) width * (double) data->height / (double) height;
319 height = data->height;
321 height = 0.5 + (double) height * (double) data->width / (double) width;
325 if (data->width > 0) {
329 if (data->height > 0) {
330 height = data->height;
334 gdk_pixbuf_loader_set_size (loader, width, height);
338 empathy_avatar_pixbuf_roundify (GdkPixbuf *pixbuf)
340 gint width, height, rowstride;
343 width = gdk_pixbuf_get_width (pixbuf);
344 height = gdk_pixbuf_get_height (pixbuf);
345 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
346 pixels = gdk_pixbuf_get_pixels (pixbuf);
348 if (width < 6 || height < 6) {
356 pixels[rowstride + 3] = 0x80;
357 pixels[rowstride * 2 + 3] = 0xC0;
360 pixels[width * 4 - 1] = 0;
361 pixels[width * 4 - 5] = 0x80;
362 pixels[width * 4 - 9] = 0xC0;
363 pixels[rowstride + (width * 4) - 1] = 0x80;
364 pixels[(2 * rowstride) + (width * 4) - 1] = 0xC0;
367 pixels[(height - 1) * rowstride + 3] = 0;
368 pixels[(height - 1) * rowstride + 7] = 0x80;
369 pixels[(height - 1) * rowstride + 11] = 0xC0;
370 pixels[(height - 2) * rowstride + 3] = 0x80;
371 pixels[(height - 3) * rowstride + 3] = 0xC0;
374 pixels[height * rowstride - 1] = 0;
375 pixels[(height - 1) * rowstride - 1] = 0x80;
376 pixels[(height - 2) * rowstride - 1] = 0xC0;
377 pixels[height * rowstride - 5] = 0x80;
378 pixels[height * rowstride - 9] = 0xC0;
382 empathy_gdk_pixbuf_is_opaque (GdkPixbuf *pixbuf)
384 gint width, height, rowstride, i;
388 width = gdk_pixbuf_get_width (pixbuf);
389 height = gdk_pixbuf_get_height (pixbuf);
390 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
391 pixels = gdk_pixbuf_get_pixels (pixbuf);
394 for (i = 3; i < rowstride; i+=4) {
400 for (i = 1; i < height - 1; i++) {
401 row = pixels + (i*rowstride);
402 if (row[3] < 0xfe || row[rowstride-1] < 0xfe) {
407 row = pixels + ((height-1) * rowstride);
408 for (i = 3; i < rowstride; i+=4) {
418 empathy_pixbuf_from_avatar_scaled (EmpathyAvatar *avatar,
423 GdkPixbufLoader *loader;
424 struct SizeData data;
425 GError *error = NULL;
432 data.height = height;
433 data.preserve_aspect_ratio = TRUE;
435 loader = gdk_pixbuf_loader_new ();
437 g_signal_connect (loader, "size-prepared",
438 G_CALLBACK (pixbuf_from_avatar_size_prepared_cb),
441 if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) {
442 g_warning ("Couldn't write avatar image:%p with "
443 "length:%" G_GSIZE_FORMAT " to pixbuf loader: %s",
444 avatar->data, avatar->len, error->message);
445 g_error_free (error);
449 gdk_pixbuf_loader_close (loader, NULL);
451 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
452 if (!gdk_pixbuf_get_has_alpha (pixbuf)) {
453 GdkPixbuf *rounded_pixbuf;
455 rounded_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
456 gdk_pixbuf_get_width (pixbuf),
457 gdk_pixbuf_get_height (pixbuf));
458 gdk_pixbuf_copy_area (pixbuf, 0, 0,
459 gdk_pixbuf_get_width (pixbuf),
460 gdk_pixbuf_get_height (pixbuf),
463 pixbuf = rounded_pixbuf;
465 g_object_ref (pixbuf);
468 if (empathy_gdk_pixbuf_is_opaque (pixbuf)) {
469 empathy_avatar_pixbuf_roundify (pixbuf);
472 g_object_unref (loader);
478 empathy_pixbuf_avatar_from_contact_scaled (EmpathyContact *contact,
482 EmpathyAvatar *avatar;
484 g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
486 avatar = empathy_contact_get_avatar (contact);
488 return empathy_pixbuf_from_avatar_scaled (avatar, width, height);
491 /* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
492 * that to make it easier to apply changes from the original code.
494 #define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
496 /* this function acts like g_utf8_offset_to_pointer() except that if it finds a
497 * decomposable character it consumes the decomposition length from the given
498 * offset. So it's useful when the offset was calculated for the normalized
499 * version of str, but we need a pointer to str itself. */
501 pointer_from_offset_skipping_decomp (const gchar *str, gint offset)
503 gchar *casefold, *normal;
509 q = g_utf8_next_char (p);
510 casefold = g_utf8_casefold (p, q - p);
511 normal = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
512 offset -= g_utf8_strlen (normal, -1);
521 g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
525 const gchar *ret = NULL;
528 gchar *caseless_haystack;
531 g_return_val_if_fail (haystack != NULL, NULL);
532 g_return_val_if_fail (needle != NULL, NULL);
534 casefold = g_utf8_casefold (haystack, -1);
535 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
538 needle_len = g_utf8_strlen (needle, -1);
539 haystack_len = g_utf8_strlen (caseless_haystack, -1);
543 ret = (gchar *)haystack;
547 if (haystack_len < needle_len)
553 p = (gchar*)caseless_haystack;
554 needle_len = strlen (needle);
559 if ((strncmp (p, needle, needle_len) == 0))
561 ret = pointer_from_offset_skipping_decomp (haystack, i);
565 p = g_utf8_next_char (p);
570 g_free (caseless_haystack);
576 g_utf8_caselessnmatch (const char *s1, const char *s2,
577 gssize n1, gssize n2)
580 gchar *normalized_s1;
581 gchar *normalized_s2;
584 gboolean ret = FALSE;
586 g_return_val_if_fail (s1 != NULL, FALSE);
587 g_return_val_if_fail (s2 != NULL, FALSE);
588 g_return_val_if_fail (n1 > 0, FALSE);
589 g_return_val_if_fail (n2 > 0, FALSE);
591 casefold = g_utf8_casefold (s1, n1);
592 normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
595 casefold = g_utf8_casefold (s2, n2);
596 normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
599 len_s1 = strlen (normalized_s1);
600 len_s2 = strlen (normalized_s2);
605 ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0);
608 g_free (normalized_s1);
609 g_free (normalized_s2);
615 forward_chars_with_skipping (GtkTextIter *iter,
617 gboolean skip_invisible,
618 gboolean skip_nontext,
619 gboolean skip_decomp)
623 g_return_if_fail (count >= 0);
629 gboolean ignored = FALSE;
631 /* minimal workaround to avoid the infinite loop of bug #168247.
632 * It doesn't fix the problemjust the symptom...
634 if (gtk_text_iter_is_end (iter))
637 if (skip_nontext && gtk_text_iter_get_char (iter) == GTK_TEXT_UNKNOWN_CHAR)
640 if (!ignored && skip_invisible &&
641 /* _gtk_text_btree_char_is_invisible (iter)*/ FALSE)
644 if (!ignored && skip_decomp)
646 /* being UTF8 correct sucks; this accounts for extra
647 offsets coming from canonical decompositions of
648 UTF8 characters (e.g. accented characters) which
649 g_utf8_normalize() performs */
654 buffer_len = g_unichar_to_utf8 (gtk_text_iter_get_char (iter), buffer);
655 normal = g_utf8_normalize (buffer, buffer_len, G_NORMALIZE_NFD);
656 i -= (g_utf8_strlen (normal, -1) - 1);
660 gtk_text_iter_forward_char (iter);
668 lines_match (const GtkTextIter *start,
670 gboolean visible_only,
672 GtkTextIter *match_start,
673 GtkTextIter *match_end)
680 if (*lines == NULL || **lines == '\0')
683 *match_start = *start;
690 gtk_text_iter_forward_line (&next);
692 /* No more text in buffer, but *lines is nonempty */
693 if (gtk_text_iter_equal (start, &next))
699 line_text = gtk_text_iter_get_visible_slice (start, &next);
701 line_text = gtk_text_iter_get_slice (start, &next);
706 line_text = gtk_text_iter_get_visible_text (start, &next);
708 line_text = gtk_text_iter_get_text (start, &next);
711 if (match_start) /* if this is the first line we're matching */
713 found = g_utf8_strcasestr (line_text, *lines);
717 /* If it's not the first line, we have to match from the
720 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
733 /* Get offset to start of search string */
734 offset = g_utf8_strlen (line_text, found - line_text);
738 /* If match start needs to be returned, set it to the
739 * start of the search string.
741 forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
747 /* Go to end of search string */
748 forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
757 /* pass NULL for match_start, since we don't need to find the
760 return lines_match (&next, lines, visible_only, slice, NULL, match_end);
763 /* strsplit () that retains the delimiter as part of the string. */
765 strbreakup (const char *string,
766 const char *delimiter,
769 GSList *string_list = NULL, *slist;
770 gchar **str_array, *s, *casefold, *new_string;
773 g_return_val_if_fail (string != NULL, NULL);
774 g_return_val_if_fail (delimiter != NULL, NULL);
777 max_tokens = G_MAXINT;
779 s = strstr (string, delimiter);
782 guint delimiter_len = strlen (delimiter);
788 len = s - string + delimiter_len;
789 new_string = g_new (gchar, len + 1);
790 strncpy (new_string, string, len);
792 casefold = g_utf8_casefold (new_string, -1);
794 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
796 string_list = g_slist_prepend (string_list, new_string);
798 string = s + delimiter_len;
799 s = strstr (string, delimiter);
800 } while (--max_tokens && s);
806 casefold = g_utf8_casefold (string, -1);
807 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
809 string_list = g_slist_prepend (string_list, new_string);
812 str_array = g_new (gchar*, n);
816 str_array[i--] = NULL;
817 for (slist = string_list; slist; slist = slist->next)
818 str_array[i--] = slist->data;
820 g_slist_free (string_list);
826 empathy_text_iter_forward_search (const GtkTextIter *iter,
828 GtkTextIter *match_start,
829 GtkTextIter *match_end,
830 const GtkTextIter *limit)
832 gchar **lines = NULL;
834 gboolean retval = FALSE;
836 gboolean visible_only;
839 g_return_val_if_fail (iter != NULL, FALSE);
840 g_return_val_if_fail (str != NULL, FALSE);
842 if (limit && gtk_text_iter_compare (iter, limit) >= 0)
846 /* If we can move one char, return the empty string there */
849 if (gtk_text_iter_forward_char (&match)) {
850 if (limit && gtk_text_iter_equal (&match, limit)) {
855 *match_start = match;
869 /* locate all lines */
870 lines = strbreakup (str, "\n", -1);
875 /* This loop has an inefficient worst-case, where
876 * gtk_text_iter_get_text () is called repeatedly on
881 if (limit && gtk_text_iter_compare (&search, limit) >= 0) {
885 if (lines_match (&search, (const gchar**)lines,
886 visible_only, slice, &match, &end)) {
888 (limit && gtk_text_iter_compare (&end, limit) <= 0)) {
892 *match_start = match;
900 } while (gtk_text_iter_forward_line (&search));
902 g_strfreev ((gchar**)lines);
908 g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
912 const gchar *ret = NULL;
915 gchar *caseless_haystack;
918 g_return_val_if_fail (haystack != NULL, NULL);
919 g_return_val_if_fail (needle != NULL, NULL);
921 casefold = g_utf8_casefold (haystack, -1);
922 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
925 needle_len = g_utf8_strlen (needle, -1);
926 haystack_len = g_utf8_strlen (caseless_haystack, -1);
930 ret = (gchar *)haystack;
934 if (haystack_len < needle_len)
940 i = haystack_len - needle_len;
941 p = g_utf8_offset_to_pointer (caseless_haystack, i);
942 needle_len = strlen (needle);
944 while (p >= caseless_haystack)
946 if (strncmp (p, needle, needle_len) == 0)
948 ret = pointer_from_offset_skipping_decomp (haystack, i);
952 p = g_utf8_prev_char (p);
957 g_free (caseless_haystack);
963 backward_lines_match (const GtkTextIter *start,
965 gboolean visible_only,
967 GtkTextIter *match_start,
968 GtkTextIter *match_end)
970 GtkTextIter line, next;
975 if (*lines == NULL || **lines == '\0')
978 *match_start = *start;
984 line = next = *start;
985 if (gtk_text_iter_get_line_offset (&next) == 0)
987 if (!gtk_text_iter_backward_line (&next))
991 gtk_text_iter_set_line_offset (&next, 0);
996 line_text = gtk_text_iter_get_visible_slice (&next, &line);
998 line_text = gtk_text_iter_get_slice (&next, &line);
1003 line_text = gtk_text_iter_get_visible_text (&next, &line);
1005 line_text = gtk_text_iter_get_text (&next, &line);
1008 if (match_start) /* if this is the first line we're matching */
1010 found = g_utf8_strrcasestr (line_text, *lines);
1014 /* If it's not the first line, we have to match from the
1015 * start of the line.
1017 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
1030 /* Get offset to start of search string */
1031 offset = g_utf8_strlen (line_text, found - line_text);
1033 forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
1035 /* If match start needs to be returned, set it to the
1036 * start of the search string.
1040 *match_start = next;
1043 /* Go to end of search string */
1044 forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
1053 /* try to match the rest of the lines forward, passing NULL
1054 * for match_start so lines_match will try to match the entire
1056 return lines_match (&next, lines, visible_only,
1057 slice, NULL, match_end);
1061 empathy_text_iter_backward_search (const GtkTextIter *iter,
1063 GtkTextIter *match_start,
1064 GtkTextIter *match_end,
1065 const GtkTextIter *limit)
1067 gchar **lines = NULL;
1069 gboolean retval = FALSE;
1071 gboolean visible_only;
1074 g_return_val_if_fail (iter != NULL, FALSE);
1075 g_return_val_if_fail (str != NULL, FALSE);
1077 if (limit && gtk_text_iter_compare (iter, limit) <= 0)
1082 /* If we can move one char, return the empty string there */
1085 if (gtk_text_iter_backward_char (&match))
1087 if (limit && gtk_text_iter_equal (&match, limit))
1091 *match_start = match;
1102 visible_only = TRUE;
1105 /* locate all lines */
1106 lines = strbreakup (str, "\n", -1);
1112 /* This loop has an inefficient worst-case, where
1113 * gtk_text_iter_get_text () is called repeatedly on
1118 if (limit && gtk_text_iter_compare (&search, limit) <= 0)
1121 if (backward_lines_match (&search, (const gchar**)lines,
1122 visible_only, slice, &match, &end))
1124 if (limit == NULL || (limit &&
1125 gtk_text_iter_compare (&end, limit) > 0))
1130 *match_start = match;
1137 if (gtk_text_iter_get_line_offset (&search) == 0)
1139 if (!gtk_text_iter_backward_line (&search))
1144 gtk_text_iter_set_line_offset (&search, 0);
1148 g_strfreev ((gchar**)lines);
1154 window_get_is_on_current_workspace (GtkWindow *window)
1156 GdkWindow *gdk_window;
1158 gdk_window = GTK_WIDGET (window)->window;
1160 return !(gdk_window_get_state (gdk_window) &
1161 GDK_WINDOW_STATE_ICONIFIED);
1167 /* Checks if the window is visible as in visible on the current workspace. */
1169 empathy_window_get_is_visible (GtkWindow *window)
1171 g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
1173 return GTK_WIDGET_VISIBLE (GTK_WIDGET (window)) &&
1174 window_get_is_on_current_workspace (window);
1178 empathy_window_iconify (GtkWindow *window, GtkStatusIcon *status_icon)
1180 GdkRectangle icon_location;
1183 GdkWindow *gdk_window;
1185 gtk_status_icon_get_geometry (status_icon, NULL, &icon_location, NULL);
1186 gdk_window = GTK_WIDGET (window)->window;
1187 dpy = gdk_x11_drawable_get_xdisplay (gdk_window);
1189 data[0] = icon_location.x;
1190 data[1] = icon_location.y;
1191 data[2] = icon_location.width;
1192 data[3] = icon_location.height;
1194 XChangeProperty (dpy,
1195 GDK_WINDOW_XID (gdk_window),
1196 gdk_x11_get_xatom_by_name_for_display (gdk_drawable_get_display (gdk_window),
1197 "_NET_WM_ICON_GEOMETRY"),
1198 XA_CARDINAL, 32, PropModeReplace,
1199 (guchar *)&data, 4);
1201 gtk_window_set_skip_taskbar_hint (window, TRUE);
1202 gtk_window_iconify (window);
1206 /* Takes care of moving the window to the current workspace. */
1208 empathy_window_present (GtkWindow *window,
1209 gboolean steal_focus)
1211 gboolean on_current;
1214 g_return_if_fail (window != NULL);
1216 /* There are three cases: hidden, visible, visible on another
1220 on_current = window_get_is_on_current_workspace (window);
1222 if ( GTK_WIDGET_VISIBLE (GTK_WIDGET (window)) && !on_current) {
1223 /* Hide it so present brings it to the current workspace. */
1224 gtk_widget_hide (GTK_WIDGET (window));
1227 gtk_window_set_skip_taskbar_hint (window, FALSE);
1229 timestamp = gtk_get_current_event_time ();
1230 if (steal_focus && timestamp != GDK_CURRENT_TIME) {
1231 gtk_window_present_with_time (window, timestamp);
1233 gtk_window_present (window);
1238 empathy_get_toplevel_window (GtkWidget *widget)
1240 GtkWidget *toplevel;
1242 g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1244 toplevel = gtk_widget_get_toplevel (widget);
1245 if (GTK_IS_WINDOW (toplevel) &&
1246 GTK_WIDGET_TOPLEVEL (toplevel)) {
1247 return GTK_WINDOW (toplevel);
1253 /* The URL opening code can't handle schemeless strings, so we try to be
1254 * smart and add http if there is no scheme or doesn't look like a mail
1255 * address. This should work in most cases, and let us click on strings
1256 * like "www.gnome.org".
1259 fixup_url (const gchar *url)
1263 if (!g_str_has_prefix (url, "http://") &&
1264 !strstr (url, ":/") &&
1265 !strstr (url, "@")) {
1266 real_url = g_strdup_printf ("http://%s", url);
1268 real_url = g_strdup (url);
1275 empathy_url_show (const char *url)
1280 real_url = fixup_url (url);
1281 res = gnome_vfs_url_show (real_url);
1282 if (res != GNOME_VFS_OK) {
1283 empathy_debug (DEBUG_DOMAIN, "Couldn't show URL %s: %s",
1285 gnome_vfs_result_to_string (res));
1292 link_button_hook (GtkLinkButton *button,
1296 empathy_url_show (link);
1300 empathy_link_button_new (const gchar *url,
1303 static gboolean hook = FALSE;
1307 gtk_link_button_set_uri_hook (link_button_hook, NULL, NULL);
1310 return gtk_link_button_new_with_label (url, title);
1314 empathy_toggle_button_set_state_quietly (GtkWidget *widget,
1319 g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
1321 g_signal_handlers_block_by_func (widget, callback, user_data);
1322 g_object_set (widget, "active", active, NULL);
1323 g_signal_handlers_unblock_by_func (widget, callback, user_data);