]> git.0d.be Git - empathy.git/commitdiff
Create contact menu in empathy-contact-menu.h
authorXavier Claessens <xclaesse@src.gnome.org>
Fri, 25 Apr 2008 09:33:29 +0000 (09:33 +0000)
committerXavier Claessens <xclaesse@src.gnome.org>
Fri, 25 Apr 2008 09:33:29 +0000 (09:33 +0000)
svn path=/trunk/; revision=1046

libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-contact-list-view.c
libempathy-gtk/empathy-contact-list-view.h
libempathy-gtk/empathy-contact-menu.c
libempathy-gtk/empathy-contact-menu.h
megaphone/src/megaphone-applet.c
python/pyempathy/pyempathy.defs
python/pyempathygtk/pyempathygtk.defs
python/update-binding.sh
src/empathy-main-window.c

index 55282d164bc4c44dd554c7f37896180d5f0ab0e6..22b6f46bb8897dae624dfe521a9182f512251358 100644 (file)
@@ -1203,12 +1203,11 @@ chat_set_show_contacts (EmpathyChat *chat, gboolean show)
 
                store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
                priv->contact_list_view = GTK_WIDGET (empathy_contact_list_view_new (store,
-                       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
-                       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
-                       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
-                       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
-                       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
-                       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO));
+                       EMPATHY_CONTACT_LIST_FEATURE_NONE,
+                       EMPATHY_CONTACT_FEATURE_CHAT |
+                       EMPATHY_CONTACT_FEATURE_CALL |
+                       EMPATHY_CONTACT_FEATURE_LOG |
+                       EMPATHY_CONTACT_FEATURE_INFO));
                gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
                                   priv->contact_list_view);
                gtk_widget_show (priv->contact_list_view);
