source: projects/synaptic/trunk/common/rpackageview.h @ 280

Revision 280, 4.7 KB checked in by yasumichi, 13 years ago (diff)

first import

Line 
1/* rpackageview.h - Package sectioning system
2 *
3 * Copyright (c) 2004 Conectiva S/A
4 *               2004 Michael Vogt <mvo@debian.org>
5 *
6 * Author: Gustavo Niemeyer
7 *         Michael Vogt <mvo@debian.org>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 * USA
23 */
24
25
26#ifndef RPACKAGEVIEW_H
27#define RPACKAGEVIEW_H
28
29#include <string>
30#include <map>
31
32#include "rpackage.h"
33#include "rpackagefilter.h"
34
35#include "i18n.h"
36
37using namespace std;
38
39struct RFilter;
40
41enum {PACKAGE_VIEW_SECTION,
42      PACKAGE_VIEW_STATUS,
43      PACKAGE_VIEW_CUSTOM,
44      PACKAGE_VIEW_SEARCH,
45      N_PACKAGE_VIEWS
46};
47
48class RPackageView {
49 protected:
50
51   map<string, vector<RPackage *> > _view;
52
53   bool _hasSelection;
54   string _selectedName;
55
56   // packages in selected
57   vector<RPackage *> _selectedView;
58
59   // all packages in current global filter
60   vector<RPackage *> &_all;
61
62 public:
63   RPackageView(vector<RPackage *> &allPackages): _all(allPackages) {};
64   virtual ~RPackageView() {};
65
66   bool hasSelection() { return _hasSelection; };
67   string getSelected() { return _selectedName; };
68   bool setSelected(string name);
69   void showAll() { 
70      _selectedView = _all; 
71      _hasSelection = false;
72      _selectedName.clear();
73   };
74
75   vector<string> getSubViews();
76
77   virtual string getName() = 0;
78   virtual void addPackage(RPackage *package) = 0;
79
80   typedef vector<RPackage *>::iterator iterator;
81
82   virtual iterator begin() { return _selectedView.begin(); };
83   virtual iterator end() { return _selectedView.end(); };
84
85   virtual void clear();
86   virtual void clearSelection();
87};
88
89
90
91class RPackageViewSections : public RPackageView {
92 public:
93   RPackageViewSections(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {};
94
95   string getName() {
96      return _("Sections");
97   };
98
99   void addPackage(RPackage *package);
100};
101
102class RPackageViewAlphabetic : public RPackageView {
103 public:
104   RPackageViewAlphabetic(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {};
105   string getName() {
106      return _("Alphabetic");
107   };
108
109   void addPackage(RPackage *package) {
110      char letter[2] = { ' ', '\0' };
111      letter[0] = toupper(package->name()[0]);
112      _view[letter].push_back(package);
113   };
114};
115
116class RPackageViewStatus:public RPackageView {
117 protected:
118   // mark the software as unsupported in status view
119   bool markUnsupported;
120   vector<string> supportedComponents;
121
122 public:
123   RPackageViewStatus(vector<RPackage *> &allPkgs);
124
125   string getName() {
126      return _("Status");
127   };
128
129   void addPackage(RPackage *package);
130};
131
132class RPackageViewSearch : public RPackageView {
133 protected:
134   vector<string> searchStrings;
135   string searchName;
136   int searchType;
137   int found; // nr of found pkgs for the last search
138 public:
139   RPackageViewSearch(vector<RPackage *> &allPkgs) 
140      : RPackageView(allPkgs), found(0) {};
141
142   int setSearch(string searchName, int type, string searchString);
143
144   string getName() {
145      return _("Search History");
146   };
147
148   void addPackage(RPackage *package);
149};
150
151
152class RPackageViewFilter : public RPackageView {
153 protected:
154   vector<RFilter *> _filterL;
155   set<string> _sectionList;   // list of all available package sections
156
157 public:
158   void storeFilters();
159   void restoreFilters();
160   // called after the filtereditor was run
161   void refreshFilters();
162
163   bool registerFilter(RFilter *filter);
164   void unregisterFilter(RFilter *filter);
165
166   void makePresetFilters();
167
168   RFilter* findFilter(string name);
169   unsigned int nrOfFilters() { return _filterL.size(); };
170   RFilter *findFilter(unsigned int index) {
171      if (index > _filterL.size())
172         return NULL;
173      else
174         return _filterL[index];
175   };
176
177   // used by kynaptic
178   int getFilterIndex(RFilter *filter);
179
180   vector<string> getFilterNames();
181   const set<string> &getSections() { return _sectionList; };
182
183   RPackageViewFilter(vector<RPackage *> &allPkgs);
184
185   // build packages list on "demand"
186   virtual iterator begin();
187
188   // we never need to clear because we build the view "on-demand"
189   virtual void clear() {clearSelection();};
190
191   string getName() {
192      return _("Custom");
193   };
194
195   void addPackage(RPackage *package);
196};
197
198
199
200#endif
201
202// vim:sts=3:sw=3
Note: See TracBrowser for help on using the repository browser.