add support of macvlan

add support of profile removal
This commit is contained in:
arcan1s 2014-06-02 00:43:13 +04:00
parent 8a031f2183
commit 4051d2f2c8
14 changed files with 411 additions and 9 deletions

View File

@ -1,3 +1,7 @@
Ver.1.1.1:
+ [gui] added suppoort of macvlan
+ [gui] added ability to remove profile
Ver.1.1.0 (netctl-1.7 update):
+ [gui] added frequency
+ [plasmoid] added menu title

View File

@ -63,8 +63,6 @@ Additional information
TODO (wish list)
----------------
* update to upstream (add support of macvlan)
* add option to remove profile
* add contextual actions to tables
Links

View File

@ -8,7 +8,7 @@ cmake_policy (SET CMP0015 NEW)
project (netctl-gui)
set (PROJECT_VERSION_MAJOR 1)
set (PROJECT_VERSION_MINOR 1)
set (PROJECT_VERSION_PATCH 0)
set (PROJECT_VERSION_PATCH 1)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
configure_file (${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)

View File

@ -484,6 +484,33 @@
<translation>Maximum time, in seconds, to wait for IPv6s Duplicate Address Detection to succeed</translation>
</message>
</context>
<context>
<name>MacvlanWidget</name>
<message>
<source>Form</source>
<translation>Form</translation>
</message>
<message>
<source>macvlan settings</source>
<translation>macvlan settings</translation>
</message>
<message>
<source>Mode</source>
<translation>Mode</translation>
</message>
<message>
<source>MAC address</source>
<translation>MAC address</translation>
</message>
<message>
<source>Only connect to specified MAC address</source>
<translation type="obsolete">Only connect to specified MAC address</translation>
</message>
<message>
<source>Optional static MAC address</source>
<translation>Optional static MAC address</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
@ -690,6 +717,10 @@
<source>Name Description Status</source>
<translation>Name Description Status</translation>
</message>
<message>
<source>Remove</source>
<translation>Remove</translation>
</message>
</context>
<context>
<name>MobileWidget</name>

View File

@ -484,6 +484,33 @@
<translation>Максимальное время в секундах для ожидания выполнения детектирования дубликации IPv6 адресов</translation>
</message>
</context>
<context>
<name>MacvlanWidget</name>
<message>
<source>Form</source>
<translation>Form</translation>
</message>
<message>
<source>macvlan settings</source>
<translation>Опции macvlan</translation>
</message>
<message>
<source>Mode</source>
<translation>Режим</translation>
</message>
<message>
<source>MAC address</source>
<translation>MAC адрес</translation>
</message>
<message>
<source>Only connect to specified MAC address</source>
<translation type="obsolete">Подключаться только к указанному MAC адресу</translation>
</message>
<message>
<source>Optional static MAC address</source>
<translation>Статический MAC адрес, если нужно</translation>
</message>
</context>
<context>
<name>MainWindow</name>
<message>
@ -690,6 +717,10 @@
<source>Name Description Status</source>
<translation>Имя Описание Статус</translation>
</message>
<message>
<source>Remove</source>
<translation>Удалить</translation>
</message>
</context>
<context>
<name>MobileWidget</name>

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>431</width>
<height>537</height>
<width>429</width>
<height>535</height>
</rect>
</property>
<property name="windowTitle">
@ -118,6 +118,11 @@
<string notr="true">vlan</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">macvlan</string>
</property>
</item>
</widget>
</item>
</layout>

View File

@ -0,0 +1,93 @@
/***************************************************************************
* This file is part of netctl-gui *
* *
* netctl-gui is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* netctl-gui 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "macvlanwidget.h"
#include "ui_macvlanwidget.h"
MacvlanWidget::MacvlanWidget(QWidget *parent)
: QWidget(parent),
ui(new Ui::MacvlanWidget)
{
ui->setupUi(this);
createFilter();
}
MacvlanWidget::~MacvlanWidget()
{
delete ui;
}
void MacvlanWidget::clear()
{
ui->comboBox_mode->setCurrentIndex(0);
ui->lineEdit_mac->clear();
}
void MacvlanWidget::setShown(const bool state)
{
if (state)
show();
else
hide();
}
void MacvlanWidget::createFilter()
{
// mac
ui->lineEdit_mac->setInputMask(QString(">HH:HH:HH:HH:HH:HH"));
}
QMap<QString, QString> MacvlanWidget::getSettings()
{
QMap<QString, QString> macvlanSettings;
if (isOk() != 0)
return macvlanSettings;
macvlanSettings[QString("Mode")] = ui->comboBox_mode->currentText();
if (!ui->lineEdit_mac->text().split(QString(":")).join(QString("")).remove(QString(" ")).isEmpty())
macvlanSettings[QString("MACAddress")] = ui->lineEdit_mac->text();
return macvlanSettings;
}
int MacvlanWidget::isOk()
{
// all fine
return 0;
}
void MacvlanWidget::setSettings(const QMap<QString, QString> settings)
{
QMap<QString, QString> macvlanSettings = settings;
if (macvlanSettings.contains(QString("Mode")))
for (int i=0; i<ui->comboBox_mode->count(); i++)
if (macvlanSettings[QString("Mode")].remove(QString("'")) == ui->comboBox_mode->itemText(i))
ui->comboBox_mode->setCurrentIndex(i);
if (macvlanSettings.contains(QString("MACAddress")))
ui->lineEdit_mac->setText(macvlanSettings[QString("MACAddress")]);
}

View File

@ -0,0 +1,49 @@
/***************************************************************************
* This file is part of netctl-gui *
* *
* netctl-gui is free software: you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation, either version 3 of the *
* License, or (at your option) any later version. *
* *
* netctl-gui 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#ifndef MACVLANWIDGET_H
#define MACVLANWIDGET_H
#include <QWidget>
namespace Ui {
class MacvlanWidget;
}
class MacvlanWidget : public QWidget
{
Q_OBJECT
public:
explicit MacvlanWidget(QWidget *parent = 0);
~MacvlanWidget();
QMap<QString, QString> getSettings();
int isOk();
void setSettings(const QMap<QString, QString> settings);
public slots:
void clear();
void setShown(const bool state);
private:
Ui::MacvlanWidget *ui;
void createFilter();
};
#endif /* MACVLANWIDGET_H */

View File

@ -0,0 +1,94 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MacvlanWidget</class>
<widget class="QWidget" name="MacvlanWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>396</width>
<height>101</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QDockWidget" name="dockWidget_macvlan">
<property name="features">
<set>QDockWidget::NoDockWidgetFeatures</set>
</property>
<property name="windowTitle">
<string>macvlan settings</string>
</property>
<widget class="QWidget" name="dockWidgetContents_macvlan">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="layout_mode">
<item>
<widget class="QLabel" name="label_mode">
<property name="text">
<string>Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_mode">
<item>
<property name="text">
<string notr="true">bridge</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">vepa</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">private</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">passthru</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QHBoxLayout" name="layout_mac">
<item>
<widget class="QLabel" name="label_mac">
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>MAC address</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_mac">
<property name="toolTip">
<string>Optional static MAC address</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -28,6 +28,7 @@
#include "ethernetwidget.h"
#include "generalwidget.h"
#include "ipwidget.h"
#include "macvlanwidget.h"
#include "mobilewidget.h"
#include "netctlinteract.h"
#include "netctlprofile.h"
@ -67,6 +68,8 @@ MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const int ta
ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid);
ethernetWid = new EthernetWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid);
macvlanWid = new MacvlanWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid);
mobileWid = new MobileWidget(this);
ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid);
pppoeWid = new PppoeWidget(this);
@ -100,6 +103,7 @@ MainWindow::~MainWindow()
delete ethernetWid;
delete generalWid;
delete ipWid;
delete macvlanWid;
delete mobileWid;
delete pppoeWid;
delete tunnelWid;
@ -154,6 +158,7 @@ void MainWindow::createActions()
// main page events
connect(ui->pushButton_mainRefresh, SIGNAL(clicked(bool)), this, SLOT(updateMainTab()));
connect(ui->pushButton_mainRemove, SIGNAL(clicked(bool)), this, SLOT(mainTabRemoveProfile()));
connect(ui->pushButton_mainEnable, SIGNAL(clicked(bool)), this, SLOT(mainTabEnableProfile()));
connect(ui->pushButton_mainRestart, SIGNAL(clicked(bool)), this, SLOT(mainTabRestartProfile()));
connect(ui->pushButton_mainStart, SIGNAL(clicked(bool)), this, SLOT(mainTabStartProfile()));
@ -301,6 +306,21 @@ void MainWindow::updateWifiTab()
// main tab slots
void MainWindow::mainTabRemoveProfile()
{
qDebug() << "[MainWindow]" << "[mainTabRemoveProfile]";
ui->tabWidget->setDisabled(true);
// call netctlprofile
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
if (netctlProfile->removeProfile(profile))
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
updateMainTab();
}
void MainWindow::mainTabEnableProfile()
{
if (!checkExternalApps(QString("netctl"))) {
@ -442,6 +462,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(true);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -454,6 +475,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -467,6 +489,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -479,6 +502,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(true);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -491,6 +515,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(false);
bridgeWid->setShown(false);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(true);
tunnelWid->setShown(false);
@ -503,6 +528,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(false);
bridgeWid->setShown(false);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(true);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -515,6 +541,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(true);
@ -527,6 +554,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(false);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -539,6 +567,7 @@ void MainWindow::profileTabChangeState(const QString current)
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(true);
macvlanWid->setShown(false);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
@ -546,6 +575,19 @@ void MainWindow::profileTabChangeState(const QString current)
vlanWid->setShown(true);
wirelessWid->setShown(false);
}
else if (current == QString("macvlan")) {
generalWid->setShown(true);
ipWid->setShown(true);
bridgeWid->setShown(false);
ethernetWid->setShown(true);
macvlanWid->setShown(true);
mobileWid->setShown(false);
pppoeWid->setShown(false);
tunnelWid->setShown(false);
tuntapWid->setShown(false);
vlanWid->setShown(false);
wirelessWid->setShown(false);
}
}
@ -594,7 +636,8 @@ void MainWindow::profileTabCreateProfile()
(generalWid->connectionType->currentText() == QString("bridge")) ||
(generalWid->connectionType->currentText() == QString("tunnel")) ||
(generalWid->connectionType->currentText() == QString("tuntap")) ||
(generalWid->connectionType->currentText() == QString("vlan"))) {
(generalWid->connectionType->currentText() == QString("vlan")) ||
(generalWid->connectionType->currentText() == QString("macvlan"))) {
if (ipWid->isOk() == 1) {
errorWin = new ErrorWindow(this, 6);
errorWin->show();
@ -697,6 +740,13 @@ void MainWindow::profileTabCreateProfile()
return;
}
}
else if (generalWid->connectionType->currentText() == QString("macvlan")) {
if (ethernetWid->isOk() == 1) {
errorWin = new ErrorWindow(this, 7);
errorWin->show();
return;
}
}
qDebug() << "[MainWindow]" << "[profileTabCreateProfile]";
ui->tabWidget->setDisabled(true);
@ -771,6 +821,17 @@ void MainWindow::profileTabCreateProfile()
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
}
else if (generalWid->connectionType->currentText() == QString("macvlan")) {
QMap<QString, QString> addSettings = ipWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = ethernetWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
addSettings = macvlanWid->getSettings();
for (int i=0; i<addSettings.keys().count(); i++)
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
}
// call netctlprofile
QString profileTempName = netctlProfile->createProfile(profile, settings);
@ -825,6 +886,11 @@ void MainWindow::profileTabLoadProfile()
ethernetWid->setSettings(settings);
vlanWid->setSettings(settings);
}
else if (generalWid->connectionType->currentText() == QString("macvlan")) {
ipWid->setSettings(settings);
ethernetWid->setSettings(settings);
macvlanWid->setSettings(settings);
}
}

