Verified Commit dfa06f3a authored by azubieta's avatar azubieta
Browse files

Add register job

parent bb370a6f
...@@ -2,6 +2,7 @@ add_executable( ...@@ -2,6 +2,7 @@ add_executable(
plasma-appimage-integration plasma-appimage-integration
main.cpp main.cpp
UpdateJob.cpp UpdateJob.cpp
RegisterJob.cpp
RemoveJob.cpp RemoveJob.cpp
InstallJob.cpp InstallJob.cpp
UninstallJob.cpp UninstallJob.cpp
......
// libraries
#include <KLocalizedString>
// local
#include "RegisterJob.h"
#include "LauncherInterface.h"
RegisterJob::RegisterJob(const QString& target, QObject* parent)
: KJob(parent), target(target),
launcherInterface(new OrgAppimageServices1LauncherInterface("org.appimage.Services1.Launcher",
"/org/appimage/Services1/Launcher",
QDBusConnection::sessionBus(), this)) {}
void RegisterJob::start() {
description(this, i18n("Creating launcher entry"),
qMakePair<QString, QString>(i18nc("Target AppImage", "Application"), target));
auto reply = launcherInterface->registerApp(target);
if (reply.isError()) {
setError(-1);
setErrorText(reply.error().message());
}
auto* watcher = new QDBusPendingCallWatcher(reply, this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, &RegisterJob::callFinishedSlot);
}
void RegisterJob::callFinishedSlot(QDBusPendingCallWatcher* watcher) {
if (watcher->isError()) {
setError(-1);
setErrorText(watcher->error().message());
}
// notify result delayed
QTimer::singleShot(1000, this, &RegisterJob::emitResult);
}
#pragma once
// libraries
#include <KJob>
#include <QUrl>
class QDBusPendingCallWatcher;
class OrgAppimageServices1LauncherInterface;
class RegisterJob : public KJob {
public:
RegisterJob(const QString& target, QObject* parent = nullptr);
void start() override;
protected slots:
void callFinishedSlot(QDBusPendingCallWatcher* watcher);
private:
QString target;
OrgAppimageServices1LauncherInterface* launcherInterface;
};
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
// local // local
#include "UpdateJob.h" #include "UpdateJob.h"
#include "RegisterJob.h"
#include "RemoveJob.h" #include "RemoveJob.h"
#include "InstallJob.h" #include "InstallJob.h"
#include "UninstallJob.h" #include "UninstallJob.h"
...@@ -66,6 +67,11 @@ int main(int argc, char** argv) { ...@@ -66,6 +67,11 @@ int main(int argc, char** argv) {
job = new RemoveJob(target); job = new RemoveJob(target);
} }
if (command == "register") {
target = parseTarget(parser);
job = new RegisterJob(target);
}
if (command == "install") { if (command == "install") {
target = parseTarget(parser); target = parseTarget(parser);
job = new InstallJob(target); job = new InstallJob(target);
......
...@@ -94,25 +94,13 @@ QAction *AppImageFileItemActions::createInstallAction(const KFileItemListPropert ...@@ -94,25 +94,13 @@ QAction *AppImageFileItemActions::createInstallAction(const KFileItemListPropert
void AppImageFileItemActions::addToMenu() { void AppImageFileItemActions::addToMenu() {
const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>(); const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
QWidget* parentWidget = sender()->property("parentWidget").value<QWidget*>(); QString program = "plasma-appimage-integration";
QList<QDBusPendingReply<bool>> replies; for (const QUrl& url : urls) {
for (const QUrl& url : urls) QStringList arguments;
replies += launcherInterface->registerApp(url.toString()); arguments << "register" << url.toLocalFile();
QString errorTitle = i18n("Add to launcher failed"); QProcess::startDetached(program, arguments);
for (QDBusPendingReply<bool>& reply: replies) {
reply.waitForFinished();
if (reply.isError())
showErrorMessage(errorTitle, reply.error().message(), parentWidget);
else {
// notify failed operation
if (!reply.value()) {
QString url = urls.at(replies.indexOf(reply)).toString();
showErrorMessage(errorTitle, i18n("\"%0\"\nthe file seems broken").arg(url), parentWidget);
}
}
} }
} }
......
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