/* rpackagelister.h - package cache and list manipulation * * Copyright (c) 2000, 2001 Conectiva S/A * 2002 Michael Vogt * * Author: Alfredo K. Kojima * Michael Vogt * * 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 #include #include #include #include #include #include "rpackagecache.h" #include "rpackage.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; virtual ~RPackageObserver() {}; }; class RCacheObserver { public: virtual void notifyCacheOpen() = 0; virtual void notifyCachePreChange() = 0; virtual void notifyCachePostChange() = 0; virtual ~RCacheObserver() {}; }; // base sort class // for a example use see sortPackages() template 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; // Other members. vector _packages; vector _packagesIndex; vector _viewPackages; vector _viewPackagesIndex; // It shouldn't be needed to control this inside this class. -- niemeyer bool _updating; // all known packages (needed identifing "new" pkgs) set packageNames; bool _cacheValid; // is the cache valid? int _installedCount; // # of installed packages vector _actors; RPackageViewFilter *_filterView; // the package view that does the filtering RPackageViewSearch *_searchView; // the package view that does the (simple) search public: unsigned int _viewMode; typedef enum { LIST_SORT_NAME, 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 pkgState; #endif private: vector _views; RPackageView *_selectedView; RPackageStatus _pkgStatus; void applyInitialSelection(); bool lockPackageCache(FileFd &lock); void sortPackages(vector &packages,listSortMode mode); struct { char *pattern; regex_t regex; bool isRegex; int last; } _searchData; vector _packageObservers; vector _cacheObservers; RUserDialog *_userDialog; void makeCommitLog(); void writeCommitLog(); string _logEntry; time_t _logTime; // undo/redo stuff list undoStack; list redoStack; public: // clean files older than "Synaptic::delHistory" void cleanCommitLog(); void sortPackages(listSortMode mode) { sortPackages(_viewPackages, mode); }; void setView(unsigned int index); vector getViews(); vector 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(); // 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 &getPackages() { return _packages; }; const vector &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 &toReInstall, 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 &held, vector &kept, vector &essential, vector &toInstall, vector &toReInstall, vector &toUpgrade, vector &toRemove, vector &toPurge, vector &toDowngrade, #ifdef WITH_APT_AUTH vector ¬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 &kept, vector &toInstall, vector &toReInstall, vector &toUpgrade, vector &toRemove, vector &toDowngrade, vector ¬Authenticated, vector &exclude, bool sorted = true); // open it with lock bool openCache(bool lock=true); 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); void setProgressMeter(OpProgress *progMeter) { if(_progMeter != NULL) delete _progMeter; _progMeter = progMeter; }; void setUserDialog(RUserDialog *dialog) { _userDialog = dialog; }; // policy stuff vector getPolicyArchives(bool filenames_only=false) { if (_cacheValid) return _cache->getPolicyArchives(filenames_only); else return vector(); }; // 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; }; RPackageLister(); ~RPackageLister(); }; #endif // vim:ts=3:sw=3:et