]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/gossip-contact-list.c
Auto away when session id idle, instead of when screensaver is active.
[empathy.git] / libempathy-gtk / gossip-contact-list.c
index a96c28e51939df91facb7bd36ddc87242fe52e8e..e4abccc80ac1bc46e914b5da64e60fe8137fd71f 100644 (file)
 #include <glade/glade.h>
 
 #include <libmissioncontrol/mc-account.h>
+#include <libmissioncontrol/mission-control.h>
 
+#include <libempathy/empathy-contact-list.h>
 #include <libempathy/empathy-contact-manager.h>
 #include <libempathy/gossip-debug.h>
-#include <libempathy/empathy-session.h>
+#include <libempathy/gossip-utils.h>
 
+#include "empathy-images.h"
 #include "gossip-contact-list.h"
 #include "gossip-contact-groups.h"
 #include "gossip-cell-renderer-expander.h"
 #include "gossip-cell-renderer-text.h"
-#include "gossip-stock.h"
 #include "gossip-ui-utils.h"
 //#include "gossip-chat-invite.h"
 //#include "gossip-contact-info-dialog.h"
@@ -65,7 +67,7 @@
 #define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CONTACT_LIST, GossipContactListPriv))
 
 struct _GossipContactListPriv {
-       EmpathyContactManager *manager;
+       EmpathyContactList    *list;
 
        GHashTable            *groups;
 
@@ -80,6 +82,8 @@ struct _GossipContactListPriv {
        gboolean               show_avatars;
        gboolean               is_compact;
        gboolean               show_active;
+
+       GossipContactListSort  sort_criterium;
 };
 
 typedef struct {
@@ -122,7 +126,7 @@ static gboolean contact_list_row_separator_func              (GtkTreeModel
                                                              gpointer                data);
 static void     contact_list_contact_update                  (GossipContactList      *list,
                                                              GossipContact          *contact);
-static void     contact_list_contact_added_cb                (EmpathyContactManager  *manager,
+static void     contact_list_contact_added_cb                (EmpathyContactList     *list_iface,
                                                              GossipContact          *contact,
                                                              GossipContactList      *list);
 static void     contact_list_contact_updated_cb              (GossipContact          *contact,
@@ -131,7 +135,7 @@ static void     contact_list_contact_updated_cb              (GossipContact
 static void     contact_list_contact_groups_updated_cb       (GossipContact          *contact,
                                                              GParamSpec             *param,
                                                              GossipContactList      *list);
-static void     contact_list_contact_removed_cb              (EmpathyContactManager  *manager,
+static void     contact_list_contact_removed_cb              (EmpathyContactList     *list_iface,
                                                              GossipContact          *contact,
                                                              GossipContactList      *list);
 static void     contact_list_contact_set_active              (GossipContactList      *list,
@@ -232,7 +236,11 @@ static void     contact_list_row_expand_or_collapse_cb       (GossipContactList
                                                              GtkTreeIter            *iter,
                                                              GtkTreePath            *path,
                                                              gpointer                user_data);
-static gint     contact_list_sort_func                       (GtkTreeModel           *model,
+static gint     contact_list_name_sort_func                  (GtkTreeModel           *model,
+                                                             GtkTreeIter            *iter_a,
+                                                             GtkTreeIter            *iter_b,
+                                                             gpointer                user_data);
+static gint     contact_list_state_sort_func                 (GtkTreeModel           *model,
                                                              GtkTreeIter            *iter_a,
                                                              GtkTreeIter            *iter_b,
                                                              gpointer                user_data);
@@ -247,26 +255,15 @@ static gboolean contact_list_find_contact_foreach            (GtkTreeModel
                                                              FindContact            *fc);
 static void     contact_list_action_cb                       (GtkAction              *action,
                                                              GossipContactList      *list);
+static void     contact_list_action_activated                (GossipContactList      *list,
+                                                             GossipContact          *contact);
 static gboolean contact_list_update_list_mode_foreach        (GtkTreeModel           *model,
                                                              GtkTreePath            *path,
                                                              GtkTreeIter            *iter,
                                                              GossipContactList      *list);
-enum {
-       CONTACT_CHAT,
-       CONTACT_INFORMATION,
-       CONTACT_EDIT,
-       CONTACT_REMOVE,
-       CONTACT_INVITE,
-       CONTACT_SEND_FILE,
-       CONTACT_LOG,
-       GROUP_RENAME,
-       LAST_SIGNAL
-};
-
-static guint signals[LAST_SIGNAL];
 
 enum {
-       COL_PIXBUF_STATUS,
+       COL_ICON_STATUS,
        COL_PIXBUF_AVATAR,
        COL_PIXBUF_AVATAR_VISIBLE,
        COL_NAME,
@@ -285,7 +282,8 @@ enum {
        PROP_SHOW_OFFLINE,
        PROP_SHOW_AVATARS,
        PROP_IS_COMPACT,
-       PROP_FILTER
+       PROP_FILTER,
+       PROP_SORT_CRITERIUM
 };
 
 static const GtkActionEntry entries[] = {
@@ -297,11 +295,11 @@ static const GtkActionEntry entries[] = {
          N_("_Group"),NULL, NULL,
          NULL
        },
-       { "Chat", GOSSIP_STOCK_MESSAGE,
+       { "Chat", EMPATHY_IMAGE_MESSAGE,
          N_("_Chat"), NULL, N_("Chat with contact"),
          G_CALLBACK (contact_list_action_cb)
        },
-       { "Information", GOSSIP_STOCK_CONTACT_INFORMATION,
+       { "Information", EMPATHY_IMAGE_CONTACT_INFORMATION,
          N_("Infor_mation"), "<control>I", N_("View contact information"),
          G_CALLBACK (contact_list_action_cb)
        },
@@ -317,7 +315,7 @@ static const GtkActionEntry entries[] = {
          N_("_Remove"), NULL, N_("Remove contact"),
          G_CALLBACK (contact_list_action_cb)
        },
-       { "Invite", GOSSIP_STOCK_GROUP_MESSAGE,
+       { "Invite", EMPATHY_IMAGE_GROUP_MESSAGE,
          N_("_Invite to Chat Room"), NULL, N_("Invite to a currently open chat room"),
          G_CALLBACK (contact_list_action_cb)
        },
@@ -372,6 +370,28 @@ static const GtkTargetEntry drag_types_source[] = {
 static GdkAtom drag_atoms_dest[G_N_ELEMENTS (drag_types_dest)];
 static GdkAtom drag_atoms_source[G_N_ELEMENTS (drag_types_source)];
 
+GType
+gossip_contact_list_sort_get_type (void)
+{
+       static GType etype = 0;
+
+       if (etype == 0) {
+               static const GEnumValue values[] = {
+                       { GOSSIP_CONTACT_LIST_SORT_NAME, 
+                         "GOSSIP_CONTACT_LIST_SORT_NAME", 
+                         "name" },
+                       { GOSSIP_CONTACT_LIST_SORT_STATE, 
+                         "GOSSIP_CONTACT_LIST_SORT_STATE", 
+                         "state" },
+                       { 0, NULL, NULL }
+               };
+
+               etype = g_enum_register_static ("GossipContactListSort", values);
+       }
+
+       return etype;
+}
+
 G_DEFINE_TYPE (GossipContactList, gossip_contact_list, GTK_TYPE_TREE_VIEW);
 
 static void
@@ -383,80 +403,6 @@ gossip_contact_list_class_init (GossipContactListClass *klass)
        object_class->get_property = contact_list_get_property;
        object_class->set_property = contact_list_set_property;
 
-       signals[CONTACT_CHAT] =
-               g_signal_new ("contact-chat",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[CONTACT_INFORMATION] =
-               g_signal_new ("contact-information",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[CONTACT_EDIT] =
-               g_signal_new ("contact-edit",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[CONTACT_REMOVE] =
-               g_signal_new ("contact-remove",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[CONTACT_INVITE] =
-               g_signal_new ("contact-invite",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[CONTACT_SEND_FILE] =
-               g_signal_new ("contact-send-file",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[CONTACT_LOG] =
-               g_signal_new ("contact-log",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__OBJECT,
-                             G_TYPE_NONE,
-                             1, GOSSIP_TYPE_CONTACT);
-       signals[GROUP_RENAME] =
-               g_signal_new ("group-rename",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST,
-                             0,
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__STRING,
-                             G_TYPE_NONE,
-                             1, G_TYPE_STRING);
-
-
        g_object_class_install_property (object_class,
                                         PROP_SHOW_OFFLINE,
                                         g_param_spec_boolean ("show-offline",
@@ -489,6 +435,15 @@ gossip_contact_list_class_init (GossipContactListClass *klass)
                                                              NULL,
                                                              G_PARAM_READWRITE));
 
+       g_object_class_install_property (object_class,
+                                        PROP_SORT_CRITERIUM,
+                                        g_param_spec_enum ("sort-criterium",
+                                                            "Sort citerium",
+                                                            "The sort criterium to use for sorting the contact list",
+                                                            GOSSIP_TYPE_CONTACT_LIST_SORT,
+                                                            GOSSIP_CONTACT_LIST_SORT_NAME,
+                                                            G_PARAM_READWRITE));
+
        g_type_class_add_private (object_class, sizeof (GossipContactListPriv));
 }
 
@@ -502,15 +457,14 @@ gossip_contact_list_init (GossipContactList *list)
 
        priv = GET_PRIV (list);
 
-       priv->manager = empathy_session_get_contact_manager ();
-       g_object_ref (priv->manager);
+       priv->list = EMPATHY_CONTACT_LIST (empathy_contact_manager_new ());
        priv->is_compact = FALSE;
        priv->show_active = TRUE;
        priv->show_avatars = TRUE;
 
        contact_list_create_model (list);
        contact_list_setup_view (list);
-       empathy_contact_manager_setup (priv->manager);
+       empathy_contact_list_setup (priv->list);
 
        /* Get saved group states. */
        gossip_contact_groups_get_all ();
@@ -535,11 +489,11 @@ gossip_contact_list_init (GossipContactList *list)
                                              NULL, NULL);
 
        /* Signal connection. */
-       g_signal_connect (priv->manager,
+       g_signal_connect (priv->list,
                          "contact-added",
                          G_CALLBACK (contact_list_contact_added_cb),
                          list);
-       g_signal_connect (priv->manager,
+       g_signal_connect (priv->list,
                          "contact-removed",
                          G_CALLBACK (contact_list_contact_removed_cb),
                          list);
@@ -563,13 +517,13 @@ gossip_contact_list_init (GossipContactList *list)
                          GINT_TO_POINTER (FALSE));
 
        /* Add contacts already created */
-       contacts = empathy_contact_manager_get_contacts (priv->manager);
+       contacts = empathy_contact_list_get_contacts (priv->list);
        for (l = contacts; l; l = l->next) {
                GossipContact *contact;
 
                contact = l->data;
 
-               contact_list_contact_added_cb (priv->manager, contact, list);
+               contact_list_contact_added_cb (priv->list, contact, list);
 
                g_object_unref (contact);
        }
@@ -583,9 +537,9 @@ contact_list_finalize (GObject *object)
 
        priv = GET_PRIV (object);
 
-       /* FIXME: disconnect all signals on the manager and contacts */
+       /* FIXME: disconnect all signals on the list and contacts */
 
-       g_object_unref (priv->manager);
+       g_object_unref (priv->list);
        g_object_unref (priv->ui);
        g_object_unref (priv->store);
        g_object_unref (priv->filter);
@@ -617,6 +571,9 @@ contact_list_get_property (GObject    *object,
        case PROP_FILTER:
                g_value_set_string (value, priv->filter_text);
                break;
+       case PROP_SORT_CRITERIUM:
+               g_value_set_enum (value, priv->sort_criterium);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -650,6 +607,10 @@ contact_list_set_property (GObject      *object,
                gossip_contact_list_set_filter (GOSSIP_CONTACT_LIST (object),
                                                g_value_get_string (value));
                break;
+       case PROP_SORT_CRITERIUM:
+               gossip_contact_list_set_sort_criterium (GOSSIP_CONTACT_LIST (object),
+                                                       g_value_get_enum (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -686,7 +647,6 @@ contact_list_contact_update (GossipContactList *list,
        gboolean               do_remove = FALSE;
        gboolean               do_set_active = FALSE;
        gboolean               do_set_refresh = FALSE;
-       GdkPixbuf             *pixbuf_presence;
        GdkPixbuf             *pixbuf_avatar;
 
        priv = GET_PRIV (list);
@@ -785,11 +745,10 @@ contact_list_contact_update (GossipContactList *list,
                set_model = TRUE;
        }
 
-       pixbuf_presence = gossip_pixbuf_for_contact (contact);
        pixbuf_avatar = gossip_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
        for (l = iters; l && set_model; l = l->next) {
                gtk_tree_store_set (priv->store, l->data,
-                                   COL_PIXBUF_STATUS, pixbuf_presence,
+                                   COL_ICON_STATUS, gossip_icon_name_for_contact (contact),
                                    COL_STATUS, gossip_contact_get_status (contact),
                                    COL_IS_ONLINE, now_online,
                                    COL_NAME, gossip_contact_get_name (contact),
@@ -797,9 +756,6 @@ contact_list_contact_update (GossipContactList *list,
                                    -1);
        }
 
-       if (pixbuf_presence) {
-               g_object_unref (pixbuf_presence);
-       }
        if (pixbuf_avatar) {
                g_object_unref (pixbuf_avatar);
        }
@@ -825,9 +781,9 @@ contact_list_contact_update (GossipContactList *list,
 }
 
 static void
-contact_list_contact_added_cb (EmpathyContactManager *manager,
-                              GossipContact         *contact,
-                              GossipContactList     *list)
+contact_list_contact_added_cb (EmpathyContactList *list_iface,
+                              GossipContact      *contact,
+                              GossipContactList  *list)
 {
        GossipContactListPriv *priv;
 
@@ -893,9 +849,9 @@ contact_list_contact_updated_cb (GossipContact     *contact,
 }
 
 static void
-contact_list_contact_removed_cb (EmpathyContactManager *manager,
-                                GossipContact         *contact,
-                                GossipContactList     *list)
+contact_list_contact_removed_cb (EmpathyContactList *list_iface,
+                                GossipContact      *contact,
+                                GossipContactList  *list)
 {
        gossip_debug (DEBUG_DOMAIN, "Contact:'%s' removed",
                      gossip_contact_get_name (contact));
@@ -1120,7 +1076,7 @@ contact_list_get_group (GossipContactList *list,
 
                gtk_tree_store_append (priv->store, &iter_group, NULL);
                gtk_tree_store_set (priv->store, &iter_group,
-                                   COL_PIXBUF_STATUS, NULL,
+                                   COL_ICON_STATUS, NULL,
                                    COL_NAME, name,
                                    COL_IS_GROUP, TRUE,
                                    COL_IS_ACTIVE, FALSE,
@@ -1181,16 +1137,14 @@ contact_list_add_contact (GossipContactList *list,
                return;
        }
 
-       model = GTK_TREE_MODEL (priv->store);
+       model = gtk_tree_view_get_model (GTK_TREE_VIEW (list));
 
        /* If no groups just add it at the top level. */
        groups = gossip_contact_get_groups (contact);
        if (!groups) {
-               GdkPixbuf *pixbuf_status;
                GdkPixbuf *pixbuf_avatar;
                gboolean   show_avatar = FALSE;
 
-               pixbuf_status = gossip_pixbuf_for_contact (contact);
                pixbuf_avatar = gossip_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
 
                if (priv->show_avatars && !priv->is_compact) {
@@ -1209,7 +1163,7 @@ contact_list_add_contact (GossipContactList *list,
 
                gtk_tree_store_append (priv->store, &iter, NULL);
                gtk_tree_store_set (priv->store, &iter,
-                                   COL_PIXBUF_STATUS, pixbuf_status,
+                                   COL_ICON_STATUS, gossip_icon_name_for_contact (contact),
                                    COL_PIXBUF_AVATAR, pixbuf_avatar,
                                    COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
                                    COL_NAME, gossip_contact_get_name (contact),
@@ -1229,16 +1183,12 @@ contact_list_add_contact (GossipContactList *list,
                if (pixbuf_avatar) {
                        g_object_unref (pixbuf_avatar);
                }
-               if (pixbuf_status) {
-                       g_object_unref (pixbuf_status);
-               }
        }
 
        /* Else add to each group. */
        for (l = groups; l; l = l->next) {
                GtkTreePath *path;
                GtkTreeIter  model_iter_group;
-               GdkPixbuf   *pixbuf_status;
                GdkPixbuf   *pixbuf_avatar;
                const gchar *name;
                gboolean     created;
@@ -1250,7 +1200,6 @@ contact_list_add_contact (GossipContactList *list,
                        continue;
                }
 
-               pixbuf_status = gossip_pixbuf_for_contact (contact);
                pixbuf_avatar = gossip_pixbuf_avatar_from_contact_scaled (contact, 32, 32);
 
                contact_list_get_group (list, name, &iter_group, &iter_separator, &created);
@@ -1271,7 +1220,7 @@ contact_list_add_contact (GossipContactList *list,
 
                gtk_tree_store_insert_after (priv->store, &iter, &iter_group, NULL);
                gtk_tree_store_set (priv->store, &iter,
-                                   COL_PIXBUF_STATUS, pixbuf_status,
+                                   COL_ICON_STATUS, gossip_icon_name_for_contact (contact),
                                    COL_PIXBUF_AVATAR, pixbuf_avatar,
                                    COL_PIXBUF_AVATAR_VISIBLE, show_avatar,
                                    COL_NAME, gossip_contact_get_name (contact),
@@ -1291,9 +1240,6 @@ contact_list_add_contact (GossipContactList *list,
                if (pixbuf_avatar) {
                        g_object_unref (pixbuf_avatar);
                }
-               if (pixbuf_status) {
-                       g_object_unref (pixbuf_status);
-               }
 
                if (!created) {
                        continue;
@@ -1387,7 +1333,7 @@ contact_list_create_model (GossipContactList *list)
        }
 
        priv->store = gtk_tree_store_new (COL_COUNT,
-                                         GDK_TYPE_PIXBUF,     /* Status pixbuf */
+                                         G_TYPE_STRING,       /* Status icon-name */
                                          GDK_TYPE_PIXBUF,     /* Avatar pixbuf */
                                          G_TYPE_BOOLEAN,      /* Avatar pixbuf visible */
                                          G_TYPE_STRING,       /* Name */
@@ -1405,12 +1351,14 @@ contact_list_create_model (GossipContactList *list)
        /* Set up sorting */
        gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model),
                                         COL_NAME,
-                                        contact_list_sort_func,
+                                        contact_list_name_sort_func,
+                                        list, NULL);
+       gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE (model),
+                                        COL_STATUS,
+                                        contact_list_state_sort_func,
                                         list, NULL);
 
-       gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (model),
-                                             COL_NAME,
-                                             GTK_SORT_ASCENDING);
+       gossip_contact_list_set_sort_criterium (list, priv->sort_criterium);
 
        /* Create filter */
        priv->filter = gtk_tree_model_filter_new (model, NULL);
@@ -1622,7 +1570,7 @@ contact_list_drag_data_received (GtkWidget         *widget,
                      id);
 
        /* FIXME: This is ambigous, an id can come from multiple accounts */
-       contact = empathy_contact_manager_find (priv->manager, id);
+       contact = empathy_contact_list_find (priv->list, id);
        if (!contact) {
                gossip_debug (DEBUG_DOMAIN, "No contact found associated with drag & drop");
                return;
@@ -1918,9 +1866,6 @@ contact_list_cell_set_background (GossipContactList  *list,
                                      NULL);
                }
        } else {
-               g_object_set (cell,
-                             "cell-background-gdk", NULL,
-                             NULL);
 #if 0
                gint color_sum_normal;
                gint color_sum_selected;
@@ -1957,24 +1902,22 @@ contact_list_pixbuf_cell_data_func (GtkTreeViewColumn *tree_column,
                                    GtkTreeIter       *iter,
                                    GossipContactList *list)
 {
-       GdkPixbuf *pixbuf;
-       gboolean   is_group;
-       gboolean   is_active;
+       gchar    *icon_name;
+       gboolean  is_group;
+       gboolean  is_active;
 
        gtk_tree_model_get (model, iter,
                            COL_IS_GROUP, &is_group,
                            COL_IS_ACTIVE, &is_active,
-                           COL_PIXBUF_STATUS, &pixbuf,
+                           COL_ICON_STATUS, &icon_name,
                            -1);
 
        g_object_set (cell,
                      "visible", !is_group,
-                     "pixbuf", pixbuf,
+                     "icon-name", icon_name,
                      NULL);
 
-       if (pixbuf) {
-               g_object_unref (pixbuf);
-       }
+       g_free (icon_name);
 
        contact_list_cell_set_background (list, cell, is_group, is_active);
 }
@@ -2205,7 +2148,7 @@ contact_list_row_activated_cb (GossipContactList *list,
        gtk_tree_model_get (model, &iter, COL_CONTACT, &contact, -1);
 
        if (contact) {
-               g_signal_emit (list, signals[CONTACT_CHAT], 0, contact);
+               contact_list_action_activated (list, contact);
                g_object_unref (contact);
        }
 }
@@ -2233,10 +2176,96 @@ contact_list_row_expand_or_collapse_cb (GossipContactList *list,
 }
 
 static gint
-contact_list_sort_func (GtkTreeModel *model,
-                       GtkTreeIter  *iter_a,
-                       GtkTreeIter  *iter_b,
-                       gpointer      user_data)
+contact_list_state_sort_func (GtkTreeModel *model,
+                             GtkTreeIter  *iter_a,
+                             GtkTreeIter  *iter_b,
+                             gpointer      user_data)
+{
+       gint            ret_val = 0;
+       gchar          *name_a, *name_b;
+       gboolean        is_separator_a, is_separator_b;
+       GossipContact  *contact_a, *contact_b;
+       GossipPresence *presence_a, *presence_b;
+       McPresence      state_a, state_b;
+
+       gtk_tree_model_get (model, iter_a,
+                           COL_NAME, &name_a,
+                           COL_CONTACT, &contact_a,
+                           COL_IS_SEPARATOR, &is_separator_a,
+                           -1);
+       gtk_tree_model_get (model, iter_b,
+                           COL_NAME, &name_b,
+                           COL_CONTACT, &contact_b,
+                           COL_IS_SEPARATOR, &is_separator_b,
+                           -1);
+
+       /* Separator or group? */
+       if (is_separator_a || is_separator_b) {
+               if (is_separator_a) {
+                       ret_val = -1;
+               } else if (is_separator_b) {
+                       ret_val = 1;
+               }
+       } else if (!contact_a && contact_b) {
+               ret_val = 1;
+       } else if (contact_a && !contact_b) {
+               ret_val = -1;
+       } else if (!contact_a && !contact_b) {
+               /* Handle groups */
+               ret_val = g_utf8_collate (name_a, name_b);
+       }
+
+       if (ret_val) {
+               goto free_and_out;
+       }
+
+       /* If we managed to get this far, we can start looking at
+        * the presences.
+        */
+       presence_a = gossip_contact_get_presence (GOSSIP_CONTACT (contact_a));
+       presence_b = gossip_contact_get_presence (GOSSIP_CONTACT (contact_b));
+
+       if (!presence_a && presence_b) {
+               ret_val = 1;
+       } else if (presence_a && !presence_b) {
+               ret_val = -1;
+       } else if (!presence_a && !presence_b) {
+               /* Both offline, sort by name */
+               ret_val = g_utf8_collate (name_a, name_b);
+       } else {
+               state_a = gossip_presence_get_state (presence_a);
+               state_b = gossip_presence_get_state (presence_b);
+
+               if (state_a < state_b) {
+                       ret_val = -1;
+               } else if (state_a > state_b) {
+                       ret_val = 1;
+               } else {
+                       /* Fallback: compare by name */
+                       ret_val = g_utf8_collate (name_a, name_b);
+               }
+       }
+
+free_and_out:
+       g_free (name_a);
+       g_free (name_b);
+
+       if (contact_a) {
+               g_object_unref (contact_a);
+       }
+
+       if (contact_b) {
+               g_object_unref (contact_b);
+       }
+
+       return ret_val;
+}
+
+static gint
+contact_list_name_sort_func (GtkTreeModel *model,
+                            GtkTreeIter  *iter_a,
+                            GtkTreeIter  *iter_b,
+                            gpointer      user_data)
 {
        gchar         *name_a, *name_b;
        GossipContact *contact_a, *contact_b;
@@ -2337,7 +2366,7 @@ contact_list_filter_show_group (GossipContactList *list,
         * group should be shown because a contact we want to
         * show exists in it.
         */
-       contacts = empathy_contact_manager_get_contacts (priv->manager);
+       contacts = empathy_contact_list_get_contacts (priv->list);
        for (l = contacts; l && !show_group; l = l->next) {
                if (!gossip_contact_is_in_group (l->data, group)) {
                        continue;
@@ -2485,28 +2514,21 @@ contact_list_action_cb (GtkAction         *action,
        group = gossip_contact_list_get_selected_group (list);
 
        if (contact && strcmp (name, "Chat") == 0) {
-               g_signal_emit (list, signals[CONTACT_CHAT], 0, contact);
+               contact_list_action_activated (list, contact);
        }
        else if (contact && strcmp (name, "Information") == 0) {
-               g_signal_emit (list, signals[CONTACT_INFORMATION], 0, contact);
        }
        else if (contact && strcmp (name, "Edit") == 0) {
-               g_signal_emit (list, signals[CONTACT_EDIT], 0, contact);
        }
        else if (contact && strcmp (name, "Remove") == 0) {
-               g_signal_emit (list, signals[CONTACT_REMOVE], 0, contact);
        }
        else if (contact && strcmp (name, "Invite") == 0) {
-               g_signal_emit (list, signals[CONTACT_INVITE], 0, contact);
        }
        else if (contact && strcmp (name, "SendFile") == 0) {
-               g_signal_emit (list, signals[CONTACT_SEND_FILE], 0, contact);
        }
        else if (contact && strcmp (name, "Log") == 0) {
-               g_signal_emit (list, signals[CONTACT_LOG], 0, contact);
        }
        else if (group && strcmp (name, "Rename") == 0) {
-               g_signal_emit (list, signals[GROUP_RENAME], 0, group);
        }
 
        g_free (group);
@@ -2515,6 +2537,22 @@ contact_list_action_cb (GtkAction         *action,
        }
 }
 
+static void
+contact_list_action_activated (GossipContactList *list,
+                              GossipContact     *contact)
+{
+       MissionControl *mc;
+
+       mc = gossip_mission_control_new ();
+       mission_control_request_channel (mc,
+                                        gossip_contact_get_account (contact),
+                                        TP_IFACE_CHANNEL_TYPE_TEXT,
+                                        gossip_contact_get_handle (contact),
+                                        TP_HANDLE_TYPE_CONTACT,
+                                        NULL, NULL);
+       g_object_unref (mc);
+}
+
 static gboolean
 contact_list_update_list_mode_foreach (GtkTreeModel      *model,
                                       GtkTreePath       *path,
@@ -2635,6 +2673,18 @@ gossip_contact_list_get_is_compact (GossipContactList *list)
        return priv->is_compact;
 }
 
+GossipContactListSort
+gossip_contact_list_get_sort_criterium (GossipContactList *list)
+{
+       GossipContactListPriv *priv;
+
+       g_return_val_if_fail (GOSSIP_IS_CONTACT_LIST (list), 0);
+
+       priv = GET_PRIV (list);
+
+       return priv->sort_criterium;
+}
+
 void
 gossip_contact_list_set_show_offline (GossipContactList *list,
                                      gboolean           show_offline)
@@ -2653,7 +2703,7 @@ gossip_contact_list_set_show_offline (GossipContactList *list,
        /* Disable temporarily. */
        priv->show_active = FALSE;
 
-       contacts = empathy_contact_manager_get_contacts (priv->manager);
+       contacts = empathy_contact_list_get_contacts (priv->list);
        for (l = contacts; l; l = l->next) {
                GossipContact *contact;
 
@@ -2711,6 +2761,33 @@ gossip_contact_list_set_is_compact (GossipContactList *list,
                                list);
 }
 
+void
+gossip_contact_list_set_sort_criterium (GossipContactList     *list,
+                                       GossipContactListSort  sort_criterium)
+{
+       GossipContactListPriv *priv;
+
+       g_return_if_fail (GOSSIP_IS_CONTACT_LIST (list));
+
+       priv = GET_PRIV (list);
+
+       priv->sort_criterium = sort_criterium;
+
+       switch (sort_criterium) {
+       case GOSSIP_CONTACT_LIST_SORT_STATE:
+               gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store),
+                                                     COL_STATUS,
+                                                     GTK_SORT_ASCENDING);
+               break;
+               
+       case GOSSIP_CONTACT_LIST_SORT_NAME:
+               gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (priv->store),
+                                                     COL_NAME,
+                                                     GTK_SORT_ASCENDING);
+               break;
+       }
+}
+
 void
 gossip_contact_list_set_filter (GossipContactList *list,
                                const gchar       *filter)