[Aptitude-devel] r3037 - in branches/aptitude-0.3/aptitude: . src src/generic

Daniel Burrows dburrows@costa.debian.org
Fri, 22 Apr 2005 03:31:21 +0000


Author: dburrows
Date: Fri Apr 22 03:31:18 2005
New Revision: 3037

Added:
   branches/aptitude-0.3/aptitude/src/broken_indicator.cc
   branches/aptitude-0.3/aptitude/src/broken_indicator.h
Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/Makefile.am
   branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h
Log:
Write a class to display the solver info.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Apr 22 03:31:18 2005
@@ -1,5 +1,11 @@
 2005-04-21  Daniel Burrows  <dburrows@debian.org>
 
+	* src/Makefile.am, src/broken_indicator.cc, src/broken_indicator.h, src/generic/aptitude_resolver.h:
+
+	  Write a first draft of the widget to display information about
+	  the current proposed solution.  Also made some methods const
+	  that ought to be.  sleepy.
+
 	* src/generic/aptcache.cc:
 
 	  Look up BrokenCount on "this", not on the global apt_cache_file

Modified: branches/aptitude-0.3/aptitude/src/Makefile.am
==============================================================================
--- branches/aptitude-0.3/aptitude/src/Makefile.am	(original)
+++ branches/aptitude-0.3/aptitude/src/Makefile.am	Fri Apr 22 03:31:18 2005
@@ -21,6 +21,8 @@
 	apt_info_tree.h\
 	apt_options.cc	\
 	apt_options.h	\
+	broken_indicator.cc\
+	broken_indicator.h\
 	defaults.cc	\
 	defaults.h	\
 	dep_item.cc	\

