| 1 | /* |
|---|---|
| 2 | SPDX-FileCopyrightText: 2014 Lukáš Tinkl <ltinkl@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 "teamsetting.h" |
| 8 | #include "manager.h" |
| 9 | #include "teamsetting_p.h" |
| 10 | |
| 11 | #define NM_SETTING_TEAM_INTERFACE_NAME "interface-name" |
| 12 | |
| 13 | #include <QDebug> |
| 14 | |
| 15 | NetworkManager::TeamSettingPrivate::TeamSettingPrivate() |
| 16 | : name(NM_SETTING_TEAM_SETTING_NAME) |
| 17 | { |
| 18 | } |
| 19 | |
| 20 | NetworkManager::TeamSetting::TeamSetting() |
| 21 | : Setting(Setting::Team) |
| 22 | , d_ptr(new TeamSettingPrivate()) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | NetworkManager::TeamSetting::TeamSetting(const Ptr &other) |
| 27 | : Setting(other) |
| 28 | , d_ptr(new TeamSettingPrivate()) |
| 29 | { |
| 30 | setInterfaceName(other->interfaceName()); |
| 31 | setConfig(other->config()); |
| 32 | } |
| 33 | |
| 34 | NetworkManager::TeamSetting::~TeamSetting() |
| 35 | { |
| 36 | delete d_ptr; |
| 37 | } |
| 38 | |
| 39 | QString NetworkManager::TeamSetting::name() const |
| 40 | { |
| 41 | Q_D(const TeamSetting); |
| 42 | |
| 43 | return d->name; |
| 44 | } |
| 45 | |
| 46 | void NetworkManager::TeamSetting::setInterfaceName(const QString &name) |
| 47 | { |
| 48 | Q_D(TeamSetting); |
| 49 | |
| 50 | d->interfaceName = name; |
| 51 | } |
| 52 | |
| 53 | QString NetworkManager::TeamSetting::interfaceName() const |
| 54 | { |
| 55 | Q_D(const TeamSetting); |
| 56 | |
| 57 | return d->interfaceName; |
| 58 | } |
| 59 | |
| 60 | QString NetworkManager::TeamSetting::config() const |
| 61 | { |
| 62 | Q_D(const TeamSetting); |
| 63 | return d->config; |
| 64 | } |
| 65 | |
| 66 | void NetworkManager::TeamSetting::setConfig(const QString &config) |
| 67 | { |
| 68 | Q_D(TeamSetting); |
| 69 | d->config = config; |
| 70 | } |
| 71 | |
| 72 | void NetworkManager::TeamSetting::fromMap(const QVariantMap &setting) |
| 73 | { |
| 74 | if (setting.contains(key: QLatin1String(NM_SETTING_TEAM_INTERFACE_NAME))) { |
| 75 | setInterfaceName(setting.value(key: QLatin1String(NM_SETTING_TEAM_INTERFACE_NAME)).toString()); |
| 76 | } |
| 77 | |
| 78 | if (setting.contains(key: QLatin1String(NM_SETTING_TEAM_CONFIG))) { |
| 79 | setConfig(setting.value(key: QLatin1String(NM_SETTING_TEAM_CONFIG)).toString()); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | QVariantMap NetworkManager::TeamSetting::toMap() const |
| 84 | { |
| 85 | QVariantMap setting; |
| 86 | |
| 87 | if (!interfaceName().isEmpty()) { |
| 88 | setting.insert(key: QLatin1String(NM_SETTING_TEAM_INTERFACE_NAME), value: interfaceName()); |
| 89 | } |
| 90 | if (!config().isEmpty()) { |
| 91 | setting.insert(key: QLatin1String(NM_SETTING_TEAM_CONFIG), value: config()); |
| 92 | } |
| 93 | |
| 94 | return setting; |
| 95 | } |
| 96 | |
| 97 | QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::TeamSetting &setting) |
| 98 | { |
| 99 | dbg.nospace() << "type: "<< setting.typeAsString(type: setting.type()) << '\n'; |
| 100 | dbg.nospace() << "initialized: "<< !setting.isNull() << '\n'; |
| 101 | |
| 102 | dbg.nospace() << NM_SETTING_TEAM_INTERFACE_NAME << ": "<< setting.interfaceName() << '\n'; |
| 103 | dbg.nospace() << NM_SETTING_TEAM_CONFIG << ": "<< setting.config() << '\n'; |
| 104 | |
| 105 | return dbg.maybeSpace(); |
| 106 | } |
| 107 |
