fixed free space / size display on large filesystems
[fapman] / aaptinterface.h
1 /*
2         This file is part of Faster Application Manager.
3
4         Faster Application Manager is free software: you can redistribute it and/or modify
5         it under the terms of the GNU General Public License as published by
6         the Free Software Foundation, either version 3 of the License, or
7         (at your option) any later version.
8
9         Faster Application Manager is distributed in the hope that it will be useful,
10         but WITHOUT ANY WARRANTY; without even the implied warranty of
11         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12         GNU General Public License for more details.
13
14         You should have received a copy of the GNU General Public License
15         along with Faster Application Manager.  If not, see <http://www.gnu.org/licenses/>.
16
17         (C) Heikki Holstila 2010
18 */
19
20 #ifndef AAPTINTERFACE_H
21 #define AAPTINTERFACE_H
22
23 #include <QtGui>
24 #include <QtNetwork>
25 #include "blacklistselect.h"
26
27
28 const QString KFapmanDir = "/root/.fapman";
29 const QString KLogFile = "/root/.fapman/lastlog.txt";
30 const QString KBlacklistFile = "/root/.fapman/black.list";
31 const QString KOwnRepoFile = "/root/.fapman/repos.list";
32 const QString KOwnRepoNamesFile = "/root/.fapman/repos.names";
33
34 const QString KHamRepoListFile = "/etc/apt/sources.list.d/hildon-application-manager.list";
35
36 const QString KLastUpdateFile = "/opt/fapman-cache/lastupdate";
37 const QString KDateCacheFile = "/opt/fapman-cache/dates.cache";
38 const QString KAptSourceList = "/opt/fapman-cache/sources.list";
39 const QString KAptListDir = "/opt/fapman-cache/lists";
40 const QString KAptArchivePartialDir = "/var/cache/apt/archives/partial";
41 const QString KAptPreferencesFile = "/etc/apt/preferences";
42
43 const QString KDpkgStatusFile = "/var/lib/dpkg/status";
44 const QString KDpkgInfoDir = "/var/lib/dpkg/info";
45
46 const int KListExpireTime = 3600;
47
48 const int KDataReadBufferSize = 100000;
49
50 class MainWindow;
51 class FileReadThread;
52 class DateFetchThread;
53 class dimmer;
54 class Package;
55 class Repository;
56 class Settings;
57
58
59 class AAptInterface : public QObject
60 {
61         Q_OBJECT
62
63 public:
64         enum interfaceMode { ModeNone, ModeReadPackages, ModeFetchDates, ModeAptGetUpdate,
65                                                  ModeAptGetSimulate, ModeAptGetInstall, ModeAptGetClean };
66         enum multiLine { MultiLineNone, MultiLineDesc, MultiLineIcon, MultiLineUpgradeDesc };
67
68         explicit AAptInterface(QObject* parent);
69         virtual ~AAptInterface();
70         void setSettings(Settings* s_) { iSettings = s_; }
71
72         void addQueuedOperation(interfaceMode mode_);
73         bool run(dimmer* uiDimmer);
74         void setProcessPackages(QStringList pkgs) { iProcessPackages=pkgs; iProcessPackagesOrig=pkgs; }
75         QStringList processPackages() const { return iProcessPackages; }
76         QStringList processPackageVersions() const { return iProcessPackageVersions; }
77
78         bool running() const;
79         bool cancel();
80
81         int numSelectedPackages() const { return iNumSelectedPackages; }
82         void setNumSelectedPackages(int p_) { iNumSelectedPackages=p_; }
83
84         const QHash<QString, Package*>* packagesAvailable() { return &iPackagesAvailable; }
85         const QHash<QString, Package*>* packagesInstalled() { return &iPackagesInstalled; }
86         QList<Repository*>* repositories() { return  &iRepositories; }
87
88         // new api functions to support multiple packages with the same name
89         /*
90         QList<Package*> allLatestAvailablePackages();
91         QList<Package*> allAvailablePackagesNamed(QString name);
92         Package* findNewestAvailablePackage(QString name);
93         */
94
95         QByteArray readLogFile();
96         void readRepositoryInfo();
97         bool writeRepositories();
98         bool needRepoRefresh();
99         void removeFromBlacklist(Package* pkg, BlacklistSelect::blackList oldstate);
100         void writeBlacklist();
101
102         bool dateCacheExists();
103
104         void setNeedRefresh(int repos, int lists, int dpkg, int dates);
105         void setSkipListAndDates() { iSkipRefreshListAndDates=true; }
106         bool needListOrDateRefresh();
107
108         bool loadInstallFiles(QStringList files_);
109
110         QDateTime lastListUpdate() { return iLastListUpdate; }
111         QDateTime lastDpkgUpdate() { return iLastDpkgUpdate; }
112
113 private:
114         AAptInterface(const AAptInterface& old);
115         AAptInterface operator= (const AAptInterface& old);
116
117         void runNext();
118         void cleanAfterRunEach();
119         void cleanAfterRunAll();
120         void cleanAfterError();
121
122         bool startAptGetUpdate();
123         bool startAptGetSimulate();
124         bool startAptGetInstall();
125         bool startAptGetClean();
126
127         QString setQProcessErrorMessage(QProcess::ProcessError error);
128         QString finishProcessCommonErrorMessages(QByteArray& output);
129
130         void communicateStatusToUi(bool success, QString title="", QString msg="");
131         void logToFile( QString data, bool logtime=true );
132         void logToFile( QByteArray data, bool logtime=true );
133
134         void startPkgListRead();
135         void startFetchDates();
136
137         Package* ReadNextPackage(QFile& f, quint64& currentreaddata);
138         bool processPackageDataLine(Package*& pkg, QByteArray& line);
139
140         void readBlacklist();
141         void writeDateCache();
142         void readDateCache();
143         void readPinnedPackages();
144
145 private slots:
146         void errorAptGetUpdate(QProcess::ProcessError error);
147         void errorAptGetSimulate(QProcess::ProcessError error);
148         void errorAptGetInstall(QProcess::ProcessError error);
149         void errorAptGetClean(QProcess::ProcessError error);
150
151         void finishedAptGetUpdate(int exitCode, QProcess::ExitStatus exitStatus);
152         void finishedAptGetSimulate(int exitCode, QProcess::ExitStatus exitStatus);
153         void finishedAptGetInstall(int exitCode, QProcess::ExitStatus exitStatus);
154         void finishedAptGetClean(int exitCode, QProcess::ExitStatus exitStatus);
155
156         void uiUpdaterAptGetUpdate();
157         void uiUpdaterAptGetInstall();
158         void progressCheckTimerCallback();
159
160         void dateFetchNetworkReply(QNetworkReply* reply);
161
162 private:
163         QHash<QString, Package*> iPackagesAvailable;
164         QHash<QString, Package*> iPackagesInstalled;
165         int iNumSelectedPackages;
166
167         QStringList iProcessPackages;
168         QStringList iProcessPackagesOrig;
169         QStringList iProcessPackageVersions;
170         QList<interfaceMode> iOperationsQueue;
171         QList<Repository*> iRepositories;
172         QStringList iQueueMessages;
173
174         MainWindow* iMainWindow;
175         Settings* iSettings;
176         interfaceMode iMode;
177         QList<interfaceMode> iModeLog;
178         dimmer* iUiDimmer;
179         bool iCanCancel;
180         bool iTerminated;
181         bool iErrorDone;
182         bool iNeedRepoRefresh;
183         bool iNeedListRefresh;
184         bool iNeedDpkgRefresh;
185         bool iNeedDateRefresh;
186         bool iSkipRefreshListAndDates;
187         QDateTime iLastListUpdate;
188         QDateTime iLastDpkgUpdate;
189
190         QProcess* iProcAptGetUpdate;
191         QProcess* iProcAptGetSimulate;
192         QProcess* iProcAptGetInstall;
193         QProcess* iProcAptGetClean;
194         QByteArray iProcAptGetUpdateOutput;
195         QByteArray iProcAptGetInstallOutput;
196
197         int iAptGetDownloadCount;
198         int iAptGetInstallCount;
199         int iAptGetRemoveCount;
200         int iAptGetInstallTotal;
201         int iAptGetRemoveTotal;
202         qint64 iAptGetCurrentFileDownloadSize;
203         qint64 iAptGetCurrentFileTotalSize;
204         QString iAptGetCurrentDownloadFileName;
205         QTimer* iProgressCheckTimer;
206         int iSpeedKbps;
207         int iSpeedKbpsPrev;
208         bool iUpdateSpeed;
209
210         int iCatalogCounter;
211         int iCatalogsTotal;
212
213         QStringList iBlacklist;
214
215         multiLine iMultiLine;
216         char* iDataReadBuffer;
217
218         int iDateRequestsWaiting;
219         int iDateRequestsSent;
220         int iDateRequestsReceived;
221         int iDateRequestErrors;
222         QNetworkReply::NetworkError iNetworkError;
223 };
224
225
226 #endif // AAPTINTERFACE_H