Verified Commit 18f5bd1e authored by azubieta's avatar azubieta
Browse files

Add install command

parent 1af17332
Pipeline #659 passed with stage
in 6 minutes and 48 seconds
......@@ -3,6 +3,7 @@ add_executable(
main.cpp
UpdateJob.cpp
RemoveJob.cpp
InstallJob.cpp
)
target_link_libraries(plasma-appimage-integration appimageservices-interfaces KF5::KIOWidgets KF5::I18n KF5::Notifications)
......
// libraries
#include <QtCore/QTimer>
#include <QtCore/QDebug>
#include <KI18n/KLocalizedString>
#include <utility>
// local
#include "InstallJob.h"
InstallJob::InstallJob(QString target, QObject* parent) : KJob(parent), target(std::move(target)) {}
void InstallJob::start() {
process.setProgram("pkexec");
process.setArguments({"appimage-services", "install", target});
qDebug() << "calling pkexec appimage-services install " << target;
connect(&process, SIGNAL(finished(int)), this, SLOT(onProcessFinished(int)));
description(this, i18n("Installing Application"),
qMakePair<QString, QString>(i18nc("The AppImage being installed", "Source"), target));
process.start();
}
void InstallJob::onProcessFinished(int exitCode) {
qDebug() << exitCode;
qDebug() << process.errorString();
if (exitCode != 0) {
setError(exitCode);
setErrorText(process.readAllStandardError());
}
// notify result delayed
QTimer::singleShot(1000, this, &InstallJob::emitResult);
}
#pragma once
// libraries
#include <KJob>
#include <QtCore/QProcess>
class InstallJob : public KJob {
Q_OBJECT
public:
explicit InstallJob(QString target, QObject* parent = nullptr);
void start() override;
protected slots:
void onProcessFinished(int exitCode);
private:
QString target;
QProcess process;
};
......@@ -11,6 +11,7 @@
// local
#include "UpdateJob.h"
#include "RemoveJob.h"
#include "InstallJob.h"
QString parseTarget(QCommandLineParser& parser) {
......@@ -51,6 +52,13 @@ void executeRemoveCommand(const QString& target) {
}
void executeInstallCommand(const QString& target) {
KJob* job = new InstallJob(target);
KIO::getJobTracker()->registerJob(job);
job->start();
}
int main(int argc, char** argv) {
QApplication app(argc, argv);
QApplication::setApplicationName("plasma-appimage-integration");
......@@ -82,6 +90,10 @@ int main(int argc, char** argv) {
executeRemoveCommand(target);
}
if (command == "install") {
QString target = parseTarget(parser);
executeInstallCommand(target);
}
return QApplication::exec();
}
......
......@@ -45,7 +45,7 @@ QList<QAction*> AppImageFileItemActions::actions(const KFileItemListProperties&
actions += createRemoveFromMenuAction(fileItemInfos, parentWidget);
}
} else {
qWarning() << "Unable to connect to the AppImage Launcher Service";
qWarning() << "Discarding AppImage Add/Remove to Menu actions. Unable to connect to the AppImage Launcher Service";
}
if (launcherInterface->isValid()) {
......@@ -55,9 +55,11 @@ QList<QAction*> AppImageFileItemActions::actions(const KFileItemListProperties&
connect(updateAction, &QAction::triggered, this, &AppImageFileItemActions::update);
actions += updateAction;
} else {
qWarning() << "Unable to connect to the AppImage Updater Service";
qWarning() << "Discarding AppImage Update action. Unable to connect to the AppImage Launcher Updater";
}
actions += createInstallAction(fileItemInfos, parentWidget);
return actions;
}
......@@ -81,6 +83,15 @@ QAction* AppImageFileItemActions::createAddToMenuAction(const KFileItemListPrope
return addToMenuAction;
}
QAction *AppImageFileItemActions::createInstallAction(const KFileItemListProperties &fileItemInfos,
QWidget *parentWidget) const {
QAction* installAction = new QAction(QIcon::fromTheme("install"), "Install", parentWidget);
installAction->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList()));
installAction->setProperty("parentWidget", QVariant::fromValue(parentWidget));
connect(installAction, &QAction::triggered, this, &AppImageFileItemActions::install);
return installAction;
}
void AppImageFileItemActions::addToMenu() {
const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
QWidget* parentWidget = sender()->property("parentWidget").value<QWidget*>();
......@@ -123,6 +134,18 @@ void AppImageFileItemActions::update() {
}
}
void AppImageFileItemActions::install() {
const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
QString program = "plasma-appimage-integration";
for (const QUrl& url : urls) {
QStringList arguments;
arguments << "install" << url.toLocalFile();
QProcess::startDetached(program, arguments);
}
}
void AppImageFileItemActions::showErrorMessage(const QString& title, const QString& message, QWidget* parentWidget) {
KNotification* notify = new KNotification(QStringLiteral("notification"), parentWidget,
KNotification::CloseOnTimeout | KNotification::DefaultEvent);
......
......@@ -33,6 +33,8 @@ private Q_SLOTS:
void update();
void install();
private:
OrgAppimageServices1LauncherInterface* launcherInterface;
OrgAppimageServices1UpdaterInterface* updaterInterface;
......@@ -42,4 +44,6 @@ private:
QAction* createAddToMenuAction(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) const;
QAction* createRemoveFromMenuAction(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) const;
QAction* createInstallAction(const KFileItemListProperties& fileItemInfos, QWidget* parentWidget) const;
};
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