[Aptitude-svn-commit] r3881 - in branches/aptitude-0.3/aptitude: . src

Daniel Burrows dburrows at costa.debian.org
Wed Aug 17 01:15:50 UTC 2005


Author: dburrows
Date: Wed Aug 17 01:15:47 2005
New Revision: 3881

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/solution_screen.cc
Log:
Add a class that describes actions rather than just displaying the associated version.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Aug 17 01:15:47 2005
@@ -1,5 +1,10 @@
 2005-08-16  Daniel Burrows  <dburrows at debian.org>
 
+	* src/solution_screen.cc:
+
+	  Add a class that describes an action instead of just presenting
+	  its associated version.
+
 	* src/generic/problemresolver/dump_universe.h:
 
 	  Indent soft dependencies the same way as hard dependencies.

Modified: branches/aptitude-0.3/aptitude/src/solution_screen.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/solution_screen.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/solution_screen.cc	Wed Aug 17 01:15:47 2005
@@ -47,6 +47,50 @@
   }
 };
 
+enum action_type {action_remove, action_keep, action_install,
+		  action_downgrade, action_upgrade};
+
+/** A simpler version of find_pkg_state that doesn't care about
+ *  automaticness.
+ */
+static
+action_type analyze_action(const aptitude_universe::version &ver)
+{
+  pkgCache::PkgIterator pkg=ver.get_pkg();
+  pkgCache::VerIterator curver=pkg.CurrentVer();
+  pkgCache::VerIterator newver=ver.get_ver();
+
+  if(curver.end())
+    {
+      if(newver.end())
+	return action_keep;
+      else
+	return action_install;
+    }
+  else if(newver.end())
+    return action_remove;
+  else if(newver == curver)
+    return action_keep;
+  else
+    {
+      int cmp=_system->VS->CmpVersion(curver.VerStr(),
+				      newver.VerStr());
+
+      // The versions shouldn't be equal -- otherwise
+      // something is majorly wrong.
+      // assert(cmp!=0);
+      //
+      // The above is not true: consider, eg, the case of a
+      // locally compiled package and a standard package.
+
+      /** \todo indicate "sidegrades" separately? */
+      if(cmp <= 0)
+	return action_upgrade;
+      else
+	return action_downgrade;
+    }
+}
+
 /** Partition the set of all packages into several vectors,
  *  according to the action to be performed on each package.
  *
@@ -61,51 +105,36 @@
  *         its target version will be placed in this vector.
  */
 void bin_actions(const aptitude_solution &sol,
-		  vector<aptitude_solution::action> &remove_actions,
-		  vector<aptitude_solution::action> &keep_actions,
-		  vector<aptitude_solution::action> &install_actions,
-		  vector<aptitude_solution::action> &downgrade_actions,
-		  vector<aptitude_solution::action> &upgrade_actions)
+		 vector<aptitude_solution::action> &remove_actions,
+		 vector<aptitude_solution::action> &keep_actions,
+		 vector<aptitude_solution::action> &install_actions,
+		 vector<aptitude_solution::action> &downgrade_actions,
+		 vector<aptitude_solution::action> &upgrade_actions)
 {
 
   for(std::map<aptitude_universe::package,
 	aptitude_solution::action>::const_iterator i=sol.get_actions().begin();
       i!=sol.get_actions().end(); ++i)
-    {
-      pkgCache::PkgIterator pkg=i->first.get_pkg();
-      pkgCache::VerIterator curver=pkg.CurrentVer();
-      pkgCache::VerIterator newver=i->second.ver.get_ver();
-
-      if(curver.end())
-	{
-	  if(newver.end())
-	    keep_actions.push_back(i->second);
-	  else
-	    install_actions.push_back(i->second);
-	}
-      else if(newver.end())
+    switch(analyze_action(i->second.ver))
+      {
+      case action_remove:
 	remove_actions.push_back(i->second);
-      else if(newver == curver)
+	break;
+      case action_keep:
 	keep_actions.push_back(i->second);
-      else
-	{
-	  int cmp=_system->VS->CmpVersion(curver.VerStr(),
-					  newver.VerStr());
-
-	  // The versions shouldn't be equal -- otherwise
-	  // something is majorly wrong.
-	  // assert(cmp!=0);
-	  //
-	  // The above is not true: consider, eg, the case of a
-	  // locally compiled package and a standard package.
-
-	  /** \todo indicate "sidegrades" separately? */
-	  if(cmp<=0)
-	    upgrade_actions.push_back(i->second);
-	  else if(cmp>0)
-	    downgrade_actions.push_back(i->second);
-	}
-    }
+	break;
+      case action_install:
+	install_actions.push_back(i->second);
+	break;
+      case action_downgrade:
+	downgrade_actions.push_back(i->second);
+	break;
+      case action_upgrade:
+	upgrade_actions.push_back(i->second);
+	break;
+      default:
+	abort();
+      }
 }
 
 static string archives(const pkgCache::VerIterator &ver)
@@ -301,6 +330,134 @@
       }
   }
 
