Include a Other Software section in Help file
[geeqie.git] / src / exif-common.c
index 400a2fb..833a86c 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"
@@ -662,7 +663,7 @@ static void zd_tz(ZoneDetectResult *results, gchar **timezone, gchar **countryna
 /**
  * @brief Gets timezone data from an exif structure
  * @param[in] exif
- * @returns TRUE if timezone data found
+ * @returns TRUE if timezone data found AND GPS date and time found
  * @param[out] exif_date_time exif date/time in the form 2018:11:30:17:05:04
  * @param[out] timezone in the form "Europe/London"
  * @param[out] countryname in the form "United Kingdom"
@@ -684,10 +685,12 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
        gchar *lat_min;
        gchar *lon_deg;
        gchar *lon_min;
-       gchar *zd_path;
+       gchar *timezone_path;
        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");
@@ -696,13 +699,14 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
        text_date = exif_get_data_as_text(exif, "Exif.GPSInfo.GPSDateStamp");
        text_time = exif_get_data_as_text(exif, "Exif.GPSInfo.GPSTimeStamp");
 
-       if (text_latitude && text_longitude && text_latitude_ref &&
-                                               text_longitude_ref && text_date && text_time)
+       if (text_latitude && text_longitude && text_latitude_ref && text_longitude_ref)
                {
-               *exif_date_time = g_strconcat(text_date, ":", text_time, NULL);
-
                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"))
                        {
@@ -710,16 +714,22 @@ 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;
                        }
 
-               zd_path = g_build_filename(GQ_BIN_DIR, TIMEZONE_DATABASE, NULL);
-               if (g_file_test(zd_path, G_FILE_TEST_EXISTS))
+               path = path_from_utf8(TIMEZONE_DATABASE);
+               basename = g_path_get_basename(path);
+               timezone_path = g_build_filename(get_rc_dir(), basename, NULL);
+               if (g_file_test(timezone_path, G_FILE_TEST_EXISTS))
                        {
-                       cd = ZDOpenDatabase(zd_path);
+                       cd = ZDOpenDatabase(timezone_path);
                        if (cd)
                                {
                                results = ZDLookup(cd, latitude, longitude, NULL);
@@ -731,13 +741,23 @@ static gboolean exif_build_tz_data(ExifData *exif, gchar **exif_date_time, gchar
                                }
                        else
                                {
-                               log_printf("Error: Init of timezone database %s failed\n", zd_path);
+                               log_printf("Error: Init of timezone database %s failed\n", timezone_path);
                                }
                        ZDCloseDatabase(cd);
                        }
-               g_free(zd_path);
+               g_free(path);
+               g_free(timezone_path);
+               g_free(basename);
                }
 
+       if (ret && text_date && text_time)
+               {
+               *exif_date_time = g_strconcat(text_date, ":", text_time, NULL);
+               }
+       else
+               {
+               ret = FALSE;
+               }
        return ret;
 }
 
@@ -795,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);
 
@@ -822,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;
@@ -924,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 }
 };
 
@@ -949,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;
 
@@ -1172,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);
@@ -1204,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: */