Commit 463199a1 authored by Eric Gregory's avatar Eric Gregory

Closes #7031 Searches can now be cancelled

parent ec8d68ca
......@@ -66,6 +66,7 @@ public class GearyController {
private Geary.ConversationMonitor? current_conversations = null;
private Cancellable cancellable_folder = new Cancellable();
private Cancellable cancellable_message = new Cancellable();
private Cancellable cancellable_search = new Cancellable();
private Gee.HashMap<Geary.Account, Cancellable> inbox_cancellables
= new Gee.HashMap<Geary.Account, Cancellable>();
private int busy_count = 0;
......@@ -783,6 +784,13 @@ public class GearyController {
old_cancellable.cancel();
}
private void cancel_search() {
Cancellable old_cancellable = cancellable_search;
cancellable_search = new Cancellable();
old_cancellable.cancel();
}
// We need to include the second parameter, or valac doesn't recognize the function as matching
// YorbaApplication.exiting's signature.
private bool on_application_exiting(YorbaApplication sender, bool panicked) {
......@@ -1469,11 +1477,13 @@ public class GearyController {
if (current_account == null)
return;
cancel_search(); // Stop any search in progress.
Geary.SearchFolder? folder;
try {
folder = (Geary.SearchFolder) current_account.get_special_folder(
Geary.SpecialFolderType.SEARCH);
folder.set_search_keywords(search_text);
folder.set_search_keywords(search_text, cancellable_search);
} catch (Error e) {
debug("Could not get search folder: %s", e.message);
......
......@@ -57,9 +57,9 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder {
/**
* Sets the keyword string for this search.
*/
public void set_search_keywords(string keywords) {
public void set_search_keywords(string keywords, Cancellable? cancellable = null) {
search_keywords_changed(keywords);
set_search_keywords_async.begin(keywords, on_set_search_keywords_complete);
set_search_keywords_async.begin(keywords, cancellable, on_set_search_keywords_complete);
}
private void on_set_search_keywords_complete(Object? source, AsyncResult result) {
......@@ -70,12 +70,12 @@ public class Geary.SearchFolder : Geary.AbstractLocalFolder {
}
}
private async void set_search_keywords_async(string keywords) throws Error {
private async void set_search_keywords_async(string keywords, Cancellable? cancellable = null) throws Error {
int result_mutex_token = yield result_mutex.claim_async();
Error? error = null;
try {
Gee.Collection<Geary.Email>? _new_results = yield account.local_search_async(
keywords, Geary.Email.Field.PROPERTIES, false, exclude_folders, null, null);
keywords, Geary.Email.Field.PROPERTIES, false, exclude_folders, null, cancellable);
if (_new_results == null) {
// No results? Remove all existing results and return early. If there are no
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment