summaryrefslogtreecommitdiff
path: root/src/gtk/resolver.cc
diff options
context:
space:
mode:
authorDaniel Burrows <dburrows@debian.org>2009-01-04 19:34:07 -0800
committerDaniel Burrows <dburrows@debian.org>2009-01-04 19:34:07 -0800
commit51e07b5c9d6631ed12a48599b025b34d12fc8590 (patch)
tree5c73c9725c80421c10b78badced419a839f46386 /src/gtk/resolver.cc
parent7e9eb975918e80c913e4a28397f9a05544f6b9f2 (diff)
downloadaptitude-51e07b5c9d6631ed12a48599b025b34d12fc8590.tar.gz
Implement a first cut of an explanation mode for the GUI resolver.
Diffstat (limited to 'src/gtk/resolver.cc')
-rw-r--r--src/gtk/resolver.cc107
1 files changed, 106 insertions, 1 deletions
diff --git a/src/gtk/resolver.cc b/src/gtk/resolver.cc
index becf2b48..041c75de 100644
--- a/src/gtk/resolver.cc
+++ b/src/gtk/resolver.cc
@@ -28,11 +28,16 @@
#include <apt-pkg/error.h>
+#include <solution_fragment.h> // For archives_text.
+#include <solution_item.h> // For action_type.
+
#include <generic/apt/apt_undo_group.h>
#include <generic/problemresolver/exceptions.h>
#include <gui.h>
+#include <cwidget/generic/util/ssprintf.h>
+
namespace gui
{
namespace
@@ -460,6 +465,106 @@ namespace gui
return store;
}
+ Glib::RefPtr<Gtk::TreeStore> ResolverTab::render_as_explanation(const aptitude_solution &sol)
+ {
+ Glib::RefPtr<Gtk::TreeStore> store(createstore());
+
+ if(sol.get_actions().empty())
+ {
+ Gtk::TreeModel::iterator iter = store->append();
+ Gtk::TreeModel::Row row = *iter;
+ row[pResolverView->resolver_columns.Name] = _("Internal error: unexpected null solution.");
+ }
+ else
+ {
+ std::vector<aptitude_solution::action> actions;
+
+ for(imm::map<aptitude_universe::package, aptitude_solution::action>::const_iterator
+ it = sol.get_actions().begin();
+ it != sol.get_actions().end(); ++it)
+ actions.push_back(it->second);
+
+ std::sort(actions.begin(), actions.end(),
+ aptitude_solution::action_id_compare());
+
+ for(std::vector<aptitude_solution::action>::const_iterator
+ it = actions.begin(); it != actions.end(); ++it)
+ {
+ Gtk::TreeModel::iterator parent_iter = store->append();
+ Gtk::TreeModel::Row parent_row = *parent_iter;
+
+ parent_row[pResolverView->resolver_columns.Name] = cwidget::util::transcode(dep_text((*it).d.get_dep()), "UTF-8");
+
+ Gtk::TreeModel::iterator iter = store->append(parent_row.children());
+ Gtk::TreeModel::Row row = *iter;
+ Glib::ustring name;
+
+ aptitude_resolver_version ver((*it).ver);
+ pkgCache::PkgIterator pkg = ver.get_pkg();
+ action_type action(analyze_action(ver));
+
+ using cwidget::util::ssprintf;
+
+ switch(action)
+ {
+ case action_remove:
+ name = ssprintf(_("Remove %s [%s (%s)]"),
+ pkg.Name(),
+ pkg.CurrentVer().VerStr(),
+ archives_text(pkg.CurrentVer()).c_str());
+ break;
+
+ case action_install:
+ name = ssprintf(_("Install %s [%s (%s)]"),
+ pkg.Name(),
+ ver.get_ver().VerStr(),
+ archives_text(ver.get_ver()).c_str());
+ break;
+
+ case action_keep:
+ if(ver.get_ver().end())
+ name = ssprintf(_("Cancel the installation of %s"),
+ pkg.Name());
+ else if(ver.get_package().current_version().get_ver().end())
+ name = ssprintf(_("Cancel the removal of %s"),
+ pkg.Name());
+ else
+ name = ssprintf(_("Keep %s at version %s (%s)"),
+ pkg.Name(),
+ ver.get_ver().VerStr(),
+ archives_text(ver.get_ver()).c_str());
+ break;
+
+ case action_upgrade:
+ name = ssprintf(_("Upgrade %s [%s (%s) -> %s (%s)]"),
+ pkg.Name(),
+ pkg.CurrentVer().VerStr(),
+ archives_text(pkg.CurrentVer()).c_str(),
+ ver.get_ver().VerStr(),
+ archives_text(ver.get_ver()).c_str());
+ break;
+
+ case action_downgrade:
+ name = ssprintf(_("Downgrade %s [%s (%s) -> %s (%s)]"),
+ pkg.Name(),
+ pkg.CurrentVer().VerStr(),
+ archives_text(pkg.CurrentVer()).c_str(),
+ ver.get_ver().VerStr(),
+ archives_text(ver.get_ver()).c_str());
+ break;
+
+ default:
+ name = "Internal error: bad action type";
+ break;
+ }
+
+ row[pResolverView->resolver_columns.Name] = name;
+ }
+ }
+
+ return store;
+ }
+
void ResolverTab::update_from_state(const resolver_manager::state &state)
{
Glib::RefPtr<Gtk::TreeStore> store = Gtk::TreeStore::create(pResolverView->resolver_columns);
@@ -517,7 +622,7 @@ namespace gui
last_sol = sol;
- store = render_as_action_groups(sol);
+ store = render_as_explanation(sol);
}
pResolverView->set_model(store);