[epiphany] Handle moved or deleted download files
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany] Handle moved or deleted download files
- Date: Sat, 4 May 2019 14:30:12 +0000 (UTC)
commit 127b007baa72a67d43ce37309e63d6cba96aa55e
Author: Jan-Michael Brummer <jan brummer tabos org>
Date: Sat May 4 15:19:45 2019 +0200
Handle moved or deleted download files
Show a status message to inform the user that the download file has been moved or deleted and
disable open file button.
Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/155
embed/ephy-download.c | 37 +++++++++++++++++++++++++++++++++++++
lib/widgets/ephy-download-widget.c | 11 +++++++++++
2 files changed, 48 insertions(+)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 941cdcd44..72cffb0e1 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -50,6 +50,7 @@ struct _EphyDownload {
guint32 start_time;
gboolean finished;
GError *error;
+ GFileMonitor *file_monitor;
};
G_DEFINE_TYPE (EphyDownload, ephy_download, G_TYPE_OBJECT)
@@ -70,6 +71,7 @@ enum {
FILENAME_SUGGESTED,
ERROR,
COMPLETED,
+ MOVED,
LAST_SIGNAL
};
@@ -477,6 +479,7 @@ ephy_download_dispose (GObject *object)
download->download = NULL;
}
+ g_clear_object (&download->file_monitor);
g_clear_error (&download->error);
g_clear_pointer (&download->content_type, g_free);
@@ -584,6 +587,19 @@ ephy_download_class_init (EphyDownloadClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE,
0);
+
+ /**
+ * EphyDownload::moved:
+ *
+ * The ::moved signal is emitted when a finished @download has been moved (or deleted).
+ **/
+ signals[MOVED] = g_signal_new ("moved",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL, NULL,
+ G_TYPE_NONE,
+ 0);
/**
* EphyDownload::error:
*
@@ -720,10 +736,24 @@ display_download_finished_notification (WebKitDownload *download)
}
}
+static void
+download_file_monitor_changed (GFileMonitor *monitor,
+ GFile *file,
+ GFile *other_file,
+ GFileMonitorEvent event_type,
+ EphyDownload *download)
+{
+ if (event_type == G_FILE_MONITOR_EVENT_DELETED || event_type == G_FILE_MONITOR_EVENT_MOVED)
+ g_signal_emit (download, signals[MOVED], 0);
+}
+
static void
download_finished_cb (WebKitDownload *wk_download,
EphyDownload *download)
{
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GFile) file = NULL;
+
download->finished = TRUE;
ephy_download_do_download_action (download, download->action, download->start_time);
@@ -732,6 +762,13 @@ download_finished_cb (WebKitDownload *wk_download,
display_download_finished_notification (wk_download);
g_signal_emit (download, signals[COMPLETED], 0);
+
+ file = g_file_new_for_uri (webkit_download_get_destination (wk_download));
+ download->file_monitor = g_file_monitor (file, G_FILE_MONITOR_NONE, NULL, &error);
+ if (!download->file_monitor)
+ g_warning ("Could not add a file monitor for %s, error: %s\n", g_file_get_uri (file), error->message);
+ else
+ g_signal_connect (download->file_monitor, "changed", G_CALLBACK (download_file_monitor_changed),
download);
}
static void
diff --git a/lib/widgets/ephy-download-widget.c b/lib/widgets/ephy-download-widget.c
index 94a55d3fb..3bf611088 100644
--- a/lib/widgets/ephy-download-widget.c
+++ b/lib/widgets/ephy-download-widget.c
@@ -217,6 +217,14 @@ download_finished_cb (EphyDownload *download,
GTK_ICON_SIZE_MENU);
}
+static void
+download_moved_cb (EphyDownload *download,
+ EphyDownloadWidget *widget)
+{
+ update_status_label (widget, _("Moved or deleted"));
+ gtk_widget_set_sensitive (widget->action_button, FALSE);
+}
+
static void
download_failed_cb (EphyDownload *download,
GError *error,
@@ -430,6 +438,9 @@ ephy_download_widget_constructed (GObject *object)
g_signal_connect (widget->download, "error",
G_CALLBACK (download_failed_cb),
widget);
+ g_signal_connect (widget->download, "moved",
+ G_CALLBACK (download_moved_cb),
+ widget);
g_signal_connect (widget->download, "notify::content-type",
G_CALLBACK (download_content_type_changed_cb),
widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]