/*
- * Geeqie
- * (C) 2005 John Ellis
- * Copyright (C) 2008 - 2010 The Geeqie Team
+ * Copyright (C) 2005 John Ellis
+ * Copyright (C) 2008 - 2016 The Geeqie Team
*
* Author: John Ellis
*
- * This software is released under the GNU General Public License (GNU GPL).
- * Please read the included file COPYING for more information.
- * This software comes with no warranty of any kind, use at your own risk!
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
#include "main.h"
#include "search.h"
#include "image-load.h"
#include "img-view.h"
#include "layout.h"
+#include "math.h"
#include "menu.h"
#include "metadata.h"
#include "misc.h"
#define SEARCH_BUFFER_MATCH_MISS 1
#define SEARCH_BUFFER_FLUSH_SIZE 99
-
typedef enum {
SEARCH_MATCH_NONE,
SEARCH_MATCH_EQUAL,
GList *search_keyword_list;
gchar *search_comment;
gboolean search_comment_match_case;
+ gboolean search_date_exif;
MatchType search_type;
MatchType match_dimensions;
MatchType match_keywords;
MatchType match_comment;
+ MatchType match_gps;
gboolean match_name_enable;
gboolean match_size_enable;
ThumbLoader *thumb_loader;
gboolean thumb_enable;
FileData *thumb_fd;
+
+ /* Used for lat/long coordinate search
+ */
+ gint search_gps;
+ gdouble search_lat, search_lon;
+ GtkWidget *entry_gps_coord;
+ GtkWidget *check_gps;
+ GtkWidget *spin_gps;
+ GtkWidget *units_gps;
+ GtkWidget *menu_gps;
+ gboolean match_gps_enable;
+
};
typedef struct _MatchFileData MatchFileData;
{ N_("miss"), SEARCH_MATCH_NONE }
};
+static const MatchList text_search_menu_gps[] = {
+ { N_("not geocoded"), SEARCH_MATCH_NONE },
+ { N_("less than"), SEARCH_MATCH_UNDER },
+ { N_("greater than"), SEARCH_MATCH_OVER }
+};
+
static GList *search_window_list = NULL;
t = search_result_count(sd, &t_bytes);
s = search_result_selection_count(sd, &s_bytes);
-
+
tt = text_from_size_abrev(t_bytes);
if (s > 0)
gtk_tree_view_column_set_fixed_width(column, (sd->thumb_enable) ? options->thumbnails.max_width : 4);
-#if GTK_CHECK_VERSION(2,18,0)
list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(column));
-#else
- list = gtk_tree_view_column_get_cell_renderers(column);
-#endif
if (!list) return;
cell = list->data;
g_list_free(list);
if (event->state & GDK_CONTROL_MASK)
{
- gint edit_val = -1;
-
stop_signal = TRUE;
switch (event->keyval)
{
case '1':
- edit_val = 0;
- break;
case '2':
- edit_val = 1;
- break;
case '3':
- edit_val = 2;
- break;
case '4':
- edit_val = 3;
- break;
case '5':
- edit_val = 4;
- break;
case '6':
- edit_val = 5;
- break;
case '7':
- edit_val = 6;
- break;
case '8':
- edit_val = 7;
- break;
case '9':
- edit_val = 8;
- break;
case '0':
- edit_val = 9;
break;
case 'C': case 'c':
file_util_copy(NULL, search_result_selection_list(sd), NULL, widget);
gtk_tree_selection_select_all(selection);
}
break;
- case GDK_Delete: case GDK_KP_Delete:
+ case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
search_result_clear(sd);
break;
default:
stop_signal = FALSE;
break;
}
-#if 0
- if (edit_val >= 0)
- {
- search_result_edit_selected(sd, edit_val);
- }
-#endif
}
else
{
stop_signal = TRUE;
switch (event->keyval)
{
- case GDK_Return: case GDK_KP_Enter:
+ case GDK_KEY_Return: case GDK_KEY_KP_Enter:
if (mfd) layout_set_fd(NULL, mfd->fd);
break;
case 'V': case 'v':
filelist_free(list);
}
break;
- case GDK_Delete: case GDK_KP_Delete:
+ case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
search_result_remove_selection(sd);
break;
case 'C': case 'c':
search_result_collection_from_selection(sd);
break;
- case GDK_Menu:
- case GDK_F10:
+ case GDK_KEY_Menu:
+ case GDK_KEY_F10:
{
GtkWidget *menu;
- sd->click_fd = mfd->fd;
+ if (mfd)
+ sd->click_fd = mfd->fd;
+ else
+ sd->click_fd = NULL;
+
menu = search_result_menu(sd, (mfd != NULL), (search_result_count(sd, NULL) > 0));
gtk_menu_popup(GTK_MENU(menu), NULL, NULL,
search_result_menu_pos_cb, sd, 0, GDK_CURRENT_TIME);
}
break;
+ case GDK_KEY_F1:
+ help_window_show("GuideReferenceKeyboardShortcuts.html#SearchKeyboardShortcuts");
+ break;
default:
stop_signal = FALSE;
break;
};
static gint n_result_drag_types = 2;
+static GtkTargetEntry result_drop_types[] = {
+ { "text/uri-list", 0, TARGET_URI_LIST },
+ { "text/plain", 0, TARGET_TEXT_PLAIN }
+};
+static gint n_result_drop_types = 2;
+
static void search_dnd_data_set(GtkWidget *widget, GdkDragContext *context,
GtkSelectionData *selection_data, guint info,
guint time, gpointer data)
{
SearchData *sd = data;
- gchar *uri_text;
- gint length;
GList *list;
- switch (info)
- {
- case TARGET_URI_LIST:
- case TARGET_TEXT_PLAIN:
- list = search_result_selection_list(sd);
- if (!list) return;
- uri_text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN));
- filelist_free(list);
- break;
- default:
- uri_text = NULL;
- break;
- }
+ list = search_result_selection_list(sd);
+ if (!list) return;
- if (uri_text) gtk_selection_data_set(selection_data, selection_data->target,
- 8, (guchar *)uri_text, length);
- g_free(uri_text);
+ uri_selection_data_set_uris_from_filelist(selection_data, list);
+ filelist_free(list);
}
static void search_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data)
}
}
+static void search_gps_dnd_received_cb(GtkWidget *pane, GdkDragContext *context,
+ gint x, gint y,
+ GtkSelectionData *selection_data, guint info,
+ guint time, gpointer data)
+{
+ SearchData *sd = data;
+ GList *list;
+ gdouble latitude, longitude;
+ FileData *fd;
+
+ if (info == TARGET_URI_LIST)
+ {
+ list = uri_filelist_from_gtk_selection_data(selection_data);
+
+ /* If more than one file, use only the first file in a list.
+ */
+ if (list != NULL)
+ {
+ fd = list->data;
+ latitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLatitude", 1000);
+ longitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLongitude", 1000);
+ if (latitude != 1000 && longitude != 1000)
+ {
+ gtk_entry_set_text(GTK_ENTRY(sd->entry_gps_coord),
+ g_strdup_printf("%lf %lf", latitude, longitude));
+ }
+ else
+ {
+ gtk_entry_set_text(GTK_ENTRY(sd->entry_gps_coord), "Image is not geocoded");
+ }
+ }
+ }
+
+ if (info == TARGET_TEXT_PLAIN)
+ {
+ gtk_entry_set_text(GTK_ENTRY(sd->entry_gps_coord),"");
+ }
+}
+
static void search_dnd_init(SearchData *sd)
{
gtk_drag_source_set(sd->result_view, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
G_CALLBACK(search_dnd_data_set), sd);
g_signal_connect(G_OBJECT(sd->result_view), "drag_begin",
G_CALLBACK(search_dnd_begin), sd);
-#if 0
- g_signal_connect(G_OBJECT(sd->result_view), "drag_end",
- G_CALLBACK(search_dnd_end), sd);
-#endif
+ gtk_drag_dest_set(GTK_WIDGET(sd->entry_gps_coord),
+ GTK_DEST_DEFAULT_ALL,
+ result_drop_types, n_result_drop_types,
+ GDK_ACTION_COPY);
+
+ g_signal_connect(G_OBJECT(sd->entry_gps_coord), "drag_data_received",
+ G_CALLBACK(search_gps_dnd_received_cb), sd);
}
/*
gint width = 0;
gint height = 0;
gint sim = 0;
+ time_t file_date;
if (!sd->search_file_list) return FALSE;
tested = TRUE;
match = FALSE;
+ if (sd->search_date_exif)
+ {
+ read_exif_time_data(fd);
+ file_date = fd->exifdate;
+ }
+ else
+ {
+ file_date = fd->date;
+ }
+
if (sd->match_date == SEARCH_MATCH_EQUAL)
{
struct tm *lt;
- lt = localtime(&fd->date);
+ lt = localtime(&file_date);
match = (lt &&
lt->tm_year == sd->search_date_y - 1900 &&
lt->tm_mon == sd->search_date_m - 1 &&
}
else if (sd->match_date == SEARCH_MATCH_UNDER)
{
- match = (fd->date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y));
+ match = (file_date < convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y));
}
else if (sd->match_date == SEARCH_MATCH_OVER)
{
- match = (fd->date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1);
+ match = (file_date > convert_dmy_to_time(sd->search_date_d, sd->search_date_m, sd->search_date_y) + 60 * 60 * 24 - 1);
}
else if (sd->match_date == SEARCH_MATCH_BETWEEN)
{
{
a += 60 * 60 * 24 - 1;
}
- match = MATCH_IS_BETWEEN(fd->date, a, b);
+ match = MATCH_IS_BETWEEN(file_date, a, b);
}
}
}
}
- if ((match || extra_only) &&
- (sd->match_dimensions_enable || sd->match_similarity_enable))
+ if (match && sd->match_gps_enable)
+ {
+ /* Calculate the distance the image is from the specified origin.
+ * This is a standard algorithm. A simplified one may be faster.
+ */
+ #define RADIANS 0.0174532925
+ #define KM_EARTH_RADIUS 6371
+ #define MILES_EARTH_RADIUS 3959
+ #define NAUTICAL_MILES_EARTH_RADIUS 3440
+
+ gdouble latitude, longitude, range, conversion;
+
+ if (g_strcmp0(gtk_combo_box_text_get_active_text(
+ GTK_COMBO_BOX_TEXT(sd->units_gps)), _("km")) == 0)
+ {
+ conversion = KM_EARTH_RADIUS;
+ }
+ else if (g_strcmp0(gtk_combo_box_text_get_active_text(
+ GTK_COMBO_BOX_TEXT(sd->units_gps)), _("miles")) == 0)
+ {
+ conversion = MILES_EARTH_RADIUS;
+ }
+ else
+ {
+ conversion = NAUTICAL_MILES_EARTH_RADIUS;
+ }
+
+ tested = TRUE;
+ match = FALSE;
+
+ latitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLatitude", 1000);
+ longitude = metadata_read_GPS_coord(fd, "Xmp.exif.GPSLongitude", 1000);
+ if (latitude != 1000 && longitude != 1000)
+ {
+ range = conversion * acos(sin(latitude * RADIANS) *
+ sin(sd->search_lat * RADIANS) + cos(latitude * RADIANS) *
+ cos(sd->search_lat * RADIANS) * cos((sd->search_lon -
+ longitude) * RADIANS));
+ if (sd->match_gps == SEARCH_MATCH_UNDER)
+ {
+ if (sd->search_gps >= range)
+ match = TRUE;
+ }
+ else if (sd->match_gps == SEARCH_MATCH_OVER)
+ {
+ if (sd->search_gps < range)
+ match = TRUE;
+ }
+ }
+ else if (sd->match_gps == SEARCH_MATCH_NONE)
+ {
+ match = TRUE;
+ }
+ }
+
+ if ((match || extra_only) && (sd->match_dimensions_enable ||
+ sd ->match_similarity_enable))
{
tested = TRUE;
SearchData *sd = data;
GtkTreeViewColumn *column;
gchar *path;
+ gchar *entry_text;
if (sd->search_folder_list)
{
tab_completion_append_to_history(sd->entry_similarity, sd->search_similarity_path);
}
+ /* Check the coordinate entry.
+ * If the result is not sensible, it should get blocked.
+ */
+ if (sd->match_gps_enable)
+ {
+ if (sd->match_gps != SEARCH_MATCH_NONE)
+ {
+ entry_text = decode_geo_parameters(gtk_entry_get_text(
+ GTK_ENTRY(sd->entry_gps_coord)));
+
+ sd->search_lat = 1000;
+ sd->search_lon = 1000;
+ sscanf(entry_text," %lf %lf ", &sd->search_lat, &sd->search_lon );
+ if (!(entry_text != NULL && !g_strstr_len(entry_text, -1, "Error") &&
+ sd->search_lat >= -90 && sd->search_lat <= 90 &&
+ sd->search_lon >= -180 && sd->search_lon <= 180))
+ {
+ file_util_warning_dialog(_(
+ "Entry does not contain a valid lat/long value"),
+ entry_text, GTK_STOCK_DIALOG_WARNING, sd->window);
+ return;
+ }
+ g_free(entry_text);
+ }
+ }
+
string_list_free(sd->search_keyword_list);
sd->search_keyword_list = keyword_list_pull(sd->entry_keywords);
{
if (visible)
{
-#if GTK_CHECK_VERSION(2,20,0)
if (!gtk_widget_get_visible(widget)) gtk_widget_show(widget);
-#else
- if (!GTK_WIDGET_VISIBLE(widget)) gtk_widget_show(widget);
-#endif
}
else
{
-#if GTK_CHECK_VERSION(2,20,0)
if (gtk_widget_get_visible(widget)) gtk_widget_hide(widget);
-#else
- if (GTK_WIDGET_VISIBLE(widget)) gtk_widget_hide(widget);
-#endif
}
}
*value = (gint)gtk_adjustment_get_value(adjustment);
}
+static void menu_choice_gps_cb(GtkWidget *combo, gpointer data)
+{
+ SearchData *sd = data;
+
+ if (!menu_choice_get_match_type(combo, &sd->match_gps)) return;
+
+ menu_choice_set_visible(gtk_widget_get_parent(sd->spin_gps),
+ (sd->match_gps != SEARCH_MATCH_NONE));
+}
+
static GtkWidget *menu_spin(GtkWidget *box, gdouble min, gdouble max, gint value,
GCallback func, gpointer data)
{
sd->match_name_enable = TRUE;
sd->search_similarity = 95;
-
+
+ sd->search_gps = 1;
+ sd->match_gps = SEARCH_MATCH_NONE;
+
if (example_file)
{
sd->search_similarity_path = g_strdup(example_file->path);
date_selection_time_set(sd->date_sel_end, time(NULL));
gtk_box_pack_start(GTK_BOX(hbox2), sd->date_sel_end, FALSE, FALSE, 0);
gtk_widget_show(sd->date_sel_end);
+ pref_checkbox_new_int(hbox, _("Exif date"),
+ sd->search_date_exif, &sd->search_date_exif);
/* Search for image dimensions */
hbox = menu_choice(sd->box_search, &sd->check_dimensions, &sd->menu_dimensions,
pref_checkbox_new_int(hbox, _("Match case"),
sd->search_comment_match_case, &sd->search_comment_match_case);
+ /* Search for images within a specified range of a lat/long coordinate
+ */
+ hbox = menu_choice(sd->box_search, &sd->check_gps, &sd->menu_gps,
+ _("Image is"), &sd->match_gps_enable,
+ text_search_menu_gps, sizeof(text_search_menu_gps) / sizeof(MatchList),
+ G_CALLBACK(menu_choice_gps_cb), sd);
+
+ hbox2 = gtk_hbox_new(FALSE, PREF_PAD_SPACE);
+ gtk_box_pack_start(GTK_BOX(hbox), hbox2, FALSE, FALSE, 0);
+ sd->spin_gps = menu_spin(hbox2, 1, 9999, sd->search_gps,
+ G_CALLBACK(menu_choice_spin_cb), &sd->search_gps);
+
+ sd->units_gps = gtk_combo_box_text_new();
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sd->units_gps), _("km"));
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sd->units_gps), _("miles"));
+ gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(sd->units_gps), _("n.m."));
+ gtk_box_pack_start(GTK_BOX(hbox2), sd->units_gps, FALSE, FALSE, 0);
+ gtk_combo_box_set_active(GTK_COMBO_BOX(sd->units_gps), 0);
+ gtk_widget_set_tooltip_text(sd->units_gps, "kilometres, miles or nautical miles");
+ gtk_widget_show(sd->units_gps);
+
+ pref_label_new(hbox2, _("from"));
+
+ sd->entry_gps_coord = gtk_entry_new();
+ gtk_editable_set_editable(GTK_EDITABLE(sd->entry_gps_coord), TRUE);
+ gtk_widget_set_has_tooltip(sd->entry_gps_coord, TRUE);
+ gtk_widget_set_tooltip_text(sd->entry_gps_coord, _("Enter a coordinate in the form:\n89.123 179.456\nor drag-and-drop a geo-coded image\nor left-click on the map and paste\nor cut-and-paste or drag-and-drop\nan internet search URL\nSee the Help file"));
+ gtk_box_pack_start(GTK_BOX(hbox2), sd->entry_gps_coord, TRUE, TRUE, 0);
+ gtk_widget_set_sensitive(sd->entry_gps_coord, TRUE);
+
+ gtk_widget_show(sd->entry_gps_coord);
+
/* Done the types of searches */
scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(sd->result_view), TRUE);
gtk_tree_view_set_enable_search(GTK_TREE_VIEW(sd->result_view), FALSE);
-#if 0
- gtk_tree_view_set_search_column(GTK_TREE_VIEW(sd->result_view), SEARCH_COLUMN_NAME);
-#endif
-
search_result_add_column(sd, SEARCH_COLUMN_RANK, _("Rank"), FALSE, FALSE);
search_result_add_column(sd, SEARCH_COLUMN_THUMB, "", TRUE, FALSE);
search_result_add_column(sd, SEARCH_COLUMN_NAME, _("Name"), FALSE, FALSE);
sd->label_progress = gtk_progress_bar_new();
gtk_widget_set_size_request(sd->label_progress, 50, -1);
+#if GTK_CHECK_VERSION(3,0,0)
+ gtk_progress_bar_set_text(GTK_PROGRESS_BAR(sd->label_progress), "");
+ gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(sd->label_progress), TRUE);
+#endif
gtk_box_pack_start(GTK_BOX(hbox), sd->label_progress, TRUE, TRUE, 0);
gtk_widget_show(sd->label_progress);
if (!(type & NOTIFY_CHANGE) || !fd->change) return;
DEBUG_1("Notify search: %s %04x", fd->path, type);
-
+
switch (fd->change->type)
{
case FILEDATA_CHANGE_MOVE: