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):
33 #include <glib/gi18n.h>
35 #include <glade/glade.h>
36 #include <libgnome/libgnome.h>
38 #include <libmissioncontrol/mc-profile.h>
40 #include <libempathy/gossip-paths.h>
41 #include <libempathy/gossip-debug.h>
43 #include "gossip-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 = gossip_paths_get_glade_path (filename);
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 gossip_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 gossip_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 gossip_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 gossip_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 gossip_pixbuf_from_icon_name (const gchar *icon_name,
206 GtkIconSize icon_size)
209 GdkPixbuf *pixbuf = NULL;
210 GError *error = NULL;
212 theme = gtk_icon_theme_get_default ();
214 pixbuf = gtk_icon_theme_load_icon (theme,
220 gossip_debug (DEBUG_DOMAIN, "Error loading icon: %s", error->message);
221 g_clear_error (&error);
228 gossip_pixbuf_from_smiley (GossipSmiley type,
229 GtkIconSize icon_size)
231 const gchar *icon_id;
234 case GOSSIP_SMILEY_NORMAL: /* :) */
235 icon_id = "stock_smiley-1";
237 case GOSSIP_SMILEY_WINK: /* ;) */
238 icon_id = "stock_smiley-3";
240 case GOSSIP_SMILEY_BIGEYE: /* =) */
241 icon_id = "stock_smiley-2";
243 case GOSSIP_SMILEY_NOSE: /* :-) */
244 icon_id = "stock_smiley-7";
246 case GOSSIP_SMILEY_CRY: /* :'( */
247 icon_id = "stock_smiley-11";
249 case GOSSIP_SMILEY_SAD: /* :( */
250 icon_id = "stock_smiley-4";
252 case GOSSIP_SMILEY_SCEPTICAL: /* :/ */
253 icon_id = "stock_smiley-9";
255 case GOSSIP_SMILEY_BIGSMILE: /* :D */
256 icon_id = "stock_smiley-6";
258 case GOSSIP_SMILEY_INDIFFERENT: /* :| */
259 icon_id = "stock_smiley-8";
261 case GOSSIP_SMILEY_TOUNGE: /* :p */
262 icon_id = "stock_smiley-10";
264 case GOSSIP_SMILEY_SHOCKED: /* :o */
265 icon_id = "stock_smiley-5";
267 case GOSSIP_SMILEY_COOL: /* 8) */
268 icon_id = "stock_smiley-15";
270 case GOSSIP_SMILEY_SORRY: /* *| */
271 icon_id = "stock_smiley-12";
273 case GOSSIP_SMILEY_KISS: /* :* */
274 icon_id = "stock_smiley-13";
276 case GOSSIP_SMILEY_SHUTUP: /* :# */
277 icon_id = "stock_smiley-14";
279 case GOSSIP_SMILEY_YAWN: /* |O */
282 case GOSSIP_SMILEY_CONFUSED: /* :$ */
283 icon_id = "stock_smiley-17";
285 case GOSSIP_SMILEY_ANGEL: /* O) */
286 icon_id = "stock_smiley-18";
288 case GOSSIP_SMILEY_OOOH: /* :x */
289 icon_id = "stock_smiley-19";
291 case GOSSIP_SMILEY_LOOKAWAY: /* *) */
292 icon_id = "stock_smiley-20";
294 case GOSSIP_SMILEY_BLUSH: /* *S */
295 icon_id = "stock_smiley-23";
297 case GOSSIP_SMILEY_COOLBIGSMILE: /* 8D */
298 icon_id = "stock_smiley-25";
300 case GOSSIP_SMILEY_ANGRY: /* :@ */
301 icon_id = "stock_smiley-16";
303 case GOSSIP_SMILEY_BOSS: /* @) */
304 icon_id = "stock_smiley-21";
306 case GOSSIP_SMILEY_MONKEY: /* #) */
307 icon_id = "stock_smiley-22";
309 case GOSSIP_SMILEY_SILLY: /* O) */
310 icon_id = "stock_smiley-24";
312 case GOSSIP_SMILEY_SICK: /* +o( */
313 icon_id = "stock_smiley-26";
317 g_assert_not_reached ();
322 return gossip_pixbuf_from_icon_name (icon_id, icon_size);
326 gossip_icon_name_from_account (McAccount *account)
330 profile = mc_account_get_profile (account);
332 return mc_profile_get_icon_name (profile);
336 gossip_icon_name_for_presence_state (McPresence state)
339 case MC_PRESENCE_AVAILABLE:
340 return EMPATHY_IMAGE_AVAILABLE;
341 case MC_PRESENCE_DO_NOT_DISTURB:
342 return EMPATHY_IMAGE_BUSY;
343 case MC_PRESENCE_AWAY:
344 return EMPATHY_IMAGE_AWAY;
345 case MC_PRESENCE_EXTENDED_AWAY:
346 return EMPATHY_IMAGE_EXT_AWAY;
347 case MC_PRESENCE_HIDDEN:
348 case MC_PRESENCE_OFFLINE:
349 case MC_PRESENCE_UNSET:
350 return EMPATHY_IMAGE_OFFLINE;
352 g_assert_not_reached ();
359 gossip_icon_name_for_presence (GossipPresence *presence)
363 g_return_val_if_fail (GOSSIP_IS_PRESENCE (presence),
364 EMPATHY_IMAGE_OFFLINE);
366 state = gossip_presence_get_state (presence);
368 return gossip_icon_name_for_presence_state (state);
372 gossip_icon_name_for_contact (GossipContact *contact)
374 GossipPresence *presence;
375 GossipSubscription subscription;
377 g_return_val_if_fail (GOSSIP_IS_CONTACT (contact),
378 EMPATHY_IMAGE_OFFLINE);
380 presence = gossip_contact_get_presence (contact);
383 return gossip_icon_name_for_presence (presence);
386 subscription = gossip_contact_get_subscription (contact);
388 if (subscription != GOSSIP_SUBSCRIPTION_BOTH &&
389 subscription != GOSSIP_SUBSCRIPTION_TO) {
390 return EMPATHY_IMAGE_PENDING;
393 return EMPATHY_IMAGE_OFFLINE;
397 gossip_pixbuf_avatar_from_contact (GossipContact *contact)
400 GdkPixbufLoader *loader;
401 GossipAvatar *avatar;
402 GError *error = NULL;
404 g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
406 avatar = gossip_contact_get_avatar (contact);
411 loader = gdk_pixbuf_loader_new ();
413 if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) {
414 g_warning ("Couldn't write avatar image:%p with "
415 "length:%" G_GSIZE_FORMAT " to pixbuf loader: %s",
416 avatar->data, avatar->len, error->message);
417 g_error_free (error);
421 gdk_pixbuf_loader_close (loader, NULL);
423 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
425 g_object_ref (pixbuf);
426 g_object_unref (loader);
432 pixbuf_from_avatar_size_prepared_cb (GdkPixbufLoader *loader,
435 struct SizeData *data)
437 g_return_if_fail (width > 0 && height > 0);
439 if (data->preserve_aspect_ratio && (data->width > 0 || data->height > 0)) {
440 if (width < data->width && height < data->height) {
445 if (data->width < 0) {
446 width = width * (double) data->height / (gdouble) height;
447 height = data->height;
448 } else if (data->height < 0) {
449 height = height * (double) data->width / (double) width;
451 } else if ((double) height * (double) data->width >
452 (double) width * (double) data->height) {
453 width = 0.5 + (double) width * (double) data->height / (double) height;
454 height = data->height;
456 height = 0.5 + (double) height * (double) data->width / (double) width;
460 if (data->width > 0) {
464 if (data->height > 0) {
465 height = data->height;
469 gdk_pixbuf_loader_set_size (loader, width, height);
473 gossip_pixbuf_from_avatar_scaled (GossipAvatar *avatar,
478 GdkPixbufLoader *loader;
479 struct SizeData data;
480 GError *error = NULL;
487 data.height = height;
488 data.preserve_aspect_ratio = TRUE;
490 loader = gdk_pixbuf_loader_new ();
492 g_signal_connect (loader, "size-prepared",
493 G_CALLBACK (pixbuf_from_avatar_size_prepared_cb),
496 if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) {
497 g_warning ("Couldn't write avatar image:%p with "
498 "length:%" G_GSIZE_FORMAT " to pixbuf loader: %s",
499 avatar->data, avatar->len, error->message);
500 g_error_free (error);
504 gdk_pixbuf_loader_close (loader, NULL);
506 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
508 g_object_ref (pixbuf);
509 g_object_unref (loader);
515 gossip_pixbuf_avatar_from_contact_scaled (GossipContact *contact,
519 GossipAvatar *avatar;
521 g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
523 avatar = gossip_contact_get_avatar (contact);
525 return gossip_pixbuf_from_avatar_scaled (avatar, width, height);
527 /* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
528 * that to make it easier to apply changes from the original code.
530 #define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
532 /* this function acts like g_utf8_offset_to_pointer() except that if it finds a
533 * decomposable character it consumes the decomposition length from the given
534 * offset. So it's useful when the offset was calculated for the normalized
535 * version of str, but we need a pointer to str itself. */
537 pointer_from_offset_skipping_decomp (const gchar *str, gint offset)
539 gchar *casefold, *normal;
545 q = g_utf8_next_char (p);
546 casefold = g_utf8_casefold (p, q - p);
547 normal = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
548 offset -= g_utf8_strlen (normal, -1);
557 g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
561 const gchar *ret = NULL;
564 gchar *caseless_haystack;
567 g_return_val_if_fail (haystack != NULL, NULL);
568 g_return_val_if_fail (needle != NULL, NULL);
570 casefold = g_utf8_casefold (haystack, -1);
571 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
574 needle_len = g_utf8_strlen (needle, -1);
575 haystack_len = g_utf8_strlen (caseless_haystack, -1);
579 ret = (gchar *)haystack;
583 if (haystack_len < needle_len)
589 p = (gchar*)caseless_haystack;
590 needle_len = strlen (needle);
595 if ((strncmp (p, needle, needle_len) == 0))
597 ret = pointer_from_offset_skipping_decomp (haystack, i);
601 p = g_utf8_next_char (p);
606 g_free (caseless_haystack);
612 g_utf8_caselessnmatch (const char *s1, const char *s2,
613 gssize n1, gssize n2)
616 gchar *normalized_s1;
617 gchar *normalized_s2;
620 gboolean ret = FALSE;
622 g_return_val_if_fail (s1 != NULL, FALSE);
623 g_return_val_if_fail (s2 != NULL, FALSE);
624 g_return_val_if_fail (n1 > 0, FALSE);
625 g_return_val_if_fail (n2 > 0, FALSE);
627 casefold = g_utf8_casefold (s1, n1);
628 normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
631 casefold = g_utf8_casefold (s2, n2);
632 normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
635 len_s1 = strlen (normalized_s1);
636 len_s2 = strlen (normalized_s2);
641 ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0);
644 g_free (normalized_s1);
645 g_free (normalized_s2);
651 forward_chars_with_skipping (GtkTextIter *iter,
653 gboolean skip_invisible,
654 gboolean skip_nontext,
655 gboolean skip_decomp)
659 g_return_if_fail (count >= 0);
665 gboolean ignored = FALSE;
667 /* minimal workaround to avoid the infinite loop of bug #168247.
668 * It doesn't fix the problemjust the symptom...
670 if (gtk_text_iter_is_end (iter))
673 if (skip_nontext && gtk_text_iter_get_char (iter) == GTK_TEXT_UNKNOWN_CHAR)
676 if (!ignored && skip_invisible &&
677 /* _gtk_text_btree_char_is_invisible (iter)*/ FALSE)
680 if (!ignored && skip_decomp)
682 /* being UTF8 correct sucks; this accounts for extra
683 offsets coming from canonical decompositions of
684 UTF8 characters (e.g. accented characters) which
685 g_utf8_normalize() performs */
690 buffer_len = g_unichar_to_utf8 (gtk_text_iter_get_char (iter), buffer);
691 normal = g_utf8_normalize (buffer, buffer_len, G_NORMALIZE_NFD);
692 i -= (g_utf8_strlen (normal, -1) - 1);
696 gtk_text_iter_forward_char (iter);
704 lines_match (const GtkTextIter *start,
706 gboolean visible_only,
708 GtkTextIter *match_start,
709 GtkTextIter *match_end)
716 if (*lines == NULL || **lines == '\0')
719 *match_start = *start;
726 gtk_text_iter_forward_line (&next);
728 /* No more text in buffer, but *lines is nonempty */
729 if (gtk_text_iter_equal (start, &next))
735 line_text = gtk_text_iter_get_visible_slice (start, &next);
737 line_text = gtk_text_iter_get_slice (start, &next);
742 line_text = gtk_text_iter_get_visible_text (start, &next);
744 line_text = gtk_text_iter_get_text (start, &next);
747 if (match_start) /* if this is the first line we're matching */
749 found = g_utf8_strcasestr (line_text, *lines);
753 /* If it's not the first line, we have to match from the
756 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
769 /* Get offset to start of search string */
770 offset = g_utf8_strlen (line_text, found - line_text);
774 /* If match start needs to be returned, set it to the
775 * start of the search string.
777 forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
783 /* Go to end of search string */
784 forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
793 /* pass NULL for match_start, since we don't need to find the
796 return lines_match (&next, lines, visible_only, slice, NULL, match_end);
799 /* strsplit () that retains the delimiter as part of the string. */
801 strbreakup (const char *string,
802 const char *delimiter,
805 GSList *string_list = NULL, *slist;
806 gchar **str_array, *s, *casefold, *new_string;
809 g_return_val_if_fail (string != NULL, NULL);
810 g_return_val_if_fail (delimiter != NULL, NULL);
813 max_tokens = G_MAXINT;
815 s = strstr (string, delimiter);
818 guint delimiter_len = strlen (delimiter);
824 len = s - string + delimiter_len;
825 new_string = g_new (gchar, len + 1);
826 strncpy (new_string, string, len);
828 casefold = g_utf8_casefold (new_string, -1);
830 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
832 string_list = g_slist_prepend (string_list, new_string);
834 string = s + delimiter_len;
835 s = strstr (string, delimiter);
836 } while (--max_tokens && s);
842 casefold = g_utf8_casefold (string, -1);
843 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
845 string_list = g_slist_prepend (string_list, new_string);
848 str_array = g_new (gchar*, n);
852 str_array[i--] = NULL;
853 for (slist = string_list; slist; slist = slist->next)
854 str_array[i--] = slist->data;
856 g_slist_free (string_list);
862 gossip_text_iter_forward_search (const GtkTextIter *iter,
864 GtkTextIter *match_start,
865 GtkTextIter *match_end,
866 const GtkTextIter *limit)
868 gchar **lines = NULL;
870 gboolean retval = FALSE;
872 gboolean visible_only;
875 g_return_val_if_fail (iter != NULL, FALSE);
876 g_return_val_if_fail (str != NULL, FALSE);
878 if (limit && gtk_text_iter_compare (iter, limit) >= 0)
882 /* If we can move one char, return the empty string there */
885 if (gtk_text_iter_forward_char (&match)) {
886 if (limit && gtk_text_iter_equal (&match, limit)) {
891 *match_start = match;
905 /* locate all lines */
906 lines = strbreakup (str, "\n", -1);
911 /* This loop has an inefficient worst-case, where
912 * gtk_text_iter_get_text () is called repeatedly on
917 if (limit && gtk_text_iter_compare (&search, limit) >= 0) {
921 if (lines_match (&search, (const gchar**)lines,
922 visible_only, slice, &match, &end)) {
924 (limit && gtk_text_iter_compare (&end, limit) <= 0)) {
928 *match_start = match;
936 } while (gtk_text_iter_forward_line (&search));
938 g_strfreev ((gchar**)lines);
944 g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
948 const gchar *ret = NULL;
951 gchar *caseless_haystack;
954 g_return_val_if_fail (haystack != NULL, NULL);
955 g_return_val_if_fail (needle != NULL, NULL);
957 casefold = g_utf8_casefold (haystack, -1);
958 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
961 needle_len = g_utf8_strlen (needle, -1);
962 haystack_len = g_utf8_strlen (caseless_haystack, -1);
966 ret = (gchar *)haystack;
970 if (haystack_len < needle_len)
976 i = haystack_len - needle_len;
977 p = g_utf8_offset_to_pointer (caseless_haystack, i);
978 needle_len = strlen (needle);
980 while (p >= caseless_haystack)
982 if (strncmp (p, needle, needle_len) == 0)
984 ret = pointer_from_offset_skipping_decomp (haystack, i);
988 p = g_utf8_prev_char (p);
993 g_free (caseless_haystack);
999 backward_lines_match (const GtkTextIter *start,
1000 const gchar **lines,
1001 gboolean visible_only,
1003 GtkTextIter *match_start,
1004 GtkTextIter *match_end)
1006 GtkTextIter line, next;
1011 if (*lines == NULL || **lines == '\0')
1014 *match_start = *start;
1016 *match_end = *start;
1020 line = next = *start;
1021 if (gtk_text_iter_get_line_offset (&next) == 0)
1023 if (!gtk_text_iter_backward_line (&next))
1027 gtk_text_iter_set_line_offset (&next, 0);
1032 line_text = gtk_text_iter_get_visible_slice (&next, &line);
1034 line_text = gtk_text_iter_get_slice (&next, &line);
1039 line_text = gtk_text_iter_get_visible_text (&next, &line);
1041 line_text = gtk_text_iter_get_text (&next, &line);
1044 if (match_start) /* if this is the first line we're matching */
1046 found = g_utf8_strrcasestr (line_text, *lines);
1050 /* If it's not the first line, we have to match from the
1051 * start of the line.
1053 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
1066 /* Get offset to start of search string */
1067 offset = g_utf8_strlen (line_text, found - line_text);
1069 forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
1071 /* If match start needs to be returned, set it to the
1072 * start of the search string.
1076 *match_start = next;
1079 /* Go to end of search string */
1080 forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
1089 /* try to match the rest of the lines forward, passing NULL
1090 * for match_start so lines_match will try to match the entire
1092 return lines_match (&next, lines, visible_only,
1093 slice, NULL, match_end);
1097 gossip_text_iter_backward_search (const GtkTextIter *iter,
1099 GtkTextIter *match_start,
1100 GtkTextIter *match_end,
1101 const GtkTextIter *limit)
1103 gchar **lines = NULL;
1105 gboolean retval = FALSE;
1107 gboolean visible_only;
1110 g_return_val_if_fail (iter != NULL, FALSE);
1111 g_return_val_if_fail (str != NULL, FALSE);
1113 if (limit && gtk_text_iter_compare (iter, limit) <= 0)
1118 /* If we can move one char, return the empty string there */
1121 if (gtk_text_iter_backward_char (&match))
1123 if (limit && gtk_text_iter_equal (&match, limit))
1127 *match_start = match;
1138 visible_only = TRUE;
1141 /* locate all lines */
1142 lines = strbreakup (str, "\n", -1);
1148 /* This loop has an inefficient worst-case, where
1149 * gtk_text_iter_get_text () is called repeatedly on
1154 if (limit && gtk_text_iter_compare (&search, limit) <= 0)
1157 if (backward_lines_match (&search, (const gchar**)lines,
1158 visible_only, slice, &match, &end))
1160 if (limit == NULL || (limit &&
1161 gtk_text_iter_compare (&end, limit) > 0))
1166 *match_start = match;
1173 if (gtk_text_iter_get_line_offset (&search) == 0)
1175 if (!gtk_text_iter_backward_line (&search))
1180 gtk_text_iter_set_line_offset (&search, 0);
1184 g_strfreev ((gchar**)lines);
1190 window_get_is_on_current_workspace (GtkWindow *window)
1192 GdkWindow *gdk_window;
1194 gdk_window = GTK_WIDGET (window)->window;
1196 return !(gdk_window_get_state (gdk_window) &
1197 GDK_WINDOW_STATE_ICONIFIED);
1203 /* Checks if the window is visible as in visible on the current workspace. */
1205 gossip_window_get_is_visible (GtkWindow *window)
1209 g_return_val_if_fail (window != NULL, FALSE);
1211 g_object_get (window,
1212 "visible", &visible,
1215 return visible && window_get_is_on_current_workspace (window);
1218 /* Takes care of moving the window to the current workspace. */
1220 gossip_window_present (GtkWindow *window,
1221 gboolean steal_focus)
1224 gboolean on_current;
1227 g_return_if_fail (window != NULL);
1229 /* There are three cases: hidden, visible, visible on another
1233 g_object_get (window,
1234 "visible", &visible,
1237 on_current = window_get_is_on_current_workspace (window);
1239 if (visible && !on_current) {
1240 /* Hide it so present brings it to the current workspace. */
1241 gtk_widget_hide (GTK_WIDGET (window));
1244 timestamp = gtk_get_current_event_time ();
1245 if (steal_focus && timestamp != GDK_CURRENT_TIME) {
1246 gtk_window_present_with_time (window, timestamp);
1248 gtk_window_present (window);
1252 /* The URL opening code can't handle schemeless strings, so we try to be
1253 * smart and add http if there is no scheme or doesn't look like a mail
1254 * address. This should work in most cases, and let us click on strings
1255 * like "www.gnome.org".
1258 fixup_url (const gchar *url)
1262 if (!g_str_has_prefix (url, "http://") &&
1263 !strstr (url, ":/") &&
1264 !strstr (url, "@")) {
1265 real_url = g_strdup_printf ("http://%s", url);
1267 real_url = g_strdup (url);
1274 gossip_url_show (const char *url)
1277 GError *error = NULL;
1279 real_url = fixup_url (url);
1280 gnome_url_show (real_url, &error);
1282 g_warning ("Couldn't show URL:'%s'", real_url);
1283 g_error_free (error);
1290 link_button_hook (GtkLinkButton *button,
1294 gossip_url_show (link);
1298 gossip_link_button_new (const gchar *url,
1301 static gboolean hook = FALSE;
1305 gtk_link_button_set_uri_hook (link_button_hook, NULL, NULL);
1308 return gtk_link_button_new_with_label (url, title);
1311 /* FIXME: Do this in a proper way at some point, probably in GTK+? */
1313 gossip_window_set_default_icon_name (const gchar *name)
1315 gtk_window_set_default_icon_name (name);
1319 gossip_toggle_button_set_state_quietly (GtkWidget *widget,
1324 g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
1326 g_signal_handlers_block_by_func (widget, callback, user_data);
1327 g_object_set (widget, "active", active, NULL);
1328 g_signal_handlers_unblock_by_func (widget, callback, user_data);