1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 * Copyright (C) 2005-2007 Imendio AB
4 * Copyright (C) 2007-2010 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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301 USA
21 * Authors: Mikael Hallendal <micke@imendio.com>
22 * Martyn Russell <martyn@imendio.com>
23 * Xavier Claessens <xclaesse@gmail.com>
24 * Travis Reitter <travis.reitter@collabora.co.uk>
31 #include <glib/gi18n-lib.h>
32 #include <gdk/gdkkeysyms.h>
35 #include <telepathy-glib/account-manager.h>
36 #include <telepathy-glib/util.h>
38 #include <folks/folks.h>
39 #include <folks/folks-telepathy.h>
41 #include <libempathy/empathy-call-factory.h>
42 #include <libempathy/empathy-individual-manager.h>
43 #include <libempathy/empathy-contact-groups.h>
44 #include <libempathy/empathy-dispatcher.h>
45 #include <libempathy/empathy-utils.h>
47 #include "empathy-individual-view.h"
48 #include "empathy-individual-menu.h"
49 #include "empathy-individual-store.h"
50 #include "empathy-images.h"
51 #include "empathy-linking-dialog.h"
52 #include "empathy-cell-renderer-expander.h"
53 #include "empathy-cell-renderer-text.h"
54 #include "empathy-cell-renderer-activatable.h"
55 #include "empathy-ui-utils.h"
56 #include "empathy-gtk-enum-types.h"
57 #include "empathy-gtk-marshal.h"
59 #define DEBUG_FLAG EMPATHY_DEBUG_CONTACT
60 #include <libempathy/empathy-debug.h>
62 /* Active users are those which have recently changed state
63 * (e.g. online, offline or from normal to a busy state).
66 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIndividualView)
69 EmpathyIndividualStore *store;
70 GtkTreeRowReference *drag_row;
71 EmpathyIndividualViewFeatureFlags view_features;
72 EmpathyIndividualFeatureFlags individual_features;
73 GtkWidget *tooltip_widget;
75 gboolean show_offline;
76 gboolean show_untrusted;
78 GtkTreeModelFilter *filter;
79 GtkWidget *search_widget;
81 guint expand_groups_idle_handler;
82 /* owned string (group name) -> bool (whether to expand/contract) */
83 GHashTable *expand_groups;
86 guint auto_scroll_timeout_id;
87 /* Distance between mouse pointer and the nearby border. Negative when
90 } EmpathyIndividualViewPriv;
94 EmpathyIndividualView *view;
101 EmpathyIndividualView *view;
102 FolksIndividual *individual;
111 PROP_INDIVIDUAL_FEATURES,
116 /* TODO: re-add DRAG_TYPE_CONTACT_ID, for the case that we're dragging around
117 * specific EmpathyContacts (between/in/out of Individuals) */
120 DND_DRAG_TYPE_INDIVIDUAL_ID,
121 DND_DRAG_TYPE_PERSONA_ID,
122 DND_DRAG_TYPE_URI_LIST,
123 DND_DRAG_TYPE_STRING,
126 #define DRAG_TYPE(T,I) \
127 { (gchar *) T, 0, I }
129 static const GtkTargetEntry drag_types_dest[] = {
130 DRAG_TYPE ("text/individual-id", DND_DRAG_TYPE_INDIVIDUAL_ID),
131 DRAG_TYPE ("text/persona-id", DND_DRAG_TYPE_PERSONA_ID),
132 DRAG_TYPE ("text/path-list", DND_DRAG_TYPE_URI_LIST),
133 DRAG_TYPE ("text/uri-list", DND_DRAG_TYPE_URI_LIST),
134 DRAG_TYPE ("text/plain", DND_DRAG_TYPE_STRING),
135 DRAG_TYPE ("STRING", DND_DRAG_TYPE_STRING),
138 static const GtkTargetEntry drag_types_source[] = {
139 DRAG_TYPE ("text/individual-id", DND_DRAG_TYPE_INDIVIDUAL_ID),
144 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
145 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
149 DRAG_INDIVIDUAL_RECEIVED,
150 DRAG_PERSONA_RECEIVED,
154 static guint signals[LAST_SIGNAL];
156 G_DEFINE_TYPE (EmpathyIndividualView, empathy_individual_view,
160 individual_view_tooltip_destroy_cb (GtkWidget *widget,
161 EmpathyIndividualView *view)
163 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
165 if (priv->tooltip_widget != NULL)
167 DEBUG ("Tooltip destroyed");
168 tp_clear_object (&priv->tooltip_widget);
173 individual_view_query_tooltip_cb (EmpathyIndividualView *view,
176 gboolean keyboard_mode,
180 EmpathyIndividualViewPriv *priv;
181 FolksIndividual *individual;
185 static gint running = 0;
186 gboolean ret = FALSE;
188 priv = GET_PRIV (view);
190 /* Avoid an infinite loop. See GNOME bug #574377 */
196 /* Don't show the tooltip if there's already a popup menu */
197 if (gtk_menu_get_for_attach_widget (GTK_WIDGET (view)) != NULL)
200 if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (view), &x, &y,
201 keyboard_mode, &model, &path, &iter))
204 gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (view), tooltip, path);
205 gtk_tree_path_free (path);
207 gtk_tree_model_get (model, &iter,
208 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
210 if (individual == NULL)
213 if (priv->tooltip_widget == NULL)
215 priv->tooltip_widget = empathy_individual_widget_new (individual,
216 EMPATHY_INDIVIDUAL_WIDGET_FOR_TOOLTIP |
217 EMPATHY_INDIVIDUAL_WIDGET_SHOW_LOCATION |
218 EMPATHY_INDIVIDUAL_WIDGET_SHOW_CLIENT_TYPES);
219 gtk_container_set_border_width (GTK_CONTAINER (priv->tooltip_widget), 8);
220 g_object_ref (priv->tooltip_widget);
221 g_signal_connect (priv->tooltip_widget, "destroy",
222 G_CALLBACK (individual_view_tooltip_destroy_cb), view);
223 gtk_widget_show (priv->tooltip_widget);
227 empathy_individual_widget_set_individual (
228 EMPATHY_INDIVIDUAL_WIDGET (priv->tooltip_widget), individual);
231 gtk_tooltip_set_custom (tooltip, priv->tooltip_widget);
234 g_object_unref (individual);
242 groups_change_group_cb (GObject *source,
243 GAsyncResult *result,
246 FolksGroupable *groupable = FOLKS_GROUPABLE (source);
247 GError *error = NULL;
249 folks_groupable_change_group_finish (groupable, result, &error);
252 g_warning ("failed to change group: %s", error->message);
253 g_clear_error (&error);
258 group_can_be_modified (const gchar *name,
259 gboolean is_fake_group,
262 /* Real groups can always be modified */
266 /* The favorite fake group can be modified so users can
267 * add/remove favorites using DnD */
268 if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
271 /* We can remove contacts from the 'ungrouped' fake group */
272 if (!adding && !tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_UNGROUPED))
279 individual_view_individual_drag_received (GtkWidget *self,
280 GdkDragContext *context,
283 GtkSelectionData *selection)
285 EmpathyIndividualViewPriv *priv;
286 EmpathyIndividualManager *manager = NULL;
287 FolksIndividual *individual;
288 GtkTreePath *source_path;
289 const gchar *sel_data;
290 gchar *new_group = NULL;
291 gchar *old_group = NULL;
292 gboolean new_group_is_fake, old_group_is_fake = TRUE, retval = FALSE;
294 priv = GET_PRIV (self);
296 sel_data = (const gchar *) gtk_selection_data_get_data (selection);
297 new_group = empathy_individual_store_get_parent_group (model, path,
298 NULL, &new_group_is_fake);
300 if (!group_can_be_modified (new_group, new_group_is_fake, TRUE))
303 /* Get source group information iff the view has the FEATURE_GROUPS_CHANGE
304 * feature. Otherwise, we just add the dropped contact to whichever group
305 * they were dropped in, and don't remove them from their old group. This
306 * allows for Individual views which shouldn't allow Individuals to have
307 * their groups changed, and also for dragging Individuals between Individual
309 if ((priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE) &&
310 priv->drag_row != NULL)
312 source_path = gtk_tree_row_reference_get_path (priv->drag_row);
316 empathy_individual_store_get_parent_group (model, source_path,
317 NULL, &old_group_is_fake);
318 gtk_tree_path_free (source_path);
321 if (!group_can_be_modified (old_group, old_group_is_fake, FALSE))
324 if (!tp_strdiff (old_group, new_group))
327 else if (priv->drag_row != NULL)
329 /* We don't allow changing Individuals' groups, and this Individual was
330 * dragged from another group in *this* Individual view, so we disallow
335 /* XXX: for contacts, we used to ensure the account, create the contact
336 * factory, and then wait on the contacts. But they should already be
337 * created by this point */
339 manager = empathy_individual_manager_dup_singleton ();
340 individual = empathy_individual_manager_lookup_member (manager, sel_data);
342 if (individual == NULL)
344 DEBUG ("failed to find drag event individual with ID '%s'", sel_data);
348 /* FIXME: We should probably wait for the cb before calling
351 /* Emit a signal notifying of the drag. We change the Individual's groups in
352 * the default signal handler. */
353 g_signal_emit (self, signals[DRAG_INDIVIDUAL_RECEIVED], 0,
354 gdk_drag_context_get_selected_action (context), individual, new_group,
360 tp_clear_object (&manager);
368 real_drag_individual_received_cb (EmpathyIndividualView *self,
369 GdkDragAction action,
370 FolksIndividual *individual,
371 const gchar *new_group,
372 const gchar *old_group)
374 DEBUG ("individual %s dragged from '%s' to '%s'",
375 folks_individual_get_id (individual), old_group, new_group);
377 if (!tp_strdiff (new_group, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
379 /* Mark contact as favourite */
380 folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual), TRUE);
384 if (!tp_strdiff (old_group, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
386 /* Remove contact as favourite */
387 folks_favourite_set_is_favourite (FOLKS_FAVOURITE (individual), FALSE);
389 /* Don't try to remove it */
393 if (new_group != NULL)
395 folks_groupable_change_group (FOLKS_GROUPABLE (individual), new_group, TRUE,
396 groups_change_group_cb, NULL);
399 if (old_group != NULL && action == GDK_ACTION_MOVE)
401 folks_groupable_change_group (FOLKS_GROUPABLE (individual), old_group,
402 FALSE, groups_change_group_cb, NULL);
407 individual_view_persona_drag_received (GtkWidget *self,
408 GdkDragContext *context,
411 GtkSelectionData *selection)
413 EmpathyIndividualViewPriv *priv;
414 EmpathyIndividualManager *manager = NULL;
415 FolksIndividual *individual = NULL;
416 FolksPersona *persona = NULL;
417 const gchar *persona_uid;
418 GList *individuals, *l;
419 gboolean retval = FALSE;
421 priv = GET_PRIV (self);
423 persona_uid = (const gchar *) gtk_selection_data_get_data (selection);
425 /* FIXME: This is slow, but the only way to find the Persona we're having
427 manager = empathy_individual_manager_dup_singleton ();
428 individuals = empathy_individual_manager_get_members (manager);
430 for (l = individuals; l != NULL; l = l->next)
434 personas = folks_individual_get_personas (FOLKS_INDIVIDUAL (l->data));
436 for (p = personas; p != NULL; p = p->next)
438 if (!tp_strdiff (folks_persona_get_uid (FOLKS_PERSONA (p->data)),
441 persona = g_object_ref (p->data);
442 individual = g_object_ref (l->data);
449 g_list_free (individuals);
451 if (persona == NULL || individual == NULL)
453 DEBUG ("Failed to find drag event persona with UID '%s'", persona_uid);
457 /* Emit a signal notifying of the drag. We change the Individual's groups in
458 * the default signal handler. */
459 g_signal_emit (self, signals[DRAG_PERSONA_RECEIVED], 0,
460 gdk_drag_context_get_selected_action (context), persona, individual,
464 tp_clear_object (&manager);
465 tp_clear_object (&persona);
466 tp_clear_object (&individual);
472 individual_view_file_drag_received (GtkWidget *view,
473 GdkDragContext *context,
476 GtkSelectionData *selection)
479 const gchar *sel_data;
480 FolksIndividual *individual;
481 EmpathyContact *contact;
483 sel_data = (const gchar *) gtk_selection_data_get_data (selection);
485 gtk_tree_model_get_iter (model, &iter, path);
486 gtk_tree_model_get (model, &iter,
487 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
488 if (individual == NULL)
491 contact = empathy_contact_dup_from_folks_individual (individual);
492 empathy_send_file_from_uri_list (contact, sel_data);
494 g_object_unref (individual);
495 tp_clear_object (&contact);
501 individual_view_drag_data_received (GtkWidget *view,
502 GdkDragContext *context,
505 GtkSelectionData *selection,
511 GtkTreeViewDropPosition position;
513 gboolean success = TRUE;
515 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
517 /* Get destination group information. */
518 is_row = gtk_tree_view_get_dest_row_at_pos (GTK_TREE_VIEW (view),
519 x, y, &path, &position);
524 else if (info == DND_DRAG_TYPE_INDIVIDUAL_ID)
526 success = individual_view_individual_drag_received (view,
527 context, model, path, selection);
529 else if (info == DND_DRAG_TYPE_PERSONA_ID)
531 success = individual_view_persona_drag_received (view, context, model,
534 else if (info == DND_DRAG_TYPE_URI_LIST || info == DND_DRAG_TYPE_STRING)
536 success = individual_view_file_drag_received (view,
537 context, model, path, selection);
540 gtk_tree_path_free (path);
541 gtk_drag_finish (context, success, FALSE, GDK_CURRENT_TIME);
545 individual_view_drag_motion_cb (DragMotionData *data)
547 if (data->view != NULL)
549 gtk_tree_view_expand_row (GTK_TREE_VIEW (data->view), data->path, FALSE);
550 g_object_remove_weak_pointer (G_OBJECT (data->view),
551 (gpointer *) &data->view);
554 data->timeout_id = 0;
559 /* Minimum distance between the mouse pointer and a horizontal border when we
560 start auto scrolling. */
561 #define AUTO_SCROLL_MARGIN_SIZE 20
562 /* How far to scroll per one tick. */
563 #define AUTO_SCROLL_PITCH 10
566 individual_view_auto_scroll_cb (EmpathyIndividualView *self)
568 EmpathyIndividualViewPriv *priv = GET_PRIV (self);
572 adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (self));
574 if (priv->distance < 0)
575 new_value = gtk_adjustment_get_value (adj) - AUTO_SCROLL_PITCH;
577 new_value = gtk_adjustment_get_value (adj) + AUTO_SCROLL_PITCH;
579 new_value = CLAMP (new_value, gtk_adjustment_get_lower (adj),
580 gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj));
582 gtk_adjustment_set_value (adj, new_value);
588 individual_view_drag_motion (GtkWidget *widget,
589 GdkDragContext *context,
594 EmpathyIndividualViewPriv *priv;
598 static DragMotionData *dm = NULL;
601 gboolean is_different = FALSE;
602 gboolean cleanup = TRUE;
603 gboolean retval = TRUE;
604 GtkAllocation allocation;
606 priv = GET_PRIV (EMPATHY_INDIVIDUAL_VIEW (widget));
607 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
610 if (priv->auto_scroll_timeout_id != 0)
612 g_source_remove (priv->auto_scroll_timeout_id);
613 priv->auto_scroll_timeout_id = 0;
616 gtk_widget_get_allocation (widget, &allocation);
618 if (y < AUTO_SCROLL_MARGIN_SIZE ||
619 y > (allocation.height - AUTO_SCROLL_MARGIN_SIZE))
621 if (y < AUTO_SCROLL_MARGIN_SIZE)
622 priv->distance = MIN (-y, -1);
624 priv->distance = MAX (allocation.height - y, 1);
626 priv->auto_scroll_timeout_id = g_timeout_add (10 * ABS (priv->distance),
627 (GSourceFunc) individual_view_auto_scroll_cb, widget);
630 is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
631 x, y, &path, NULL, NULL, NULL);
633 cleanup &= (dm == NULL);
637 cleanup &= (dm && gtk_tree_path_compare (dm->path, path) != 0);
638 is_different = ((dm == NULL) || ((dm != NULL)
639 && gtk_tree_path_compare (dm->path, path) != 0));
646 /* Coordinates don't point to an actual row, so make sure the pointer
647 and highlighting don't indicate that a drag is possible.
649 gdk_drag_status (context, GDK_ACTION_DEFAULT, time_);
650 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), NULL, 0);
653 target = gtk_drag_dest_find_target (widget, context, NULL);
654 gtk_tree_model_get_iter (model, &iter, path);
656 if (target == drag_atoms_dest[DND_DRAG_TYPE_URI_LIST] ||
657 target == drag_atoms_dest[DND_DRAG_TYPE_STRING])
659 /* This is a file drag, and it can only be dropped on contacts,
661 * If we don't have FEATURE_FILE_DROP, disallow the drop completely,
662 * even if we have a valid target. */
663 FolksIndividual *individual = NULL;
664 EmpathyCapabilities caps = EMPATHY_CAPABILITIES_NONE;
666 if (priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_FILE_DROP)
668 gtk_tree_model_get (model, &iter,
669 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
673 if (individual != NULL)
675 EmpathyContact *contact = NULL;
677 contact = empathy_contact_dup_from_folks_individual (individual);
678 caps = empathy_contact_get_capabilities (contact);
680 tp_clear_object (&contact);
683 if (individual != NULL &&
684 folks_presence_is_online (FOLKS_PRESENCE (individual)) &&
685 (caps & EMPATHY_CAPABILITIES_FT))
687 gdk_drag_status (context, GDK_ACTION_COPY, time_);
688 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
689 path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
693 gdk_drag_status (context, 0, time_);
694 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget), NULL, 0);
698 if (individual != NULL)
699 g_object_unref (individual);
701 else if ((target == drag_atoms_dest[DND_DRAG_TYPE_INDIVIDUAL_ID] &&
702 (priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_CHANGE ||
703 priv->drag_row == NULL)) ||
704 (target == drag_atoms_dest[DND_DRAG_TYPE_PERSONA_ID] &&
705 priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_PERSONA_DROP))
707 /* If target != GDK_NONE, then we have a contact (individual or persona)
708 drag. If we're pointing to a group, highlight it. Otherwise, if the
709 contact we're pointing to is in a group, highlight that. Otherwise,
710 set the drag position to before the first row for a drag into
711 the "non-group" at the top.
712 If it's an Individual:
713 We only highlight things if the contact is from a different
714 Individual view, or if this Individual view has
715 FEATURE_GROUPS_CHANGE. This prevents highlighting in Individual views
716 which don't have FEATURE_GROUPS_CHANGE, but do have
717 FEATURE_INDIVIDUAL_DRAG and FEATURE_INDIVIDUAL_DROP.
719 We only highlight things if we have FEATURE_PERSONA_DROP.
721 GtkTreeIter group_iter;
723 GtkTreePath *group_path;
724 gtk_tree_model_get (model, &iter,
725 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
732 if (gtk_tree_model_iter_parent (model, &group_iter, &iter))
733 gtk_tree_model_get (model, &group_iter,
734 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group, -1);
738 gdk_drag_status (context, GDK_ACTION_MOVE, time_);
739 group_path = gtk_tree_model_get_path (model, &group_iter);
740 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
741 group_path, GTK_TREE_VIEW_DROP_INTO_OR_BEFORE);
742 gtk_tree_path_free (group_path);
746 group_path = gtk_tree_path_new_first ();
747 gdk_drag_status (context, GDK_ACTION_MOVE, time_);
748 gtk_tree_view_set_drag_dest_row (GTK_TREE_VIEW (widget),
749 group_path, GTK_TREE_VIEW_DROP_BEFORE);
753 if (!is_different && !cleanup)
758 gtk_tree_path_free (dm->path);
761 g_source_remove (dm->timeout_id);
769 if (!gtk_tree_view_row_expanded (GTK_TREE_VIEW (widget), path))
771 dm = g_new0 (DragMotionData, 1);
773 dm->view = EMPATHY_INDIVIDUAL_VIEW (widget);
774 g_object_add_weak_pointer (G_OBJECT (widget), (gpointer *) &dm->view);
775 dm->path = gtk_tree_path_copy (path);
777 dm->timeout_id = g_timeout_add_seconds (1,
778 (GSourceFunc) individual_view_drag_motion_cb, dm);
785 individual_view_drag_begin (GtkWidget *widget,
786 GdkDragContext *context)
788 EmpathyIndividualViewPriv *priv;
789 GtkTreeSelection *selection;
794 priv = GET_PRIV (widget);
796 GTK_WIDGET_CLASS (empathy_individual_view_parent_class)->drag_begin (widget,
799 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
800 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
803 path = gtk_tree_model_get_path (model, &iter);
804 priv->drag_row = gtk_tree_row_reference_new (model, path);
805 gtk_tree_path_free (path);
809 individual_view_drag_data_get (GtkWidget *widget,
810 GdkDragContext *context,
811 GtkSelectionData *selection,
815 EmpathyIndividualViewPriv *priv;
816 GtkTreePath *src_path;
819 FolksIndividual *individual;
820 const gchar *individual_id;
822 priv = GET_PRIV (widget);
824 model = gtk_tree_view_get_model (GTK_TREE_VIEW (widget));
825 if (priv->drag_row == NULL)
828 src_path = gtk_tree_row_reference_get_path (priv->drag_row);
829 if (src_path == NULL)
832 if (!gtk_tree_model_get_iter (model, &iter, src_path))
834 gtk_tree_path_free (src_path);
838 gtk_tree_path_free (src_path);
841 empathy_individual_view_dup_selected (EMPATHY_INDIVIDUAL_VIEW (widget));
842 if (individual == NULL)
845 individual_id = folks_individual_get_id (individual);
847 if (info == DND_DRAG_TYPE_INDIVIDUAL_ID)
849 gtk_selection_data_set (selection, drag_atoms_source[info], 8,
850 (guchar *) individual_id, strlen (individual_id) + 1);
853 g_object_unref (individual);
857 individual_view_drag_end (GtkWidget *widget,
858 GdkDragContext *context)
860 EmpathyIndividualViewPriv *priv;
862 priv = GET_PRIV (widget);
864 GTK_WIDGET_CLASS (empathy_individual_view_parent_class)->drag_end (widget,
869 gtk_tree_row_reference_free (priv->drag_row);
870 priv->drag_row = NULL;
875 individual_view_drag_drop (GtkWidget *widget,
876 GdkDragContext *drag_context,
886 EmpathyIndividualView *view;
892 individual_view_popup_menu_idle_cb (gpointer user_data)
894 MenuPopupData *data = user_data;
897 menu = empathy_individual_view_get_individual_menu (data->view);
899 menu = empathy_individual_view_get_group_menu (data->view);
903 g_signal_connect (menu, "deactivate", G_CALLBACK (gtk_menu_detach), NULL);
904 gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (data->view),
906 gtk_widget_show (menu);
907 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, data->button,
909 g_object_ref_sink (menu);
910 g_object_unref (menu);
913 g_slice_free (MenuPopupData, data);
919 individual_view_button_press_event_cb (EmpathyIndividualView *view,
920 GdkEventButton *event,
923 if (event->button == 3)
927 data = g_slice_new (MenuPopupData);
929 data->button = event->button;
930 data->time = event->time;
931 g_idle_add (individual_view_popup_menu_idle_cb, data);
938 individual_view_key_press_event_cb (EmpathyIndividualView *view,
942 if (event->keyval == GDK_KEY_Menu)
946 data = g_slice_new (MenuPopupData);
949 data->time = event->time;
950 g_idle_add (individual_view_popup_menu_idle_cb, data);
957 individual_view_row_activated (GtkTreeView *view,
959 GtkTreeViewColumn *column)
961 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
962 FolksIndividual *individual;
963 EmpathyContact *contact;
967 if (!(priv->individual_features & EMPATHY_INDIVIDUAL_FEATURE_CHAT))
970 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
971 gtk_tree_model_get_iter (model, &iter, path);
972 gtk_tree_model_get (model, &iter,
973 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
975 if (individual == NULL)
978 /* Determine which Persona to chat to, by choosing the most available one. */
979 contact = empathy_contact_dup_best_for_action (individual,
980 EMPATHY_ACTION_CHAT);
984 DEBUG ("Starting a chat");
986 empathy_dispatcher_chat_with_contact (contact,
987 gtk_get_current_event_time ());
990 g_object_unref (individual);
991 tp_clear_object (&contact);
995 individual_view_call_activated_cb (EmpathyCellRendererActivatable *cell,
996 const gchar *path_string,
997 EmpathyIndividualView *view)
999 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1001 GtkTreeModel *model;
1003 FolksIndividual *individual;
1004 GdkEventButton *event;
1005 GtkMenuShell *shell;
1008 if (!(priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_CALL))
1011 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1012 if (!gtk_tree_model_get_iter_from_string (model, &iter, path_string))
1015 gtk_tree_model_get (model, &iter,
1016 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
1017 if (individual == NULL)
1020 event = (GdkEventButton *) gtk_get_current_event ();
1022 menu = gtk_menu_new ();
1023 shell = GTK_MENU_SHELL (menu);
1026 item = empathy_individual_audio_call_menu_item_new (individual, NULL);
1027 gtk_menu_shell_append (shell, item);
1028 gtk_widget_show (item);
1031 item = empathy_individual_video_call_menu_item_new (individual, NULL);
1032 gtk_menu_shell_append (shell, item);
1033 gtk_widget_show (item);
1035 g_signal_connect (menu, "deactivate", G_CALLBACK (gtk_menu_detach), NULL);
1036 gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (view), NULL);
1037 gtk_widget_show (menu);
1038 gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
1039 event->button, event->time);
1040 g_object_ref_sink (menu);
1041 g_object_unref (menu);
1043 g_object_unref (individual);
1047 individual_view_cell_set_background (EmpathyIndividualView *view,
1048 GtkCellRenderer *cell,
1055 style = gtk_widget_get_style (GTK_WIDGET (view));
1057 if (!is_group && is_active)
1059 color = style->bg[GTK_STATE_SELECTED];
1061 /* Here we take the current theme colour and add it to
1062 * the colour for white and average the two. This
1063 * gives a colour which is inline with the theme but
1066 color.red = (color.red + (style->white).red) / 2;
1067 color.green = (color.green + (style->white).green) / 2;
1068 color.blue = (color.blue + (style->white).blue) / 2;
1070 g_object_set (cell, "cell-background-gdk", &color, NULL);
1073 g_object_set (cell, "cell-background-gdk", NULL, NULL);
1077 individual_view_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
1078 GtkCellRenderer *cell,
1079 GtkTreeModel *model,
1081 EmpathyIndividualView *view)
1087 gtk_tree_model_get (model, iter,
1088 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1089 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, &is_active,
1090 EMPATHY_INDIVIDUAL_STORE_COL_ICON_STATUS, &pixbuf, -1);
1093 "visible", !is_group,
1097 tp_clear_object (&pixbuf);
1099 individual_view_cell_set_background (view, cell, is_group, is_active);
1103 individual_view_group_icon_cell_data_func (GtkTreeViewColumn *tree_column,
1104 GtkCellRenderer *cell,
1105 GtkTreeModel *model,
1107 EmpathyIndividualView *view)
1109 GdkPixbuf *pixbuf = NULL;
1113 gtk_tree_model_get (model, iter,
1114 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1115 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1120 if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_FAVORITE))
1122 pixbuf = empathy_pixbuf_from_icon_name ("emblem-favorite",
1123 GTK_ICON_SIZE_MENU);
1125 else if (!tp_strdiff (name, EMPATHY_INDIVIDUAL_STORE_PEOPLE_NEARBY))
1127 pixbuf = empathy_pixbuf_from_icon_name ("im-local-xmpp",
1128 GTK_ICON_SIZE_MENU);
1133 "visible", pixbuf != NULL,
1137 tp_clear_object (&pixbuf);
1143 individual_view_audio_call_cell_data_func (GtkTreeViewColumn *tree_column,
1144 GtkCellRenderer *cell,
1145 GtkTreeModel *model,
1147 EmpathyIndividualView *view)
1151 gboolean can_audio, can_video;
1153 gtk_tree_model_get (model, iter,
1154 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1155 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, &is_active,
1156 EMPATHY_INDIVIDUAL_STORE_COL_CAN_AUDIO_CALL, &can_audio,
1157 EMPATHY_INDIVIDUAL_STORE_COL_CAN_VIDEO_CALL, &can_video, -1);
1160 "visible", !is_group && (can_audio || can_video),
1161 "icon-name", can_video ? EMPATHY_IMAGE_VIDEO_CALL : EMPATHY_IMAGE_VOIP,
1164 individual_view_cell_set_background (view, cell, is_group, is_active);
1168 individual_view_avatar_cell_data_func (GtkTreeViewColumn *tree_column,
1169 GtkCellRenderer *cell,
1170 GtkTreeModel *model,
1172 EmpathyIndividualView *view)
1175 gboolean show_avatar;
1179 gtk_tree_model_get (model, iter,
1180 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR, &pixbuf,
1181 EMPATHY_INDIVIDUAL_STORE_COL_PIXBUF_AVATAR_VISIBLE, &show_avatar,
1182 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1183 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, &is_active, -1);
1186 "visible", !is_group && show_avatar,
1190 tp_clear_object (&pixbuf);
1192 individual_view_cell_set_background (view, cell, is_group, is_active);
1196 individual_view_text_cell_data_func (GtkTreeViewColumn *tree_column,
1197 GtkCellRenderer *cell,
1198 GtkTreeModel *model,
1200 EmpathyIndividualView *view)
1205 gtk_tree_model_get (model, iter,
1206 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1207 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, &is_active, -1);
1209 individual_view_cell_set_background (view, cell, is_group, is_active);
1213 individual_view_expander_cell_data_func (GtkTreeViewColumn *column,
1214 GtkCellRenderer *cell,
1215 GtkTreeModel *model,
1217 EmpathyIndividualView *view)
1222 gtk_tree_model_get (model, iter,
1223 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1224 EMPATHY_INDIVIDUAL_STORE_COL_IS_ACTIVE, &is_active, -1);
1226 if (gtk_tree_model_iter_has_child (model, iter))
1229 gboolean row_expanded;
1231 path = gtk_tree_model_get_path (model, iter);
1233 gtk_tree_view_row_expanded (GTK_TREE_VIEW
1234 (gtk_tree_view_column_get_tree_view (column)), path);
1235 gtk_tree_path_free (path);
1240 row_expanded ? GTK_EXPANDER_EXPANDED : GTK_EXPANDER_COLLAPSED,
1244 g_object_set (cell, "visible", FALSE, NULL);
1246 individual_view_cell_set_background (view, cell, is_group, is_active);
1250 individual_view_row_expand_or_collapse_cb (EmpathyIndividualView *view,
1255 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1256 GtkTreeModel *model;
1260 if (!(priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_SAVE))
1263 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1265 gtk_tree_model_get (model, iter,
1266 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name, -1);
1268 expanded = GPOINTER_TO_INT (user_data);
1269 empathy_contact_group_set_expanded (name, expanded);
1275 individual_view_start_search_cb (EmpathyIndividualView *view,
1278 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1280 if (priv->search_widget == NULL)
1283 empathy_individual_view_start_search (view);
1289 individual_view_search_text_notify_cb (EmpathyLiveSearch *search,
1291 EmpathyIndividualView *view)
1293 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1295 GtkTreeViewColumn *focus_column;
1296 GtkTreeModel *model;
1298 gboolean set_cursor = FALSE;
1300 gtk_tree_model_filter_refilter (priv->filter);
1302 /* Set cursor on the first contact. If it is already set on a group,
1303 * set it on its first child contact. Note that first child of a group
1304 * is its separator, that's why we actually set to the 2nd
1307 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1308 gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, &focus_column);
1312 path = gtk_tree_path_new_from_string ("0:1");
1315 else if (gtk_tree_path_get_depth (path) < 2)
1319 gtk_tree_model_get_iter (model, &iter, path);
1320 gtk_tree_model_get (model, &iter,
1321 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1326 gtk_tree_path_down (path);
1327 gtk_tree_path_next (path);
1334 /* FIXME: Workaround for GTK bug #621651, we have to make sure the path is
1336 if (gtk_tree_model_get_iter (model, &iter, path))
1338 gtk_tree_view_set_cursor (GTK_TREE_VIEW (view), path, focus_column,
1343 gtk_tree_path_free (path);
1347 individual_view_search_activate_cb (GtkWidget *search,
1348 EmpathyIndividualView *view)
1351 GtkTreeViewColumn *focus_column;
1353 gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &path, &focus_column);
1356 gtk_tree_view_row_activated (GTK_TREE_VIEW (view), path, focus_column);
1357 gtk_tree_path_free (path);
1359 gtk_widget_hide (search);
1364 individual_view_search_key_navigation_cb (GtkWidget *search,
1366 EmpathyIndividualView *view)
1368 GdkEventKey *eventkey = ((GdkEventKey *) event);
1369 gboolean ret = FALSE;
1371 if (eventkey->keyval == GDK_KEY_Up || eventkey->keyval == GDK_KEY_Down)
1373 GdkEvent *new_event;
1375 new_event = gdk_event_copy (event);
1376 gtk_widget_grab_focus (GTK_WIDGET (view));
1377 ret = gtk_widget_event (GTK_WIDGET (view), new_event);
1378 gtk_widget_grab_focus (search);
1380 gdk_event_free (new_event);
1387 individual_view_search_hide_cb (EmpathyLiveSearch *search,
1388 EmpathyIndividualView *view)
1390 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1391 GtkTreeModel *model;
1392 GtkTreePath *cursor_path;
1394 gboolean valid = FALSE;
1396 /* block expand or collapse handlers, they would write the
1397 * expand or collapsed setting to file otherwise */
1398 g_signal_handlers_block_by_func (view,
1399 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (TRUE));
1400 g_signal_handlers_block_by_func (view,
1401 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (FALSE));
1403 /* restore which groups are expanded and which are not */
1404 model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
1405 for (valid = gtk_tree_model_get_iter_first (model, &iter);
1406 valid; valid = gtk_tree_model_iter_next (model, &iter))
1412 gtk_tree_model_get (model, &iter,
1413 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1414 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1423 path = gtk_tree_model_get_path (model, &iter);
1424 if ((priv->view_features &
1425 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_SAVE) == 0 ||
1426 empathy_contact_group_get_expanded (name))
1428 gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, TRUE);
1432 gtk_tree_view_collapse_row (GTK_TREE_VIEW (view), path);
1435 gtk_tree_path_free (path);
1439 /* unblock expand or collapse handlers */
1440 g_signal_handlers_unblock_by_func (view,
1441 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (TRUE));
1442 g_signal_handlers_unblock_by_func (view,
1443 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (FALSE));
1445 /* keep the selected contact visible */
1446 gtk_tree_view_get_cursor (GTK_TREE_VIEW (view), &cursor_path, NULL);
1448 if (cursor_path != NULL)
1449 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), cursor_path, NULL,
1452 gtk_tree_path_free (cursor_path);
1456 individual_view_search_show_cb (EmpathyLiveSearch *search,
1457 EmpathyIndividualView *view)
1459 /* block expand or collapse handlers during expand all, they would
1460 * write the expand or collapsed setting to file otherwise */
1461 g_signal_handlers_block_by_func (view,
1462 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (TRUE));
1464 gtk_tree_view_expand_all (GTK_TREE_VIEW (view));
1466 g_signal_handlers_unblock_by_func (view,
1467 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (TRUE));
1471 expand_idle_foreach_cb (GtkTreeModel *model,
1474 EmpathyIndividualView *self)
1476 EmpathyIndividualViewPriv *priv;
1478 gpointer should_expand;
1481 /* We only want groups */
1482 if (gtk_tree_path_get_depth (path) > 1)
1485 gtk_tree_model_get (model, iter,
1486 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1487 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1490 if (is_group == FALSE)
1496 priv = GET_PRIV (self);
1498 if (g_hash_table_lookup_extended (priv->expand_groups, name, NULL,
1499 &should_expand) == TRUE)
1501 if (GPOINTER_TO_INT (should_expand) == TRUE)
1502 gtk_tree_view_expand_row (GTK_TREE_VIEW (self), path, FALSE);
1504 gtk_tree_view_collapse_row (GTK_TREE_VIEW (self), path);
1506 g_hash_table_remove (priv->expand_groups, name);
1515 individual_view_expand_idle_cb (EmpathyIndividualView *self)
1517 EmpathyIndividualViewPriv *priv = GET_PRIV (self);
1519 DEBUG ("individual_view_expand_idle_cb");
1521 g_signal_handlers_block_by_func (self,
1522 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (TRUE));
1523 g_signal_handlers_block_by_func (self,
1524 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (FALSE));
1526 /* The store/filter could've been removed while we were in the idle queue */
1527 if (priv->filter != NULL)
1529 gtk_tree_model_foreach (GTK_TREE_MODEL (priv->filter),
1530 (GtkTreeModelForeachFunc) expand_idle_foreach_cb, self);
1533 g_signal_handlers_unblock_by_func (self,
1534 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (FALSE));
1535 g_signal_handlers_unblock_by_func (self,
1536 individual_view_row_expand_or_collapse_cb, GINT_TO_POINTER (TRUE));
1538 /* Empty the table of groups to expand/contract, since it may contain groups
1539 * which no longer exist in the tree view. This can happen after going
1540 * offline, for example. */
1541 g_hash_table_remove_all (priv->expand_groups);
1542 priv->expand_groups_idle_handler = 0;
1543 g_object_unref (self);
1549 individual_view_row_has_child_toggled_cb (GtkTreeModel *model,
1552 EmpathyIndividualView *view)
1554 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1555 gboolean should_expand, is_group = FALSE;
1557 gpointer will_expand;
1559 gtk_tree_model_get (model, iter,
1560 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1561 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
1564 if (!is_group || EMP_STR_EMPTY (name))
1570 should_expand = (priv->view_features &
1571 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_SAVE) == 0 ||
1572 (priv->search_widget != NULL &&
1573 gtk_widget_get_visible (priv->search_widget)) ||
1574 empathy_contact_group_get_expanded (name);
1576 /* FIXME: It doesn't work to call gtk_tree_view_expand_row () from within
1577 * gtk_tree_model_filter_refilter (). We add the rows to expand/contract to
1578 * a hash table, and expand or contract them as appropriate all at once in
1579 * an idle handler which iterates over all the group rows. */
1580 if (g_hash_table_lookup_extended (priv->expand_groups, name, NULL,
1581 &will_expand) == FALSE ||
1582 GPOINTER_TO_INT (will_expand) != should_expand)
1584 g_hash_table_insert (priv->expand_groups, g_strdup (name),
1585 GINT_TO_POINTER (should_expand));
1587 if (priv->expand_groups_idle_handler == 0)
1589 priv->expand_groups_idle_handler =
1590 g_idle_add ((GSourceFunc) individual_view_expand_idle_cb,
1591 g_object_ref (view));
1598 /* FIXME: This is a workaround for bgo#621076 */
1600 individual_view_verify_group_visibility (EmpathyIndividualView *view,
1603 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1604 GtkTreeModel *model;
1605 GtkTreePath *parent_path;
1606 GtkTreeIter parent_iter;
1608 if (gtk_tree_path_get_depth (path) < 2)
1611 /* A group row is visible if and only if at least one if its child is visible.
1612 * So when a row is inserted/deleted/changed in the base model, that could
1613 * modify the visibility of its parent in the filter model.
1616 model = GTK_TREE_MODEL (priv->store);
1617 parent_path = gtk_tree_path_copy (path);
1618 gtk_tree_path_up (parent_path);
1619 if (gtk_tree_model_get_iter (model, &parent_iter, parent_path))
1621 /* This tells the filter to verify the visibility of that row, and
1622 * show/hide it if necessary */
1623 gtk_tree_model_row_changed (GTK_TREE_MODEL (priv->store),
1624 parent_path, &parent_iter);
1626 gtk_tree_path_free (parent_path);
1630 individual_view_store_row_changed_cb (GtkTreeModel *model,
1633 EmpathyIndividualView *view)
1635 individual_view_verify_group_visibility (view, path);
1639 individual_view_store_row_deleted_cb (GtkTreeModel *model,
1641 EmpathyIndividualView *view)
1643 individual_view_verify_group_visibility (view, path);
1647 individual_view_is_visible_individual (EmpathyIndividualView *self,
1648 FolksIndividual *individual,
1650 gboolean is_searching)
1652 EmpathyIndividualViewPriv *priv = GET_PRIV (self);
1653 EmpathyLiveSearch *live = EMPATHY_LIVE_SEARCH (priv->search_widget);
1655 GList *personas, *l;
1657 /* We're only giving the visibility wrt filtering here, not things like
1659 if (priv->show_untrusted == FALSE &&
1660 folks_individual_get_trust_level (individual) == FOLKS_TRUST_LEVEL_NONE)
1665 if (is_searching == FALSE)
1666 return (priv->show_offline || is_online);
1668 /* check alias name */
1669 str = folks_aliasable_get_alias (FOLKS_ALIASABLE (individual));
1671 if (empathy_live_search_match (live, str))
1674 /* check contact id, remove the @server.com part */
1675 personas = folks_individual_get_personas (individual);
1676 for (l = personas; l; l = l->next)
1679 gchar *dup_str = NULL;
1682 if (!TPF_IS_PERSONA (l->data))
1685 str = folks_persona_get_display_id (l->data);
1686 p = strstr (str, "@");
1688 str = dup_str = g_strndup (str, p - str);
1690 visible = empathy_live_search_match (live, str);
1696 /* FIXME: Add more rules here, we could check phone numbers in
1697 * contact's vCard for example. */
1703 individual_view_filter_visible_func (GtkTreeModel *model,
1707 EmpathyIndividualView *self = EMPATHY_INDIVIDUAL_VIEW (user_data);
1708 EmpathyIndividualViewPriv *priv = GET_PRIV (self);
1709 FolksIndividual *individual = NULL;
1710 gboolean is_group, is_separator, valid;
1711 GtkTreeIter child_iter;
1712 gboolean visible, is_online;
1713 gboolean is_searching = TRUE;
1715 if (priv->search_widget == NULL ||
1716 !gtk_widget_get_visible (priv->search_widget))
1717 is_searching = FALSE;
1719 gtk_tree_model_get (model, iter,
1720 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
1721 EMPATHY_INDIVIDUAL_STORE_COL_IS_SEPARATOR, &is_separator,
1722 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &is_online,
1723 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
1726 if (individual != NULL)
1728 visible = individual_view_is_visible_individual (self, individual,
1729 is_online, is_searching);
1731 g_object_unref (individual);
1733 /* FIXME: Work around bgo#626552/bgo#621076 */
1734 if (visible == TRUE)
1736 GtkTreePath *path = gtk_tree_model_get_path (model, iter);
1737 individual_view_verify_group_visibility (self, path);
1738 gtk_tree_path_free (path);
1747 /* Not a contact, not a separator, must be a group */
1748 g_return_val_if_fail (is_group, FALSE);
1750 /* only show groups which are not empty */
1751 for (valid = gtk_tree_model_iter_children (model, &child_iter, iter);
1752 valid; valid = gtk_tree_model_iter_next (model, &child_iter))
1754 gtk_tree_model_get (model, &child_iter,
1755 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual,
1756 EMPATHY_INDIVIDUAL_STORE_COL_IS_ONLINE, &is_online,
1759 if (individual == NULL)
1762 visible = individual_view_is_visible_individual (self, individual,
1763 is_online, is_searching);
1764 g_object_unref (individual);
1766 /* show group if it has at least one visible contact in it */
1767 if (visible == TRUE)
1775 individual_view_constructed (GObject *object)
1777 EmpathyIndividualView *view = EMPATHY_INDIVIDUAL_VIEW (object);
1778 GtkCellRenderer *cell;
1779 GtkTreeViewColumn *col;
1784 "headers-visible", FALSE,
1785 "show-expanders", FALSE,
1788 col = gtk_tree_view_column_new ();
1791 cell = gtk_cell_renderer_pixbuf_new ();
1792 gtk_tree_view_column_pack_start (col, cell, FALSE);
1793 gtk_tree_view_column_set_cell_data_func (col, cell,
1794 (GtkTreeCellDataFunc) individual_view_pixbuf_cell_data_func,
1804 cell = gtk_cell_renderer_pixbuf_new ();
1805 gtk_tree_view_column_pack_start (col, cell, FALSE);
1806 gtk_tree_view_column_set_cell_data_func (col, cell,
1807 (GtkTreeCellDataFunc) individual_view_group_icon_cell_data_func,
1819 cell = empathy_cell_renderer_text_new ();
1820 gtk_tree_view_column_pack_start (col, cell, TRUE);
1821 gtk_tree_view_column_set_cell_data_func (col, cell,
1822 (GtkTreeCellDataFunc) individual_view_text_cell_data_func, view, NULL);
1824 gtk_tree_view_column_add_attribute (col, cell,
1825 "name", EMPATHY_INDIVIDUAL_STORE_COL_NAME);
1826 gtk_tree_view_column_add_attribute (col, cell,
1827 "text", EMPATHY_INDIVIDUAL_STORE_COL_NAME);
1828 gtk_tree_view_column_add_attribute (col, cell,
1829 "presence-type", EMPATHY_INDIVIDUAL_STORE_COL_PRESENCE_TYPE);
1830 gtk_tree_view_column_add_attribute (col, cell,
1831 "status", EMPATHY_INDIVIDUAL_STORE_COL_STATUS);
1832 gtk_tree_view_column_add_attribute (col, cell,
1833 "is_group", EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP);
1834 gtk_tree_view_column_add_attribute (col, cell,
1835 "compact", EMPATHY_INDIVIDUAL_STORE_COL_COMPACT);
1836 gtk_tree_view_column_add_attribute (col, cell,
1837 "client-types", EMPATHY_INDIVIDUAL_STORE_COL_CLIENT_TYPES);
1839 /* Audio Call Icon */
1840 cell = empathy_cell_renderer_activatable_new ();
1841 gtk_tree_view_column_pack_start (col, cell, FALSE);
1842 gtk_tree_view_column_set_cell_data_func (col, cell,
1843 (GtkTreeCellDataFunc) individual_view_audio_call_cell_data_func,
1846 g_object_set (cell, "visible", FALSE, NULL);
1848 g_signal_connect (cell, "path-activated",
1849 G_CALLBACK (individual_view_call_activated_cb), view);
1852 cell = gtk_cell_renderer_pixbuf_new ();
1853 gtk_tree_view_column_pack_start (col, cell, FALSE);
1854 gtk_tree_view_column_set_cell_data_func (col, cell,
1855 (GtkTreeCellDataFunc) individual_view_avatar_cell_data_func,
1867 cell = empathy_cell_renderer_expander_new ();
1868 gtk_tree_view_column_pack_end (col, cell, FALSE);
1869 gtk_tree_view_column_set_cell_data_func (col, cell,
1870 (GtkTreeCellDataFunc) individual_view_expander_cell_data_func,
1873 /* Actually add the column now we have added all cell renderers */
1874 gtk_tree_view_append_column (GTK_TREE_VIEW (view), col);
1877 for (i = 0; i < G_N_ELEMENTS (drag_types_dest); ++i)
1879 drag_atoms_dest[i] = gdk_atom_intern (drag_types_dest[i].target, FALSE);
1882 for (i = 0; i < G_N_ELEMENTS (drag_types_source); ++i)
1884 drag_atoms_source[i] = gdk_atom_intern (drag_types_source[i].target,
1890 individual_view_set_view_features (EmpathyIndividualView *view,
1891 EmpathyIndividualFeatureFlags features)
1893 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1894 gboolean has_tooltip;
1896 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view));
1898 priv->view_features = features;
1900 /* Setting reorderable is a hack that gets us row previews as drag icons
1901 for free. We override all the drag handlers. It's tricky to get the
1902 position of the drag icon right in drag_begin. GtkTreeView has special
1903 voodoo for it, so we let it do the voodoo that he do (but only if dragging
1906 gtk_tree_view_set_reorderable (GTK_TREE_VIEW (view),
1907 (features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DRAG));
1909 /* Update DnD source/dest */
1910 if (features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DRAG)
1912 gtk_drag_source_set (GTK_WIDGET (view),
1915 G_N_ELEMENTS (drag_types_source),
1916 GDK_ACTION_MOVE | GDK_ACTION_COPY);
1920 gtk_drag_source_unset (GTK_WIDGET (view));
1924 if (features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_DROP)
1926 gtk_drag_dest_set (GTK_WIDGET (view),
1927 GTK_DEST_DEFAULT_ALL,
1929 G_N_ELEMENTS (drag_types_dest), GDK_ACTION_MOVE | GDK_ACTION_COPY);
1933 /* FIXME: URI could still be droped depending on FT feature */
1934 gtk_drag_dest_unset (GTK_WIDGET (view));
1937 /* Update has-tooltip */
1939 (features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_TOOLTIP) != 0;
1940 gtk_widget_set_has_tooltip (GTK_WIDGET (view), has_tooltip);
1944 individual_view_dispose (GObject *object)
1946 EmpathyIndividualView *view = EMPATHY_INDIVIDUAL_VIEW (object);
1947 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
1949 tp_clear_object (&priv->store);
1950 tp_clear_object (&priv->filter);
1951 tp_clear_pointer (&priv->tooltip_widget, gtk_widget_destroy);
1953 empathy_individual_view_set_live_search (view, NULL);
1955 G_OBJECT_CLASS (empathy_individual_view_parent_class)->dispose (object);
1959 individual_view_finalize (GObject *object)
1961 EmpathyIndividualViewPriv *priv = GET_PRIV (object);
1963 if (priv->expand_groups_idle_handler != 0)
1964 g_source_remove (priv->expand_groups_idle_handler);
1965 g_hash_table_destroy (priv->expand_groups);
1967 G_OBJECT_CLASS (empathy_individual_view_parent_class)->finalize (object);
1971 individual_view_get_property (GObject *object,
1976 EmpathyIndividualViewPriv *priv;
1978 priv = GET_PRIV (object);
1983 g_value_set_object (value, priv->store);
1985 case PROP_VIEW_FEATURES:
1986 g_value_set_flags (value, priv->view_features);
1988 case PROP_INDIVIDUAL_FEATURES:
1989 g_value_set_flags (value, priv->individual_features);
1991 case PROP_SHOW_OFFLINE:
1992 g_value_set_boolean (value, priv->show_offline);
1994 case PROP_SHOW_UNTRUSTED:
1995 g_value_set_boolean (value, priv->show_untrusted);
1998 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
2004 individual_view_set_property (GObject *object,
2006 const GValue *value,
2009 EmpathyIndividualView *view = EMPATHY_INDIVIDUAL_VIEW (object);
2010 EmpathyIndividualViewPriv *priv = GET_PRIV (object);
2015 empathy_individual_view_set_store (view, g_value_get_object (value));
2017 case PROP_VIEW_FEATURES:
2018 individual_view_set_view_features (view, g_value_get_flags (value));
2020 case PROP_INDIVIDUAL_FEATURES:
2021 priv->individual_features = g_value_get_flags (value);
2023 case PROP_SHOW_OFFLINE:
2024 empathy_individual_view_set_show_offline (view,
2025 g_value_get_boolean (value));
2027 case PROP_SHOW_UNTRUSTED:
2028 empathy_individual_view_set_show_untrusted (view,
2029 g_value_get_boolean (value));
2032 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
2038 empathy_individual_view_class_init (EmpathyIndividualViewClass *klass)
2040 GObjectClass *object_class = G_OBJECT_CLASS (klass);
2041 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
2042 GtkTreeViewClass *tree_view_class = GTK_TREE_VIEW_CLASS (klass);
2044 object_class->constructed = individual_view_constructed;
2045 object_class->dispose = individual_view_dispose;
2046 object_class->finalize = individual_view_finalize;
2047 object_class->get_property = individual_view_get_property;
2048 object_class->set_property = individual_view_set_property;
2050 widget_class->drag_data_received = individual_view_drag_data_received;
2051 widget_class->drag_drop = individual_view_drag_drop;
2052 widget_class->drag_begin = individual_view_drag_begin;
2053 widget_class->drag_data_get = individual_view_drag_data_get;
2054 widget_class->drag_end = individual_view_drag_end;
2055 widget_class->drag_motion = individual_view_drag_motion;
2057 /* We use the class method to let user of this widget to connect to
2058 * the signal and stop emission of the signal so the default handler
2059 * won't be called. */
2060 tree_view_class->row_activated = individual_view_row_activated;
2062 klass->drag_individual_received = real_drag_individual_received_cb;
2064 signals[DRAG_INDIVIDUAL_RECEIVED] =
2065 g_signal_new ("drag-individual-received",
2066 G_OBJECT_CLASS_TYPE (klass),
2068 G_STRUCT_OFFSET (EmpathyIndividualViewClass, drag_individual_received),
2070 _empathy_gtk_marshal_VOID__UINT_OBJECT_STRING_STRING,
2071 G_TYPE_NONE, 4, G_TYPE_UINT, FOLKS_TYPE_INDIVIDUAL,
2072 G_TYPE_STRING, G_TYPE_STRING);
2074 signals[DRAG_PERSONA_RECEIVED] =
2075 g_signal_new ("drag-persona-received",
2076 G_OBJECT_CLASS_TYPE (klass),
2078 G_STRUCT_OFFSET (EmpathyIndividualViewClass, drag_persona_received),
2080 _empathy_gtk_marshal_BOOLEAN__UINT_OBJECT_OBJECT,
2081 G_TYPE_BOOLEAN, 3, G_TYPE_UINT, FOLKS_TYPE_PERSONA, FOLKS_TYPE_INDIVIDUAL);
2083 g_object_class_install_property (object_class,
2085 g_param_spec_object ("store",
2086 "The store of the view",
2087 "The store of the view",
2088 EMPATHY_TYPE_INDIVIDUAL_STORE,
2089 G_PARAM_READWRITE));
2090 g_object_class_install_property (object_class,
2092 g_param_spec_flags ("view-features",
2093 "Features of the view",
2094 "Flags for all enabled features",
2095 EMPATHY_TYPE_INDIVIDUAL_VIEW_FEATURE_FLAGS,
2096 EMPATHY_INDIVIDUAL_VIEW_FEATURE_NONE, G_PARAM_READWRITE));
2097 g_object_class_install_property (object_class,
2098 PROP_INDIVIDUAL_FEATURES,
2099 g_param_spec_flags ("individual-features",
2100 "Features of the individual menu",
2101 "Flags for all enabled features for the menu",
2102 EMPATHY_TYPE_INDIVIDUAL_FEATURE_FLAGS,
2103 EMPATHY_INDIVIDUAL_FEATURE_NONE, G_PARAM_READWRITE));
2104 g_object_class_install_property (object_class,
2106 g_param_spec_boolean ("show-offline",
2108 "Whether contact list should display "
2109 "offline contacts", FALSE, G_PARAM_READWRITE));
2110 g_object_class_install_property (object_class,
2111 PROP_SHOW_UNTRUSTED,
2112 g_param_spec_boolean ("show-untrusted",
2113 "Show Untrusted Individuals",
2114 "Whether the view should display untrusted individuals; "
2115 "those who could not be who they say they are.",
2116 TRUE, G_PARAM_READWRITE));
2118 g_type_class_add_private (object_class, sizeof (EmpathyIndividualViewPriv));
2122 empathy_individual_view_init (EmpathyIndividualView *view)
2124 EmpathyIndividualViewPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (view,
2125 EMPATHY_TYPE_INDIVIDUAL_VIEW, EmpathyIndividualViewPriv);
2129 priv->show_untrusted = TRUE;
2131 /* Get saved group states. */
2132 empathy_contact_groups_get_all ();
2134 priv->expand_groups = g_hash_table_new_full (g_str_hash, g_str_equal,
2135 (GDestroyNotify) g_free, NULL);
2137 gtk_tree_view_set_row_separator_func (GTK_TREE_VIEW (view),
2138 empathy_individual_store_row_separator_func, NULL, NULL);
2140 /* Connect to tree view signals rather than override. */
2141 g_signal_connect (view, "button-press-event",
2142 G_CALLBACK (individual_view_button_press_event_cb), NULL);
2143 g_signal_connect (view, "key-press-event",
2144 G_CALLBACK (individual_view_key_press_event_cb), NULL);
2145 g_signal_connect (view, "row-expanded",
2146 G_CALLBACK (individual_view_row_expand_or_collapse_cb),
2147 GINT_TO_POINTER (TRUE));
2148 g_signal_connect (view, "row-collapsed",
2149 G_CALLBACK (individual_view_row_expand_or_collapse_cb),
2150 GINT_TO_POINTER (FALSE));
2151 g_signal_connect (view, "query-tooltip",
2152 G_CALLBACK (individual_view_query_tooltip_cb), NULL);
2155 EmpathyIndividualView *
2156 empathy_individual_view_new (EmpathyIndividualStore *store,
2157 EmpathyIndividualViewFeatureFlags view_features,
2158 EmpathyIndividualFeatureFlags individual_features)
2160 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_STORE (store), NULL);
2162 return g_object_new (EMPATHY_TYPE_INDIVIDUAL_VIEW,
2164 "individual-features", individual_features,
2165 "view-features", view_features, NULL);
2169 empathy_individual_view_dup_selected (EmpathyIndividualView *view)
2171 EmpathyIndividualViewPriv *priv;
2172 GtkTreeSelection *selection;
2174 GtkTreeModel *model;
2175 FolksIndividual *individual;
2177 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view), NULL);
2179 priv = GET_PRIV (view);
2181 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
2182 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
2185 gtk_tree_model_get (model, &iter,
2186 EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, -1);
2192 empathy_individual_view_dup_selected_group (EmpathyIndividualView *view,
2193 gboolean *is_fake_group)
2195 EmpathyIndividualViewPriv *priv;
2196 GtkTreeSelection *selection;
2198 GtkTreeModel *model;
2203 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view), NULL);
2205 priv = GET_PRIV (view);
2207 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
2208 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
2211 gtk_tree_model_get (model, &iter,
2212 EMPATHY_INDIVIDUAL_STORE_COL_IS_GROUP, &is_group,
2213 EMPATHY_INDIVIDUAL_STORE_COL_NAME, &name,
2214 EMPATHY_INDIVIDUAL_STORE_COL_IS_FAKE_GROUP, &fake, -1);
2222 if (is_fake_group != NULL)
2223 *is_fake_group = fake;
2229 individual_view_remove_dialog_show (GtkWindow *parent,
2230 const gchar *message,
2231 const gchar *secondary_text)
2236 dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
2237 GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE, "%s", message);
2238 gtk_dialog_add_buttons (GTK_DIALOG (dialog),
2239 GTK_STOCK_CANCEL, GTK_RESPONSE_NO,
2240 GTK_STOCK_DELETE, GTK_RESPONSE_YES, NULL);
2241 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
2242 "%s", secondary_text);
2244 gtk_widget_show (dialog);
2246 res = gtk_dialog_run (GTK_DIALOG (dialog));
2247 gtk_widget_destroy (dialog);
2249 return (res == GTK_RESPONSE_YES);
2253 individual_view_group_remove_activate_cb (GtkMenuItem *menuitem,
2254 EmpathyIndividualView *view)
2258 group = empathy_individual_view_dup_selected_group (view, NULL);
2265 g_strdup_printf (_("Do you really want to remove the group '%s'?"),
2267 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
2268 if (individual_view_remove_dialog_show (parent, _("Removing group"),
2271 EmpathyIndividualManager *manager =
2272 empathy_individual_manager_dup_singleton ();
2273 empathy_individual_manager_remove_group (manager, group);
2274 g_object_unref (G_OBJECT (manager));
2284 empathy_individual_view_get_group_menu (EmpathyIndividualView *view)
2286 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
2291 gboolean is_fake_group;
2293 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view), NULL);
2295 if (!(priv->view_features & (EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_RENAME |
2296 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_REMOVE)))
2299 group = empathy_individual_view_dup_selected_group (view, &is_fake_group);
2300 if (!group || is_fake_group)
2302 /* We can't alter fake groups */
2307 menu = gtk_menu_new ();
2310 if (priv->view_features &
2311 EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_RENAME) {
2312 item = gtk_menu_item_new_with_mnemonic (_("Re_name"));
2313 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2314 gtk_widget_show (item);
2315 g_signal_connect (item, "activate",
2316 G_CALLBACK (individual_view_group_rename_activate_cb),
2321 if (priv->view_features & EMPATHY_INDIVIDUAL_VIEW_FEATURE_GROUPS_REMOVE)
2323 item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
2324 image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
2325 GTK_ICON_SIZE_MENU);
2326 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
2327 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2328 gtk_widget_show (item);
2329 g_signal_connect (item, "activate",
2330 G_CALLBACK (individual_view_group_remove_activate_cb), view);
2339 individual_view_remove_activate_cb (GtkMenuItem *menuitem,
2340 EmpathyIndividualView *view)
2342 FolksIndividual *individual;
2344 individual = empathy_individual_view_dup_selected (view);
2346 if (individual != NULL)
2351 parent = empathy_get_toplevel_window (GTK_WIDGET (view));
2354 ("Do you really want to remove the contact '%s'?"),
2355 folks_aliasable_get_alias (FOLKS_ALIASABLE (individual)));
2356 if (individual_view_remove_dialog_show (parent, _("Removing contact"),
2359 EmpathyIndividualManager *manager;
2361 manager = empathy_individual_manager_dup_singleton ();
2362 empathy_individual_manager_remove (manager, individual, "");
2363 g_object_unref (G_OBJECT (manager));
2367 g_object_unref (individual);
2372 individual_menu_link_contacts_activated_cb (EmpathyIndividualMenu *menu,
2373 EmpathyLinkingDialog *linking_dialog,
2374 EmpathyIndividualView *self)
2376 EmpathyIndividualViewPriv *priv = GET_PRIV (self);
2377 EmpathyIndividualLinker *linker;
2379 linker = empathy_linking_dialog_get_individual_linker (linking_dialog);
2380 empathy_individual_linker_set_search_text (linker,
2381 empathy_live_search_get_text (EMPATHY_LIVE_SEARCH (priv->search_widget)));
2385 empathy_individual_view_get_individual_menu (EmpathyIndividualView *view)
2387 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
2388 FolksIndividual *individual;
2389 GtkWidget *menu = NULL;
2392 gboolean can_remove = FALSE;
2395 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (view), NULL);
2397 individual = empathy_individual_view_dup_selected (view);
2398 if (individual == NULL)
2401 /* If any of the Individual's personas can be removed, add an option to
2402 * remove. This will act as a best-effort option. If any Personas cannot be
2403 * removed from the server, then this option will just be inactive upon
2404 * subsequent menu openings */
2405 for (l = folks_individual_get_personas (individual); l != NULL; l = l->next)
2407 FolksPersona *persona = FOLKS_PERSONA (l->data);
2408 FolksPersonaStore *store = folks_persona_get_store (persona);
2409 FolksMaybeBool maybe_can_remove =
2410 folks_persona_store_get_can_remove_personas (store);
2412 if (maybe_can_remove == FOLKS_MAYBE_BOOL_TRUE)
2419 menu = empathy_individual_menu_new (individual, priv->individual_features);
2421 /* Remove contact */
2422 if ((priv->view_features &
2423 EMPATHY_INDIVIDUAL_VIEW_FEATURE_INDIVIDUAL_REMOVE) &&
2426 /* create the menu if required, or just add a separator */
2428 menu = gtk_menu_new ();
2431 item = gtk_separator_menu_item_new ();
2432 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2433 gtk_widget_show (item);
2437 item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
2438 image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
2439 GTK_ICON_SIZE_MENU);
2440 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
2441 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
2442 gtk_widget_show (item);
2443 g_signal_connect (item, "activate",
2444 G_CALLBACK (individual_view_remove_activate_cb), view);
2447 /* Connect to EmpathyIndividualMenu::link-contacts-activated so that we can
2448 * set the live search text on the new linking dialogue to be the same as
2450 g_signal_connect (menu, "link-contacts-activated",
2451 (GCallback) individual_menu_link_contacts_activated_cb, view);
2453 g_object_unref (individual);
2459 empathy_individual_view_set_live_search (EmpathyIndividualView *view,
2460 EmpathyLiveSearch *search)
2462 EmpathyIndividualViewPriv *priv = GET_PRIV (view);
2464 /* remove old handlers if old search was not null */
2465 if (priv->search_widget != NULL)
2467 g_signal_handlers_disconnect_by_func (view,
2468 individual_view_start_search_cb, NULL);
2470 g_signal_handlers_disconnect_by_func (priv->search_widget,
2471 individual_view_search_text_notify_cb, view);
2472 g_signal_handlers_disconnect_by_func (priv->search_widget,
2473 individual_view_search_activate_cb, view);
2474 g_signal_handlers_disconnect_by_func (priv->search_widget,
2475 individual_view_search_key_navigation_cb, view);
2476 g_signal_handlers_disconnect_by_func (priv->search_widget,
2477 individual_view_search_hide_cb, view);
2478 g_signal_handlers_disconnect_by_func (priv->search_widget,
2479 individual_view_search_show_cb, view);
2480 g_object_unref (priv->search_widget);
2481 priv->search_widget = NULL;
2484 /* connect handlers if new search is not null */
2487 priv->search_widget = g_object_ref (search);
2489 g_signal_connect (view, "start-interactive-search",
2490 G_CALLBACK (individual_view_start_search_cb), NULL);
2492 g_signal_connect (priv->search_widget, "notify::text",
2493 G_CALLBACK (individual_view_search_text_notify_cb), view);
2494 g_signal_connect (priv->search_widget, "activate",
2495 G_CALLBACK (individual_view_search_activate_cb), view);
2496 g_signal_connect (priv->search_widget, "key-navigation",
2497 G_CALLBACK (individual_view_search_key_navigation_cb), view);
2498 g_signal_connect (priv->search_widget, "hide",
2499 G_CALLBACK (individual_view_search_hide_cb), view);
2500 g_signal_connect (priv->search_widget, "show",
2501 G_CALLBACK (individual_view_search_show_cb), view);
2506 empathy_individual_view_is_searching (EmpathyIndividualView *self)
2508 EmpathyIndividualViewPriv *priv;
2510 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self), FALSE);
2512 priv = GET_PRIV (self);
2514 return (priv->search_widget != NULL &&
2515 gtk_widget_get_visible (priv->search_widget));
2519 empathy_individual_view_get_show_offline (EmpathyIndividualView *self)
2521 EmpathyIndividualViewPriv *priv;
2523 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self), FALSE);
2525 priv = GET_PRIV (self);
2527 return priv->show_offline;
2531 empathy_individual_view_set_show_offline (EmpathyIndividualView *self,
2532 gboolean show_offline)
2534 EmpathyIndividualViewPriv *priv;
2536 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self));
2538 priv = GET_PRIV (self);
2540 priv->show_offline = show_offline;
2542 g_object_notify (G_OBJECT (self), "show-offline");
2543 gtk_tree_model_filter_refilter (priv->filter);
2547 empathy_individual_view_get_show_untrusted (EmpathyIndividualView *self)
2549 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self), FALSE);
2551 return GET_PRIV (self)->show_untrusted;
2555 empathy_individual_view_set_show_untrusted (EmpathyIndividualView *self,
2556 gboolean show_untrusted)
2558 EmpathyIndividualViewPriv *priv;
2560 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self));
2562 priv = GET_PRIV (self);
2564 priv->show_untrusted = show_untrusted;
2566 g_object_notify (G_OBJECT (self), "show-untrusted");
2567 gtk_tree_model_filter_refilter (priv->filter);
2570 EmpathyIndividualStore *
2571 empathy_individual_view_get_store (EmpathyIndividualView *self)
2573 g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self), NULL);
2575 return GET_PRIV (self)->store;
2579 empathy_individual_view_set_store (EmpathyIndividualView *self,
2580 EmpathyIndividualStore *store)
2582 EmpathyIndividualViewPriv *priv;
2584 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self));
2585 g_return_if_fail (store == NULL || EMPATHY_IS_INDIVIDUAL_STORE (store));
2587 priv = GET_PRIV (self);
2589 /* Destroy the old filter and remove the old store */
2590 if (priv->store != NULL)
2592 g_signal_handlers_disconnect_by_func (priv->store,
2593 individual_view_store_row_changed_cb, self);
2594 g_signal_handlers_disconnect_by_func (priv->store,
2595 individual_view_store_row_deleted_cb, self);
2597 g_signal_handlers_disconnect_by_func (priv->filter,
2598 individual_view_row_has_child_toggled_cb, self);
2600 gtk_tree_view_set_model (GTK_TREE_VIEW (self), NULL);
2603 tp_clear_object (&priv->filter);
2604 tp_clear_object (&priv->store);
2606 /* Set the new store */
2607 priv->store = store;
2611 g_object_ref (store);
2613 /* Create a new filter */
2614 priv->filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (
2615 GTK_TREE_MODEL (priv->store), NULL));
2616 gtk_tree_model_filter_set_visible_func (priv->filter,
2617 individual_view_filter_visible_func, self, NULL);
2619 g_signal_connect (priv->filter, "row-has-child-toggled",
2620 G_CALLBACK (individual_view_row_has_child_toggled_cb), self);
2621 gtk_tree_view_set_model (GTK_TREE_VIEW (self),
2622 GTK_TREE_MODEL (priv->filter));
2624 tp_g_signal_connect_object (priv->store, "row-changed",
2625 G_CALLBACK (individual_view_store_row_changed_cb), self, 0);
2626 tp_g_signal_connect_object (priv->store, "row-inserted",
2627 G_CALLBACK (individual_view_store_row_changed_cb), self, 0);
2628 tp_g_signal_connect_object (priv->store, "row-deleted",
2629 G_CALLBACK (individual_view_store_row_deleted_cb), self, 0);
2634 empathy_individual_view_start_search (EmpathyIndividualView *self)
2636 EmpathyIndividualViewPriv *priv = GET_PRIV (self);
2638 g_return_if_fail (EMPATHY_IS_INDIVIDUAL_VIEW (self));
2639 g_return_if_fail (priv->search_widget != NULL);
2641 if (gtk_widget_get_visible (GTK_WIDGET (priv->search_widget)))
2642 gtk_widget_grab_focus (GTK_WIDGET (priv->search_widget));
2644 gtk_widget_show (GTK_WIDGET (priv->search_widget));