File indexing completed on 2023-09-24 04:02:12

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 "object.h"
0008 
0009 #include <QDBusConnection>
0010 #include <QDBusMessage>
0011 
0012 Object::Object()
0013     : m_parent(nullptr)
0014 {
0015 }
0016 
0017 QObject *Object::objectParent() const
0018 {
0019     return m_parent;
0020 }
0021 
0022 void Object::setObjectParent(QObject *parent)
0023 {
0024     m_parent = parent;
0025 }
0026 
0027 QDBusObjectPath Object::path() const
0028 {
0029     return m_path;
0030 }
0031 
0032 void Object::setPath(const QDBusObjectPath &path)
0033 {
0034     m_path = path;
0035 }
0036 
0037 QString Object::name() const
0038 {
0039     return m_name;
0040 }
0041 
0042 void Object::setName(const QString &name)
0043 {
0044     m_name = name;
0045 }
0046 
0047 bool Object::haveProperties() const
0048 {
0049     return !m_properties.isEmpty();
0050 }
0051 
0052 QVariantMap Object::properties() const
0053 {
0054     return m_properties;
0055 }
0056 
0057 void Object::setProperties(const QVariantMap &properties)
0058 {
0059     m_properties = properties;
0060 }
0061 
0062 QVariant Object::property(const QString &name) const
0063 {
0064     return m_properties.value(name);
0065 }
0066 
0067 void Object::changeProperty(const QString &name, const QVariant &value)
0068 {
0069     if (m_properties.value(name) == value) {
0070         return;
0071     }
0072 
0073     QVariantMap updatedProperties;
0074     updatedProperties[name] = value;
0075 
0076     m_properties[name] = value;
0077 
0078     QDBusMessage signal = QDBusMessage::createSignal(m_path.path(), QStringLiteral("org.freedesktop.DBus.Properties"), QStringLiteral("PropertiesChanged"));
0079     signal << m_name;
0080     signal << updatedProperties;
0081     signal << QStringList();
0082     QDBusConnection::sessionBus().send(signal);
0083 }