vlanwidget.cpp 3.66 KB
Newer Older
Lukáš Tinkl's avatar
Lukáš Tinkl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
    Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) version 3, or any
    later version accepted by the membership of KDE e.V. (or its
    successor approved by the membership of KDE e.V.), which shall
    act as a proxy defined in Section 6 of version 3 of the license.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "vlanwidget.h"
#include "ui_vlan.h"
#include "uiutils.h"

25
#include <NetworkManagerQt/VlanSetting>
Lukáš Tinkl's avatar
Lukáš Tinkl committed
26 27
#include <NetworkManagerQt/Settings>

28
VlanWidget::VlanWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f):
Lukáš Tinkl's avatar
Lukáš Tinkl committed
29 30 31 32 33 34 35
    SettingWidget(setting, parent, f),
    m_ui(new Ui::VlanWidget)
{
    m_ui->setupUi(this);

    fillConnections();

36
    connect(m_ui->ifaceName, &KLineEdit::textChanged, this, &VlanWidget::slotWidgetChanged);
37
    connect(m_ui->parent, QOverload<int>::of(&KComboBox::currentIndexChanged), this, &VlanWidget::slotWidgetChanged);
38
    connect(m_ui->parent->lineEdit(), &QLineEdit::textChanged, this, &VlanWidget::slotWidgetChanged);
39

40 41 42
    // Connect for setting check
    watchChangedSetting();

43 44
    KAcceleratorManager::manage(this);

45
    if (setting) {
Lukáš Tinkl's avatar
Lukáš Tinkl committed
46
        loadConfig(setting);
47
    }
Lukáš Tinkl's avatar
Lukáš Tinkl committed
48 49 50 51
}

VlanWidget::~VlanWidget()
{
Jan Grulich's avatar
Jan Grulich committed
52
    delete m_ui;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
53 54
}

55
void VlanWidget::loadConfig(const NetworkManager::Setting::Ptr &setting)
Lukáš Tinkl's avatar
Lukáš Tinkl committed
56
{
57
    NetworkManager::VlanSetting::Ptr vlanSetting = setting.staticCast<NetworkManager::VlanSetting>();
Lukáš Tinkl's avatar
Lukáš Tinkl committed
58 59 60 61 62 63

    m_ui->parent->setCurrentIndex(m_ui->parent->findData(vlanSetting->parent()));

    m_ui->id->setValue(vlanSetting->id());
    m_ui->ifaceName->setText(vlanSetting->interfaceName());

64 65 66
    m_ui->reorderHeaders->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::ReorderHeaders));
    m_ui->gvrp->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::Gvrp));
    m_ui->looseBinding->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::LooseBinding));
Lukáš Tinkl's avatar
Lukáš Tinkl committed
67 68
}

69
QVariantMap VlanWidget::setting() const
Lukáš Tinkl's avatar
Lukáš Tinkl committed
70
{
71
    NetworkManager::VlanSetting setting;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
72 73 74 75 76 77 78 79

    setting.setParent(m_ui->parent->itemData(m_ui->parent->currentIndex()).toString());
    setting.setId(m_ui->id->value());

    const QString ifaceName = m_ui->ifaceName->text();
    if (!ifaceName.isEmpty())
        setting.setInterfaceName(ifaceName);

80
    NetworkManager::VlanSetting::Flags flags;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
81
    if (m_ui->reorderHeaders->isChecked())
82
        flags |= NetworkManager::VlanSetting::ReorderHeaders;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
83
    if (m_ui->gvrp->isChecked())
84
        flags |= NetworkManager::VlanSetting::Gvrp;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
85
    if (m_ui->looseBinding->isChecked())
86
        flags |= NetworkManager::VlanSetting::LooseBinding;
Lukáš Tinkl's avatar
Lukáš Tinkl committed
87 88 89 90 91 92 93 94 95 96
    if (flags)
        setting.setFlags(flags);

    return setting.toMap();
}

void VlanWidget::fillConnections()
{
    m_ui->parent->clear();

Jan Grulich's avatar
Jan Grulich committed
97
    for (const NetworkManager::Connection::Ptr &con : NetworkManager::listConnections()) {
98
        if (!con->settings()->isSlave() && con->settings()->connectionType() == NetworkManager::ConnectionSettings::Wired)
Lukáš Tinkl's avatar
Lukáš Tinkl committed
99 100 101
            m_ui->parent->addItem(con->name(), con->uuid());
    }
}
102

103
bool VlanWidget::isValid() const
104 105 106
{
    return !m_ui->parent->currentText().isEmpty() || !m_ui->ifaceName->text().isEmpty();
}