Move history_list_*() functions to separate files:
authorLaurent Monin <geeqie@norz.org>
Sun, 20 Jul 2008 14:56:32 +0000 (14:56 +0000)
committerLaurent Monin <geeqie@norz.org>
Sun, 20 Jul 2008 14:56:32 +0000 (14:56 +0000)
history_list.c and history_list.h.

18 files changed:
src/Makefile.am
src/bar_exif.c
src/bar_info.c
src/bar_sort.c
src/dnd.c
src/history_list.c [new file with mode: 0644]
src/history_list.h [new file with mode: 0644]
src/layout.c
src/layout_util.c
src/main.c
src/pan-view.c
src/ui_bookmark.c
src/ui_bookmark.h
src/ui_misc.c
src/ui_tabcomp.c
src/view_dir.c
src/view_dir_list.c
src/view_dir_tree.c

index 1018e7e..274411f 100644 (file)
@@ -135,6 +135,8 @@ geeqie_SOURCES = \
        fullscreen.h    \
        histogram.c     \
        histogram.h     \
+       history_list.c  \
+       history_list.h  \
        image.c         \
        image.h         \
        image-load.c    \
index e4e6179..e2a1242 100644 (file)
@@ -15,7 +15,7 @@
 #include "bar_exif.h"
 
 #include "exif.h"
-#include "ui_bookmark.h"
+#include "history_list.h"
 #include "ui_misc.h"
 #include "filedata.h"
 
index c94ae07..badd945 100644 (file)
 
 #include "cache.h"
 #include "filedata.h"
+#include "history_list.h"
 #include "info.h"
 #include "secure_save.h"
 #include "utilops.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_misc.h"
 #include "ui_utildlg.h"
index f530540..102c592 100644 (file)
@@ -17,6 +17,7 @@
 #include "collect.h"
 #include "collect-io.h"
 #include "filedata.h"
+#include "history_list.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "utilops.h"
index 36e9c63..016c67d 100644 (file)
--- a/src/dnd.c
+++ b/src/dnd.c
@@ -16,7 +16,6 @@
 
 #include "collect.h"
 #include "image.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 
 
