Update installation script for metadata spelling
[geeqie.git] / src / exif-common.c
index 9463a5b..4d14b75 100644 (file)
@@ -53,6 +53,7 @@
 #include "filefilter.h"
 #include "filecache.h"
 #include "format_raw.h"
+#include "glua.h"
 #include "ui_fileops.h"
 #include "cache.h"
 #include "jpeg_parser.h"
@@ -659,6 +660,11 @@ static void zd_tz(ZoneDetectResult *results, gchar **timezone, gchar **countryna
        g_free(timezone_id);
 }
 
+void ZoneDetect_onError(int errZD, int errNative)
+{
+       log_printf("Error: ZoneDetect %s (0x%08X)\n", ZDGetErrorString(errZD), (unsigned)errNative);
+}
+
 /**
  * @brief Gets timezone data from an exif structure
  * @param[in] exif
@@ -688,8 +694,6 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
        ZoneDetect *cd;
        ZoneDetectResult *results;
        gboolean ret = FALSE;
-       gchar *basename;
-       gchar *path;
 
        text_latitude = exif_get_data_as_text(exif, "Exif.GPSInfo.GPSLatitude");
        text_longitude = exif_get_data_as_text(exif, "Exif.GPSInfo.GPSLongitude");
@@ -702,6 +706,10 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
                {
                lat_deg = strtok(text_latitude, "deg'");
                lat_min = strtok(NULL, "deg'");
+               if (!lat_deg || !lat_min)
+                       {
+                       return FALSE;
+                       }
                latitude = atof(lat_deg) + atof(lat_min) / 60;
                if (!g_strcmp0(text_latitude_ref, "South"))
                        {
@@ -709,17 +717,20 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
                        }
                lon_deg = strtok(text_longitude, "deg'");
                lon_min = strtok(NULL, "deg'");
+               if (!lon_deg || !lon_min)
+                       {
+                       return FALSE;
+                       }
                longitude = atof(lon_deg) + atof(lon_min) / 60;
                if (!g_strcmp0(text_longitude_ref, "West"))
                        {
                        longitude = -longitude;
                        }
 
-               path = path_from_utf8(TIMEZONE_DATABASE);
-               basename = g_path_get_basename(path);
-               timezone_path = g_build_filename(get_rc_dir(), basename, NULL);
+               timezone_path = g_build_filename(get_rc_dir(), TIMEZONE_DATABASE_FILE, NULL);
                if (g_file_test(timezone_path, G_FILE_TEST_EXISTS))
                        {
+                       ZDSetErrorHandler(ZoneDetect_onError);
                        cd = ZDOpenDatabase(timezone_path);
                        if (cd)
                                {
@@ -736,9 +747,7 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
                                }
                        ZDCloseDatabase(cd);
                        }
-               g_free(path);
                g_free(timezone_path);
-               g_free(basename);
                }
 
        if (ret && text_date && text_time)
@@ -806,10 +815,9 @@ static gchar *exif_build_formatted_localtime(ExifData *exif)
                                else
                                        {
                                        g_free(exif_date_time);
-                                       exif_date_time = g_strdup(tmp);
+                                       exif_date_time = tmp;
                                        }
                                }
-                               g_free(tmp);
                        }
                putenv(time_zone_org);
 
@@ -833,7 +841,6 @@ static gchar *exif_build_formatted_localtime(ExifData *exif)
  */
 static gchar *exif_build_formatted_timezone(ExifData *exif)
 {
-       gchar *time_zone = NULL;
        gchar *exif_date_time = NULL;
        gchar *timezone = NULL;
        gchar *countryname = NULL;
@@ -935,6 +942,8 @@ ExifFormattedText ExifFormattedList[] = {
        {"file.group",                          N_("File group"),       NULL},
        {"file.link",                           N_("File link"),        NULL},
        {"file.class",                          N_("File class"),       NULL},
+       {"file.page_no",                        N_("Page no."),         NULL},
+       {"lua.lensID",                          N_("Lens"),             NULL},
        { NULL, NULL, NULL }
 };
 
@@ -960,8 +969,7 @@ gchar *exif_get_description_by_key(const gchar *key)
 {
        if (!key) return NULL;
 
-       if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0 ||
-           strncmp(key, "file.", 5) == 0)
+       if (strncmp(key, EXIF_FORMATTED(), EXIF_FORMATTED_LEN) == 0 || strncmp(key, "file.", 5) == 0 || strncmp(key, "lua.", 4) == 0)
                {
                gint i;
 
@@ -1140,7 +1148,7 @@ gboolean exif_jpeg_parse_color(ExifData *exif, guchar *data, guint size)
  * it is here because it shares tag neming infrastructure with exif
  * we should probably not invest too much effort into this because
  * new exiv2 will support the same functionality
- * http://dev.exiv2.org/issues/show/505
+ * https://dev.exiv2.org/issues/505
  *-------------------------------------------------------------------
  */
 
@@ -1183,6 +1191,8 @@ static gchar *mode_number(mode_t m)
 
 gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format)
 {
+       gchar *page_n_of_m;
+
        if (strcmp(key, "file.size") == 0)
                {
                return g_strdup_printf("%ld", (long)fd->size);
@@ -1215,8 +1225,43 @@ gchar *metadata_file_info(FileData *fd, const gchar *key, MetadataFormat format)
                {
                return g_strdup(fd->sym_link);
                }
+       if (strcmp(key, "file.page_no") == 0)
+               {
+               if (fd->page_total > 1)
+                       {
+                       page_n_of_m = g_strdup_printf("[%d/%d]", fd->page_num + 1, fd->page_total);
+                       return page_n_of_m;
+                       }
+               else
+                       {
+                       return NULL;
+                       }
+               }
        return g_strdup("");
 }
 
+#ifdef HAVE_LUA
+gchar *metadata_lua_info(FileData *fd, const gchar *key, MetadataFormat format)
+{
+       gchar *script_name;
+       gchar *script_name_utf8;
+       gchar *data;
+       gchar *raw_data;
+       gchar *valid_data;
+
+       script_name_utf8 = g_strdup(key + 4);
+       script_name = path_from_utf8(script_name_utf8);
+
+       raw_data = lua_callvalue(fd, script_name, NULL);
+       valid_data = g_utf8_make_valid(raw_data, -1);
+       data = g_utf8_substring(valid_data, 0, 150);
+
+       g_free(script_name);
+       g_free(script_name_utf8);
+       g_free(raw_data);
+       g_free(valid_data);
 
+       return data;
+}
+#endif
 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */