mirror of
https://github.com/transmission/transmission
synced 2024-12-25 01:03:01 +00:00
0bfbc3eba7
* chore: fix some sonarcloud html warnings (e.g. deprecated attribute use) * chore: uppercase literal suffixes * chore: remove redundant casts * chore: remove commented-out code * chore: use qInfo() instead of std::cerr
57 lines
1.6 KiB
C++
57 lines
1.6 KiB
C++
/*
|
|
* 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>
|
|
#include <QtDebug>
|
|
|
|
#include "DBusInteropHelper.h"
|
|
#include "InteropObject.h"
|
|
|
|
bool DBusInteropHelper::isConnected() const
|
|
{
|
|
return QDBusConnection::sessionBus().isConnected();
|
|
}
|
|
|
|
QVariant DBusInteropHelper::addMetainfo(QString const& metainfo)
|
|
{
|
|
auto request = QDBusMessage::createMethodCall(
|
|
QStringLiteral("com.transmissionbt.Transmission"),
|
|
QStringLiteral("/com/transmissionbt/Transmission"),
|
|
QStringLiteral("com.transmissionbt.Transmission"),
|
|
QStringLiteral("AddMetainfo")
|
|
);
|
|
request.setArguments(QVariantList() << metainfo);
|
|
|
|
QDBusReply<bool> const response = QDBusConnection::sessionBus().call(request);
|
|
return response.isValid() ? QVariant(response.value()) : QVariant();
|
|
}
|
|
|
|
void DBusInteropHelper::registerObject(QObject* parent)
|
|
{
|
|
auto bus = QDBusConnection::sessionBus();
|
|
if (!bus.isConnected())
|
|
{
|
|
return;
|
|
}
|
|
|
|
auto const service_name = QStringLiteral("com.transmissionbt.Transmission");
|
|
if (!bus.registerService(service_name))
|
|
{
|
|
qWarning() << "couldn't register" << qPrintable(service_name);
|
|
}
|
|
|
|
auto const object_path = QStringLiteral("/com/transmissionbt/Transmission");
|
|
if (!bus.registerObject(object_path, new InteropObject(parent), QDBusConnection::ExportAllSlots))
|
|
{
|
|
qWarning() << "couldn't register" << qPrintable(object_path);
|
|
}
|
|
}
|