mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
added settings functions
added const type
This commit is contained in:
parent
fbad5a6c7d
commit
2cade97786
@ -40,7 +40,7 @@ void BridgeWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void BridgeWidget::setShown(bool state)
|
||||
void BridgeWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private:
|
||||
Ui::BridgeWidget *ui;
|
||||
|
@ -32,7 +32,7 @@ ErrorWindow::~ErrorWindow()
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ErrorWindow::setMessage(int mess)
|
||||
void ErrorWindow::setMessage(const int mess)
|
||||
{
|
||||
QString message;
|
||||
switch(mess) {
|
||||
|
@ -30,12 +30,13 @@ class ErrorWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ErrorWindow(QWidget *parent = 0, int messageNumber = 0);
|
||||
explicit ErrorWindow(QWidget *parent = 0,
|
||||
int messageNumber = 0);
|
||||
~ErrorWindow();
|
||||
|
||||
private:
|
||||
Ui::ErrorWindow *ui;
|
||||
void setMessage(int mess);
|
||||
void setMessage(const int mess);
|
||||
};
|
||||
|
||||
#endif /* ERRORWINDOW_H */
|
||||
|
@ -54,7 +54,7 @@ void EthernetWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void EthernetWidget::setShown(bool state)
|
||||
void EthernetWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
@ -96,7 +96,7 @@ void EthernetWidget::showAdvanced()
|
||||
}
|
||||
|
||||
|
||||
void EthernetWidget::showWpa(int state)
|
||||
void EthernetWidget::showWpa(const int state)
|
||||
{
|
||||
if (state == 0)
|
||||
ui->widget_wpa->setHidden(true);
|
||||
|
@ -39,12 +39,12 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private slots:
|
||||
void selectWpaConfig();
|
||||
void showAdvanced();
|
||||
void showWpa(int state);
|
||||
void showWpa(const int state);
|
||||
|
||||
private:
|
||||
Ui::EthernetWidget *ui;
|
||||
|
@ -21,14 +21,14 @@
|
||||
#include <QKeyEvent>
|
||||
|
||||
|
||||
GeneralWidget::GeneralWidget(QWidget *parent, QString ifaceDir, QString profileDir)
|
||||
GeneralWidget::GeneralWidget(QWidget *parent, QMap<QString, QString> settings)
|
||||
: QWidget(parent),
|
||||
ifaceDirectory(new QDir(ifaceDir)),
|
||||
profileDirectory(new QDir(profileDir)),
|
||||
ui(new Ui::GeneralWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connectionType = ui->comboBox_connection;
|
||||
ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]);
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
createActions();
|
||||
clear();
|
||||
}
|
||||
@ -66,7 +66,7 @@ void GeneralWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void GeneralWidget::setShown(bool state)
|
||||
void GeneralWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
|
@ -34,8 +34,7 @@ class GeneralWidget : public QWidget
|
||||
|
||||
public:
|
||||
explicit GeneralWidget(QWidget *parent = 0,
|
||||
QString ifaceDir = QString(""),
|
||||
QString profileDir = QString(""));
|
||||
QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~GeneralWidget();
|
||||
QComboBox *connectionType;
|
||||
QMap<QString, QString> getSettings();
|
||||
@ -44,7 +43,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private slots:
|
||||
void addAfter();
|
||||
|
@ -89,7 +89,7 @@ void IpWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void IpWidget::setShown(bool state)
|
||||
void IpWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
@ -168,7 +168,7 @@ void IpWidget::keyPressEvent(QKeyEvent *pressedKey)
|
||||
}
|
||||
|
||||
|
||||
QString IpWidget::getIp(QString rawIp)
|
||||
QString IpWidget::getIp(const QString rawIp)
|
||||
{
|
||||
QStringList ip = rawIp.split(QString("."));
|
||||
|
||||
@ -190,7 +190,7 @@ QString IpWidget::getIp(QString rawIp)
|
||||
}
|
||||
|
||||
|
||||
QString IpWidget::getPrefix(QString rawPrefix)
|
||||
QString IpWidget::getPrefix(const QString rawPrefix)
|
||||
{
|
||||
QString prefix;
|
||||
|
||||
@ -205,7 +205,7 @@ QString IpWidget::getPrefix(QString rawPrefix)
|
||||
}
|
||||
|
||||
|
||||
QString IpWidget::getIp6(QString rawIp)
|
||||
QString IpWidget::getIp6(const QString rawIp)
|
||||
{
|
||||
QString ip = rawIp;
|
||||
|
||||
@ -216,7 +216,7 @@ QString IpWidget::getIp6(QString rawIp)
|
||||
}
|
||||
|
||||
|
||||
QString IpWidget::getPrefix6(QString rawPrefix)
|
||||
QString IpWidget::getPrefix6(const QString rawPrefix)
|
||||
{
|
||||
QString prefix;
|
||||
|
||||
@ -300,7 +300,7 @@ void IpWidget::addDnsOpt()
|
||||
}
|
||||
|
||||
|
||||
void IpWidget::changeIpMode(QString currentText)
|
||||
void IpWidget::changeIpMode(const QString currentText)
|
||||
{
|
||||
if (currentText == QString("dhcp"))
|
||||
ui->widget_ip->setHidden(true);
|
||||
@ -309,7 +309,7 @@ void IpWidget::changeIpMode(QString currentText)
|
||||
}
|
||||
|
||||
|
||||
void IpWidget::ipEnable(int state)
|
||||
void IpWidget::ipEnable(const int state)
|
||||
{
|
||||
if (state == 0) {
|
||||
ui->comboBox_ip->setDisabled(true);
|
||||
@ -324,7 +324,7 @@ void IpWidget::ipEnable(int state)
|
||||
}
|
||||
|
||||
|
||||
void IpWidget::changeIp6Mode(QString currentText)
|
||||
void IpWidget::changeIp6Mode(const QString currentText)
|
||||
{
|
||||
if ((currentText == QString("dhcp")) ||
|
||||
(currentText == QString("dhcp-noaddr")))
|
||||
@ -335,7 +335,7 @@ void IpWidget::changeIp6Mode(QString currentText)
|
||||
}
|
||||
|
||||
|
||||
void IpWidget::ip6Enable(int state)
|
||||
void IpWidget::ip6Enable(const int state)
|
||||
{
|
||||
if (state == 0) {
|
||||
ui->comboBox_ip6->setDisabled(true);
|
||||
@ -350,7 +350,7 @@ void IpWidget::ip6Enable(int state)
|
||||
}
|
||||
|
||||
|
||||
void IpWidget::changeDhcpClient(QString currentText)
|
||||
void IpWidget::changeDhcpClient(const QString currentText)
|
||||
{
|
||||
if (currentText == QString("dhcpcd")) {
|
||||
ui->widget_dhcpcdOpt->setShown(true);
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private slots:
|
||||
// buttons
|
||||
@ -50,13 +50,13 @@ private slots:
|
||||
void addDns();
|
||||
void addDnsOpt();
|
||||
// ip mode
|
||||
void changeIpMode(QString currentText);
|
||||
void ipEnable(int state);
|
||||
void changeIpMode(const QString currentText);
|
||||
void ipEnable(const int state);
|
||||
// ipv6 mode
|
||||
void changeIp6Mode(QString currentText);
|
||||
void changeIp6Mode(const QString currentText);
|
||||
void ip6Enable(int state);
|
||||
// dhcp client
|
||||
void changeDhcpClient(QString currentText);
|
||||
void changeDhcpClient(const QString currentText);
|
||||
void showAdvanced();
|
||||
|
||||
private:
|
||||
@ -64,10 +64,10 @@ private:
|
||||
void createActions();
|
||||
void createFilter();
|
||||
void keyPressEvent(QKeyEvent *pressedKey);
|
||||
QString getIp(QString rawIp);
|
||||
QString getPrefix(QString rawPrefix);
|
||||
QString getIp6(QString rawIp);
|
||||
QString getPrefix6(QString rawPrefix);
|
||||
QString getIp(const QString rawIp);
|
||||
QString getPrefix(const QString rawPrefix);
|
||||
QString getIp6(const QString rawIp);
|
||||
QString getPrefix6(const QString rawPrefix);
|
||||
};
|
||||
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QProcess>
|
||||
|
||||
#include "bridgewidget.h"
|
||||
@ -31,6 +32,7 @@
|
||||
#include "netctlprofile.h"
|
||||
#include "passwdwidget.h"
|
||||
#include "pppoewidget.h"
|
||||
#include "settingswindow.h"
|
||||
#include "tunnelwidget.h"
|
||||
#include "tuntapwidget.h"
|
||||
#include "vlanwidget.h"
|
||||
@ -39,36 +41,22 @@
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent, bool defaultSettings, int tabNum)
|
||||
MainWindow::MainWindow(QWidget *parent, const bool defaultSettings, const int tabNum)
|
||||
: QMainWindow(parent),
|
||||
ui(new Ui::MainWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tabWidget->setCurrentIndex(tabNum-1);
|
||||
|
||||
// SettingsWindow *settingsWindow;
|
||||
// settingsWindow = new SettingsWindow(this);
|
||||
// if (defaultSettings)
|
||||
// стандартные настройки
|
||||
// delete settingsWindow;
|
||||
|
||||
// temporary block
|
||||
netctlPath = QString("/usr/bin/netctl");
|
||||
profileDir = QString("/etc/netctl");
|
||||
sudoPath = QString("/usr/bin/kdesu");
|
||||
wpaConfig.append(QString("/usr/bin/wpa_cli"));
|
||||
wpaConfig.append(QString("/usr/bin/wpa_supplicant"));
|
||||
preferedInterface = QString("");
|
||||
//// additional settings
|
||||
ifaceDir = QString("/sys/class/net/");
|
||||
rfkillDir = QString("/sys/class/rfkill/");
|
||||
wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui.pid"));
|
||||
wpaConfig.append(QString("nl80211,wext"));
|
||||
wpaConfig.append(QString("/run/wpa_supplicant_netctl-gui"));
|
||||
wpaConfig.append(QString("users"));
|
||||
QString configPath = QDir::homePath() + QDir::separator() + QString(".config") +
|
||||
QDir::separator() + QString("netctl-gui.conf");
|
||||
settingsWin = new SettingsWindow(this, configPath);
|
||||
if (defaultSettings)
|
||||
settingsWin->setDefault();
|
||||
configuration = settingsWin->getSettings();
|
||||
|
||||
// gui
|
||||
generalWid = new GeneralWidget(this, ifaceDir, profileDir);
|
||||
generalWid = new GeneralWidget(this, configuration);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(generalWid);
|
||||
ipWid = new IpWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(ipWid);
|
||||
@ -86,12 +74,12 @@ MainWindow::MainWindow(QWidget *parent, bool defaultSettings, int tabNum)
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid);
|
||||
vlanWid = new VlanWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid);
|
||||
wirelessWid = new WirelessWidget(this, rfkillDir);
|
||||
wirelessWid = new WirelessWidget(this, configuration);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid);
|
||||
// backend
|
||||
netctlCommand = new Netctl(this, netctlPath, profileDir, sudoPath);
|
||||
netctlProfile = new NetctlProfile(this, profileDir, sudoPath);
|
||||
wpaCommand = new WpaSup(this, wpaConfig, sudoPath, ifaceDir, preferedInterface);
|
||||
netctlCommand = new Netctl(this, configuration);
|
||||
netctlProfile = new NetctlProfile(this, configuration);
|
||||
wpaCommand = new WpaSup(this, configuration);
|
||||
|
||||
createActions();
|
||||
updateTabs(ui->tabWidget->currentIndex());
|
||||
@ -115,21 +103,23 @@ MainWindow::~MainWindow()
|
||||
delete tuntapWid;
|
||||
delete vlanWid;
|
||||
delete wirelessWid;
|
||||
|
||||
delete settingsWin;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::checkExternalApps(QString apps = QString("all"))
|
||||
bool MainWindow::checkExternalApps(const QString apps = QString("all"))
|
||||
{
|
||||
QStringList commandLine;
|
||||
commandLine.append("which");
|
||||
commandLine.append(sudoPath);
|
||||
commandLine.append(configuration[QString("SUDO_PATH")]);
|
||||
if ((apps == QString("netctl")) || (apps == QString("all"))) {
|
||||
commandLine.append(netctlPath);
|
||||
commandLine.append(configuration[QString("NETCTL_PATH")]);
|
||||
}
|
||||
if ((apps == QString("wpasup")) || (apps == QString("all"))) {
|
||||
commandLine.append(wpaConfig[0]);
|
||||
commandLine.append(wpaConfig[1]);
|
||||
commandLine.append(configuration[QString("WPACLI_PATH")]);
|
||||
commandLine.append(configuration[QString("WPASUP_PATH")]);
|
||||
}
|
||||
QProcess command;
|
||||
command.start(commandLine.join(QString(" ")));
|
||||
@ -141,7 +131,7 @@ bool MainWindow::checkExternalApps(QString apps = QString("all"))
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::checkState(QString state, QString item)
|
||||
bool MainWindow::checkState(const QString state, const QString item)
|
||||
{
|
||||
if (item.indexOf(state) > -1)
|
||||
return true;
|
||||
@ -154,6 +144,7 @@ bool MainWindow::checkState(QString state, QString item)
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
|
||||
connect(ui->actionSettings, SIGNAL(triggered(bool)), settingsWin, SLOT(showWindow()));
|
||||
connect(ui->actionQuit, SIGNAL(triggered(bool)), this, SLOT(close()));
|
||||
|
||||
// main page events
|
||||
@ -415,7 +406,7 @@ void MainWindow::profileTabBrowseProfile()
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::profileTabChangeState(QString current)
|
||||
void MainWindow::profileTabChangeState(const QString current)
|
||||
{
|
||||
if (current == QString("ethernet")) {
|
||||
generalWid->setShown(true);
|
||||
@ -806,7 +797,7 @@ void MainWindow::profileTabLoadProfile()
|
||||
|
||||
|
||||
// wifi tab slots
|
||||
void MainWindow::wifiTabSetEnabled(bool state)
|
||||
void MainWindow::wifiTabSetEnabled(const bool state)
|
||||
{
|
||||
if (state) {
|
||||
ui->tableWidget_wifi->show();
|
||||
@ -822,7 +813,7 @@ void MainWindow::wifiTabSetEnabled(bool state)
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::connectToUnknownEssid(QString passwd)
|
||||
void MainWindow::connectToUnknownEssid(const QString passwd)
|
||||
{
|
||||
if (!passwd.isEmpty())
|
||||
delete passwdWid;
|
||||
|
@ -33,6 +33,7 @@ class Netctl;
|
||||
class NetctlProfile;
|
||||
class PasswdWidget;
|
||||
class PppoeWidget;
|
||||
class SettingsWindow;
|
||||
class TunnelWidget;
|
||||
class TuntapWidget;
|
||||
class VlanWidget;
|
||||
@ -49,25 +50,17 @@ class MainWindow : public QMainWindow
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0,
|
||||
bool defaultSettings = false,
|
||||
int tabNum = 0);
|
||||
const bool defaultSettings = false,
|
||||
const int tabNum = 0);
|
||||
~MainWindow();
|
||||
Netctl *netctlCommand;
|
||||
NetctlProfile *netctlProfile;
|
||||
WpaSup *wpaCommand;
|
||||
enum wpaConfigIndex {
|
||||
wpaCliPath = 0,
|
||||
wpaSupplicantPath = 1,
|
||||
wpaPidPath = 2,
|
||||
wpadSupDrivers = 3,
|
||||
wpaConfDir = 4,
|
||||
wpaConfGroup = 5
|
||||
};
|
||||
|
||||
public slots:
|
||||
void updateTabs(const int tab);
|
||||
// wifi tab slots
|
||||
void connectToUnknownEssid(QString passwd);
|
||||
void connectToUnknownEssid(const QString passwd);
|
||||
|
||||
private slots:
|
||||
void updateMainTab();
|
||||
@ -80,12 +73,12 @@ private slots:
|
||||
void mainTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous);
|
||||
// profile tab slots
|
||||
void profileTabBrowseProfile();
|
||||
void profileTabChangeState(QString current);
|
||||
void profileTabChangeState(const QString current);
|
||||
void profileTabClear();
|
||||
void profileTabCreateProfile();
|
||||
void profileTabLoadProfile();
|
||||
// wifi tab slots
|
||||
void wifiTabSetEnabled(bool state);
|
||||
void wifiTabSetEnabled(const bool state);
|
||||
void wifiTabStart();
|
||||
void wifiTabRefreshButtons(QTableWidgetItem *current, QTableWidgetItem *previous);
|
||||
|
||||
@ -105,17 +98,12 @@ private:
|
||||
// backend
|
||||
ErrorWindow *errorWin;
|
||||
PasswdWidget *passwdWid;
|
||||
bool checkExternalApps(QString apps);
|
||||
bool checkState(QString state, QString item);
|
||||
SettingsWindow *settingsWin;
|
||||
bool checkExternalApps(const QString apps);
|
||||
bool checkState(const QString state, const QString item);
|
||||
void createActions();
|
||||
// configuration
|
||||
QString ifaceDir;
|
||||
QString netctlPath;
|
||||
QString preferedInterface;
|
||||
QString profileDir;
|
||||
QString rfkillDir;
|
||||
QString sudoPath;
|
||||
QStringList wpaConfig;
|
||||
QMap<QString, QString> configuration;
|
||||
};
|
||||
|
||||
|
||||
|
@ -56,7 +56,7 @@ void MobileWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void MobileWidget::setShown(bool state)
|
||||
void MobileWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private slots:
|
||||
void selectOptionsFile();
|
||||
|
@ -23,13 +23,12 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
|
||||
Netctl::Netctl(MainWindow *wid, QString netctlPath, QString profileDir, QString sudoPath)
|
||||
: parent(wid),
|
||||
netctlCommand(netctlPath),
|
||||
profileDirectory(new QDir(profileDir)),
|
||||
sudoCommand(sudoPath)
|
||||
Netctl::Netctl(MainWindow *wid, QMap<QString, QString> settings)
|
||||
: parent(wid)
|
||||
{
|
||||
|
||||
netctlCommand = settings[QString("NETCTL_PATH")];
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
}
|
||||
|
||||
|
||||
@ -58,7 +57,7 @@ QList<QStringList> Netctl::getProfileList()
|
||||
}
|
||||
|
||||
|
||||
QStringList Netctl::getProfileDescriptions(QStringList profileList)
|
||||
QStringList Netctl::getProfileDescriptions(const QStringList profileList)
|
||||
{
|
||||
QStringList descriptions;
|
||||
|
||||
@ -88,7 +87,7 @@ QStringList Netctl::getProfileDescriptions(QStringList profileList)
|
||||
}
|
||||
|
||||
|
||||
QStringList Netctl::getProfileStatuses(QStringList profileList)
|
||||
QStringList Netctl::getProfileStatuses(const QStringList profileList)
|
||||
{
|
||||
QStringList statuses;
|
||||
|
||||
@ -109,7 +108,7 @@ QStringList Netctl::getProfileStatuses(QStringList profileList)
|
||||
}
|
||||
|
||||
|
||||
QString Netctl::getSsidFromProfile(QString profile)
|
||||
QString Netctl::getSsidFromProfile(const QString profile)
|
||||
{
|
||||
QString ssidName = QString("");
|
||||
QFile profileFile(profileDirectory->absolutePath() + QDir::separator() + profile);
|
||||
@ -136,7 +135,7 @@ QString Netctl::getSsidFromProfile(QString profile)
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::isProfileActive(QString profile)
|
||||
bool Netctl::isProfileActive(const QString profile)
|
||||
{
|
||||
bool status = false;
|
||||
QProcess command;
|
||||
@ -153,7 +152,7 @@ bool Netctl::isProfileActive(QString profile)
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::isProfileEnabled(QString profile)
|
||||
bool Netctl::isProfileEnabled(const QString profile)
|
||||
{
|
||||
bool status = false;
|
||||
QProcess command;
|
||||
@ -175,7 +174,7 @@ bool Netctl::isProfileEnabled(QString profile)
|
||||
|
||||
|
||||
// functions
|
||||
bool Netctl::enableProfile(QString profile)
|
||||
bool Netctl::enableProfile(const QString profile)
|
||||
{
|
||||
QProcess command;
|
||||
if (isProfileEnabled(profile))
|
||||
@ -190,7 +189,7 @@ bool Netctl::enableProfile(QString profile)
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::restartProfile(QString profile)
|
||||
bool Netctl::restartProfile(const QString profile)
|
||||
{
|
||||
QProcess command;
|
||||
if (isProfileActive(profile))
|
||||
@ -203,7 +202,7 @@ bool Netctl::restartProfile(QString profile)
|
||||
}
|
||||
|
||||
|
||||
bool Netctl::startProfile(QString profile)
|
||||
bool Netctl::startProfile(const QString profile)
|
||||
{
|
||||
QProcess command;
|
||||
if (isProfileActive(profile))
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define NETCTLINTERACT_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
@ -30,23 +31,21 @@ class Netctl : public QObject
|
||||
|
||||
public:
|
||||
explicit Netctl(MainWindow *wid = 0,
|
||||
QString netctlPath = QString(""),
|
||||
QString profileDir = QString(""),
|
||||
QString sudoPath = QString(""));
|
||||
QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~Netctl();
|
||||
// general information
|
||||
QList<QStringList> getProfileList();
|
||||
QStringList getProfileDescriptions(QStringList profileList);
|
||||
QStringList getProfileStatuses(QStringList profileList);
|
||||
QString getSsidFromProfile(QString profile);
|
||||
bool isProfileActive(QString profile);
|
||||
bool isProfileEnabled(QString profile);
|
||||
QStringList getProfileDescriptions(const QStringList profileList);
|
||||
QStringList getProfileStatuses(const QStringList profileList);
|
||||
QString getSsidFromProfile(const QString profile);
|
||||
bool isProfileActive(const QString profile);
|
||||
bool isProfileEnabled(const QString profile);
|
||||
|
||||
public slots:
|
||||
// functions
|
||||
bool enableProfile(QString profile);
|
||||
bool restartProfile(QString profile);
|
||||
bool startProfile(QString profile);
|
||||
bool enableProfile(const QString profile);
|
||||
bool restartProfile(const QString profile);
|
||||
bool startProfile(const QString profile);
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
|
@ -26,12 +26,11 @@
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
NetctlProfile::NetctlProfile(MainWindow *wid, QString profileDir, QString sudoPath)
|
||||
: parent(wid),
|
||||
profileDirectory(new QDir(profileDir)),
|
||||
sudoCommand(sudoPath)
|
||||
NetctlProfile::NetctlProfile(MainWindow *wid, QMap<QString, QString> settings)
|
||||
: parent(wid)
|
||||
{
|
||||
|
||||
profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
}
|
||||
|
||||
|
||||
@ -41,7 +40,7 @@ NetctlProfile::~NetctlProfile()
|
||||
}
|
||||
|
||||
|
||||
bool NetctlProfile::copyProfile(QString oldPath)
|
||||
bool NetctlProfile::copyProfile(const QString oldPath)
|
||||
{
|
||||
QString newPath = profileDirectory->absolutePath() + QDir::separator() + QFileInfo(oldPath).fileName();
|
||||
QProcess command;
|
||||
@ -54,7 +53,7 @@ bool NetctlProfile::copyProfile(QString oldPath)
|
||||
}
|
||||
|
||||
|
||||
QString NetctlProfile::createProfile(QString profile, QMap<QString, QString> settings)
|
||||
QString NetctlProfile::createProfile(const QString profile, const QMap<QString, QString> settings)
|
||||
{
|
||||
|
||||
QString profileTempName = QDir::homePath() + QDir::separator() +
|
||||
@ -88,7 +87,7 @@ QString NetctlProfile::createProfile(QString profile, QMap<QString, QString> set
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> NetctlProfile::getSettingsFromProfile(QString profile)
|
||||
QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile)
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
QFile profileFile;
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define NETCTLPROFILE_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
@ -30,12 +31,11 @@ class NetctlProfile : public QObject
|
||||
|
||||
public:
|
||||
explicit NetctlProfile(MainWindow *wid = 0,
|
||||
QString profileDir = QString(""),
|
||||
QString sudoPath = QString(""));
|
||||
QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~NetctlProfile();
|
||||
bool copyProfile(QString oldPath);
|
||||
QString createProfile(QString profile, QMap<QString, QString> settings);
|
||||
QMap<QString, QString> getSettingsFromProfile(QString profile);
|
||||
bool copyProfile(const QString oldPath);
|
||||
QString createProfile(const QString profile, const QMap<QString, QString> settings);
|
||||
QMap<QString, QString> getSettingsFromProfile(const QString profile);
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
|
@ -27,8 +27,8 @@ PasswdWidget::PasswdWidget(MainWindow *wid)
|
||||
ui(new Ui::PasswdWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
cancelButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
||||
okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
createActions();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ void PppoeWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::setShown(bool state)
|
||||
void PppoeWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
@ -91,7 +91,7 @@ void PppoeWidget::createActions()
|
||||
}
|
||||
|
||||
|
||||
void PppoeWidget::changeMode(QString currentText)
|
||||
void PppoeWidget::changeMode(const QString currentText)
|
||||
{
|
||||
if (currentText == QString("persist"))
|
||||
ui->widget_timeout->setHidden(true);
|
||||
|
@ -38,10 +38,10 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private slots:
|
||||
void changeMode(QString currentText);
|
||||
void changeMode(const QString currentText);
|
||||
void selectOptionsFile();
|
||||
void showAdvanced();
|
||||
|
||||
|
@ -18,16 +18,261 @@
|
||||
#include "settingswindow.h"
|
||||
#include "ui_settingswindow.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
|
||||
SettingsWindow::SettingsWindow(QWidget *parent)
|
||||
: QMainWindow(parent),
|
||||
#include "mainwindow.h"
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
SettingsWindow::SettingsWindow(MainWindow *wid, QString configFile)
|
||||
: QMainWindow(wid),
|
||||
parent(wid),
|
||||
file(configFile),
|
||||
ui(new Ui::SettingsWindow)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
cancelButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
|
||||
defaultButton = ui->buttonBox->button(QDialogButtonBox::Reset);
|
||||
okButton = ui->buttonBox->button(QDialogButtonBox::Ok);
|
||||
ui->comboBox_language->addItem(QString("english"));
|
||||
ui->comboBox_language->addItem(QString("russian"));
|
||||
createActions();
|
||||
}
|
||||
|
||||
|
||||
SettingsWindow::~SettingsWindow()
|
||||
{
|
||||
delete cancelButton;
|
||||
delete defaultButton;
|
||||
delete okButton;
|
||||
delete ui;
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::createActions()
|
||||
{
|
||||
connect(ui->comboBox_language, SIGNAL(currentIndexChanged(int)), ui->label_info, SLOT(show()));
|
||||
connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(close()));
|
||||
connect(defaultButton, SIGNAL(clicked(bool)), this, SLOT(setDefault()));
|
||||
connect(okButton, SIGNAL(clicked(bool)), this, SLOT(saveSettings()));
|
||||
connect(okButton, SIGNAL(clicked(bool)), this, SLOT(close()));
|
||||
// buttons
|
||||
connect(ui->pushButton_interfaceDir, SIGNAL(clicked(bool)), SLOT(selectIfaceDir()));
|
||||
connect(ui->pushButton_netctlPath, SIGNAL(clicked(bool)), SLOT(selectNetctlPath()));
|
||||
connect(ui->pushButton_profilePath, SIGNAL(clicked(bool)), SLOT(selectProfileDir()));
|
||||
connect(ui->pushButton_rfkill, SIGNAL(clicked(bool)), SLOT(selectRfkillDir()));
|
||||
connect(ui->pushButton_sudo, SIGNAL(clicked(bool)), SLOT(selectSudoPath()));
|
||||
connect(ui->pushButton_wpaCliPath, SIGNAL(clicked(bool)), SLOT(selectWpaCliPath()));
|
||||
connect(ui->pushButton_wpaSupPath, SIGNAL(clicked(bool)), SLOT(selectWpaSupPath()));
|
||||
}
|
||||
|
||||
|
||||
// ESC press event
|
||||
void SettingsWindow::keyPressEvent(QKeyEvent *pressedKey)
|
||||
{
|
||||
if (pressedKey->key() == Qt::Key_Escape)
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::saveSettings()
|
||||
{
|
||||
QMap<QString, QString> settings = readSettings();
|
||||
QFile configFile(file);
|
||||
|
||||
if (!configFile.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
return;
|
||||
QTextStream out(&configFile);
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
out << settings.keys()[i] << QString("=") << settings[settings.keys()[i]] << QString("\n");
|
||||
configFile.close();
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::setDefault()
|
||||
{
|
||||
setSettings(getDefault());
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectIfaceDir()
|
||||
{
|
||||
QString directory = QFileDialog::getExistingDirectory(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select path to directory with interfaces"),
|
||||
QString("/sys/"));
|
||||
if (!directory.isEmpty())
|
||||
ui->lineEdit_interfacesDir->setText(directory);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectNetctlPath()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select netctl command"),
|
||||
QString("/usr/bin/"),
|
||||
QApplication::translate("SettingsWindow", "All files (*)"));
|
||||
if (!filename.isEmpty())
|
||||
ui->lineEdit_netctlPath->setText(filename);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectProfileDir()
|
||||
{
|
||||
QString directory = QFileDialog::getExistingDirectory(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select path to profile directory"),
|
||||
QString("/etc/"));
|
||||
if (!directory.isEmpty())
|
||||
ui->lineEdit_profilePath->setText(directory);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectRfkillDir()
|
||||
{
|
||||
QString directory = QFileDialog::getExistingDirectory(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select path to directory with rfkill devices"),
|
||||
QString("/sys/"));
|
||||
if (!directory.isEmpty())
|
||||
ui->lineEdit_rfkill->setText(directory);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectSudoPath()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select sudo command"),
|
||||
QString("/usr/bin/"),
|
||||
QApplication::translate("SettingsWindow", "All files (*)"));
|
||||
if (!filename.isEmpty())
|
||||
ui->lineEdit_sudo->setText(filename);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectWpaCliPath()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select wpa_cli command"),
|
||||
QString("/usr/bin/"),
|
||||
QApplication::translate("SettingsWindow", "All files (*)"));
|
||||
if (!filename.isEmpty())
|
||||
ui->lineEdit_wpaCliPath->setText(filename);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::selectWpaSupPath()
|
||||
{
|
||||
QString filename = QFileDialog::getOpenFileName(
|
||||
this,
|
||||
QApplication::translate("SettingsWindow", "Select wpa_supplicant command"),
|
||||
QString("/usr/bin/"),
|
||||
QApplication::translate("SettingsWindow", "All files (*)"));
|
||||
if (!filename.isEmpty())
|
||||
ui->lineEdit_wpaSupPath->setText(filename);
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::showWindow()
|
||||
{
|
||||
setSettings(getSettings());
|
||||
ui->label_info->hide();
|
||||
show();
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> SettingsWindow::readSettings()
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
|
||||
settings[QString("CTRL_DIR")] = ui->lineEdit_wpaDir->text();
|
||||
settings[QString("CTRL_GROUP")] = ui->lineEdit_wpaGroup->text();
|
||||
settings[QString("IFACE_DIR")] = ui->lineEdit_interfacesDir->text();
|
||||
settings[QString("LANGUAGE")] = ui->comboBox_language->currentText();
|
||||
settings[QString("NETCTL_PATH")] = ui->lineEdit_netctlPath->text();
|
||||
settings[QString("PID_FILE")] = ui->lineEdit_pid->text();
|
||||
settings[QString("PREFERED_IFACE")] = ui->lineEdit_interface->text();
|
||||
settings[QString("PROFILE_DIR")] = ui->lineEdit_profilePath->text();
|
||||
settings[QString("RFKILL_DIR")] = ui->lineEdit_rfkill->text();
|
||||
settings[QString("SUDO_PATH")] = ui->lineEdit_sudo->text();
|
||||
settings[QString("WPA_DRIVERS")] = ui->lineEdit_wpaSupDrivers->text();
|
||||
settings[QString("WPACLI_PATH")] = ui->lineEdit_wpaCliPath->text();
|
||||
settings[QString("WPASUP_PATH")] = ui->lineEdit_wpaSupPath->text();
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
void SettingsWindow::setSettings(QMap<QString, QString> settings)
|
||||
{
|
||||
ui->lineEdit_wpaDir->setText(settings[QString("CTRL_DIR")]);
|
||||
ui->lineEdit_wpaGroup->setText(settings[QString("CTRL_GROUP")]);
|
||||
ui->lineEdit_interfacesDir->setText(settings[QString("IFACE_DIR")]);
|
||||
ui->comboBox_language->setCurrentIndex(0);
|
||||
for (int i=0; i<ui->comboBox_language->count(); i++)
|
||||
if (ui->comboBox_language->itemText(i) == settings[QString("LANGUAGE")])
|
||||
ui->comboBox_language->setCurrentIndex(i);
|
||||
ui->lineEdit_netctlPath->setText(settings[QString("NETCTL_PATH")]);
|
||||
ui->lineEdit_pid->setText(settings[QString("PID_FILE")]);
|
||||
ui->lineEdit_interface->setText(settings[QString("PREFERED_IFACE")]);
|
||||
ui->lineEdit_profilePath->setText(settings[QString("PROFILE_DIR")]);
|
||||
ui->lineEdit_rfkill->setText(settings[QString("RFKILL_DIR")]);
|
||||
ui->lineEdit_sudo->setText(settings[QString("SUDO_PATH")]);
|
||||
ui->lineEdit_wpaSupDrivers->setText(settings[QString("WPA_DRIVERS")]);
|
||||
ui->lineEdit_wpaCliPath->setText(settings[QString("WPACLI_PATH")]);
|
||||
ui->lineEdit_wpaSupPath->setText(settings[QString("WPASUP_PATH")]);
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> SettingsWindow::getDefault()
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
|
||||
settings[QString("CTRL_DIR")] = QString("/run/wpa_supplicant_netctl-gui");
|
||||
settings[QString("CTRL_GROUP")] = QString("users");
|
||||
settings[QString("IFACE_DIR")] = QString("/sys/class/net/");
|
||||
settings[QString("LANGUAGE")] = QString("english");
|
||||
settings[QString("NETCTL_PATH")] = QString("/usr/bin/netctl");
|
||||
settings[QString("PID_FILE")] = QString("/run/wpa_supplicant_netctl-gui.pid");
|
||||
settings[QString("PREFERED_IFACE")] = QString("");
|
||||
settings[QString("PROFILE_DIR")] = QString("/etc/netctl/");
|
||||
settings[QString("RFKILL_DIR")] = QString("/sys/class/rfkill/");
|
||||
settings[QString("SUDO_PATH")] = QString("/usr/bin/kdesu");
|
||||
settings[QString("WPA_DRIVERS")] = QString("nl80211,wext");
|
||||
settings[QString("WPACLI_PATH")] = QString("/usr/bin/wpa_cli");
|
||||
settings[QString("WPASUP_PATH")] = QString("/usr/bin/wpa_supplicant");
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> SettingsWindow::getSettings()
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
QFile configFile(file);
|
||||
QString fileStr;
|
||||
|
||||
if (!configFile.open(QIODevice::ReadOnly))
|
||||
return getDefault();
|
||||
while (true) {
|
||||
fileStr = QString(configFile.readLine());
|
||||
if (configFile.atEnd())
|
||||
break;
|
||||
else if (fileStr[0] != '#') {
|
||||
if (fileStr.indexOf(QString("=")) > -1)
|
||||
settings[fileStr.split(QString("="))[0]] = fileStr.split(QString("="))[1]
|
||||
.remove(QString(" "))
|
||||
.trimmed();
|
||||
}
|
||||
}
|
||||
|
||||
configFile.close();
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
@ -18,9 +18,13 @@
|
||||
#ifndef SETTINGSWINDOW_H
|
||||
#define SETTINGSWINDOW_H
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
|
||||
namespace Ui {
|
||||
class SettingsWindow;
|
||||
}
|
||||
@ -30,11 +34,39 @@ class SettingsWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit SettingsWindow(QWidget *parent = 0);
|
||||
explicit SettingsWindow(MainWindow *wid = 0,
|
||||
QString configFile = QString(""));
|
||||
~SettingsWindow();
|
||||
QMap<QString, QString> getDefault();
|
||||
QMap<QString, QString> getSettings();
|
||||
|
||||
public slots:
|
||||
void setDefault();
|
||||
void showWindow();
|
||||
|
||||
private slots:
|
||||
void saveSettings();
|
||||
// buttons
|
||||
void selectIfaceDir();
|
||||
void selectNetctlPath();
|
||||
void selectProfileDir();
|
||||
void selectRfkillDir();
|
||||
void selectSudoPath();
|
||||
void selectWpaCliPath();
|
||||
void selectWpaSupPath();
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
QString file;
|
||||
Ui::SettingsWindow *ui;
|
||||
QPushButton *cancelButton;
|
||||
QPushButton *defaultButton;
|
||||
QPushButton *okButton;
|
||||
void createActions();
|
||||
// ESC pressed event
|
||||
void keyPressEvent(QKeyEvent *pressedKey);
|
||||
QMap<QString, QString> readSettings();
|
||||
void setSettings(QMap<QString, QString> settings);
|
||||
};
|
||||
|
||||
|
||||
|
@ -490,7 +490,7 @@
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -43,7 +43,7 @@ void TunnelWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void TunnelWidget::setShown(bool state)
|
||||
void TunnelWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
@ -61,7 +61,7 @@ void TunnelWidget::createFilter()
|
||||
}
|
||||
|
||||
|
||||
QString TunnelWidget::getIp(QString rawIp)
|
||||
QString TunnelWidget::getIp(const QString rawIp)
|
||||
{
|
||||
QStringList ip = rawIp.split(QString("."));
|
||||
|
||||
|
@ -38,12 +38,12 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private:
|
||||
Ui::TunnelWidget *ui;
|
||||
void createFilter();
|
||||
QString getIp(QString rawIp);
|
||||
QString getIp(const QString rawIp);
|
||||
};
|
||||
|
||||
|
||||
|
@ -42,7 +42,7 @@ void TuntapWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void TuntapWidget::setShown(bool state)
|
||||
void TuntapWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private:
|
||||
Ui::TuntapWidget *ui;
|
||||
|
@ -40,7 +40,7 @@ void VlanWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void VlanWidget::setShown(bool state)
|
||||
void VlanWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private:
|
||||
Ui::VlanWidget *ui;
|
||||
|
@ -23,12 +23,12 @@
|
||||
#include <QKeyEvent>
|
||||
|
||||
|
||||
WirelessWidget::WirelessWidget(QWidget *parent, QString rfkillDir)
|
||||
WirelessWidget::WirelessWidget(QWidget *parent, QMap<QString, QString> settings)
|
||||
: QWidget(parent),
|
||||
rfkillDirectory(new QDir(rfkillDir)),
|
||||
ui(new Ui::WirelessWidget)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
rfkillDirectory = new QDir(settings[QString("RFKILL_DIR")]);
|
||||
createActions();
|
||||
clear();
|
||||
}
|
||||
@ -83,7 +83,7 @@ void WirelessWidget::clear()
|
||||
}
|
||||
|
||||
|
||||
void WirelessWidget::setShown(bool state)
|
||||
void WirelessWidget::setShown(const bool state)
|
||||
{
|
||||
if (state)
|
||||
show();
|
||||
@ -150,7 +150,7 @@ void WirelessWidget::addOption()
|
||||
}
|
||||
|
||||
|
||||
void WirelessWidget::changeSecurity(QString currentText)
|
||||
void WirelessWidget::changeSecurity(const QString currentText)
|
||||
{
|
||||
if (currentText == QString("none")) {
|
||||
ui->widget_essid->setShown(true);
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define WIRELESSWIDGET_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
@ -32,7 +33,7 @@ class WirelessWidget : public QWidget
|
||||
|
||||
public:
|
||||
explicit WirelessWidget(QWidget *parent = 0,
|
||||
QString rfkillDir = QString(""));
|
||||
QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~WirelessWidget();
|
||||
QMap<QString, QString> getSettings();
|
||||
int isOk();
|
||||
@ -40,13 +41,13 @@ public:
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void setShown(bool state);
|
||||
void setShown(const bool state);
|
||||
|
||||
private slots:
|
||||
void addDriver();
|
||||
void addFreq();
|
||||
void addOption();
|
||||
void changeSecurity(QString currentText);
|
||||
void changeSecurity(const QString currentText);
|
||||
void showAdvanced();
|
||||
void selectWpaConfig();
|
||||
|
||||
|
@ -24,15 +24,21 @@
|
||||
#include "sleepthread.h"
|
||||
|
||||
|
||||
WpaSup::WpaSup(MainWindow *wid, QStringList wpaConfig, QString sudoPath, QString ifaceDir, QString preferedInterface)
|
||||
: parent(wid),
|
||||
wpaConf(wpaConfig),
|
||||
sudoCommand(sudoPath),
|
||||
ifaceDirectory(new QDir(ifaceDir)),
|
||||
mainInterface(preferedInterface)
|
||||
WpaSup::WpaSup(MainWindow *wid, QMap<QString, QString> settings)
|
||||
: parent(wid)
|
||||
{
|
||||
ctrlDir = settings[QString("CTRL_DIR")];
|
||||
ctrlGroup = settings[QString("CTRL_GROUP")];
|
||||
ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]);
|
||||
mainInterface = settings[QString("PREFERED_IFACE")];
|
||||
pidFile = settings[QString("PID_FILE")];
|
||||
sudoCommand = settings[QString("SUDO_PATH")];
|
||||
wpaCliPath = settings[QString("WPACLI_PATH")];
|
||||
wpaDrivers = settings[QString("WPA_DRIVERS")];
|
||||
wpaSupPath = settings[QString("WPASUP_PATH")];
|
||||
|
||||
// terminate old loaded profile
|
||||
if (QFile(wpaConf[2]).exists() || QDir(wpaConf[4]).exists())
|
||||
if (QFile(pidFile).exists() || QDir(ctrlDir).exists())
|
||||
stopWpaSupplicant();
|
||||
}
|
||||
|
||||
@ -62,12 +68,12 @@ QStringList WpaSup::getInterfaceList()
|
||||
|
||||
|
||||
// functions
|
||||
bool WpaSup::wpaCliCall(QString commandLine)
|
||||
bool WpaSup::wpaCliCall(const QString commandLine)
|
||||
{
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
command.start(wpaConf[0] + QString(" -i ") + interface + QString(" -p ") + wpaConf[4] +
|
||||
QString(" -P ") + wpaConf[2] + QString(" ") + commandLine);
|
||||
command.start(wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine);
|
||||
command.waitForFinished(-1);
|
||||
SleepThread::sleep(1);
|
||||
if (command.exitCode() == 0)
|
||||
@ -77,18 +83,18 @@ bool WpaSup::wpaCliCall(QString commandLine)
|
||||
}
|
||||
|
||||
|
||||
QString WpaSup::getWpaCliOutput(QString commandLine)
|
||||
QString WpaSup::getWpaCliOutput(const QString commandLine)
|
||||
{
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
command.start(wpaConf[0] + QString(" -i ") + interface + QString(" -p ") + wpaConf[4] +
|
||||
QString(" -P ") + wpaConf[2] + QString(" ") + commandLine);
|
||||
command.start(wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine);
|
||||
command.waitForFinished(-1);
|
||||
return command.readAllStandardOutput();
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::isProfileActive(QString profile)
|
||||
bool WpaSup::isProfileActive(const QString profile)
|
||||
{
|
||||
QString profileFile;
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
@ -99,7 +105,7 @@ bool WpaSup::isProfileActive(QString profile)
|
||||
}
|
||||
|
||||
|
||||
bool WpaSup::isProfileExists(QString profile)
|
||||
bool WpaSup::isProfileExists(const QString profile)
|
||||
{
|
||||
bool exists = false;
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
@ -110,7 +116,7 @@ bool WpaSup::isProfileExists(QString profile)
|
||||
}
|
||||
|
||||
|
||||
QString WpaSup::existentProfile(QString profile)
|
||||
QString WpaSup::existentProfile(const QString profile)
|
||||
{
|
||||
QString profileFile = QString("");
|
||||
QList<QStringList> profileList = parent->netctlCommand->getProfileList();
|
||||
@ -123,12 +129,12 @@ QString WpaSup::existentProfile(QString profile)
|
||||
|
||||
bool WpaSup::startWpaSupplicant()
|
||||
{
|
||||
if (!QFile(wpaConf[2]).exists()) {
|
||||
if (!QFile(pidFile).exists()) {
|
||||
QString interface = getInterfaceList()[0];
|
||||
QProcess command;
|
||||
command.start(sudoCommand + QString(" ") + wpaConf[1] + QString(" -B -P ") + wpaConf[2] +
|
||||
QString(" -i ") + interface + QString(" -D ") + wpaConf[3] +
|
||||
QString(" -C \"DIR=") + wpaConf[4] + QString(" GROUP=") + wpaConf[5]);
|
||||
command.start(sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile +
|
||||
QString(" -i ") + interface + QString(" -D ") + wpaDrivers +
|
||||
QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup);
|
||||
command.waitForFinished(-1);
|
||||
SleepThread::sleep(1);
|
||||
if (command.exitCode() != 0)
|
||||
|
@ -19,6 +19,7 @@
|
||||
#define WPASUPINTERACT_H
|
||||
|
||||
#include <QDir>
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
@ -30,19 +31,16 @@ class WpaSup : public QObject
|
||||
|
||||
public:
|
||||
explicit WpaSup(MainWindow *wid = 0,
|
||||
QStringList wpaConfig = QStringList(),
|
||||
QString sudoPath = QString(""),
|
||||
QString ifaceDir = QString(""),
|
||||
QString preferedInterface = QString(""));
|
||||
QMap<QString, QString> settings = QMap<QString, QString>());
|
||||
~WpaSup();
|
||||
// general information
|
||||
QStringList getInterfaceList();
|
||||
// functions
|
||||
bool wpaCliCall(QString commandLine);
|
||||
QString getWpaCliOutput(QString commandLine);
|
||||
bool isProfileExists(QString profile);
|
||||
QString existentProfile(QString profile);
|
||||
bool isProfileActive(QString profile);
|
||||
bool wpaCliCall(const QString commandLine);
|
||||
QString getWpaCliOutput(const QString commandLine);
|
||||
bool isProfileExists(const QString profile);
|
||||
QString existentProfile(const QString profile);
|
||||
bool isProfileActive(const QString profile);
|
||||
|
||||
public slots:
|
||||
// functions
|
||||
@ -52,10 +50,15 @@ public slots:
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
QStringList wpaConf;
|
||||
QString sudoCommand;
|
||||
QString ctrlDir;
|
||||
QString ctrlGroup;
|
||||
QDir *ifaceDirectory;
|
||||
QString mainInterface;
|
||||
QString pidFile;
|
||||
QString sudoCommand;
|
||||
QString wpaCliPath;
|
||||
QString wpaDrivers;
|
||||
QString wpaSupPath;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user