From 6a0b87d4f56a1d09b1699738a1f58fd06fb65a51 Mon Sep 17 00:00:00 2001 From: Daniel Carl Date: Thu, 6 Mar 2014 00:47:02 +0100 Subject: [PATCH] Added wget style progressbar. --- src/config.def.h | 8 ++++++++ src/main.c | 26 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/config.def.h b/src/config.def.h index 3986b24..3540f62 100644 --- a/src/config.def.h +++ b/src/config.def.h @@ -36,6 +36,8 @@ #define FEATURE_TITLE_PROGRESS /* should the history indicator [+-] be shown in status bar after url */ #define FEATURE_HISTORY_INDICATOR +/* show wget style progressbar in status bar */ +#define FEATURE_WGET_PROGRESS_BAR /* time in seconds after that message will be removed from inputbox if the @@ -53,6 +55,12 @@ #define WIN_WIDTH 800 #define WIN_HEIGHT 600 +#ifdef FEATURE_WGET_PROGRESS_BAR +/* chars to use for the progressbar */ +#define PROGRESS_BAR "=> " +#define PROGRESS_BAR_LEN 20 +#endif + /* template to run shell command for vimb command :shellcmd */ #define SHELL_CMD "/bin/sh -c '%s'" diff --git a/src/main.c b/src/main.c index 8532898..56bf382 100644 --- a/src/main.c +++ b/src/main.c @@ -70,6 +70,9 @@ static gboolean mimetype_decision_cb(WebKitWebView *webview, static void download_progress_cp(WebKitDownload *download, GParamSpec *pspec); /* functions */ +#ifdef FEATURE_WGET_PROGRESS_BAR +static void wget_bar(int len, int progress, char *string); +#endif static void update_title(void); static void init_core(void); static void marks_clear(void); @@ -238,6 +241,23 @@ void vb_set_widget_font(GtkWidget *widget, const VbColor *fg, const VbColor *bg, VB_WIDGET_OVERRIDE_BACKGROUND(widget, VB_GTK_STATE_NORMAL, bg); } +#ifdef FEATURE_WGET_PROGRESS_BAR +static void wget_bar(int len, int progress, char *string) +{ + int i, state; + + state = progress * len / 100; + for (i = 0; i < state; i++) { + string[i] = PROGRESS_BAR[0]; + } + string[i++] = PROGRESS_BAR[1]; + for (; i < len; i++) { + string[i] = PROGRESS_BAR[2]; + } + string[i] = '\0'; +} +#endif + void vb_update_statusbar() { int max, val, num; @@ -251,7 +271,13 @@ void vb_update_statusbar() /* show load status of page or the downloads */ if (vb.state.progress != 100) { +#ifdef FEATURE_WGET_PROGRESS_BAR + char bar[PROGRESS_BAR_LEN + 1]; + wget_bar(PROGRESS_BAR_LEN, vb.state.progress, bar); + g_string_append_printf(status, " [%s]", bar); +#else g_string_append_printf(status, " [%i%%]", vb.state.progress); +#endif } /* show the scroll status */ -- 2.20.1