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



commit f776e493900371e114a5768acfd13d89ce71cc19
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 |   62 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 59 insertions(+), 3 deletions(-)
---
diff --git a/src/ephy-window.c b/src/ephy-window.c
index bc6c68a..1cd986d 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);
 
@@ -2980,8 +3034,10 @@ notebook_page_close_request_cb (EphyNotebook *notebook,
 		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)) &&
+	    (!window_has_ongoing_downloads (window) ||
+	     confirm_close_with_downloads (window)))
 	{
 		gtk_widget_destroy (GTK_WIDGET (embed));
 	}



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