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 <iostream>
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
#include <QDBusMessage>
|
|
|
|
#include <QDBusReply>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVariant>
|
|
|
|
|
|
|
|
#include "DBusInteropHelper.h"
|
|
|
|
#include "InteropObject.h"
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
auto const DBusService = QStringLiteral("com.transmissionbt.Transmission");
|
|
|
|
auto const DBusObjectPath = QStringLiteral("/com/transmissionbt/Transmission");
|
|
|
|
auto const DBusInterface = QStringLiteral("com.transmissionbt.Transmission");
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
QVariant DBusInteropHelper::addMetainfo(QString const& metainfo)
|
2015-12-16 17:57:05 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
QDBusMessage request = QDBusMessage::createMethodCall(DBusService, DBusObjectPath, DBusInterface,
|
2020-05-29 17:40:07 +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
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QDBusConnection bus = QDBusConnection::sessionBus();
|
|
|
|
|
|
|
|
if (!bus.isConnected())
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
if (!bus.registerService(DBusService))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
std::cerr << "couldn't register " << qPrintable(DBusService) << std::endl;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-06-05 19:02:11 +00:00
|
|
|
if (!bus.registerObject(DBusObjectPath, new InteropObject(parent), QDBusConnection::ExportAllSlots))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-06-05 19:02:11 +00:00
|
|
|
std::cerr << "couldn't register " << qPrintable(DBusObjectPath) << std::endl;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2015-12-16 17:57:05 +00:00
|
|
|
}
|