View File

@ -28,6 +28,7 @@ class ErrorWindow;
class EthernetWidget;
class GeneralWidget;
class IpWidget;
class MacvlanWidget;
class MobileWidget;
class Netctl;
class NetctlProfile;
@ -67,6 +68,7 @@ private slots:
void updateProfileTab();
void updateWifiTab();
// main tab slots
void mainTabRemoveProfile();
void mainTabEnableProfile();
void mainTabRestartProfile();
void mainTabStartProfile();
@ -89,6 +91,7 @@ private:
EthernetWidget *ethernetWid;
GeneralWidget *generalWid;
IpWidget *ipWid;
MacvlanWidget *macvlanWid;
MobileWidget *mobileWid;
PppoeWidget *pppoeWid;
TunnelWidget *tunnelWid;

View File

@ -86,6 +86,16 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_mainRemove">
<property name="text">
<string>Remove</string>
</property>
<property name="autoDefault">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="spacer_mainButtons">
<property name="orientation">
@ -190,8 +200,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>98</width>
<height>28</height>
<width>96</width>
<height>26</height>
</rect>
</property>
<property name="sizePolicy">
@ -356,7 +366,7 @@
<x>0</x>
<y>0</y>
<width>491</width>
<height>20</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuMenu">
@ -390,6 +400,7 @@
<tabstop>tabWidget</tabstop>
<tabstop>tableWidget_main</tabstop>
<tabstop>pushButton_mainRefresh</tabstop>
<tabstop>pushButton_mainRemove</tabstop>
<tabstop>pushButton_mainEnable</tabstop>
<tabstop>pushButton_mainRestart</tabstop>
<tabstop>pushButton_mainStart</tabstop>

View File

@ -55,6 +55,22 @@ bool NetctlProfile::copyProfile(const QString oldPath)
}
bool NetctlProfile::removeProfile(const QString profile)
{
QString profilePath = profileDirectory->absolutePath() + QDir::separator() + profile;
QProcess command;
QString commandText = sudoCommand + QString(" /usr/bin/rm ") + profilePath;
qDebug() << "[NetctlProfile]" << "[removeProfile]" << ":" << "Run cmd" << commandText;
command.start(commandText);
command.waitForFinished(-1);
if (command.exitCode() == 0)
return true;
else
return false;
}
QString NetctlProfile::createProfile(const QString profile, const QMap<QString, QString> settings)
{

View File

@ -34,6 +34,7 @@ public:
const QMap<QString, QString> settings = QMap<QString, QString>());
~NetctlProfile();
bool copyProfile(const QString oldPath);
bool removeProfile(const QString profile);
QString createProfile(const QString profile, const QMap<QString, QString> settings);
QMap<QString, QString> getSettingsFromProfile(const QString profile);