Git-Url:
http://git.frugalware.org/gitweb/gitweb.cgi?p=gfpm/.git;a=commitdiff;h=48af41f8c64c124aa5438e521739a824450049a1
commit 48af41f8c64c124aa5438e521739a824450049a1
Author: Priyank <[EMAIL PROTECTED]>
Date: Tue Jul 31 23:53:18 2007 +0530
gfpm-progress: progressbar now also displays the transfer rate while
downloading packages or syncing repos.
diff --git a/glade/gfpm.glade b/glade/gfpm.glade
index fb7b97c..7e15c97 100644
--- a/glade/gfpm.glade
+++ b/glade/gfpm.glade
@@ -565,51 +565,33 @@ Installed packages</property>
</packing>
</child>
<child>
- <widget class="GtkHButtonBox" id="hbuttonbox1">
+ <widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
- <property name="layout_style">GTK_BUTTONBOX_END</property>
+ <property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
<child>
- <widget class="GtkButton" id="button1">
+ <widget class="GtkLabel" id="label8">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="response_id">0</property>
- <child>
- <widget class="GtkAlignment" id="alignment4">
- <property name="visible">True</property>
- <property name="xscale">0</property>
- <property name="yscale">0</property>
- <child>
- <widget class="GtkHBox" id="hbox2">
- <property name="visible">True</property>
- <property name="spacing">2</property>
- <child>
- <widget class="GtkImage" id="image8">
- <property name="visible">True</property>
- <property name="stock">gtk-cancel</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- </packing>
- </child>
- <child>
- <widget class="GtkLabel" id="label8">
- <property name="visible">True</property>
- <property name="label"
translatable="yes">Cancel</property>
- <property name="use_underline">True</property>
- </widget>
- <packing>
- <property name="expand">False</property>
- <property name="fill">False</property>
- <property name="position">1</property>
- </packing>
- </child>
- </widget>
- </child>
- </widget>
- </child>
+ <property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Transfer Rate:
</property>
</widget>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkLabel" id="rate_pr_label">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK</property>
+ <property name="xalign">0</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <placeholder/>
</child>
</widget>
<packing>
diff --git a/src/gfpm-progress.c b/src/gfpm-progress.c
index 99c8bf3..21d6251 100644
--- a/src/gfpm-progress.c
+++ b/src/gfpm-progress.c
@@ -2,6 +2,7 @@
* gfpm-progress.c for gfpm
*
* Copyright (C) 2006-2007 by Priyank Gosalia <[EMAIL PROTECTED]>
+ * Portions of this code Copyright (C) 2002-2006 Judd Vinet <[EMAIL
PROTECTED]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,6 +20,8 @@
*/
#define _GNU_SOURCE
+#include <time.h>
+#include <sys/time.h>
#include <glade/glade.h>
#include "gfpm.h"
#include "gfpm-progress.h"
@@ -33,10 +36,13 @@ GtkProgressBar *progressbar = NULL;
GtkWidget *progresswindow = NULL;
GtkWidget *main_label = NULL;
GtkWidget *sub_label = NULL;
+GtkWidget *rate_label = NULL;
-float rate;
-int offset;
-char reponame[PM_DLFNM_LEN+1];
+float rate;
+int offset;
+int xferred1;
+struct timeval t0, t;
+char reponame[PM_DLFNM_LEN+1];
void
gfpm_progress_init (void)
@@ -51,6 +57,7 @@ gfpm_progress_init (void)
progresswindow = glade_xml_get_widget (xml, "progresswindow");
main_label = glade_xml_get_widget (xml, "main_pr_label");
sub_label = glade_xml_get_widget (xml, "sub_pr_label");
+ rate_label = glade_xml_get_widget (xml, "rate_pr_label");
return;
}
@@ -69,17 +76,43 @@ gfpm_progress_show (gboolean show)
int
gfpm_progress_update (netbuf *ctl, int xferred, void *arg)
{
- int size;
- int per;
- char text[6];
+ int size;
+ int per;
+ char text[6];
+ char rate_text[10];
+ struct timeval t1;
+ float tdiff;
ctl = NULL;
size = *(int*)arg;
per = ((float)(xferred+offset) / size) * 100;
sprintf (text, "%d %%", per);
+ gettimeofday (&t1, NULL);
+ if (xferred+offset == size)
+ t = t0;
+ tdiff = t1.tv_sec-t.tv_sec + (float)(t1.tv_usec-t.tv_usec) / 1000000;
+ if (xferred+offset == size)
+ {
+ rate = xferred / (tdiff * 1024);
+ }
+ else if (tdiff > 1)
+ {
+ rate = (xferred - xferred1) / (tdiff * 1024);
+ xferred1 = xferred;
+ gettimeofday (&t, NULL);
+ }
+ if (rate > 1000)
+ {
+ sprintf (rate_text, "%6.0fK/s", rate);
+ }
+ else
+ {
+ sprintf (rate_text, "%6.1fK/s", rate);
+ }
while (gtk_events_pending ())
gtk_main_iteration ();
gtk_progress_bar_set_text (progressbar, text);
+ gtk_label_set_text (GTK_LABEL(rate_label), rate_text);
gtk_progress_bar_set_fraction (progressbar, (float)per/100);
gfpm_progress_set_sub_text (reponame);
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git