Translated using Weblate (Chinese (Simplified))
[cygwin-setup.git] / PickView.h
blob483341415e079382f1ce7486675faf78425aa71c
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 PackageRemovable,
40 PackageUnneeded,
41 Category,
44 PickView ();
45 ~PickView();
46 void defaultTrust (trusts trust);
47 void setViewMode (views mode);
48 views getViewMode ();
49 void init(views _mode, ListView *_listview, Window *parent);
50 void build_category_tree();
51 static unsigned int mode_caption (views mode);
52 void setObsolete (bool doit);
53 void refresh();
54 void init_headers ();
56 void SetPackageFilter (const std::string &filterString)
58 packageFilterString = filterString;
61 Window *GetParent(void) { return parent; }
63 private:
64 views view_mode;
65 ListView *listview;
66 bool showObsolete;
67 std::string packageFilterString;
68 ListViewContents contents;
69 CategoryTree *cat_tree_root;
70 Window *parent;
72 void insert_pkg (packagemeta &, int indent = 0);
73 void insert_category (CategoryTree *);
76 // column numbers, must match index into pkg_headers[]
77 enum
79 pkgname_col = 0, // package/category name
80 current_col = 1,
81 new_col = 2, // action
82 srctick_col = 3,
83 cat_col = 4,
84 size_col = 5,
85 pkg_col = 6 // desc
88 bool isObsolete (std::set <std::string, casecompare_lt_op> &categories);
89 bool isObsolete (const std::string& catname);
92 // Helper class which stores the contents and collapsed/expanded state for each
93 // category (and the pseudo-category 'All')
96 class CategoryTree
98 public:
99 CategoryTree(Category & cat, bool collapsed) :
100 _cat (cat),
101 _collapsed(collapsed),
102 _action (packagemeta::NoChange_action)
106 ~CategoryTree()
110 std::vector <CategoryTree *> & bucket()
112 return _bucket;
115 bool &collapsed()
117 return _collapsed;
120 const Category &category()
122 return _cat;
125 packagemeta::_actions & action()
127 return _action;
130 int do_action(packagemeta::_actions action_id, trusts const deftrust)
132 int u = 1;
133 _action = action_id;
135 if (_bucket.size())
137 for (std::vector <CategoryTree *>::const_iterator i = _bucket.begin();
138 i != _bucket.end();
139 i++)
141 // recurse for all contained non-obsolete categories
142 if (isObsolete((*i)->_cat.first))
143 continue;
145 int l = (*i)->do_action(action_id, deftrust);
147 if (!_collapsed)
148 u += l;
151 else
153 // otherwise, this is a leaf category, so apply action to all packages
154 // in this category
155 int l = 0;
156 for (std::vector <packagemeta *>::const_iterator pkg = _cat.second.begin();
157 pkg != _cat.second.end();
158 ++pkg)
160 (*pkg)->select_action(action_id, deftrust);
161 l++;
164 // these lines need to be updated, if displayed
165 if (!_collapsed)
166 u += l;
168 return u;
171 private:
172 Category & _cat;
173 bool _collapsed;
174 std::vector <CategoryTree *> _bucket;
175 packagemeta::_actions _action;
178 #endif /* SETUP_PICKVIEW_H */