2 This file is part of Faster Application Manager.
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.
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.
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/>.
17 (C) Heikki Holstila 2010
20 #ifndef AAPTINTERFACE_H
21 #define AAPTINTERFACE_H
25 #include "blacklistselect.h"
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";
34 const QString KHamRepoListFile = "/etc/apt/sources.list.d/hildon-application-manager.list";
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";
43 const QString KDpkgStatusFile = "/var/lib/dpkg/status";
44 const QString KDpkgInfoDir = "/var/lib/dpkg/info";
46 const int KListExpireTime = 3600;
48 const int KDataReadBufferSize = 100000;
52 class DateFetchThread;
59 class AAptInterface : public QObject
64 enum interfaceMode { ModeNone, ModeReadPackages, ModeFetchDates, ModeAptGetUpdate,
65 ModeAptGetSimulate, ModeAptGetInstall, ModeAptGetClean };
66 enum multiLine { MultiLineNone, MultiLineDesc, MultiLineIcon, MultiLineUpgradeDesc };
68 explicit AAptInterface(QObject* parent);
69 virtual ~AAptInterface();
70 void setSettings(Settings* s_) { iSettings = s_; }
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; }
81 int numSelectedPackages() const { return iNumSelectedPackages; }
82 void setNumSelectedPackages(int p_) { iNumSelectedPackages=p_; }
84 const QHash<QString, Package*>* packagesAvailable() { return &iPackagesAvailable; }
85 const QHash<QString, Package*>* packagesInstalled() { return &iPackagesInstalled; }
86 QList<Repository*>* repositories() { return &iRepositories; }
88 // new api functions to support multiple packages with the same name
90 QList<Package*> allLatestAvailablePackages();
91 QList<Package*> allAvailablePackagesNamed(QString name);
92 Package* findNewestAvailablePackage(QString name);
95 QByteArray readLogFile();
96 void readRepositoryInfo();
97 bool writeRepositories();
98 bool needRepoRefresh();
99 void removeFromBlacklist(Package* pkg, BlacklistSelect::blackList oldstate);
100 void writeBlacklist();
102 bool dateCacheExists();
104 void setNeedRefresh(int repos, int lists, int dpkg, int dates);
105 void setSkipListAndDates() { iSkipRefreshListAndDates=true; }
106 bool needListOrDateRefresh();
108 bool loadInstallFiles(QStringList files_);
110 QDateTime lastListUpdate() { return iLastListUpdate; }
111 QDateTime lastDpkgUpdate() { return iLastDpkgUpdate; }
114 AAptInterface(const AAptInterface& old);
115 AAptInterface operator= (const AAptInterface& old);
118 void cleanAfterRunEach();
119 void cleanAfterRunAll();
120 void cleanAfterError();
122 bool startAptGetUpdate();
123 bool startAptGetSimulate();
124 bool startAptGetInstall();
125 bool startAptGetClean();
127 QString setQProcessErrorMessage(QProcess::ProcessError error);
128 QString finishProcessCommonErrorMessages(QByteArray& output);
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 );
134 void startPkgListRead();
135 void startFetchDates();
137 Package* ReadNextPackage(QFile& f, quint64& currentreaddata);
138 bool processPackageDataLine(Package*& pkg, QByteArray& line);
140 void readBlacklist();
141 void writeDateCache();
142 void readDateCache();
143 void readPinnedPackages();
146 void errorAptGetUpdate(QProcess::ProcessError error);
147 void errorAptGetSimulate(QProcess::ProcessError error);
148 void errorAptGetInstall(QProcess::ProcessError error);
149 void errorAptGetClean(QProcess::ProcessError error);
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);
156 void uiUpdaterAptGetUpdate();
157 void uiUpdaterAptGetInstall();
158 void progressCheckTimerCallback();
160 void dateFetchNetworkReply(QNetworkReply* reply);
163 QHash<QString, Package*> iPackagesAvailable;
164 QHash<QString, Package*> iPackagesInstalled;
165 int iNumSelectedPackages;
167 QStringList iProcessPackages;
168 QStringList iProcessPackagesOrig;
169 QStringList iProcessPackageVersions;
170 QList<interfaceMode> iOperationsQueue;
171 QList<Repository*> iRepositories;
172 QStringList iQueueMessages;
174 MainWindow* iMainWindow;
177 QList<interfaceMode> iModeLog;
182 bool iNeedRepoRefresh;
183 bool iNeedListRefresh;
184 bool iNeedDpkgRefresh;
185 bool iNeedDateRefresh;
186 bool iSkipRefreshListAndDates;
187 QDateTime iLastListUpdate;
188 QDateTime iLastDpkgUpdate;
190 QProcess* iProcAptGetUpdate;
191 QProcess* iProcAptGetSimulate;
192 QProcess* iProcAptGetInstall;
193 QProcess* iProcAptGetClean;
194 QByteArray iProcAptGetUpdateOutput;
195 QByteArray iProcAptGetInstallOutput;
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;
213 QStringList iBlacklist;
215 multiLine iMultiLine;
216 char* iDataReadBuffer;
218 int iDateRequestsWaiting;
219 int iDateRequestsSent;
220 int iDateRequestsReceived;
221 int iDateRequestErrors;
222 QNetworkReply::NetworkError iNetworkError;
226 #endif // AAPTINTERFACE_H