#include "filefilter.h"
#include "filecache.h"
#include "format_raw.h"
+#include "glua.h"
#include "ui_fileops.h"
#include "cache.h"
#include "jpeg_parser.h"
/**
* @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"
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");
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"))
{
}
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);
}
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;
}
else
{
g_free(exif_date_time);
- exif_date_time = g_strdup(tmp);
+ exif_date_time = tmp;
}
}
- g_free(tmp);
}
putenv(time_zone_org);
*/
static gchar *exif_build_formatted_timezone(ExifData *exif)
{
- gchar *time_zone = NULL;
gchar *exif_date_time = NULL;
gchar *timezone = NULL;
gchar *countryname = NULL;
{"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 }
};
{
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;
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);
{
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: */