Commit fa278f29 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

Snap: make it possible to install "Classic" apps

Classic, which is an euphemism for unsafe, applications were not
supported so far. Now it will ask the user for confirmation to install.

CCBUG: 392769
parent 3125c8c7
......@@ -160,13 +160,13 @@ Transaction* SnapBackend::installApplication(AbstractResource* app, const AddonL
Transaction* SnapBackend::installApplication(AbstractResource* _app)
{
auto app = qobject_cast<SnapResource*>(_app);
return new SnapTransaction(app, m_client.install(app->packageName()), Transaction::InstallRole, AbstractResource::Installed);
return new SnapTransaction(&m_client, app, Transaction::InstallRole, AbstractResource::Installed);
}
Transaction* SnapBackend::removeApplication(AbstractResource* _app)
{
auto app = qobject_cast<SnapResource*>(_app);
return new SnapTransaction(app, m_client.remove(app->packageName()), Transaction::RemoveRole, AbstractResource::None);
return new SnapTransaction(&m_client, app, Transaction::RemoveRole, AbstractResource::None);
}
QString SnapBackend::displayName() const
......
......@@ -26,22 +26,20 @@
#include <QProcess>
#include <QJsonDocument>
#include <QJsonArray>
#include <KLocalizedString>
#include "libsnapclient/config-paths.h"
#include "utils.h"
SnapTransaction::SnapTransaction(SnapResource* app, QSnapdRequest* request, Role role, AbstractResource::State newState)
SnapTransaction::SnapTransaction(QSnapdClient* client, SnapResource* app, Role role, AbstractResource::State newState)
: Transaction(app, app, role)
, m_client(client)
, m_app(app)
, m_request(request)
, m_newState(newState)
{
setCancellable(false);
connect(request, &QSnapdRequest::progress, this, &SnapTransaction::progressed);
connect(request, &QSnapdRequest::complete, this, &SnapTransaction::finishTransaction);
setStatus(SetupStatus);
setStatus(DownloadingStatus);
request->runAsync();
if (role == RemoveRole)
setRequest(m_client->remove(app->packageName()));
else
setRequest(m_client->install(app->packageName()));
}
void SnapTransaction::cancel()
......@@ -56,6 +54,12 @@ void SnapTransaction::finishTransaction()
static_cast<SnapBackend*>(m_app->backend())->refreshStates();
m_app->setState(m_newState);
break;
case QSnapdRequest::NeedsClassic:
if (role() == Transaction::InstallRole) {
Q_EMIT proceedRequest(m_app->name(), i18n("This snap application needs security confinement measures disabled."));
return;
}
break;
case QSnapdRequest::AuthDataRequired: {
QProcess* p = new QProcess;
p->setProgram(QStringLiteral(CMAKE_INSTALL_FULL_LIBEXECDIR "/discover/SnapMacaroonDialog"));
......@@ -79,6 +83,7 @@ void SnapTransaction::finishTransaction()
});
} return;
default:
qDebug() << "snap error" << m_request << m_request->error() << m_request->errorString();
Q_EMIT passiveMessage(m_request->errorString());
break;
}
......@@ -86,6 +91,24 @@ void SnapTransaction::finishTransaction()
setStatus(DoneStatus);
}
void SnapTransaction::proceed()
{
setRequest(m_client->install(QSnapdClient::Classic, m_app->packageName()));
}
void SnapTransaction::setRequest(QSnapdRequest* req)
{
m_request.reset(req);
setCancellable(false);
connect(m_request.data(), &QSnapdRequest::progress, this, &SnapTransaction::progressed);
connect(m_request.data(), &QSnapdRequest::complete, this, &SnapTransaction::finishTransaction);
setStatus(SetupStatus);
setStatus(DownloadingStatus);
m_request->runAsync();
}
void SnapTransaction::progressed()
{
const auto change = m_request->change();
......
......@@ -27,23 +27,27 @@
class SnapResource;
class QSnapdRequest;
class QSnapdClient;
class SnapTransaction : public Transaction
{
Q_OBJECT
public:
SnapTransaction(SnapResource* app, QSnapdRequest* request, Role role, AbstractResource::State newState);
SnapTransaction(QSnapdClient* client, SnapResource* app, Role role, AbstractResource::State newState);
void cancel() override;
void proceed() override;
private Q_SLOTS:
void finishTransaction();
private:
void setRequest(QSnapdRequest* req);
void progressed();
QSnapdClient * const m_client;
SnapResource * const m_app;
const QScopedPointer<QSnapdRequest> m_request;
QScopedPointer<QSnapdRequest> m_request;
const AbstractResource::State m_newState;
};
......
Supports Markdown
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