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

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

first import

Line 
1/* rpackagelister.h - package cache and list manipulation
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
27#ifndef _RPACKAGELISTER_H_
28#define _RPACKAGELISTER_H_
29
30
31#include <vector>
32#include <list>
33#include <map>
34#include <set>
35#include <regex.h>
36#include <apt-pkg/depcache.h>
37
38#include "rpackagecache.h"
39#include "rpackage.h"
40#include "rpackageview.h"
41#include "ruserdialog.h"
42#include "config.h"
43
44using namespace std;
45
46class OpProgress;
47class RPackageCache;
48class RPackageFilter;
49class RCacheActor;
50class RPackageViewFilter;
51class RPackageViewSearch;
52class pkgRecords;
53class pkgAcquireStatus;
54class pkgPackageManager;
55
56
57struct RFilter;
58class RPackageView;
59
60class RInstallProgress;
61
62class RPackageObserver {
63 public:
64   virtual void notifyChange(RPackage *pkg) = 0;
65   virtual void notifyPreFilteredChange() = 0;
66   virtual void notifyPostFilteredChange() = 0;
67   virtual ~RPackageObserver() {};
68};
69
70class RCacheObserver {
71 public:
72   virtual void notifyCacheOpen() = 0;
73   virtual void notifyCachePreChange() = 0;
74   virtual void notifyCachePostChange() = 0;
75   virtual ~RCacheObserver() {};
76};
77
78// base sort class
79// for a example use see sortPackages()
80template<class T>
81class sortFunc {
82 protected:
83   bool _ascent;
84   T cmp;
85 public:
86   sortFunc(bool ascent) : _ascent(ascent) {};
87   bool operator() (RPackage *x, RPackage *y) {
88      if(_ascent) 
89         return cmp(x,y);
90      else
91         return cmp(y,x);
92   }
93};
94
95
96class RPackageLister {
97
98   protected:
99
100   // Internal APT stuff.
101   RPackageCache * _cache;
102   pkgRecords *_records;
103   OpProgress *_progMeter;
104
105   // Other members.
106   vector<RPackage *> _packages;
107   vector<int> _packagesIndex;
108
109   vector<RPackage *> _viewPackages;
110   vector<int> _viewPackagesIndex;
111
112   // It shouldn't be needed to control this inside this class. -- niemeyer
113   bool _updating;
114
115   // all known packages (needed identifing "new" pkgs)
116   set<string> packageNames; 
117
118   bool _cacheValid;            // is the cache valid?
119
120   int _installedCount;         // # of installed packages
121
122   vector<RCacheActor *> _actors;
123
124   RPackageViewFilter *_filterView; // the package view that does the filtering
125   RPackageViewSearch *_searchView; // the package view that does the (simple) search
126   
127   public:
128
129   unsigned int _viewMode;
130
131   typedef enum {
132      LIST_SORT_NAME,
133      LIST_SORT_SIZE_ASC,
134      LIST_SORT_SIZE_DES,
135      LIST_SORT_SUPPORTED_ASC,
136      LIST_SORT_SUPPORTED_DES,
137      LIST_SORT_SECTION_ASC,
138      LIST_SORT_SECTION_DES,
139      LIST_SORT_COMPONENT_ASC,
140      LIST_SORT_COMPONENT_DES,
141      LIST_SORT_DLSIZE_ASC,
142      LIST_SORT_DLSIZE_DES,
143      LIST_SORT_STATUS_ASC,
144      LIST_SORT_STATUS_DES,
145      LIST_SORT_VERSION_ASC,
146      LIST_SORT_VERSION_DES,
147      LIST_SORT_INST_VERSION_ASC,
148      LIST_SORT_INST_VERSION_DES
149   } listSortMode;
150   listSortMode _sortMode;
151
152#ifdef HAVE_RPM
153   typedef pkgDepCache::State pkgState;
154#else
155   typedef vector<int> pkgState;
156#endif
157
158   private:
159
160   vector<RPackageView *> _views;
161   RPackageView *_selectedView;
162   RPackageStatus _pkgStatus;
163   
164   void applyInitialSelection();
165
166   bool lockPackageCache(FileFd &lock);
167
168   void sortPackages(vector<RPackage *> &packages,listSortMode mode);
169
170   struct {
171      char *pattern;
172      regex_t regex;
173      bool isRegex;
174      int last;
175   } _searchData;
176
177   vector<RPackageObserver *> _packageObservers;
178   vector<RCacheObserver *> _cacheObservers;
179
180   RUserDialog *_userDialog;
181
182   void makeCommitLog();
183   void writeCommitLog();
184   string _logEntry;
185   time_t _logTime;
186
187   // undo/redo stuff
188   list<pkgState> undoStack;
189   list<pkgState> redoStack;
190
191   public:
192   // clean files older than "Synaptic::delHistory"
193   void cleanCommitLog();
194
195   void sortPackages(listSortMode mode) {
196      sortPackages(_viewPackages, mode);
197   };
198
199   void setView(unsigned int index);
200   vector<string> getViews();
201   vector<string> getSubViews();
202
203   // set subView (if newView is empty, set to all packages)
204   bool setSubView(string newView="");
205
206   // this needs a different name, something like refresh
207   void reapplyFilter();
208
209   // is is exposed for the stuff like filter manager window
210   RPackageViewFilter *filterView() { return _filterView; };
211   RPackageViewSearch *searchView() { return _searchView; };
212
213   // find
214   int findPackage(const char *pattern);
215   int findNextPackage();
216
217   const vector<RPackage *> &getPackages() { return _packages; };
218   const vector<RPackage *> &getViewPackages() { return _viewPackages; };
219   RPackage *getPackage(int index) { return _packages.at(index); };
220   RPackage *getViewPackage(int index) { return _viewPackages.at(index); };
221   RPackage *getPackage(pkgCache::PkgIterator &pkg);
222   RPackage *getPackage(string name);
223   int getPackageIndex(RPackage *pkg);
224   int getViewPackageIndex(RPackage *pkg);
225
226   int packagesSize() { return _packages.size(); };
227   int viewPackagesSize() { return _updating ? 0 : _viewPackages.size(); };
228
229   void getStats(int &installed, int &broken, int &toInstall, int &toReInstall,
230                 int &toRemove, double &sizeChange);
231
232   void getSummary(int &held, int &kept, int &essential,
233                   int &toInstall, int &toReInstall, int &toUpgrade, 
234                   int &toRemove,  int &toDowngrade, 
235                   int &unAuthenticated,  double &sizeChange);
236
237
238   void getDetailedSummary(vector<RPackage *> &held,
239                           vector<RPackage *> &kept,
240                           vector<RPackage *> &essential,
241                           vector<RPackage *> &toInstall,
242                           vector<RPackage *> &toReInstall,
243                           vector<RPackage *> &toUpgrade,
244                           vector<RPackage *> &toRemove,
245                           vector<RPackage *> &toPurge,
246                           vector<RPackage *> &toDowngrade,
247#ifdef WITH_APT_AUTH
248                           vector<string> &notAuthenticated,
249#endif
250                           double &sizeChange);
251
252   void getDownloadSummary(int &dlCount, double &dlSize);
253
254   void saveUndoState(pkgState &state);
255   void saveUndoState();
256   void undo();
257   void redo();
258   void saveState(pkgState &state);
259   void restoreState(pkgState &state);
260   bool getStateChanges(pkgState &state,
261                        vector<RPackage *> &kept,
262                        vector<RPackage *> &toInstall,
263                        vector<RPackage *> &toReInstall,
264                        vector<RPackage *> &toUpgrade,
265                        vector<RPackage *> &toRemove,
266                        vector<RPackage *> &toDowngrade,
267                        vector<RPackage *> &notAuthenticated,
268                        vector<RPackage *> &exclude, bool sorted = true);
269
270   // open it with lock
271   bool openCache(bool lock=true);
272
273   bool fixBroken();
274
275   bool check();
276   bool upgradable();
277
278   bool upgrade();
279   bool distUpgrade();
280
281   bool cleanPackageCache(bool forceClean = false);
282
283   bool updateCache(pkgAcquireStatus *status, string &error);
284   bool commitChanges(pkgAcquireStatus *status, RInstallProgress *iprog);
285
286   void setProgressMeter(OpProgress *progMeter) {
287      if(_progMeter != NULL)
288         delete _progMeter;
289      _progMeter = progMeter;
290   };
291
292   void setUserDialog(RUserDialog *dialog) {
293      _userDialog = dialog;
294   };
295
296   // policy stuff                             
297   vector<string> getPolicyArchives(bool filenames_only=false) {
298      if (_cacheValid)
299         return _cache->getPolicyArchives(filenames_only);
300      else
301         return vector<string>();
302   };
303
304   // notification stuff about changes in packages
305   void notifyPreChange(RPackage *pkg);
306   void notifyPostChange(RPackage *pkg);
307   void notifyChange(RPackage *pkg);
308   void registerObserver(RPackageObserver *observer);
309   void unregisterObserver(RPackageObserver *observer);
310
311   // notification stuff about changes in cache
312   void notifyCacheOpen();
313   void notifyCachePreChange();
314   void notifyCachePostChange();
315   void registerCacheObserver(RCacheObserver *observer);
316   void unregisterCacheObserver(RCacheObserver *observer);
317
318   bool readSelections(istream &in);
319   bool writeSelections(ostream &out, bool fullState);
320
321   RPackageCache* getCache() { return _cache; };
322
323   RPackageLister();
324   ~RPackageLister();
325};
326
327
328#endif
329
330// vim:ts=3:sw=3:et
Note: See TracBrowser for help on using the repository browser.