[epiphany/downloads: 10/12] e-window: confirm close with downloads



commit d7d3d393464d20942ace025edc3f70927fbd70b0
Author: Diego Escalante Urrelo <descalante igalia com>
Date:   Thu Jan 27 13:49:20 2011 -0500

    e-window: confirm close with downloads

 src/ephy-window.c |   75 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 68 insertions(+), 7 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 9a11af1..4b54cbe 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -574,6 +574,23 @@ confirm_close_with_modified_forms (EphyWindow *window)
 	return TRUE;
 }
 
+static gboolean
+confirm_close_with_downloads (EphyWindow *window)
+{
+	GtkWidget *dialog;
+	int response;
+
+	dialog = construct_confirm_close_dialog (window,
+			_("There are ongoing downloads in this window"),
+			_("If you close this window, the downloads will be cancelled"),
+			_("Close window and cancel downloads"));
+	response = gtk_dialog_run (GTK_DIALOG (dialog));
+
+	gtk_widget_destroy (dialog);
+
+	return response == GTK_RESPONSE_ACCEPT;
+}
+
 static void
 impl_remove_child (EphyEmbedContainer *container,
 		   EphyEmbed *child)
@@ -1013,6 +1030,36 @@ ephy_window_key_press_event (GtkWidget *widget,
 }
 
 static gboolean
+window_has_ongoing_downloads (EphyWindow *window)
+{
+	GList *l, *downloads;
+	gboolean downloading = FALSE;
+
+	downloads = gtk_container_get_children (GTK_CONTAINER (window->priv->downloads_box));
+
+	for (l = downloads; l != NULL; l = l->next)
+	{
+		EphyDownload *download;
+		WebKitDownloadStatus status;
+
+		if (EPHY_IS_DOWNLOAD_WIDGET (l->data) != TRUE)
+			continue;
+
+		download = ephy_download_widget_get_download (EPHY_DOWNLOAD_WIDGET (l->data));
+		status = webkit_download_get_status (ephy_download_get_webkit_download (download));
+
+		if (status == WEBKIT_DOWNLOAD_STATUS_STARTED)
+		{
+			downloading = TRUE;
+			break;
+		}
+	}
+	g_list_free (downloads);
+
+	return downloading;
+}
+
+static gboolean
 ephy_window_delete_event (GtkWidget *widget,
 			  GdkEventAny *event)
 {
@@ -1054,7 +1101,14 @@ ephy_window_delete_event (GtkWidget *widget,
 			return TRUE;
 		}
 	}
-	
+
+
+	if (window_has_ongoing_downloads (window) && confirm_close_with_downloads (window) == FALSE)
+	{
+		/* stop window close */
+		return TRUE;
+	}
+
 	/* See bug #114689 */
 	gtk_widget_hide (widget);
 
@@ -2973,15 +3027,22 @@ notebook_page_close_request_cb (EphyNotebook *notebook,
 {
 	EphyWindowPrivate *priv = window->priv;
 
-	if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
-				    EPHY_PREFS_LOCKDOWN_QUIT) &&
-	    gtk_notebook_get_n_pages (priv->notebook) == 1)
+	if (gtk_notebook_get_n_pages (priv->notebook) == 1)
 	{
-		return;
+		if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
+					    EPHY_PREFS_LOCKDOWN_QUIT))
+		{
+			return;
+		}
+		if (window_has_ongoing_downloads (window) &&
+		    !confirm_close_with_downloads (window))
+		{
+			return;
+		}
 	}
 
-	if (!ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed)) ||
-	    confirm_close_with_modified_forms (window))
+	if ((!ephy_web_view_has_modified_forms (ephy_embed_get_web_view (embed)) ||
+	     confirm_close_with_modified_forms (window)))
 	{
 		gtk_widget_destroy (GTK_WIDGET (embed));
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]