This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix download dialog meters


Hi,

I've been sitting on this for a while. It's about darn time I check it
in.

See http://sources.redhat.com/ml/insight/2004-q4/msg00083.html

Keith

Changelog:
2004-12-08  Keith Seitz  <kseitz@sources.redhat.com>
 
        * library/download.ith (completed_steps): New variable.
        * library/download.itb (Download::constructor): Remove
        "-fraction" option from iwidgets feedback widget. It's not a
valid
        option!
        (update_download): Compute the step number and use that to
        update the feedback widget.
        (done): Use completed_steps to figure out how many steps
        the dumb feedback meter needs to show full.

Index: download.itb
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.itb,v
retrieving revision 1.9
diff -u -p -r1.9 download.itb
--- download.itb	15 Oct 2002 21:19:51 -0000	1.9
+++ download.itb	8 Dec 2004 22:25:02 -0000
@@ -31,7 +31,7 @@ itcl::body Download::constructor {args} 
 
   set i 0
   while {$i <$num_sections} {
-    iwidgets::feedback $f.meter$i -steps $num_steps -fraction 0.0
+    iwidgets::feedback $f.meter$i -steps $num_steps
     grid forget [$f.meter$i component percentage]
     label $f.sec$i -text [lindex $section(names) $i] -anchor w
     label $f.num$i -text $bytes($i) -anchor e
@@ -63,11 +63,26 @@ itcl::body Download::update_download { s
     set i $section($s)
 
     if {$s == $sec} {
-      set f [expr {$num / $bytes($i)}]
-      $itk_interior.f.meter$i configure -fraction $f
+      # Advance feedback meter. The iwidgets meter leaves a lot to
+      # be desired. No way to query the current setting. No way to
+      # set the state of the meter by percentage. It only understands
+      # steps, and we must be careful not to step the widget past the
+      # the configured number of steps, or else the meter will be
+      # set wrong. How lame.
+      set steps [expr {$num / $bytes($i) * $num_steps}]
+      if {[expr {$completed_steps($s) + $steps}] > $num_steps} {
+	set steps [expr {$num_steps - $completed_steps($s)}]
+      }
+      incr completed_steps($s) $steps
+      $itk_interior.f.meter$i step $steps
       break
     } else {
-      $itk_interior.f.meter$i configure -fraction 1.0
+      # Section already loaded. Make sure meter is at 100%.
+      if {$completed_steps($s) < $num_steps} {
+        set steps [expr {$num_steps - $completed_steps($s)}]
+        set completed_steps($s) $num_steps
+        $itk_interior.f.meter$i step $steps
+      }
     }
   }
 
@@ -91,7 +106,11 @@ itcl::body Download::done { {msg ""} } {
     # set all indicators to FULL
     foreach sec $section(names) {
       set i $section($sec)
-      $itk_interior.f.meter$i configure -fraction 1.0
+      if {$completed_steps($sec) < $num_steps} {
+        set steps [expr {$num_steps - $completed_steps($sec)}]
+        set completed_steps($sec) $num_steps
+        $itk_interior.f.meter$i step $steps
+      }
     }
   } else {
     # download failed
@@ -221,6 +240,7 @@ itcl::body Download::download_it { } {
     set b [lindex $x 1]
     set bytes($i) [expr {double($b)}]
     incr total_bytes $b
+    set completed_steps($s) 0
     incr i
   }
   set num_sections $i
Index: download.ith
===================================================================
RCS file: /cvs/src/src/gdb/gdbtk/library/download.ith,v
retrieving revision 1.5
diff -u -p -r1.5 download.ith
--- download.ith	15 Oct 2002 21:19:51 -0000	1.5
+++ download.ith	8 Dec 2004 22:25:02 -0000
@@ -22,6 +22,9 @@ itcl::class Download {
     common num_sections
     common num_steps 100
 
+    # completed steps in feedback meter (iwidget::feedback is lame)
+    common completed_steps
+
     method _ignore_on_save {} { return 1 }
     proc dont_remember_size {} { return 1}
   }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]