Unverified Commit 7054dc41 authored by azubieta's avatar azubieta

Handle missing settings gracefully

parent 0ba2b0d1
......@@ -21,7 +21,6 @@ extern "C" {
// local
#include <FileDownload.h>
#include "InstallCommand.h"
#include <Settings.h>
InstallCommand::InstallCommand(const QString& appId, QObject* parent) : Command(parent), appId(appId), out(stdout),
fileDownload(nullptr) {
......@@ -34,8 +33,7 @@ InstallCommand::InstallCommand(const QString& appId, QObject* parent) : Command(
}
void InstallCommand::execute() {
Settings settings;
for (const QString& provider: settings.getOCSProviders()) {
for (const QString& provider: ocsProvidersList) {
providerManager.addProviderFile(QUrl(provider));
}
}
......@@ -211,3 +209,7 @@ void InstallCommand::handleAtticaProviderAdded(const Attica::Provider& provider)
void InstallCommand::handleAtticaFailedToLoad(const QUrl& provider, QNetworkReply::NetworkError error) {
emit Command::executionFailed("Unable to connect to " + provider.toString());
}
void InstallCommand::setOcsProvidersList(QStringList list) {
ocsProvidersList = list;
}
......@@ -16,6 +16,8 @@ Q_OBJECT
public:
InstallCommand(const QString& appId, QObject* parent = nullptr);
void setOcsProvidersList(QStringList list);
public slots:
void execute() override;
......@@ -56,4 +58,5 @@ private:
QString targetPath;
QTextStream out;
QStringList ocsProvidersList;
};
......@@ -5,7 +5,6 @@
#include <Attica/Content>
// local
#include <Settings.h>
#include "SearchCommand.h"
SearchCommand::SearchCommand(const QString& query) : query(query) {
......@@ -17,8 +16,7 @@ SearchCommand::SearchCommand(const QString& query) : query(query) {
}
void SearchCommand::execute() {
Settings settings;
for (const QString& providerStr: settings.getOCSProviders()) {
for (const QString& providerStr: ocsProvidersList) {
providerManagers.addProviderFile(QUrl(providerStr));
}
}
......@@ -76,3 +74,7 @@ void SearchCommand::handleAtticaFailedToLoad(const QUrl& provider, QNetworkReply
emit Command::executionFailed("Unable to connect to " + provider.toString());
}
void SearchCommand::setOcsProvidersList(QStringList list) {
ocsProvidersList = list;
}
......@@ -12,6 +12,8 @@ Q_OBJECT
public:
explicit SearchCommand(const QString& query);
void setOcsProvidersList(QStringList list);
public slots:
void execute() override;
......@@ -38,4 +40,5 @@ protected:
QString query;
QStringList applicationsIds;
QStringList ocsProvidersList;
};
......@@ -8,6 +8,7 @@
#include "commands/InstallCommand.h"
#include "commands/ListCommand.h"
#include "commands/RemoveCommand.h"
#include "settings/Settings.h"
int main(int argc, char** argv) {
QCoreApplication app(argc, argv);
......@@ -33,14 +34,24 @@ int main(int argc, char** argv) {
QTextStream out(stdout);
Command* command = nullptr;
Settings settings;
Command* abstractCommand = nullptr;
if (!args.isEmpty() && args.first() == "search") {
args.pop_front();
if (args.empty())
out << "Missing search query. Example:\n"
"\tapp search firefox\n\n";
else
command = new SearchCommand(args.first());
else {
QStringList ocsProvidersList = settings.getOCSProviders();
if (!ocsProvidersList.empty()) {
auto command = new SearchCommand(args.first());
command->setOcsProvidersList(ocsProvidersList);
abstractCommand = command;
} else {
exit(1);
}
}
}
if (!args.isEmpty() && args.first() == "install") {
......@@ -48,12 +59,20 @@ int main(int argc, char** argv) {
if (args.empty())
out << "Missing store id. Example:\n"
"\tapp get 1230\n\n";
else
command = new InstallCommand(args.first());
else {
QStringList ocsProvidersList = settings.getOCSProviders();
if (!ocsProvidersList.empty()) {
auto command = new InstallCommand(args.first());
command->setOcsProvidersList(ocsProvidersList);
abstractCommand = command;
} else {
exit(1);
}
}
}
if (!args.isEmpty() && args.first() == "list")
command = new ListCommand();
abstractCommand = new ListCommand();
if (!args.isEmpty() && args.first() == "remove") {
args.pop_front();
......@@ -61,19 +80,21 @@ int main(int argc, char** argv) {
out << "Missing application id. Example:\n"
"\tapp remove firefox\n\n";
else
command = new RemoveCommand(args.first());
abstractCommand = new RemoveCommand(args.first());
}
if (!args.isEmpty() && args.first() == "update")
out << "ERROR: Updates aren't supported yet. Use AppImageUpate in the meanwhile.\n";
if (command) {
QObject::connect(command, &Command::executionCompleted, &app, &QCoreApplication::quit, Qt::QueuedConnection);
QObject::connect(command, &Command::executionFailed, &app, &QCoreApplication::quit, Qt::QueuedConnection);
QObject::connect(command, &Command::executionFailed, [&out](const QString& message) {
if (abstractCommand) {
QObject::connect(abstractCommand, &Command::executionCompleted, &app, &QCoreApplication::quit,
Qt::QueuedConnection);
QObject::connect(abstractCommand, &Command::executionFailed, &app, &QCoreApplication::quit,
Qt::QueuedConnection);
QObject::connect(abstractCommand, &Command::executionFailed, [&out](const QString& message) {
out << message << '\n';
});
QTimer::singleShot(0, command, &Command::execute);
QTimer::singleShot(0, abstractCommand, &Command::execute);
return QCoreApplication::exec();
} else {
......
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