diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-06-07 20:53:45 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2011-06-08 17:14:20 +0800 |
commit | 49f661f321635b6b0350dbf27aec3548fbff8ee2 (patch) | |
tree | 99b208adf1d6c6f43224953534265e1f27230756 /src/empathy-main-window.c | |
parent | 92ee08109f1af2bd3862b6f1c21a7a52adb0f9a4 (diff) | |
download | gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.tar gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.tar.gz gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.tar.bz2 gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.tar.lz gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.tar.xz gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.tar.zst gsoc2013-empathy-49f661f321635b6b0350dbf27aec3548fbff8ee2.zip |
individual-store: keep track of the number of events associated with each row
Diffstat (limited to 'src/empathy-main-window.c')
-rw-r--r-- | src/empathy-main-window.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/empathy-main-window.c b/src/empathy-main-window.c index 9cc65ba61..a9e76a286 100644 --- a/src/empathy-main-window.c +++ b/src/empathy-main-window.c @@ -432,11 +432,93 @@ main_window_auth_display (EmpathyMainWindow *window, } static void +modify_event_count (GtkTreeModel *model, + GtkTreeIter *iter, + EmpathyEvent *event, + gboolean increase) +{ + FolksIndividual *individual; + EmpathyContact *contact; + guint count; + + gtk_tree_model_get (model, iter, + EMPATHY_INDIVIDUAL_STORE_COL_INDIVIDUAL, &individual, + EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, &count, + -1); + + if (individual == NULL) + return; + + increase ? count++ : count--; + + contact = empathy_contact_dup_from_folks_individual (individual); + if (contact == event->contact) { + gtk_tree_store_set (GTK_TREE_STORE (model), iter, + EMPATHY_INDIVIDUAL_STORE_COL_EVENT_COUNT, count, -1); + } + + tp_clear_object (&contact); + g_object_unref (individual); +} + +static gboolean +increase_event_count_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) +{ + EmpathyEvent *event = user_data; + + modify_event_count (model, iter, event, TRUE); + + return FALSE; +} + +static void +increase_event_count (EmpathyMainWindow *self, + EmpathyEvent *event) +{ + EmpathyMainWindowPriv *priv = GET_PRIV (self); + GtkTreeModel *model; + + model = GTK_TREE_MODEL (priv->individual_store); + + gtk_tree_model_foreach (model, increase_event_count_foreach, event); +} + +static gboolean +decrease_event_count_foreach (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data) +{ + EmpathyEvent *event = user_data; + + modify_event_count (model, iter, event, FALSE); + + return FALSE; +} + +static void +decrease_event_count (EmpathyMainWindow *self, + EmpathyEvent *event) +{ + EmpathyMainWindowPriv *priv = GET_PRIV (self); + GtkTreeModel *model; + + model = GTK_TREE_MODEL (priv->individual_store); + + gtk_tree_model_foreach (model, decrease_event_count_foreach, event); +} + +static void main_window_event_added_cb (EmpathyEventManager *manager, EmpathyEvent *event, EmpathyMainWindow *window) { if (event->contact) { + increase_event_count (window, event); + main_window_flash_start (window); } else if (event->type == EMPATHY_EVENT_TYPE_AUTH) { main_window_auth_display (window, event); @@ -460,6 +542,8 @@ main_window_event_removed_cb (EmpathyEventManager *manager, return; } + decrease_event_count (window, event); + data.on = FALSE; data.event = event; data.window = window; |