]> git.0d.be Git - empathy.git/commitdiff
Set a tooltip on contact list view showing EmpathyContactWidget information
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 30 May 2008 11:58:02 +0000 (11:58 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 30 May 2008 11:58:02 +0000 (11:58 +0000)
svn path=/trunk/; revision=1131

libempathy-gtk/empathy-contact-list-view.c
libempathy-gtk/empathy-contact-list-view.h

index 58ae7711f458900fa28e67a7cde5f5a4baf346a3..3443950de52a503a4ff16e7fc0ff57a80dc68a27 100644 (file)
@@ -66,6 +66,7 @@ typedef struct {
        GtkTreeRowReference            *drag_row;
        EmpathyContactListFeatureFlags  list_features;
        EmpathyContactFeatureFlags      contact_features;
+       GtkWidget                      *tooltip_widget;
 } EmpathyContactListViewPriv;
 
 typedef struct {
@@ -116,6 +117,67 @@ static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE (EmpathyContactListView, empathy_contact_list_view, GTK_TYPE_TREE_VIEW);
 
+static void
+contact_list_view_tooltip_destroy_cb (GtkWidget              *widget,
+                                     EmpathyContactListView *view)
+{
+       EmpathyContactListViewPriv *priv = GET_PRIV (view);
+
+       DEBUG ("Tooltip destroyed");
+       if (priv->tooltip_widget) {
+               g_object_unref (priv->tooltip_widget);
+               priv->tooltip_widget = NULL;
+       }
+}
+
+static gboolean
+contact_list_view_query_tooltip_cb (EmpathyContactListView *view,
+                                   gint                    x,
+                                   gint                    y,
+                                   gboolean                keyboard_mode,
+                                   GtkTooltip             *tooltip,
+                                   gpointer                user_data)
+{
+       EmpathyContactListViewPriv *priv = GET_PRIV (view);
+       EmpathyContact             *contact;
+       GtkTreeModel               *model;
+       GtkTreeIter                 iter;
+       GtkTreePath                *path;
+
+       if (!gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (view), &x, &y,
+                                               keyboard_mode,
+                                               &model, &path, &iter)) {
+               return FALSE;
+       }
+
+       gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (view), tooltip, path);
+       gtk_tree_path_free (path);
+
+       gtk_tree_model_get (model, &iter,
+                           EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
+                           -1);
+       if (!contact) {
+               return FALSE;
+       }
+
+       if (!priv->tooltip_widget) {
+               priv->tooltip_widget = empathy_contact_widget_new (contact,
+                                               EMPATHY_CONTACT_WIDGET_EDIT_NONE);
+               g_object_ref (priv->tooltip_widget);
+               g_signal_connect (priv->tooltip_widget, "destroy",
+                                 G_CALLBACK (contact_list_view_tooltip_destroy_cb),
+                                 view);
+
+       } else {
+               empathy_contact_widget_set_contact (priv->tooltip_widget, contact);
+       }
+       gtk_tooltip_set_custom (tooltip, priv->tooltip_widget);
+
+       g_object_unref (contact);
+
+       return TRUE;
+}
+
 static void
 contact_list_view_drag_data_received (GtkWidget         *widget,
                                      GdkDragContext    *context,
@@ -900,6 +962,10 @@ contact_list_view_set_list_features (EmpathyContactListView         *view,
                /* FIXME: URI could still be  droped depending on FT feature */
                gtk_drag_dest_unset (GTK_WIDGET (view));
        }
+
+       /* Update has-tooltip */
+       gtk_widget_set_has_tooltip (GTK_WIDGET (view),
+                                   features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_TOOLTIP);
 }
 
 static void
@@ -913,6 +979,10 @@ contact_list_view_finalize (GObject *object)
                g_object_unref (priv->store);
        }
 
+       if (priv->tooltip_widget) {
+               g_object_unref (priv->tooltip_widget);
+       }
+
        G_OBJECT_CLASS (empathy_contact_list_view_parent_class)->finalize (object);
 }
 
@@ -1041,26 +1111,24 @@ empathy_contact_list_view_init (EmpathyContactListView *view)
                                              NULL, NULL);
 
        /* Connect to tree view signals rather than override. */
-       g_signal_connect (view,
-                         "button-press-event",
+       g_signal_connect (view, "button-press-event",
                          G_CALLBACK (contact_list_view_button_press_event_cb),
                          NULL);
-       g_signal_connect (view,
-                         "key-press-event",
+       g_signal_connect (view, "key-press-event",
                          G_CALLBACK (contact_list_view_key_press_event_cb),
                          NULL);
-       g_signal_connect (view,
-                         "row-activated",
+       g_signal_connect (view, "row-activated",
                          G_CALLBACK (contact_list_view_row_activated_cb),
                          NULL);
-       g_signal_connect (view,
-                         "row-expanded",
+       g_signal_connect (view, "row-expanded",
                          G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
                          GINT_TO_POINTER (TRUE));
-       g_signal_connect (view,
-                         "row-collapsed",
+       g_signal_connect (view, "row-collapsed",
                          G_CALLBACK (contact_list_view_row_expand_or_collapse_cb),
                          GINT_TO_POINTER (FALSE));
+       g_signal_connect (view, "query-tooltip",
+                         G_CALLBACK (contact_list_view_query_tooltip_cb),
+                         NULL);
 }
 
 EmpathyContactListView *
index 39dc5966b0e6838b81e5a9e39f5b1a7ab4446009..82990d64f5e9b19c050b3acef7154c6d17c4acd6 100644 (file)
@@ -53,7 +53,8 @@ typedef enum {
        EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE = 1 << 3,
        EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP = 1 << 4,
        EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG = 1 << 5,
-       EMPATHY_CONTACT_LIST_FEATURE_ALL = (1 << 6) - 1,
+       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_TOOLTIP = 1 << 6,
+       EMPATHY_CONTACT_LIST_FEATURE_ALL = (1 << 7) - 1,
 } EmpathyContactListFeatureFlags;
 
 struct _EmpathyContactListView {