diff --git a/src/history_list.c b/src/history_list.c
new file mode 100644 (file)
index 0000000..0aa8e9a
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * Geeqie
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * Authors: John Ellis, Vladimir Nadvornik, Laurent Monin
+ *
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#include "main.h"
+#include "history_list.h"
+
+#include "secure_save.h"
+#include "ui_fileops.h"
+
+/*
+ *-----------------------------------------------------------------------------
+ * history lists
+ *-----------------------------------------------------------------------------
+ */
+
+#define HISTORY_DEFAULT_KEY_COUNT 16
+
+
+typedef struct _HistoryData HistoryData;
+struct _HistoryData
+{
+       gchar *key;
+       GList *list;
+};
+
+static GList *history_list = NULL;
+
+
+static gchar *quoted_from_text(const gchar *text)
+{
+       const gchar *ptr;
+       gint c = 0;
+       gint l = strlen(text);
+
+       if (l == 0) return NULL;
+
+       while (c < l && text[c] !='"') c++;
+       if (text[c] == '"')
+               {
+               gint e;
+               c++;
+               ptr = text + c;
+               e = c;
+               while (e < l && text[e] !='"') e++;
+               if (text[e] == '"')
+                       {
+                       if (e - c > 0)
+                               {
+                               return g_strndup(ptr, e - c);
+                               }
+                       }
+               }
+       return NULL;
+}
+
+gint history_list_load(const gchar *path)
+{
+       FILE *f;
+       gchar *key = NULL;
+       gchar s_buf[1024];
+       gchar *pathl;
+
+       pathl = path_from_utf8(path);
+       f = fopen(pathl, "r");
+       g_free(pathl);
+       if (!f) return FALSE;
+
+       /* first line must start with History comment */
+       if (!fgets(s_buf, sizeof(s_buf), f) ||
+           strncmp(s_buf, "#History", 8) != 0)
+               {
+               fclose(f);
+               return FALSE;
+               }
+
+       while (fgets(s_buf, sizeof(s_buf), f))
+               {
+               if (s_buf[0]=='#') continue;
+               if (s_buf[0]=='[')
+                       {
+                       gint c;
+                       gchar *ptr;
+
+                       ptr = s_buf + 1;
+                       c = 0;
+                       while (ptr[c] != ']' && ptr[c] != '\n' && ptr[c] != '\0') c++;
+
+                       g_free(key);
+                       key = g_strndup(ptr, c);
+                       }
+               else
+                       {
+                       gchar *value;
+
+                       value = quoted_from_text(s_buf);
+                       if (value && key)
+                               {
+                               history_list_add_to_key(key, value, 0);
+                               }
+                       g_free(value);
+                       }
+               }
+
+       fclose(f);
+
+       g_free(key);
+
+       return TRUE;
+}
+
+gint history_list_save(const gchar *path)
+{
+       SecureSaveInfo *ssi;
+       GList *list;
+       gchar *pathl;
+
+       pathl = path_from_utf8(path);
+       ssi = secure_open(pathl);
+       g_free(pathl);
+       if (!ssi)
+               {
+               log_printf(_("Unable to write history lists to: %s\n"), path);
+               return FALSE;
+               }
+
+       secure_fprintf(ssi, "#History lists\n\n");
+
+       list = g_list_last(history_list);
+       while (list && secsave_errno == SS_ERR_NONE)
+               {
+               HistoryData *hd;
+               GList *work;
+
+               hd = list->data;
+               list = list->prev;
+
+               secure_fprintf(ssi, "[%s]\n", hd->key);
+
+               /* save them inverted (oldest to newest)
+                * so that when reading they are added correctly
+                */
+               work = g_list_last(hd->list);
+               while (work && secsave_errno == SS_ERR_NONE)
+                       {
+                       secure_fprintf(ssi, "\"%s\"\n", (gchar *)work->data);
+                       work = work->prev;
+                       }
+               secure_fputc(ssi, '\n');
+               }
+
+       secure_fprintf(ssi, "#end\n");
+
+       return (secure_close(ssi) == 0);
+}
+
+static void history_list_free(HistoryData *hd)
+{
+       GList *work;
+
+       if (!hd) return;
+
+       work = hd->list;
+       while (work)
+               {
+               g_free(work->data);
+               work = work->next;
+               }
+
+       g_free(hd->key);
+       g_free(hd);
+}
+
+static HistoryData *history_list_find_by_key(const gchar* key)
+{
+       GList *work = history_list;
+
+       if (!key) return NULL;
+
+       while (work)
+               {
+               HistoryData *hd = work->data;
+               if (strcmp(hd->key, key) == 0) return hd;
+               work = work->next;
+               }
+       return NULL;
+}
+
+const gchar *history_list_find_last_path_by_key(const gchar* key)
+{
+       HistoryData *hd;
+
+       hd = history_list_find_by_key(key);
+       if (!hd || !hd->list) return NULL;
+
+       return hd->list->data;
+}
+
+void history_list_free_key(const gchar *key)
+{
+       HistoryData *hd;
+       hd = history_list_find_by_key(key);
+       if (!hd) return;
+
+       history_list = g_list_remove(history_list, hd);
+       history_list_free(hd);
+}
+
+void history_list_add_to_key(const gchar *key, const gchar *path, gint max)
+{
+       HistoryData *hd;
+       GList *work;
+
+       if (!key || !path) return;
+
+       hd = history_list_find_by_key(key);
+       if (!hd)
+               {
+               hd = g_new(HistoryData, 1);
+               hd->key = g_strdup(key);
+               hd->list = NULL;
+               history_list = g_list_prepend(history_list, hd);
+               }
+
+       /* if already in the list, simply move it to the top */
+       work = hd->list;
+       while (work)
+               {
+               gchar *buf = work->data;
+
+               if (strcmp(buf, path) == 0)
+                       {
+                       /* if not first, move it */
+                       if (work != hd->list)
+                               {
+                               hd->list = g_list_remove(hd->list, buf);
+                               hd->list = g_list_prepend(hd->list, buf);
+                               }
+                       return;
+                       }
+               work = work->next;
+               }
+
+       hd->list = g_list_prepend(hd->list, g_strdup(path));
+
+       if (max == -1) max = HISTORY_DEFAULT_KEY_COUNT;
+       if (max > 0)
+               {
+               gint len = 0;
+               GList *work = hd->list;
+               GList *last = NULL;
+
+               while (work)
+                       {
+                       len++;
+                       last = work;
+                       work = work->next;
+                       }
+
+               work = last;
+               while (work && len > max)
+                       {
+                       GList *node = work;
+                       work = work->prev;
+
+                       g_free(node->data);
+                       hd->list = g_list_delete_link(hd->list, node);
+                       len--;
+                       }
+               }
+}
+
+void history_list_item_change(const gchar *key, const gchar *oldpath, const gchar *newpath)
+{
+       HistoryData *hd;
+       GList *work;
+
+       if (!oldpath) return;
+       hd = history_list_find_by_key(key);
+       if (!hd) return;
+
+       work = hd->list;
+       while (work)
+               {
+               gchar *buf = work->data;
+               if (strcmp(buf, oldpath) == 0)
+                       {
+                       if (newpath)
+                               {
+                               work->data = g_strdup(newpath);
+                               }
+                       else
+                               {
+                               hd->list = g_list_remove(hd->list, buf);
+                               }
+                       g_free(buf);
+                       return;
+                       }
+               work = work->next;
+               }
+}
+
+void history_list_item_move(const gchar *key, const gchar *path, gint direction)
+{
+       HistoryData *hd;
+       GList *work;
+       gint p = 0;
+
+       if (!path) return;
+       hd = history_list_find_by_key(key);
+       if (!hd) return;
+
+       work = hd->list;
+       while (work)
+               {
+               gchar *buf = work->data;
+               if (strcmp(buf, path) == 0)
+                       {
+                       p += direction;
+                       if (p < 0) return;
+                       hd->list = g_list_remove(hd->list, buf);
+                       hd->list = g_list_insert(hd->list, buf, p);
+                       return;
+                       }
+               work = work->next;
+               p++;
+               }
+}
+
+void history_list_item_remove(const gchar *key, const gchar *path)
+{
+       history_list_item_change(key, path, NULL);
+}
+
+GList *history_list_get_by_key(const gchar *key)
+{
+       HistoryData *hd;
+
+       hd = history_list_find_by_key(key);
+       if (!hd) return NULL;
+
+       return hd->list;
+}
diff --git a/src/history_list.h b/src/history_list.h
new file mode 100644 (file)
index 0000000..827f24e
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Geeqie
+ * Copyright (C) 2008 The Geeqie Team
+ *
+ * Author: John Ellis, Vladimir Nadvornik, Laurent Monin
+ *
+ * This software is released under the GNU General Public License (GNU GPL).
+ * Please read the included file COPYING for more information.
+ * This software comes with no warranty of any kind, use at your own risk!
+ */
+
+#ifndef HISTORY_LIST_H
+#define HISTORY_LIST_H
+
+/* history lists */
+
+gint history_list_load(const gchar *path);
+gint history_list_save(const gchar *path);
+
+void history_list_free_key(const gchar *key);
+
+void history_list_add_to_key(const gchar *key, const gchar *path, gint max);
+
+void history_list_item_change(const gchar *key, const gchar *oldpath, const gchar *newpath);
+void history_list_item_move(const gchar *key, const gchar *path, gint direction);
+void history_list_item_remove(const gchar *key, const gchar *path);
+
+const gchar *history_list_find_last_path_by_key(const gchar* key);
+
+/* the returned GList is internal, don't free it */
+GList *history_list_get_by_key(const gchar *key);
+
+
+#endif /* HISTORY_LIST_H */
index 0c0f217..9230cfe 100644 (file)
@@ -27,7 +27,6 @@
 #include "utilops.h"
 #include "view_dir.h"
 #include "view_file.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_misc.h"
