[epiphany/downloads: 9/9] ephy-download: add animations to UI
- From: Diego Escalante Urrelo <diegoe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/downloads: 9/9] ephy-download: add animations to UI
- Date: Fri, 21 Jan 2011 03:29:01 +0000 (UTC)
commit 8463f2bcd196ffc515cccc35f8ffe0330a8554dd
Author: Diego Escalante Urrelo <descalante igalia com>
Date: Thu Jan 20 14:59:48 2011 -0500
ephy-download: add animations to UI
embed/ephy-download.c | 208 +++++++++++++++++++++++++++----------------------
po/POTFILES.in | 3 +-
2 files changed, 115 insertions(+), 96 deletions(-)
---
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 0e3cff5..068fd99 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -29,9 +29,10 @@
#include "ephy-embed.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-type-builtins.h"
-#include "ephy-file-chooser.h"
#include "ephy-file-helpers.h"
#include "ephy-prefs.h"
+#include "ephy-settings.h"
+#include "totem-glow-button.h"
#include <errno.h>
#include <glib/gi18n.h>
@@ -61,6 +62,7 @@ struct _EphyDownloadPrivate
GtkWidget *widget;
};
+/* GObject boilerplate {{{*/
enum
{
PROP_0,
@@ -76,7 +78,6 @@ enum
PROP_EMBED
};
-/* GObject boilerplate {{{*/
static void
ephy_download_get_property (GObject *object,
guint property_id,
@@ -141,46 +142,10 @@ ephy_download_set_property (GObject *object,
ephy_download_set_embed (download, g_value_get_object (value));
break;
}
-}/*}}}*/
-
-/* Utility functions {{{*/
-static void
-do_download_action (EphyDownload *ephy_download,
- EphyDownloadActionType action)
-{
- GFile *destination;
- const char *destination_uri;
- EphyDownloadPrivate *priv;
-
- priv = ephy_download->priv;
-
- destination_uri = webkit_download_get_destination_uri (priv->download);
- destination = g_file_new_for_uri (destination_uri);
-
- switch ((action ? action : priv->action))
- {
- case EPHY_DOWNLOAD_ACTION_BROWSE_TO:
- {
- LOG ("download_status_changed_cb: browse_to");
- ephy_file_browse_to (destination, priv->start_time);
- break;
- }
- case EPHY_DOWNLOAD_ACTION_OPEN:
- {
- LOG ("download_status_changed_cb: open");
- ephy_file_launch_handler (NULL, destination, priv->start_time);
- break;
- }
- case EPHY_DOWNLOAD_ACTION_NONE:
- LOG ("download_status_changed_cb: nothing to do");
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- g_object_unref (destination);
}
+/*}}}*/
+/* Utility functions {{{*/
static GtkTreeIter
get_iter_for_download (EphyDownload *download)
{
@@ -195,6 +160,19 @@ get_iter_for_download (EphyDownload *download)
return iter;
}
+static void
+destroy_and_remove (EphyDownload *download)
+{
+ GtkTreeIter iter;
+
+ gtk_widget_destroy (download->priv->widget);
+
+ iter = get_iter_for_download (download);
+ gtk_list_store_remove (ephy_embed_shell_get_downloads (embed_shell), &iter);
+
+ g_object_unref (download);
+}
+
static GdkPixbuf *
get_icon_from_download (WebKitDownload *download)
{
@@ -277,6 +255,43 @@ decide_action_from_mime (EphyDownload *ephy_download)
return action;
}
+static void
+do_download_action (EphyDownload *ephy_download,
+ EphyDownloadActionType action)
+{
+ GFile *destination;
+ const char *destination_uri;
+ EphyDownloadPrivate *priv;
+
+ priv = ephy_download->priv;
+
+ destination_uri = webkit_download_get_destination_uri (priv->download);
+ destination = g_file_new_for_uri (destination_uri);
+
+ switch ((action ? action : priv->action))
+ {
+ case EPHY_DOWNLOAD_ACTION_BROWSE_TO:
+ {
+ LOG ("download_status_changed_cb: browse_to");
+ ephy_file_browse_to (destination, priv->start_time);
+ break;
+ }
+ case EPHY_DOWNLOAD_ACTION_OPEN:
+ {
+ LOG ("download_status_changed_cb: open");
+ ephy_file_launch_handler (NULL, destination, priv->start_time);
+ break;
+ }
+ case EPHY_DOWNLOAD_ACTION_NONE:
+ LOG ("download_status_changed_cb: nothing to do");
+ break;
+ default:
+ g_assert_not_reached ();
+ break;
+ }
+ g_object_unref (destination);
+}
+
/* From the old embed/mozilla/MozDownload.cpp */
static const char*
file_is_compressed (const char *filename)
@@ -399,7 +414,8 @@ define_destination_uri (EphyDownload *download)
g_assert (destination_uri);
return destination_uri;
-}/*}}}*/
+}
+/*}}}*/
/* Public API {{{*/
/* IMPORTANT: USE GOD DAMN FILE:// PREFIX */
@@ -417,7 +433,6 @@ ephy_download_set_destination_uri (EphyDownload *download, const char *destinati
g_free (scheme);
priv->destination = g_strdup (destination);
- LOG ("destination set: %s", destination);
webkit_download_set_destination_uri (priv->download, priv->destination);
g_object_notify (G_OBJECT (download), "destination");
@@ -703,6 +718,7 @@ ephy_download_init (EphyDownload *download)
}
/*}}}*/
+/* EphyDownload creation and watcher {{{*/
static void
download_status_changed_cb (GObject *object,
GParamSpec *pspec,
@@ -715,11 +731,15 @@ download_status_changed_cb (GObject *object,
status = webkit_download_get_status (priv->download);
- LOG ("status-changed %d", status);
-
if (status == WEBKIT_DOWNLOAD_STATUS_FINISHED) {
- do_download_action (download, EPHY_DOWNLOAD_ACTION_NONE);
g_signal_emit_by_name (download, "completed");
+
+ if (g_settings_get_boolean (EPHY_SETTINGS_MAIN, EPHY_PREFS_AUTO_DOWNLOADS)) {
+ do_download_action (download, decide_action_from_mime (download));
+ destroy_and_remove (download);
+ } else {
+ do_download_action (download, EPHY_DOWNLOAD_ACTION_NONE);
+ }
} else if (status == WEBKIT_DOWNLOAD_STATUS_CANCELLED ||
status == WEBKIT_DOWNLOAD_STATUS_ERROR) {
} else if (status == WEBKIT_DOWNLOAD_STATUS_STARTED) {
@@ -777,9 +797,9 @@ _ephy_download_new (WebKitDownload *download, const char *uri)
g_object_unref (request);
}
- g_signal_connect (webkit_download, "notify::status",
- G_CALLBACK (download_status_changed_cb),
- ephy_download);
+ g_signal_connect_after (webkit_download, "notify::status",
+ G_CALLBACK (download_status_changed_cb),
+ ephy_download);
g_signal_connect (webkit_download, "error",
G_CALLBACK (download_error_cb),
ephy_download);
@@ -801,20 +821,9 @@ ephy_download_new_for_uri (const char *uri)
{
return _ephy_download_new (NULL, uri);
}
+/*}}}*/
-static void
-destroy_and_remove (EphyDownload *download)
-{
- GtkTreeIter iter;
-
- gtk_widget_destroy (download->priv->widget);
-
- iter = get_iter_for_download (download);
- gtk_list_store_remove (ephy_embed_shell_get_downloads (embed_shell), &iter);
-
- g_object_unref (download);
-}
-
+/* Widget magic {{{*/
static void
download_clicked_cb (GtkButton *button,
EphyDownload *download)
@@ -827,7 +836,6 @@ download_clicked_cb (GtkButton *button,
return;
do_download_action (download, decide_action_from_mime (download));
-
destroy_and_remove (download);
}
@@ -859,12 +867,19 @@ download_menu_clicked_cb (GtkWidget *button,
gboolean finished;
GtkWidget *item;
GtkWidget *menu;
+ GtkWidget *box;
+ GList *children = NULL;
char *basename;
status = webkit_download_get_status (download->priv->download);
finished = (status == WEBKIT_DOWNLOAD_STATUS_FINISHED);
basename = g_filename_display_basename (download->priv->destination);
+ box = gtk_widget_get_parent (button);
+ children = gtk_container_get_children (GTK_CONTAINER (box));
+ totem_glow_button_set_glow (TOTEM_GLOW_BUTTON (children->data), FALSE);
+ g_list_free (children);
+
menu = gtk_menu_new ();
item = gtk_menu_item_new_with_label (basename);
@@ -914,17 +929,18 @@ format_interval (gdouble interval)
interval -= mins * 60;
secs = (int) interval;
- // FIXME: need ngettext, too lazy now.
- if (hours > 1) {
- if (mins > 1)
- return g_strdup_printf (_("%u:%02u hours left"), hours, mins);
+ LOG ("%u:%u:%u", hours, mins, secs);
+
+ if (hours > 0) {
+ if (mins > 0)
+ return g_strdup_printf (ngettext ("%u:%02u hour left", "%u:%02u hours left", hours), hours, mins);
else
- return g_strdup_printf (_("%u hours left"), hours);
+ return g_strdup_printf (ngettext ("%u hour left", "%u hours left", hours), hours);
} else {
- if (mins > 1)
- return g_strdup_printf (_("%02u minutes left"), mins);
+ if (mins > 0)
+ return g_strdup_printf (ngettext ("%u:%02u minute left", "%u:%02u minutes left", mins), mins, secs);
else
- return g_strdup_printf (_("%02u seconds left"), secs);
+ return g_strdup_printf (ngettext ("%u second left", "%u seconds left", secs), secs);
}
}
@@ -950,56 +966,61 @@ get_remaining_time (WebKitDownload *download)
}
static void
-progress_button_cb (GObject *object,
- GParamSpec *pspec,
- GtkWidget *widget)
+widget_status_cb (GObject *object,
+ GParamSpec *pspec,
+ GtkWidget *widget)
{
WebKitDownloadStatus status;
- gboolean finished;
status = webkit_download_get_status (WEBKIT_DOWNLOAD (object));
- finished = (status == WEBKIT_DOWNLOAD_STATUS_FINISHED);
-
- gtk_widget_set_sensitive (widget, finished);
- if (finished) {
- // animate
- }
+ if ((status == WEBKIT_DOWNLOAD_STATUS_FINISHED))
+ totem_glow_button_set_glow (TOTEM_GLOW_BUTTON (widget), TRUE);
}
static void
-progress_text_cb (GObject *object,
- GParamSpec *pspec,
- GtkWidget *widget)
+widget_progress_cb (GObject *object,
+ GParamSpec *pspec,
+ GtkWidget *widget)
{
WebKitDownload *download;
+ char *destination;
gdouble time;
char *remaining;
int progress;
char *remaining_label;
+ char *remaining_tooltip;
+ GtkWidget *box;
download = WEBKIT_DOWNLOAD (object);
+ destination = g_filename_display_basename (webkit_download_get_destination_uri (download));
+ progress = webkit_download_get_progress (download) * 100;
time = get_remaining_time (download);
+
if (time > 0)
remaining = format_interval (time);
else
remaining = g_strdup (_("Finished"));
- progress = webkit_download_get_progress (download) * 100;
-
remaining_label = g_strdup_printf ("%d%% (%s)", progress, remaining);
+ remaining_tooltip = g_strdup_printf ("%s\n%s", destination, remaining_label);
gtk_label_set_text (GTK_LABEL (widget), remaining_label);
+
+ box = gtk_widget_get_parent (gtk_widget_get_parent (widget));
+ gtk_widget_set_tooltip_text (box, remaining_tooltip);
+
+ g_free (destination);
g_free (remaining);
g_free (remaining_label);
+ g_free (remaining_tooltip);
}
GtkWidget *
ephy_download_get_widget (EphyDownload *download)
{
EphyDownloadPrivate *priv;
-
priv = download->priv;
if (priv->widget == NULL) {
@@ -1020,7 +1041,7 @@ ephy_download_get_widget (EphyDownload *download)
grid = gtk_grid_new ();
hbox = gtk_hbox_new (FALSE, 0);
- button = gtk_button_new ();
+ button = totem_glow_button_new ();
menu = gtk_button_new ();
icon = gtk_image_new_from_pixbuf (pixbuf);
@@ -1036,15 +1057,16 @@ ephy_download_get_widget (EphyDownload *download)
gtk_grid_attach (GTK_GRID (grid), text, 1, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), remain, 1, 1, 1, 1);
+ gtk_widget_set_tooltip_text (hbox, dest);
+
if (pixbuf)
g_object_unref (pixbuf);
-
g_free (dest);
g_signal_connect (priv->download, "notify::progress",
- G_CALLBACK (progress_text_cb), remain);
+ G_CALLBACK (widget_progress_cb), remain);
g_signal_connect (priv->download, "notify::status",
- G_CALLBACK (progress_button_cb), button);
+ G_CALLBACK (widget_status_cb), button);
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE);
gtk_button_set_relief (GTK_BUTTON (menu), GTK_RELIEF_NONE);
@@ -1064,13 +1086,11 @@ ephy_download_get_widget (EphyDownload *download)
gtk_widget_show_all (button);
gtk_widget_show_all (menu);
- priv->widget = hbox;
-
- g_object_add_weak_pointer (G_OBJECT (priv->widget),
- (gpointer *) &priv->widget);
+ priv->widget = g_object_ref (hbox);
g_object_set_data (G_OBJECT (priv->widget), "download", download);
}
return priv->widget;
}
+/*}}}*/
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4e297e6..300c809 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -10,9 +10,8 @@ data/org.gnome.epiphany.gschema.xml.in
[type: gettext/glade] data/glade/form-signing-dialog.ui
[type: gettext/glade] data/glade/prefs-dialog.ui
[type: gettext/glade] data/glade/print.ui
-embed/downloader-view.c
+embed/ephy-download.c
embed/ephy-embed.c
-embed/ephy-embed-persist.c
embed/ephy-embed-shell.c
embed/ephy-embed-single.c
embed/ephy-embed-utils.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]