File indexing completed on 2024-07-07 03:47:43

0001 /*
0002  * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com>
0003  *
0004  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005  */
0006 
0007 #include "obexagentmanager.h"
0008 
0009 #include <QDBusConnection>
0010 #include <QDBusMessage>
0011 
0012 ObexAgentManager::ObexAgentManager(QObject *parent)
0013     : QDBusAbstractAdaptor(parent)
0014 {
0015     setName(QStringLiteral("org.bluez.obex.AgentManager1"));
0016     setPath(QDBusObjectPath(QStringLiteral("/org/bluez/obex")));
0017 }
0018 
0019 void ObexAgentManager::runAction(const QString &actionName, const QVariantMap &properties)
0020 {
0021     if (actionName == QLatin1String("authorize-push")) {
0022         runAuthorizePushAction(properties);
0023     }
0024 }
0025 
0026 void ObexAgentManager::RegisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg)
0027 {
0028     m_agent = path;
0029     m_service = msg.service();
0030 }
0031 
0032 void ObexAgentManager::UnregisterAgent(const QDBusObjectPath &path, const QDBusMessage &msg)
0033 {
0034     if (m_agent == path && m_service == msg.service()) {
0035         m_agent = QDBusObjectPath();
0036         m_service.clear();
0037     }
0038 }
0039 
0040 void ObexAgentManager::runAuthorizePushAction(const QVariantMap &properties)
0041 {
0042     Q_UNUSED(properties)
0043 
0044     QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.obex.Agent1"), QStringLiteral("AuthorizePush"));
0045 
0046     call << QVariant::fromValue(QDBusObjectPath(QStringLiteral("/org/bluez/session1/transfer1")));
0047     const QString &fileName = QDBusConnection::sessionBus().call(call).arguments().first().toString();
0048     Q_UNUSED(fileName)
0049 }
0050 
0051 void ObexAgentManager::runCancelAction()
0052 {
0053     QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.obex.Agent1"), QStringLiteral("Cancel"));
0054     QDBusConnection::sessionBus().call(call);
0055 }
0056 
0057 void ObexAgentManager::runReleaseAction()
0058 {
0059     QDBusMessage call = QDBusMessage::createMethodCall(m_service, m_agent.path(), QStringLiteral("org.bluez.obex.Agent1"), QStringLiteral("Release"));
0060     QDBusConnection::sessionBus().call(call);
0061 }
0062 
0063 #include "moc_obexagentmanager.cpp"