Howdy, all

The attached (incremental) patch adds search support for Ratings. You can search for images with ratings less than, equal to, or greater than a specific value; images with ratings in a specified range, or images without ratings.

Full patch:
http://ocaml.xvm.mit.edu/~xsdg/stuff/geeqie/ratings/ratings.v5.full.patch.txt

Cheers,
--xsdg
commit c49f2751dd0aac4f5c90e5399178ff84e7cfccca
Author: Omari Stephens <x...@xsdg.org>
Date:   Sat Nov 21 20:32:19 2009 +0000

    Add support for searching for Ratings

diff --git a/trunk/src/bar_rating.c b/trunk/src/bar_rating.c
index 80b972c..0898183 100644
--- a/trunk/src/bar_rating.c
+++ b/trunk/src/bar_rating.c
@@ -310,7 +310,8 @@ static GtkWidget *bar_pane_rating_new(const gchar *id, 
const gchar *title, const
 
 
        // SPIN BUTTON
-       prd->spinbutton = (GtkSpinButton*) gtk_spin_button_new_with_range(0.0, 
10.0, 1.0);
+       prd->spinbutton = (GtkSpinButton*) 
gtk_spin_button_new_with_range((gdouble) MIN_RATING,
+                       (gdouble) MAX_RATING, 1.0);
        gtk_spin_button_set_numeric(prd->spinbutton, TRUE);
        gtk_spin_button_set_snap_to_ticks(prd->spinbutton, TRUE);
 
diff --git a/trunk/src/bar_rating.h b/trunk/src/bar_rating.h
index 7453a4c..1862159 100644
--- a/trunk/src/bar_rating.h
+++ b/trunk/src/bar_rating.h
@@ -22,6 +22,9 @@ void bar_pane_rating_inc_value(gpointer data);
 void bar_pane_rating_dec_value(gpointer data);
 void bar_pane_rating_set_value(gint value, gpointer data);
 
+#define MIN_RATING 0
+#define MAX_RATING 10
+
 
 #endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
diff --git a/trunk/src/filedata.c b/trunk/src/filedata.c
index 43dc828..97e5ff9 100644
--- a/trunk/src/filedata.c
+++ b/trunk/src/filedata.c
@@ -230,6 +230,9 @@ static void file_data_set_collate_keys(FileData *fd)
        g_free(fd->collate_key_name);
        g_free(fd->collate_key_name_nocase);
 
+       g_free(fd->metadata_collate_key);
+       fd->metadata_collate_key = NULL;
+
 #if GLIB_CHECK_VERSION(2, 8, 0)
        fd->collate_key_name = g_utf8_collate_key_for_filename(fd->name, -1);
        fd->collate_key_name_nocase = 
g_utf8_collate_key_for_filename(caseless_name, -1);
diff --git a/trunk/src/search.c b/trunk/src/search.c
index 451e091..f99687b 100644
--- a/trunk/src/search.c
+++ b/trunk/src/search.c
@@ -40,6 +40,7 @@
 #include "utilops.h"
 #include "window.h"
 #include "bar_keywords.h"
+#include "bar_rating.h"
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
@@ -122,6 +123,11 @@ struct _SearchData
        GtkWidget *spin_similarity;
        GtkWidget *entry_similarity;
 
+       GtkWidget *check_rating;
+       GtkWidget *menu_rating;
+       GtkWidget *spin_rating;
+       GtkWidget *spin_rating_end;
+
        GtkWidget *check_keywords;
        GtkWidget *menu_keywords;
        GtkWidget *entry_keywords;
@@ -136,6 +142,8 @@ struct _SearchData
        gboolean   search_name_match_case;
        gint64 search_size;
        gint64 search_size_end;
+       guint64 search_rating;
+       guint64 search_rating_end;
        gint   search_date_y;
        gint   search_date_m;
        gint   search_date_d;
@@ -159,6 +167,7 @@ struct _SearchData
        MatchType match_size;
        MatchType match_date;
        MatchType match_dimensions;
+       MatchType match_rating;
        MatchType match_keywords;
        MatchType match_comment;
 
@@ -167,6 +176,7 @@ struct _SearchData
        gboolean match_date_enable;
        gboolean match_dimensions_enable;
        gboolean match_similarity_enable;
+       gboolean match_rating_enable;
        gboolean match_keywords_enable;
        gboolean match_comment_enable;
 
@@ -233,6 +243,14 @@ static const MatchList text_search_menu_date[] = {
        { N_("between"),        SEARCH_MATCH_BETWEEN }
 };
 
+static const MatchList text_search_menu_rating[] = {
+       { N_("equal to"),       SEARCH_MATCH_EQUAL },
+       { N_("less than"),      SEARCH_MATCH_UNDER },
+       { N_("greater than"),   SEARCH_MATCH_OVER },
+       { N_("between"),        SEARCH_MATCH_BETWEEN },
+       { N_("unset"),          SEARCH_MATCH_NONE },
+};
+
 static const MatchList text_search_menu_keyword[] = {
        { N_("match all"),      SEARCH_MATCH_ALL },
        { N_("match any"),      SEARCH_MATCH_ANY },
@@ -1799,6 +1817,36 @@ static gboolean search_file_next(SearchData *sd)
                        }
                }
 
