This is the mail archive of the
cygwin-apps
mailing list for the Cygwin project.
[PATCH 1/2] Push the implementation of defaultTrust() down from the PickView class to packagedb class
- From: Jon TURNEY <jon dot turney at dronecode dot org dot uk>
- To: cygwin-apps at cygwin dot com
- Cc: Jon TURNEY <jon dot turney at dronecode dot org dot uk>
- Date: Fri, 22 Jul 2011 14:22:31 +0100
- Subject: [PATCH 1/2] Push the implementation of defaultTrust() down from the PickView class to packagedb class
- References: <1311340952-3288-1-git-send-email-jon.turney@dronecode.org.uk>
I can't see why this implementation doesn't belong in the db object, not the UI object
Also: reading the code, the "remove catagories with no package" code looks wrong. It tries
to avoid having an invalid iterator after the erase() by preincrementing it, but this means it
is double incremented, so if there are 2 adjacent categories with no packages, only the first
will get removed. But this code doesn't belong here anyhow, it should be done, once, after
we've built the packagedb.
Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk>
2011-07-21 Jon TURNEY <jon.turney@dronecode.org.uk>
* PickView.cc (defaultTrust): Move implementation which deals with
package db from here...
* package_db.cc (defaultTrust): ... to here.
* package_db.h (packagedb): ... a new member function.
---
PickView.cc | 28 ++++------------------------
package_db.cc | 27 +++++++++++++++++++++++++++
package_db.h | 4 ++++
3 files changed, 35 insertions(+), 24 deletions(-)
diff --git a/PickView.cc b/PickView.cc
index 27e53c2..f153e48 100644
--- a/PickView.cc
+++ b/PickView.cc
@@ -971,33 +971,13 @@ void
PickView::defaultTrust (trusts trust)
{
this->deftrust = trust;
+
packagedb db;
- for (packagedb::packagecollection::iterator i = db.packages.begin ();
- i != db.packages.end (); ++i)
- {
- packagemeta & pkg = *(i->second);
- if (pkg.installed
- || pkg.categories.find ("Base") != pkg.categories.end ()
- || pkg.categories.find ("Misc") != pkg.categories.end ())
- {
- pkg.desired = pkg.trustp (trust);
- if (pkg.desired)
- pkg.desired.pick (pkg.desired.accessible() &&
- pkg.desired != pkg.installed, &pkg);
- }
- else
- pkg.desired = packageversion ();
- }
+ db.defaultTrust(trust);
+
+ // force the picker to redraw
RECT r = GetClientRect ();
InvalidateRect (this->GetHWND(), &r, TRUE);
- // and then do the same for categories with no packages.
- for (packagedb::categoriesType::iterator n = packagedb::categories.begin();
- n != packagedb::categories.end(); ++n)
- if (!n->second.size())
- {
- log (LOG_BABBLE) << "Removing empty category " << n->first << endLog;
- packagedb::categories.erase (n++);
- }
}
/* This recalculates all column widths and resets the view */
diff --git a/package_db.cc b/package_db.cc
index f853824..8c8644f 100644
--- a/package_db.cc
+++ b/package_db.cc
@@ -425,3 +425,30 @@ packagedb::fillMissingCategory ()
}
}
+void
+packagedb::defaultTrust (trusts trust)
+{
+ for (packagedb::packagecollection::iterator i = packages.begin (); i != packages.end (); ++i)
+ {
+ packagemeta & pkg = *(i->second);
+ if (pkg.installed
+ || pkg.categories.find ("Base") != pkg.categories.end ()
+ || pkg.categories.find ("Misc") != pkg.categories.end ())
+ {
+ pkg.desired = pkg.trustp (trust);
+ if (pkg.desired)
+ pkg.desired.pick (pkg.desired.accessible() && pkg.desired != pkg.installed, &pkg);
+ }
+ else
+ pkg.desired = packageversion ();
+ }
+
+ // side effect, remove categories with no packages.
+ for (packagedb::categoriesType::iterator n = packagedb::categories.begin();
+ n != packagedb::categories.end(); ++n)
+ if (!n->second.size())
+ {
+ log (LOG_BABBLE) << "Removing empty category " << n->first << endLog;
+ packagedb::categories.erase (n++);
+ }
+}
diff --git a/package_db.h b/package_db.h
index fe1ec4c..bc828a1 100644
--- a/package_db.h
+++ b/package_db.h
@@ -56,6 +56,9 @@ typedef std::vector <packagemeta *>::iterator PackageDBConnectedIterator;
task or root path any later in the execution sequence.
*/
+
+#include <PackageTrust.h>
+
class packagedb
{
public:
@@ -67,6 +70,7 @@ public:
PackageDBConnectedIterator connectedBegin();
PackageDBConnectedIterator connectedEnd();
void fillMissingCategory();
+ void defaultTrust (trusts trust);
void markUnVisited();
void setExistence();
typedef std::map <std::string, packagemeta *> packagecollection;
--
1.7.5.1