summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2012-06-22 10:48:45 +0200
committerCarlos Garcia Campos <carlosgc@gnome.org>2012-06-25 17:51:30 +0200
commitfb062ec392862e2f14ca3b6466e200a31dee2737 (patch)
tree9901793c294d43c7062f2ebdd8666cf53ae17a45
parent5e3aa77ad8a6293f31f548366c87a7cd50c861fb (diff)
downloadepiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar.gz
ephy-download-widget: add ephy_download_widget_download_finished()
It makes easier to check whether download finished, and it's compatible with WebKit2.
-rw-r--r--lib/widgets/ephy-download-widget.c48
-rw-r--r--lib/widgets/ephy-download-widget.h8
-rw-r--r--src/ephy-window.c24
3 files changed, 35 insertions, 45 deletions
diff --git a/lib/widgets/ephy-download-widget.c b/lib/widgets/ephy-download-widget.c
index 936c93083..09000bd58 100644
--- a/lib/widgets/ephy-download-widget.c
+++ b/lib/widgets/ephy-download-widget.c
@@ -50,6 +50,8 @@ struct _EphyDownloadWidgetPrivate
GtkWidget *button;
GtkWidget *menu;
GtkWidget *icon;
+
+ gboolean finished;
};
enum
@@ -130,21 +132,14 @@ static void
download_clicked_cb (GtkButton *button,
EphyDownloadWidget *widget)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Downloads */
-#else
- WebKitDownloadStatus status;
EphyDownload *download;
- download = widget->priv->download;
- status = webkit_download_get_status (ephy_download_get_webkit_download (download));
-
- if (status != WEBKIT_DOWNLOAD_STATUS_FINISHED)
+ if (!widget->priv->finished)
return;
+ download = widget->priv->download;
if (ephy_download_do_download_action (download, EPHY_DOWNLOAD_ACTION_AUTO))
gtk_widget_destroy (GTK_WIDGET (widget));
-#endif
}
#ifdef HAVE_WEBKIT2
@@ -244,10 +239,12 @@ widget_status_cb (GObject *object,
status = webkit_download_get_status (WEBKIT_DOWNLOAD (object));
- if (status == WEBKIT_DOWNLOAD_STATUS_FINISHED) {
- update_download_label_and_tooltip (widget, _("Finished"));
- totem_glow_button_set_glow (TOTEM_GLOW_BUTTON (widget->priv->button), TRUE);
- }
+ if (status != WEBKIT_DOWNLOAD_STATUS_FINISHED)
+ return;
+
+ widget->priv->finished = TRUE;
+ update_download_label_and_tooltip (widget, _("Finished"));
+ totem_glow_button_set_glow (TOTEM_GLOW_BUTTON (widget->priv->button), TRUE);
}
static gboolean
@@ -304,8 +301,6 @@ download_menu_clicked_cb (GtkWidget *button,
#ifdef HAVE_WEBKIT2
/* TODO: Downloads */
#else
- WebKitDownloadStatus status;
- gboolean finished;
GtkWidget *item;
GtkWidget *menu;
GtkWidget *box;
@@ -316,8 +311,6 @@ download_menu_clicked_cb (GtkWidget *button,
download = ephy_download_get_webkit_download (widget->priv->download);
- status = webkit_download_get_status (download);
- finished = (status == WEBKIT_DOWNLOAD_STATUS_FINISHED);
basename = g_filename_display_basename (webkit_download_get_destination_uri (download));
name = g_uri_unescape_string (basename, NULL);
@@ -336,7 +329,7 @@ download_menu_clicked_cb (GtkWidget *button,
item = gtk_menu_item_new_with_label (_("Cancel"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_set_sensitive (item, !finished);
+ gtk_widget_set_sensitive (item, !widget->priv->finished);
g_signal_connect (item, "activate",
G_CALLBACK (cancel_activate_cb), widget);
@@ -345,13 +338,13 @@ download_menu_clicked_cb (GtkWidget *button,
item = gtk_menu_item_new_with_label (_("Open"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_set_sensitive (item, finished);
+ gtk_widget_set_sensitive (item, widget->priv->finished);
g_signal_connect (item, "activate",
G_CALLBACK (open_activate_cb), widget);
item = gtk_menu_item_new_with_label (_("Show in folder"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_set_sensitive (item, finished);
+ gtk_widget_set_sensitive (item, widget->priv->finished);
g_signal_connect (item, "activate",
G_CALLBACK (folder_activate_cb), widget);
@@ -487,6 +480,21 @@ ephy_download_widget_get_download (EphyDownloadWidget *widget)
}
/**
+ * ephy_download_widget_download_is_finished:
+ * @widget: an #EphyDownloadWidget
+ *
+ * Whether the download finished
+ *
+ * Returns: %TRUE if download operation finished or %FALSE otherwise
+ **/
+gboolean
+ephy_download_widget_download_is_finished (EphyDownloadWidget *widget)
+{
+ g_return_val_if_fail (EPHY_IS_DOWNLOAD_WIDGET (widget), FALSE);
+ return widget->priv->finished;
+}
+
+/**
* ephy_download_widget_new:
* @ephy_download: the #EphyDownload that @widget is wrapping
*
diff --git a/lib/widgets/ephy-download-widget.h b/lib/widgets/ephy-download-widget.h
index b767e5e32..cbdab20fb 100644
--- a/lib/widgets/ephy-download-widget.h
+++ b/lib/widgets/ephy-download-widget.h
@@ -57,11 +57,13 @@ struct _EphyDownloadWidgetClass
GtkBoxClass parent_class;
};
-GType ephy_download_widget_get_type (void) G_GNUC_CONST;
+GType ephy_download_widget_get_type (void) G_GNUC_CONST;
-GtkWidget *ephy_download_widget_new (EphyDownload *ephy_download);
+GtkWidget *ephy_download_widget_new (EphyDownload *ephy_download);
-EphyDownload *ephy_download_widget_get_download (EphyDownloadWidget *widget);
+EphyDownload *ephy_download_widget_get_download (EphyDownloadWidget *widget);
+
+gboolean ephy_download_widget_download_is_finished (EphyDownloadWidget *widget);
G_END_DECLS
diff --git a/src/ephy-window.c b/src/ephy-window.c
index 8ebaa7e07..e5e9c04ce 100644
--- a/src/ephy-window.c
+++ b/src/ephy-window.c
@@ -948,24 +948,14 @@ window_has_ongoing_downloads (EphyWindow *window)
for (l = downloads; l != NULL; l = l->next)
{
-#ifdef HAVE_WEBKIT2
- /* TODO: Downloads */
-#else
- 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)
+ if (!ephy_download_widget_download_is_finished (EPHY_DOWNLOAD_WIDGET (l->data)))
{
downloading = TRUE;
break;
}
-#endif
}
g_list_free (downloads);
@@ -3156,23 +3146,13 @@ downloads_close_cb (GtkButton *button, EphyWindow *window)
for (l = downloads; l != NULL; l = l->next)
{
- EphyDownload *download;
-#ifdef HAVE_WEBKIT2
- /* TODO: Downloads */
-#else
- 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_FINISHED)
+ if (ephy_download_widget_download_is_finished (EPHY_DOWNLOAD_WIDGET (l->data)))
{
gtk_widget_destroy (GTK_WIDGET (l->data));
}
-#endif
}
g_list_free (downloads);