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

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

first import

Line 
1/* rpackagefilter.h - filters for package listing
2 *
3 * Copyright (c) 2000, 2001 Conectiva S/A
4 *               2002 Michael Vogt <mvo@debian.org>
5 *
6 * Author: Alfredo K. Kojima <kojima@conectiva.com.br>
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 _RPACKAGEFILTER_H_
27#define _RPACKAGEFILTER_H_
28
29#include <set>
30#include <vector>
31#include <string>
32#include <fstream>
33#include <iostream>
34#include <apt-pkg/tagfile.h>
35
36#include <regex.h>
37
38#include "rpackagelister.h"
39
40using namespace std;
41
42class RPackage;
43class RPackageLister;
44
45class Configuration;
46
47
48class RPackageFilter {
49
50
51   public:
52
53   virtual const char *type() = 0;
54
55   virtual bool filter(RPackage *pkg) = 0;
56   virtual void reset() = 0;
57
58   virtual bool read(Configuration &conf, string key) = 0;
59   virtual bool write(ofstream &out, string pad) = 0;
60
61   RPackageFilter() {};
62   virtual ~RPackageFilter() {};
63};
64
65
66extern const char *RPFSection;
67
68class RSectionPackageFilter : public RPackageFilter {
69   
70   protected:
71
72   vector<string> _groups;
73   bool _inclusive;             // include or exclude the packages
74
75   public:
76
77   RSectionPackageFilter() : _inclusive(false) {};
78   virtual ~RSectionPackageFilter() {};
79
80   inline virtual void reset() {
81      clear();
82      _inclusive = false;
83   };
84
85   inline virtual const char *type() { return RPFSection; };
86
87   void setInclusive(bool flag) { _inclusive = flag; };
88   bool inclusive();
89
90   inline void addSection(string group) { _groups.push_back(group); };
91   int count();
92   string section(int index);
93   void clear();
94
95   virtual bool filter(RPackage *pkg);
96   virtual bool read(Configuration &conf, string key);
97   virtual bool write(ofstream &out, string pad);
98};
99
100
101extern const char *RPFPattern;
102
103class RPatternPackageFilter : public RPackageFilter {
104 public:
105   typedef enum {
106      Name,
107      Description,
108      Maintainer,
109      Version,
110      Depends,
111      Provides,
112      Conflicts,
113      Replaces,                 // (or obsoletes)
114      Recommends,
115      Suggests,
116      RDepends,                  // reverse depends
117      Origin                   // package origin (like security.debian.org)
118   } DepType;
119
120   
121 protected:
122   struct Pattern {
123      DepType where;
124      string pattern;
125      bool exclusive;
126        vector<regex_t *> regexps;
127   };
128   vector<Pattern> _patterns;
129   
130   bool and_mode; // patterns are applied in "AND" mode if true, "OR" if false
131
132   inline bool filterName(Pattern pat, RPackage *pkg);
133   inline bool filterVersion(Pattern pat, RPackage *pkg);
134   inline bool filterDescription(Pattern pat, RPackage *pkg);
135   inline bool filterMaintainer(Pattern pat, RPackage *pkg);
136   inline bool filterDepends(Pattern pat, RPackage *pkg, 
137                             pkgCache::Dep::DepType filterType);
138   inline bool filterProvides(Pattern pat, RPackage *pkg);
139   inline bool filterRDepends(Pattern pat, RPackage *pkg);
140   inline bool filterOrigin(Pattern pat, RPackage *pkg);
141
142 public:
143
144   static char *TypeName[];
145
146   RPatternPackageFilter() : and_mode(true) {};
147   RPatternPackageFilter(RPatternPackageFilter &f);
148   virtual ~RPatternPackageFilter();
149
150   inline virtual void reset() { clear(); };
151
152   inline virtual const char *type() { return RPFPattern; };
153
154   void addPattern(DepType type, string pattern, bool exclusive);
155   inline int count() { return _patterns.size(); };
156   inline void getPattern(int index, DepType &type, string &pattern,
157                          bool &exclusive) {
158      type = _patterns[index].where;
159      pattern = _patterns[index].pattern;
160      exclusive = _patterns[index].exclusive;
161   };
162   void clear();
163   bool getAndMode() { return and_mode; };
164   void setAndMode(bool b) { and_mode=b; };
165
166   virtual bool filter(RPackage *pkg);
167   virtual bool read(Configuration &conf, string key);
168   virtual bool write(ofstream &out, string pad);
169};
170
171
172extern const char *RPFStatus;
173
174class RStatusPackageFilter : public RPackageFilter {
175
176   protected:
177     
178   int _status;
179
180   public:
181
182   enum Types {
183      Installed = 1 << 0,
184      Upgradable = 1 << 1,      // installed but upgradable
185      Broken = 1 << 2,          // installed but dependencies are broken
186      NotInstalled = 1 << 3,
187      MarkInstall = 1 << 4,
188      MarkRemove = 1 << 5,
189      MarkKeep = 1 << 6,
190      NewPackage = 1 << 7,      // new Package (after update)
191      PinnedPackage = 1 << 8,   // pinned Package (never upgrade)
192      OrphanedPackage = 1 << 9, // orphaned (identfied with deborphan)
193      ResidualConfig = 1 << 10, // not installed but has config left
194      NotInstallable = 1 << 11,  // the package is not aviailable in repository
195      UpstreamUpgradable = 1 << 12 // new upstream version
196   };
197
198   RStatusPackageFilter() : _status(~0)
199   {};
200   inline virtual void reset() { _status = ~0; };
201
202   inline virtual const char *type() { return RPFStatus; };
203
204   inline void setStatus(int status) { _status = status; };
205   inline int status() { return _status; };
206
207   virtual bool filter(RPackage *pkg);
208   virtual bool read(Configuration &conf, string key);
209   virtual bool write(ofstream &out, string pad);
210};
211
212
213extern const char *RPFPriority;
214
215class RPriorityPackageFilter:public RPackageFilter {
216
217   public:
218
219   RPriorityPackageFilter()  {};
220
221   inline virtual void reset() {};
222
223   inline virtual const char *type() { return RPFPriority; };
224
225   virtual bool filter(RPackage *pkg);
226   virtual bool read(Configuration &conf, string key);
227   virtual bool write(ofstream &out, string pad);
228};
229
230
231extern const char *RPFReducedView;
232
233class RReducedViewPackageFilter : public RPackageFilter {
234
235   protected:
236
237   bool _enabled;
238
239   set<string> _hide;
240   vector<string> _hide_wildcard;
241   vector<regex_t *> _hide_regex;
242
243   void addFile(string FileName);
244
245   public:
246
247   RReducedViewPackageFilter() : _enabled(false) {};
248   ~RReducedViewPackageFilter();
249
250   inline virtual void reset() { _hide.clear(); };
251
252   inline virtual const char *type() { return RPFReducedView; };
253
254   virtual bool filter(RPackage *pkg);
255   virtual bool read(Configuration &conf, string key);
256   virtual bool write(ofstream &out, string pad);
257
258   void enable() { _enabled = true; };
259   void disable() { _enabled = false; };
260};
261
262struct RFilter {
263
264   public:
265
266   RFilter()
267      :   section(), pattern(), status(),
268          priority(), reducedview(), preset()
269   {};
270
271   void setName(string name);
272   string getName();
273
274   bool read(Configuration &conf, string key);
275   bool write(ofstream &out);
276   bool apply(RPackage *package);
277   void reset();
278
279   RSectionPackageFilter section;
280   RPatternPackageFilter pattern;
281   RStatusPackageFilter status;
282   RPriorityPackageFilter priority;
283   RReducedViewPackageFilter reducedview;
284
285   bool preset;
286
287   protected:
288
289   string name;
290};
291
292
293#endif
294
295// vim:ts=3:sw=3:et
Note: See TracBrowser for help on using the repository browser.