Unverified Commit 6ba0b878 authored by azubieta's avatar azubieta

Ask wich file to download if there are many

parent 88ee0621
Pipeline #392 failed with stages
in 49 seconds
......@@ -16,7 +16,7 @@ extern "C" {
#include <XdgUtils/DesktopEntry/DesktopEntry.h>
#include <XdgUtils/DesktopEntry/DesktopEntryStringsValue.h>
#include <yaml-cpp/yaml.h>
#include <QTextStream>
// local
#include <FileDownload.h>
......@@ -163,43 +163,85 @@ void InstallCommand::handleGetDownloadLinkJobFinished(Attica::BaseJob* job) {
QString architecture = QSysInfo::buildCpuArchitecture().replace("_", "-");
qDebug() << "Looking for " << architecture << " AppImages";
static QString archTag = "application##architecture=" + architecture;
static QString pkgTypeTag = "application##packagetype=appimage";
QUrl downloadLink;
QList<Attica::DownloadDescription> compatibleDownloads;
auto list = content.downloadUrlDescriptions();
for (const auto& downloadDescription : list) {
if (downloadDescription.tags().contains("application##packagetype=appimage") &&
downloadDescription.tags().contains(archTag)) {
downloadLink = downloadDescription.link();
targetPath = buildTargetPath(content);
if (downloadDescription.tags().contains(pkgTypeTag) &&
(!downloadDescription.tags().contains("application##architecture=") ||
downloadDescription.tags().contains(archTag))) {
break;
compatibleDownloads << downloadDescription;
}
}
if (downloadLink.isEmpty()) {
if (compatibleDownloads.isEmpty()) {
emit executionFailed("Unable to find a download for " + appId);
} else {
createApplicationsDir();
fileDownload = new FileDownload(downloadLink, targetPath, this);
fileDownload->setProgressNotificationsEnabled(true);
connect(fileDownload, &Download::progress, this, &InstallCommand::handleDownloadProgress,
Qt::QueuedConnection);
connect(fileDownload, &Download::completed, this, &InstallCommand::handleDownloadCompleted,
Qt::QueuedConnection);
connect(fileDownload, &Download::stopped, this, &InstallCommand::handleDownloadFailed,
Qt::QueuedConnection);
out << "Downloading " << appId << " from " << downloadLink.toString() << "\n";
fileDownload->start();
targetPath = buildTargetPath(content);
int userPick = 0;
if (compatibleDownloads.size() != 1)
userPick = askWhichFileDownload(compatibleDownloads);
else
userPick = 1;
if (userPick == -1) {
emit Command::executionCompleted();
return;
} else {
const QUrl link = compatibleDownloads.at(userPick - 1).link();
startFileDownload(link);
}
}
} else
emit executionFailed("Unable to resolve the application download link.");
}
int InstallCommand::askWhichFileDownload(const QList<Attica::DownloadDescription>& compatibleDownloads) {
int userPick;
out << "Available AppImage files:\n";
for (int i = 1; i <= compatibleDownloads.size(); i++) {
const auto& downloadDescription = compatibleDownloads.at(i - 1);
out << i << "- " << downloadDescription.name() << "\n";
}
QTextStream in(stdin);
while (userPick <= 0 || userPick > compatibleDownloads.size()) {
out << "Enter the file number to download or 'x' to exit: ";
out.flush();
QString line = in.readLine();
if (line.startsWith("x"))
return -1;
bool isInt = false;
userPick = line.toInt(&isInt);
if (!isInt || userPick <= 0 || userPick > compatibleDownloads.size())
out << "Invalid option\n";
}
return userPick;
}
void InstallCommand::startFileDownload(const QUrl& downloadLink) {
createApplicationsDir();
fileDownload = new FileDownload(downloadLink, targetPath, this);
fileDownload->setProgressNotificationsEnabled(true);
connect(fileDownload, &Download::progress, this, &InstallCommand::handleDownloadProgress,
Qt::QueuedConnection);
connect(fileDownload, &Download::completed, this, &InstallCommand::handleDownloadCompleted,
Qt::QueuedConnection);
connect(fileDownload, &Download::stopped, this, &InstallCommand::handleDownloadFailed,
Qt::QueuedConnection);
out << "Downloading " << appId << " from " << downloadLink.toString() << "\n";
fileDownload->start();
}
void InstallCommand::handleAtticaProviderAdded(const Attica::Provider& provider) {
InstallCommand::provider = provider;
......
......@@ -5,6 +5,7 @@
#include <QString>
#include <Attica/ProviderManager>
#include <Attica/ListJob>
#include <Attica/DownloadDescription>
// local
#include <Command.h>
......@@ -59,4 +60,8 @@ private:
QTextStream out;
QStringList ocsProvidersList;
void startFileDownload(const QUrl& downloadLink);
int askWhichFileDownload(const QList<Attica::DownloadDescription>& compatibleDownloads);
};
......@@ -47,7 +47,7 @@ int main(int argc, char** argv) {
const char* msgPrefix;
// Ignore debug unless in verbose mode
if (!verboseMode && type < QtInfoMsg)
if (!verboseMode && type == QtDebugMsg)
return;
switch (type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment