empathy r1131 - trunk/libempathy-gtk



Author: xclaesse
Date: Fri May 30 11:58:02 2008
New Revision: 1131
URL: http://svn.gnome.org/viewvc/empathy?rev=1131&view=rev

Log:
Set a tooltip on contact list view showing EmpathyContactWidget information


Modified:
   trunk/libempathy-gtk/empathy-contact-list-view.c
   trunk/libempathy-gtk/empathy-contact-list-view.h

Modified: trunk/libempathy-gtk/empathy-contact-list-view.c
==============================================================================
--- trunk/libempathy-gtk/empathy-contact-list-view.c	(original)
+++ trunk/libempathy-gtk/empathy-contact-list-view.c	Fri May 30 11:58:02 2008
@@ -66,6 +66,7 @@
 	GtkTreeRowReference            *drag_row;
 	EmpathyContactListFeatureFlags  list_features;
 	EmpathyContactFeatureFlags      contact_features;
+	GtkWidget                      *tooltip_widget;
 } EmpathyContactListViewPriv;
 
 typedef struct {
@@ -117,6 +118,67 @@
 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,
 				      gint               x,
@@ -900,6 +962,10 @@
 		/* 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 @@
 		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 @@
 					      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 *

Modified: trunk/libempathy-gtk/empathy-contact-list-view.h
==============================================================================
--- trunk/libempathy-gtk/empathy-contact-list-view.h	(original)
+++ trunk/libempathy-gtk/empathy-contact-list-view.h	Fri May 30 11:58:02 2008
@@ -53,7 +53,8 @@
 	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 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]