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