@@ -1709,39 +1708,16 @@ empathy_chat_get_contact_menu (EmpathyChat *chat)
        g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
 
        if (priv->remote_contact) {
-               GtkMenuShell *shell;
-               GtkWidget    *item;
-
-               menu = gtk_menu_new ();
-               shell = GTK_MENU_SHELL (menu);
-
-               item = empathy_contact_call_menu_item_new (priv->remote_contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-
-               item = empathy_contact_log_menu_item_new (priv->remote_contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-
-               /* Separator */
-               item = gtk_separator_menu_item_new ();
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-
-               item = empathy_contact_info_menu_item_new (priv->remote_contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
+               menu = empathy_contact_menu_new (priv->remote_contact,
+                                                EMPATHY_CONTACT_FEATURE_CALL |
+                                                EMPATHY_CONTACT_FEATURE_LOG |
+                                                EMPATHY_CONTACT_FEATURE_INFO);
        }
        else if (priv->contact_list_view) {
                EmpathyContactListView *view;
-               EmpathyContact         *contact;
 
                view = EMPATHY_CONTACT_LIST_VIEW (priv->contact_list_view);
-               contact = empathy_contact_list_view_get_selected (view);
-               if (contact) {
-                       menu = empathy_contact_list_view_get_contact_menu (view, contact);
-                       g_object_unref (contact);
-               }
+               menu = empathy_contact_list_view_get_contact_menu (view);
        }
 
        return menu;
index b0bfdf909e70ef42cec60a5eacb31e62f8cdcc88..646629bb0be8160d76bc6b1b7a237883fdb3df9f 100644 (file)
@@ -41,7 +41,6 @@
 
 #include "empathy-contact-list-view.h"
 #include "empathy-contact-list-store.h"
-#include "empathy-contact-menu.h"
 #include "empathy-images.h"
 #include "empathy-cell-renderer-expander.h"
 #include "empathy-cell-renderer-text.h"
 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), EMPATHY_TYPE_CONTACT_LIST_VIEW, EmpathyContactListViewPriv))
 
 typedef struct {
-       EmpathyContactListStore    *store;
-       GtkTreeRowReference        *drag_row;
-       EmpathyContactListFeatures  features;
+       EmpathyContactListStore        *store;
+       GtkTreeRowReference            *drag_row;
+       EmpathyContactListFeatureFlags  list_features;
+       EmpathyContactFeatureFlags      contact_features;
 } EmpathyContactListViewPriv;
 
 typedef struct {
@@ -81,7 +81,9 @@ typedef struct {
 
 enum {
        PROP_0,
-       PROP_FEATURES
+       PROP_STORE,
+       PROP_LIST_FEATURES,
+       PROP_CONTACT_FEATURES,
 };
 
 enum DndDragType {
@@ -388,67 +390,55 @@ contact_list_view_drag_drop (GtkWidget      *widget,
        return FALSE;
 }
 
+typedef struct {
+       EmpathyContactListView *view;
+       guint                   button;
+       guint32                 time;
+} MenuPopupData;
+
 static gboolean
-contact_list_view_button_press_event_cb (EmpathyContactListView *view,
-                                        GdkEventButton        *event,
-                                        gpointer               user_data)
+contact_list_view_popup_menu_idle_cb (gpointer user_data)
 {
-       EmpathyContactListViewPriv *priv;
-       EmpathyContact             *contact;
-       GtkTreePath               *path;
-       GtkTreeSelection          *selection;
-       GtkTreeModel              *model;
-       GtkTreeIter                iter;
-       gboolean                   row_exists;
-       GtkWidget                 *menu;
-
-       priv = GET_PRIV (view);
-
-       if (event->button != 3) {
-               return FALSE;
-       }
-
-       selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
-       model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));
-
-       gtk_widget_grab_focus (GTK_WIDGET (view));
-
-       row_exists = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (view),
-                                                   event->x, event->y,
-                                                   &path,
-                                                   NULL, NULL, NULL);
-       if (!row_exists) {
-               return FALSE;
-       }
-
-       gtk_tree_selection_unselect_all (selection);
-       gtk_tree_selection_select_path (selection, path);
-
-       gtk_tree_model_get_iter (model, &iter, path);
-       gtk_tree_path_free (path);
+       MenuPopupData *data = user_data;
+       GtkWidget     *menu;
 
-       gtk_tree_model_get (model, &iter,
-                           EMPATHY_CONTACT_LIST_STORE_COL_CONTACT, &contact,
-                           -1);
-
-       if (contact) {
-               menu = empathy_contact_list_view_get_contact_menu (view, contact);
-               g_object_unref (contact);
-       } else {
-               menu = empathy_contact_list_view_get_group_menu (view);
+       menu = empathy_contact_list_view_get_contact_menu (data->view);
+       if (!menu) {
+               menu = empathy_contact_list_view_get_group_menu (data->view);
        }
 
        if (!menu) {
-               return FALSE;
+               goto OUT;
        }
 
        gtk_widget_show (menu);
 
        gtk_menu_popup (GTK_MENU (menu),
                        NULL, NULL, NULL, NULL,
-                       event->button, event->time);
+                       data->button, data->time);
 
-       return TRUE;
+OUT:
+       g_slice_free (MenuPopupData, data);
+
+       return FALSE;
+}
+
+static gboolean
+contact_list_view_button_press_event_cb (EmpathyContactListView *view,
+                                        GdkEventButton         *event,
+                                        gpointer                user_data)
+{
+       if (event->button == 3) {
+               MenuPopupData *data;
+
+               data = g_slice_new (MenuPopupData);
+               data->view = view;
+               data->button = event->button;
+               data->time = event->time;
+               g_idle_add (contact_list_view_popup_menu_idle_cb, data);
+       }
+
+       return FALSE;
 }
 
 static void
