#include <gtk/gtk.h>
#include <glade/glade.h>
-#include <libtelepathy/tp-helpers.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"
#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CONTACT_LIST, GossipContactListPriv))
struct _GossipContactListPriv {
- EmpathyContactManager *manager;
+ EmpathyContactList *list;
GHashTable *groups;
gboolean show_avatars;
gboolean is_compact;
gboolean show_active;
+
+ GossipContactListSort sort_criterium;
};
typedef struct {
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,
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,
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);
GossipContactList *list);
enum {
- COL_PIXBUF_STATUS,
+ COL_ICON_STATUS,
COL_PIXBUF_AVATAR,
COL_PIXBUF_AVATAR_VISIBLE,
COL_NAME,
PROP_SHOW_OFFLINE,
PROP_SHOW_AVATARS,
PROP_IS_COMPACT,
- PROP_FILTER
+ PROP_FILTER,
+ PROP_SORT_CRITERIUM
};
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)
},
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)
},
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
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));
}
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 ();
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);
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);
}
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);
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;
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;
gboolean do_remove = FALSE;
gboolean do_set_active = FALSE;
gboolean do_set_refresh = FALSE;
- GdkPixbuf *pixbuf_presence;
GdkPixbuf *pixbuf_avatar;
priv = GET_PRIV (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),
-1);
}
- if (pixbuf_presence) {
- g_object_unref (pixbuf_presence);
- }
if (pixbuf_avatar) {
g_object_unref (pixbuf_avatar);
}
}
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;
}
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));
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,
/* 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) {
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),
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;
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);
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),
if (pixbuf_avatar) {
g_object_unref (pixbuf_avatar);
}
- if (pixbuf_status) {
- g_object_unref (pixbuf_status);
- }
if (!created) {
continue;
}
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 */
/* 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);
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;
NULL);
}
} else {
- g_object_set (cell,
- "cell-background-gdk", NULL,
- NULL);
#if 0
gint color_sum_normal;
gint color_sum_selected;
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);
}
}
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;
* 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;
{
MissionControl *mc;
- mc = mission_control_new (tp_get_bus ());
+ mc = gossip_mission_control_new ();
mission_control_request_channel (mc,
gossip_contact_get_account (contact),
TP_IFACE_CHANNEL_TYPE_TEXT,
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)
/* 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;
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)