Author: abrander
Date: 2013-03-31 13:20:05 +0200 (Sun, 31 Mar 2013)
New Revision: 4343

Modified:
   trunk/librawstudio/rs-library.c
   trunk/librawstudio/rs-library.h
   trunk/src/rs-tag-gui.c
Log:
Changed rs_library_search() to accept a string argument (and fixed a memory 
leak in the process).

Modified: trunk/librawstudio/rs-library.c
===================================================================
--- trunk/librawstudio/rs-library.c     2013-03-31 10:45:51 UTC (rev 4342)
+++ trunk/librawstudio/rs-library.c     2013-03-31 11:20:05 UTC (rev 4343)
@@ -715,10 +715,10 @@
 }
 
 GList *
-rs_library_search(RSLibrary *library, GList *tags)
+rs_library_search(RSLibrary *library, const gchar *needle)
 {
        g_return_val_if_fail(RS_IS_LIBRARY(library), NULL);
-       g_return_val_if_fail(tags != NULL, NULL);
+       g_return_val_if_fail(needle != NULL, NULL);
 
        if (!rs_library_has_database_connection(library)) return NULL;
 
@@ -726,19 +726,23 @@
        gint rc;
        sqlite3 *db = library->db;
        gchar *tag;
-       gint n, num_tags = g_list_length(tags);
+       gint n, num_tags;
        GList *photos = NULL;
        GTimer *gt = g_timer_new();
        gchar *filename;
+       gchar **needle_parts;
 
        sqlite3_prepare_v2(db, "create temp table filter (photo integer)", -1, 
&stmt, NULL);
        rc = sqlite3_step(stmt);
        sqlite3_finalize(stmt);
        library_sqlite_error(db, rc);
-       
+
+       needle_parts = g_strsplit_set(needle, " ", 0);
+       num_tags = g_strv_length(needle_parts);
+
        for (n = 0; n < num_tags; n++)
        {
-               tag = (gchar *) g_list_nth_data(tags, n);
+               tag = needle_parts[n];
 
                g_mutex_lock(library->id_lock);
                sqlite3_prepare_v2(db, "insert into filter select 
phototags.photo from phototags, tags where phototags.tag = tags.id and 
lower(tags.tagname) = lower(?1) ;", -1, &stmt, NULL);
@@ -748,6 +752,8 @@
                g_mutex_unlock(library->id_lock);
        }
 
+       g_strfreev(needle_parts);
+
        sqlite3_prepare_v2(db, "create temp table result (photo integer, count 
integer)", -1, &stmt, NULL);
        rc = sqlite3_step(stmt);
        sqlite3_finalize(stmt);

Modified: trunk/librawstudio/rs-library.h
===================================================================
--- trunk/librawstudio/rs-library.h     2013-03-31 10:45:51 UTC (rev 4342)
+++ trunk/librawstudio/rs-library.h     2013-03-31 11:20:05 UTC (rev 4343)
@@ -54,7 +54,7 @@
 void rs_library_photo_add_tag(RSLibrary *library, const gchar *filename, gint 
tag_id, const gboolean autotag);
 void rs_library_delete_photo(RSLibrary *library, const gchar *photo);
 gboolean rs_library_delete_tag(RSLibrary *library, const gchar *tag, const 
gboolean force);
-GList *rs_library_search(RSLibrary *library, GList *tags);
+GList *rs_library_search(RSLibrary *library, const gchar *needle);
 GList *rs_library_photo_tags(RSLibrary *library, const gchar *photo, const 
gboolean autotag);
 GList *rs_library_find_tag(RSLibrary *library, const gchar *tag);
 gboolean rs_library_set_tag_search(gchar *str);

Modified: trunk/src/rs-tag-gui.c
===================================================================
--- trunk/src/rs-tag-gui.c      2013-03-31 10:45:51 UTC (rev 4342)
+++ trunk/src/rs-tag-gui.c      2013-03-31 11:20:05 UTC (rev 4343)
@@ -50,10 +50,8 @@
        cb_carrier *carrier = user_data;
        const gchar *text = gtk_entry_get_text(entry);
 
-       GList *tags = rs_split_string(text, " ");
+       GList *photos = rs_library_search(carrier->library, text);
 
-       GList *photos = rs_library_search(carrier->library, tags);
-
        /* FIXME: deselect all photos in store */
        rs_store_remove(carrier->store, NULL, NULL);
        g_list_foreach(photos, load_photos, carrier->store);
@@ -70,7 +68,6 @@
        rs_conf_unset(CONF_LWD);
 
        g_list_free(photos);
-       g_list_free(tags);
 }
 
 GtkWidget *


_______________________________________________
Rawstudio-commit mailing list
[email protected]
http://rawstudio.org/cgi-bin/mailman/listinfo/rawstudio-commit

Reply via email to