@@ -462,7 +452,7 @@ contact_list_view_row_activated_cb (EmpathyContactListView *view,
        GtkTreeModel               *model;
        GtkTreeIter                 iter;
 
-       if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT)) {
+       if (!(priv->contact_features & EMPATHY_CONTACT_FEATURE_CHAT)) {
                return;
        }
 
@@ -489,7 +479,7 @@ contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
        GtkTreeIter                 iter;
        EmpathyContact             *contact;
 
-       if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL)) {
+       if (!(priv->contact_features & EMPATHY_CONTACT_FEATURE_CALL)) {
                return;
        }
 
@@ -693,7 +683,7 @@ contact_list_view_row_expand_or_collapse_cb (EmpathyContactListView *view,
        gchar                      *name;
        gboolean                    expanded;
 
-       if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE)) {
+       if (!(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE)) {
                return;
        }
 
@@ -729,7 +719,7 @@ contact_list_view_row_has_child_toggled_cb (GtkTreeModel          *model,
                return;
        }
 
-       if (!(priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE) ||
+       if (!(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE) ||
            empathy_contact_group_get_expanded (name)) {
                g_signal_handlers_block_by_func (view,
                                                 contact_list_view_row_expand_or_collapse_cb,
@@ -864,6 +854,40 @@ contact_list_view_setup (EmpathyContactListView *view)
        }
 }
 
+static void
+contact_list_view_set_list_features (EmpathyContactListView         *view,
+                                    EmpathyContactListFeatureFlags  features)
+{
+       EmpathyContactListViewPriv *priv = GET_PRIV (view);
+
+       g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));
+
+       priv->list_features = features;
+
+       /* Update DnD source/dest */
+       if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG) {
+               gtk_drag_source_set (GTK_WIDGET (view),
+                                    GDK_BUTTON1_MASK,
+                                    drag_types_source,
+                                    G_N_ELEMENTS (drag_types_source),
+                                    GDK_ACTION_MOVE | GDK_ACTION_COPY);
+       } else {
+               gtk_drag_source_unset (GTK_WIDGET (view));
+
+       }
+
+       if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP) {
+               gtk_drag_dest_set (GTK_WIDGET (view),
+                                  GTK_DEST_DEFAULT_ALL,
+                                  drag_types_dest,
+                                  G_N_ELEMENTS (drag_types_dest),
+                                  GDK_ACTION_MOVE | GDK_ACTION_COPY);
+       } else {
+               /* FIXME: URI could still be  droped depending on FT feature */
+               gtk_drag_dest_unset (GTK_WIDGET (view));
+       }
+}
+
 static void
 contact_list_view_finalize (GObject *object)
 {
@@ -889,8 +913,14 @@ contact_list_view_get_property (GObject    *object,
        priv = GET_PRIV (object);
 
        switch (param_id) {
-       case PROP_FEATURES:
-               g_value_set_flags (value, priv->features);
+       case PROP_STORE:
+               g_value_set_object (value, priv->store);
+               break;
+       case PROP_LIST_FEATURES:
+               g_value_set_flags (value, priv->list_features);
+               break;
+       case PROP_CONTACT_FEATURES:
+               g_value_set_flags (value, priv->contact_features);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -905,13 +935,18 @@ contact_list_view_set_property (GObject      *object,
                                GParamSpec   *pspec)
 {
        EmpathyContactListView     *view = EMPATHY_CONTACT_LIST_VIEW (object);
-       EmpathyContactListViewPriv *priv;
-
-       priv = GET_PRIV (object);
+       EmpathyContactListViewPriv *priv = GET_PRIV (object);
 
        switch (param_id) {
-       case PROP_FEATURES:
-               empathy_contact_list_view_set_features (view, g_value_get_flags (value));
+       case PROP_STORE:
+               priv->store = g_value_dup_object (value);
+               contact_list_view_setup (view);
+               break;
+       case PROP_LIST_FEATURES:
+               contact_list_view_set_list_features (view, g_value_get_flags (value));
+               break;
+       case PROP_CONTACT_FEATURES:
+               priv->contact_features = g_value_get_flags (value);
                break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
@@ -951,12 +986,27 @@ empathy_contact_list_view_class_init (EmpathyContactListViewClass *klass)
                              3, EMPATHY_TYPE_CONTACT, G_TYPE_STRING, G_TYPE_STRING);
 
        g_object_class_install_property (object_class,
-                                        PROP_FEATURES,
-                                        g_param_spec_flags ("features",
+                                        PROP_STORE,
+                                        g_param_spec_object ("store",
+                                                            "The store of the view",
+                                                            "The store of the view",
+                                                             EMPATHY_TYPE_CONTACT_LIST_STORE,
+                                                             G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_LIST_FEATURES,
+                                        g_param_spec_flags ("list-features",
                                                             "Features of the view",
                                                             "Falgs for all enabled features",
-                                                             EMPATHY_TYPE_CONTACT_LIST_FEATURES,
-                                                             0,
+                                                             EMPATHY_TYPE_CONTACT_LIST_FEATURE_FLAGS,
+                                                             EMPATHY_CONTACT_LIST_FEATURE_NONE,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (object_class,
+                                        PROP_CONTACT_FEATURES,
+                                        g_param_spec_flags ("contact-features",
+                                                            "Features of the contact menu",
+                                                            "Falgs for all enabled features for the menu",
+                                                             EMPATHY_TYPE_CONTACT_FEATURE_FLAGS,
+                                                             EMPATHY_CONTACT_FEATURE_NONE,
                                                              G_PARAM_READWRITE));
 
        g_type_class_add_private (object_class, sizeof (EmpathyContactListViewPriv));
@@ -992,69 +1042,17 @@ empathy_contact_list_view_init (EmpathyContactListView *view)
 }
 
 EmpathyContactListView *
-empathy_contact_list_view_new (EmpathyContactListStore    *store,
-                              EmpathyContactListFeatures  features)
+empathy_contact_list_view_new (EmpathyContactListStore        *store,
+                              EmpathyContactListFeatureFlags  list_features,
+                              EmpathyContactFeatureFlags      contact_features)
 {
-       EmpathyContactListView     *view;
-       EmpathyContactListViewPriv *priv;
-
        g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), NULL);
        
-       view = g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW,
-                           "features", features,
-                           NULL);
-
-       priv = GET_PRIV (view);
-       priv->store = g_object_ref (store);
-       contact_list_view_setup (EMPATHY_CONTACT_LIST_VIEW (view));
-
-       return view;
-}
-
-void
-empathy_contact_list_view_set_features (EmpathyContactListView     *view,
-                                       EmpathyContactListFeatures  features)
-{
-       EmpathyContactListViewPriv *priv = GET_PRIV (view);
-
-       g_return_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view));
-
-       priv->features = features;
-
-       /* Update DnD source/dest */
-       if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG) {
-               gtk_drag_source_set (GTK_WIDGET (view),
-                                    GDK_BUTTON1_MASK,
-                                    drag_types_source,
-                                    G_N_ELEMENTS (drag_types_source),
-                                    GDK_ACTION_MOVE | GDK_ACTION_COPY);
-       } else {
-               gtk_drag_source_unset (GTK_WIDGET (view));
-
-       }
-
-       if (features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP) {
-               gtk_drag_dest_set (GTK_WIDGET (view),
-                                  GTK_DEST_DEFAULT_ALL,
-                                  drag_types_dest,
-                                  G_N_ELEMENTS (drag_types_dest),
-                                  GDK_ACTION_MOVE | GDK_ACTION_COPY);
-       } else {
-               /* FIXME: URI could still be  droped depending on FT feature */
-               gtk_drag_dest_unset (GTK_WIDGET (view));
-       }
-
-       g_object_notify (G_OBJECT (view), "features");
-}
-
-EmpathyContactListFeatures
-empathy_contact_list_view_get_features (EmpathyContactListView  *view)
-{
-       EmpathyContactListViewPriv *priv = GET_PRIV (view);
-
-       g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), FALSE);
-
-       return priv->features;
+       return g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW,
+                            "store", store,
+                            "contact-features", contact_features,
+                            "list-features", list_features,
+                            NULL);
 }
 
 EmpathyContact *
