2015-12-16 17:57:05 +00:00
|
|
|
/*
|
|
|
|
* This file Copyright (C) 2015 Mnemosyne LLC
|
|
|
|
*
|
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusReply>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
2020-11-02 15:16:12 +00:00
|
|
|
#include <QtDebug>
|
2015-12-16 17:57:05 +00:00
|
|
|
|
|
|
|
#include "DBusInteropHelper.h"
|
|
|
|
#include "InteropObject.h"
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool DBusInteropHelper::isConnected() const
|
2015-12-16 17:57:05 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return QDBusConnection::sessionBus().isConnected();
|
2015-12-16 17:57:05 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 03:31:02 +00:00
|
|
|
QVariant DBusInteropHelper::addMetainfo(QString const& metainfo) const
|
2015-12-16 17:57:05 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
auto request = QDBusMessage::createMethodCall(
|
|
|
|
QStringLiteral("com.transmissionbt.Transmission"),
|
2020-08-17 01:43:14 +00:00
|
|
|
QStringLiteral("/com/transmissionbt/Transmission"),
|
2020-08-15 15:42:51 +00:00
|
|
|
QStringLiteral("com.transmissionbt.Transmission"),
|
|
|
|
QStringLiteral("AddMetainfo")
|
|
|
|
);
|
2017-04-19 12:04:45 +00:00
|
|
|
request.setArguments(QVariantList() << metainfo);
|
2015-12-16 17:57:05 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QDBusReply<bool> const response = QDBusConnection::sessionBus().call(request);
|
2017-04-19 12:04:45 +00:00
|
|
|
return response.isValid() ? QVariant(response.value()) : QVariant();
|
2015-12-16 17:57:05 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void DBusInteropHelper::registerObject(QObject* parent)
|
2015-12-16 17:57:05 +00:00
|
|
|
{
|
2020-08-15 15:42:51 +00:00
|
|
|
auto bus = QDBusConnection::sessionBus();
|
2017-04-19 12:04:45 +00:00
|
|
|
if (!bus.isConnected())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-15 15:42:51 +00:00
|
|
|
auto const service_name = QStringLiteral("com.transmissionbt.Transmission");
|
|
|
|
if (!bus.registerService(service_name))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-02 15:16:12 +00:00
|
|
|
qWarning() << "couldn't register" << qPrintable(service_name);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-08-17 01:43:14 +00:00
|
|
|
auto const object_path = QStringLiteral("/com/transmissionbt/Transmission");
|
2020-08-15 15:42:51 +00:00
|
|
|
if (!bus.registerObject(object_path, new InteropObject(parent), QDBusConnection::ExportAllSlots))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-11-02 15:16:12 +00:00
|
|
|
qWarning() << "couldn't register" << qPrintable(object_path);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-12-16 17:57:05 +00:00
|
|
|
}
|