File: rpackageview.h

package info (click to toggle)
synaptic 0.91.7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,676 kB
  • sloc: cpp: 19,830; xml: 10,562; ansic: 2,084; makefile: 498; sed: 93; python: 82; sh: 52
file content (247 lines) | stat: -rw-r--r-- 5,843 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
/* rpackageview.h - Package sectioning system
 *
 * Copyright (c) 2004 Conectiva S/A
 *               2004 Michael Vogt <mvo@debian.org>
 *
 * Author: Gustavo Niemeyer
 *         Michael Vogt <mvo@debian.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */


#ifndef RPACKAGEVIEW_H
#define RPACKAGEVIEW_H

#include <string>
#include <map>

#ifdef WITH_EPT
#include <ept/axi/axi.h>
#endif

#include "rpackage.h"
#include "rpackagefilter.h"

#include "i18n.h"

using namespace std;

struct RFilter;

enum {PACKAGE_VIEW_SECTION,
      PACKAGE_VIEW_STATUS,
      PACKAGE_VIEW_ORIGIN,
      PACKAGE_VIEW_CUSTOM,
      PACKAGE_VIEW_SEARCH,
      PACKAGE_VIEW_ARCHITECTURE,
      N_PACKAGE_VIEWS
};

class RPackageView {
 protected:

   map<string, vector<RPackage *> > _view;

   bool _hasSelection;
   string _selectedName;

   // packages in selected
   vector<RPackage *> _selectedView;

   // all packages in current global filter
   vector<RPackage *> &_all;

 public:
   RPackageView(vector<RPackage *> &allPackages): _all(allPackages) {}
   virtual ~RPackageView() {}

   bool hasSelection() { return _hasSelection; }
   string getSelected() { return _selectedName; }
   bool hasPackage(RPackage *pkg);
   virtual bool setSelected(string name);

   void showAll() {
      _selectedView = _all;
      _hasSelection = false;
      _selectedName.clear();
   }

   virtual vector<string> getSubViews();

   virtual string getName() = 0;
   virtual void addPackage(RPackage *package) = 0;

   typedef vector<RPackage *>::iterator iterator;

   virtual iterator begin() { return _selectedView.begin(); }
   virtual iterator end() { return _selectedView.end(); }

   virtual void clear();
   virtual void clearSelection();

   virtual void refresh();
};



class RPackageViewSections : public RPackageView {
 public:
   RPackageViewSections(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {}

   string getName() {
      return _("Sections");
   };

   void addPackage(RPackage *package);
};

class RPackageViewAlphabetic : public RPackageView {
 public:
   RPackageViewAlphabetic(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {}
   string getName() {
      return _("Alphabetic");
   }

   void addPackage(RPackage *package) {
      char letter[2] = { ' ', '\0' };
      letter[0] = toupper(package->name()[0]);
      _view[letter].push_back(package);
   }
};

class RPackageViewArchitecture : public RPackageView {
 public:
   RPackageViewArchitecture(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {}
   string getName() {
      return _("Architecture");
   }

   void addPackage(RPackage *package);
};

class RPackageViewOrigin : public RPackageView {
 public:
   RPackageViewOrigin(vector<RPackage *> &allPkgs) : RPackageView(allPkgs) {}
   string getName() {
      return _("Origin");
   }

   void addPackage(RPackage *package);
};

class RPackageViewStatus:public RPackageView {
 protected:
   // mark the software as unsupported in status view
   bool markUnsupported;
   vector<string> supportedComponents;

 public:
   RPackageViewStatus(vector<RPackage *> &allPkgs);

   string getName() {
      return _("Status");
   }

   void addPackage(RPackage *package);
};

class RPackageViewSearch : public RPackageView {
   struct searchItem {
      vector<string> searchStrings;
      string searchName;
      int searchType;
   };
   // the search history
   map<string, searchItem> searchHistory;
   searchItem _currentSearchItem;
   int found; // nr of found pkgs for the last search

   bool xapianSearch();

 public:
 RPackageViewSearch(vector<RPackage *> &allPkgs)
    : RPackageView(allPkgs), found(0) {}

   int setSearch(string searchName, int type, string searchString,
		 OpProgress &searchProgress);

   string getName() {
      return _("Search History");
   }

   // return search history here
   virtual vector<string> getSubViews();
   virtual bool setSelected(string name);

   void addPackage(RPackage *package);

   // no-op
   virtual void refresh() {}
};


class RPackageViewFilter : public RPackageView {
 protected:
   vector<RFilter *> _filterL;
   set<string> _sectionList;   // list of all available package sections

 public:
   void storeFilters();
   void restoreFilters();
   // called after the filtereditor was run
   void refreshFilters();
   void refresh();

   bool registerFilter(RFilter *filter);
   void unregisterFilter(RFilter *filter);

   void makePresetFilters();

   RFilter* findFilter(string name);
   unsigned int nrOfFilters() { return _filterL.size(); }
   RFilter *findFilter(unsigned int index) {
      if (index > _filterL.size())
         return NULL;
      else
         return _filterL[index];
   }

   // used by kynaptic
   int getFilterIndex(RFilter *filter);

   vector<string> getFilterNames();
   const set<string> &getSections();

   RPackageViewFilter(vector<RPackage *> &allPkgs);

   // build packages list on "demand"
   virtual iterator begin();

   // we never need to clear because we build the view "on-demand"
   virtual void clear() { clearSelection(); }

   string getName() {
      return _("Custom");
   }

   void addPackage(RPackage *package);
};


#endif

// vim:sts=3:sw=3