0.7.1
[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 KDefaultUserOpenSaveDir = "/home/user/MyDocs";
35
36 #ifdef Q_WS_MAEMO_5
37         const QString KHamRepoListFile = "/etc/apt/sources.list.d/hildon-application-manager.list";
38 #else
39         const QString KHamRepoListFile = "/etc/apt/sources.list";
40 #endif
41
42 const QString KLastUpdateFile = "/opt/fapman-cache/lastupdate";
43 const QString KDateCacheFile = "/opt/fapman-cache/dates.cache";
44 const QString KAptSourceList = "/opt/fapman-cache/sources.list";
45 const QString KAptListDir = "/opt/fapman-cache/lists";
46 const QString KAptArchivePartialDir = "/var/cache/apt/archives/partial";
47 const QString KAptPreferencesFile = "/etc/apt/preferences";
48
49 const QString KDpkgStatusFile = "/var/lib/dpkg/status";
50 const QString KDpkgInfoDir = "/var/lib/dpkg/info";
51
52 const int KListExpireTime = 3600;
53
54 const int KDataReadBufferSize = 100000;
55
56 class MainWindow;
57 class FileReadThread;
58 class DateFetchThread;
59 class dimmer;
60 class Package;
61 class Repository;
62 class Settings;
63
64
65 class AAptInterface : public QObject
66 {
67         Q_OBJECT
68
69 public:
70         enum interfaceMode { ModeNone, ModeReadPackages, ModeFetchDates, ModeAptGetUpdate,
71                                                  ModeAptGetSimulate, ModeAptGetInstall, ModeAptGetClean };
72         enum multiLine { MultiLineNone, MultiLineDesc, MultiLineIcon, MultiLineUpgradeDesc };
73
74         explicit AAptInterface(QObject* parent);
75         virtual ~AAptInterface();
76         void setSettings(Settings* s_) { iSettings = s_; }
77
78         void addQueuedOperation(interfaceMode mode_);
79         bool run(dimmer* uiDimmer);
80         void setProcessPackages(QStringList pkgs) { iProcessPackages=pkgs; iProcessPackagesOrig=pkgs; }
81         QStringList processPackages() const { return iProcessPackages; }
82         QStringList processPackageVersions() const { return iProcessPackageVersions; }
83
84         bool running() const;
85         bool cancel();
86
87         int numSelectedPackages() const { return iNumSelectedPackages; }
88         void setNumSelectedPackages(int p_) { iNumSelectedPackages=p_; }
89
90         const QHash<QString, Package*>* packagesAvailable() { return &iPackagesAvailable; }
91         const QHash<QString, Package*>* packagesInstalled() { return &iPackagesInstalled; }
92         QList<Repository*>* repositories() { return  &iRepositories; }
93
94         QByteArray readLogFile();
95         void readRepositoryInfo();
96         bool writeRepositories();
97         bool needRepoRefresh();
98         void removeFromBlacklist(Package* pkg, BlacklistSelect::blackList oldstate);
99         void writeBlacklist();
100
101         bool dateCacheExists();
102
103         void setNeedRefresh(int repos, int lists, int dpkg, int dates);
104         void setSkipListAndDates() { iSkipRefreshListAndDates=true; }
105         bool needListOrDateRefresh();
106
107         QDateTime lastListUpdate() { return iLastListUpdate; }
108         QDateTime lastDpkgUpdate() { return iLastDpkgUpdate; }
109
110 private:
111         AAptInterface(const AAptInterface& old);
112         AAptInterface operator= (const AAptInterface& old);
113
114         void runNext();
115         void cleanAfterRunEach();
116         void cleanAfterRunAll();
117         void cleanAfterError();
118
119         bool startAptGetUpdate();
120         bool startAptGetSimulate();
121         bool startAptGetInstall();
122         bool startAptGetClean();
123
124         QString setQProcessErrorMessage(QProcess::ProcessError error);
125         QString finishProcessCommonErrorMessages(QByteArray& output);
126
127         void communicateStatusToUi(bool success, QString title="", QString msg="");
128         void logToFile( QString data, bool logtime=true );
129         void logToFile( QByteArray data, bool logtime=true );
130
131         void startPkgListRead();
132         void startFetchDates();
133
134         Package* ReadNextPackage(QFile& f, quint64& currentreaddata);
135         bool processPackageDataLine(Package*& pkg, QByteArray& line);
136
137         void readBlacklist();
138         void writeDateCache();
139         void readDateCache();
140         void readPinnedPackages();
141
142 private slots:
143         void errorAptGetUpdate(QProcess::ProcessError error);
144         void errorAptGetSimulate(QProcess::ProcessError error);
145         void errorAptGetInstall(QProcess::ProcessError error);
146         void errorAptGetClean(QProcess::ProcessError error);
147
148         void finishedAptGetUpdate(int exitCode, QProcess::ExitStatus exitStatus);
149         void finishedAptGetSimulate(int exitCode, QProcess::ExitStatus exitStatus);
150         void finishedAptGetInstall(int exitCode, QProcess::ExitStatus exitStatus);
151         void finishedAptGetClean(int exitCode, QProcess::ExitStatus exitStatus);
152
153         void uiUpdaterAptGetUpdate();
154         void uiUpdaterAptGetInstall();
155         void progressCheckTimerCallback();
156
157         void dateFetchNetworkReply(QNetworkReply* reply);
158
159 private:
160         QHash<QString, Package*> iPackagesAvailable;
161         QHash<QString, Package*> iPackagesInstalled;
162         int iNumSelectedPackages;
163
164         QStringList iProcessPackages;
165         QStringList iProcessPackagesOrig;
166         QStringList iProcessPackageVersions;
167         QList<interfaceMode> iOperationsQueue;
168         QList<Repository*> iRepositories;
169         QStringList iQueueMessages;
170
171         MainWindow* iMainWindow;
172         Settings* iSettings;
173         interfaceMode iMode;
174         QList<interfaceMode> iModeLog;
175         dimmer* iUiDimmer;
176         bool iCanCancel;
177         bool iTerminated;
178         bool iErrorDone;
179         bool iNeedRepoRefresh;
180         bool iNeedListRefresh;
181         bool iNeedDpkgRefresh;
182         bool iNeedDateRefresh;
183         bool iSkipRefreshListAndDates;
184         QDateTime iLastListUpdate;
185         QDateTime iLastDpkgUpdate;
186
187         QProcess* iProcAptGetUpdate;
188         QProcess* iProcAptGetSimulate;
189         QProcess* iProcAptGetInstall;
190         QProcess* iProcAptGetClean;
191         QByteArray iProcAptGetUpdateOutput;
192         QByteArray iProcAptGetInstallOutput;
193
194         int iAptGetDownloadCount;
195         int iAptGetInstallCount;
196         int iAptGetRemoveCount;
197         int iAptGetInstallTotal;
198         int iAptGetRemoveTotal;
199         qint64 iAptGetCurrentFileDownloadSize;
200         qint64 iAptGetCurrentFileTotalSize;
201         QString iAptGetCurrentDownloadFileName;
202         QTimer* iProgressCheckTimer;
203         int iSpeedKbps;
204         int iSpeedKbpsPrev;
205         bool iUpdateSpeed;
206
207         int iCatalogCounter;
208         int iCatalogsTotal;
209
210         QStringList iBlacklist;
211
212         multiLine iMultiLine;
213         char* iDataReadBuffer;
214
215         int iDateRequestsWaiting;
216         int iDateRequestsSent;
217         int iDateRequestsReceived;
218         int iDateRequestErrors;
219         QNetworkReply::NetworkError iNetworkError;
220 };
221
222
223 #endif // AAPTINTERFACE_H