index 172823c..53d7efd 100644 (file)
@@ -24,6 +24,7 @@
 #include "dupe.h"
 #include "editors.h"
 #include "filedata.h"
+#include "history_list.h"
 #include "image-overlay.h"
 #include "img-view.h"
 #include "info.h"
@@ -35,7 +36,6 @@
 #include "print.h"
 #include "search.h"
 #include "utilops.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_misc.h"
index 7b2acdb..45504f1 100644 (file)
 #include "collect-io.h"
 #include "filedata.h"
 #include "filefilter.h"
+#include "history_list.h"
 #include "image-overlay.h"
 #include "layout.h"
 #include "layout_image.h"
 #include "rcfile.h"
 #include "remote.h"
 #include "similar.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_utildlg.h"
 #include "cache_maint.h"
index dd6f1c9..721925d 100644 (file)
@@ -19,6 +19,7 @@
 #include "editors.h"
 #include "exif.h"
 #include "fullscreen.h"
+#include "history_list.h"
 #include "img-view.h"
 #include "info.h"
 #include "menu.h"
index 8f05a66..4e595a0 100644 (file)
@@ -24,7 +24,9 @@
 #include <gdk/gdkkeysyms.h> /* for key values */
 
 #include "main.h"
+
 #include "filedata.h"
