Added wget style progressbar.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 5 Mar 2014 23:47:02 +0000 (00:47 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 5 Mar 2014 23:47:02 +0000 (00:47 +0100)
src/config.def.h
src/main.c

index 3986b24..3540f62 100644 (file)
@@ -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
 #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'"
 
index 8532898..56bf382 100644 (file)
@@ -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 */