#include "config.h"
-
#include "empathy-roster-view.h"
#include <glib/gi18n-lib.h>
-#include <libempathy-gtk/empathy-roster-contact.h>
-#include <libempathy-gtk/empathy-roster-group.h>
-#include <libempathy-gtk/empathy-ui-utils.h>
-
-#include <libempathy/empathy-utils.h>
+#include "empathy-contact-groups.h"
+#include "empathy-roster-contact.h"
+#include "empathy-roster-group.h"
+#include "empathy-ui-utils.h"
-G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, EGG_TYPE_LIST_BOX)
+G_DEFINE_TYPE (EmpathyRosterView, empathy_roster_view, GTK_TYPE_LIST_BOX)
/* Flashing delay for icons (milliseconds). */
#define FLASH_TIMEOUT 500
+/* Delay in milliseconds between the last stroke on the keyboard and the start
+ * of the live search. */
+#define SEARCH_TIMEOUT 500
+
enum
{
- PROP_MANAGER = 1,
- PROP_MODEL,
+ PROP_MODEL = 1,
PROP_SHOW_OFFLINE,
PROP_SHOW_GROUPS,
PROP_EMPTY,
struct _EmpathyRosterViewPriv
{
- EmpathyIndividualManager *manager;
-
/* FolksIndividual (borrowed) -> GHashTable (
* (gchar * group_name) -> EmpathyRosterContact (borrowed))
*
guint flash_id;
gboolean display_flash_event;
+ guint search_id;
+
gboolean show_offline;
gboolean show_groups;
gboolean empty;
- EmpathyLiveSearch *search;
+ TpawLiveSearch *search;
EmpathyRosterModel *model;
};
+/* Prototypes to break cycles */
+static void remove_from_group (EmpathyRosterView *self,
+ FolksIndividual *individual,
+ const gchar *group);
+
typedef struct
{
guint id;
switch (property_id)
{
- case PROP_MANAGER:
- g_value_set_object (value, self->priv->manager);
- break;
case PROP_MODEL:
g_value_set_object (value, self->priv->model);
break;
switch (property_id)
{
- case PROP_MANAGER:
- g_assert (self->priv->manager == NULL); /* construct only */
- self->priv->manager = g_value_dup_object (value);
- break;
case PROP_MODEL:
g_assert (self->priv->model == NULL);
self->priv->model = g_value_dup_object (value);
}
static void
-roster_contact_changed_cb (GtkWidget *child,
+roster_contact_changed_cb (GtkListBoxRow *child,
GParamSpec *spec,
EmpathyRosterView *self)
{
- egg_list_box_child_changed (EGG_LIST_BOX (self), child);
+ gtk_list_box_row_changed (child);
}
static GtkWidget *
g_signal_connect (contact, "notify::alias",
G_CALLBACK (roster_contact_changed_cb), self);
+ /* Need to resort if most recent event changed */
+ g_signal_connect (contact, "notify::most-recent-event",
+ G_CALLBACK (roster_contact_changed_cb), self);
+
gtk_widget_show (contact);
gtk_container_add (GTK_CONTAINER (self), contact);
}
static void
-group_expanded_cb (EmpathyRosterGroup *group,
+group_expanded_cb (GtkWidget *expander,
GParamSpec *spec,
- EmpathyRosterView *self)
+ EmpathyRosterGroup *group)
{
GList *widgets, *l;
widgets = empathy_roster_group_get_widgets (group);
for (l = widgets; l != NULL; l = g_list_next (l))
{
- egg_list_box_child_changed (EGG_LIST_BOX (self), l->data);
+ gtk_list_box_row_changed (l->data);
}
g_list_free (widgets);
+
+ empathy_contact_group_set_expanded (empathy_roster_group_get_name (group),
+ gtk_expander_get_expanded (group->expander));
}
static EmpathyRosterGroup *
if (roster_group != NULL)
return EMPATHY_ROSTER_GROUP (roster_group);
- if (!tp_strdiff (group, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
+ if (!tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
roster_group = empathy_roster_group_new (group, "emblem-favorite-symbolic");
- else if (!tp_strdiff (group, EMPATHY_ROSTER_VIEW_GROUP_PEOPLE_NEARBY))
+ else if (!tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_PEOPLE_NEARBY))
roster_group = empathy_roster_group_new (group, "im-local-xmpp");
else
roster_group = empathy_roster_group_new (group, NULL);
- g_signal_connect (roster_group, "notify::expanded",
- G_CALLBACK (group_expanded_cb), self);
+ gtk_expander_set_expanded (EMPATHY_ROSTER_GROUP (roster_group)->expander,
+ empathy_contact_group_get_expanded (group));
+
+ g_signal_connect (EMPATHY_ROSTER_GROUP (roster_group)->expander,
+ "notify::expanded", G_CALLBACK (group_expanded_cb), roster_group);
gtk_widget_show (roster_group);
gtk_container_add (GTK_CONTAINER (self), roster_group);
return EMPATHY_ROSTER_GROUP (roster_group);
}
+static void
+update_empty (EmpathyRosterView *self,
+ gboolean empty)
+{
+ if (self->priv->empty == empty)
+ return;
+
+ self->priv->empty = empty;
+ g_object_notify (G_OBJECT (self), "empty");
+}
+
+static gboolean filter_group (EmpathyRosterView *self,
+ EmpathyRosterGroup *group);
+
+static gboolean
+at_least_one_group_displayed (EmpathyRosterView *self)
+{
+ GHashTableIter iter;
+ gpointer v;
+
+ g_hash_table_iter_init (&iter, self->priv->roster_groups);
+ while (g_hash_table_iter_next (&iter, NULL, &v))
+ {
+ EmpathyRosterGroup *group = EMPATHY_ROSTER_GROUP (v);
+
+ if (filter_group (self, group))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+static void
+check_if_empty (EmpathyRosterView *self)
+{
+ /* Roster is considered as empty if there is no contact *and* no group
+ * currently displayed. */
+ if (g_hash_table_size (self->priv->displayed_contacts) != 0 ||
+ at_least_one_group_displayed (self))
+ {
+ update_empty (self, FALSE);
+ return;
+ }
+
+ update_empty (self, TRUE);
+}
+
static void
update_group_widgets (EmpathyRosterView *self,
EmpathyRosterGroup *group,
count = empathy_roster_group_remove_widget (group, GTK_WIDGET (contact));
if (count != old_count)
- egg_list_box_child_changed (EGG_LIST_BOX (self), GTK_WIDGET (group));
+ {
+ gtk_list_box_row_changed (GTK_LIST_BOX_ROW (group));
+
+ check_if_empty (self);
+ }
}
static void
if (contacts == NULL)
return;
+ if (g_hash_table_lookup (contacts, group) != NULL)
+ return;
+
if (tp_strdiff (group, NO_GROUP))
roster_group = ensure_roster_group (self, group);
update_group_widgets (self, roster_group,
EMPATHY_ROSTER_CONTACT (contact), TRUE);
}
+
+ if (tp_strdiff (group, NO_GROUP) &&
+ tp_strdiff (group, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED) &&
+ g_hash_table_size (contacts) == 2 /* 1:Ungrouped and 2:first group */)
+ {
+ remove_from_group (self, individual,
+ EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
+ }
+}
+
+static void
+individual_favourite_change_cb (FolksIndividual *individual,
+ GParamSpec *spec,
+ EmpathyRosterView *self)
+{
+ /* We may have to refilter the contact as only favorite contacts are always
+ * displayed regardless of their presence. */
+ GHashTable *contacts;
+ GtkWidget *contact;
+
+ contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
+ if (contacts == NULL)
+ return;
+
+ if (self->priv->show_groups)
+ contact = g_hash_table_lookup (contacts,
+ EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP);
+ else
+ contact = g_hash_table_lookup (contacts, NO_GROUP);
+
+ if (contact == NULL)
+ return;
+
+ gtk_list_box_row_changed (GTK_LIST_BOX_ROW (contact));
}
static void
else
{
GList *groups, *l;
- GList *tops;
-
- tops = empathy_roster_model_get_top_individuals (self->priv->model);
- if (folks_favourite_details_get_is_favourite (
- FOLKS_FAVOURITE_DETAILS (individual)) ||
- g_list_index (tops, individual) != -1)
- {
- add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
- }
-
- groups = empathy_roster_model_get_groups_for_individual (self->priv->model,
+ groups = empathy_roster_model_dup_groups_for_individual (self->priv->model,
individual);
if (g_list_length (groups) > 0)
else
{
/* No group, adds to Ungrouped */
- add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED);
+ add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
}
- g_list_free (groups);
+ g_list_free_full (groups, g_free);
}
+
+ tp_g_signal_connect_object (individual, "notify::is-favourite",
+ G_CALLBACK (individual_favourite_change_cb), self, 0);
}
static void
individual_removed (self, individual);
}
-static gint
-compare_roster_contacts_by_alias (EmpathyRosterContact *a,
- EmpathyRosterContact *b)
+static gboolean
+contact_in_top (EmpathyRosterView *self,
+ EmpathyRosterContact *contact)
{
- FolksIndividual *ind_a, *ind_b;
- const gchar *alias_a, *alias_b;
+ if (!self->priv->show_groups)
+ {
+ /* Always display top contacts in non-group mode. */
+ GList *groups;
+ FolksIndividual *individual;
+ gboolean result = FALSE;
- ind_a = empathy_roster_contact_get_individual (a);
- ind_b = empathy_roster_contact_get_individual (b);
+ individual = empathy_roster_contact_get_individual (contact);
- alias_a = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_a));
- alias_b = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_b));
+ groups = empathy_roster_model_dup_groups_for_individual (
+ self->priv->model, individual);
- return g_ascii_strcasecmp (alias_a, alias_b);
-}
+ if (g_list_find_custom (groups, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP,
+ (GCompareFunc) g_strcmp0) != NULL)
+ result = TRUE;
-static gboolean
-contact_is_favourite (EmpathyRosterContact *contact)
-{
- FolksIndividual *individual;
+ g_list_free_full (groups, g_free);
- individual = empathy_roster_contact_get_individual (contact);
+ return result;
+ }
- return folks_favourite_details_get_is_favourite (
- FOLKS_FAVOURITE_DETAILS (individual));
+ if (!tp_strdiff (empathy_roster_contact_get_group (contact),
+ EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
+ /* If we are displaying contacts, we only want to *always* display the
+ * RosterContact which is displayed at the top; not the ones displayed in
+ * the 'normal' group sections */
+ return TRUE;
+
+ return FALSE;
}
-static gboolean
-contact_in_top (EmpathyRosterView *self,
- EmpathyRosterContact *contact)
+static gint
+compare_roster_contacts_by_conversation_time (EmpathyRosterContact *a,
+ EmpathyRosterContact *b)
{
- FolksIndividual *individual;
- GList *tops;
+ gint64 ts_a, ts_b;
- if (contact_is_favourite (contact))
- return TRUE;
+ ts_a = empathy_roster_contact_get_most_recent_timestamp (a);
+ ts_b = empathy_roster_contact_get_most_recent_timestamp (b);
- individual = empathy_roster_contact_get_individual (contact);
+ if (ts_a == ts_b) return 0;
+ if (ts_a > ts_b) return -1;
+ return 1;
+}
- tops = empathy_roster_model_get_top_individuals (self->priv->model);
+static gint
+compare_roster_contacts_by_alias (EmpathyRosterContact *a,
+ EmpathyRosterContact *b)
+{
+ FolksIndividual *ind_a, *ind_b;
+ const gchar *alias_a, *alias_b;
- if (g_list_index (tops, individual) != -1)
- return TRUE;
+ ind_a = empathy_roster_contact_get_individual (a);
+ ind_b = empathy_roster_contact_get_individual (b);
- return FALSE;
+ alias_a = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_a));
+ alias_b = folks_alias_details_get_alias (FOLKS_ALIAS_DETAILS (ind_b));
+
+ return g_utf8_collate (alias_a, alias_b);
}
static gint
if (top_a == top_b)
/* Both contacts are in the top of the roster (or not). Sort them
* alphabetically */
- return compare_roster_contacts_by_alias (a, b);
+ return compare_roster_contacts_by_conversation_time (a, b);
else if (top_a)
return -1;
else
compare_group_names (const gchar *group_a,
const gchar *group_b)
{
- if (!tp_strdiff (group_a, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
+ if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
return -1;
- if (!tp_strdiff (group_b, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
+ if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_TOP_GROUP))
return 1;
- if (!tp_strdiff (group_a, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED))
+ if (!tp_strdiff (group_a, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
return 1;
- else if (!tp_strdiff (group_b, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED))
+ else if (!tp_strdiff (group_b, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED))
return -1;
- return g_ascii_strcasecmp (group_a, group_b);
+ return g_utf8_collate (group_a, group_b);
}
static gint
if (!tp_strdiff (group_a, group_b))
/* Same group, compare the contacts */
- return compare_roster_contacts_by_alias (a, b);
+ return compare_roster_contacts_by_conversation_time (a, b);
/* Sort by group */
return compare_group_names (group_a, group_b);
}
static gint
-roster_view_sort (gconstpointer a,
- gconstpointer b,
+roster_view_sort (GtkListBoxRow *a,
+ GtkListBoxRow *b,
gpointer user_data)
{
EmpathyRosterView *self = user_data;
}
static void
-update_separator (GtkWidget **separator,
- GtkWidget *child,
- GtkWidget *before,
+update_header (GtkListBoxRow *row,
+ GtkListBoxRow *before,
gpointer user_data)
{
if (before == NULL)
{
/* No separator before the first row */
- g_clear_object (separator);
+ gtk_list_box_row_set_header (row, NULL);
return;
}
- if (*separator != NULL)
+ if (gtk_list_box_row_get_header (row) != NULL)
return;
- *separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
- g_object_ref_sink (*separator);
+ gtk_list_box_row_set_header (row,
+ gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
}
static gboolean
return gtk_widget_get_visible (GTK_WIDGET (self->priv->search));
}
-static void
-update_empty (EmpathyRosterView *self,
- gboolean empty)
-{
- if (self->priv->empty == empty)
- return;
-
- self->priv->empty = empty;
- g_object_notify (G_OBJECT (self), "empty");
-}
-
static void
add_to_displayed (EmpathyRosterView *self,
EmpathyRosterContact *contact)
while (g_hash_table_iter_next (&iter, &k, NULL))
{
const gchar *group_name = k;
- GtkWidget *group;
+ GtkListBoxRow *group;
group = g_hash_table_lookup (self->priv->roster_groups, group_name);
if (group == NULL)
continue;
- egg_list_box_child_changed (EGG_LIST_BOX (self), group);
+ gtk_list_box_row_changed (group);
}
}
{
g_hash_table_remove (self->priv->displayed_contacts, contact);
- if (g_hash_table_size (self->priv->displayed_contacts) == 0)
- update_empty (self, TRUE);
+ check_if_empty (self);
+}
+
+static gboolean
+contact_is_favorite (EmpathyRosterContact *contact)
+{
+ FolksIndividual *individual;
+
+ individual = empathy_roster_contact_get_individual (contact);
+
+ return folks_favourite_details_get_is_favourite (
+ FOLKS_FAVOURITE_DETAILS (individual));
}
/**
individual = empathy_roster_contact_get_individual (contact);
return empathy_individual_match_string (individual,
- empathy_live_search_get_text (self->priv->search),
- empathy_live_search_get_words (self->priv->search));
+ tpaw_live_search_get_text (self->priv->search),
+ tpaw_live_search_get_words (self->priv->search));
}
if (self->priv->show_offline)
return TRUE;
- if (contact_is_favourite (contact))
- {
- const gchar *group_name;
-
- if (!self->priv->show_groups)
- /* Always display favourite contacts in non-group mode. */
- return TRUE;
-
- group_name = empathy_roster_contact_get_group (contact);
-
- if (!tp_strdiff (group_name, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP))
- /* Always display favourite contact in group mode only in the
- * 'top group'*/
- return TRUE;
- }
+ if (contact_in_top (self, contact) &&
+ contact_is_favorite (contact))
+ /* Favorite top contacts are always displayed */
+ return TRUE;
return empathy_roster_contact_is_online (contact);
}
{
/* When searching, always display even if the group is closed */
if (!is_searching (self) &&
- !gtk_expander_get_expanded (GTK_EXPANDER (group)))
+ !gtk_expander_get_expanded (group->expander))
displayed = FALSE;
}
}
EmpathyRosterGroup *group)
{
GList *widgets, *l;
+ gboolean result = FALSE;
/* Display the group if it contains at least one displayed contact */
widgets = empathy_roster_group_get_widgets (group);
EmpathyRosterContact *contact = l->data;
if (contact_should_be_displayed (self, contact))
- return TRUE;
+ {
+ result = TRUE;
+ break;
+ }
}
- return FALSE;
+ g_list_free (widgets);
+
+ return result;
}
static gboolean
-filter_list (GtkWidget *child,
+filter_list (GtkListBoxRow *child,
gpointer user_data)
{
EmpathyRosterView *self = user_data;
g_return_val_if_reached (FALSE);
}
-/* @list: GList of EmpathyRosterContact
- *
- * Returns: %TRUE if @list contains an EmpathyRosterContact associated with
- * @individual */
-static gboolean
-individual_in_list (FolksIndividual *individual,
- GList *list)
-{
- GList *l;
-
- for (l = list; l != NULL; l = g_list_next (l))
- {
- EmpathyRosterContact *contact = l->data;
-
- if (empathy_roster_contact_get_individual (contact) == individual)
- return TRUE;
- }
-
- return FALSE;
-}
-
static void
populate_view (EmpathyRosterView *self)
{
if (g_hash_table_size (contacts) == 0)
{
- add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_UNGROUPED);
+ add_to_group (self, individual, EMPATHY_ROSTER_MODEL_GROUP_UNGROUPED);
}
roster_group = lookup_roster_group (self, group);
gtk_container_remove (GTK_CONTAINER (self), contact);
}
-static void
-update_top_contacts (EmpathyRosterView *self)
-{
- GList *tops, *l;
- GList *to_add = NULL, *to_remove = NULL;
- EmpathyRosterGroup *group;
-
- if (!self->priv->show_groups)
- {
- egg_list_box_resort (EGG_LIST_BOX (self));
- return;
- }
-
- tops = empathy_roster_model_get_top_individuals (self->priv->model);
-
- group = g_hash_table_lookup (self->priv->roster_groups,
- EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
- if (group == NULL)
- {
- to_add = g_list_copy (tops);
- }
- else
- {
- GList *contacts;
-
- contacts = empathy_roster_group_get_widgets (group);
-
- /* Check which EmpathyRosterContact have to be removed */
- for (l = contacts; l != NULL; l = g_list_next (l))
- {
- EmpathyRosterContact *contact = l->data;
- FolksIndividual *individual;
-
- if (contact_is_favourite (contact))
- continue;
-
- individual = empathy_roster_contact_get_individual (contact);
-
- if (g_list_find (tops, individual) == NULL)
- to_remove = g_list_prepend (to_remove, individual);
- }
-
- /* Check which EmpathyRosterContact have to be added */
- for (l = tops; l != NULL; l = g_list_next (l))
- {
- FolksIndividual *individual = l->data;
-
- if (!individual_in_list (individual, contacts))
- to_add = g_list_prepend (to_add, individual);
- }
- }
-
- for (l = to_add; l != NULL; l = g_list_next (l))
- add_to_group (self, l->data, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-
- for (l = to_remove; l != NULL; l = g_list_next (l))
- remove_from_group (self, l->data, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
-
- g_list_free (to_add);
- g_list_free (to_remove);
-}
-
static void
groups_changed_cb (EmpathyRosterModel *model,
FolksIndividual *individual,
EmpathyRosterView *self)
{
if (!self->priv->show_groups)
- return;
+ {
+ gtk_list_box_invalidate_sort (GTK_LIST_BOX (self));
+ return;
+ }
if (is_member)
{
}
}
-static void
-top_individuals_changed_cb (EmpathyRosterModel *model,
- EmpathyRosterView *self)
-{
- update_top_contacts (self);
-}
-
-static void
-favourites_changed_cb (EmpathyIndividualManager *manager,
- FolksIndividual *individual,
- gboolean favourite,
- EmpathyRosterView *self)
-{
- GHashTable *contacts;
-
- contacts = g_hash_table_lookup (self->priv->roster_contacts, individual);
- if (contacts == NULL)
- return;
-
- if (self->priv->show_groups)
- {
- if (favourite)
- add_to_group (self, individual, EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
- else
- remove_from_group (self, individual,
- EMPATHY_ROSTER_VIEW_GROUP_TOP_GROUP);
- }
- else
- {
- GtkWidget *contact;
-
- contact = g_hash_table_lookup (contacts, NO_GROUP);
- if (contact == NULL)
- return;
-
- egg_list_box_child_changed (EGG_LIST_BOX (self), contact);
- }
-}
-
static void
empathy_roster_view_constructed (GObject *object)
{
if (chain_up != NULL)
chain_up (object);
- g_assert (EMPATHY_IS_INDIVIDUAL_MANAGER (self->priv->manager));
g_assert (EMPATHY_IS_ROSTER_MODEL (self->priv->model));
+ /* Get saved group states. */
+ empathy_contact_groups_get_all ();
+
populate_view (self);
tp_g_signal_connect_object (self->priv->model, "individual-added",
G_CALLBACK (individual_removed_cb), self, 0);
tp_g_signal_connect_object (self->priv->model, "groups-changed",
G_CALLBACK (groups_changed_cb), self, 0);
- tp_g_signal_connect_object (self->priv->model, "top-individuals-changed",
- G_CALLBACK (top_individuals_changed_cb), self, 0);
- tp_g_signal_connect_object (self->priv->manager, "notify::favourites-changed",
- G_CALLBACK (favourites_changed_cb), self, 0);
- egg_list_box_set_sort_func (EGG_LIST_BOX (self),
+ gtk_list_box_set_sort_func (GTK_LIST_BOX (self),
roster_view_sort, self, NULL);
- egg_list_box_set_separator_funcs (EGG_LIST_BOX (self), update_separator,
- self, NULL);
+ gtk_list_box_set_header_func (GTK_LIST_BOX (self), update_header, self, NULL);
- egg_list_box_set_filter_func (EGG_LIST_BOX (self), filter_list, self, NULL);
+ gtk_list_box_set_filter_func (GTK_LIST_BOX (self), filter_list, self, NULL);
- egg_list_box_set_activate_on_single_click (EGG_LIST_BOX (self), FALSE);
+ gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (self), FALSE);
+}
+
+static void
+clear_view (EmpathyRosterView *self)
+{
+ g_hash_table_remove_all (self->priv->roster_contacts);
+ g_hash_table_remove_all (self->priv->roster_groups);
+ g_hash_table_remove_all (self->priv->displayed_contacts);
+
+ gtk_container_foreach (GTK_CONTAINER (self),
+ (GtkCallback) gtk_widget_destroy, NULL);
}
static void
void (*chain_up) (GObject *) =
((GObjectClass *) empathy_roster_view_parent_class)->dispose;
+ /* Start by clearing the view so our internal hash tables are cleared from
+ * objects being destroyed. */
+ clear_view (self);
+
stop_flashing (self);
empathy_roster_view_set_live_search (self, NULL);
- g_clear_object (&self->priv->manager);
g_clear_object (&self->priv->model);
+ if (self->priv->search_id != 0)
+ {
+ g_source_remove (self->priv->search_id);
+ self->priv->search_id = 0;
+ }
+
if (chain_up != NULL)
chain_up (object);
}
}
static void
-empathy_roster_view_child_activated (EggListBox *box,
- GtkWidget *child)
+empathy_roster_view_row_activated (GtkListBox *box,
+ GtkListBoxRow *row)
{
EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (box);
EmpathyRosterContact *contact;
FolksIndividual *individual;
GList *l;
- if (!EMPATHY_IS_ROSTER_CONTACT (child))
+ if (!EMPATHY_IS_ROSTER_CONTACT (row))
return;
- contact = EMPATHY_ROSTER_CONTACT (child);
+ contact = EMPATHY_ROSTER_CONTACT (row);
individual = empathy_roster_contact_get_individual (contact);
/* Activate the oldest event associated with this contact, if any */
static void
fire_popup_individual_menu (EmpathyRosterView *self,
- GtkWidget *child,
+ GtkListBoxRow *row,
guint button,
guint time)
{
EmpathyRosterContact *contact;
FolksIndividual *individual;
+ const gchar *active_group;
- if (!EMPATHY_IS_ROSTER_CONTACT (child))
+ if (!EMPATHY_IS_ROSTER_CONTACT (row))
return;
- contact = EMPATHY_ROSTER_CONTACT (child);
+ contact = EMPATHY_ROSTER_CONTACT (row);
individual = empathy_roster_contact_get_individual (contact);
+ active_group = empathy_roster_contact_get_group (contact);
g_signal_emit (self, signals[SIG_POPUP_INDIVIDUAL_MENU], 0,
- individual, button, time);
+ active_group, individual, button, time);
}
static gboolean
if (event->button == 3)
{
- GtkWidget *child;
+ GtkListBoxRow *row;
- child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), event->y);
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (self), event->y);
- if (child != NULL)
+ if (row != NULL)
{
- egg_list_box_select_child (EGG_LIST_BOX (self), child);
+ gtk_list_box_select_row (GTK_LIST_BOX (self), row);
- fire_popup_individual_menu (self, child, event->button, event->time);
+ fire_popup_individual_menu (self, row, event->button, event->time);
}
}
if (event->keyval == GDK_KEY_Menu)
{
- GtkWidget *child;
+ GtkListBoxRow *row;
- child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
+ row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self));
- if (child != NULL)
- fire_popup_individual_menu (self, child, 0, event->time);
+ if (row != NULL)
+ fire_popup_individual_menu (self, row, 0, event->time);
}
return chain_up (widget, event);
}
/**
- * @out_child: (out) (allow-none)
+ * @out_row: (out) (allow-none)
*/
FolksIndividual *
empathy_roster_view_get_individual_at_y (EmpathyRosterView *self,
gint y,
- GtkWidget **out_child)
+ GtkListBoxRow **out_row)
{
- GtkWidget *child;
+ GtkListBoxRow *row;
- child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (self), y);
- if (out_child != NULL)
- *out_child = child;
+ if (out_row != NULL)
+ *out_row = row;
- if (!EMPATHY_IS_ROSTER_CONTACT (child))
+ if (!EMPATHY_IS_ROSTER_CONTACT (row))
return NULL;
- return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
+ return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (row));
}
-/**
- * @out_child: (out) (allow-none)
- */
const gchar *
empathy_roster_view_get_group_at_y (EmpathyRosterView *self,
gint y)
{
- GtkWidget *child;
+ GtkListBoxRow *row;
- child = egg_list_box_get_child_at_y (EGG_LIST_BOX (self), y);
+ row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (self), y);
- if (EMPATHY_IS_ROSTER_CONTACT (child))
- return empathy_roster_contact_get_group (EMPATHY_ROSTER_CONTACT (child));
- else if (EMPATHY_IS_ROSTER_GROUP (child))
- return empathy_roster_group_get_name (EMPATHY_ROSTER_GROUP (child));
+ if (EMPATHY_IS_ROSTER_CONTACT (row))
+ return empathy_roster_contact_get_group (EMPATHY_ROSTER_CONTACT (row));
+ else if (EMPATHY_IS_ROSTER_GROUP (row))
+ return empathy_roster_group_get_name (EMPATHY_ROSTER_GROUP (row));
return NULL;
}
EmpathyRosterView *self = EMPATHY_ROSTER_VIEW (widget);
FolksIndividual *individual;
gboolean result;
- GtkWidget *child;
+ GtkListBoxRow *row;
- individual = empathy_roster_view_get_individual_at_y (self, y, &child);
+ individual = empathy_roster_view_get_individual_at_y (self, y, &row);
if (individual == NULL)
return FALSE;
{
GtkAllocation allocation;
- gtk_widget_get_allocation (child, &allocation);
+ gtk_widget_get_allocation (GTK_WIDGET (row), &allocation);
gtk_tooltip_set_tip_area (tooltip, (GdkRectangle *) &allocation);
}
EmpathyRosterViewClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
- EggListBoxClass *box_class = EGG_LIST_BOX_CLASS (klass);
+ GtkListBoxClass *box_class = GTK_LIST_BOX_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GParamSpec *spec;
container_class->remove = empathy_roster_view_remove;
- box_class->child_activated = empathy_roster_view_child_activated;
-
- spec = g_param_spec_object ("manager", "Manager",
- "EmpathyIndividualManager",
- EMPATHY_TYPE_INDIVIDUAL_MANAGER,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
- g_object_class_install_property (oclass, PROP_MANAGER, spec);
+ box_class->row_activated = empathy_roster_view_row_activated;
spec = g_param_spec_object ("model", "Model",
"EmpathyRosterModel",
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
- 3, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT, G_TYPE_UINT);
+ 4, G_TYPE_STRING, FOLKS_TYPE_INDIVIDUAL, G_TYPE_UINT,
+ G_TYPE_UINT);
signals[SIG_EVENT_ACTIVATED] = g_signal_new ("event-activated",
G_OBJECT_CLASS_TYPE (klass),
}
GtkWidget *
-empathy_roster_view_new (EmpathyIndividualManager *manager,
- EmpathyRosterModel *model)
+empathy_roster_view_new (EmpathyRosterModel *model)
{
- g_return_val_if_fail (EMPATHY_IS_INDIVIDUAL_MANAGER (manager), NULL);
g_return_val_if_fail (EMPATHY_IS_ROSTER_MODEL (model), NULL);
return g_object_new (EMPATHY_TYPE_ROSTER_VIEW,
- "manager", manager,
"model", model,
NULL);
}
-EmpathyIndividualManager *
-empathy_roster_view_get_manager (EmpathyRosterView *self)
-{
- return self->priv->manager;
-}
-
void
empathy_roster_view_show_offline (EmpathyRosterView *self,
gboolean show)
return;
self->priv->show_offline = show;
- egg_list_box_refilter (EGG_LIST_BOX (self));
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (self));
g_object_notify (G_OBJECT (self), "show-offline");
}
-static void
-clear_view (EmpathyRosterView *self)
-{
- gtk_container_foreach (GTK_CONTAINER (self),
- (GtkCallback) gtk_widget_destroy, NULL);
-
- g_hash_table_remove_all (self->priv->roster_contacts);
- g_hash_table_remove_all (self->priv->roster_groups);
- g_hash_table_remove_all (self->priv->displayed_contacts);
-}
-
void
empathy_roster_view_show_groups (EmpathyRosterView *self,
gboolean show)
if (!EMPATHY_IS_ROSTER_CONTACT (child))
continue;
- egg_list_box_select_child (EGG_LIST_BOX (self), child);
+ gtk_list_box_select_row (GTK_LIST_BOX (self), GTK_LIST_BOX_ROW (child));
break;
}
g_list_free (children);
}
+static gboolean
+search_timeout_cb (EmpathyRosterView *self)
+{
+ gtk_list_box_invalidate_filter (GTK_LIST_BOX (self));
+
+ select_first_contact (self);
+
+ self->priv->search_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
static void
-search_text_notify_cb (EmpathyLiveSearch *search,
+search_text_notify_cb (TpawLiveSearch *search,
GParamSpec *pspec,
EmpathyRosterView *self)
{
- egg_list_box_refilter (EGG_LIST_BOX (self));
+ if (self->priv->search_id != 0)
+ g_source_remove (self->priv->search_id);
- select_first_contact (self);
+ self->priv->search_id = g_timeout_add (SEARCH_TIMEOUT,
+ (GSourceFunc) search_timeout_cb, self);
}
static void
search_activate_cb (GtkWidget *search,
EmpathyRosterView *self)
{
- EggListBox *box = EGG_LIST_BOX (self);
- GtkWidget *child;
+ GtkListBox *box = GTK_LIST_BOX (self);
+ GtkListBoxRow *row;
- child = egg_list_box_get_selected_child (box);
- if (child == NULL)
+ row = gtk_list_box_get_selected_row (box);
+ if (row == NULL)
return;
- empathy_roster_view_child_activated (box, child);
+ empathy_roster_view_row_activated (box, row);
}
void
empathy_roster_view_set_live_search (EmpathyRosterView *self,
- EmpathyLiveSearch *search)
+ TpawLiveSearch *search)
{
if (self->priv->search != NULL)
{
FolksIndividual *
empathy_roster_view_get_selected_individual (EmpathyRosterView *self)
{
- GtkWidget *child;
+ GtkListBoxRow *row;
- child = egg_list_box_get_selected_child (EGG_LIST_BOX (self));
+ row = gtk_list_box_get_selected_row (GTK_LIST_BOX (self));
- if (!EMPATHY_IS_ROSTER_CONTACT (child))
+ if (!EMPATHY_IS_ROSTER_CONTACT (row))
return NULL;
- return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (child));
+ return empathy_roster_contact_get_individual (EMPATHY_ROSTER_CONTACT (row));
}