mirror of
https://github.com/transmission/transmission
synced 2024-12-30 19:46:56 +00:00
1f28470cf4
Further reading: * https://forum.qt.io/topic/78540/qstringliteral-vs-qlatin1string/2 * https://woboq.com/blog/qstringliteral.html * https://www.qt.io/blog/2014/06/13/qt-weekly-13-qstringliteral tl;dr: QLatin1Literal uses less memory than QStringLiteral; however, since most Qt APIs require a QString argument, there's extra runtime cost of converting QLatin1Strings to QStrings. QStringLiteral uses a little more memory but constructs its QStrings at compile time. ok, the `prefer-qstringliteral` branch is getting out of control: the secondary goal of fixing a .clang-tidy issue is causing more diffs than the primary goal. So, I'm breaking it into two separate PRs.
62 lines
1.6 KiB
C++
62 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 <iostream>
|
|
|
|
#include <QDBusConnection>
|
|
#include <QDBusMessage>
|
|
#include <QDBusReply>
|
|
#include <QString>
|
|
#include <QVariant>
|
|
|
|
#include "DBusInteropHelper.h"
|
|
#include "InteropObject.h"
|
|
|
|
namespace
|
|
{
|
|
|
|
auto const DBUS_SERVICE = QStringLiteral("com.transmissionbt.Transmission");
|
|
auto const DBUS_OBJECT_PATH = QStringLiteral("/com/transmissionbt/Transmission");
|
|
auto const DBUS_INTERFACE = QStringLiteral("com.transmissionbt.Transmission");
|
|
|
|
} // namespace
|
|
|
|
bool DBusInteropHelper::isConnected() const
|
|
{
|
|
return QDBusConnection::sessionBus().isConnected();
|
|
}
|
|
|
|
QVariant DBusInteropHelper::addMetainfo(QString const& metainfo)
|
|
{
|
|
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_SERVICE, DBUS_OBJECT_PATH, DBUS_INTERFACE,
|
|
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)
|
|
{
|
|
QDBusConnection bus = QDBusConnection::sessionBus();
|
|
|
|
if (!bus.isConnected())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!bus.registerService(DBUS_SERVICE))
|
|
{
|
|
std::cerr << "couldn't register " << qPrintable(DBUS_SERVICE) << std::endl;
|
|
}
|
|
|
|
if (!bus.registerObject(DBUS_OBJECT_PATH, new InteropObject(parent), QDBusConnection::ExportAllSlots))
|
|
{
|
|
std::cerr << "couldn't register " << qPrintable(DBUS_OBJECT_PATH) << std::endl;
|
|
}
|
|
}
|