[evince] history: Limit history depth
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince] history: Limit history depth
- Date: Tue, 18 Jun 2013 17:35:14 +0000 (UTC)
commit dd992f8d576b6a9aeec08338c14853884103e327
Author: Christian Persch <chpe gnome org>
Date: Tue Jun 18 11:47:02 2013 +0200
history: Limit history depth
shell/ev-history.c | 30 +++++++++++++++++++++++++++++-
1 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/shell/ev-history.c b/shell/ev-history.c
index 6745919..6e02370 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 {
@@ -64,6 +66,32 @@ ev_history_clear (EvHistory *history)
}
static void
+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;
+
+ /* 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);
+}
+
+static void
ev_history_finalize (GObject *object)
{
EvHistory *history = EV_HISTORY (object);
@@ -139,7 +167,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]