1/*
2 SPDX-FileCopyrightText: Pranav Gade <pranavgade20@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "matchsetting.h"
8#include "matchsetting_p.h"
9
10#include <QDebug>
11
12#if !NM_CHECK_VERSION(1, 14, 0)
13#define NM_SETTING_MATCH_SETTING_NAME "match"
14#define NM_SETTING_MATCH_INTERFACE_NAME "interface-name"
15#endif
16
17NetworkManager::MatchSettingPrivate::MatchSettingPrivate()
18 : name(NM_SETTING_MATCH_SETTING_NAME)
19{
20}
21
22NetworkManager::MatchSetting::MatchSetting()
23 : Setting(Setting::Match)
24 , d_ptr(new MatchSettingPrivate())
25{
26}
27
28NetworkManager::MatchSetting::MatchSetting(const Ptr &other)
29 : Setting(other)
30 , d_ptr(new MatchSettingPrivate())
31{
32 setInterfaceName(other->interfaceName());
33}
34
35NetworkManager::MatchSetting::~MatchSetting()
36{
37 delete d_ptr;
38}
39
40QString NetworkManager::MatchSetting::name() const
41{
42 Q_D(const MatchSetting);
43
44 return d->name;
45}
46
47void NetworkManager::MatchSetting::setInterfaceName(const QStringList &name)
48{
49 Q_D(MatchSetting);
50
51 d->interfaceName = name;
52}
53
54QStringList NetworkManager::MatchSetting::interfaceName() const
55{
56 Q_D(const MatchSetting);
57
58 return d->interfaceName;
59}
60
61void NetworkManager::MatchSetting::fromMap(const QVariantMap &setting)
62{
63 if (setting.contains(key: QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME))) {
64 setInterfaceName(setting.value(key: QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME)).toStringList());
65 }
66}
67
68QVariantMap NetworkManager::MatchSetting::toMap() const
69{
70 QVariantMap setting;
71
72 if (!interfaceName().isEmpty()) {
73 setting.insert(key: QLatin1String(NM_SETTING_MATCH_INTERFACE_NAME), value: interfaceName());
74 }
75
76 return setting;
77}
78
79QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::MatchSetting &setting)
80{
81 dbg.nospace() << "type: " << setting.typeAsString(type: setting.type()) << '\n';
82 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
83
84 dbg.nospace() << NM_SETTING_MATCH_INTERFACE_NAME << ": " << setting.interfaceName() << '\n';
85
86 return dbg.maybeSpace();
87}
88

source code of networkmanager-qt/src/settings/matchsetting.cpp