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 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
|
/* rpackagelister.h - package cache and list manipulation
*
* Copyright (c) 2000, 2001 Conectiva S/A
* 2002 Michael Vogt <mvo@debian.org>
*
* Author: Alfredo K. Kojima <kojima@conectiva.com.br>
* 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 _RPACKAGELISTER_H_
#define _RPACKAGELISTER_H_
#include <vector>
#include <list>
#include <map>
#include <set>
#include <regex.h>
#include <apt-pkg/depcache.h>
#include <apt-pkg/acquire.h>
#include <apt-pkg/progress.h>
#ifdef WITH_EPT
#include <ept/axi/axi.h>
#endif
#include "rpackagecache.h"
#include "rpackage.h"
#include "rpackagestatus.h"
#include "rpackageview.h"
#include "ruserdialog.h"
#include "config.h"
using namespace std;
class OpProgress;
class RPackageCache;
class RPackageFilter;
class RCacheActor;
class RPackageViewFilter;
class RPackageViewSearch;
class pkgRecords;
class pkgAcquireStatus;
class pkgPackageManager;
struct RFilter;
class RPackageView;
class RInstallProgress;
class RPackageObserver {
public:
virtual void notifyChange(RPackage *pkg) = 0;
virtual void notifyPreFilteredChange() = 0;
virtual void notifyPostFilteredChange() = 0;
};
class RCacheObserver {
public:
virtual void notifyCacheOpen() = 0;
virtual void notifyCachePreChange() = 0;
virtual void notifyCachePostChange() = 0;
};
// base sort class
// for a example use see sortPackages()
template<class T>
class sortFunc {
protected:
bool _ascent;
T cmp;
public:
sortFunc(bool ascent) : _ascent(ascent) {}
bool operator() (RPackage *x, RPackage *y) {
if(_ascent)
return cmp(x,y);
else
return cmp(y,x);
}
};
class RPackageLister {
protected:
// Internal APT stuff.
RPackageCache * _cache;
pkgRecords *_records;
OpProgress *_progMeter;
#ifdef WITH_EPT
Xapian::Database *_xapianDatabase;
#endif
// Other members.
vector<RPackage *> _packages;
vector<int> _packagesIndex;
vector<RPackage *> _viewPackages;
vector<int> _viewPackagesIndex;
// this is what we feed to the views as "all packages" to avoid
// to show all the multiarch versions by default, the user can
// turn that off with a config option
vector<RPackage *> _nativeArchPackages;
// It shouldn't be needed to control this inside this class. -- niemeyer
bool _updating;
// all known packages (needed identifing "new" pkgs)
set<string> packageNames;
bool _cacheValid; // is the cache valid?
int _installedCount; // # of installed packages
vector<RCacheActor *> _actors;
RPackageViewFilter *_filterView; // the package view that does the filtering
RPackageViewSearch *_searchView; // the package view that does the (simple) search
// helper for the limitBySearch() code
bool xapianSearch(string searchString);
public:
unsigned int _viewMode;
typedef enum {
LIST_SORT_DEFAULT,
LIST_SORT_NAME_ASC,
LIST_SORT_NAME_DES,
LIST_SORT_SIZE_ASC,
LIST_SORT_SIZE_DES,
LIST_SORT_SUPPORTED_ASC,
LIST_SORT_SUPPORTED_DES,
LIST_SORT_SECTION_ASC,
LIST_SORT_SECTION_DES,
LIST_SORT_COMPONENT_ASC,
LIST_SORT_COMPONENT_DES,
LIST_SORT_DLSIZE_ASC,
LIST_SORT_DLSIZE_DES,
LIST_SORT_STATUS_ASC,
LIST_SORT_STATUS_DES,
LIST_SORT_VERSION_ASC,
LIST_SORT_VERSION_DES,
LIST_SORT_INST_VERSION_ASC,
LIST_SORT_INST_VERSION_DES
} listSortMode;
listSortMode _sortMode;
#ifdef HAVE_RPM
typedef pkgDepCache::State pkgState;
#else
typedef vector<int> pkgState;
#endif
private:
vector<RPackageView *> _views;
RPackageView *_selectedView;
RPackageStatus _pkgStatus;
void applyInitialSelection();
bool lockPackageCache(FileFd &lock);
void sortPackages(vector<RPackage *> &packages,listSortMode mode);
struct {
char *pattern;
regex_t regex;
bool isRegex;
int last;
} _searchData;
vector<RPackageObserver *> _packageObservers;
vector<RCacheObserver *> _cacheObservers;
RUserDialog *_userDialog;
void makeCommitLog();
void writeCommitLog();
string _logEntry;
time_t _logTime;
// undo/redo stuff
list<pkgState> undoStack;
list<pkgState> redoStack;
public:
// limit what the current view displays
bool limitBySearch(string searchString);
// clean files older than "Synaptic::delHistory"
void cleanCommitLog();
void sortPackages(listSortMode mode) {
sortPackages(_viewPackages, mode);
}
void setView(unsigned int index);
vector<string> getViews();
vector<string> getSubViews();
// set subView (if newView is empty, set to all packages)
bool setSubView(string newView="");
// this needs a different name, something like refresh
void reapplyFilter();
// refresh view
void refreshView();
// is is exposed for the stuff like filter manager window
RPackageViewFilter *filterView() { return _filterView; }
RPackageViewSearch *searchView() { return _searchView; }
// find
int findPackage(const char *pattern);
int findNextPackage();
const vector<RPackage *> &getPackages() { return _packages; }
const vector<RPackage *> &getViewPackages() { return _viewPackages; }
RPackage *getPackage(int index) { return _packages.at(index); }
RPackage *getViewPackage(int index) { return _viewPackages.at(index); }
RPackage *getPackage(pkgCache::PkgIterator &pkg);
RPackage *getPackage(string name);
int getPackageIndex(RPackage *pkg);
int getViewPackageIndex(RPackage *pkg);
int packagesSize() { return _packages.size(); }
int viewPackagesSize() { return _updating ? 0 : _viewPackages.size(); }
void getStats(int &installed, int &broken, int &toInstall,
int &toRemove, double &sizeChange);
void getSummary(int &held, int &kept, int &essential,
int &toInstall, int &toReInstall, int &toUpgrade,
int &toRemove, int &toDowngrade,
int &unAuthenticated, double &sizeChange);
void getDetailedSummary(vector<RPackage *> &held,
vector<RPackage *> &kept,
vector<RPackage *> &essential,
vector<RPackage *> &toInstall,
vector<RPackage *> &toReInstall,
vector<RPackage *> &toUpgrade,
vector<RPackage *> &toRemove,
vector<RPackage *> &toPurge,
vector<RPackage *> &toDowngrade,
#ifdef WITH_APT_AUTH
vector<string> ¬Authenticated,
#endif
double &sizeChange);
void getDownloadSummary(int &dlCount, double &dlSize);
void saveUndoState(pkgState &state);
void saveUndoState();
void undo();
void redo();
void saveState(pkgState &state);
void restoreState(pkgState &state);
bool getStateChanges(pkgState &state,
vector<RPackage *> &kept,
vector<RPackage *> &toInstall,
vector<RPackage *> &toReInstall,
vector<RPackage *> &toUpgrade,
vector<RPackage *> &toRemove,
vector<RPackage *> &toDowngrade,
vector<RPackage *> ¬Authenticated,
const vector<RPackage *> &exclude,
bool sorted = true);
// open (lock if run as root)
bool openCache();
bool fixBroken();
bool check();
bool upgradable();
bool upgrade();
bool distUpgrade();
bool cleanPackageCache(bool forceClean = false);
bool updateCache(pkgAcquireStatus *status, string &error);
bool commitChanges(pkgAcquireStatus *status, RInstallProgress *iprog);
// some information
bool getDownloadUris(vector<string> &uris);
bool addArchiveToCache(string archiveDir, string &pkgname);
void setProgressMeter(OpProgress *progMeter) {
if(_progMeter != NULL)
delete _progMeter;
_progMeter = progMeter;
}
void setUserDialog(RUserDialog *dialog) {
_userDialog = dialog;
}
// policy stuff
vector<string> getPolicyArchives(bool filenames_only=false) {
if (_cacheValid)
return _cache->getPolicyArchives(filenames_only);
else
return vector<string>();
}
// multiarch
bool isMultiarchSystem();
// notification stuff about changes in packages
void notifyPreChange(RPackage *pkg);
void notifyPostChange(RPackage *pkg);
void notifyChange(RPackage *pkg);
void registerObserver(RPackageObserver *observer);
void unregisterObserver(RPackageObserver *observer);
// notification stuff about changes in cache
void notifyCacheOpen();
void notifyCachePreChange();
void notifyCachePostChange();
void registerCacheObserver(RCacheObserver *observer);
void unregisterCacheObserver(RCacheObserver *observer);
bool readSelections(istream &in);
bool writeSelections(ostream &out, bool fullState);
RPackageCache* getCache() { return _cache; }
#ifdef WITH_EPT
Xapian::Database* xapiandatabase() { return _xapianDatabase; }
bool xapianIndexNeedsUpdate();
bool openXapianIndex();
#endif
RPackageLister();
~RPackageLister();
};
#endif
// vim:ts=3:sw=3:et
|