[PATCH] setup: add "Size" column to chooser (take 2)

Igor Pechtchanski pechtcha@cs.nyu.edu
Tue May 24 14:16:00 GMT 2005


Here's a new iteration of this patch.  It incorporates Max's review and
adds comments in the size computation logic.

The size is now computed as follows: if the binary or the source package
is selected, the total size of the selected packages is used.  Otherwise,
the size of the binary package is shown (if one exists), else the size of
the source (if one exists), else "?".  As Max, I'm not sure this is the
right solution -- comments welcome.
	Igor
P.S. The ChangeLog changed slightly -- new one 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 function.
	* String++.h (format_1000s): Declare new function.

-- 
				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 14:06:29 -0000
@@ -88,6 +88,28 @@ 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;
+      // Use chosen version or the default
+      packageversion picked = pkg.desired;
+      if (!picked) picked = pkg.trustp(theView.deftrust);
+      // If source is picked, add up the size
+      if (picked.sourcePackage().picked())
+        sz += picked.sourcePackage().source()->size;
+      // If binary or nothing is picked, add up the binary size
+      if (picked.picked() || sz == 0)
+	sz += picked.source()->size;
+      // If no binary, add up the source size
+      if (sz == 0)
+        sz += picked.sourcePackage().source()->size;
+      // If size still 0, size must be unknown
+      s = (sz == 0) ? "?" : format_1000s(sz);
+      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 14:06:30 -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 14:06:30 -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 14:06:30 -0000
@@ -304,3 +304,23 @@ operator << (ostream &os, String const &
   os << theString.c_str();
   return os;
 }
+
+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 14:06:30 -0000
@@ -115,4 +115,7 @@ char *new_cstr_char_array (const String 
    bar", "TOSTRING(foo)", to yield "bar". */
 #define TOSTRING(X) __TOSTRING__(X)
 
+String
+format_1000s(const int num, char sep = ',');
+
 #endif /* SETUP_STRING___H */


More information about the Cygwin-apps mailing list