Include a Other Software section in Help file
[geeqie.git] / src / metadata.c
index 86a2cd2..a4c7d02 100644 (file)
@@ -19,6 +19,8 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <locale.h>
+
 #include "main.h"
 #include "metadata.h"
 
@@ -298,11 +300,13 @@ gboolean metadata_write_perform(FileData *fd)
 {
        gboolean success;
        ExifData *exif;
+       guint lf;
 
        g_assert(fd->change);
 
+       lf = strlen(GQ_CACHE_EXT_METADATA);
        if (fd->change->dest &&
-           strcmp(registered_extension_from_path(fd->change->dest), GQ_CACHE_EXT_METADATA) == 0)
+           g_ascii_strncasecmp(fd->change->dest + strlen(fd->change->dest) - lf, GQ_CACHE_EXT_METADATA, lf) == 0)
                {
                success = metadata_legacy_write(fd);
                if (success) metadata_legacy_delete(fd, fd->change->dest);
@@ -324,7 +328,9 @@ gboolean metadata_write_perform(FileData *fd)
                   (we can't wait until the sidecar is discovered by directory scanning because
                    exif_read_fd is called before that and it would read the main file only and
                    store the metadata in the cache)
-                   FIXME: this does not catch new sidecars created by independent external programs
+               */
+               /**
+               @FIXME this does not catch new sidecars created by independent external programs
                */
                file_data_unref(file_data_new_group(fd->change->dest));
 
@@ -666,7 +672,7 @@ GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format)
        const GList *cache_entry;
        if (!fd) return NULL;
 
-       /* unwritten data overide everything */
+       /* unwritten data override everything */
        if (fd->modified_xmp && format == METADATA_PLAIN)
                {
                list = g_hash_table_lookup(fd->modified_xmp, key);
@@ -707,6 +713,12 @@ GList *metadata_read_list(FileData *fd, const gchar *key, MetadataFormat format)
                {
                return g_list_append(NULL, metadata_file_info(fd, key, format));
                }
+#ifdef HAVE_LUA
+       else if (strncmp(key, "lua.", 4) == 0)
+               {
+               return g_list_append(NULL, metadata_lua_info(fd, key, format));
+               }
+#endif
 
        exif = exif_read_fd(fd); /* this is cached, thus inexpensive */
        if (!exif) return NULL;
@@ -747,6 +759,16 @@ guint64 metadata_read_int(FileData *fd, const gchar *key, guint64 fallback)
        return ret;
 }
 
+gchar *metadata_read_rating_stars(FileData *fd)
+{
+       gchar *ret;
+       gint n = metadata_read_int(fd, RATING_KEY, METADATA_PLAIN);
+
+       ret = convert_rating_to_stars(n);
+
+       return ret;
+}
+
 gdouble metadata_read_GPS_coord(FileData *fd, const gchar *key, gdouble fallback)
 {
        gdouble coord;
@@ -841,6 +863,7 @@ gboolean metadata_write_GPS_coord(FileData *fd, const gchar *key, gdouble value)
        char *coordinate;
        char *ref;
        gboolean ok = TRUE;
+       char *old_locale, *saved_locale;
 
        param = value;
        if (param < 0)
@@ -865,8 +888,20 @@ gboolean metadata_write_GPS_coord(FileData *fd, const gchar *key, gdouble value)
 
        if (ok)
                {
+               /* Avoid locale problems with commas and decimal points in numbers */
+               old_locale = setlocale(LC_ALL, NULL);
+               saved_locale = strdup(old_locale);
+               if (saved_locale == NULL)
+                       {
+                       return FALSE;
+                       }
+               setlocale(LC_ALL, "C");
+
                coordinate = g_strdup_printf("%i,%lf,%s", deg, min, ref);
                metadata_write_string(fd, key, coordinate );
+
+               setlocale(LC_ALL, saved_locale);
+               free(saved_locale);
                g_free(coordinate);
                }
 
@@ -894,7 +929,7 @@ gboolean metadata_append_list(FileData *fd, const gchar *key, const GList *value
 }
 
 /**
- * \see find_string_in_list
+ * @see find_string_in_list
  */
 gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string)
 {
@@ -927,7 +962,7 @@ gchar *find_string_in_list_utf8nocase(GList *list, const gchar *string)
 }
 
 /**
- * \see find_string_in_list
+ * @see find_string_in_list
  */
 gchar *find_string_in_list_utf8case(GList *list, const gchar *string)
 {
@@ -945,18 +980,18 @@ gchar *find_string_in_list_utf8case(GList *list, const gchar *string)
 } // gchar *find_string_in_list_utf...
 
 /**
- * \brief Find a existent string in a list.
+ * @brief Find a existent string in a list.
  *
  * This is a switch between find_string_in_list_utf8case and
  * find_string_in_list_utf8nocase to search with or without case for the
  * existence of a string.
  *
- * \param list The list to search in
- * \param string The string to search for
- * \return The string or NULL
+ * @param list The list to search in
+ * @param string The string to search for
+ * @return The string or NULL
  *
- * \see find_string_in_list_utf8case
- * \see find_string_in_list_utf8nocase
+ * @see find_string_in_list_utf8case
+ * @see find_string_in_list_utf8nocase
  */
 gchar *find_string_in_list(GList *list, const gchar *string)
 {
@@ -1012,7 +1047,7 @@ GList *string_to_keywords_list(const gchar *text)
 
 gboolean meta_data_get_keyword_mark(FileData *fd, gint n, gpointer data)
 {
-       /* FIXME: do not use global keyword_tree */
+       /** @FIXME do not use global keyword_tree */
        GList *path = data;
        GList *keywords;
        gboolean found = FALSE;
@@ -1810,6 +1845,35 @@ void keyword_tree_write_config(GString *outstr, gint indent)
        WRITE_NL(); WRITE_STRING("</keyword_tree>");
 }
 
+ void keyword_tree_node_disconnect_marks(GtkTreeModel *keyword_tree, GtkTreeIter *iter_ptr)
+{
+       GtkTreeIter iter = *iter_ptr;
+
+       while (TRUE)
+               {
+               GtkTreeIter children;
+
+               meta_data_connect_mark_with_keyword((keyword_tree), &iter, -1);
+
+               if (gtk_tree_model_iter_children((keyword_tree), &children, &iter))
+                       {
+                       keyword_tree_node_disconnect_marks((keyword_tree), &children);
+                       }
+
+               if (!gtk_tree_model_iter_next((keyword_tree), &iter)) return;
+               }
+}
+
+void keyword_tree_disconnect_marks()
+{
+       GtkTreeIter iter;
+
+       if (keyword_tree && gtk_tree_model_get_iter_first(GTK_TREE_MODEL(keyword_tree), &iter))
+               {
+               keyword_tree_node_disconnect_marks(GTK_TREE_MODEL(keyword_tree), &iter);
+               }
+}
+
 GtkTreeIter *keyword_add_from_config(GtkTreeStore *keyword_tree, GtkTreeIter *parent, const gchar **attribute_names, const gchar **attribute_values)
 {
        gchar *name = NULL;