]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-contact-list-view.c
Updated Basque language
[empathy.git] / libempathy-gtk / empathy-contact-list-view.c
index a88e34bca7addc681916ccf8e898a7d74fdb9c52..dcbbb18bf57ffccf276ed544ef5c21e8b24ed02e 100644 (file)
@@ -32,7 +32,6 @@
 #include <gtk/gtk.h>
 
 #include <telepathy-glib/util.h>
-#include <libmissioncontrol/mc-account.h>
 
 #include <libempathy/empathy-account-manager.h>
 #include <libempathy/empathy-call-factory.h>
@@ -121,7 +120,7 @@ contact_list_view_tooltip_destroy_cb (GtkWidget              *widget,
                                      EmpathyContactListView *view)
 {
        EmpathyContactListViewPriv *priv = GET_PRIV (view);
-       
+
        if (priv->tooltip_widget) {
                DEBUG ("Tooltip destroyed");
                g_object_unref (priv->tooltip_widget);
@@ -169,7 +168,8 @@ contact_list_view_query_tooltip_cb (EmpathyContactListView *view,
 
        if (!priv->tooltip_widget) {
                priv->tooltip_widget = empathy_contact_widget_new (contact,
-                       EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP);
+                       EMPATHY_CONTACT_WIDGET_FOR_TOOLTIP |
+                       EMPATHY_CONTACT_WIDGET_SHOW_LOCATION);
                g_object_ref (priv->tooltip_widget);
                g_signal_connect (priv->tooltip_widget, "destroy",
                                  G_CALLBACK (contact_list_view_tooltip_destroy_cb),
@@ -229,7 +229,7 @@ contact_list_view_drag_got_contact (EmpathyTpContactFactory *factory,
        if (data->new_group) {
                empathy_contact_list_add_to_group (list, contact, data->new_group);
        }
-       if (data->old_group && data->action == GDK_ACTION_MOVE) {       
+       if (data->old_group && data->action == GDK_ACTION_MOVE) {
                empathy_contact_list_remove_from_group (list, contact, data->old_group);
        }
 }
@@ -246,7 +246,7 @@ contact_list_view_drag_data_received (GtkWidget         *view,
        EmpathyContactListViewPriv *priv;
        EmpathyAccountManager      *account_manager;
        EmpathyTpContactFactory    *factory = NULL;
-       McAccount                  *account;
+       EmpathyAccount             *account;
        GtkTreeModel               *model;
        GtkTreeViewDropPosition     position;
        GtkTreePath                *path;
@@ -292,7 +292,7 @@ contact_list_view_drag_data_received (GtkWidget         *view,
                goto OUT;
        }
 
-       id = (const gchar*) selection->data;
+       id = (const gchar*) gtk_selection_data_get_data (selection);
        DEBUG ("Received %s%s drag & drop contact from roster with id:'%s'",
                context->action == GDK_ACTION_MOVE ? "move" : "",
                context->action == GDK_ACTION_COPY ? "copy" : "",
@@ -301,19 +301,17 @@ contact_list_view_drag_data_received (GtkWidget         *view,
        strv = g_strsplit (id, "/", 2);
        account_id = strv[0];
        contact_id = strv[1];
-       account = mc_account_lookup (account_id);
+  account_manager = empathy_account_manager_dup_singleton ();
+       account = empathy_account_manager_get_account (account_manager, account_id);
        if (account) {
                TpConnection *connection;
 
-               /* FIXME: We assume we have already an account manager */
-               account_manager = empathy_account_manager_dup_singleton ();
-               connection = empathy_account_manager_get_connection (account_manager,
-                                                                    account);
+               connection = empathy_account_get_connection (account);
                if (connection) {
                        factory = empathy_tp_contact_factory_dup_singleton (connection);
                }
-               g_object_unref (account_manager);
        }
+       g_object_unref (account_manager);
 
        if (!factory) {
                DEBUG ("Failed to get factory for account '%s'", account_id);
@@ -366,6 +364,7 @@ contact_list_view_drag_motion (GtkWidget      *widget,
        gboolean               is_row;
        gboolean               is_different = FALSE;
        gboolean               cleanup = TRUE;
+       int                    action = 0;
 
        is_row = gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
                                                x,
@@ -384,6 +383,13 @@ contact_list_view_drag_motion (GtkWidget      *widget,
                cleanup &= FALSE;
        }
 
+       if (context->actions == GDK_ACTION_COPY) {
+               action = context->suggested_action;
+       } else if (context->actions & GDK_ACTION_MOVE) {
+               action = GDK_ACTION_MOVE;
+       }
+       gdk_drag_status (context, action, time);
+
        if (!is_different && !cleanup) {
                return TRUE;
        }
@@ -450,7 +456,7 @@ contact_list_view_drag_data_get (GtkWidget        *widget,
        GtkTreeIter                 iter;
        GtkTreeModel               *model;
        EmpathyContact             *contact;
-       McAccount                  *account;
+       EmpathyAccount             *account;
        const gchar                *contact_id;
        const gchar                *account_id;
        gchar                      *str;
@@ -480,7 +486,7 @@ contact_list_view_drag_data_get (GtkWidget        *widget,
        }
 
        account = empathy_contact_get_account (contact);
-       account_id = mc_account_get_unique_name (account);
+       account_id = empathy_account_get_unique_name (account);
        contact_id = empathy_contact_get_id (contact);
        g_object_unref (contact);
        str = g_strconcat (account_id, "/", contact_id, NULL);
@@ -615,9 +621,10 @@ contact_list_view_row_activated (GtkTreeView       *view,
 }
 
 static void
-contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
-                                    const gchar                    *path_string,
-                                    EmpathyContactListView         *view)
+contact_list_start_voip_call (EmpathyCellRendererActivatable *cell,
+    const gchar                    *path_string,
+    EmpathyContactListView         *view,
+    gboolean with_video)
 {
        EmpathyContactListViewPriv *priv = GET_PRIV (view);
        GtkTreeModel               *model;
@@ -639,14 +646,31 @@ contact_list_view_voip_activated_cb (EmpathyCellRendererActivatable *cell,
 
        if (contact) {
                EmpathyCallFactory *factory;
-
                factory = empathy_call_factory_get ();
-               empathy_call_factory_new_call (factory, contact);
-
+               empathy_call_factory_new_call_with_streams (factory, contact,
+                       TRUE, with_video);
                g_object_unref (contact);
        }
 }
 
+static void
+contact_list_view_video_call_activated_cb (
+    EmpathyCellRendererActivatable *cell,
+    const gchar                    *path_string,
+    EmpathyContactListView         *view)
+{
+  contact_list_start_voip_call (cell, path_string, view, TRUE);
+}
+
+
+static void
+contact_list_view_audio_call_activated_cb (EmpathyCellRendererActivatable *cell,
+                                    const gchar                    *path_string,
+                                    EmpathyContactListView         *view)
+{
+  contact_list_start_voip_call (cell, path_string, view, FALSE);
+}
+
 static void
 contact_list_view_cell_set_background (EmpathyContactListView *view,
                                       GtkCellRenderer       *cell,
@@ -708,7 +732,8 @@ contact_list_view_pixbuf_cell_data_func (GtkTreeViewColumn     *tree_column,
 }
 
 static void
-contact_list_view_voip_cell_data_func (GtkTreeViewColumn      *tree_column,
+contact_list_view_audio_call_cell_data_func (
+                                      GtkTreeViewColumn      *tree_column,
                                       GtkCellRenderer        *cell,
                                       GtkTreeModel           *model,
                                       GtkTreeIter            *iter,
@@ -721,7 +746,7 @@ contact_list_view_voip_cell_data_func (GtkTreeViewColumn      *tree_column,
        gtk_tree_model_get (model, iter,
                            EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
                            EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
-                           EMPATHY_CONTACT_LIST_STORE_COL_CAN_VOIP, &can_voip,
+                           EMPATHY_CONTACT_LIST_STORE_COL_CAN_AUDIO_CALL, &can_voip,
                            -1);
 
        g_object_set (cell,
@@ -732,6 +757,33 @@ contact_list_view_voip_cell_data_func (GtkTreeViewColumn      *tree_column,
        contact_list_view_cell_set_background (view, cell, is_group, is_active);
 }
 
+static void
+contact_list_view_video_call_cell_data_func (
+                                      GtkTreeViewColumn      *tree_column,
+                                      GtkCellRenderer        *cell,
+                                      GtkTreeModel           *model,
+                                      GtkTreeIter            *iter,
+                                      EmpathyContactListView *view)
+{
+       gboolean is_group;
+       gboolean is_active;
+       gboolean can_voip;
+
+       gtk_tree_model_get (model, iter,
+                           EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
+                           EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
+                           EMPATHY_CONTACT_LIST_STORE_COL_CAN_VIDEO_CALL, &can_voip,
+                           -1);
+
+       g_object_set (cell,
+                     "visible", !is_group && can_voip,
+                     "icon-name", EMPATHY_IMAGE_VIDEO_CALL,
+                     NULL);
+
+       contact_list_view_cell_set_background (view, cell, is_group, is_active);
+}
+
+
 static void
 contact_list_view_avatar_cell_data_func (GtkTreeViewColumn     *tree_column,
                                         GtkCellRenderer       *cell,
@@ -773,16 +825,20 @@ contact_list_view_text_cell_data_func (GtkTreeViewColumn     *tree_column,
        gboolean is_group;
        gboolean is_active;
        gboolean show_status;
+       gchar *name;
 
        gtk_tree_model_get (model, iter,
                            EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP, &is_group,
                            EMPATHY_CONTACT_LIST_STORE_COL_IS_ACTIVE, &is_active,
                            EMPATHY_CONTACT_LIST_STORE_COL_STATUS_VISIBLE, &show_status,
+                           EMPATHY_CONTACT_LIST_STORE_COL_NAME, &name,
                            -1);
 
        g_object_set (cell,
                      "show-status", show_status,
+                     "text", name,
                      NULL);
+       g_free (name);
 
        contact_list_view_cell_set_background (view, cell, is_group, is_active);
 }
@@ -807,7 +863,7 @@ contact_list_view_expander_cell_data_func (GtkTreeViewColumn     *column,
                gboolean     row_expanded;
 
                path = gtk_tree_model_get_path (model, iter);
-               row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (column->tree_view), path);
+               row_expanded = gtk_tree_view_row_expanded (GTK_TREE_VIEW (gtk_tree_view_column_get_tree_view (column)), path);
                gtk_tree_path_free (path);
 
                g_object_set (cell,
@@ -948,12 +1004,28 @@ contact_list_view_setup (EmpathyContactListView *view)
        gtk_tree_view_column_add_attribute (col, cell,
                                            "is_group", EMPATHY_CONTACT_LIST_STORE_COL_IS_GROUP);
 
-       /* Voip Capability Icon */
+       /* Audio Call Icon */
+       cell = empathy_cell_renderer_activatable_new ();
+       gtk_tree_view_column_pack_start (col, cell, FALSE);
+       gtk_tree_view_column_set_cell_data_func (
+               col, cell,
+               (GtkTreeCellDataFunc) contact_list_view_audio_call_cell_data_func,
+               view, NULL);
+
+       g_object_set (cell,
+                     "visible", FALSE,
+                     NULL);
+
+       g_signal_connect (cell, "path-activated",
+                         G_CALLBACK (contact_list_view_audio_call_activated_cb),
+                         view);
+
+       /* Video Call Icon */
        cell = empathy_cell_renderer_activatable_new ();
        gtk_tree_view_column_pack_start (col, cell, FALSE);
        gtk_tree_view_column_set_cell_data_func (
                col, cell,
-               (GtkTreeCellDataFunc) contact_list_view_voip_cell_data_func,
+               (GtkTreeCellDataFunc) contact_list_view_video_call_cell_data_func,
                view, NULL);
 
        g_object_set (cell,
@@ -961,7 +1033,7 @@ contact_list_view_setup (EmpathyContactListView *view)
                      NULL);
 
        g_signal_connect (cell, "path-activated",
-                         G_CALLBACK (contact_list_view_voip_activated_cb),
+                         G_CALLBACK (contact_list_view_video_call_activated_cb),
                          view);
 
        /* Avatar */
@@ -1209,7 +1281,7 @@ empathy_contact_list_view_new (EmpathyContactListStore        *store,
                               EmpathyContactFeatureFlags      contact_features)
 {
        g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_STORE (store), NULL);
-       
+
        return g_object_new (EMPATHY_TYPE_CONTACT_LIST_VIEW,
                             "store", store,
                             "contact-features", contact_features,
@@ -1242,6 +1314,31 @@ empathy_contact_list_view_dup_selected (EmpathyContactListView *view)
        return contact;
 }
 
+EmpathyContactListFlags
+empathy_contact_list_view_get_flags (EmpathyContactListView *view)
+{
+       EmpathyContactListViewPriv *priv;
+       GtkTreeSelection          *selection;
+       GtkTreeIter                iter;
+       GtkTreeModel              *model;
+       EmpathyContactListFlags    flags;
+
+       g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), 0);
+
+       priv = GET_PRIV (view);
+
+       selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
+       if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
+               return 0;
+       }
+
+       gtk_tree_model_get (model, &iter,
+                           EMPATHY_CONTACT_LIST_STORE_COL_FLAGS, &flags,
+                           -1);
+
+       return flags;
+}
+
 gchar *
 empathy_contact_list_view_get_selected_group (EmpathyContactListView *view)
 {
@@ -1281,7 +1378,7 @@ contact_list_view_remove_dialog_show (GtkWindow   *parent,
 {
        GtkWidget *dialog;
        gboolean res;
-       
+
        dialog = gtk_message_dialog_new (parent, GTK_DIALOG_MODAL,
                                         GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                                         "%s", message);
@@ -1383,7 +1480,7 @@ contact_list_view_remove_activate_cb (GtkMenuItem            *menuitem,
 {
        EmpathyContactListViewPriv *priv = GET_PRIV (view);
        EmpathyContact             *contact;
-               
+
        contact = empathy_contact_list_view_dup_selected (view);
 
        if (contact) {
@@ -1392,13 +1489,12 @@ contact_list_view_remove_activate_cb (GtkMenuItem            *menuitem,
 
                parent = empathy_get_toplevel_window (GTK_WIDGET (view));
                text = g_strdup_printf (_("Do you really want to remove the contact '%s'?"),
-                                       empathy_contact_get_name (contact));                                            
+                                       empathy_contact_get_name (contact));
                if (contact_list_view_remove_dialog_show (parent, _("Removing contact"), text)) {
                        EmpathyContactList *list;
 
                        list = empathy_contact_list_store_get_list_iface (priv->store);
-                       empathy_contact_list_remove (list, contact,
-                               _("Sorry, I don't want you in my contact list anymore."));
+                       empathy_contact_list_remove (list, contact, "");
                }
 
                g_free (text);
@@ -1414,6 +1510,7 @@ empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view)
        GtkWidget                  *menu;
        GtkWidget                  *item;
        GtkWidget                  *image;
+       EmpathyContactListFlags     flags;
 
        g_return_val_if_fail (EMPATHY_IS_CONTACT_LIST_VIEW (view), NULL);
 
@@ -1421,25 +1518,23 @@ empathy_contact_list_view_get_contact_menu (EmpathyContactListView *view)
        if (!contact) {
                return NULL;
        }
+       flags = empathy_contact_list_view_get_flags (view);
 
        menu = empathy_contact_menu_new (contact, priv->contact_features);
 
-       if (!(priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE)) {
-               g_object_unref (contact);
-               return menu;
-       }
-
-       if (menu) {
-               /* Separator */
-               item = gtk_separator_menu_item_new ();
-               gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-               gtk_widget_show (item);
-       } else {
-               menu = gtk_menu_new ();
-       }
-
        /* Remove contact */
-       if (priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE) {
+       if (priv->list_features & EMPATHY_CONTACT_LIST_FEATURE_CONTACT_REMOVE &&
+           flags & EMPATHY_CONTACT_LIST_CAN_REMOVE) {
+               /* create the menu if required, or just add a separator */
+               if (!menu) {
+                       menu = gtk_menu_new ();
+               } else {
+                       item = gtk_separator_menu_item_new ();
+                       gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+                       gtk_widget_show (item);
+               }
+
+               /* Remove */
                item = gtk_image_menu_item_new_with_mnemonic (_("_Remove"));
                image = gtk_image_new_from_icon_name (GTK_STOCK_REMOVE,
                                                      GTK_ICON_SIZE_MENU);