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

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

first import

Line 
1/* rpackage.h - wrapper for accessing package information
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 * Portions Taken from Gnome APT
10 *   Copyright (C) 1998 Havoc Pennington <hp@pobox.com>
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of the
16 * License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26 * USA
27 */
28
29
30
31#ifndef _RPACKAGE_H_
32#define _RPACKAGE_H_
33
34#include <vector>
35
36#include <apt-pkg/pkgcache.h>
37#include <apt-pkg/acquire.h>
38#include "rconfiguration.h"
39#include "i18n.h"
40
41using namespace std;
42
43class pkgDepCache;
44class RPackageLister;
45class pkgRecords;
46
47enum { NO_PARSER, DEB_PARSER, STRIP_WS_PARSER, RPM_PARSER };
48
49// taken from apt (pkgcache.cc) to make our life easier
50// (and added "RDepends" after "Obsoletes"
51static const char *DepTypeStr[] = 
52   {"",_("Depends"),_("PreDepends"),_("Suggests"),
53    _("Recommends"),_("Conflicts"),_("Replaces"),
54    _("Obsoletes"), _("Dependency of")};
55
56typedef struct  {
57   pkgCache::Dep::DepType type; // type as enum
58   const char* name;            // target pkg name
59   const char* version;         // target version 
60   const char* versionComp;     // target version compare type ( << , > etc)
61   bool isSatisfied;            // dependecy is satified
62   bool isVirtual;              // package is virtual
63   bool isOr;                   // or dependency (with next pkg)
64} DepInformation;
65
66
67class RPackage {
68
69   protected:
70
71   RPackageLister *_lister;
72
73   pkgRecords *_records;
74   pkgDepCache *_depcache;
75   pkgCache::PkgIterator *_package;
76
77   // save the default candidate version to undo version selection
78   string _defaultCandVer;
79
80   bool _notify;
81
82   // Virtual pkgs provided by this one.
83   // FIXME: broken right now
84   bool isShallowDependency(RPackage *pkg);
85   int _boolFlags;
86
87 public:
88
89   enum Flags {
90      FKeep             = 1 << 0,
91      FInstall          = 1 << 1,
92      FNewInstall       = 1 << 2,
93      FReInstall        = 1 << 3,
94      FUpgrade          = 1 << 4,
95      FDowngrade        = 1 << 5,
96      FRemove           = 1 << 6,
97      FHeld             = 1 << 7,
98      FInstalled        = 1 << 8,
99      FOutdated         = 1 << 9,
100      FNowBroken        = 1 << 10,
101      FInstBroken       = 1 << 11,
102      FOrphaned         = 1 << 12,
103      FPinned           = 1 << 13,
104      FNew              = 1 << 14,
105      FResidualConfig   = 1 << 15,
106      FNotInstallable   = 1 << 16,
107      FPurge            = 1 << 17,
108      FImportant        = 1 << 18,
109      FOverrideVersion  = 1 << 19,
110   };
111
112   enum UpdateImportance {
113      IUnknown,
114      INormal,
115      ICritical,
116      ISecurity
117   };
118
119   pkgCache::PkgIterator *package() { return _package; };
120
121   inline const char *name() { return _package->Name(); };
122
123   const char *section();
124   const char *priority();
125
126   const char *summary();
127   const char *description();
128   const char *installedFiles();
129
130   // get changelog file from the debian server (debian only of course)
131   string getChangelogFile(pkgAcquire *fetcher);
132
133   vector<string> provides();
134
135   // get all available versions (version, release)
136   vector<pair<string, string> > getAvailableVersions();
137
138   // get origin of the package
139   string getCanidateOrigin();
140
141   // get installed component (like main, contrib, non-free)
142   string component();
143   
144   // get label of download site
145   string label();
146   
147   const char *maintainer();
148   const char *vendor();
149
150   const char *installedVersion();
151   long installedSize();
152
153   // sourcepkg
154   const char *srcPackage();
155
156   // relative to version that would be installed
157   const char *availableVersion();
158   long availableInstalledSize();
159   long availablePackageSize();
160
161   // does the pkg depends on this one?
162   bool dependsOn(const char *pkgname);
163
164   // getDeps of installed pkg
165   vector<DepInformation> enumDeps(bool useCanidateVersion=false);
166
167   // reverse dependencies
168   vector<DepInformation> enumRDeps();
169
170   int getFlags();
171
172   bool wouldBreak();
173
174   bool isTrusted();
175
176   void setKeep();
177   void setInstall();
178   void setReInstall(bool flag);
179   void setRemove(bool purge = false);
180
181   void setPinned(bool flag);
182
183   void setNew(bool flag = true) {
184      _boolFlags = flag ? (_boolFlags | FNew) : (_boolFlags & ~FNew);
185   };
186   void setOrphaned(bool flag = true) {
187      _boolFlags = flag ? (_boolFlags | FOrphaned) : (_boolFlags & ~FOrphaned);
188   };
189
190   void setNotify(bool flag = true);
191
192   // Shallow doesnt remove things other pkgs depend on.
193   void setRemoveWithDeps(bool shallow, bool purge = false);
194
195   // mainpulate the candiate version
196   bool setVersion(string verTag);
197   void unsetVersion(); 
198   string showWhyInstBroken();
199
200   RPackage(RPackageLister *lister, pkgDepCache *depcache,
201            pkgRecords *records, pkgCache::PkgIterator &pkg);
202   ~RPackage();
203};
204
205
206class RPackageStatus {
207 public:
208   enum PkgStatus {
209      ToInstall, ToReInstall, ToUpgrade, ToDowngrade, ToRemove, ToPurge,
210      NotInstalled, NotInstalledLocked,
211      InstalledUpdated, InstalledOutdated, InstalledLocked,
212      IsBroken, IsNew,
213      N_STATUS_COUNT
214   };
215
216 protected:
217   // the supported archive-labels and components
218   vector<string> supportedLabels;
219   vector<string> supportedComponents;
220   bool markUnsupported;
221
222   // this is the short string to load the icons
223   const char *PackageStatusShortString[N_STATUS_COUNT];
224   // this is the long string for the gui description of the state
225   const char *PackageStatusLongString[N_STATUS_COUNT];
226
227
228   // this does the actual work
229   int getStatus(RPackage *pkg);
230
231
232 public:
233   RPackageStatus() : markUnsupported(false) {};
234   virtual ~RPackageStatus() {};
235
236   // this reads the pixmaps and the colors
237   virtual void init();
238
239   // here we get the description for the States
240   const char *getLongStatusString(int i) {
241      return PackageStatusLongString[i];
242   };
243   const char *getLongStatusString(RPackage *pkg) {
244      return PackageStatusLongString[getStatus(pkg)];
245   };
246
247   const char *getShortStatusString(int i) {
248      return PackageStatusShortString[i];
249   };
250
251   bool isSupported(RPackage *pkg);
252   
253};
254
255
256
257#endif
258
259// vim:ts=3:sw=3:et
Note: See TracBrowser for help on using the repository browser.