]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/gossip-contact-list-view.c
sv.po: Updated Swedish translation
[empathy.git] / libempathy-gtk / gossip-contact-list-view.c
index 368ba8be48204ff408eb3e6975f16afc4b85575a..5c3fd274d9703a71c68c1d800e12c2ba9afd8434 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <libempathy/empathy-contact-manager.h>
 #include <libempathy/empathy-contact-list.h>
+#include <libempathy/empathy-log-manager.h>
 #include <libempathy/gossip-debug.h>
 #include <libempathy/gossip-utils.h>
 #include <libempathy/empathy-marshal.h>
 #include "gossip-cell-renderer-expander.h"
 #include "gossip-cell-renderer-text.h"
 #include "gossip-ui-utils.h"
+#include "empathy-contact-dialogs.h"
 //#include "gossip-chat-invite.h"
-//#include "gossip-contact-info-dialog.h"
-//#include "gossip-edit-contact-dialog.h"
 //#include "gossip-ft-window.h"
-//#include "gossip-log-window.h"
+#include "gossip-log-window.h"
 
 #define DEBUG_DOMAIN "ContactListView"
 
@@ -114,27 +114,27 @@ static void        contact_list_view_drag_data_received        (GtkWidget
                                                                gint                        y,
                                                                GtkSelectionData           *selection,
                                                                guint                       info,
-                                                               guint                       time,
-                                                               gpointer                    user_data);
+                                                               guint                       time);
 static gboolean    contact_list_view_drag_motion               (GtkWidget                  *widget,
                                                                GdkDragContext             *context,
                                                                gint                        x,
                                                                gint                        y,
-                                                               guint                       time,
-                                                               gpointer                    data);
+                                                               guint                       time);
 static gboolean    contact_list_view_drag_motion_cb            (DragMotionData             *data);
 static void        contact_list_view_drag_begin                (GtkWidget                  *widget,
-                                                               GdkDragContext             *context,
-                                                               gpointer                    user_data);
+                                                               GdkDragContext             *context);
 static void        contact_list_view_drag_data_get             (GtkWidget                  *widget,
                                                                GdkDragContext             *context,
                                                                GtkSelectionData           *selection,
                                                                guint                       info,
-                                                               guint                       time,
-                                                               gpointer                    user_data);
+                                                               guint                       time);
 static void        contact_list_view_drag_end                  (GtkWidget                  *widget,
-                                                               GdkDragContext             *context,
-                                                               gpointer                    user_data);
+                                                               GdkDragContext             *context);
+static gboolean    contact_list_view_drag_drop                 (GtkWidget                  *widget,
+                                                               GdkDragContext             *drag_context,
+                                                               gint                        x,
+                                                               gint                        y,
+                                                               guint                       time);
 static void        contact_list_view_cell_set_background       (GossipContactListView      *view,
                                                                GtkCellRenderer            *cell,
                                                                gboolean                    is_group,
@@ -287,12 +287,24 @@ G_DEFINE_TYPE (GossipContactListView, gossip_contact_list_view, GTK_TYPE_TREE_VI
 static void
 gossip_contact_list_view_class_init (GossipContactListViewClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+       GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
        object_class->finalize = contact_list_view_finalize;
        object_class->get_property = contact_list_view_get_property;
        object_class->set_property = contact_list_view_set_property;
 
+       widget_class->drag_data_received = contact_list_view_drag_data_received;
+       widget_class->drag_drop          = contact_list_view_drag_drop;
+       widget_class->drag_begin         = contact_list_view_drag_begin;
+       widget_class->drag_data_get      = contact_list_view_drag_data_get;
+       widget_class->drag_end           = contact_list_view_drag_end;
+       /* FIXME: noticed but when you drag the row over the treeview
+        * fast, it seems to stop redrawing itself, if we don't
+        * connect this signal, all is fine.
+        */
+       widget_class->drag_motion        = contact_list_view_drag_motion;
+
        signals[DRAG_CONTACT_RECEIVED] =
                g_signal_new ("drag-contact-received",
                              G_OBJECT_CLASS_TYPE (klass),
@@ -515,14 +527,20 @@ GtkWidget *
 gossip_contact_list_view_get_contact_menu (GossipContactListView *view,
                                           GossipContact         *contact)
 {
-       gboolean can_show_log;
-       gboolean can_send_file;
+       EmpathyLogManager *log_manager;
+       gboolean           can_show_log;
+       gboolean           can_send_file;
 
        g_return_val_if_fail (GOSSIP_IS_CONTACT_LIST_VIEW (view), NULL);
        g_return_val_if_fail (GOSSIP_IS_CONTACT (contact), NULL);
 
-       can_show_log = FALSE; /* FIXME: gossip_log_exists_for_contact (contact); */
+       log_manager = empathy_log_manager_new ();
+       can_show_log = empathy_log_manager_exists (log_manager,
+                                                  gossip_contact_get_account (contact),
+                                                  gossip_contact_get_id (contact),
+                                                  FALSE);
        can_send_file = FALSE;
+       g_object_unref (log_manager);
 
        return contact_list_view_get_contact_menu (view,
                                                   can_send_file,
@@ -686,33 +704,6 @@ contact_list_view_setup (GossipContactListView *view)
                           drag_types_dest,
                           G_N_ELEMENTS (drag_types_dest),
                           GDK_ACTION_MOVE | GDK_ACTION_LINK);
-
-       g_signal_connect (GTK_WIDGET (view),
-                         "drag-data-received",
-                         G_CALLBACK (contact_list_view_drag_data_received),
-                         NULL);
-
-       /* FIXME: noticed but when you drag the row over the treeview
-        * fast, it seems to stop redrawing itself, if we don't
-        * connect this signal, all is fine.
-        */
-       g_signal_connect (view,
-                         "drag-motion",
-                         G_CALLBACK (contact_list_view_drag_motion),
-                         NULL);
-
-       g_signal_connect (view,
-                         "drag-begin",
-                         G_CALLBACK (contact_list_view_drag_begin),
-                         NULL);
-       g_signal_connect (view,
-                         "drag-data-get",
-                         G_CALLBACK (contact_list_view_drag_data_get),
-                         NULL);
-       g_signal_connect (view,
-                         "drag-end",
-                         G_CALLBACK (contact_list_view_drag_end),
-                         NULL);
 }
 
 static void
@@ -802,11 +793,10 @@ contact_list_view_drag_data_received (GtkWidget         *widget,
                                      gint               y,
                                      GtkSelectionData  *selection,
                                      guint              info,
-                                     guint              time,
-                                     gpointer           user_data)
+                                     guint              time)
 {
        GossipContactListViewPriv *priv;
-       EmpathyContactManager     *manager;
+       EmpathyContactList        *list;
        GtkTreeModel              *model;
        GtkTreePath               *path;
        GtkTreeViewDropPosition    position;
@@ -825,9 +815,8 @@ contact_list_view_drag_data_received (GtkWidget         *widget,
                      id);
 
        /* FIXME: This is ambigous, an id can come from multiple accounts */
-       manager = empathy_contact_manager_new ();
-       contact = empathy_contact_list_find (EMPATHY_CONTACT_LIST (manager), id);
-       g_object_unref (manager);
+       list = gossip_contact_list_store_get_list_iface (priv->store);
+       contact = empathy_contact_list_find (list, id);
 
        if (!contact) {
                gossip_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
@@ -887,8 +876,7 @@ contact_list_view_drag_motion (GtkWidget      *widget,
                               GdkDragContext *context,
                               gint            x,
                               gint            y,
-                              guint           time,
-                              gpointer        data)
+                              guint           time)
 {
        static DragMotionData *dm = NULL;
        GtkTreePath           *path;
@@ -957,8 +945,7 @@ contact_list_view_drag_motion_cb (DragMotionData *data)
 
 static void
 contact_list_view_drag_begin (GtkWidget      *widget,
-                             GdkDragContext *context,
-                             gpointer        user_data)
+                             GdkDragContext *context)
 {
        GossipContactListViewPriv *priv;
        GtkTreeSelection          *selection;
@@ -968,6 +955,9 @@ contact_list_view_drag_begin (GtkWidget      *widget,
 
        priv = GET_PRIV (widget);
 
+       GTK_WIDGET_CLASS (gossip_contact_list_view_parent_class)->drag_begin (widget,
+                                                                             context);
+
        selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (widget));
        if (!gtk_tree_selection_get_selected (selection, &model, &iter)) {
                return;
@@ -983,8 +973,7 @@ contact_list_view_drag_data_get (GtkWidget        *widget,
                                 GdkDragContext   *context,
                                 GtkSelectionData *selection,
                                 guint             info,
-                                guint             time,
-                                gpointer          user_data)
+                                guint             time)
 {
        GossipContactListViewPriv *priv;
        GtkTreePath               *src_path;
@@ -1033,19 +1022,31 @@ contact_list_view_drag_data_get (GtkWidget        *widget,
 
 static void
 contact_list_view_drag_end (GtkWidget      *widget,
-                           GdkDragContext *context,
-                           gpointer        user_data)
+                           GdkDragContext *context)
 {
        GossipContactListViewPriv *priv;
 
        priv = GET_PRIV (widget);
 
+       GTK_WIDGET_CLASS (gossip_contact_list_view_parent_class)->drag_end (widget,
+                                                                           context);
+
        if (priv->drag_row) {
                gtk_tree_row_reference_free (priv->drag_row);
                priv->drag_row = NULL;
        }
 }
 
+static gboolean
+contact_list_view_drag_drop (GtkWidget      *widget,
+                            GdkDragContext *drag_context,
+                            gint            x,
+                            gint            y,
+                            guint           time)
+{
+       return FALSE;
+}
+
 static void
 contact_list_view_cell_set_background (GossipContactListView *view,
                                       GtkCellRenderer       *cell,
@@ -1386,14 +1387,15 @@ contact_list_view_filter_show_group (GossipContactListView *view,
        contacts = empathy_contact_list_get_members (list);
        for (l = contacts; l && !show_group; l = l->next) {
                if (!gossip_contact_is_in_group (l->data, group)) {
+                       g_object_unref (l->data);
                        continue;
                }
 
                if (contact_list_view_filter_show_contact (l->data, filter)) {
                        show_group = TRUE;
                }
+               g_object_unref (l->data);
        }
-       g_list_foreach (contacts, (GFunc) g_object_unref, NULL);
        g_list_free (contacts);
        g_free (str);
 
@@ -1449,9 +1451,13 @@ static void
 contact_list_view_action_cb (GtkAction             *action,
                             GossipContactListView *view)
 {
-       GossipContact *contact;
-       const gchar   *name;
-       gchar         *group;
+       GossipContactListViewPriv *priv;
+       GossipContact             *contact;
+       const gchar               *name;
+       gchar                     *group;
+       GtkWindow                 *parent;
+
+       priv = GET_PRIV (view);
 
        name = gtk_action_get_name (action);
        if (!name) {
@@ -1462,21 +1468,34 @@ contact_list_view_action_cb (GtkAction             *action,
 
        contact = gossip_contact_list_view_get_selected (view);
        group = gossip_contact_list_view_get_selected_group (view);
+       parent = gossip_get_toplevel_window (GTK_WIDGET (view));
 
        if (contact && strcmp (name, "Chat") == 0) {
                contact_list_view_action_activated (view, contact);
        }
        else if (contact && strcmp (name, "Information") == 0) {
+               empathy_contact_information_dialog_show (contact, parent, FALSE);
        }
        else if (contact && strcmp (name, "Edit") == 0) {
+               empathy_contact_information_dialog_show (contact, parent, TRUE);
        }
        else if (contact && strcmp (name, "Remove") == 0) {
+               /* FIXME: Ask for confirmation */
+               EmpathyContactList *list;
+
+               list = gossip_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."));
        }
        else if (contact && strcmp (name, "Invite") == 0) {
        }
        else if (contact && strcmp (name, "SendFile") == 0) {
        }
        else if (contact && strcmp (name, "Log") == 0) {
+               gossip_log_window_show (gossip_contact_get_account (contact),
+                                       gossip_contact_get_id (contact),
+                                       FALSE,
+                                       parent);
        }
        else if (group && strcmp (name, "Rename") == 0) {
        }