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 "gossip-stock.h"
49 gboolean preserve_aspect_ratio;
53 get_glade_file (const gchar *filename,
56 const gchar *first_required_widget,
62 GtkWidget **widget_ptr;
64 path = gossip_paths_get_glade_path (filename);
65 gui = glade_xml_new (path, root, domain);
69 g_warning ("Couldn't find necessary glade file '%s'", filename);
73 for (name = first_required_widget; name; name = va_arg (args, char *)) {
74 widget_ptr = va_arg (args, void *);
76 *widget_ptr = glade_xml_get_widget (gui, name);
79 g_warning ("Glade file '%s' is missing widget '%s'.",
89 gossip_glade_get_file_simple (const gchar *filename,
92 const gchar *first_required_widget, ...)
97 va_start (args, first_required_widget);
99 gui = get_glade_file (filename,
102 first_required_widget,
111 g_object_unref (gui);
115 gossip_glade_get_file (const gchar *filename,
118 const gchar *first_required_widget, ...)
123 va_start (args, first_required_widget);
125 gui = get_glade_file (filename,
128 first_required_widget,
141 gossip_glade_connect (GladeXML *gui,
143 gchar *first_widget, ...)
151 va_start (args, first_widget);
153 for (name = first_widget; name; name = va_arg (args, char *)) {
154 signal = va_arg (args, void *);
155 callback = va_arg (args, void *);
157 widget = glade_xml_get_widget (gui, name);
159 g_warning ("Glade file is missing widget '%s', aborting",
164 g_signal_connect (widget,
166 G_CALLBACK (callback),
174 gossip_glade_setup_size_group (GladeXML *gui,
175 GtkSizeGroupMode mode,
176 gchar *first_widget, ...)
180 GtkSizeGroup *size_group;
183 va_start (args, first_widget);
185 size_group = gtk_size_group_new (mode);
187 for (name = first_widget; name; name = va_arg (args, char *)) {
188 widget = glade_xml_get_widget (gui, name);
190 g_warning ("Glade file is missing widget '%s'", name);
194 gtk_size_group_add_widget (size_group, widget);
197 g_object_unref (size_group);
203 gossip_pixbuf_from_smiley (GossipSmiley type,
204 GtkIconSize icon_size)
207 GdkPixbuf *pixbuf = NULL;
208 GError *error = NULL;
211 const gchar *icon_id;
213 theme = gtk_icon_theme_get_default ();
215 if (!gtk_icon_size_lookup (icon_size, &w, &h)) {
222 case GOSSIP_SMILEY_NORMAL: /* :) */
223 icon_id = "stock_smiley-1";
225 case GOSSIP_SMILEY_WINK: /* ;) */
226 icon_id = "stock_smiley-3";
228 case GOSSIP_SMILEY_BIGEYE: /* =) */
229 icon_id = "stock_smiley-2";
231 case GOSSIP_SMILEY_NOSE: /* :-) */
232 icon_id = "stock_smiley-7";
234 case GOSSIP_SMILEY_CRY: /* :'( */
235 icon_id = "stock_smiley-11";
237 case GOSSIP_SMILEY_SAD: /* :( */
238 icon_id = "stock_smiley-4";
240 case GOSSIP_SMILEY_SCEPTICAL: /* :/ */
241 icon_id = "stock_smiley-9";
243 case GOSSIP_SMILEY_BIGSMILE: /* :D */
244 icon_id = "stock_smiley-6";
246 case GOSSIP_SMILEY_INDIFFERENT: /* :| */
247 icon_id = "stock_smiley-8";
249 case GOSSIP_SMILEY_TOUNGE: /* :p */
250 icon_id = "stock_smiley-10";
252 case GOSSIP_SMILEY_SHOCKED: /* :o */
253 icon_id = "stock_smiley-5";
255 case GOSSIP_SMILEY_COOL: /* 8) */
256 icon_id = "stock_smiley-15";
258 case GOSSIP_SMILEY_SORRY: /* *| */
259 icon_id = "stock_smiley-12";
261 case GOSSIP_SMILEY_KISS: /* :* */
262 icon_id = "stock_smiley-13";
264 case GOSSIP_SMILEY_SHUTUP: /* :# */
265 icon_id = "stock_smiley-14";
267 case GOSSIP_SMILEY_YAWN: /* |O */
270 case GOSSIP_SMILEY_CONFUSED: /* :$ */
271 icon_id = "stock_smiley-17";
273 case GOSSIP_SMILEY_ANGEL: /* O) */
274 icon_id = "stock_smiley-18";
276 case GOSSIP_SMILEY_OOOH: /* :x */
277 icon_id = "stock_smiley-19";
279 case GOSSIP_SMILEY_LOOKAWAY: /* *) */
280 icon_id = "stock_smiley-20";
282 case GOSSIP_SMILEY_BLUSH: /* *S */
283 icon_id = "stock_smiley-23";
285 case GOSSIP_SMILEY_COOLBIGSMILE: /* 8D */
286 icon_id = "stock_smiley-25";
288 case GOSSIP_SMILEY_ANGRY: /* :@ */
289 icon_id = "stock_smiley-16";
291 case GOSSIP_SMILEY_BOSS: /* @) */
292 icon_id = "stock_smiley-21";
294 case GOSSIP_SMILEY_MONKEY: /* #) */
295 icon_id = "stock_smiley-22";
297 case GOSSIP_SMILEY_SILLY: /* O) */
298 icon_id = "stock_smiley-24";
300 case GOSSIP_SMILEY_SICK: /* +o( */
301 icon_id = "stock_smiley-26";
305 g_assert_not_reached ();
309 pixbuf = gtk_icon_theme_load_icon (theme,
310 icon_id, /* icon name */
319 gossip_pixbuf_from_profile (McProfile *profile,
320 GtkIconSize icon_size)
325 const gchar *icon_id = NULL;
326 GError *error = NULL;
328 theme = gtk_icon_theme_get_default ();
330 if (gtk_icon_size_lookup (icon_size, &w, &h)) {
334 icon_id = mc_profile_get_icon_name (profile);
336 theme = gtk_icon_theme_get_default ();
337 return gtk_icon_theme_load_icon (theme,
338 icon_id, /* Icon name */
345 gossip_pixbuf_from_account (McAccount *account,
346 GtkIconSize icon_size)
350 profile = mc_account_get_profile (account);
352 return gossip_pixbuf_from_profile (profile, icon_size);
356 gossip_pixbuf_for_presence_state (McPresence state)
360 stock = gossip_stock_for_state (state);
362 return gossip_stock_render (stock, GTK_ICON_SIZE_MENU);
366 gossip_pixbuf_for_presence (GossipPresence *presence)
370 g_return_val_if_fail (GOSSIP_IS_PRESENCE (presence),
371 gossip_pixbuf_offline ());
373 state = gossip_presence_get_state (presence);
375 return gossip_pixbuf_for_presence_state (state);
379 gossip_pixbuf_for_contact (GossipContact *contact)
381 GossipPresence *presence;
382 GossipSubscription subscription;
384 g_return_val_if_fail (GOSSIP_IS_CONTACT (contact),
385 gossip_pixbuf_offline ());
387 presence = gossip_contact_get_presence (contact);
390 return gossip_pixbuf_for_presence (presence);
393 subscription = gossip_contact_get_subscription (contact);
395 if (subscription != GOSSIP_SUBSCRIPTION_BOTH &&
396 subscription != GOSSIP_SUBSCRIPTION_TO) {
397 return gossip_stock_render (GOSSIP_STOCK_PENDING,
401 return gossip_pixbuf_offline ();
405 gossip_pixbuf_offline (void)
407 return gossip_stock_render (GOSSIP_STOCK_OFFLINE,
412 gossip_pixbuf_avatar_from_contact (GossipContact *contact)
415 GdkPixbufLoader *loader;
416 GossipAvatar *avatar;
417 GError *error = NULL;
419 g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
421 avatar = gossip_contact_get_avatar (contact);
426 loader = gdk_pixbuf_loader_new ();
428 if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) {
429 g_warning ("Couldn't write avatar image:%p with "
430 "length:%" G_GSIZE_FORMAT " to pixbuf loader: %s",
431 avatar->data, avatar->len, error->message);
432 g_error_free (error);
436 gdk_pixbuf_loader_close (loader, NULL);
438 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
440 g_object_ref (pixbuf);
441 g_object_unref (loader);
447 pixbuf_from_avatar_size_prepared_cb (GdkPixbufLoader *loader,
450 struct SizeData *data)
452 g_return_if_fail (width > 0 && height > 0);
454 if (data->preserve_aspect_ratio && (data->width > 0 || data->height > 0)) {
455 if (width < data->width && height < data->height) {
460 if (data->width < 0) {
461 width = width * (double) data->height / (gdouble) height;
462 height = data->height;
463 } else if (data->height < 0) {
464 height = height * (double) data->width / (double) width;
466 } else if ((double) height * (double) data->width >
467 (double) width * (double) data->height) {
468 width = 0.5 + (double) width * (double) data->height / (double) height;
469 height = data->height;
471 height = 0.5 + (double) height * (double) data->width / (double) width;
475 if (data->width > 0) {
479 if (data->height > 0) {
480 height = data->height;
484 gdk_pixbuf_loader_set_size (loader, width, height);
488 gossip_pixbuf_from_avatar_scaled (GossipAvatar *avatar,
493 GdkPixbufLoader *loader;
494 struct SizeData data;
495 GError *error = NULL;
502 data.height = height;
503 data.preserve_aspect_ratio = TRUE;
505 loader = gdk_pixbuf_loader_new ();
507 g_signal_connect (loader, "size-prepared",
508 G_CALLBACK (pixbuf_from_avatar_size_prepared_cb),
511 if (!gdk_pixbuf_loader_write (loader, avatar->data, avatar->len, &error)) {
512 g_warning ("Couldn't write avatar image:%p with "
513 "length:%" G_GSIZE_FORMAT " to pixbuf loader: %s",
514 avatar->data, avatar->len, error->message);
515 g_error_free (error);
519 gdk_pixbuf_loader_close (loader, NULL);
521 pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
523 g_object_ref (pixbuf);
524 g_object_unref (loader);
530 gossip_pixbuf_avatar_from_contact_scaled (GossipContact *contact,
534 GossipAvatar *avatar;
536 g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
538 avatar = gossip_contact_get_avatar (contact);
540 return gossip_pixbuf_from_avatar_scaled (avatar, width, height);
542 /* Stolen from GtkSourceView, hence the weird intendation. Please keep it like
543 * that to make it easier to apply changes from the original code.
545 #define GTK_TEXT_UNKNOWN_CHAR 0xFFFC
547 /* this function acts like g_utf8_offset_to_pointer() except that if it finds a
548 * decomposable character it consumes the decomposition length from the given
549 * offset. So it's useful when the offset was calculated for the normalized
550 * version of str, but we need a pointer to str itself. */
552 pointer_from_offset_skipping_decomp (const gchar *str, gint offset)
554 gchar *casefold, *normal;
560 q = g_utf8_next_char (p);
561 casefold = g_utf8_casefold (p, q - p);
562 normal = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
563 offset -= g_utf8_strlen (normal, -1);
572 g_utf8_strcasestr (const gchar *haystack, const gchar *needle)
576 const gchar *ret = NULL;
579 gchar *caseless_haystack;
582 g_return_val_if_fail (haystack != NULL, NULL);
583 g_return_val_if_fail (needle != NULL, NULL);
585 casefold = g_utf8_casefold (haystack, -1);
586 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
589 needle_len = g_utf8_strlen (needle, -1);
590 haystack_len = g_utf8_strlen (caseless_haystack, -1);
594 ret = (gchar *)haystack;
598 if (haystack_len < needle_len)
604 p = (gchar*)caseless_haystack;
605 needle_len = strlen (needle);
610 if ((strncmp (p, needle, needle_len) == 0))
612 ret = pointer_from_offset_skipping_decomp (haystack, i);
616 p = g_utf8_next_char (p);
621 g_free (caseless_haystack);
627 g_utf8_caselessnmatch (const char *s1, const char *s2,
628 gssize n1, gssize n2)
631 gchar *normalized_s1;
632 gchar *normalized_s2;
635 gboolean ret = FALSE;
637 g_return_val_if_fail (s1 != NULL, FALSE);
638 g_return_val_if_fail (s2 != NULL, FALSE);
639 g_return_val_if_fail (n1 > 0, FALSE);
640 g_return_val_if_fail (n2 > 0, FALSE);
642 casefold = g_utf8_casefold (s1, n1);
643 normalized_s1 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
646 casefold = g_utf8_casefold (s2, n2);
647 normalized_s2 = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
650 len_s1 = strlen (normalized_s1);
651 len_s2 = strlen (normalized_s2);
656 ret = (strncmp (normalized_s1, normalized_s2, len_s2) == 0);
659 g_free (normalized_s1);
660 g_free (normalized_s2);
666 forward_chars_with_skipping (GtkTextIter *iter,
668 gboolean skip_invisible,
669 gboolean skip_nontext,
670 gboolean skip_decomp)
674 g_return_if_fail (count >= 0);
680 gboolean ignored = FALSE;
682 /* minimal workaround to avoid the infinite loop of bug #168247.
683 * It doesn't fix the problemjust the symptom...
685 if (gtk_text_iter_is_end (iter))
688 if (skip_nontext && gtk_text_iter_get_char (iter) == GTK_TEXT_UNKNOWN_CHAR)
691 if (!ignored && skip_invisible &&
692 /* _gtk_text_btree_char_is_invisible (iter)*/ FALSE)
695 if (!ignored && skip_decomp)
697 /* being UTF8 correct sucks; this accounts for extra
698 offsets coming from canonical decompositions of
699 UTF8 characters (e.g. accented characters) which
700 g_utf8_normalize() performs */
705 buffer_len = g_unichar_to_utf8 (gtk_text_iter_get_char (iter), buffer);
706 normal = g_utf8_normalize (buffer, buffer_len, G_NORMALIZE_NFD);
707 i -= (g_utf8_strlen (normal, -1) - 1);
711 gtk_text_iter_forward_char (iter);
719 lines_match (const GtkTextIter *start,
721 gboolean visible_only,
723 GtkTextIter *match_start,
724 GtkTextIter *match_end)
731 if (*lines == NULL || **lines == '\0')
734 *match_start = *start;
741 gtk_text_iter_forward_line (&next);
743 /* No more text in buffer, but *lines is nonempty */
744 if (gtk_text_iter_equal (start, &next))
750 line_text = gtk_text_iter_get_visible_slice (start, &next);
752 line_text = gtk_text_iter_get_slice (start, &next);
757 line_text = gtk_text_iter_get_visible_text (start, &next);
759 line_text = gtk_text_iter_get_text (start, &next);
762 if (match_start) /* if this is the first line we're matching */
764 found = g_utf8_strcasestr (line_text, *lines);
768 /* If it's not the first line, we have to match from the
771 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
784 /* Get offset to start of search string */
785 offset = g_utf8_strlen (line_text, found - line_text);
789 /* If match start needs to be returned, set it to the
790 * start of the search string.
792 forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
798 /* Go to end of search string */
799 forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
808 /* pass NULL for match_start, since we don't need to find the
811 return lines_match (&next, lines, visible_only, slice, NULL, match_end);
814 /* strsplit () that retains the delimiter as part of the string. */
816 strbreakup (const char *string,
817 const char *delimiter,
820 GSList *string_list = NULL, *slist;
821 gchar **str_array, *s, *casefold, *new_string;
824 g_return_val_if_fail (string != NULL, NULL);
825 g_return_val_if_fail (delimiter != NULL, NULL);
828 max_tokens = G_MAXINT;
830 s = strstr (string, delimiter);
833 guint delimiter_len = strlen (delimiter);
839 len = s - string + delimiter_len;
840 new_string = g_new (gchar, len + 1);
841 strncpy (new_string, string, len);
843 casefold = g_utf8_casefold (new_string, -1);
845 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
847 string_list = g_slist_prepend (string_list, new_string);
849 string = s + delimiter_len;
850 s = strstr (string, delimiter);
851 } while (--max_tokens && s);
857 casefold = g_utf8_casefold (string, -1);
858 new_string = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
860 string_list = g_slist_prepend (string_list, new_string);
863 str_array = g_new (gchar*, n);
867 str_array[i--] = NULL;
868 for (slist = string_list; slist; slist = slist->next)
869 str_array[i--] = slist->data;
871 g_slist_free (string_list);
877 gossip_text_iter_forward_search (const GtkTextIter *iter,
879 GtkTextIter *match_start,
880 GtkTextIter *match_end,
881 const GtkTextIter *limit)
883 gchar **lines = NULL;
885 gboolean retval = FALSE;
887 gboolean visible_only;
890 g_return_val_if_fail (iter != NULL, FALSE);
891 g_return_val_if_fail (str != NULL, FALSE);
893 if (limit && gtk_text_iter_compare (iter, limit) >= 0)
897 /* If we can move one char, return the empty string there */
900 if (gtk_text_iter_forward_char (&match)) {
901 if (limit && gtk_text_iter_equal (&match, limit)) {
906 *match_start = match;
920 /* locate all lines */
921 lines = strbreakup (str, "\n", -1);
926 /* This loop has an inefficient worst-case, where
927 * gtk_text_iter_get_text () is called repeatedly on
932 if (limit && gtk_text_iter_compare (&search, limit) >= 0) {
936 if (lines_match (&search, (const gchar**)lines,
937 visible_only, slice, &match, &end)) {
939 (limit && gtk_text_iter_compare (&end, limit) <= 0)) {
943 *match_start = match;
951 } while (gtk_text_iter_forward_line (&search));
953 g_strfreev ((gchar**)lines);
959 g_utf8_strrcasestr (const gchar *haystack, const gchar *needle)
963 const gchar *ret = NULL;
966 gchar *caseless_haystack;
969 g_return_val_if_fail (haystack != NULL, NULL);
970 g_return_val_if_fail (needle != NULL, NULL);
972 casefold = g_utf8_casefold (haystack, -1);
973 caseless_haystack = g_utf8_normalize (casefold, -1, G_NORMALIZE_NFD);
976 needle_len = g_utf8_strlen (needle, -1);
977 haystack_len = g_utf8_strlen (caseless_haystack, -1);
981 ret = (gchar *)haystack;
985 if (haystack_len < needle_len)
991 i = haystack_len - needle_len;
992 p = g_utf8_offset_to_pointer (caseless_haystack, i);
993 needle_len = strlen (needle);
995 while (p >= caseless_haystack)
997 if (strncmp (p, needle, needle_len) == 0)
999 ret = pointer_from_offset_skipping_decomp (haystack, i);
1003 p = g_utf8_prev_char (p);
1008 g_free (caseless_haystack);
1014 backward_lines_match (const GtkTextIter *start,
1015 const gchar **lines,
1016 gboolean visible_only,
1018 GtkTextIter *match_start,
1019 GtkTextIter *match_end)
1021 GtkTextIter line, next;
1026 if (*lines == NULL || **lines == '\0')
1029 *match_start = *start;
1031 *match_end = *start;
1035 line = next = *start;
1036 if (gtk_text_iter_get_line_offset (&next) == 0)
1038 if (!gtk_text_iter_backward_line (&next))
1042 gtk_text_iter_set_line_offset (&next, 0);
1047 line_text = gtk_text_iter_get_visible_slice (&next, &line);
1049 line_text = gtk_text_iter_get_slice (&next, &line);
1054 line_text = gtk_text_iter_get_visible_text (&next, &line);
1056 line_text = gtk_text_iter_get_text (&next, &line);
1059 if (match_start) /* if this is the first line we're matching */
1061 found = g_utf8_strrcasestr (line_text, *lines);
1065 /* If it's not the first line, we have to match from the
1066 * start of the line.
1068 if (g_utf8_caselessnmatch (line_text, *lines, strlen (line_text),
1081 /* Get offset to start of search string */
1082 offset = g_utf8_strlen (line_text, found - line_text);
1084 forward_chars_with_skipping (&next, offset, visible_only, !slice, FALSE);
1086 /* If match start needs to be returned, set it to the
1087 * start of the search string.
1091 *match_start = next;
1094 /* Go to end of search string */
1095 forward_chars_with_skipping (&next, g_utf8_strlen (*lines, -1), visible_only, !slice, TRUE);
1104 /* try to match the rest of the lines forward, passing NULL
1105 * for match_start so lines_match will try to match the entire
1107 return lines_match (&next, lines, visible_only,
1108 slice, NULL, match_end);
1112 gossip_text_iter_backward_search (const GtkTextIter *iter,
1114 GtkTextIter *match_start,
1115 GtkTextIter *match_end,
1116 const GtkTextIter *limit)
1118 gchar **lines = NULL;
1120 gboolean retval = FALSE;
1122 gboolean visible_only;
1125 g_return_val_if_fail (iter != NULL, FALSE);
1126 g_return_val_if_fail (str != NULL, FALSE);
1128 if (limit && gtk_text_iter_compare (iter, limit) <= 0)
1133 /* If we can move one char, return the empty string there */
1136 if (gtk_text_iter_backward_char (&match))
1138 if (limit && gtk_text_iter_equal (&match, limit))
1142 *match_start = match;
1153 visible_only = TRUE;
1156 /* locate all lines */
1157 lines = strbreakup (str, "\n", -1);
1163 /* This loop has an inefficient worst-case, where
1164 * gtk_text_iter_get_text () is called repeatedly on
1169 if (limit && gtk_text_iter_compare (&search, limit) <= 0)
1172 if (backward_lines_match (&search, (const gchar**)lines,
1173 visible_only, slice, &match, &end))
1175 if (limit == NULL || (limit &&
1176 gtk_text_iter_compare (&end, limit) > 0))
1181 *match_start = match;
1188 if (gtk_text_iter_get_line_offset (&search) == 0)
1190 if (!gtk_text_iter_backward_line (&search))
1195 gtk_text_iter_set_line_offset (&search, 0);
1199 g_strfreev ((gchar**)lines);
1205 window_get_is_on_current_workspace (GtkWindow *window)
1207 GdkWindow *gdk_window;
1209 gdk_window = GTK_WIDGET (window)->window;
1211 return !(gdk_window_get_state (gdk_window) &
1212 GDK_WINDOW_STATE_ICONIFIED);
1218 /* Checks if the window is visible as in visible on the current workspace. */
1220 gossip_window_get_is_visible (GtkWindow *window)
1224 g_return_val_if_fail (window != NULL, FALSE);
1226 g_object_get (window,
1227 "visible", &visible,
1230 return visible && window_get_is_on_current_workspace (window);
1233 /* Takes care of moving the window to the current workspace. */
1235 gossip_window_present (GtkWindow *window,
1236 gboolean steal_focus)
1239 gboolean on_current;
1242 g_return_if_fail (window != NULL);
1244 /* There are three cases: hidden, visible, visible on another
1248 g_object_get (window,
1249 "visible", &visible,
1252 on_current = window_get_is_on_current_workspace (window);
1254 if (visible && !on_current) {
1255 /* Hide it so present brings it to the current workspace. */
1256 gtk_widget_hide (GTK_WIDGET (window));
1259 timestamp = gtk_get_current_event_time ();
1260 if (steal_focus && timestamp != GDK_CURRENT_TIME) {
1261 gtk_window_present_with_time (window, timestamp);
1263 gtk_window_present (window);
1267 /* The URL opening code can't handle schemeless strings, so we try to be
1268 * smart and add http if there is no scheme or doesn't look like a mail
1269 * address. This should work in most cases, and let us click on strings
1270 * like "www.gnome.org".
1273 fixup_url (const gchar *url)
1277 if (!g_str_has_prefix (url, "http://") &&
1278 !strstr (url, ":/") &&
1279 !strstr (url, "@")) {
1280 real_url = g_strdup_printf ("http://%s", url);
1282 real_url = g_strdup (url);
1289 gossip_url_show (const char *url)
1292 GError *error = NULL;
1294 real_url = fixup_url (url);
1295 gnome_url_show (real_url, &error);
1297 g_warning ("Couldn't show URL:'%s'", real_url);
1298 g_error_free (error);
1305 link_button_hook (GtkLinkButton *button,
1309 gossip_url_show (link);
1313 gossip_link_button_new (const gchar *url,
1316 static gboolean hook = FALSE;
1320 gtk_link_button_set_uri_hook (link_button_hook, NULL, NULL);
1323 return gtk_link_button_new_with_label (url, title);
1326 /* FIXME: Do this in a proper way at some point, probably in GTK+? */
1328 gossip_window_set_default_icon_name (const gchar *name)
1330 gtk_window_set_default_icon_name (name);
1334 gossip_toggle_button_set_state_quietly (GtkWidget *widget,
1339 g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));
1341 g_signal_handlers_block_by_func (widget, callback, user_data);
1342 g_object_set (widget, "active", active, NULL);
1343 g_signal_handlers_unblock_by_func (widget, callback, user_data);