diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-01 21:00:35 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-06-14 15:21:49 +0800 |
commit | a96c2a5c0ac5133ab8b7a14fab0f2857cead162d (patch) | |
tree | 95c9305295e9461b5575e8576a395072855dfc54 | |
parent | 785ce2292d3b61afd25099fd87eb3b7fbf4f4270 (diff) | |
download | gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.tar gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.tar.gz gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.tar.bz2 gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.tar.lz gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.tar.xz gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.tar.zst gsoc2013-empathy-a96c2a5c0ac5133ab8b7a14fab0f2857cead162d.zip |
Add popup-individual-menu signal
-rw-r--r-- | libempathy-gtk/empathy-roster-view.c | 73 | ||||
-rw-r--r-- | tests/interactive/test-empathy-roster-view.c | 30 |
2 files changed, 103 insertions, 0 deletions
diff --git a/libempathy-gtk/empathy-roster-view.c b/libempathy-gtk/empathy-roster-view.c index dadc044c8..28aac164c 100644 --- a/libempathy-gtk/empathy-roster-view.c +++ b/libempathy-gtk/empathy-roster-view.c @@ -21,6 +21,7 @@ enum enum { SIG_INDIVIDUAL_ACTIVATED, + SIG_POPUP_INDIVIDUAL_MENU, LAST_SIGNAL }; @@ -815,11 +816,73 @@ empathy_roster_view_child_activated (EggListBox *box, } static void +fire_popup_individual_menu (EmpathyRosterView *self, + GtkWidget *child, + guint button, + guint time) +{ + EmpathyRosterContact *contact; + FolksIndividual *individual; + + if (!EMPATHY_IS_ROSTER_CONTACT (child)) + return; + + contact = EMPATHY_ROSTER_CONTACT (child); + individual = empathy_roster_contact_get_individual (contact); + + g_signal_emit (self, signals[SIG_POPUP_INDIVIDUAL_MENU], 0, + individual, button, time); +} + +static gboolean +empathy_roster_view_button_press_event (GtkWidget *widget, + GdkEventButton *event) +{ + EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget); + gboolean (*chain_up) (GtkWidget *, GdkEventButton *) = + ((GtkWidgetClass *) empathy_roster_view_parent_class)->button_press_event; + + if (event->button == 3) + { + GtkWidget *child; + + child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), event->y); + + if (child != NULL) + fire_popup_individual_menu (self, child, event->button, event->time); + } + + return chain_up (widget, event); +} + +static gboolean +empathy_roster_view_key_press_event (GtkWidget *widget, + GdkEventKey *event) +{ + EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget); + gboolean (*chain_up) (GtkWidget *, GdkEventKey *) = + ((GtkWidgetClass *) empathy_roster_view_parent_class)->key_press_event; + + if (event->keyval == GDK_KEY_Menu) + { + GtkWidget *child; + + child = egg_list_box_get_selected_child (EGG_LIST_BOX (self)); + + if (child != NULL) + fire_popup_individual_menu (self, child, 0, event->time); + } + + return chain_up (widget, event); +} + +static void empathy_roster_view_class_init ( EmpathyRosterViewClass *klass) { GObjectClass *oclass = G_OBJECT_CLASS (klass); EggListBoxClass *box_class = EGG_LIST_BOX_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GParamSpec *spec; oclass->get_property = empathy_roster_view_get_property; @@ -828,6 +891,9 @@ empathy_roster_view_class_init ( oclass->dispose = empathy_roster_view_dispose; oclass->finalize = empathy_roster_view_finalize; + widget_class->button_press_event = empathy_roster_view_button_press_event; + widget_class->key_press_event = empathy_roster_view_key_press_event; + box_class->child_activated = empathy_roster_view_child_activated; spec = g_param_spec_object ("manager", "Manager", @@ -855,6 +921,13 @@ empathy_roster_view_class_init ( G_TYPE_NONE, 1, FOLKS_TYPE_INDIVIDUAL); + signals[SIG_POPUP_INDIVIDUAL_MENU] = g_signal_new ("popup-individual-menu", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, NULL, + G_TYPE_NONE, + 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT, G_TYPE_UINT); + g_type_class_add_private (klass, sizeof (EmpathyRosterViewPriv)); } diff --git a/tests/interactive/test-empathy-roster-view.c b/tests/interactive/test-empathy-roster-view.c index fd9457d53..c76f670c8 100644 --- a/tests/interactive/test-empathy-roster-view.c +++ b/tests/interactive/test-empathy-roster-view.c @@ -24,6 +24,34 @@ individual_activated_cb (EmpathyRosterView *self, folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual))); } +static void +popup_individual_menu_cb (EmpathyRosterView *self, + FolksIndividual *individual, + guint button, + guint time, + gpointer user_data) +{ + GtkWidget *menu, *item; + + g_print ("'%s' popup menu\n", + folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (individual))); + + menu = gtk_menu_new (); + + g_signal_connect (menu, "deactivate", + G_CALLBACK (gtk_widget_destroy), NULL); + + item = gtk_menu_item_new_with_label (folks_alias_details_get_alias ( + FOLKS_ALIAS_DETAILS (individual))); + gtk_widget_show (item); + + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + + gtk_menu_attach_to_widget (GTK_MENU (menu), GTK_WIDGET (self), NULL); + + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, button, time); +} + int main (int argc, char **argv) @@ -57,6 +85,8 @@ main (int argc, g_signal_connect (view, "individual-activated", G_CALLBACK (individual_activated_cb), NULL); + g_signal_connect (view, "popup-individual-menu", + G_CALLBACK (popup_individual_menu_cb), NULL); empathy_roster_view_show_offline (EMPATHY_ROSTER_VIEW (view), show_offline); empathy_roster_view_show_groups (EMPATHY_ROSTER_VIEW (view), show_groups); |