@@ -1180,14 +1178,20 @@ GtkWidget *
 empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
 {
        EmpathyContactListViewPriv *priv = GET_PRIV (view);
+       gchar                      *group;
        GtkWidget                  *menu;
        GtkWidget                  *item;
        GtkWidget                  *image;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
 
-       if (!(priv->features & (EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME |
-                               EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE))) {
+       if (!(priv->list_features & (EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME |
+                                    EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE))) {
+               return NULL;
+       }
+
+       group = empathy_contact_list_view_get_selected_group (view);
+       if (!group) {
                return NULL;
        }
 
@@ -1203,7 +1207,7 @@ empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
                                  view);
        }*/
 
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE) {
+       if (priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE) {
                item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
                image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
                                                      GTK_ICON_SIZE_MENU);
@@ -1215,6 +1219,8 @@ empathy_contact_list_view_get_group_menu (EmpathyContactListView *view)
                                  view);
        }
 
+       g_free (group);
+
        return menu;
 }
 
@@ -1248,89 +1254,53 @@ contact_list_view_remove_activate_cb (GtkMenuItem            *menuitem,
 }
 
 GtkWidget *
-empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view,
-                                           EmpathyContact         *contact)
+empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view)
 {
        EmpathyContactListViewPriv *priv = GET_PRIV (view);
+       EmpathyContact             *contact;
        GtkWidget                  *menu;
-       GtkMenuShell               *shell;
        GtkWidget                  *item;
        GtkWidget                  *image;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
-       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
-
-       if (!(priv->features & (EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO |
-                               EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE))) {
-               return NULL;
-       }
 
-       menu = gtk_menu_new ();
-       shell = GTK_MENU_SHELL (menu);
-
-       /* Main items */
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT) {
-               item = empathy_contact_chat_menu_item_new (contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-       }
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL) {
-               item = empathy_contact_call_menu_item_new (contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-       }
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG) {
-               item = empathy_contact_log_menu_item_new (contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
+       contact = empathy_contact_list_view_get_selected (view);
+       if (!contact) {
+               return NULL;
        }
 
-       /* Separator */
-       if (priv->features & (EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT |
-                             EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO)) {
-               item = gtk_separator_menu_item_new ();
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-       }
+       menu = empathy_contact_menu_new (contact, priv->contact_features);
 
-       /* More items */
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT) {
-               item = empathy_contact_edit_menu_item_new (contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
-       }
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO) {
-               item = empathy_contact_info_menu_item_new (contact);
-               gtk_menu_shell_append (shell, item);
-               gtk_widget_show (item);
+       if (!menu &&
+           !(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE)) {
+               g_object_unref (contact);
+               return NULL;
        }
 
-       /* Separator */
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE) {
+       if (menu) {
+               /* Separator */
                item = gtk_separator_menu_item_new ();
-               gtk_menu_shell_append (shell, item);
+               gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
                gtk_widget_show (item);
+       } else {
+               menu = gtk_menu_new ();
        }
 
-       /* Custom items */
-       if (priv->features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE) {
+       /* Remove contact */
+       if (priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE) {
                item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
                image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
                                                      GTK_ICON_SIZE_MENU);
                gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image);
-               gtk_menu_shell_append (shell, item);
+               gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
                gtk_widget_show (item);
                g_signal_connect (item, "activate",
                                  G_CALLBACK (contact_list_view_remove_activate_cb),
                                  view);
        }
 
+       g_object_unref (contact);
+
        return menu;
 }
 
