diff --git a/src/util/externalcommand_polkitbackend.h b/src/util/externalcommand_polkitbackend.h --- a/src/util/externalcommand_polkitbackend.h +++ b/src/util/externalcommand_polkitbackend.h @@ -115,6 +115,7 @@ void authStatusChanged(); Q_SIGNALS: + void actionAuthorized(); void actionPerformed(); private: diff --git a/src/util/externalcommand_polkitbackend.cpp b/src/util/externalcommand_polkitbackend.cpp --- a/src/util/externalcommand_polkitbackend.cpp +++ b/src/util/externalcommand_polkitbackend.cpp @@ -153,6 +153,7 @@ } if (event.result() == Authority::Yes) { + emit actionAuthorized(); return true; } else { return false; diff --git a/src/util/externalcommandhelper.h b/src/util/externalcommandhelper.h --- a/src/util/externalcommandhelper.h +++ b/src/util/externalcommandhelper.h @@ -41,7 +41,7 @@ bool writeData(const QString& targetDevice, const QByteArray& buffer, const qint64 offset); public Q_SLOTS: - Q_SCRIPTABLE QVariantMap init(QVariantMap reply); + Q_SCRIPTABLE int helperMain(int argc, char **argv); Q_SCRIPTABLE QVariantMap start(const QString& command, const QStringList& arguments, const QByteArray& input, const int processChannelMode); Q_SCRIPTABLE QVariantMap copyblocks(const QString& sourceDevice, const qint64 sourceFirstByte, const qint64 sourceLength, const QString& targetDevice, const qint64 targetFirstByte, const qint64 blockSize); Q_SCRIPTABLE bool writeData(const QByteArray& buffer, const QString& targetDevice, const qint64 targetFirstByte); diff --git a/src/util/externalcommandhelper.cpp b/src/util/externalcommandhelper.cpp --- a/src/util/externalcommandhelper.cpp +++ b/src/util/externalcommandhelper.cpp @@ -27,9 +27,11 @@ #include #include -#include #include +#define HELPER_MAIN() \ + int main(int argc, char **argv) { ExternalCommandHelper helper; return helper.helperMain(argc, argv); } + /** Initialize ExternalCommandHelper Daemon and prepare DBus interface * * Helper runs in the background until application exits. @@ -44,25 +46,32 @@ * command execution requests from the application that started the helper. * */ -QVariantMap ExternalCommandHelper::init(QVariantMap reply) + +/** Reads the given number of bytes from the sourceDevice into the given buffer. + @param argc argument count + @param argv argumnet vector + @return 0 on success, non-zero on failure +*/ +int ExternalCommandHelper::helperMain(int argc, char **argv) { - if (!QDBusConnection::systemBus().isConnected() || !QDBusConnection::systemBus().registerService(QStringLiteral("org.kde.kpmcore.helperinterface")) || + QCoreApplication app(argc, argv); + + if (!QDBusConnection::systemBus().isConnected() || + !QDBusConnection::systemBus().registerService(QStringLiteral("org.kde.kpmcore.helperinterface")) || !QDBusConnection::systemBus().registerObject(QStringLiteral("/Helper"), this, QDBusConnection::ExportAllSlots)) { + qDebug() << "Failed to initialize the Helper"; qWarning() << QDBusConnection::systemBus().lastError().message(); - reply[QStringLiteral("success")] = false; - // End the application loop started by KAuth's main() code. Our loop - // exits when our client disappears. Without client we have no reason to - // live. + // We have no reason to live when Main GUI app has expired qApp->quit(); - - return reply; + + return app.exec(); } m_loop = std::make_unique(); emit reportProgress(QVariantMap()); - // QDBus Srvice watcher which keeps an eye on the client (Main GUI app) + // QDBus Service watcher which keeps an eye on the client (Main GUI app) // End the loop and return only once the client has unregistered over the QDBus. auto serviceWatcher = new QDBusServiceWatcher(QStringLiteral("org.kde.kpmcore.applicationinterface"), QDBusConnection::systemBus(), @@ -75,11 +84,10 @@ }); m_loop->exec(); - reply[QStringLiteral("success")] = true; - - qApp->quit(); - return reply; + qApp->quit(); + + return app.exec(); } @@ -307,6 +315,6 @@ *report() << QString::fromLocal8Bit(s); }*/ -KAUTH_HELPER_MAIN("org.kde.kpmcore.externalcommand", ExternalCommandHelper) +HELPER_MAIN() #include "moc_externalcommandhelper.cpp"