]> git.0d.be Git - empathy.git/commitdiff
add API for individual tooltips
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Mon, 4 Jun 2012 12:57:03 +0000 (14:57 +0200)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 14 Jun 2012 07:21:49 +0000 (09:21 +0200)
libempathy-gtk/empathy-roster-view.c
libempathy-gtk/empathy-roster-view.h
tests/interactive/test-empathy-roster-view.c

index 28aac164cc827eed220c8c62191d6f819a9a17df..3803c8b174588cd6e8fd732b82c218167ced0c6f 100644 (file)
@@ -50,6 +50,9 @@ struct _EmpathyRosterViewPriv
   gboolean show_groups;
 
   EmpathyLiveSearch *search;
+
+  EmpathyRosterViewIndividualTooltipCb individual_tooltip_cb;
+  gpointer individual_tooltip_data;
 };
 
 static void
@@ -876,6 +879,43 @@ empathy_roster_view_key_press_event (GtkWidget *widget,
   return chain_up (widget, event);
 }
 
+static gboolean
+empathy_roster_view_query_tooltip (GtkWidget *widget,
+    gint x,
+    gint y,
+    gboolean keyboard_mode,
+    GtkTooltip *tooltip)
+{
+  EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
+  GtkWidget *child;
+  EmpathyRosterContact *contact;
+  FolksIndividual *individual;
+
+  if (self->priv->individual_tooltip_cb == NULL)
+    return FALSE;
+
+  child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
+  if (!EMPATHY_IS_ROSTER_CONTACT (child))
+    return FALSE;
+
+  contact = EMPATHY_ROSTER_CONTACT (child);
+  individual = empathy_roster_contact_get_individual (contact);
+
+  return self->priv->individual_tooltip_cb (self, individual, keyboard_mode,
+      tooltip, self->priv->individual_tooltip_data);
+}
+
+void
+empathy_roster_view_set_individual_tooltip_cb (EmpathyRosterView *self,
+    EmpathyRosterViewIndividualTooltipCb callback,
+    gpointer user_data)
+{
+  self->priv->individual_tooltip_cb = callback;
+  self->priv->individual_tooltip_data = user_data;
+
+  gtk_widget_set_has_tooltip (GTK_WIDGET (self), callback != NULL);
+}
+
 static void
 empathy_roster_view_class_init (
     EmpathyRosterViewClass *klass)
@@ -893,6 +933,7 @@ empathy_roster_view_class_init (
 
   widget_class->button_press_event = empathy_roster_view_button_press_event;
   widget_class->key_press_event = empathy_roster_view_key_press_event;
+  widget_class->query_tooltip = empathy_roster_view_query_tooltip;
 
   box_class->child_activated = empathy_roster_view_child_activated;
 
index e5c3a6f40a0051dbc244e7d873a5167793df8ee8..e5160f6a370421e6c2ff0818e66574e5b861eaf3 100644 (file)
@@ -64,6 +64,17 @@ void empathy_roster_view_show_groups (EmpathyRosterView *self,
 void empathy_roster_view_set_live_search (EmpathyRosterView *self,
     EmpathyLiveSearch *search);
 
+typedef gboolean (* EmpathyRosterViewIndividualTooltipCb) (
+    EmpathyRosterView *self,
+    FolksIndividual *individual,
+    gboolean keyboard_mode,
+    GtkTooltip *tooltip,
+    gpointer user_data);
+
+void empathy_roster_view_set_individual_tooltip_cb (EmpathyRosterView *self,
+    EmpathyRosterViewIndividualTooltipCb callback,
+    gpointer user_data);
+
 G_END_DECLS
 
 #endif /* #ifndef __EMPATHY_ROSTER_VIEW_H__*/
index c76f670c80ee0c3d639cb9223a474a86bf373b01..f10aaf2d76f912879d466e67cf8613bbcde39a0c 100644 (file)
@@ -52,6 +52,19 @@ popup_individual_menu_cb (EmpathyRosterView *self,
   gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time);
 }
 
+static gboolean
+individual_tooltip_cb (EmpathyRosterView *view,
+    FolksIndividual *individual,
+    gboolean keyboard_mode,
+    GtkTooltip *tooltip,
+    gpointer user_data)
+{
+  gtk_tooltip_set_text (tooltip,
+      folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual)));
+
+  return TRUE;
+}
+
 int
 main (int argc,
     char **argv)
@@ -91,6 +104,9 @@ main (int argc,
   empathy_roster_view_show_offline (EMPATHY_ROSTER_VIEW (view), show_offline);
   empathy_roster_view_show_groups (EMPATHY_ROSTER_VIEW (view), show_groups);
 
+  empathy_roster_view_set_individual_tooltip_cb (EMPATHY_ROSTER_VIEW (view),
+      individual_tooltip_cb, NULL);
+
   g_object_unref (mgr);
 
   search = empathy_live_search_new (view);