aboutsummaryrefslogtreecommitdiffstats
path: root/embed/ephy-download.c
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2003-10-19 17:53:50 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-10-19 17:53:50 +0800
commitffba6a5ae788b7c8ad83809a944907caa7a8fe84 (patch)
treedb6f0f070124b950f7ed6109b2ff0ba477e6eafd /embed/ephy-download.c
parent80f66913e794ce851a9e38145fd2f0cf0ca7dd31 (diff)
downloadgsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar
gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.gz
gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.bz2
gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.lz
gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.xz
gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.tar.zst
gsoc2013-epiphany-ffba6a5ae788b7c8ad83809a944907caa7a8fe84.zip
Update remaning time every two seconds
2003-10-19 Marco Pesenti Gritti <marco@gnome.org> * TODO: * embed/ephy-download.c: (ephy_download_class_init), (ephy_download_init), (update_remaining_time), (ephy_download_get_remaining_time): * embed/ephy-download.h: Update remaning time every two seconds * embed/mozilla/mozilla-download.cpp: Source/target was swapped * embed/mozilla/EphyHeaderSniffer.cpp: * embed/mozilla/EphyHeaderSniffer.h: Fix style
Diffstat (limited to 'embed/ephy-download.c')
-rw-r--r--embed/ephy-download.c45
1 files changed, 38 insertions, 7 deletions
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 0e72f9d90..f7e09d94f 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -26,6 +26,10 @@
#include <libgnomevfs/gnome-vfs-uri.h>
+#define EPHY_DOWNLOAD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_DOWNLOAD, EphyDownloadPrivate))
+
+#define REMAINING_TIME_UPDATE_SECS 2
+
static void
ephy_download_class_init (EphyDownloadClass *klass);
static void
@@ -37,6 +41,12 @@ enum
LAST_SIGNAL
};
+struct EphyDownloadPrivate
+{
+ long remaining_time_last_update;
+ long remaining_time;
+};
+
static GObjectClass *parent_class = NULL;
static guint ephy_download_signals[LAST_SIGNAL] = { 0 };
@@ -72,6 +82,8 @@ ephy_download_get_type (void)
static void
ephy_download_class_init (EphyDownloadClass *klass)
{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
parent_class = g_type_class_peek_parent (klass);
ephy_download_signals[CHANGED] =
@@ -83,11 +95,17 @@ ephy_download_class_init (EphyDownloadClass *klass)
g_cclosure_marshal_VOID__VOID,
G_TYPE_NONE,
0);
+
+ g_type_class_add_private (object_class, sizeof(EphyDownloadPrivate));
}
static void
-ephy_download_init (EphyDownload *dv)
+ephy_download_init (EphyDownload *download)
{
+ download->priv = EPHY_DOWNLOAD_GET_PRIVATE (download);
+
+ download->priv->remaining_time = 0;
+ download->priv->remaining_time_last_update = 0;
}
EphyDownload *
@@ -119,11 +137,10 @@ ephy_download_get_name (EphyDownload *download)
return result;
}
-long
-ephy_download_get_remaining_time (EphyDownload *download)
+static void
+update_remaining_time (EphyDownload *download)
{
- long elapsed_time, remaining_time = 0;
- long total, cur;
+ long elapsed_time, total, cur;
total = ephy_download_get_total_progress (download);
cur = ephy_download_get_current_progress (download);
@@ -131,10 +148,24 @@ ephy_download_get_remaining_time (EphyDownload *download)
if (cur > 0)
{
- remaining_time = elapsed_time * (total - cur) / cur;
+ download->priv->remaining_time = elapsed_time * (total - cur) / cur;
+ }
+}
+
+long
+ephy_download_get_remaining_time (EphyDownload *download)
+{
+ long elapsed_time;
+
+ elapsed_time = ephy_download_get_elapsed_time (download);
+ if (elapsed_time - download->priv->remaining_time_last_update >=
+ REMAINING_TIME_UPDATE_SECS)
+ {
+ update_remaining_time (download);
+ download->priv->remaining_time_last_update = elapsed_time;
}
- return remaining_time;
+ return download->priv->remaining_time;
}
char *