Added: branches/aptitude-0.3/aptitude/src/broken_indicator.cc
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/broken_indicator.cc	Fri Apr 22 03:31:18 2005
@@ -0,0 +1,177 @@
+// broken_indicator.cc
+//
+//   Copyright (C) 2005 Daniel Burrows
+//
+//   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 the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+
+#include "broken_indicator.h"
+
+#include <aptitude.h>
+
+#include <generic/apt.h>
+#include <generic/aptcache.h>
+#include <generic/aptitude_resolver.h>
+
+#include <vscreen/config/colors.h>
+#include <vscreen/config/keybindings.h>
+#include <vscreen/fragment.h>
+#include <vscreen/vs_text_layout.h>
+
+#include <apt-pkg/pkgsystem.h>
+
+#include <string>
+#include <vector>
+
+using namespace std;
+
+/** A simple indicator, usually placed at the bottom of the screen,
+ *  that describes the current state of the problem resolver.  Hidden
+ *  if no problem resolver is active.
+ *
+ *  \todo write a simple table fragment class and use that to
+ *  right-justify the text that obviously should be
+ */
+class broken_indicator:public vs_text_layout
+{
+  void update()
+  {
+    if((!apt_cache_file) || !(*apt_cache_file)->resolver_exists())
+      set_fragment(NULL);
+
+    string next=global_bindings.keyname("NextSolution");
+    string prev=global_bindings.keyname("PrevSolution");
+    string examine=global_bindings.keyname("ExamineSolution");
+    string apply=global_bindings.keyname("ApplySolution");
+
+    // try to retrieve the current solution to show information about
+    // it.
+    try
+      {
+	aptitude_resolver::solution sol=(*apt_cache_file)->get_current_solution();
+
+	int install_count=0, remove_count=0, keep_count=0, upgrade_count=0, downgrade_count=0;
+
+	for(std::map<aptitude_resolver::package,
+	      aptitude_resolver::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 instver=(*apt_cache_file)[pkg].InstVerIter(*apt_cache_file);
+	    pkgCache::VerIterator newver=i->second.ver.get_ver();
+
+	    // If not, we have a problem.
+	    assert(instver!=newver);
+
+	    if(curver.end())
+	      ++install_count;
+	    else if(newver.end())
+	      ++remove_count;
+	    else if(newver == curver)
+	      ++keep_count;
+	    else
+	      {
+		int cmp=_system->VS->CmpVersion(curver.VerStr(),
+						newver.VerStr());
+
+		// The versions shouldn't be equal -- otherwise
+		// something is majorly wrong.
+		assert(cmp!=0);
+
+		if(cmp<0)
+		  ++upgrade_count;
+		else if(cmp>0)
+		  ++downgrade_count;
+	      }
+
+	    vector<fragment *> fragments;
+
+	    fragments.push_back(fragf(_("Suggest ")));
+
+	    vector<fragment *> suggestions;
+
+	    char buf[512];
+
+	    if(install_count>0)
+	      {
+		snprintf(buf, 512, _("%d installs"),
+			 install_count);
+		suggestions.push_back(text_fragment(buf));
+	      }
+
+	    if(remove_count>0)
+	      {
+		snprintf(buf, 512, _("%d removals"),
+			 remove_count);
+		suggestions.push_back(text_fragment(buf));
+	      }
+
+	    if(upgrade_count>0)
+	      {
+		snprintf(buf, 512, _("%d upgrades"),
+			 upgrade_count);
+		suggestions.push_back(text_fragment(buf));
+	      }
+
+	    if(downgrade_count>0)
+	      {
+		snprintf(buf, 512, _("%d downgrades"),
+			 upgrade_count);
+		suggestions.push_back(text_fragment(buf));
+	      }
+
+	    fragments.push_back(join_fragments(suggestions,
+					       ","));
+
+	    fragments.push_back(fragf("  "));
+
+	    vector<fragment *> key_hints;
+
+	    key_hints.push_back(fragf("%s: examine",
+				      examine.c_str()));
+	    key_hints.push_back(fragf("%s: apply",
+				      apply.c_str()));
+	    key_hints.push_back(fragf("%s: next",
+				      next.c_str()));
+	    key_hints.push_back(fragf("%s: previous",
+				      prev.c_str()));
+
+	    fragments.push_back(join_fragments(key_hints,
+					       "  "));
+
+	    fragment *f=sequence_fragment(fragments);
+	    f->set_attr(get_color("Error"));
+	    set_fragment(f);
+	  }
+      }
+    catch(NoMoreTime)
+      {
+	set_fragment(fragf(_("%CSolution search failed.  %s: try harder"),
+			   "Error",
+			   next.c_str()));
+      }
+    catch(NoMoreSolutions)
+      {
+	set_fragment(fragf(_("%CUnable to resolve dependencies."),
+			   "Error"));
+      }
+  }
+public:
+  broken_indicator()
+  {
+    update();
+  }
+};

Added: branches/aptitude-0.3/aptitude/src/broken_indicator.h
==============================================================================
--- (empty file)
+++ branches/aptitude-0.3/aptitude/src/broken_indicator.h	Fri Apr 22 03:31:18 2005
@@ -0,0 +1,31 @@
+// broken_indicator.h                        -*-c++-*-
+//
+//   Copyright (C) 2005 Daniel Burrows
+//
+//   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 the Free Software Foundation; either version 2 of
+//   the License, or (at your option) any later version.
+//
+//   This program is distributed in the hope that it will be useful,
+//   but WITHOUT ANY WARRANTY; without even the implied warranty of
+//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//   General Public License for more details.
+//
+//   You should have received a copy of the GNU General Public License
+//   along with this program; see the file COPYING.  If not, write to
+//   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+//   Boston, MA 02111-1307, USA.
+//
+// Generates a (hopefully) unobtrusive hint about how to use the
+// problem resolver.
+
+#ifndef BROKEN_INDICATOR_H
+#define BROKEN_INDICATOR_H
+
+class vscreen_widget;
+
+/** \return a newly generated "broken indicator". */
+vscreen_widget *make_broken_indicator();
+
+#endif // BROKEN_INDICATOR_H

Modified: branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/aptitude_resolver.h	Fri Apr 22 03:31:18 2005
@@ -111,12 +111,12 @@
   {
   }
 
-  pkgCache::PkgIterator get_pkg()
+  pkgCache::PkgIterator get_pkg() const
   {
     return pkg;
   }
 
-  pkgCache::VerIterator get_ver()
+  pkgCache::VerIterator get_ver() const
   {
     return ver;
   }