index 34f194b1487441434af735712f53d95aa30351c1..47159fd24e9703a43c2bed0ba4063edbcda6ec07 100644 (file)
@@ -31,6 +31,7 @@
 #include <libempathy/empathy-contact.h>
 
 #include "empathy-contact-list-store.h"
+#include "empathy-contact-menu.h"
 
 G_BEGIN_DECLS
 
@@ -49,18 +50,11 @@ typedef enum {
        EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE = 1 << 0,
        EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME = 1 << 1,
        EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE = 1 << 2,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT = 1 << 3,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL = 1 << 4,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG = 1 << 5,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT = 1 << 6,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE = 1 << 7,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT = 1 << 8,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO = 1 << 9,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE = 1 << 10,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP = 1 << 11,
-       EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG = 1 << 12,
-       EMPATHY_CONTACT_LIST_FEATURE_ALL = (1 << 13) - 1,
-} EmpathyContactListFeatures;
+       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,
+} EmpathyContactListFeatureFlags;
 
 struct _EmpathyContactListView {
        GtkTreeView            parent;
@@ -71,16 +65,13 @@ struct _EmpathyContactListViewClass {
 };
 
 GType                      empathy_contact_list_view_get_type           (void) G_GNUC_CONST;
-EmpathyContactListView *   empathy_contact_list_view_new                (EmpathyContactListStore    *store,
-                                                                        EmpathyContactListFeatures  features);
-void                       empathy_contact_list_view_set_features       (EmpathyContactListView     *view,
-                                                                        EmpathyContactListFeatures  features);
-EmpathyContactListFeatures empathy_contact_list_view_get_features       (EmpathyContactListView     *view);
-EmpathyContact *           empathy_contact_list_view_get_selected       (EmpathyContactListView     *view);
-gchar *                    empathy_contact_list_view_get_selected_group (EmpathyContactListView     *view);
-GtkWidget *                empathy_contact_list_view_get_contact_menu   (EmpathyContactListView     *view,
-                                                                        EmpathyContact             *contact);
-GtkWidget *                empathy_contact_list_view_get_group_menu     (EmpathyContactListView     *view);
+EmpathyContactListView *   empathy_contact_list_view_new                (EmpathyContactListStore        *store,
+                                                                        EmpathyContactListFeatureFlags  list_features,
+                                                                        EmpathyContactFeatureFlags      contact_features);
+EmpathyContact *           empathy_contact_list_view_get_selected       (EmpathyContactListView         *view);
+gchar *                    empathy_contact_list_view_get_selected_group (EmpathyContactListView         *view);
+GtkWidget *                empathy_contact_list_view_get_contact_menu   (EmpathyContactListView         *view);
+GtkWidget *                empathy_contact_list_view_get_group_menu     (EmpathyContactListView         *view);
 
 G_END_DECLS
 
index 4509dd171b2b6ce4c158ff0660d5081cb0be7e42..b06bcd3e4c9a2faf8460a33c57b24aa3de4d0842 100644 (file)
 
 #define DEBUG_DOMAIN "ContactMenu"
 
+GtkWidget *
+empathy_contact_menu_new (EmpathyContact             *contact,
+                         EmpathyContactFeatureFlags  features)
+{
+       GtkWidget    *menu;
+       GtkMenuShell *shell;
+       GtkWidget    *item;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT (contact), NULL);
+
+       if (features == EMPATHY_CONTACT_FEATURE_NONE) {
+               return NULL;
+       }
+
+       menu = gtk_menu_new ();
+       shell = GTK_MENU_SHELL (menu);
+
+       /* Chat */
+       if (features & EMPATHY_CONTACT_FEATURE_CHAT) {
+               item = empathy_contact_chat_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
+       /* Call */
+       if (features & EMPATHY_CONTACT_FEATURE_CALL) {
+               item = empathy_contact_call_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
+       /* Log */
+       if (features & EMPATHY_CONTACT_FEATURE_LOG) {
+               item = empathy_contact_log_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
+       /* Separator */
+       if (features & (EMPATHY_CONTACT_FEATURE_EDIT |
+                       EMPATHY_CONTACT_FEATURE_INFO)) {
+               item = gtk_separator_menu_item_new ();
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
+       /* Edit */
+       if (features & EMPATHY_CONTACT_FEATURE_EDIT) {
+               item = empathy_contact_edit_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
+       /* Info */
+       if (features & EMPATHY_CONTACT_FEATURE_INFO) {
+               item = empathy_contact_info_menu_item_new (contact);
+               gtk_menu_shell_append (shell, item);
+               gtk_widget_show (item);
+       }
+
+       return menu;
+}
+
 GtkWidget *
 empathy_contact_chat_menu_item_new (EmpathyContact *contact)
 {
index 4b9427b763a643215574f0094b093d9a51fb0baf..dd8d16147e2b3bdba1e5c3ea0d356e11f303a2ca 100644 (file)
 
 G_BEGIN_DECLS
 
-GtkWidget * empathy_contact_chat_menu_item_new (EmpathyContact *contact);
-GtkWidget * empathy_contact_call_menu_item_new (EmpathyContact *contact);
-GtkWidget * empathy_contact_log_menu_item_new  (EmpathyContact *contact);
-GtkWidget * empathy_contact_info_menu_item_new (EmpathyContact *contact);
-GtkWidget * empathy_contact_edit_menu_item_new (EmpathyContact *contact);
+typedef enum {
+       EMPATHY_CONTACT_FEATURE_NONE = 0,
+       EMPATHY_CONTACT_FEATURE_CHAT = 1 << 0,
+       EMPATHY_CONTACT_FEATURE_CALL = 1 << 1,
+       EMPATHY_CONTACT_FEATURE_LOG = 1 << 2,
+       EMPATHY_CONTACT_FEATURE_EDIT = 1 << 3,
+       EMPATHY_CONTACT_FEATURE_INFO = 1 << 4,
+       EMPATHY_CONTACT_FEATURE_ALL = (1 << 5) - 1,
+} EmpathyContactFeatureFlags;
+
+GtkWidget * empathy_contact_menu_new           (EmpathyContact             *contact,
+                                               EmpathyContactFeatureFlags  features);
+GtkWidget * empathy_contact_chat_menu_item_new (EmpathyContact             *contact);
+GtkWidget * empathy_contact_call_menu_item_new (EmpathyContact             *contact);
+GtkWidget * empathy_contact_log_menu_item_new  (EmpathyContact             *contact);
+GtkWidget * empathy_contact_info_menu_item_new (EmpathyContact             *contact);
+GtkWidget * empathy_contact_edit_menu_item_new (EmpathyContact             *contact);
 
 G_END_DECLS
 
index 17ae2c50b508afe6a2ebb9082ab18fe9070d63a7..ad0952891dc7b03695ea6687bdc3808a1ed93d69 100644 (file)
@@ -366,7 +366,8 @@ megaphone_applet_show_preferences (MegaphoneApplet *applet)
                      "sort-criterium", EMPATHY_CONTACT_LIST_STORE_SORT_NAME,
                      NULL);
        contact_list = empathy_contact_list_view_new (contact_store,
-                                                     EMPATHY_CONTACT_LIST_FEATURE_NONE);
+                                                     EMPATHY_CONTACT_LIST_FEATURE_NONE,
+                                                     EMPATHY_CONTACT_FEATURE_NONE);
        g_object_unref (contact_manager);
        g_object_unref (contact_store);
        gtk_widget_show (GTK_WIDGET (contact_list));
index 99e0680675ab88842b9f6101da64fb6732141ab4..a722461c438ffa7e51208a67a8bc8f768161ae71 100644 (file)
   (values
     '("as-is" "EMPATHY_REGEX_AS_IS")
     '("browser" "EMPATHY_REGEX_BROWSER")
+    '("apt" "EMPATHY_REGEX_APT")
     '("email" "EMPATHY_REGEX_EMAIL")
     '("other" "EMPATHY_REGEX_OTHER")
     '("all" "EMPATHY_REGEX_ALL")
   (return-type "McAccount*")
 )
 
+(define-method get_channel
+  (of-object "EmpathyTpChat")
+  (c-name "empathy_tp_chat_get_channel")
+  (return-type "TpChannel*")
+)
+
 (define-method is_ready
   (of-object "EmpathyTpChat")
   (c-name "empathy_tp_chat_is_ready")
index fd3ca2015fb07dfe69c25e423bc1009fdc205f59..604c959cddc1d49a2d4d1053f4d60f264ee0e209 100644 (file)
   )
 )
 
-(define-flags ContactListFeatures
+(define-flags ContactListFeatureFlags
   (in-module "Empathy")
-  (c-name "EmpathyContactListFeatures")
-  (gtype-id "EMPATHY_TYPE_CONTACT_LIST_FEATURES")
+  (c-name "EmpathyContactListFeatureFlags")
+  (gtype-id "EMPATHY_TYPE_CONTACT_LIST_FEATURE_FLAGS")
   (values
     '("none" "EMPATHY_CONTACT_LIST_FEATURE_NONE")
     '("groups-save" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_SAVE")
     '("groups-rename" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_RENAME")
     '("groups-remove" "EMPATHY_CONTACT_LIST_FEATURE_GROUPS_REMOVE")
-    '("contact-chat" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT")
-    '("contact-call" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL")
-    '("contact-log" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG")
-    '("contact-ft" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT")
-    '("contact-invite" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE")
-    '("contact-edit" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_EDIT")
-    '("contact-info" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO")
     '("contact-remove" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE")
     '("contact-drop" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DROP")
     '("contact-drag" "EMPATHY_CONTACT_LIST_FEATURE_CONTACT_DRAG")
   )
 )
 
+(define-flags ContactFeatureFlags
+  (in-module "Empathy")
+  (c-name "EmpathyContactFeatureFlags")
+  (gtype-id "EMPATHY_TYPE_CONTACT_FEATURE_FLAGS")
+  (values
+    '("none" "EMPATHY_CONTACT_FEATURE_NONE")
+    '("chat" "EMPATHY_CONTACT_FEATURE_CHAT")
+    '("call" "EMPATHY_CONTACT_FEATURE_CALL")
+    '("log" "EMPATHY_CONTACT_FEATURE_LOG")
+    '("edit" "EMPATHY_CONTACT_FEATURE_EDIT")
+    '("info" "EMPATHY_CONTACT_FEATURE_INFO")
+    '("all" "EMPATHY_CONTACT_FEATURE_ALL")
+  )
+)
+
 
 ;; From empathy-images.h
 
   (return-type "guint")
 )
 
+(define-method get_contact_menu
+  (of-object "EmpathyChat")
+  (c-name "empathy_chat_get_contact_menu")
+  (return-type "GtkWidget*")
+)
+
 (define-method clear
   (of-object "EmpathyChat")
   (c-name "empathy_chat_clear")
   )
 )
 
-(define-method set_margin
-  (of-object "EmpathyChatView")
-  (c-name "empathy_chat_view_set_margin")
-  (return-type "none")
-  (parameters
-    '("gint" "margin")
-  )
-)
-
 (define-method scroll
   (of-object "EmpathyChatView")
   (c-name "empathy_chat_view_scroll")
   )
 )
 
-(define-method set_is_group_chat
-  (of-object "EmpathyChatView")
-  (c-name "empathy_chat_view_set_is_group_chat")
-  (return-type "none")
-  (parameters
-    '("gboolean" "is_group_chat")
-  )
-)
-
 (define-method get_last_timestamp
   (of-object "EmpathyChatView")
   (c-name "empathy_chat_view_get_last_timestamp")
   (return-type "EmpathyContactListView*")
   (parameters
     '("EmpathyContactListStore*" "store")
-    '("EmpathyContactListFeatures" "features")
+    '("EmpathyContactListFeatureFlags" "list_features")
+    '("EmpathyContactFeatureFlags" "contact_features")
   )
 )
 
-(define-method set_features
-  (of-object "EmpathyContactListView")
-  (c-name "empathy_contact_list_view_set_features")
-  (return-type "none")
-  (parameters
-    '("EmpathyContactListFeatures" "features")
-  )
-)
-
-(define-method get_features
-  (of-object "EmpathyContactListView")
-  (c-name "empathy_contact_list_view_get_features")
-  (return-type "EmpathyContactListFeatures")
-)
-
 (define-method get_selected
   (of-object "EmpathyContactListView")
   (c-name "empathy_contact_list_view_get_selected")
   (of-object "EmpathyContactListView")
   (c-name "empathy_contact_list_view_get_contact_menu")
   (return-type "GtkWidget*")
-  (parameters
-    '("EmpathyContact*" "contact")
-  )
 )
 
 (define-method get_group_menu
 )
 
 
+
+;; From empathy-contact-menu.h
+
+(define-method menu_new
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_menu_new")
+  (return-type "GtkWidget*")
+  (parameters
+    '("EmpathyContactFeatureFlags" "features")
+  )
+)
+
+(define-method chat_menu_item_new
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_chat_menu_item_new")
+  (return-type "GtkWidget*")
+)
+
+(define-method call_menu_item_new
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_call_menu_item_new")
+  (return-type "GtkWidget*")
+)
+
+(define-method log_menu_item_new
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_log_menu_item_new")
+  (return-type "GtkWidget*")
+)
+
+(define-method info_menu_item_new
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_info_menu_item_new")
+  (return-type "GtkWidget*")
+)
+
+(define-method edit_menu_item_new
+  (of-object "EmpathyContact")
+  (c-name "empathy_contact_edit_menu_item_new")
+  (return-type "GtkWidget*")
+)
+
+
index 4f780aedc77afbee6b688a1147894b2650c41902..b39341ffcefc389001f4b1644ba98813ab97138e 100755 (executable)
@@ -67,6 +67,7 @@ python /usr/share/pygtk/2.0/codegen/h2def.py  \
        empathy-smiley-manager.h                \
        empathy-cell-renderer-text.h            \
        empathy-spell.h                         \
+       empathy-contact-menu.h                  \
  > ../python/pyempathygtk/pyempathygtk.defs
 
 # Keep original version
index 7b616f4ab24e3083076823187fdb142497406263..089fb98b70358dd9c80c4758e8806846e13eca91 100644 (file)
@@ -291,7 +291,8 @@ empathy_main_window_show (void)
        list_iface = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
        window->list_store = empathy_contact_list_store_new (list_iface);
        window->list_view = empathy_contact_list_view_new (window->list_store,
-                                                          EMPATHY_CONTACT_LIST_FEATURE_ALL);
+                                                          EMPATHY_CONTACT_LIST_FEATURE_ALL,
+                                                          EMPATHY_CONTACT_FEATURE_ALL);
        g_object_unref (list_iface);
 
        gtk_widget_show (GTK_WIDGET (window->list_view));