+       if (match && sd->match_rating_enable)
+               {
+               tested = TRUE;
+               match = FALSE;
+               guint64 rating = metadata_read_int(fd, RATING_KEY, (guint64) 
-1);
+
+               if (rating == (guint64) -1)
+                       {
+                       /* Files without a rating only match if we're actively 
looking for them */
+                       match = (sd->match_rating == SEARCH_MATCH_NONE);
+                       }
+               else if (sd->match_rating == SEARCH_MATCH_EQUAL)
+                       {
+                       match = (rating == sd->search_rating);
+                       }
+               else if (sd->match_rating == SEARCH_MATCH_UNDER)
+                       {
+                       match = (rating < sd->search_rating);
+                       }
+               else if (sd->match_rating == SEARCH_MATCH_OVER)
+                       {
+                       match = (rating > sd->search_rating);
+                       }
+               else if (sd->match_rating == SEARCH_MATCH_BETWEEN)
+                       {
+                       match = MATCH_IS_BETWEEN(rating, sd->search_rating,
+                                                sd->search_rating_end);
+                       }
+               }
+
        if (match && sd->match_keywords_enable && sd->search_keyword_list)
                {
                GList *list;
@@ -2427,6 +2475,17 @@ static void menu_choice_dimensions_cb(GtkWidget *combo, 
gpointer data)
                                (sd->match_dimensions == SEARCH_MATCH_BETWEEN));
 }
 
+static void menu_choice_rating_cb(GtkWidget *combo, gpointer data)
+{
+       SearchData *sd = data;
+
+       if (!menu_choice_get_match_type(combo, &sd->match_rating)) return;
+
+       menu_choice_set_visible(sd->spin_rating, sd->match_rating != 
SEARCH_MATCH_NONE);
+       menu_choice_set_visible(gtk_widget_get_parent(sd->spin_rating_end),
+                               (sd->match_rating == SEARCH_MATCH_BETWEEN));
+}
+
 static void menu_choice_keyword_cb(GtkWidget *combo, gpointer data)
 {
        SearchData *sd = data;
@@ -2623,6 +2682,7 @@ void search_new(FileData *dir_fd, FileData *example_file)
        sd->match_size = SEARCH_MATCH_EQUAL;
        sd->match_date = SEARCH_MATCH_EQUAL;
        sd->match_dimensions = SEARCH_MATCH_EQUAL;
+       sd->match_rating = SEARCH_MATCH_EQUAL;
        sd->match_keywords = SEARCH_MATCH_ALL;
        sd->match_comment = SEARCH_MATCH_CONTAINS;
 
@@ -2762,6 +2822,19 @@ void search_new(FileData *dir_fd, FileData *example_file)
        gtk_box_pack_start(GTK_BOX(hbox), combo, TRUE, TRUE, 0);
        gtk_widget_show(combo);
 
+       /* Search for rating */
+       hbox = menu_choice(sd->box_search, &sd->check_rating, &sd->menu_rating,
+                          _("Rating is"), &sd->match_rating_enable, 
text_search_menu_rating,
+                          sizeof(text_search_menu_rating) / sizeof(MatchList),
+                          G_CALLBACK(menu_choice_rating_cb), sd);
+       sd->spin_rating = menu_spin(hbox, MIN_RATING, MAX_RATING, 
sd->search_rating,
+                                 G_CALLBACK(menu_choice_spin_cb), 
&sd->search_rating);
+       hbox2 = gtk_hbox_new(FALSE, PREF_PAD_SPACE);
+       gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0);
+       pref_label_new(hbox2, _("and"));
+       sd->spin_rating_end = menu_spin(hbox2, MIN_RATING, MAX_RATING, 
sd->search_rating_end,
+                                     G_CALLBACK(menu_choice_spin_cb), 
&sd->search_rating_end);
+
        /* Search for image keywords */
        hbox = menu_choice(sd->box_search, &sd->check_keywords, 
&sd->menu_keywords,
                           _("Keywords"), &sd->match_keywords_enable,
diff --git a/trunk/src/typedefs.h b/trunk/src/typedefs.h
index 86fc4ea..0691778 100644
--- a/trunk/src/typedefs.h
+++ b/trunk/src/typedefs.h
@@ -463,6 +463,7 @@ struct _FileData {
        const gchar *extension;
        gchar *collate_key_name;
        gchar *collate_key_name_nocase;
+       gchar *metadata_collate_key; /* for sorting by metadata tags */
        gint64 size;
        time_t date;
        mode_t mode; /* this is needed at least for notification in view_dir 
because it is preserved after the file/directory is deleted */
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Geeqie-devel mailing list
Geeqie-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geeqie-devel

Reply via email to