diff options
author | Luis de Bethencourt <luis.debethencourt@collabora.com> | 2011-05-13 17:25:03 +0200 |
---|---|---|
committer | Luis de Bethencourt <luis@debethencourt.com> | 2011-05-13 17:28:21 +0200 |
commit | 54c4559a0282890753fba2ca1bf75459d7c9fe42 (patch) | |
tree | f9b8f9825ca687b39d5ac838701bfca16f629e3e | |
parent | 019369de93a9dbb03b822859cb0d3681023b8ef8 (diff) |
general: save uris of played files in the history
save a history of the 50 last played files in the
~/.config/snappy/history file.
-rw-r--r-- | src/gst_engine.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/gst_engine.c b/src/gst_engine.c index 676867f..3a07a98 100644 --- a/src/gst_engine.c +++ b/src/gst_engine.c @@ -48,6 +48,55 @@ typedef enum /* -------------------- static functions --------------------- */ gboolean +add_uri_to_history (gchar * uri) +{ + const gchar *config_dir; + gchar *path, *data, *key; + gsize length, max = 50; + FILE *file; + GKeyFile *keyfile; + GKeyFileFlags flags; + gboolean ret; + + keyfile = g_key_file_new (); + flags = G_KEY_FILE_KEEP_COMMENTS; + + // config file path + config_dir = g_get_user_config_dir (); + path = g_strdup_printf ("%s/snappy/history", config_dir); + + if (g_key_file_load_from_file (keyfile, path, flags, NULL)) { + // set uri in history + 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); + } + } else { + // if group "history" doesn't exist create it and populate it + g_key_file_set_boolean (keyfile, "history", uri, TRUE); + } + + // save gkeyfile to a file + data = g_key_file_to_data (keyfile, NULL, NULL); + file = fopen (path, "w"); + fputs (data, file); + fclose (file); + + g_free (data); + g_free (path); + + ret = TRUE; + } else { + ret = FALSE; + } + + return ret; +} + +gboolean add_uri_unfinished_playback (GstEngine * engine, gchar * uri, gint64 position) { guint hash_key; @@ -282,6 +331,8 @@ bus_call (GstBus * bus, GstMessage * msg, gpointer data) seek (engine, position); } + add_uri_to_history (engine->uri); + update_controls (ui); engine->has_started = TRUE; } |