[PATCH] setup: add "Size" column to chooser

Igor Pechtchanski pechtcha@cs.nyu.edu
Tue May 24 05:58:00 GMT 2005


As promised earlier, here's a patch against the current CVS that adds the
"Size" column to the setup chooser screen, showing the size of the package
tarball(s).  It seems to work well for me.  Two caveats: since the size
information is extracted from setup.ini, if a package is not in setup.ini,
the size will be wrong or nonexistent; and this doesn't work well for
source-only packages (mostly because currently only one version of the
source can be selected).  Please test.  Comments welcome.
	Igor
ChangeLog below:
==============================================================================
2005-05-24  Igor Pechtchanski  <pechtcha@cs.nyu.edu>

	* PickView.h (PickView::size_col): New instance variable.
	* PickView.cc (pkg_headers, cat_headers): Add size column.
	(PickView::set_headers): Initialize size_col.
	(PickView::init_headers): Include width of size column.
	* PickPackageLine.cc (PickPackageLine::paint): Handle size_col.
	* String++.cc (format_1000s): New functions.
	* String++.h (format_1000s): Declare new functions.

-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"The Sun will pass between the Earth and the Moon tonight for a total
Lunar eclipse..." -- WCBS Radio Newsbrief, Oct 27 2004, 12:01 pm EDT
-------------- next part --------------
Index: PickPackageLine.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickPackageLine.cc,v
retrieving revision 2.16
diff -u -p -r2.16 PickPackageLine.cc
--- PickPackageLine.cc	21 May 2005 23:04:02 -0000	2.16
+++ PickPackageLine.cc	24 May 2005 04:44:57 -0000
@@ -88,6 +88,22 @@ PickPackageLine::paint (HDC hdc, HRGN un
           TextOut (hdc, x + HMARGIN / 2, y, s.c_str(), s.size());
         }
     }
+  else if (col_num == theView.size_col)
+    {
+      int sz = 0;
+      packageversion picked = pkg.desired;
+      if (!picked) picked = pkg.trustp(theView.deftrust);
+      sz += picked.source()->size;
+      if (picked.sourcePackage().picked() || sz == 0)
+        sz += picked.sourcePackage().source()->size;
+      s = format_1000s(sz);
+      if (sz == 0)
+        s = "?";
+      SIZE tw;
+      GetTextExtentPoint32 (hdc, s.c_str(), s.size(), &tw);
+      int cw = theView.headers[col_num].width - HMARGIN - tw.cx;
+      TextOut (hdc, x + cw + HMARGIN / 2, y, s.c_str(), s.size());
+    }
   else if (col_num == theView.pkg_col)
     {
       s = pkg.name;
Index: PickView.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickView.cc,v
retrieving revision 2.24
diff -u -p -r2.24 PickView.cc
--- PickView.cc	21 May 2005 23:04:02 -0000	2.24
+++ PickView.cc	24 May 2005 04:44:57 -0000
@@ -34,6 +34,7 @@ static PickView::Header pkg_headers[] = 
   {"Bin?", 0, 0, false},
   {"Src?", 0, 0, false},
   {"Categories", 0, 0, true},
+  {"Size", 0, 0, true},
   {"Package", 0, 0, true},
   {0, 0, 0, false}
 };
@@ -44,6 +45,7 @@ static PickView::Header cat_headers[] = 
   {"New", 0, 0, true},
   {"Bin?", 0, 0, false},
   {"Src?", 0, 0, false},
+  {"Size", 0, 0, true},
   {"Package", 0, 0, true},
   {0, 0, 0, false}
 };
@@ -98,7 +100,8 @@ PickView::set_headers ()
       bintick_col = new_col + 1;
       srctick_col = bintick_col + 1;
       cat_col = srctick_col + 1;
-      pkg_col = cat_col + 1;
+      size_col = cat_col + 1;
+      pkg_col = size_col + 1;
       last_col = pkg_col;
     }
   else if (view_mode == views::Category)
@@ -109,7 +112,8 @@ PickView::set_headers ()
       bintick_col = new_col + 1;
       srctick_col = bintick_col + 1;
       cat_col = 0;
-      pkg_col = srctick_col + 1;
+      size_col = srctick_col + 1;
+      pkg_col = size_col + 1;
       last_col = pkg_col;
     }
   else
@@ -443,9 +447,15 @@ PickView::init_headers (HDC dc)
                     HMARGIN, current_col);
       for (set<packageversion>::iterator i = pkg.versions.begin ();
 	   i != pkg.versions.end (); ++i)
-        if (*i != pkg.installed)
-          note_width (headers, dc, i->Canonical_version (), 
-                      HMARGIN + SPIN_WIDTH, new_col);
+	{
+          if (*i != pkg.installed)
+            note_width (headers, dc, i->Canonical_version (),
+                        HMARGIN + SPIN_WIDTH, new_col);
+	  String z = format_1000s(packageversion(*i).source ()->size);
+	  note_width (headers, dc, z, HMARGIN, size_col);
+	  z = format_1000s(packageversion(i->sourcePackage ()).source ()->size);
+	  note_width (headers, dc, z, HMARGIN, size_col);
+	}
       String s = pkg.name;
       if (pkg.SDesc ().size())
 	s += String (": ") + pkg.SDesc ();
Index: PickView.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/PickView.h,v
retrieving revision 2.14
diff -u -p -r2.14 PickView.h
--- PickView.h	21 May 2005 23:04:02 -0000	2.14
+++ PickView.h	24 May 2005 04:44:57 -0000
@@ -66,6 +66,7 @@ public:
   int bintick_col;
   int srctick_col;
   int cat_col;
+  int size_col;
   int pkg_col;
   int last_col;
   int row_height;
Index: String++.cc
===================================================================
RCS file: /cvs/cygwin-apps/setup/String++.cc,v
retrieving revision 2.16
diff -u -p -r2.16 String++.cc
--- String++.cc	5 May 2005 22:48:34 -0000	2.16
+++ String++.cc	24 May 2005 04:44:57 -0000
@@ -304,3 +304,29 @@ operator << (ostream &os, String const &
   os << theString.c_str();
   return os;
 }
+
+String
+format_1000s(const int num)
+{
+  return format_1000s (num, ',');
+}
+
+String
+format_1000s(const int num, char sep)
+{
+  int mult = 1;
+  while (mult * 1000 < num)
+    mult *= 1000;
+  ostringstream os;
+  os << ((num / mult) % 1000);
+  for (mult /= 1000; mult > 0; mult /= 1000)
+    {
+      int triplet = (num / mult) % 1000;
+      os << sep;
+      if (triplet < 100) os << '0';
+      if (triplet < 10) os << '0';
+      os << triplet;
+    }
+  return String(os.str());
+}
+
Index: String++.h
===================================================================
RCS file: /cvs/cygwin-apps/setup/String++.h,v
retrieving revision 2.20
diff -u -p -r2.20 String++.h
--- String++.h	5 May 2005 22:48:34 -0000	2.20
+++ String++.h	24 May 2005 04:44:57 -0000
@@ -115,4 +115,10 @@ char *new_cstr_char_array (const String 
    bar", "TOSTRING(foo)", to yield "bar". */
 #define TOSTRING(X) __TOSTRING__(X)
 
+String
+format_1000s(const int num);
+
+String
+format_1000s(const int num, char sep);
+
 #endif /* SETUP_STRING___H */


More information about the Cygwin-apps mailing list