[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Blibqapt=5D_src=3A_Add_Backend=3A=3AsaveDownloadList?=
From: Jonathan Thomas <echidnaman () kubuntu ! org>
Date: 2011-01-31 23:43:12
Message-ID: 20110131234312.87888A609B () git ! kde ! org
[Download RAW message or body]
Git commit eafb70b79b865f1f6f9f495f978b2cca29b57878 by Jonathan Thomas.
Pushed by jmthomas into branch 'master'.
Add Backend::saveDownloadList() to create a download list usable by the \
downloadArchives() function Also change downloadArchives to take the file name of the \
download list and have it make the QStringList from that, rather than passing it one.
M +45 -1 src/backend.cpp
M +20 -1 src/backend.h
http://commits.kde.org/libqapt/eafb70b79b865f1f6f9f495f978b2cca29b57878
diff --git a/src/backend.cpp b/src/backend.cpp
index 6845f57..198e04c 100644
--- a/src/backend.cpp
+++ b/src/backend.cpp
@@ -833,10 +833,37 @@ void Backend::commitChanges()
d->worker->commitChanges(packageList);
}
-void Backend::downloadArchives(const QStringList &packages, const QString \
&destination) +void Backend::downloadArchives(const QString &listFile, const QString \
&destination) {
Q_D(Backend);
+ QFile file(listFile);
+
+ if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ // TODO: error
+ return;
+ }
+
+ QByteArray buffer = file.readAll();
+
+ QList<QByteArray> lines = buffer.split('\n');
+
+ if (lines.isEmpty() || lines.first() != QByteArray("[Download List]")) {
+ return;
+ }
+
+ lines.removeAt(0);
+
+ QStringList packages;
+ foreach (const QByteArray &line, lines) {
+ packages << line;
+ }
+
+ QString dirName = listFile.left(listFile.lastIndexOf('/'));
+
+ QDir dir(dirName);
+ dir.mkdir(QLatin1String("packages"));
+
d->worker->setLocale(QLatin1String(setlocale(LC_MESSAGES, 0)));
d->worker->downloadArchives(packages, destination);
}
@@ -987,6 +1014,23 @@ bool Backend::loadSelections(const QString &path)
return true;
}
+bool Backend::saveDownloadList(const QString &path) const
+{
+ Q_D(const Backend);
+
+ QString downloadDocument;
+ downloadDocument.append(QLatin1String("[Download List]") % QLatin1Char('\n'));
+ for (int i = 0; i < d->packages.size(); ++i) {
+ int flags = d->packages.at(i)->state();
+
+ if (flags & Package::ToInstall) {
+ downloadDocument.append(d->packages[i]->name() % QLatin1Char('\n'));
+ }
+ }
+
+ return d->writeSelectionFile(downloadDocument, path);
+}
+
bool Backend::setPackagePinned(Package *package, bool pin)
{
Q_D(Backend);
diff --git a/src/backend.h b/src/backend.h
index a3b8d45..4688b5e 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -548,7 +548,15 @@ public Q_SLOTS:
*/
void commitChanges();
- void downloadArchives(const QStringList &packages, const QString &destination);
+ /**
+ * Downloads the packages listed in the provided list file to the provided
+ * destination directory. The worker sends normal download event signals
+ * as usual, and this can be handled exactly like any other package download
+ *
+ * @param listFile The path to the package list file
+ * @param destination The path of the directory to download the packages to
+ */
+ void downloadArchives(const QString &listFile, const QString &destination);
/**
* A slot that Packages use to tell the backend they've changed.
@@ -638,6 +646,17 @@ public Q_SLOTS:
bool loadSelections(const QString &path);
/**
+ * Writes a list of packages that have been marked for installation. This
+ * list can then be loaded with the loadDownloadList() function to start
+ * downloading the packages.
+ *
+ * @param path The path to save the download list to
+ *
+ * @return @c true if savign succeeded, @c false if the saving failed
+ */
+ bool saveDownloadList(const QString &path) const;
+
+ /**
* Locks the package at either the current version if installed, or
* prevents automatic installation if not installed.
*
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic