Add a more generic mbox wrapper
[cygwin-setup.git] / PickView.h
blob1e14a74e88f8b3e286d1e49b5d4ddc7d8e3b5bd0
1 /*
2 * Copyright (c) 2002 Robert Collins.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * A copy of the GNU General Public License can be found at
10 * http://www.gnu.org/
12 * Written by Robert Collins <robertc@hotmail.com>
16 #ifndef SETUP_PICKVIEW_H
17 #define SETUP_PICKVIEW_H
19 #include <string>
21 #include "package_meta.h"
22 #include "ListView.h"
24 class Window;
25 class CategoryTree;
27 class PickView
29 public:
30 trusts deftrust; // XXX: needs accessor
32 enum class views
34 PackageFull = 0,
35 PackagePending,
36 PackageKeeps,
37 PackageSkips,
38 PackageUserPicked,
39 Category,
42 PickView ();
43 ~PickView();
44 void defaultTrust (trusts trust);
45 void setViewMode (views mode);
46 views getViewMode ();
47 void init(views _mode, ListView *_listview, Window *parent);
48 void build_category_tree();
49 static unsigned int mode_caption (views mode);
50 void setObsolete (bool doit);
51 void refresh();
52 void init_headers ();
54 void SetPackageFilter (const std::string &filterString)
56 packageFilterString = filterString;
59 Window *GetParent(void) { return parent; }
61 private:
62 views view_mode;
63 ListView *listview;
64 bool showObsolete;
65 std::string packageFilterString;
66 ListViewContents contents;
67 CategoryTree *cat_tree_root;
68 Window *parent;
70 void insert_pkg (packagemeta &, int indent = 0);
71 void insert_category (CategoryTree *);
74 // column numbers, must match index into pkg_headers[]
75 enum
77 pkgname_col = 0, // package/category name
78 current_col = 1,
79 new_col = 2, // action
80 srctick_col = 3,
81 cat_col = 4,
82 size_col = 5,
83 pkg_col = 6 // desc
86 bool isObsolete (std::set <std::string, casecompare_lt_op> &categories);
87 bool isObsolete (const std::string& catname);
90 // Helper class which stores the contents and collapsed/expanded state for each
91 // category (and the pseudo-category 'All')
94 class CategoryTree
96 public:
97 CategoryTree(Category & cat, bool collapsed) :
98 _cat (cat),
99 _collapsed(collapsed),
100 _action (packagemeta::NoChange_action)
104 ~CategoryTree()
108 std::vector <CategoryTree *> & bucket()
110 return _bucket;
113 bool &collapsed()
115 return _collapsed;
118 const Category &category()
120 return _cat;
123 packagemeta::_actions & action()
125 return _action;
128 int do_action(packagemeta::_actions action_id, trusts const deftrust)
130 int u = 1;
131 _action = action_id;
133 if (_bucket.size())
135 for (std::vector <CategoryTree *>::const_iterator i = _bucket.begin();
136 i != _bucket.end();
137 i++)
139 // recurse for all contained non-obsolete categories
140 if (isObsolete((*i)->_cat.first))
141 continue;
143 int l = (*i)->do_action(action_id, deftrust);
145 if (!_collapsed)
146 u += l;
149 else
151 // otherwise, this is a leaf category, so apply action to all packages
152 // in this category
153 int l = 0;
154 for (std::vector <packagemeta *>::const_iterator pkg = _cat.second.begin();
155 pkg != _cat.second.end();
156 ++pkg)
158 (*pkg)->select_action(action_id, deftrust);
159 l++;
162 // these lines need to be updated, if displayed
163 if (!_collapsed)
164 u += l;
166 return u;
169 private:
170 Category & _cat;
171 bool _collapsed;
172 std::vector <CategoryTree *> _bucket;
173 packagemeta::_actions _action;
176 #endif /* SETUP_PICKVIEW_H */