Move filter code into pan-fiew-filter.{c,h}
authorOmari Stephens <xsdg@google.com>
Tue, 27 Dec 2016 19:26:45 +0000 (19:26 +0000)
committerOmari Stephens <xsdg@google.com>
Mon, 3 Jul 2017 21:19:59 +0000 (21:19 +0000)
src/pan-view/pan-timeline.c
src/pan-view/pan-view-filter.c
src/pan-view/pan-view-filter.h

index e60930e..d87dbed 100644 (file)
 
 #include "pan-timeline.h"
 
-#include "metadata.h"
 #include "pan-item.h"
 #include "pan-util.h"
 #include "pan-view.h"
-#include "ui_fileops.h"
+#include "pan-view-filter.h"
 
 void pan_timeline_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *height)
 {
        GList *list;
        GList *work;
-       GHashTable *filter_kw_table;
-       GHashTableIter filter_kw_iter;
-       gchar *filter_kw;
        gint x, y;
        time_t group_start_date;
        gint total;
@@ -46,7 +42,7 @@ void pan_timeline_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *he
        gint y_height;
 
        list = pan_list_tree(dir_fd, SORT_NONE, TRUE, pw->ignore_symlinks);
-       filter_kw_table = pw->filter_ui->filter_kw_table;  // Shorthand.
+       gboolean changed = pan_filter_fd_list(&list, pw->filter_ui->filter_kw_table, PAN_VIEW_INTERSECTION);
 
        if (pw->cache_list && pw->exif_date_enable)
                {
@@ -80,35 +76,6 @@ void pan_timeline_compute(PanWindow *pw, FileData *dir_fd, gint *width, gint *he
                fd = work->data;
                work = work->next;
 
-               // Don't show images that fail the keyword test.
-               if (g_hash_table_size(filter_kw_table) > 0)
-                       {
-                       gint match_count = 0;
-                       gint miss_count = 0;
-                       // TODO(xsdg): OPTIMIZATION Do the search inside of metadata.c to avoid a
-                       // bunch of string list copies.
-                       // TODO(xsdg): Allow user to switch between union and intersection.
-                       GList *img_keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
-                       if (!img_keywords) continue;
-
-                       g_hash_table_iter_init(&filter_kw_iter, filter_kw_table);
-                       while (g_hash_table_iter_next(&filter_kw_iter, (void**)&filter_kw, NULL))
-                               {
-                               if (g_list_find_custom(img_keywords, filter_kw, (GCompareFunc)g_strcmp0))
-                                       {
-                                       ++match_count;
-                                       }
-                               else
-                                       {
-                                       ++miss_count;
-                                       }
-                               if (miss_count > 0) break;
-                               }
-
-                       string_list_free(img_keywords);
-                       if (miss_count > 0 || match_count == 0) continue;
-                       }
-
                if (!pan_date_compare(fd->date, group_start_date, PAN_DATE_LENGTH_DAY))
                        {
                        // FD starts a new day group.
index 38eff62..5c0daa2 100644 (file)
 #include "pan-view-filter.h"
 
 #include "image.h"
+#include "metadata.h"
 #include "pan-item.h"
 #include "pan-util.h"
 #include "pan-view.h"
+#include "ui_fileops.h"
 #include "ui_tabcomp.h"
 #include "ui_misc.h"
 
@@ -199,3 +201,58 @@ void pan_filter_toggle_visible(PanWindow *pw, gboolean enable)
                        }
                }
 }
+
+gboolean pan_filter_fd_list(GList **fd_list, GHashTable *kw_table, PanViewFilterMode mode)
+{
+       GList *work;
+       gboolean modified = FALSE;
+       GHashTableIter kw_iter;
+       gchar *filter_kw;
+
+
+       if (!fd_list || !*fd_list || g_hash_table_size(kw_table) == 0) return modified;
+
+       // TODO(xsdg): Pay attention to filter mode.
+       work = *fd_list;
+       while (work)
+               {
+               FileData *fd = work->data;
+               GList *last_work = work;
+               work = work->next;
+
+               // TODO(xsdg): OPTIMIZATION Do the search inside of metadata.c to avoid a
+               // bunch of string list copies.
+               GList *img_keywords = metadata_read_list(fd, KEYWORD_KEY, METADATA_PLAIN);
+               if (!img_keywords)
+                       {
+                       *fd_list = g_list_delete_link(*fd_list, last_work);
+                       modified = TRUE;
+                       continue;
+                       }
+
+               gint match_count = 0;
+               gint miss_count = 0;
+               g_hash_table_iter_init(&kw_iter, kw_table);
+               while (g_hash_table_iter_next(&kw_iter, (void**)&filter_kw, NULL))
+                       {
+                       if (g_list_find_custom(img_keywords, filter_kw, (GCompareFunc)g_strcmp0))
+                               {
+                               ++match_count;
+                               }
+                       else
+                               {
+                               ++miss_count;
+                               }
+                       if (miss_count > 0) break;
+                       }
+
+               string_list_free(img_keywords);
+               if (miss_count > 0 || match_count == 0)
+                       {
+                       *fd_list = g_list_delete_link(*fd_list, last_work);
+                       modified = TRUE;
+                       }
+               }
+
+       return modified;
+}
index ca6f198..f284328 100644 (file)
 #include "main.h"
 #include "pan-types.h"
 
+typedef enum {
+       PAN_VIEW_UNION,
+       PAN_VIEW_INTERSECTION,
+       PAN_VIEW_GROUP
+} PanViewFilterMode;
+
 void pan_filter_toggle_visible(PanWindow *pw, gboolean enable);
 void pan_filter_activate(PanWindow *pw);
 void pan_filter_activate_cb(const gchar *text, gpointer data);
@@ -36,5 +42,7 @@ PanViewFilterUi *pan_filter_ui_new(PanWindow *pw);
 // Destroys the specified PanViewFilterUi and sets the pointer to NULL.
 void pan_filter_ui_destroy(PanViewFilterUi **ui);
 
+gboolean pan_filter_fd_list(GList **fd_list, GHashTable *kw_table, PanViewFilterMode mode);
+
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */