diff options
author | Luis de Bethencourt <luis@debethencourt.com> | 2011-05-13 18:25:33 +0200 |
---|---|---|
committer | Luis de Bethencourt <luis@debethencourt.com> | 2011-05-13 18:25:33 +0200 |
commit | 698d0736321b063c078287b863323d73bdd1cbba (patch) | |
tree | 6497c9e372a16d3e1756aeefcd29be705f3a73a6 | |
parent | 54c4559a0282890753fba2ca1bf75459d7c9fe42 (diff) |
general: remove oldest uri in the history
when the maximum number of uris are saved in the history file
remove the first on of the list.
-rw-r--r-- | src/gst_engine.c | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/gst_engine.c b/src/gst_engine.c index 3a07a98..8b75979 100644 --- a/src/gst_engine.c +++ b/src/gst_engine.c @@ -50,13 +50,14 @@ typedef enum gboolean add_uri_to_history (gchar * uri) { + gboolean ret; const gchar *config_dir; gchar *path, *data, *key; + gchar **history_keys; gsize length, max = 50; FILE *file; GKeyFile *keyfile; GKeyFileFlags flags; - gboolean ret; keyfile = g_key_file_new (); flags = G_KEY_FILE_KEEP_COMMENTS; @@ -70,15 +71,20 @@ add_uri_to_history (gchar * uri) if (g_key_file_has_group (keyfile, "history")) { if (!g_key_file_has_key (keyfile, "history", uri, NULL)) { // uri is not already in history - g_key_file_get_keys (keyfile, "history", &length, NULL); - if (length < max) - g_key_file_set_boolean (keyfile, "history", uri, TRUE); + history_keys = g_key_file_get_keys (keyfile, "history", &length, NULL); + + if (length >= max) { + // remove first uri of the list + g_key_file_remove_key (keyfile, "history", history_keys[0], NULL); + } } } else { // if group "history" doesn't exist create it and populate it g_key_file_set_boolean (keyfile, "history", uri, TRUE); } + g_key_file_set_int64 (keyfile, "history", uri, g_get_real_time ()); + // save gkeyfile to a file data = g_key_file_to_data (keyfile, NULL, NULL); file = fopen (path, "w"); |