+  aptitude_universe::version get_ver() const
+  {
+    return ver;
+  }
+
+  void paint(vs_tree *win, int y, bool hierarchical, const style &st)
+  {
+    unsigned int basex = hierarchical ? 2*get_depth() : 0;
+    unsigned int width = win->getmaxx();
+
+    unsigned int x = 0;
+
+    win->move(y, 0);
+
+    if(x < width)
+      {
+	if(is_rejected())
+	  win->addch('R'); // For "reject"
+	else if(is_mandatory())
+	  win->addch('A'); // For "accept"
+	else
+	  win->addch(' ');
+	++x;
+      }
+
+    if(x < width)
+      {
+	win->addch(' ');
+	++x;
+      }
+
+    while(x < width && x < basex)
+      {
+	win->addch(' ');
+	++x;
+      }
+
+    if(x < width)
+      {
+	win->addch('-');
+	++x;
+      }
+
+    if(x < width)
+      {
+	win->addch('>');
+	++x;
+      }
+
+    if(x < width)
+      {
+	win->addch(' ');
+	++x;
+      }
+
+    wstring s;
+
+    pkgCache::PkgIterator pkg = ver.get_package().get_pkg();
+
+    switch(analyze_action(ver))
+      {
+      case action_remove:
+	s = swsprintf(transcode(_("Remove %s [%s (%s)]")).c_str(),
+		      pkg.Name(),
+		      pkg.CurrentVer().VerStr(),
+		      archives(pkg.CurrentVer()).c_str());
+	break;
+
+      case action_install:
+	s = swsprintf(transcode(_("Install %s [%s (%s)]")).c_str(),
+		      pkg.Name(),
+		      ver.get_ver().VerStr(),
+		      archives(ver.get_ver()).c_str());
+	break;
+
+      case action_keep:
+	if(ver.get_ver().end())
+	  s = swsprintf(transcode(_("Cancel the installation of %s")).c_str(),
+			pkg.Name());
+	else
+	  s = swsprintf(transcode(_("Keep %s at version %s (%s)")).c_str(),
+			pkg.Name(), ver.get_ver().VerStr(),
+			archives(ver.get_ver()).c_str());
+
+	break;
+
+      case action_upgrade:
+	s = swsprintf(transcode(_("Upgrade %s [%s (%s) -> %s (%s)]")).c_str(),
+		      pkg.CurrentVer().VerStr(),
+		      archives(pkg.CurrentVer()).c_str(),
+		      ver.get_ver().VerStr(), archives(ver.get_ver()).c_str());
+	break;
+
+
+      case action_downgrade:
+	s = swsprintf(transcode(_("Downgrade %s [%s (%s) -> %s (%s)]")).c_str(),
+		      pkg.CurrentVer().VerStr(), archives(pkg.CurrentVer()).c_str(),
+		      ver.get_ver().VerStr(), archives(ver.get_ver()).c_str());
+	break;
+      }
+
+    wstring::const_iterator loc = s.begin();
+    while(loc != s.end() && x < width)
+      {
+	win->add_wch(*loc);
+	x += wcwidth(*loc);
+	++loc;
+      }
+
+    while(x < width)
+      {
+	win->addch(' ');
+	++x;
+      }
+  }
+};
+
+/** Like a solution_act_item, but the display doesn't include the
+ *  descriptive verb ("install" or whatever).
+ */
+class solution_act_item_bare : public solution_act_item
+{
+public:
+  solution_act_item_bare(const aptitude_solution::action &act)
+    :solution_act_item(act)
+  {
+  }
+
   void paint(vs_tree *win, int y, bool hierarchical, const style &st)
   {
     unsigned int basex = hierarchical ? 2*get_depth() : 0;
@@ -333,7 +490,10 @@
 	++x;
       }
 
-    win->apply_style(st+style_attrs_flip(A_BOLD));
+    win->apply_style(st+style_attrs_on(A_BOLD));
+
+    aptitude_universe::version ver = get_ver();
+
     const char *name = ver.get_pkg().Name();
     while(x < width && *name)
       {
@@ -540,7 +700,7 @@
 
       for(vector<aptitude_solution::action>::const_iterator i = remove_actions.begin();
 	  i != remove_actions.end(); ++i)
-	remove_tree->add_child(new solution_act_item(*i));
+	remove_tree->add_child(new solution_act_item_bare(*i));
 
       root->add_child(remove_tree);
     }
@@ -551,7 +711,7 @@
 
       for(vector<aptitude_solution::action>::const_iterator i = keep_actions.begin();
 	  i != keep_actions.end(); ++i)
-	keep_tree->add_child(new solution_act_item(*i));
+	keep_tree->add_child(new solution_act_item_bare(*i));
 
       root->add_child(keep_tree);
     }
@@ -562,7 +722,7 @@
 
       for(vector<aptitude_solution::action>::const_iterator i = install_actions.begin();
 	  i != install_actions.end(); ++i)
-	install_tree->add_child(new solution_act_item(*i));
+	install_tree->add_child(new solution_act_item_bare(*i));
 
       root->add_child(install_tree);
     }
@@ -573,7 +733,7 @@
 
       for(vector<aptitude_solution::action>::const_iterator i = upgrade_actions.begin();
 	  i != upgrade_actions.end(); ++i)
-	upgrade_tree->add_child(new solution_act_item(*i));
+	upgrade_tree->add_child(new solution_act_item_bare(*i));
 
       root->add_child(upgrade_tree);
     }
@@ -584,7 +744,7 @@
 
       for(vector<aptitude_solution::action>::const_iterator i = downgrade_actions.begin();
 	  i != downgrade_actions.end(); ++i)
-	downgrade_tree->add_child(new solution_act_item(*i));
+	downgrade_tree->add_child(new solution_act_item_bare(*i));
 
       root->add_child(downgrade_tree);
     }



More information about the Aptitude-svn-commit mailing list