summaryrefslogtreecommitdiffstats
path: root/src/ui
diff options
context:
space:
mode:
authorAndrew rugby471@gmail.com <>2011-04-04 06:33:55 +0000
committerAndrew rugby471@gmail.com <>2011-04-04 06:33:55 +0000
commit4eac3bc8085a091a3fc97fcdbfeb0a688bfe3c3d (patch)
tree11a92a521a98915bafde19a332c6eb971db36476 /src/ui
parentMerge thumbnail and image downloading into one set of functions :) (diff)
downloadinkscape-4eac3bc8085a091a3fc97fcdbfeb0a688bfe3c3d.tar.gz
inkscape-4eac3bc8085a091a3fc97fcdbfeb0a688bfe3c3d.zip
implement cancelling
(bzr r10092.1.27)
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/dialog/ocaldialogs.cpp48
-rw-r--r--src/ui/dialog/ocaldialogs.h4
2 files changed, 42 insertions, 10 deletions
diff --git a/src/ui/dialog/ocaldialogs.cpp b/src/ui/dialog/ocaldialogs.cpp
index 6b1390863..889bd6776 100644
--- a/src/ui/dialog/ocaldialogs.cpp
+++ b/src/ui/dialog/ocaldialogs.cpp
@@ -669,7 +669,13 @@ void ImportDialog::on_list_results_cursor_changed()
posArray = pathlist[0].get_indices();
int row = posArray[0];
+ if (downloading_thumbnail) {
+ printf("Downloading thumbnail \n");
+ cancellable_thumbnail->cancel();
+ }
+
update_preview(row);
+ downloading_thumbnail = true;
download_resource(TYPE_THUMBNAIL, row);
}
void ImportDialog::update_preview(int row)
@@ -742,13 +748,18 @@ void ImportDialog::download_resource(ResourceType type, int row)
return;
}
- // Get Remote File URL
+ // Get Remote File URL and get the respective cancellable object
Glib::ustring url;
+ Glib::RefPtr<Gio::Cancellable> cancellable;
if (type == TYPE_IMAGE) {
url = list_results->get_text(row, RESULTS_COLUMN_URL);
+ cancellable_image = Gio::Cancellable::create();
+ cancellable = cancellable_image;
} else {
url = list_results->get_text(row, RESULTS_COLUMN_THUMBNAIL_URL);
+ cancellable_thumbnail = Gio::Cancellable::create();
+ cancellable = cancellable_thumbnail;
}
Glib::RefPtr<Gio::File> file_remote = Gio::File::create_for_uri(url);
@@ -757,14 +768,20 @@ void ImportDialog::download_resource(ResourceType type, int row)
file_remote->copy_async(file_local,
sigc::bind<Glib::RefPtr<Gio::File>, Glib::ustring, ResourceType>(
sigc::mem_fun(*this, &ImportDialog::on_resource_downloaded),
- file_remote, path, type),
+ file_remote, path, type), cancellable,
Gio::FILE_COPY_OVERWRITE);
}
void ImportDialog::on_resource_downloaded(const Glib::RefPtr<Gio::AsyncResult>& result,
Glib::RefPtr<Gio::File> file_remote, Glib::ustring path, ResourceType resource)
{
- bool success = file_remote->copy_finish(result);
+ bool success;
+
+ try {
+ success = file_remote->copy_finish(result);
+ } catch(Glib::Error) {
+ success = false;
+ }
if (resource == TYPE_IMAGE) {
on_image_downloaded(path, success);
@@ -783,8 +800,8 @@ void ImportDialog::on_image_downloaded(Glib::ustring path, bool success)
success = false;
}
- // If anything went wrong, show an error message
- if (!success) {
+ // If anything went wrong, show an error message if the user didn't do it
+ if (!success && !cancellable_image->is_cancelled()) {
widget_status->set_error(_("Could not download image"));
}
@@ -802,10 +819,12 @@ void ImportDialog::on_thumbnail_downloaded(Glib::ustring path, bool success)
success = false;
}
- // If anything went wrong, show an error message
- if (!success) {
+ // If anything went wrong, show an error message if the user didn't do it
+ if (!success && !cancellable_image->is_cancelled()) {
widget_status->set_error(_("Could not download thumbnail file"));
}
+
+ downloading_thumbnail = false;
}
/*
@@ -915,12 +934,17 @@ void ImportDialog::on_button_search_clicked()
on_entry_search_activated();
}
-
void ImportDialog::on_button_close_clicked()
{
hide();
}
+void ImportDialog::on_button_cancel_clicked()
+{
+ printf("On_button_cancel_clicked \n");
+ cancellable_image->cancel();
+}
+
/**
* Callback for user input into entry_search
*/
@@ -1059,6 +1083,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types
drawingarea_logo = new LogoArea();
notebook_content = new Gtk::Notebook();
widget_status = new StatusWidget();
+
+ downloading_thumbnail = false;
// Packing
add(*vbox);
@@ -1085,7 +1111,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types
// Properties
set_border_width(12);
- set_default_size(480, 320);
+ set_default_size(480, 330);
vbox->set_spacing(12);
hbuttonbox_bottom->set_spacing(6);
hbuttonbox_bottom->set_layout(Gtk::BUTTONBOX_END);
@@ -1120,6 +1146,8 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types
sigc::mem_fun(*this, &ImportDialog::on_button_import_clicked));
button_close->signal_clicked().connect(
sigc::mem_fun(*this, &ImportDialog::on_button_close_clicked));
+ button_cancel->signal_clicked().connect(
+ sigc::mem_fun(*this, &ImportDialog::on_button_cancel_clicked));
button_search->signal_clicked().connect(
sigc::mem_fun(*this, &ImportDialog::on_button_search_clicked));
list_results->signal_cursor_changed().connect(
@@ -1132,7 +1160,7 @@ ImportDialog::ImportDialog(Gtk::Window& parent_window, FileDialogType file_types
show_all_children();
entry_search->grab_focus();
- // Make sure the temporary directories needed later exist
+ // Create the temporary directories that will be needed later
create_temporary_dirs();
}
diff --git a/src/ui/dialog/ocaldialogs.h b/src/ui/dialog/ocaldialogs.h
index 27f699190..6e99605da 100644
--- a/src/ui/dialog/ocaldialogs.h
+++ b/src/ui/dialog/ocaldialogs.h
@@ -470,6 +470,10 @@ private:
Gtk::ScrolledWindow scrolledwindow_list;
Glib::RefPtr<Gtk::TreeSelection> selection;
+ Glib::RefPtr<Gio::Cancellable> cancellable_image;
+ Glib::RefPtr<Gio::Cancellable> cancellable_thumbnail;
+ bool downloading_thumbnail;
+
void update_label_no_search_results();
void update_preview(int row);
void on_list_results_cursor_changed();