Author: post
Date: 2010-12-30 03:41:05 +0100 (Thu, 30 Dec 2010)
New Revision: 3741

Modified:
   trunk/librawstudio/rs-library.c
Log:
Check we don't add the same autotag several times.

Modified: trunk/librawstudio/rs-library.c
===================================================================
--- trunk/librawstudio/rs-library.c     2010-12-30 02:23:56 UTC (rev 3740)
+++ trunk/librawstudio/rs-library.c     2010-12-30 02:41:05 UTC (rev 3741)
@@ -63,6 +63,7 @@
 #define LIBRARY_VERSION 2
 #define TAGS_XML_FILE "tags.xml"
 #define MAX_SEARCH_RESULTS 1000
+#include "rs-types.h"
 
 struct _RSLibrary {
        GObject parent;
@@ -867,15 +868,26 @@
                g_free(month);
        }
 
-       gint i;
+       gint i, j;
        library_execute_sql(library->db, "BEGIN TRANSACTION;");
+       gint *used_tags = g_malloc(g_list_length(tags) * sizeof(gint));
        for(i = 0; i < g_list_length(tags); i++)
        {
                gchar *tag = (gchar *) g_list_nth_data(tags, i);
                gint tag_id = rs_library_add_tag(library, tag);
-               library_photo_add_tag(library, photo_id, tag_id, TRUE);
+
+               /* Check if tag has already been added */
+               gboolean used = FALSE;
+               for (j = 0; j < i; j++)
+                       if (tag_id == used_tags[j])
+                               used = TRUE;
+
+               if (!used)
+                       library_photo_add_tag(library, photo_id, tag_id, TRUE);
+               used_tags[i] = tag_id;
                g_free(tag);
        }
+       g_free(used_tags);
        library_execute_sql(library->db, "COMMIT;");
        g_list_free(tags);
 }


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

Reply via email to