NetworkManagerQt

fakenetwork/settings.cpp
1/*
2 SPDX-FileCopyrightText: 2014 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "settings.h"
8
9#include <QDBusConnection>
10#include <QDBusMetaType>
11
12Settings::Settings(QObject *parent)
13 : QObject(parent)
14 , m_canModify(true)
15 , m_hostname(QLatin1String("fake-hostname"))
16 , m_connectionCounter(0)
17{
18 qDBusRegisterMetaType<NMVariantMapMap>();
19}
20
21Settings::~Settings()
22{
23 for (auto it = m_connections.cbegin(); it != m_connections.cend(); ++it) {
24 const QDBusObjectPath &connection = it.key();
26 Q_EMIT ConnectionRemoved(connection);
27 }
28
29 qDeleteAll(m_connections);
30}
31
32bool Settings::canModify() const
33{
34 return m_canModify;
35}
36
37QList<QDBusObjectPath> Settings::connections() const
38{
39 return m_connections.keys();
40}
41
42QString Settings::hostname() const
43{
44 return m_hostname;
45}
46
47QDBusObjectPath Settings::AddConnection(const NMVariantMapMap &connection)
48{
49 Connection *newConnection = new Connection(this, connection);
50 QString newConnectionPath = QString("/org/kde/fakenetwork/Settings/") + QString::number(m_connectionCounter++);
51 newConnection->setConnectionPath(newConnectionPath);
52 m_connections.insert(QDBusObjectPath(newConnectionPath), newConnection);
54
55 connect(newConnection, &Connection::connectionRemoved, this, &Settings::onConnectionRemoved);
56
57 Q_EMIT NewConnection(QDBusObjectPath(newConnectionPath));
58 // Send it for FakeNetwork separately to get AvailableConnections signal after NewConnection
59 Q_EMIT connectionAdded(QDBusObjectPath(newConnectionPath));
60
61 return QDBusObjectPath(newConnectionPath);
62}
63
64QDBusObjectPath Settings::AddConnectionUnsaved(const NMVariantMapMap &connection)
65{
66 Q_UNUSED(connection)
67 // TODO
68 return QDBusObjectPath();
69}
70
71QDBusObjectPath Settings::GetConnectionByUuid(const QString &uuid)
72{
73 Q_UNUSED(uuid)
74 // TODO
75 return QDBusObjectPath();
76}
77
78QList<QDBusObjectPath> Settings::ListConnections()
79{
80 return m_connections.keys();
81}
82
83void Settings::SaveHostname(const QString &hostname)
84{
85 m_hostname = hostname;
86}
87
88void Settings::onConnectionRemoved(const QDBusObjectPath &connectionPath)
89{
90 Connection *connection = m_connections.value(connectionPath);
91
92 if (connection) {
94 Q_EMIT ConnectionRemoved(connectionPath);
95 // Send it for FakeNetwork separately to get AvailableConnections signal after ConnectionRemoved
96 Q_EMIT connectionRemoved(connectionPath);
97 m_connections.remove(QDBusObjectPath(connectionPath));
98 delete connection;
99 }
100}
101
102#include "moc_settings.cpp"
NETWORKMANAGERQT_EXPORT QString hostname()
Returns hostname of the machine.
Definition settings.cpp:260
bool registerObject(const QString &path, QObject *object, RegisterOptions options)
QDBusConnection sessionBus()
void unregisterObject(const QString &path, UnregisterMode mode)
QString path() const const
const_iterator cbegin() const const
const_iterator cend() const const
iterator insert(const Key &key, const T &value)
QList< Key > keys() const const
size_type remove(const Key &key)
T value(const Key &key, const T &defaultValue) const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString number(double n, char format, int precision)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.