00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include <glib.h>
00023 #include <stdio.h>
00024
00025 #include <audacious/misc.h>
00026 #include <libaudcore/hook.h>
00027
00028 #define MAX_ENTRIES 30
00029
00030 static GQueue history = G_QUEUE_INIT;
00031 static gboolean loaded, modified;
00032
00033 static void history_save (void)
00034 {
00035 if (! modified)
00036 return;
00037
00038 config_clear_section ("history");
00039
00040 GList * node = history.head;
00041 for (gint i = 0; i < MAX_ENTRIES; i ++)
00042 {
00043 if (! node)
00044 break;
00045
00046 gchar name[32];
00047 snprintf (name, sizeof name, "entry%d", i);
00048 set_string ("history", name, node->data);
00049
00050 node = node->next;
00051 }
00052
00053 modified = FALSE;
00054 }
00055
00056 static void history_load (void)
00057 {
00058 if (loaded)
00059 return;
00060
00061 for (gint i = 0; ; i ++)
00062 {
00063 gchar name[32];
00064 snprintf (name, sizeof name, "entry%d", i);
00065 gchar * path = get_string ("history", name);
00066
00067 if (! path[0])
00068 {
00069 g_free (path);
00070 break;
00071 }
00072
00073 g_queue_push_tail (& history, path);
00074 }
00075
00076 loaded = TRUE;
00077 hook_associate ("config save", (HookFunction) history_save, NULL);
00078 }
00079
00080 const gchar * history_get (gint entry)
00081 {
00082 history_load ();
00083 return g_queue_peek_nth (& history, entry);
00084 }
00085
00086 void history_add (const gchar * path)
00087 {
00088 history_load ();
00089
00090 GList * next;
00091 for (GList * node = history.head; node; node = next)
00092 {
00093 next = node->next;
00094 if (! strcmp (node->data, path))
00095 {
00096 g_free (node->data);
00097 g_queue_delete_link (& history, node);
00098 }
00099 }
00100
00101 g_queue_push_head (& history, g_strdup (path));
00102 modified = TRUE;
00103 }