~ubuntu-branches/ubuntu/saucy/plasma-nm/saucy-proposed

« back to all changes in this revision

Viewing changes to lib/editor/vlanwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-08-16 19:07:09 UTC
  • Revision ID: package-import@ubuntu.com-20130816190709-ef9ydm9skigmg15l
Tags: upstream-0.0~git20130816
ImportĀ upstreamĀ versionĀ 0.0~git20130816

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright 2013 Lukas Tinkl <ltinkl@redhat.com>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Lesser General Public
 
6
    License as published by the Free Software Foundation; either
 
7
    version 2.1 of the License, or (at your option) version 3, or any
 
8
    later version accepted by the membership of KDE e.V. (or its
 
9
    successor approved by the membership of KDE e.V.), which shall
 
10
    act as a proxy defined in Section 6 of version 3 of the license.
 
11
 
 
12
    This library is distributed in the hope that it will be useful,
 
13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
    Lesser General Public License for more details.
 
16
 
 
17
    You should have received a copy of the GNU Lesser General Public
 
18
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 
19
*/
 
20
 
 
21
#include "vlanwidget.h"
 
22
#include "ui_vlan.h"
 
23
#include "uiutils.h"
 
24
 
 
25
#include <NetworkManagerQt/VlanSetting>
 
26
#include <NetworkManagerQt/Settings>
 
27
 
 
28
VlanWidget::VlanWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent, Qt::WindowFlags f):
 
29
    SettingWidget(setting, parent, f),
 
30
    m_ui(new Ui::VlanWidget)
 
31
{
 
32
    m_ui->setupUi(this);
 
33
 
 
34
    fillConnections();
 
35
 
 
36
    connect(m_ui->ifaceName, SIGNAL(textChanged(QString)), SLOT(slotWidgetChanged()));
 
37
    connect(m_ui->parent, SIGNAL(currentIndexChanged(int)), SLOT(slotWidgetChanged()));
 
38
    connect(m_ui->parent->lineEdit(), SIGNAL(textChanged(QString)), SLOT(slotWidgetChanged()));
 
39
 
 
40
    KAcceleratorManager::manage(this);
 
41
 
 
42
    if (setting)
 
43
        loadConfig(setting);
 
44
}
 
45
 
 
46
VlanWidget::~VlanWidget()
 
47
{
 
48
    delete m_ui;
 
49
}
 
50
 
 
51
void VlanWidget::loadConfig(const NetworkManager::Setting::Ptr &setting)
 
52
{
 
53
    NetworkManager::VlanSetting::Ptr vlanSetting = setting.staticCast<NetworkManager::VlanSetting>();
 
54
 
 
55
    m_ui->parent->setCurrentIndex(m_ui->parent->findData(vlanSetting->parent()));
 
56
 
 
57
    m_ui->id->setValue(vlanSetting->id());
 
58
    m_ui->ifaceName->setText(vlanSetting->interfaceName());
 
59
 
 
60
    m_ui->reorderHeaders->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::ReorderHeaders));
 
61
    m_ui->gvrp->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::Gvrp));
 
62
    m_ui->looseBinding->setChecked(vlanSetting->flags().testFlag(NetworkManager::VlanSetting::LooseBinding));
 
63
}
 
64
 
 
65
QVariantMap VlanWidget::setting(bool agentOwned) const
 
66
{
 
67
    Q_UNUSED(agentOwned);
 
68
 
 
69
    NetworkManager::VlanSetting setting;
 
70
 
 
71
    setting.setParent(m_ui->parent->itemData(m_ui->parent->currentIndex()).toString());
 
72
    setting.setId(m_ui->id->value());
 
73
 
 
74
    const QString ifaceName = m_ui->ifaceName->text();
 
75
    if (!ifaceName.isEmpty())
 
76
        setting.setInterfaceName(ifaceName);
 
77
 
 
78
    NetworkManager::VlanSetting::Flags flags;
 
79
    if (m_ui->reorderHeaders->isChecked())
 
80
        flags |= NetworkManager::VlanSetting::ReorderHeaders;
 
81
    if (m_ui->gvrp->isChecked())
 
82
        flags |= NetworkManager::VlanSetting::Gvrp;
 
83
    if (m_ui->looseBinding->isChecked())
 
84
        flags |= NetworkManager::VlanSetting::LooseBinding;
 
85
    if (flags)
 
86
        setting.setFlags(flags);
 
87
 
 
88
    return setting.toMap();
 
89
}
 
90
 
 
91
void VlanWidget::fillConnections()
 
92
{
 
93
    m_ui->parent->clear();
 
94
 
 
95
    foreach (const NetworkManager::Connection::Ptr &con, NetworkManager::listConnections()) {
 
96
        if (!con->settings()->isSlave() && con->settings()->connectionType() == NetworkManager::ConnectionSettings::Wired)
 
97
            m_ui->parent->addItem(con->name(), con->uuid());
 
98
    }
 
99
}
 
100
 
 
101
bool VlanWidget::isValid() const
 
102
{
 
103
    return !m_ui->parent->currentText().isEmpty() || !m_ui->ifaceName->text().isEmpty();
 
104
}