@@ -594,53 +595,43 @@ main_window_edit_button_press_event_cb (GtkWidget         *widget,
                                        GdkEventButton    *event,
                                        EmpathyMainWindow *window)
 {
-       EmpathyContact *contact;
-       gchar         *group;
+       GtkWidget *submenu;
 
        if (!event->button == 1) {
                return FALSE;
        }
 
-       group = empathy_contact_list_view_get_selected_group (window->list_view);
-       if (group) {
+       submenu = empathy_contact_list_view_get_contact_menu (window->list_view);
+       if (submenu) {
                GtkMenuItem *item;
                GtkWidget   *label;
-               GtkWidget   *submenu;
 
                item = GTK_MENU_ITEM (window->edit_context);
                label = gtk_bin_get_child (GTK_BIN (item));
-               gtk_label_set_text (GTK_LABEL (label), _("Group"));
+               gtk_label_set_text (GTK_LABEL (label), _("Contact"));
 
                gtk_widget_show (window->edit_context);
                gtk_widget_show (window->edit_context_separator);
 
-               submenu = empathy_contact_list_view_get_group_menu (window->list_view);
                gtk_menu_item_set_submenu (item, submenu);
 
-               g_free (group);
-
                return FALSE;
        }
 
-       contact = empathy_contact_list_view_get_selected (window->list_view);
-       if (contact) {
+       submenu = empathy_contact_list_view_get_group_menu (window->list_view);
+       if (submenu) {
                GtkMenuItem *item;
                GtkWidget   *label;
-               GtkWidget   *submenu;
 
                item = GTK_MENU_ITEM (window->edit_context);
                label = gtk_bin_get_child (GTK_BIN (item));
-               gtk_label_set_text (GTK_LABEL (label), _("Contact"));
+               gtk_label_set_text (GTK_LABEL (label), _("Group"));
 
                gtk_widget_show (window->edit_context);
                gtk_widget_show (window->edit_context_separator);
 
-               submenu = empathy_contact_list_view_get_contact_menu (window->list_view,
-                                                                    contact);
                gtk_menu_item_set_submenu (item, submenu);
 
-               g_object_unref (contact);
-
                return FALSE;
        }