[gthumb/gthumb-3-10] search: stop searching if the user changes location
- From: Paolo Bacchilega <paobac src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gthumb/gthumb-3-10] search: stop searching if the user changes location
- Date: Sun, 31 Jan 2021 11:41:35 +0000 (UTC)
commit a5d7c4428df61176404176a9e77291cc6014d558
Author: Paolo Bacchilega <paobac src gnome org>
Date: Sun Jan 10 10:34:20 2021 +0100
search: stop searching if the user changes location
extensions/search/callbacks.c | 28 ++++++++++++++++++++++++++++
extensions/search/callbacks.h | 2 ++
extensions/search/gth-search-task.c | 8 ++++++++
extensions/search/gth-search-task.h | 9 +++++----
extensions/search/main.c | 1 +
gthumb/gth-browser.c | 12 +++++++++++-
gthumb/gth-browser.h | 1 +
7 files changed, 56 insertions(+), 5 deletions(-)
---
diff --git a/extensions/search/callbacks.c b/extensions/search/callbacks.c
index 612d0115..2d9a7e52 100644
--- a/extensions/search/callbacks.c
+++ b/extensions/search/callbacks.c
@@ -125,6 +125,34 @@ search__gth_browser_update_extra_widget_cb (GthBrowser *browser)
}
+void
+search__gth_browser_load_location_before_cb (GthBrowser *browser,
+ GFile *next_location)
+{
+ GFile *current_location;
+ GthTask *task;
+ GFile *catalog;
+
+ /* Stop the search task if the user changes location. */
+
+ current_location = gth_browser_get_location (browser);
+ if (current_location == NULL)
+ return;
+
+ if (_g_file_equal (current_location, next_location))
+ return;
+
+ task = gth_browser_get_foreground_task (browser);
+ if ((task == NULL) || ! GTH_IS_SEARCH_TASK (task))
+ return;
+
+ catalog = gth_search_task_get_catalog (GTH_SEARCH_TASK (task));
+
+ if (_g_file_equal (current_location, catalog))
+ gth_task_cancel (task);
+}
+
+
GthCatalog *
search__gth_catalog_load_from_data_cb (const void *buffer)
{
diff --git a/extensions/search/callbacks.h b/extensions/search/callbacks.h
index 1ee9103b..f27bc530 100644
--- a/extensions/search/callbacks.h
+++ b/extensions/search/callbacks.h
@@ -29,6 +29,8 @@
void search__gth_browser_construct_cb (GthBrowser *browser);
void search__gth_browser_update_sensitivity_cb (GthBrowser *browser);
void search__gth_browser_update_extra_widget_cb (GthBrowser *browser);
+void search__gth_browser_load_location_before_cb (GthBrowser *browser,
+ GFile *location);
GthCatalog * search__gth_catalog_load_from_data_cb (const void *buffer);
GthCatalog * search__gth_catalog_new_for_uri_cb (const char *uri);
void search__dlg_catalog_properties (GtkBuilder *builder,
diff --git a/extensions/search/gth-search-task.c b/extensions/search/gth-search-task.c
index 10a225f3..d4afbe7e 100644
--- a/extensions/search/gth-search-task.c
+++ b/extensions/search/gth-search-task.c
@@ -510,3 +510,11 @@ gth_search_task_new (GthBrowser *browser,
return (GthTask*) task;
}
+
+
+GFile *
+gth_search_task_get_catalog (GthSearchTask *task)
+{
+ g_return_val_if_fail (GTH_IS_SEARCH_TASK (task), NULL);
+ return task->priv->search_catalog;
+}
diff --git a/extensions/search/gth-search-task.h b/extensions/search/gth-search-task.h
index 83bd1e45..b3425505 100644
--- a/extensions/search/gth-search-task.h
+++ b/extensions/search/gth-search-task.h
@@ -48,9 +48,10 @@ struct _GthSearchTaskClass
GthTaskClass __parent_class;
};
-GType gth_search_task_get_type (void) G_GNUC_CONST;
-GthTask * gth_search_task_new (GthBrowser *browser,
- GthSearch *search,
- GFile *search_catalog);
+GType gth_search_task_get_type (void) G_GNUC_CONST;
+GthTask * gth_search_task_new (GthBrowser *browser,
+ GthSearch *search,
+ GFile *search_catalog);
+GFile * gth_search_task_get_catalog (GthSearchTask *task);
#endif /* GTH_SEARCH_TASK_H */
diff --git a/extensions/search/main.c b/extensions/search/main.c
index 1d11a498..599a0d2e 100644
--- a/extensions/search/main.c
+++ b/extensions/search/main.c
@@ -33,6 +33,7 @@ gthumb_extension_activate (void)
gth_hook_add_callback ("gth-catalog-new-for-uri", 10, G_CALLBACK
(search__gth_catalog_new_for_uri_cb), NULL);
gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (search__gth_browser_construct_cb),
NULL);
gth_hook_add_callback ("gth-browser-update-extra-widget", 20, G_CALLBACK
(search__gth_browser_update_extra_widget_cb), NULL);
+ gth_hook_add_callback ("gth-browser-load-location-before", 10, G_CALLBACK
(search__gth_browser_load_location_before_cb), NULL);
gth_hook_add_callback ("dlg-catalog-properties", 10, G_CALLBACK (search__dlg_catalog_properties),
NULL);
gth_hook_add_callback ("dlg-catalog-properties-save", 10, G_CALLBACK
(search__dlg_catalog_properties_save), NULL);
gth_hook_add_callback ("dlg-catalog-properties-saved", 10, G_CALLBACK
(search__dlg_catalog_properties_saved), NULL);
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index a933c79e..e7b34af5 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -5104,7 +5104,10 @@ gth_browser_new (GFile *location,
GFile *
gth_browser_get_location (GthBrowser *browser)
{
- return browser->priv->location->file;
+ if (browser->priv->location != NULL)
+ return browser->priv->location->file;
+ else
+ return NULL;
}
@@ -5699,6 +5702,13 @@ gth_browser_exec_task (GthBrowser *browser,
}
+GthTask *
+gth_browser_get_foreground_task (GthBrowser *browser)
+{
+ return browser->priv->task;
+}
+
+
void
gth_browser_set_close_with_task (GthBrowser *browser,
gboolean value)
diff --git a/gthumb/gth-browser.h b/gthumb/gth-browser.h
index f3119802..003224e0 100644
--- a/gthumb/gth-browser.h
+++ b/gthumb/gth-browser.h
@@ -218,6 +218,7 @@ void gth_browser_reload (GthBrowser *browser);
void gth_browser_exec_task (GthBrowser *browser,
GthTask *task,
GthTaskFlags flags);
+GthTask * gth_browser_get_foreground_task (GthBrowser *browser);
void gth_browser_set_close_with_task (GthBrowser *browser,
gboolean value);
gboolean gth_browser_get_close_with_task (GthBrowser *browser);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]