summaryrefslogtreecommitdiff
path: root/browser.c
diff options
context:
space:
mode:
authorPeter Hofmann <scm@uninformativ.de>2014-06-19 06:31:34 +0200
committerPeter Hofmann <scm@uninformativ.de>2014-06-19 06:31:34 +0200
commit88b23648663d398d57766c583fb1911636717ce5 (patch)
treebe8bc95122e0d7a80837380879a96f93fc0e2f35 /browser.c
parente46fff5a98d2be9c15ea70aad16035227d0eba35 (diff)
downloadlariza-88b23648663d398d57766c583fb1911636717ce5.tar.gz
An indicator that shows when a download has started
Diffstat (limited to 'browser.c')
-rw-r--r--browser.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/browser.c b/browser.c
index 814a2fe..b64d7e0 100644
--- a/browser.c
+++ b/browser.c
@@ -26,6 +26,7 @@ static void changed_load_progress(GObject *obj, GParamSpec *pspec,
static void changed_title(GObject *, GParamSpec *, gpointer);
static void changed_uri(GObject *, GParamSpec *, gpointer);
static gboolean download_handle(WebKitWebView *, WebKitDownload *, gpointer);
+static gboolean download_reset_indicator(gpointer);
static gboolean download_request(WebKitWebView *, WebKitWebFrame *,
WebKitNetworkRequest *, gchar *,
WebKitWebPolicyDecision *, gpointer);
@@ -46,6 +47,7 @@ struct Client
GtkWidget *location;
GtkWidget *progress;
GtkWidget *scroll;
+ GtkWidget *status;
GtkWidget *top_box;
GtkWidget *vbox;
GtkWidget *web_view;
@@ -60,6 +62,7 @@ static gboolean cooperative_alone = TRUE;
static gboolean cooperative_instances = TRUE;
static int cooperative_pipe_fp = 0;
static gchar *download_dir = "/tmp";
+static gint downloads_indicated = 0;
static Window embed = 0;
static gchar *first_uri = NULL;
static gdouble global_zoom = 1.0;
@@ -233,7 +236,7 @@ client_new(const gchar *uri)
"mime-type-policy-decision-requested",
G_CALLBACK(download_request), NULL);
g_signal_connect(G_OBJECT(c->web_view), "download-requested",
- G_CALLBACK(download_handle), NULL);
+ G_CALLBACK(download_handle), c);
g_signal_connect(G_OBJECT(c->web_view), "key-press-event",
G_CALLBACK(key_web_view), c);
g_signal_connect(G_OBJECT(c->web_view), "button-press-event",
@@ -261,7 +264,12 @@ client_new(const gchar *uri)
c->progress = gtk_progress_bar_new();
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->progress), 0);
+ c->status = gtk_progress_bar_new();
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
+ gtk_widget_set_size_request(c->status, 20, -1);
+
c->top_box = gtk_hbox_new(FALSE, 2);
+ gtk_box_pack_start(GTK_BOX(c->top_box), c->status, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(c->top_box), c->location, TRUE, TRUE, 0);
gtk_box_pack_end(GTK_BOX(c->top_box), c->progress, FALSE, TRUE, 0);
@@ -373,6 +381,7 @@ changed_uri(GObject *obj, GParamSpec *pspec, gpointer data)
gboolean
download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data)
{
+ struct Client *c = (struct Client *)data;
gchar *path, *path2 = NULL, *uri;
gboolean ret;
int suffix = 1;
@@ -403,6 +412,10 @@ download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data
webkit_download_set_destination_uri(download, uri);
ret = TRUE;
g_free(uri);
+
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 1);
+ downloads_indicated++;
+ g_timeout_add(500, download_reset_indicator, c);
}
g_free(path);
@@ -412,6 +425,18 @@ download_handle(WebKitWebView *web_view, WebKitDownload *download, gpointer data
}
gboolean
+download_reset_indicator(gpointer data)
+{
+ struct Client *c = (struct Client *)data;
+
+ downloads_indicated--;
+ if (downloads_indicated == 0)
+ gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(c->status), 0);
+
+ return FALSE;
+}
+
+gboolean
download_request(WebKitWebView *web_view, WebKitWebFrame *frame,
WebKitNetworkRequest *request, gchar *mime_type,
WebKitWebPolicyDecision *policy_decision, gpointer data)