+#include "history_list.h"
 
 #include "secure_save.h"
 #include "ui_bookmark.h"
 #include "ui_tabcomp.h"
 
 
-/*
- *-----------------------------------------------------------------------------
- * history lists
- *-----------------------------------------------------------------------------
- */
-
-#define HISTORY_DEFAULT_KEY_COUNT 16
-
-
-typedef struct _HistoryData HistoryData;
-struct _HistoryData
-{
-       gchar *key;
-       GList *list;
-};
-
-static GList *history_list = NULL;
-
-
-static gchar *quoted_from_text(const gchar *text)
-{
-       const gchar *ptr;
-       gint c = 0;
-       gint l = strlen(text);
-
-       if (l == 0) return NULL;
-
-       while (c < l && text[c] !='"') c++;
-       if (text[c] == '"')
-               {
-               gint e;
-               c++;
-               ptr = text + c;
-               e = c;
-               while (e < l && text[e] !='"') e++;
-               if (text[e] == '"')
-                       {
-                       if (e - c > 0)
-                               {
-                               return g_strndup(ptr, e - c);
-                               }
-                       }
-               }
-       return NULL;
-}
-
-gint history_list_load(const gchar *path)
-{
-       FILE *f;
-       gchar *key = NULL;
-       gchar s_buf[1024];
-       gchar *pathl;
-
-       pathl = path_from_utf8(path);
-       f = fopen(pathl, "r");
-       g_free(pathl);
-       if (!f) return FALSE;
-
-       /* first line must start with History comment */
-       if (!fgets(s_buf, sizeof(s_buf), f) ||
-           strncmp(s_buf, "#History", 8) != 0)
-               {
-               fclose(f);
-               return FALSE;
-               }
-
-       while (fgets(s_buf, sizeof(s_buf), f))
-               {
-               if (s_buf[0]=='#') continue;
-               if (s_buf[0]=='[')
-                       {
-                       gint c;
-                       gchar *ptr;
-
-                       ptr = s_buf + 1;
-                       c = 0;
-                       while (ptr[c] != ']' && ptr[c] != '\n' && ptr[c] != '\0') c++;
-
-                       g_free(key);
-                       key = g_strndup(ptr, c);
-                       }
-               else
-                       {
-                       gchar *value;
-
-                       value = quoted_from_text(s_buf);
-                       if (value && key)
-                               {
-                               history_list_add_to_key(key, value, 0);
-                               }
-                       g_free(value);
-                       }
-               }
-
-       fclose(f);
-
-       g_free(key);
-
-       return TRUE;
-}
-
-gint history_list_save(const gchar *path)
-{
-       SecureSaveInfo *ssi;
-       GList *list;
-       gchar *pathl;
-
-       pathl = path_from_utf8(path);
-       ssi = secure_open(pathl);
-       g_free(pathl);
-       if (!ssi)
-               {
-               log_printf(_("Unable to write history lists to: %s\n"), path);
-               return FALSE;
-               }
-
-       secure_fprintf(ssi, "#History lists\n\n");
-
-       list = g_list_last(history_list);
-       while (list && secsave_errno == SS_ERR_NONE)
-               {
-               HistoryData *hd;
-               GList *work;
-
-               hd = list->data;
-               list = list->prev;
-
-               secure_fprintf(ssi, "[%s]\n", hd->key);
-
-               /* save them inverted (oldest to newest)
-                * so that when reading they are added correctly
-                */
-               work = g_list_last(hd->list);
-               while (work && secsave_errno == SS_ERR_NONE)
-                       {
-                       secure_fprintf(ssi, "\"%s\"\n", (gchar *)work->data);
-                       work = work->prev;
-                       }
-               secure_fputc(ssi, '\n');
-               }
-
-       secure_fprintf(ssi, "#end\n");
-
-       return (secure_close(ssi) == 0);
-}
-
-static void history_list_free(HistoryData *hd)
-{
-       GList *work;
-
-       if (!hd) return;
-
-       work = hd->list;
-       while (work)
-               {
-               g_free(work->data);
-               work = work->next;
-               }
-
-       g_free(hd->key);
-       g_free(hd);
-}
-
-static HistoryData *history_list_find_by_key(const gchar* key)
-{
-       GList *work = history_list;
-
-       if (!key) return NULL;
-
-       while (work)
-               {
-               HistoryData *hd = work->data;
-               if (strcmp(hd->key, key) == 0) return hd;
-               work = work->next;
-               }
-       return NULL;
-}
-
-const gchar *history_list_find_last_path_by_key(const gchar* key)
-{
-       HistoryData *hd;
-
-       hd = history_list_find_by_key(key);
-       if (!hd || !hd->list) return NULL;
-
-       return hd->list->data;
-}
-
-void history_list_free_key(const gchar *key)
-{
-       HistoryData *hd;
-       hd = history_list_find_by_key(key);
-       if (!hd) return;
-
-       history_list = g_list_remove(history_list, hd);
-       history_list_free(hd);
-}
-
-void history_list_add_to_key(const gchar *key, const gchar *path, gint max)
-{
-       HistoryData *hd;
-       GList *work;
-
-       if (!key || !path) return;
-
-       hd = history_list_find_by_key(key);
-       if (!hd)
-               {
-               hd = g_new(HistoryData, 1);
-               hd->key = g_strdup(key);
-               hd->list = NULL;
-               history_list = g_list_prepend(history_list, hd);
-               }
-
-       /* if already in the list, simply move it to the top */
-       work = hd->list;
-       while (work)
-               {
-               gchar *buf = work->data;
-
-               if (strcmp(buf, path) == 0)
-                       {
-                       /* if not first, move it */
-                       if (work != hd->list)
-                               {
-                               hd->list = g_list_remove(hd->list, buf);
-                               hd->list = g_list_prepend(hd->list, buf);
-                               }
-                       return;
-                       }
-               work = work->next;
-               }
-
-       hd->list = g_list_prepend(hd->list, g_strdup(path));
-
-       if (max == -1) max = HISTORY_DEFAULT_KEY_COUNT;
-       if (max > 0)
-               {
-               gint len = 0;
-               GList *work = hd->list;
-               GList *last = NULL;
-
-               while (work)
-                       {
-                       len++;
-                       last = work;
-                       work = work->next;
-                       }
-
-               work = last;
-               while (work && len > max)
-                       {
-                       GList *node = work;
-                       work = work->prev;
-
-                       g_free(node->data);
-                       hd->list = g_list_delete_link(hd->list, node);
-                       len--;
-                       }
-               }
-}
-
-void history_list_item_change(const gchar *key, const gchar *oldpath, const gchar *newpath)
-{
-       HistoryData *hd;
-       GList *work;
-
-       if (!oldpath) return;
-       hd = history_list_find_by_key(key);
-       if (!hd) return;
-
-       work = hd->list;
-       while (work)
-               {
-               gchar *buf = work->data;
-               if (strcmp(buf, oldpath) == 0)
-                       {
-                       if (newpath)
-                               {
-                               work->data = g_strdup(newpath);
-                               }
-                       else
-                               {
-                               hd->list = g_list_remove(hd->list, buf);
-                               }
-                       g_free(buf);
-                       return;
-                       }
-               work = work->next;
-               }
-}
-
-void history_list_item_move(const gchar *key, const gchar *path, gint direction)
-{
-       HistoryData *hd;
-       GList *work;
-       gint p = 0;
-
-       if (!path) return;
-       hd = history_list_find_by_key(key);
-       if (!hd) return;
-
-       work = hd->list;
-       while (work)
-               {
-               gchar *buf = work->data;
-               if (strcmp(buf, path) == 0)
-                       {
-                       p += direction;
-                       if (p < 0) return;
-                       hd->list = g_list_remove(hd->list, buf);
-                       hd->list = g_list_insert(hd->list, buf, p);
-                       return;
-                       }
-               work = work->next;
-               p++;
-               }
-}
-
-void history_list_item_remove(const gchar *key, const gchar *path)
-{
-       history_list_item_change(key, path, NULL);
-}
-
-GList *history_list_get_by_key(const gchar *key)
-{
-       HistoryData *hd;
-
-       hd = history_list_find_by_key(key);
-       if (!hd) return NULL;
-
-       return hd->list;
-}
 
 /*
  *-----------------------------------------------------------------------------
index 075c068..9087539 100644 (file)
 #define UI_BOOKMARK_H
 
 
-/* history lists */
-
-gint history_list_load(const gchar *path);
-gint history_list_save(const gchar *path);
-
-void history_list_free_key(const gchar *key);
-
-void history_list_add_to_key(const gchar *key, const gchar *path, gint max);
-
-void history_list_item_change(const gchar *key, const gchar *oldpath, const gchar *newpath);
-void history_list_item_move(const gchar *key, const gchar *path, gint direction);
-void history_list_item_remove(const gchar *key, const gchar *path);
-
-const gchar *history_list_find_last_path_by_key(const gchar* key);
-
-/* the returned GList is internal, don't free it */
-GList *history_list_get_by_key(const gchar *key);
-
-
 /* bookmarks */
 
 GtkWidget *bookmark_list_new(const gchar *key,
index b092aef..9f00ce8 100644 (file)
@@ -25,7 +25,7 @@
 #include "main.h"
 #include "ui_misc.h"
 
-#include "ui_bookmark.h"
+#include "history_list.h"
 
 
 /*
index 0e39b77..5497c56 100644 (file)
@@ -29,7 +29,7 @@
 #include "main.h"
 #include "ui_tabcomp.h"
 
-#include "ui_bookmark.h"
+#include "history_list.h"
 #include "ui_fileops.h"
 #include "ui_spinner.h"
 #include "ui_utildlg.h"
index 760a663..af9077b 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "dnd.h"
 #include "dupe.h"
+#include "editors.h"
 #include "filedata.h"
 #include "layout_image.h"
 #include "layout_util.h"
@@ -22,7 +23,6 @@
 #include "ui_tree_edit.h"
 #include "ui_menu.h"
 #include "utilops.h"
-#include "editors.h"
 #include "view_dir_list.h"
 #include "view_dir_tree.h"
 
index bbc5025..09cef28 100644 (file)
@@ -20,7 +20,6 @@
 #include "layout_image.h"
 #include "layout_util.h"
 #include "utilops.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tree_edit.h"
index 531050d..376cca3 100644 (file)
@@ -21,7 +21,6 @@
 #include "layout_image.h"
 #include "layout_util.h"
 #include "utilops.h"
-#include "ui_bookmark.h"
 #include "ui_fileops.h"
 #include "ui_menu.h"
 #include "ui_tree_edit.h"