~ubuntu-core-dev/synaptic/ubuntu

« back to all changes in this revision

Viewing changes to common/rpackageview.h

  • Committer: Michael Terry
  • Date: 2011-09-26 16:30:35 UTC
  • Revision ID: michael.terry@canonical.com-20110926163035-bck8ol261ksu1gmi
move to lp:ubuntu/synaptic

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
#ifdef WITH_EPT
33
 
#include <ept/axi/axi.h>
34
 
#endif
35
 
 
36
 
#include "rpackage.h"
37
 
#include "rpackagefilter.h"
38
 
 
39
 
#include "i18n.h"
40
 
 
41
 
using namespace std;
42
 
 
43
 
struct RFilter;
44
 
 
45
 
enum {PACKAGE_VIEW_SECTION,
46
 
      PACKAGE_VIEW_STATUS,
47
 
      PACKAGE_VIEW_ORIGIN,
48
 
      PACKAGE_VIEW_CUSTOM,
49
 
      PACKAGE_VIEW_SEARCH,
50
 
      N_PACKAGE_VIEWS
51
 
};
52
 
 
53
 
class RPackageView {
54
 
 protected:
55
 
 
56
 
   map<string, vector<RPackage *> > _view;
57
 
 
58
 
   bool _hasSelection;
59
 
   string _selectedName;
60
 
 
61
 
   // packages in selected
62
 
   vector<RPackage *> _selectedView;
63
 
 
64
 
   // all packages in current global filter
65
 
   vector<RPackage *> &_all;
66
 
 
67
 
 public:
68
 
   RPackageView(vector<RPackage *> &allPackages): _all(allPackages) {};
69
 
   virtual ~RPackageView() {};
70
 
 
71
 
   bool hasSelection() { return _hasSelection; };
72
 
   string getSelected() { return _selectedName; };
73
 
   bool hasPackage(RPackage *pkg);
74
 
   virtual bool setSelected(string name);
75
 
 
76
 
   void showAll() { 
77
 
      _selectedView = _all; 
78
 
      _hasSelection = false;
79
 
      _selectedName.clear();
80
 
   };
81
 
 
82
 
   virtual vector<string> getSubViews();
83
 
 
84
 
   virtual string getName() = 0;
85
 
   virtual void addPackage(RPackage *package) = 0;
86
 
 
87
 
   typedef vector<RPackage *>::iterator iterator;
88
 
 
89
 
   virtual iterator begin() { return _selectedView.begin(); };
90
 
   virtual iterator end() { return _selectedView.end(); };
91
 
 
92
 
   virtual void clear();
93
 
   virtual void clearSelection();
94
 
 
95
 
   virtual void refresh();
96
 
};
97
 
 
98
 
 
99
 
 
100
 
class RPackageViewSections : public RPackageView {
101
 
 public:
102
 
   RPackageViewSections(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {};
103
 
 
104
 
   string getName() {
105
 
      return _("Sections");
106
 
   };
107
 
 
108
 
   void addPackage(RPackage *package);
109
 
};
110
 
 
111
 
class RPackageViewAlphabetic : public RPackageView {
112
 
 public:
113
 
   RPackageViewAlphabetic(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {};
114
 
   string getName() {
115
 
      return _("Alphabetic");
116
 
   };
117
 
 
118
 
   void addPackage(RPackage *package) {
119
 
      char letter[2] = { ' ', '\0' };
120
 
      letter[0] = toupper(package->name()[0]);
121
 
      _view[letter].push_back(package);
122
 
   };
123
 
};
124
 
 
125
 
class RPackageViewOrigin : public RPackageView {
126
 
 public:
127
 
   RPackageViewOrigin(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {};
128
 
   string getName() {
129
 
      return _("Origin");
130
 
   };
131
 
 
132
 
   void addPackage(RPackage *package);
133
 
};
134
 
 
135
 
class RPackageViewStatus:public RPackageView {
136
 
 protected:
137
 
   // mark the software as unsupported in status view
138
 
   bool markUnsupported;
139
 
   vector<string> supportedComponents;
140
 
 
141
 
 public:
142
 
   RPackageViewStatus(vector<RPackage *> &allPkgs);
143
 
 
144
 
   string getName() {
145
 
      return _("Status");
146
 
   };
147
 
 
148
 
   void addPackage(RPackage *package);
149
 
};
150
 
 
151
 
class RPackageViewSearch : public RPackageView {
152
 
   struct searchItem {
153
 
      vector<string> searchStrings;
154
 
      string searchName;
155
 
      int searchType;
156
 
   };
157
 
   // the search history
158
 
   map<string, searchItem> searchHistory;
159
 
   searchItem _currentSearchItem;
160
 
   int found; // nr of found pkgs for the last search
161
 
 
162
 
   bool xapianSearch();
163
 
 
164
 
 public:
165
 
 RPackageViewSearch(vector<RPackage *> &allPkgs) 
166
 
    : RPackageView(allPkgs), found(0) {};
167
 
 
168
 
   int setSearch(string searchName, int type, string searchString, 
169
 
                 OpProgress &searchProgress);
170
 
 
171
 
   string getName() {
172
 
      return _("Search History");
173
 
   };
174
 
 
175
 
   // return search history here
176
 
   virtual vector<string> getSubViews();
177
 
   virtual bool setSelected(string name);
178
 
 
179
 
   void addPackage(RPackage *package);
180
 
 
181
 
   // no-op
182
 
   virtual void refresh() {};
183
 
};
184
 
 
185
 
 
186
 
class RPackageViewFilter : public RPackageView {
187
 
 protected:
188
 
   vector<RFilter *> _filterL;
189
 
   set<string> _sectionList;   // list of all available package sections
190
 
 
191
 
 public:
192
 
   void storeFilters();
193
 
   void restoreFilters();
194
 
   // called after the filtereditor was run
195
 
   void refreshFilters();
196
 
   void refresh();
197
 
 
198
 
   bool registerFilter(RFilter *filter);
199
 
   void unregisterFilter(RFilter *filter);
200
 
 
201
 
   void makePresetFilters();
202
 
 
203
 
   RFilter* findFilter(string name);
204
 
   unsigned int nrOfFilters() { return _filterL.size(); };
205
 
   RFilter *findFilter(unsigned int index) {
206
 
      if (index > _filterL.size())
207
 
         return NULL;
208
 
      else
209
 
         return _filterL[index];
210
 
   };
211
 
 
212
 
   // used by kynaptic
213
 
   int getFilterIndex(RFilter *filter);
214
 
 
215
 
   vector<string> getFilterNames();
216
 
   const set<string> &getSections();
217
 
 
218
 
   RPackageViewFilter(vector<RPackage *> &allPkgs);
219
 
 
220
 
   // build packages list on "demand"
221
 
   virtual iterator begin();
222
 
 
223
 
   // we never need to clear because we build the view "on-demand"
224
 
   virtual void clear() {clearSelection();};
225
 
 
226
 
   string getName() {
227
 
      return _("Custom");
228
 
   };
229
 
 
230
 
   void addPackage(RPackage *package);
231
 
};
232
 
 
233
 
#endif
234
 
 
235
 
// vim:sts=3:sw=3