diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-03-27 20:03:07 +0800 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2012-03-27 20:03:07 +0800 |
commit | 85bf02f460934eed3ad39bf830c70331a3c76ecc (patch) | |
tree | 83e0465f1d8d62f998515094955e4ec8efb98f32 /libempathy-gtk/empathy-log-window.c | |
parent | 5ef40a9e35ff8c558d423e1bb5b48d6554f72f31 (diff) | |
download | gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.tar gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.tar.gz gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.tar.bz2 gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.tar.lz gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.tar.xz gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.tar.zst gsoc2013-empathy-85bf02f460934eed3ad39bf830c70331a3c76ecc.zip |
log-window: factor out add_date_if_needed()
Free a leak as 'text' wasn't freed in the first case.
Diffstat (limited to 'libempathy-gtk/empathy-log-window.c')
-rw-r--r-- | libempathy-gtk/empathy-log-window.c | 65 |
1 files changed, 33 insertions, 32 deletions
diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index 13fdefbd5..e5cc066c2 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -1747,6 +1747,37 @@ format_date_for_display (GDate *date) } static void +add_date_if_needed (EmpathyLogWindow *self, + GDate *date) +{ + GtkTreeModel *model; + GtkListStore *store; + gchar *text; + GtkTreeIter iter; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW ( + log_window->priv->treeview_when)); + store = GTK_LIST_STORE (model); + + /* Add the date if it's not already there */ + has_element = FALSE; + gtk_tree_model_foreach (model, model_has_date, date); + if (has_element) + return; + + text = format_date_for_display (date); + + gtk_list_store_append (store, &iter); + gtk_list_store_set (store, &iter, + COL_WHEN_DATE, date, + COL_WHEN_TEXT, text, + COL_WHEN_ICON, CALENDAR_ICON, + -1); + + g_free (text); +} + +static void populate_dates_from_search_hits (GList *accounts, GList *targets) { @@ -1790,20 +1821,7 @@ populate_dates_from_search_hits (GList *accounts, if (!found) continue; - /* Add the date if it's not already there */ - has_element = FALSE; - gtk_tree_model_foreach (model, model_has_date, hit->date); - if (!has_element) - { - gchar *text = format_date_for_display (hit->date); - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COL_WHEN_DATE, hit->date, - COL_WHEN_TEXT, text, - COL_WHEN_ICON, CALENDAR_ICON, - -1); - } + add_date_if_needed (log_window, hit->date); } if (gtk_tree_model_get_iter_first (model, &iter)) @@ -3434,24 +3452,7 @@ log_manager_got_dates_cb (GObject *manager, for (l = dates; l != NULL; l = l->next) { - GDate *date = l->data; - - /* Add the date if it's not already there */ - has_element = FALSE; - gtk_tree_model_foreach (model, model_has_date, date); - if (!has_element) - { - gchar *text = format_date_for_display (date); - - gtk_list_store_append (store, &iter); - gtk_list_store_set (store, &iter, - COL_WHEN_DATE, date, - COL_WHEN_TEXT, text, - COL_WHEN_ICON, CALENDAR_ICON, - -1); - - g_free (text); - } + add_date_if_needed (log_window, l->data); } if (gtk_tree_model_get_iter_first (model, &iter)) |