diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2012-06-22 16:48:45 +0800 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2012-06-25 23:51:30 +0800 |
commit | fb062ec392862e2f14ca3b6466e200a31dee2737 (patch) | |
tree | 9901793c294d43c7062f2ebdd8666cf53ae17a45 /lib | |
parent | 5e3aa77ad8a6293f31f548366c87a7cd50c861fb (diff) | |
download | gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar.gz gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar.bz2 gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar.lz gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar.xz gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.tar.zst gsoc2013-epiphany-fb062ec392862e2f14ca3b6466e200a31dee2737.zip |
ephy-download-widget: add ephy_download_widget_download_finished()
It makes easier to check whether download finished, and it's compatible
with WebKit2.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/widgets/ephy-download-widget.c | 48 | ||||
-rw-r--r-- | lib/widgets/ephy-download-widget.h | 8 |
2 files changed, 33 insertions, 23 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 |