2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2015-2022 Mnemosyne LLC.
|
2022-02-07 16:25:02 +00:00
|
|
|
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
|
2022-01-20 18:27:56 +00:00
|
|
|
// or any future license endorsed by Mnemosyne LLC.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2015-12-16 17:57:05 +00:00
|
|
|
|
|
|
|
#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"),
|
2021-08-15 09:41:48 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-29 03:03:28 +00:00
|
|
|
if (auto const service_name = QStringLiteral("com.transmissionbt.Transmission"); !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
|
|
|
}
|
|
|
|
|
2022-11-29 03:03:28 +00:00
|
|
|
if (auto const object_path = QStringLiteral("/com/transmissionbt/Transmission");
|
|
|
|
!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
|
|
|
}
|