added app list backup, helper shell scripts
[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         bool loadInstallFiles(QStringList files_);
108
109         QDateTime lastListUpdate() { return iLastListUpdate; }
110         QDateTime lastDpkgUpdate() { return iLastDpkgUpdate; }
111
112 private:
113         AAptInterface(const AAptInterface& old);
114         AAptInterface operator= (const AAptInterface& old);
115
116         void runNext();
117         void cleanAfterRunEach();
118         void cleanAfterRunAll();
119         void cleanAfterError();
120
121         bool startAptGetUpdate();
122         bool startAptGetSimulate();
123         bool startAptGetInstall();
124         bool startAptGetClean();
125
126         QString setQProcessErrorMessage(QProcess::ProcessError error);
127         QString finishProcessCommonErrorMessages(QByteArray& output);
128
129         void communicateStatusToUi(bool success, QString title="", QString msg="");
130         void logToFile( QString data, bool logtime=true );
131         void logToFile( QByteArray data, bool logtime=true );
132
133         void startPkgListRead();
134         void startFetchDates();
135
136         Package* ReadNextPackage(QFile& f, quint64& currentreaddata);
137         bool processPackageDataLine(Package*& pkg, QByteArray& line);
138
139         void readBlacklist();
140         void writeDateCache();
141         void readDateCache();
142         void readPinnedPackages();
143
144 private slots:
145         void errorAptGetUpdate(QProcess::ProcessError error);
146         void errorAptGetSimulate(QProcess::ProcessError error);
147         void errorAptGetInstall(QProcess::ProcessError error);
148         void errorAptGetClean(QProcess::ProcessError error);
149
150         void finishedAptGetUpdate(int exitCode, QProcess::ExitStatus exitStatus);
151         void finishedAptGetSimulate(int exitCode, QProcess::ExitStatus exitStatus);
152         void finishedAptGetInstall(int exitCode, QProcess::ExitStatus exitStatus);
153         void finishedAptGetClean(int exitCode, QProcess::ExitStatus exitStatus);
154
155         void uiUpdaterAptGetUpdate();
156         void uiUpdaterAptGetInstall();
157         void progressCheckTimerCallback();
158
159         void dateFetchNetworkReply(QNetworkReply* reply);
160
161 private:
162         QHash<QString, Package*> iPackagesAvailable;
163         QHash<QString, Package*> iPackagesInstalled;
164         int iNumSelectedPackages;
165
166         QStringList iProcessPackages;
167         QStringList iProcessPackagesOrig;
168         QStringList iProcessPackageVersions;
169         QList<interfaceMode> iOperationsQueue;
170         QList<Repository*> iRepositories;
171         QStringList iQueueMessages;
172
173         MainWindow* iMainWindow;
174         Settings* iSettings;
175         interfaceMode iMode;
176         QList<interfaceMode> iModeLog;
177         dimmer* iUiDimmer;
178         bool iCanCancel;
179         bool iTerminated;
180         bool iErrorDone;
181         bool iNeedRepoRefresh;
182         bool iNeedListRefresh;
183         bool iNeedDpkgRefresh;
184         bool iNeedDateRefresh;
185         bool iSkipRefreshListAndDates;
186         QDateTime iLastListUpdate;
187         QDateTime iLastDpkgUpdate;
188
189         QProcess* iProcAptGetUpdate;
190         QProcess* iProcAptGetSimulate;
191         QProcess* iProcAptGetInstall;
192         QProcess* iProcAptGetClean;
193         QByteArray iProcAptGetUpdateOutput;
194         QByteArray iProcAptGetInstallOutput;
195
196         int iAptGetDownloadCount;
197         int iAptGetInstallCount;
198         int iAptGetRemoveCount;
199         int iAptGetInstallTotal;
200         int iAptGetRemoveTotal;
201         qint64 iAptGetCurrentFileDownloadSize;
202         qint64 iAptGetCurrentFileTotalSize;
203         QString iAptGetCurrentDownloadFileName;
204         QTimer* iProgressCheckTimer;
205         int iSpeedKbps;
206         int iSpeedKbpsPrev;
207         bool iUpdateSpeed;
208
209         int iCatalogCounter;
210         int iCatalogsTotal;
211
212         QStringList iBlacklist;
213
214         multiLine iMultiLine;
215         char* iDataReadBuffer;
216
217         int iDateRequestsWaiting;
218         int iDateRequestsSent;
219         int iDateRequestsReceived;
220         int iDateRequestErrors;
221         QNetworkReply::NetworkError iNetworkError;
222 };
223
224
225 #endif // AAPTINTERFACE_H