[evince/wip/history-fix] history: Limit history depth
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/history-fix] history: Limit history depth
- Date: Tue, 18 Jun 2013 09:47:20 +0000 (UTC)
commit b3f85ed989efae3f3a26333e8839c05444f688da
Author: Christian Persch <chpe gnome org>
Date: Tue Jun 18 11:47:02 2013 +0200
history: Limit history depth
shell/ev-history.c | 31 ++++++++++++++++++++++++++++++-
1 files changed, 30 insertions(+), 1 deletions(-)
---
diff --git a/shell/ev-history.c b/shell/ev-history.c
index 6745919..b4c41aa 100644
--- a/shell/ev-history.c
+++ b/shell/ev-history.c
@@ -31,6 +31,8 @@ enum {
N_SIGNALS
};
+#define EV_HISTORY_MAX_LENGTH (32)
+
static guint signals[N_SIGNALS] = {0, };
struct _EvHistoryPrivate {
@@ -63,6 +65,33 @@ ev_history_clear (EvHistory *history)
history->priv->current = NULL;
}
+static gboolean
+ev_history_prune (EvHistory *history)
+{
+ EvHistoryPrivate *priv = history->priv;
+ GList *l;
+ guint i;
+
+ g_assert (priv->current->next == NULL);
+
+ for (i = 0, l = priv->current; i < EV_HISTORY_MAX_LENGTH && l != NULL; i++, l = l->prev)
+ /* empty */;
+
+ if (l == NULL)
+ return FALSE;
+
+ /* Throw away all history up to @l */
+ l = l->next;
+ l->prev->next = NULL;
+ l->prev = NULL;
+
+ clear_list (priv->list);
+ priv->list = l;
+
+ g_assert (g_list_length (priv->list) == EV_HISTORY_MAX_LENGTH);
+ return TRUE;
+}
+
static void
ev_history_finalize (GObject *object)
{
@@ -139,7 +168,7 @@ ev_history_add_link (EvHistory *history,
priv->current = g_list_append (NULL, g_object_ref (link));
priv->list = g_list_concat (priv->list, priv->current);
- /* TODO: Decide a history limit and delete old links when the limit is reached */
+ ev_history_prune (history);
g_signal_emit (history, signals[CHANGED], 0);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]