diff options
author | Daniel Burrows <dburrows@debian.org> | 2009-01-04 19:00:22 -0800 |
---|---|---|
committer | Daniel Burrows <dburrows@debian.org> | 2009-01-04 19:00:22 -0800 |
commit | 7e9eb975918e80c913e4a28397f9a05544f6b9f2 (patch) | |
tree | ab964ed9399d4d8ad0c1901ca8092a9f0c6c7434 | |
parent | b2f46eeca4d2876b31709b96037e2c87e0670e11 (diff) | |
download | aptitude-7e9eb975918e80c913e4a28397f9a05544f6b9f2.tar.gz |
Extract the logic to build a tree that groups the actions of a resolver solution by type into its own method.
-rw-r--r-- | src/gtk/resolver.cc | 369 | ||||
-rw-r--r-- | src/gtk/resolver.h | 13 |
2 files changed, 199 insertions, 183 deletions
diff --git a/src/gtk/resolver.cc b/src/gtk/resolver.cc index 6aaeeed1..becf2b48 100644 --- a/src/gtk/resolver.cc +++ b/src/gtk/resolver.cc @@ -1,6 +1,6 @@ // resolver.cc // -// Copyright 1999-2008 Daniel Burrows +// Copyright 1999-2009 Daniel Burrows // Copyright 2008 Obey Arthur Liu // // This program is free software; you can redistribute it and/or modify @@ -151,15 +151,8 @@ namespace gui ResolverView::ResolverView(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade) : Gtk::TreeView(cobject) //Calls the base class constructor { - createstore(); append_column(Glib::ustring(_("Name")), Name, resolver_columns.Name, 200); append_column(Glib::ustring(_("Action")), Section, resolver_columns.Action, 200); - } - - void ResolverView::createstore() - { - resolver_store = Gtk::TreeStore::create(resolver_columns); - set_model(resolver_store); set_search_column(resolver_columns.Name); } @@ -281,6 +274,192 @@ namespace gui } } + Glib::RefPtr<Gtk::TreeStore> ResolverTab::createstore() + { + return Gtk::TreeStore::create(pResolverView->resolver_columns); + } + + Glib::RefPtr<Gtk::TreeStore> ResolverTab::render_as_action_groups(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 + { + // Bin packages according to what will happen to them. + vector<pkgCache::PkgIterator> remove_packages; + vector<pkgCache::PkgIterator> keep_packages; + vector<pkgCache::VerIterator> install_packages; + vector<pkgCache::VerIterator> downgrade_packages; + vector<pkgCache::VerIterator> upgrade_packages; + + for(imm::map<aptitude_universe::package, + generic_solution<aptitude_universe>::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_packages.push_back(pkg); + else + install_packages.push_back(newver); + } + else if(newver.end()) + remove_packages.push_back(pkg); + else if(newver == curver) + keep_packages.push_back(pkg); + else + { + int cmp=_system->VS->CmpVersion(curver.VerStr(), + newver.VerStr()); + + // The versions shouldn't be equal -- otherwise + // something is majorly wrong. + // eassert(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_packages.push_back(newver); + else if(cmp>0) + downgrade_packages.push_back(newver); + } + } + + sort(remove_packages.begin(), remove_packages.end(), pkg_name_lt()); + sort(keep_packages.begin(), keep_packages.end(), pkg_name_lt()); + sort(install_packages.begin(), install_packages.end(), ver_name_lt()); + sort(downgrade_packages.begin(), downgrade_packages.end(), ver_name_lt()); + sort(upgrade_packages.begin(), upgrade_packages.end(), ver_name_lt()); + + if(!remove_packages.empty()) + { + Gtk::TreeModel::iterator parent_iter = store->append(); + Gtk::TreeModel::Row parent_row = *parent_iter; + parent_row[pResolverView->resolver_columns.Name] = _("Remove the following packages:"); + for(vector<pkgCache::PkgIterator>::const_iterator i=remove_packages.begin(); + i!=remove_packages.end(); ++i) + { + Gtk::TreeModel::iterator iter = store->append(parent_row.children()); + Gtk::TreeModel::Row row = *iter; + row[pResolverView->resolver_columns.Name] = i->Name(); + row[pResolverView->resolver_columns.Action] = ""; + } + } + + if(!install_packages.empty()) + { + Gtk::TreeModel::iterator parent_iter = store->append(); + Gtk::TreeModel::Row parent_row = *parent_iter; + parent_row[pResolverView->resolver_columns.Name] = _("Install the following packages:"); + for(vector<pkgCache::VerIterator>::const_iterator i=install_packages.begin(); + i!=install_packages.end(); ++i) + { + Gtk::TreeModel::iterator iter = store->append(parent_row.children()); + Gtk::TreeModel::Row row = *iter; + row[pResolverView->resolver_columns.Name] = i->ParentPkg().Name(); + row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s)]", + i->VerStr(), + archives_text(*i).c_str()); + } + } + + if(!keep_packages.empty()) + { + Gtk::TreeModel::iterator parent_iter = store->append(); + Gtk::TreeModel::Row parent_row = *parent_iter; + parent_row[pResolverView->resolver_columns.Name] = _("Keep the following packages:"); + for(vector<pkgCache::PkgIterator>::const_iterator i=keep_packages.begin(); + i!=keep_packages.end(); ++i) + { + Gtk::TreeModel::iterator iter = store->append(parent_row.children()); + Gtk::TreeModel::Row row = *iter; + if(i->CurrentVer().end()) + { + row[pResolverView->resolver_columns.Name] = i->Name(); + row[pResolverView->resolver_columns.Action] = ssprintf("[%s]", + _("Not Installed")); + } + else + { + row[pResolverView->resolver_columns.Name] = i->Name(); + row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s)]", + i->CurrentVer().VerStr(), + archives_text(i->CurrentVer()).c_str()); + } + } + } + + if(!upgrade_packages.empty()) + { + Gtk::TreeModel::iterator parent_iter = store->append(); + Gtk::TreeModel::Row parent_row = *parent_iter; + parent_row[pResolverView->resolver_columns.Name] = _("Upgrade the following packages:"); + for(vector<pkgCache::VerIterator>::const_iterator i=upgrade_packages.begin(); + i!=upgrade_packages.end(); ++i) + { + Gtk::TreeModel::iterator iter = store->append(parent_row.children()); + Gtk::TreeModel::Row row = *iter; + row[pResolverView->resolver_columns.Name] = i->ParentPkg().Name(); + row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s) -> %s (%s)]", + i->ParentPkg().CurrentVer().VerStr(), + archives_text(i->ParentPkg().CurrentVer()).c_str(), + i->VerStr(), + archives_text(*i).c_str()); + } + } + + if(!downgrade_packages.empty()) + { + Gtk::TreeModel::iterator parent_iter = store->append(); + Gtk::TreeModel::Row parent_row = *parent_iter; + parent_row[pResolverView->resolver_columns.Name] = _("Downgrade the following packages:"); + for(vector<pkgCache::VerIterator>::const_iterator i=downgrade_packages.begin(); + i!=downgrade_packages.end(); ++i) + { + Gtk::TreeModel::iterator iter = store->append(parent_row.children()); + Gtk::TreeModel::Row row = *iter; + row[pResolverView->resolver_columns.Name] = i->ParentPkg().Name(); + row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s) -> %s (%s)]", + i->ParentPkg().CurrentVer().VerStr(), + archives_text(i->ParentPkg().CurrentVer()).c_str(), + i->VerStr(), + archives_text(*i).c_str()); + } + } + + const imm::set<aptitude_universe::dep> &unresolved = sol.get_unresolved_soft_deps(); + + if(!unresolved.empty()) + { + Gtk::TreeModel::iterator parent_iter = store->append(); + Gtk::TreeModel::Row parent_row = *parent_iter; + parent_row[pResolverView->resolver_columns.Name] = _("Leave the following dependencies unresolved:"); + for(imm::set<aptitude_universe::dep>::const_iterator i = unresolved.begin(); + i != unresolved.end(); ++i) + { + Gtk::TreeModel::iterator iter = store->append(parent_row.children()); + Gtk::TreeModel::Row row = *iter; + row[pResolverView->resolver_columns.Name] = cwidget::util::transcode(dep_text((*i).get_dep()).c_str(), "UTF-8"); + row[pResolverView->resolver_columns.Action] = ""; + } + } + } + + return store; + } + void ResolverTab::update_from_state(const resolver_manager::state &state) { Glib::RefPtr<Gtk::TreeStore> store = Gtk::TreeStore::create(pResolverView->resolver_columns); @@ -338,179 +517,7 @@ namespace gui last_sol = sol; - 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 - { - // Bin packages according to what will happen to them. - vector<pkgCache::PkgIterator> remove_packages; - vector<pkgCache::PkgIterator> keep_packages; - vector<pkgCache::VerIterator> install_packages; - vector<pkgCache::VerIterator> downgrade_packages; - vector<pkgCache::VerIterator> upgrade_packages; - - for(imm::map<aptitude_universe::package, - generic_solution<aptitude_universe>::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_packages.push_back(pkg); - else - install_packages.push_back(newver); - } - else if(newver.end()) - remove_packages.push_back(pkg); - else if(newver == curver) - keep_packages.push_back(pkg); - else - { - int cmp=_system->VS->CmpVersion(curver.VerStr(), - newver.VerStr()); - - // The versions shouldn't be equal -- otherwise - // something is majorly wrong. - // eassert(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_packages.push_back(newver); - else if(cmp>0) - downgrade_packages.push_back(newver); - } - } - - sort(remove_packages.begin(), remove_packages.end(), pkg_name_lt()); - sort(keep_packages.begin(), keep_packages.end(), pkg_name_lt()); - sort(install_packages.begin(), install_packages.end(), ver_name_lt()); - sort(downgrade_packages.begin(), downgrade_packages.end(), ver_name_lt()); - sort(upgrade_packages.begin(), upgrade_packages.end(), ver_name_lt()); - - if(!remove_packages.empty()) - { - Gtk::TreeModel::iterator parent_iter = store->append(); - Gtk::TreeModel::Row parent_row = *parent_iter; - parent_row[pResolverView->resolver_columns.Name] = _("Remove the following packages:"); - for(vector<pkgCache::PkgIterator>::const_iterator i=remove_packages.begin(); - i!=remove_packages.end(); ++i) - { - Gtk::TreeModel::iterator iter = store->append(parent_row.children()); - Gtk::TreeModel::Row row = *iter; - row[pResolverView->resolver_columns.Name] = i->Name(); - row[pResolverView->resolver_columns.Action] = ""; - } - } - - if(!install_packages.empty()) - { - Gtk::TreeModel::iterator parent_iter = store->append(); - Gtk::TreeModel::Row parent_row = *parent_iter; - parent_row[pResolverView->resolver_columns.Name] = _("Install the following packages:"); - for(vector<pkgCache::VerIterator>::const_iterator i=install_packages.begin(); - i!=install_packages.end(); ++i) - { - Gtk::TreeModel::iterator iter = store->append(parent_row.children()); - Gtk::TreeModel::Row row = *iter; - row[pResolverView->resolver_columns.Name] = i->ParentPkg().Name(); - row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s)]", - i->VerStr(), - archives_text(*i).c_str()); - } - } - - if(!keep_packages.empty()) - { - Gtk::TreeModel::iterator parent_iter = store->append(); - Gtk::TreeModel::Row parent_row = *parent_iter; - parent_row[pResolverView->resolver_columns.Name] = _("Keep the following packages:"); - for(vector<pkgCache::PkgIterator>::const_iterator i=keep_packages.begin(); - i!=keep_packages.end(); ++i) - { - Gtk::TreeModel::iterator iter = store->append(parent_row.children()); - Gtk::TreeModel::Row row = *iter; - if(i->CurrentVer().end()) - { - row[pResolverView->resolver_columns.Name] = i->Name(); - row[pResolverView->resolver_columns.Action] = ssprintf("[%s]", - _("Not Installed")); - } - else - { - row[pResolverView->resolver_columns.Name] = i->Name(); - row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s)]", - i->CurrentVer().VerStr(), - archives_text(i->CurrentVer()).c_str()); - } - } - } - - if(!upgrade_packages.empty()) - { - Gtk::TreeModel::iterator parent_iter = store->append(); - Gtk::TreeModel::Row parent_row = *parent_iter; - parent_row[pResolverView->resolver_columns.Name] = _("Upgrade the following packages:"); - for(vector<pkgCache::VerIterator>::const_iterator i=upgrade_packages.begin(); - i!=upgrade_packages.end(); ++i) - { - Gtk::TreeModel::iterator iter = store->append(parent_row.children()); - Gtk::TreeModel::Row row = *iter; - row[pResolverView->resolver_columns.Name] = i->ParentPkg().Name(); - row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s) -> %s (%s)]", - i->ParentPkg().CurrentVer().VerStr(), - archives_text(i->ParentPkg().CurrentVer()).c_str(), - i->VerStr(), - archives_text(*i).c_str()); - } - } - - if(!downgrade_packages.empty()) - { - Gtk::TreeModel::iterator parent_iter = store->append(); - Gtk::TreeModel::Row parent_row = *parent_iter; - parent_row[pResolverView->resolver_columns.Name] = _("Downgrade the following packages:"); - for(vector<pkgCache::VerIterator>::const_iterator i=downgrade_packages.begin(); - i!=downgrade_packages.end(); ++i) - { - Gtk::TreeModel::iterator iter = store->append(parent_row.children()); - Gtk::TreeModel::Row row = *iter; - row[pResolverView->resolver_columns.Name] = i->ParentPkg().Name(); - row[pResolverView->resolver_columns.Action] = ssprintf("[%s (%s) -> %s (%s)]", - i->ParentPkg().CurrentVer().VerStr(), - archives_text(i->ParentPkg().CurrentVer()).c_str(), - i->VerStr(), - archives_text(*i).c_str()); - } - } - - const imm::set<aptitude_universe::dep> &unresolved = sol.get_unresolved_soft_deps(); - - if(!unresolved.empty()) - { - Gtk::TreeModel::iterator parent_iter = store->append(); - Gtk::TreeModel::Row parent_row = *parent_iter; - parent_row[pResolverView->resolver_columns.Name] = _("Leave the following dependencies unresolved:"); - for(imm::set<aptitude_universe::dep>::const_iterator i = unresolved.begin(); - i != unresolved.end(); ++i) - { - Gtk::TreeModel::iterator iter = store->append(parent_row.children()); - Gtk::TreeModel::Row row = *iter; - row[pResolverView->resolver_columns.Name] = cwidget::util::transcode(dep_text((*i).get_dep()).c_str(), "UTF-8"); - row[pResolverView->resolver_columns.Action] = ""; - } - } - } + store = render_as_action_groups(sol); } pResolverView->set_model(store); diff --git a/src/gtk/resolver.h b/src/gtk/resolver.h index 60db3736..0f461b9e 100644 --- a/src/gtk/resolver.h +++ b/src/gtk/resolver.h @@ -2,7 +2,7 @@ // resolver.h // -// Copyright 1999-2008 Daniel Burrows +// Copyright 1999-2009 Daniel Burrows // Copyright 2008 Obey Arthur Liu // // This program is free software; you can redistribute it and/or modify @@ -59,12 +59,12 @@ namespace gui Gtk::TreeViewColumn * treeview_column, Gtk::TreeModelColumn<ColumnType>& model_column, int size); + public: Glib::RefPtr<Gtk::TreeStore> resolver_store; ResolverColumns resolver_columns; ResolverView(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& refGlade); - void createstore(); }; class ResolverTab : public Tab @@ -85,6 +85,15 @@ namespace gui // rebuilding the tree if the solution didn't actually change. aptitude_solution last_sol; + /** \brief Create a new, empty tree store with the correct columns + * for the resolver view. + */ + Glib::RefPtr<Gtk::TreeStore> createstore(); + /** \brief Create a new tree store and populate it with thge given + * solution, rendered with actions collected by type. + */ + Glib::RefPtr<Gtk::TreeStore> render_as_action_groups(const aptitude_solution &sol); + std::string archives_text(const pkgCache::VerIterator &ver); std::string dep_targets(const pkgCache::DepIterator &start); std::wstring dep_text(const pkgCache::DepIterator &d); |