Compare commits

..

No commits in common. "master" and "V.1.4.8" have entirely different histories.

41 changed files with 820 additions and 713 deletions

View File

@ -1,12 +1,3 @@
Ver.1.4.9
---------
* library
* fix bug with invalid enabled profile definition (#46)
* some imrovements inside
* plasmoid
* change rendering from Qt to native
* update plasmoid to recent plasma changes
Ver.1.4.8 Ver.1.4.8
--------- ---------
* gui * gui

View File

@ -3,7 +3,7 @@
pkgbase=netctl-gui pkgbase=netctl-gui
pkgname=('libnetctlgui' 'netctlgui-helper' 'netctl-gui' pkgname=('libnetctlgui' 'netctlgui-helper' 'netctl-gui'
'plasma5-applet-netctl-gui') 'plasma5-applet-netctl-gui')
pkgver=1.4.9 pkgver=1.4.8
pkgrel=1 pkgrel=1
pkgdesc="Qt4/Qt5 GUI for netctl. Also provides a widget for KDE" pkgdesc="Qt4/Qt5 GUI for netctl. Also provides a widget for KDE"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')
@ -11,7 +11,7 @@ url="http://arcanis.name/projects/netctl-gui"
license=('GPL3') license=('GPL3')
makedepends=('cmake' 'extra-cmake-modules' 'plasma-framework' 'qt5-tools') makedepends=('cmake' 'extra-cmake-modules' 'plasma-framework' 'qt5-tools')
source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz") source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz")
md5sums=('64c04c36eea017e7c0ddf687d60de128') md5sums=('0c50a436064c31f890f69d5f321d2e27')
prepare() { prepare() {
rm -rf "${srcdir}/build-"{plasmoid,qt5} rm -rf "${srcdir}/build-"{plasmoid,qt5}

View File

@ -4,7 +4,7 @@ pkgbase=netctl-gui-qt4
_pkgbase=netctl-gui _pkgbase=netctl-gui
pkgname=('libnetctlgui-qt4' 'netctlgui-helper-qt4' 'netctl-gui-qt4' pkgname=('libnetctlgui-qt4' 'netctlgui-helper-qt4' 'netctl-gui-qt4'
'kdeplasma-applets-netctl-gui') 'kdeplasma-applets-netctl-gui')
pkgver=1.4.9 pkgver=1.4.8
pkgrel=1 pkgrel=1
pkgdesc="Qt4 GUI for netctl. Also provides a widget for KDE4" pkgdesc="Qt4 GUI for netctl. Also provides a widget for KDE4"
arch=('i686' 'x86_64') arch=('i686' 'x86_64')
@ -12,7 +12,7 @@ url="http://arcanis.name/projects/netctl-gui"
license=('GPL3') license=('GPL3')
makedepends=('automoc4' 'cmake' 'kdelibs') makedepends=('automoc4' 'cmake' 'kdelibs')
source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${_pkgbase}-${pkgver}-src.tar.xz") source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${_pkgbase}-${pkgver}-src.tar.xz")
md5sums=('64c04c36eea017e7c0ddf687d60de128') md5sums=('0c50a436064c31f890f69d5f321d2e27')
prepare() { prepare() {
@ -65,6 +65,7 @@ package_libnetctlgui-qt4() {
'wpa_supplicant: wifi support') 'wpa_supplicant: wifi support')
provides=('libnetctlgui') provides=('libnetctlgui')
conflicts=('libnetctlgui') conflicts=('libnetctlgui')
install=""
cd "${srcdir}/build-qt4/netctlgui" cd "${srcdir}/build-qt4/netctlgui"
make DESTDIR="${pkgdir}" install make DESTDIR="${pkgdir}" install

@ -1 +1 @@
Subproject commit dd52af08c9d6a2c8652d2d5e21bc2a433efb497a Subproject commit d2798204a1a84a23a9510aeda73d5b9b75d2c8eb

View File

@ -11,7 +11,7 @@ set (PROJECT_CONTACT "esalexeev@gmail.com")
set (PROJECT_LICENSE "GPLv3") set (PROJECT_LICENSE "GPLv3")
set (PROJECT_VERSION_MAJOR 1) set (PROJECT_VERSION_MAJOR 1)
set (PROJECT_VERSION_MINOR 4) set (PROJECT_VERSION_MINOR 4)
set (PROJECT_VERSION_PATCH 9) set (PROJECT_VERSION_PATCH 8)
set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}) set (PROJECT_VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH})
string (TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC) string (TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC)
string (TIMESTAMP CURRENT_YEAR "%Y") string (TIMESTAMP CURRENT_YEAR "%Y")

View File

@ -86,7 +86,7 @@ QStringList Netctl::sources() const
} }
QString Netctl::getCmdOutput(const QString cmd) const QString Netctl::getCmdOutput(const QString cmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
@ -135,7 +135,7 @@ bool Netctl::sourceRequestEvent(const QString &name)
} }
QString Netctl::getExtIp(const QString cmd) const QString Netctl::getExtIp(const QString cmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
@ -144,34 +144,34 @@ QString Netctl::getExtIp(const QString cmd) const
} }
QString Netctl::getInfo(const QStringList profiles, const QStringList statuses) const QString Netctl::getInfo(const QStringList profiles, const QStringList statuses)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (profiles.count() != statuses.count()) return QString("N\\A"); if (profiles.count() != statuses.count()) return QString("N\\A");
QStringList list; QStringList list;
for (int i=0; i<profiles.count(); i++) for (int i=0; i<profiles.count(); i++)
list.append(QString("%1 (%2)").arg(profiles.at(i)).arg(statuses.at(i))); list.append(QString("%1 (%2)").arg(profiles[i]).arg(statuses[i]));
if (list.isEmpty()) list.append(QString("N\\A")); if (list.isEmpty()) list.append(QString("N\\A"));
return list.join(QString(" | ")); return list.join(QString(" | "));
} }
QStringList Netctl::getInterfaceList() const QStringList Netctl::getInterfaceList()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QList<QNetworkInterface> rawList = QNetworkInterface::allInterfaces(); QList<QNetworkInterface> rawList = QNetworkInterface::allInterfaces();
QStringList interfacesList; QStringList interfacesList;
foreach(QNetworkInterface interface, rawList) for (int i=0; i<rawList.count(); i++)
interfacesList.append(interface.name()); interfacesList.append(rawList[i].name());
return interfacesList; return interfacesList;
} }
QString Netctl::getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol) const QString Netctl::getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -181,11 +181,11 @@ QString Netctl::getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol) c
else if (protocol == QAbstractSocket::IPv6Protocol) else if (protocol == QAbstractSocket::IPv6Protocol)
intIp = QString("::1/128"); intIp = QString("::1/128");
QList<QHostAddress> rawList = QNetworkInterface::allAddresses(); QList<QHostAddress> rawList = QNetworkInterface::allAddresses();
foreach(QHostAddress address, rawList) { for (int i=0; i<rawList.count(); i++) {
if (address == QHostAddress(QHostAddress::LocalHost)) continue; if(rawList[i] == QHostAddress(QHostAddress::LocalHost)) continue;
if (address == QHostAddress(QHostAddress::LocalHostIPv6)) continue; if(rawList[i] == QHostAddress(QHostAddress::LocalHostIPv6)) continue;
if (address.protocol() != protocol) continue; if (rawList[i].protocol() != protocol) continue;
intIp = address.toString(); intIp = rawList[i].toString();
break; break;
} }
@ -197,24 +197,21 @@ QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNet
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
netctlAutoStatus = true;
QString output = getCmdOutput(QString("%1 list").arg(cmdNetctlAuto)); QString output = getCmdOutput(QString("%1 list").arg(cmdNetctlAuto));
if (output.isEmpty()) { if (output.isEmpty()) {
output = getCmdOutput(QString("%1 list").arg(cmdNetctl)); output = getCmdOutput(QString("%1 list").arg(cmdNetctl));
netctlAutoStatus = false; netctlAutoStatus = false;
} else }
netctlAutoStatus = true;
// parse // parse
QStringList currentProfiles; QStringList currentProfiles;
// workaround for first element spaces on which are trimmed QStringList profileList = output.split(QChar('\n'));
QStringList profileList = QString(" %1").arg(output).split(QChar('\n'));
for (int i=0; i<profileList.count(); i++) { for (int i=0; i<profileList.count(); i++) {
bool isActive = (profileList.at(i)[0] == QChar('*')); bool isActive = (profileList[i][0] == QChar('*'));
profileList[i].remove(0, 2); profileList[i].remove(0, 2);
if (isActive) currentProfiles.append(profileList.at(i)); if (isActive) currentProfiles.append(profileList[i]);
} }
profileList.sort();
currentProfiles.sort();
// return profiles // return profiles
currentProfile = currentProfiles; currentProfile = currentProfiles;
@ -223,7 +220,7 @@ QStringList Netctl::getProfileList(const QString cmdNetctl, const QString cmdNet
} }
QStringList Netctl::getProfileStringStatus(const QString cmdNetctl) const QStringList Netctl::getProfileStringStatus(const QString cmdNetctl)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -233,8 +230,8 @@ QStringList Netctl::getProfileStringStatus(const QString cmdNetctl) const
return status; return status;
} }
foreach(QString profile, currentProfile) { for (int i=0; i<currentProfile.count(); i++) {
TaskResult process = runTask(QString("%1 is-enabled %2").arg(cmdNetctl).arg(profile)); TaskResult process = runTask(QString("%1 is-enabled %2").arg(cmdNetctl).arg(currentProfile[i]));
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
status.append(process.exitCode == 0 ? QString("enabled") : QString("static")); status.append(process.exitCode == 0 ? QString("enabled") : QString("static"));
@ -249,8 +246,8 @@ void Netctl::initSources()
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList sourcesList = sources(); QStringList sourcesList = sources();
foreach(QString source, sourcesList) for (int i=0; i<sourcesList.count(); i++)
setData(source, QString("value"), QString("N\\A")); setData(sourcesList[i], QString("value"), QString("N\\A"));
} }

View File

@ -27,14 +27,14 @@ class Netctl : public Plasma::DataEngine
Q_OBJECT Q_OBJECT
public: public:
explicit Netctl(QObject *parent, const QVariantList &args); Netctl(QObject *parent, const QVariantList &args);
virtual ~Netctl(); ~Netctl();
QString getExtIp(const QString cmd) const; QString getExtIp(const QString cmd);
QString getInfo(const QStringList profiles, const QStringList statuses) const; QString getInfo(const QStringList profiles, const QStringList statuses);
QStringList getInterfaceList() const; QStringList getInterfaceList();
QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol) const; QString getIntIp(const QAbstractSocket::NetworkLayerProtocol protocol);
QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto); QStringList getProfileList(const QString cmdNetctl, const QString cmdNetctlAuto);
QStringList getProfileStringStatus(const QString cmdNetctl) const; QStringList getProfileStringStatus(const QString cmdNetctl);
public slots: public slots:
void initSources(); void initSources();
@ -53,7 +53,7 @@ private:
// configuration // configuration
bool debug; bool debug;
QVariantMap configuration; QVariantMap configuration;
QString getCmdOutput(const QString cmd) const; QString getCmdOutput(const QString cmd);
void readConfiguration(); void readConfiguration();
}; };

View File

@ -14,7 +14,7 @@ X-KDE-PluginInfo-Author=Evgeniy Alekseev
X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=netctl X-KDE-PluginInfo-Name=netctl
X-KDE-PluginInfo-Version=@PROJECT_VERSION@ X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Website=https://arcanis.me/projects/netctl-gui/ X-KDE-PluginInfo-Website=http://arcanis.name/projects/netctl-gui/
X-KDE-PluginInfo-Category=Network X-KDE-PluginInfo-Category=Network
X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3 X-KDE-PluginInfo-License=GPLv3

View File

@ -290,12 +290,12 @@ small {
</tr> </tr>
<!-- general information --> <!-- general information -->
<tr> <tr>
<td>QStringList ActiveProfile()</td> <td>QString ActiveProfile()</td>
<td>returns active profile from netctl or netctl-auto</td> <td>returns active profile from netctl or netctl-auto</td>
<td>no</td> <td>no</td>
</tr> </tr>
<tr> <tr>
<td>QStringList ActiveProfileStatus()</td> <td>QString ActiveProfileStatus()</td>
<td>returns active profile status from netctl or netctl-auto. May be <code>netctl-auto</code>, <code>active (enabled)</code>, <code>active (static)</code>, <code>inactive (enabled)</code>, <code>inactive (static)</code></td> <td>returns active profile status from netctl or netctl-auto. May be <code>netctl-auto</code>, <code>active (enabled)</code>, <code>active (static)</code>, <code>inactive (enabled)</code>, <code>inactive (static)</code></td>
<td>no</td> <td>no</td>
</tr> </tr>
@ -305,7 +305,7 @@ small {
<td>no</td> <td>no</td>
</tr> </tr>
<tr> <tr>
<td>QStringList netctlActiveProfile()</td> <td>QString netctlActiveProfile()</td>
<td>returns active profile from netctl even if netctl-auto is running</td> <td>returns active profile from netctl even if netctl-auto is running</td>
<td>no</td> <td>no</td>
</tr> </tr>
@ -464,7 +464,7 @@ small {
<h2><a href="#links" class="anchor" id="links"></a>External links</h2> <h2><a href="#links" class="anchor" id="links"></a>External links</h2>
<ul> <ul>
<li><a href="https://arcanis.me/projects/netctl-gui/">Homepage</a></li> <li><a href="http://arcanis.name/projects/netctl-gui/">Homepage</a></li>
<li><a href="https://github.com/arcan1s/netctl-gui">Repository</a></li> <li><a href="https://github.com/arcan1s/netctl-gui">Repository</a></li>
<li><a href="https://github.com/arcan1s/netctl-gui/issues">Bugtracker</a></li> <li><a href="https://github.com/arcan1s/netctl-gui/issues">Bugtracker</a></li>
</ul> </ul>

View File

@ -98,7 +98,7 @@ env -i bash -c "source '&lt;profile&gt;'; for i in &#36;{!&lt;key&gt;[@]}; do ec
<h2><a href="#links" class="anchor" id="links"></a>External links</h2> <h2><a href="#links" class="anchor" id="links"></a>External links</h2>
<ul> <ul>
<li><a href="https://arcanis.me/projects/netctl-gui/">Homepage</a></li> <li><a href="http://arcanis.name/projects/netctl-gui/">Homepage</a></li>
<li><a href="https://github.com/arcan1s/netctl-gui">Repository</a></li> <li><a href="https://github.com/arcan1s/netctl-gui">Repository</a></li>
<li><a href="https://github.com/arcan1s/netctl-gui/issues">Bugtracker</a></li> <li><a href="https://github.com/arcan1s/netctl-gui/issues">Bugtracker</a></li>
</ul> </ul>

View File

@ -177,7 +177,7 @@ InterfaceAnswer connectToEssid(const QString essid, QMap<QString,QString> settin
} }
netctlInformation generalInformation(NetctlInterface *interface, const bool useHelper, netctlInformation generalInformation(NetctlInterface* interface, const bool useHelper,
const bool debug) const bool debug)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -204,7 +204,7 @@ netctlInformation generalInformation(NetctlInterface *interface, const bool useH
} }
QMap<QString, QString> profileInformation(const QString profile, NetctlInterface *interface, QMap<QString, QString> profileInformation(const QString profile, NetctlInterface* interface,
const bool useHelper, const bool debug) const bool useHelper, const bool debug)
{ {
if (!useHelper) return interface->profileSettings(profile); if (!useHelper) return interface->profileSettings(profile);

View File

@ -94,10 +94,8 @@ void MainWidget::update()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (mainWindow->currentTab() == 0) { updateMainTab();
updateMainTab(); updateMenuMain();
updateMenuMain();
}
if (timer.interval() != 0) return timer.start(); if (timer.interval() != 0) return timer.start();
} }

View File

@ -111,14 +111,6 @@ MainWindow::~MainWindow()
} }
int MainWindow::currentTab()
{
if (debug) qDebug() << PDEBUG;
return ui->stackedWidget->currentIndex();
}
Qt::ToolBarArea MainWindow::getToolBarArea() Qt::ToolBarArea MainWindow::getToolBarArea()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;

View File

@ -42,12 +42,11 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = nullptr, explicit MainWindow(QWidget *parent = 0,
const QVariantMap args = QVariantMap(), const QVariantMap args = QVariantMap(),
QTranslator *qtAppTranslator = nullptr, QTranslator *qtAppTranslator = 0,
QTranslator *appTranslator = nullptr); QTranslator *appTranslator = 0);
~MainWindow(); ~MainWindow();
int currentTab();
Qt::ToolBarArea getToolBarArea(); Qt::ToolBarArea getToolBarArea();
void emitNeedToBeConfigured(); void emitNeedToBeConfigured();
QStringList printSettings(); QStringList printSettings();

View File

@ -89,6 +89,9 @@
<property name="toolTip"> <property name="toolTip">
<string>The username and password to connect with</string> <string>The username and password to connect with</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -122,6 +125,9 @@
<property name="toolTip"> <property name="toolTip">
<string>The access point (apn) to connect on</string> <string>The access point (apn) to connect on</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>

View File

@ -75,10 +75,8 @@ void WiFiMenuWidget::update()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (mainWindow->currentTab() == 2) { updateWifiTab();
updateWifiTab(); updateMenuWifi();
updateMenuWifi();
}
if (timer.interval() != 0) return timer.start(); if (timer.interval() != 0) return timer.start();
} }

View File

@ -39,25 +39,25 @@ NetctlAdaptor::~NetctlAdaptor()
// netctlCommand // netctlCommand
QStringList NetctlAdaptor::ActiveProfile() QString NetctlAdaptor::ActiveProfile()
{ {
if (isNetctlAutoActive()) if (isNetctlAutoActive())
return netctlCommand->autoGetActiveProfile(); return netctlCommand->autoGetActiveProfile();
else else
return netctlCommand->getActiveProfile(); return netctlCommand->getActiveProfile().join(QChar('|'));
} }
QStringList NetctlAdaptor::ActiveProfileStatus() QString NetctlAdaptor::ActiveProfileStatus()
{ {
if (isNetctlAutoActive()) if (isNetctlAutoActive())
return QStringList() << QString("netctl-auto"); return QString("netctl-auto");
else { else {
QStringList status; QStringList status;
QStringList profiles = ActiveProfile(); QStringList profiles = ActiveProfile().split(QChar('|'));
for (int i=0; i<profiles.count(); i++) for (int i=0; i<profiles.count(); i++)
status.append(netctlCommand->getProfileStatus(profiles[i])); status.append(netctlCommand->getProfileStatus(profiles[i]));
return status; return status.join(QChar('|'));
} }
} }
@ -108,9 +108,9 @@ bool NetctlAdaptor::isProfileEnabled(const QString profile)
} }
QStringList NetctlAdaptor::netctlActiveProfile() QString NetctlAdaptor::netctlActiveProfile()
{ {
return netctlCommand->getActiveProfile(); return netctlCommand->getActiveProfile().join(QChar('|'));
} }

View File

@ -37,8 +37,8 @@ public:
public slots: public slots:
// netctlCommand // netctlCommand
QStringList ActiveProfile(); QString ActiveProfile();
QStringList ActiveProfileStatus(); QString ActiveProfileStatus();
bool autoIsProfileActive(const QString profile); bool autoIsProfileActive(const QString profile);
bool autoIsProfileEnabled(const QString profile); bool autoIsProfileEnabled(const QString profile);
QStringList Information(); QStringList Information();
@ -46,7 +46,7 @@ public slots:
bool isNetctlAutoEnabled(); bool isNetctlAutoEnabled();
bool isProfileActive(const QString profile); bool isProfileActive(const QString profile);
bool isProfileEnabled(const QString profile); bool isProfileEnabled(const QString profile);
QStringList netctlActiveProfile(); QString netctlActiveProfile();
QStringList netctlProfileList(); QStringList netctlProfileList();
QStringList netctlVerboseProfileList(); QStringList netctlVerboseProfileList();
QStringList ProfileList(); QStringList ProfileList();

View File

@ -30,9 +30,10 @@
#include <QMap> #include <QMap>
#include <QObject> #include <QObject>
#include "version.h"
class NetctlProfile; class NetctlProfile;
struct TaskResult;
/** /**
* @struct netctlProfileInfo * @struct netctlProfileInfo
@ -93,75 +94,81 @@ public:
/** /**
* @brief Netctl class destructor * @brief Netctl class destructor
*/ */
virtual ~Netctl(); ~Netctl();
// general information // general information
/** /**
* @brief method which returns active profile name * @brief method which returns active profile name
* @return Netctl::getActiveProfileTemplate() * @return profile name or ""
*/ */
QStringList getActiveProfile() const; QStringList getActiveProfile();
/** /**
* @brief method which returns active profile name from netctl-auto * @brief method which returns active profile name from netctl-auto
* @return Netctl::getActiveProfileTemplate() * @return profile name or ""
*/ */
QStringList autoGetActiveProfile() const; QString autoGetActiveProfile();
/** /**
* @brief method which returns profile informations from netctl * @brief method which returns profile informations from netctl
* @return Netctl::getProfileListTemplate() * @return list of profiles
*/ */
QList<netctlProfileInfo> getProfileList() const; QList<netctlProfileInfo> getProfileList();
/** /**
* @brief method which returns profile informations from netctl-auto * @brief method which returns profile informations from netctl-auto
* @return Netctl::getProfileListTemplate() * @return list of profiles from netctl-auto
*/ */
QList<netctlProfileInfo> getProfileListFromNetctlAuto() const; QList<netctlProfileInfo> getProfileListFromNetctlAuto();
/**
* @brief method which gets description from profile
* @param profile profile name
* @return profile description or ""
*/
Q_DECL_DEPRECATED QString getProfileDescription(const QString profile);
/** /**
* @brief method which gets profile status * @brief method which gets profile status
* @param profile profile name * @param profile profile name
* @return profile status. It may be "active (enabled)", "active (static)", * @return profile status. It may be "active (enabled)", "active (static)",
* "inactive (enabled)", "inactive (static)" * "inactive (enabled)", "inactive (static)"
*/ */
QString getProfileStatus(const QString profile) const; QString getProfileStatus(const QString profile);
/** /**
* @brief method which checks if profile is active * @brief method which checks if profile is active
* @param profile profile name * @param profile profile name
* @return false if profile is inactive * @return false if profile is inactive
* @return true if profile is active * @return true if profile is active
*/ */
bool isProfileActive(const QString profile) const; bool isProfileActive(const QString profile);
/** /**
* @brief method which checks if profile is enabled * @brief method which checks if profile is enabled
* @param profile profile name * @param profile profile name
* @return false if profile is disabled * @return false if profile is disabled
* @return true if profile is enabled * @return true if profile is enabled
*/ */
bool isProfileEnabled(const QString profile) const; bool isProfileEnabled(const QString profile);
/** /**
* @brief method which checks if profile is active (netctl-auto) * @brief method which checks if profile is active (netctl-auto)
* @param profile profile name * @param profile profile name
* @return false if profile is inactive * @return false if profile is inactive
* @return true if profile is active * @return true if profile is active
*/ */
bool autoIsProfileActive(const QString profile) const; bool autoIsProfileActive(const QString profile);
/** /**
* @brief method which checks if profile is enabled (netctl-auto) * @brief method which checks if profile is enabled (netctl-auto)
* @param profile profile name * @param profile profile name
* @return false if profile is disabled * @return false if profile is disabled
* @return true if profile is enabled * @return true if profile is enabled
*/ */
bool autoIsProfileEnabled(const QString profile) const; bool autoIsProfileEnabled(const QString profile);
/** /**
* @brief method which checks netctl-auto autoload status * @brief method which checks netctl-auto autoload status
* @return false if netctl-auto is disabled * @return false if netctl-auto is disabled
* @return true if netctl-auto is enabled * @return true if netctl-auto is enabled
*/ */
bool isNetctlAutoEnabled() const; bool isNetctlAutoEnabled();
/** /**
* @brief method which checks netctl-auto status * @brief method which checks netctl-auto status
* @return false if netctl-auto is inactive * @return false if netctl-auto is inactive
* @return true if netctl-auto is active * @return true if netctl-auto is active
*/ */
bool isNetctlAutoRunning() const; bool isNetctlAutoRunning();
/** /**
* @brief method which check system configuration and return recommended values to keys * @brief method which check system configuration and return recommended values to keys
* @return recommended parametrs * @return recommended parametrs
@ -171,7 +178,7 @@ public:
* @brief method which gets wireless interface list from PREFERED_IFACE and IFACE_DIR * @brief method which gets wireless interface list from PREFERED_IFACE and IFACE_DIR
* @return interface list. If PREFERED_IFACE is not empty it will be first element * @return interface list. If PREFERED_IFACE is not empty it will be first element
*/ */
QStringList getWirelessInterfaceList() const; QStringList getWirelessInterfaceList();
public slots: public slots:
// functions // functions
@ -182,101 +189,101 @@ public slots:
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool enableProfile(const QString profile) const; bool enableProfile(const QString profile);
/** /**
* @brief method which force starts profile * @brief method which force starts profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool forceStartProfile(const QString profile) const; bool forceStartProfile(const QString profile);
/** /**
* @brief method which force stops profile * @brief method which force stops profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool forceStopProfile(const QString profile) const; bool forceStopProfile(const QString profile);
/** /**
* @brief method which reenables profile * @brief method which reenables profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool reenableProfile(const QString profile) const; bool reenableProfile(const QString profile);
/** /**
* @brief method which restarts profile * @brief method which restarts profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool restartProfile(const QString profile) const; bool restartProfile(const QString profile);
/** /**
* @brief method which starts or stops profile * @brief method which starts or stops profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool startProfile(const QString profile) const; bool startProfile(const QString profile);
/** /**
* @brief method which stops all profiles * @brief method which stops all profiles
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool stopAllProfiles() const; bool stopAllProfiles();
/** /**
* @brief method which starts another profile * @brief method which starts another profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool switchToProfile(const QString profile) const; bool switchToProfile(const QString profile);
// netctl-auto // netctl-auto
/** /**
* @brief method which sets all profiles disabled (netctl-auto) * @brief method which sets all profiles disabled (netctl-auto)
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoDisableAllProfiles() const; bool autoDisableAllProfiles();
/** /**
* @brief method which sets profile disabled or enabled (netctl-auto) * @brief method which sets profile disabled or enabled (netctl-auto)
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoEnableProfile(const QString profile) const; bool autoEnableProfile(const QString profile);
/** /**
* @brief method which sets all profiles enabled (netctl-auto) * @brief method which sets all profiles enabled (netctl-auto)
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoEnableAllProfiles() const; bool autoEnableAllProfiles();
/** /**
* @brief method which switchs to profile (netctl-auto) * @brief method which switchs to profile (netctl-auto)
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoStartProfile(const QString profile) const; bool autoStartProfile(const QString profile);
// netctl-auto service // netctl-auto service
/** /**
* @brief method which sets netctl-auto service enabled or disabled * @brief method which sets netctl-auto service enabled or disabled
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoEnableService() const; bool autoEnableService();
/** /**
* @brief method which restarted netctl-auto service * @brief method which restarted netctl-auto service
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoRestartService() const; bool autoRestartService();
/** /**
* @brief method which starts or stops netctl-auto service * @brief method which starts or stops netctl-auto service
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool autoStartService() const; bool autoStartService();
private: private:
/** /**
@ -290,7 +297,7 @@ private:
/** /**
* @brief use RootProcess instead of QProcess. Default is true * @brief use RootProcess instead of QProcess. Default is true
*/ */
bool useSuid; bool useSuid = true;
/** /**
* @brief directory with interfaces. Default is "/sys/class/net/" * @brief directory with interfaces. Default is "/sys/class/net/"
*/ */
@ -298,27 +305,27 @@ private:
/** /**
* @brief prefered interface for WiFi. Default is "" * @brief prefered interface for WiFi. Default is ""
*/ */
QString mainInterface; QString mainInterface = QString(PREFERED_IFACE);
/** /**
* @brief path to netctl command. Default is "netctl" * @brief path to netctl command. Default is "netctl"
*/ */
QString netctlCommand; QString netctlCommand = QString(NETCTL_PATH);
/** /**
* @brief path to netctl-auto command. Default is "netctl-auto" * @brief path to netctl-auto command. Default is "netctl-auto"
*/ */
QString netctlAutoCommand; QString netctlAutoCommand = QString(NETCTLAUTO_PATH);
/** /**
* @brief netctl-auto service name. Default is "netctl-auto" * @brief netctl-auto service name. Default is "netctl-auto"
*/ */
QString netctlAutoService; QString netctlAutoService = QString(NETCTLAUTO_SERVICE);
/** /**
* @brief path to sudo command. Default is "kdesu" * @brief path to sudo command. Default is "kdesu"
*/ */
QString sudoCommand; QString sudoCommand = QString(SUDO_PATH);
/** /**
* @brief path to systemctl command. Default is "systemctl" * @brief path to systemctl command. Default is "systemctl"
*/ */
QString systemctlCommand; QString systemctlCommand = QString(SYSTEMCTL_PATH);
// functions // functions
/** /**
* @brief method which calls command * @brief method which calls command
@ -326,22 +333,21 @@ private:
* @param command command which will be called * @param command command which will be called
* @param commandLine command which will be passed to command * @param commandLine command which will be passed to command
* @param argument argument which will be passed to commandLine * @param argument argument which will be passed to commandLine
* @return process object * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors
*/ */
TaskResult cmdCall(const bool sudo, const QString command, bool cmdCall(const bool sudo, const QString command,
const QString commandLine, const QString argument = QString()) const; const QString commandLine, const QString argument = 0);
/** /**
* @brief method which parse output for profile data * @brief method which calls command and returns its output
* @param data profile list data * @param sudo set true if sudo is needed
* @return list of active profiles if any * @param command command which will be called
* @param commandLine command which will be passed to command
* @param argument argument which will be passed to commandLine
* @return command output
*/ */
QStringList getActiveProfileTemplate(const QList<netctlProfileInfo> data) const; QString getCmdOutput(const bool sudo, const QString command,
/** const QString commandLine, const QString argument = 0);
* @brief get profile list from sources
* @param isAuto use netctl-auto instead of netctl
* @return profile list
*/
QList<netctlProfileInfo> getProfileListTemplate(const bool isAuto) const;
}; };

View File

@ -109,7 +109,7 @@ public:
/** /**
* @brief NetctlInterface class destructor * @brief NetctlInterface class destructor
*/ */
virtual ~NetctlInterface(); ~NetctlInterface();
// control methods // control methods
/** /**
* @brief method which creates and copies profile * @brief method which creates and copies profile
@ -120,7 +120,7 @@ public:
* @return InterfaceAnswer::True if profile is created * @return InterfaceAnswer::True if profile is created
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer createProfile(const QString profile, const QMap<QString, QString> settings) const; InterfaceAnswer createProfile(const QString profile, const QMap<QString, QString> settings);
/** /**
* @brief method which connects to ESSID * @brief method which connects to ESSID
* @remark netctl independ * @remark netctl independ
@ -130,7 +130,7 @@ public:
* @return InterfaceAnswer::True if profile is active * @return InterfaceAnswer::True if profile is active
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer connectToEssid(const QString essid, QMap<QString, QString> settings) const; InterfaceAnswer connectToEssid(const QString essid, QMap<QString, QString> settings);
/** /**
* @brief method which connects to existent profile by ESSID * @brief method which connects to existent profile by ESSID
* @remark netctl independ * @remark netctl independ
@ -139,7 +139,7 @@ public:
* @return InterfaceAnswer::True if profile is active * @return InterfaceAnswer::True if profile is active
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer connectToKnownEssid(const QString essid) const; InterfaceAnswer connectToKnownEssid(const QString essid);
/** /**
* @brief method which creates wireless profile and connects to it * @brief method which creates wireless profile and connects to it
* @remark netctl independ * @remark netctl independ
@ -149,7 +149,7 @@ public:
* @return InterfaceAnswer::True if profile is active * @return InterfaceAnswer::True if profile is active
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer connectToUnknownEssid(const QString essid, QMap<QString, QString> settings) const; InterfaceAnswer connectToUnknownEssid(const QString essid, QMap<QString, QString> settings);
/** /**
* @brief method which enables or disables selected profile and returns its status * @brief method which enables or disables selected profile and returns its status
* @remark netctl only * @remark netctl only
@ -158,7 +158,7 @@ public:
* @return InterfaceAnswer::True if profile is enabled * @return InterfaceAnswer::True if profile is enabled
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer enableProfile(const QString profile) const; InterfaceAnswer enableProfile(const QString profile);
/** /**
* @brief method which removes selected profile * @brief method which removes selected profile
* @remark netctl independ * @remark netctl independ
@ -166,7 +166,7 @@ public:
* @return InterfaceAnswer::True if profile does not exists anymore * @return InterfaceAnswer::True if profile does not exists anymore
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer removeProfile(const QString profile) const; InterfaceAnswer removeProfile(const QString profile);
/** /**
* @brief method which restarts selected profile and returns its status * @brief method which restarts selected profile and returns its status
* @remark netctl only * @remark netctl only
@ -175,7 +175,7 @@ public:
* @return InterfaceAnswer::True if profile is active * @return InterfaceAnswer::True if profile is active
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer restartProfile(const QString profile) const; InterfaceAnswer restartProfile(const QString profile);
/** /**
* @brief method which starts/stops or switchs to selected profile and returns its status * @brief method which starts/stops or switchs to selected profile and returns its status
* @remark netctl only * @remark netctl only
@ -184,14 +184,14 @@ public:
* @return InterfaceAnswer::True if profile is active * @return InterfaceAnswer::True if profile is active
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer startProfile(const QString profile) const; InterfaceAnswer startProfile(const QString profile);
/** /**
* @brief method which stops all profiles * @brief method which stops all profiles
* @remark netctl only * @remark netctl only
* @return InterfaceAnswer::True if there are no errors * @return InterfaceAnswer::True if there are no errors
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer stopAllProfiles() const; InterfaceAnswer stopAllProfiles();
/** /**
* @brief method which switchs to selected profile and returns its status * @brief method which switchs to selected profile and returns its status
* @remark both netctl and netctl-auto * @remark both netctl and netctl-auto
@ -200,26 +200,26 @@ public:
* @return InterfaceAnswer::True if profile is active * @return InterfaceAnswer::True if profile is active
* @return InterfaceAnswer::Error if an error occurs * @return InterfaceAnswer::Error if an error occurs
*/ */
InterfaceAnswer switchToProfile(const QString profile) const; InterfaceAnswer switchToProfile(const QString profile);
// information // information
/** /**
* @brief method which returns general information * @brief method which returns general information
* @remark both netctl and netctl-auto * @remark both netctl and netctl-auto
* @return netctlInformation structure * @return netctlInformation structure
*/ */
netctlInformation information() const; netctlInformation information();
/** /**
* @brief method which reads settings from profile * @brief method which reads settings from profile
* @param profile profile name * @param profile profile name
* @return settings from profile * @return settings from profile
*/ */
QMap<QString, QString> profileSettings(const QString profile) const; QMap<QString, QString> profileSettings(const QString profile);
/** /**
* @brief method which returns current status * @brief method which returns current status
* @remark both netctl and netctl-auto * @remark both netctl and netctl-auto
* @return netctlCurrent structure * @return netctlCurrent structure
*/ */
netctlCurrent status() const; netctlCurrent status();
private: private:
/** /**

View File

@ -30,6 +30,8 @@
#include <QMap> #include <QMap>
#include <QObject> #include <QObject>
#include "version.h"
/** /**
* @brief The NetctlProfile class interacts with netctl profiles * @brief The NetctlProfile class interacts with netctl profiles
@ -52,21 +54,21 @@ public:
/** /**
* @brief Netctl class destructor * @brief Netctl class destructor
*/ */
virtual ~NetctlProfile(); ~NetctlProfile();
/** /**
* @brief method which copies temporary profile to PROFILE_DIR * @brief method which copies temporary profile to PROFILE_DIR
* @param oldPath path to temprorary profile * @param oldPath path to temprorary profile
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool copyProfile(const QString oldPath) const; bool copyProfile(const QString oldPath);
/** /**
* @brief method which creates temporary profile * @brief method which creates temporary profile
* @param profile profile name * @param profile profile name
* @param settings profile configuration. All available keys will be printed to the profile * @param settings profile configuration. All available keys will be printed to the profile
* @return temporary profile name * @return temporary profile name
*/ */
QString createProfile(const QString profile, const QMap<QString, QString> settings) const; QString createProfile(const QString profile, const QMap<QString, QString> settings);
/** /**
* @brief method which check system configuration and return recommended values to keys * @brief method which check system configuration and return recommended values to keys
* @return recommended parametrs * @return recommended parametrs
@ -77,28 +79,28 @@ public:
* @param profile profile name * @param profile profile name
* @return settings from profile * @return settings from profile
*/ */
QMap<QString, QString> getSettingsFromProfile(const QString profile) const; QMap<QString, QString> getSettingsFromProfile(const QString profile);
/** /**
* @brief method which return value from profile by key * @brief method which return value from profile by key
* @param profile profile name * @param profile profile name
* @param key required key * @param key required key
* @return value by key * @return value by key
*/ */
QString getValueFromProfile(const QString profile, const QString key) const; QString getValueFromProfile(const QString profile, const QString key);
/** /**
* @brief method which return values from profile by keys * @brief method which return values from profile by keys
* @param profile profile name * @param profile profile name
* @param keys required keys * @param keys required keys
* @return values by keys * @return values by keys
*/ */
QStringList getValuesFromProfile(const QString profile, const QStringList keys) const; QStringList getValuesFromProfile(const QString profile, const QStringList keys);
/** /**
* @brief method which removes profile * @brief method which removes profile
* @param profile profile name * @param profile profile name
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool removeProfile(const QString profile) const; bool removeProfile(const QString profile);
private: private:
/** /**
@ -108,7 +110,7 @@ private:
/** /**
* @brief use RootProcess instead of QProcess. Default is true * @brief use RootProcess instead of QProcess. Default is true
*/ */
bool useSuid; bool useSuid = true;
/** /**
* @brief directory which contains profiles. Default is "/etc/netctl" * @brief directory which contains profiles. Default is "/etc/netctl"
*/ */
@ -116,7 +118,7 @@ private:
/** /**
* @brief path to sudo command. Default is "kdesu" * @brief path to sudo command. Default is "kdesu"
*/ */
QString sudoCommand; QString sudoCommand = QString(SUDO_PATH);
}; };

View File

@ -30,6 +30,8 @@
#include <QMap> #include <QMap>
#include <QObject> #include <QObject>
#include "version.h"
class Netctl; class Netctl;
class NetctlProfile; class NetctlProfile;
@ -111,14 +113,14 @@ public:
/** /**
* @brief WpaSup class destructor * @brief WpaSup class destructor
*/ */
virtual ~WpaSup(); ~WpaSup();
// general information // general information
/** /**
* @brief method which gets profile name by ESSID * @brief method which gets profile name by ESSID
* @param essid ESSID name * @param essid ESSID name
* @return profile name * @return profile name
*/ */
QString existentProfile(const QString essid) const; QString existentProfile(const QString essid);
/** /**
* @brief method which check system configuration and return recommended values to keys * @brief method which check system configuration and return recommended values to keys
* @return recommended parametrs * @return recommended parametrs
@ -130,7 +132,14 @@ public:
* @return false if profile is inactive * @return false if profile is inactive
* @return true if profile is active * @return true if profile is active
*/ */
bool isProfileActive(const QString essid) const; bool isProfileActive(const QString essid);
/**
* @brief method which checks profile existence by ESSID
* @param essid ESSID name
* @return false if profile does not exist
* @return true if profile exists
*/
Q_DECL_DEPRECATED bool isProfileExists(const QString essid);
public slots: public slots:
// functions // functions
@ -138,24 +147,24 @@ public slots:
* @brief method which returns active point information * @brief method which returns active point information
* @return current point information * @return current point information
*/ */
netctlWifiInfo current() const; netctlWifiInfo current();
/** /**
* @brief method which scans WiFi networks * @brief method which scans WiFi networks
* @return list of essids * @return list of essids
*/ */
QList<netctlWifiInfo> scanWifi() const; QList<netctlWifiInfo> scanWifi();
/** /**
* @brief method which calls wpa_supplicant * @brief method which calls wpa_supplicant
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool startWpaSupplicant() const; bool startWpaSupplicant();
/** /**
* @brief method which send TERMINATE signal to wpa_supplicant * @brief method which send TERMINATE signal to wpa_supplicant
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool stopWpaSupplicant() const; bool stopWpaSupplicant();
private: private:
/** /**
@ -173,54 +182,54 @@ private:
/** /**
* @brief use RootProcess instead of QProcess. Default is true * @brief use RootProcess instead of QProcess. Default is true
*/ */
bool useSuid; bool useSuid = true;
/** /**
* @brief path to ctrl_directory. Defaults is "/run/wpa_supplicant" * @brief path to ctrl_directory. Defaults is "/run/wpa_supplicant"
*/ */
QString ctrlDir; QString ctrlDir = QString(CTRL_DIR);
/** /**
* @brief group which is owner of CTRL_DIR. Default is "users" * @brief group which is owner of CTRL_DIR. Default is "users"
*/ */
QString ctrlGroup; QString ctrlGroup = QString(CTRL_GROUP);
/** /**
* @brief wpa_supplicant PID file. $i is interface. Default is "/run/wpa_supplicant_$i.pid" * @brief wpa_supplicant PID file. $i is interface. Default is "/run/wpa_supplicant_$i.pid"
*/ */
QString pidFile; QString pidFile = QString(PID_FILE);
/** /**
* @brief path to sudo command. Default is "kdesu" * @brief path to sudo command. Default is "kdesu"
*/ */
QString sudoCommand; QString sudoCommand = QString(SUDO_PATH);
/** /**
* @brief path to wpa_cli command. Default is "wpa_cli" * @brief path to wpa_cli command. Default is "wpa_cli"
*/ */
QString wpaCliPath; QString wpaCliPath = QString(WPACLI_PATH);
/** /**
* @brief wpa_supplicant drivers comma separated. Default is "nl80211,wext" * @brief wpa_supplicant drivers comma separated. Default is "nl80211,wext"
*/ */
QString wpaDrivers; QString wpaDrivers = QString(WPA_DRIVERS);
/** /**
* @brief path to wpa_supplicant command. Default is "wpa_supplicant" * @brief path to wpa_supplicant command. Default is "wpa_supplicant"
*/ */
QString wpaSupPath; QString wpaSupPath = QString(WPASUP_PATH);
// functions // functions
/** /**
* @brief method which calls wpa_cli and returns its output * @brief method which calls wpa_cli and returns its output
* @param commandLine command which will be passed to wpa_cli * @param commandLine command which will be passed to wpa_cli
* @return wpa_cli output * @return wpa_cli output
*/ */
QString getWpaCliOutput(const QString commandLine) const; QString getWpaCliOutput(const QString commandLine);
/** /**
* @brief method which will be called to sleep thread * @brief method which will be called to sleep thread
* @param sec time interval, seconds * @param sec time interval, seconds
*/ */
bool waitForProcess(const int sec) const; bool waitForProcess(const int sec);
/** /**
* @brief method which calls wpa_cli * @brief method which calls wpa_cli
* @param commandLine command which will be passed to wpa_cli * @param commandLine command which will be passed to wpa_cli
* @return false if components are not found or command exit code is not equal to 0 * @return false if components are not found or command exit code is not equal to 0
* @return true if the method was completed without errors * @return true if the method was completed without errors
*/ */
bool wpaCliCall(const QString commandLine) const; bool wpaCliCall(const QString commandLine);
}; };

View File

@ -30,8 +30,6 @@
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <task/taskadds.h> #include <task/taskadds.h>
#include "version.h"
/** /**
* @class Netctl * @class Netctl
@ -44,16 +42,27 @@ Netctl::Netctl(const bool debugCmd, const QMap<QString, QString> settings)
{ {
netctlProfile = new NetctlProfile(debug, settings); netctlProfile = new NetctlProfile(debug, settings);
ifaceDirectory = new QDir(settings.value(QString("IFACE_DIR"), QString(IFACE_DIR))); if (settings.contains(QString("IFACE_DIR")))
mainInterface = settings.value(QString("PREFERED_IFACE"), QString(PREFERED_IFACE)); ifaceDirectory = new QDir(settings[QString("IFACE_DIR")]);
netctlCommand = settings.value(QString("NETCTL_PATH"), QString(NETCTL_PATH)); else
netctlAutoCommand = settings.value(QString("NETCTLAUTO_PATH"), QString(NETCTLAUTO_PATH)); ifaceDirectory = new QDir(QString(IFACE_DIR));
netctlAutoService = settings.value(QString("NETCTLAUTO_SERVICE"), QString(NETCTLAUTO_SERVICE)); if (settings.contains(QString("PREFERED_IFACE")))
sudoCommand = settings.value(QString("SUDO_PATH"), QString(SUDO_PATH)); mainInterface = settings[QString("PREFERED_IFACE")];
systemctlCommand = settings.value(QString("SYSTEMCTL_PATH"), QString(SYSTEMCTL_PATH)); if (settings.contains(QString("NETCTL_PATH")))
useSuid = (settings.value(QString("FORCE_SUDO"), QString("true")) != QString("true")); netctlCommand = settings[QString("NETCTL_PATH")];
if (settings.contains(QString("NETCTLAUTO_PATH")))
netctlAutoCommand = settings[QString("NETCTLAUTO_PATH")];
if (settings.contains(QString("NETCTLAUTO_SERVICE")))
netctlAutoService = settings[QString("NETCTLAUTO_SERVICE")];
if (settings.contains(QString("SUDO_PATH")))
sudoCommand = settings[QString("SUDO_PATH")];
if (settings.contains(QString("SYSTEMCTL_PATH")))
systemctlCommand = settings[QString("SYSTEMCTL_PATH")];
if (settings.contains(QString("FORCE_SUDO")))
useSuid = (settings[QString("FORCE_SUDO")] != QString("true"));
if (useSuid) sudoCommand = QString(""); if (useSuid)
sudoCommand = QString("");
} }
@ -69,61 +78,207 @@ Netctl::~Netctl()
} }
// functions
/**
* @fn cmdCall
*/
bool Netctl::cmdCall(const bool sudo, const QString command, const QString commandLine, const QString argument)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
if (command.isEmpty()) {
if (debug) qDebug() << PDEBUG << ":" << "Could not find command";
return false;
}
QString cmd = QString("");
if (sudo)
cmd = QString("%1 ").arg(sudoCommand);
cmd += QString("%1 %2").arg(command).arg(commandLine);
if (!argument.isEmpty())
cmd += QString(" \"%1\"").arg(argument);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, (useSuid && sudo));
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return (process.exitCode == 0);
}
/**
* @fn getCmdOutput
*/
QString Netctl::getCmdOutput(const bool sudo, const QString command, const QString commandLine, const QString argument)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
if (command.isEmpty()) {
if (debug) qDebug() << PDEBUG << ":" << "Could not find command";
return QString();
}
QString cmd = QString("");
if (sudo)
cmd = QString("%1 ").arg(sudoCommand);
cmd += QString("%1 %2").arg(command).arg(commandLine);
if (!argument.isEmpty())
cmd += QString(" \"%1\"").arg(argument);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, (useSuid && sudo));
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process.output;
}
// general information // general information
/** /**
* @fn getActiveProfile * @fn getActiveProfile
*/ */
QStringList Netctl::getActiveProfile() const QStringList Netctl::getActiveProfile()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return getActiveProfileTemplate(getProfileList()); QStringList profile;
QList<netctlProfileInfo> fullProfilesInfo = getProfileList();
for (int i=0; i<fullProfilesInfo.count(); i++)
if (fullProfilesInfo[i].active)
profile.append(fullProfilesInfo[i].name);
return profile;
} }
/** /**
* @fn autoGetActiveProfile * @fn autoGetActiveProfile
*/ */
QStringList Netctl::autoGetActiveProfile() const QString Netctl::autoGetActiveProfile()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return getActiveProfileTemplate(getProfileListFromNetctlAuto()); QString profile = QString("");
QList<netctlProfileInfo> fullProfilesInfo = getProfileListFromNetctlAuto();
for (int i=0; i<fullProfilesInfo.count(); i++)
if (fullProfilesInfo[i].active) {
profile = fullProfilesInfo[i].name;
break;
}
return profile;
} }
/** /**
* @fn getProfileList * @fn getProfileList
*/ */
QList<netctlProfileInfo> Netctl::getProfileList() const QList<netctlProfileInfo> Netctl::getProfileList()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return getProfileListTemplate(false); QList<netctlProfileInfo> fullProfilesInfo;
QStringList output = getCmdOutput(false, netctlCommand, QString("list"))
.split(QChar('\n'), QString::SkipEmptyParts);
for (int i=0; i<output.count(); i++) {
netctlProfileInfo profileInfo;
profileInfo.name = output[i].mid(2, -1);
profileInfo.active = (output[i][0] == QChar('*'));
profileInfo.enabled = isProfileEnabled(profileInfo.name);
// external
QStringList keys;
keys.append(QString("Connection"));
keys.append(QString("Description"));
keys.append(QString("ESSID"));
keys.append(QString("Interface"));
QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name,
keys);
profileInfo.description = profileValues[1];
profileInfo.essid = profileValues[2];
profileInfo.interface = profileValues[3];
profileInfo.type = profileValues[0];
profileInfo.netctlAuto = false;
fullProfilesInfo.append(profileInfo);
}
return fullProfilesInfo;
} }
/** /**
* @fn getProfileListFromNetctlAuto * @fn getProfileListFromNetctlAuto
*/ */
QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto() const QList<netctlProfileInfo> Netctl::getProfileListFromNetctlAuto()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return getProfileListTemplate(true); QList<netctlProfileInfo> fullProfilesInfo;
QStringList output = getCmdOutput(false, netctlAutoCommand, QString("list"))
.split(QChar('\n'), QString::SkipEmptyParts);
for (int i=0; i<output.count(); i++) {
netctlProfileInfo profileInfo;
profileInfo.name = output[i].mid(2, -1);
profileInfo.active = (output[i][0] == QChar('*'));
profileInfo.enabled = (output[i][0] != QChar('!'));
// external
QStringList keys;
keys.append(QString("Connection"));
keys.append(QString("Description"));
keys.append(QString("ESSID"));
keys.append(QString("Interface"));
QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name,
keys);
profileInfo.description = profileValues[1];
profileInfo.essid = profileValues[2];
profileInfo.interface = profileValues[3];
profileInfo.type = profileValues[0];
profileInfo.netctlAuto = true;
fullProfilesInfo.append(profileInfo);
}
return fullProfilesInfo;
}
/**
* @fn getProfileDescription
*/
QString Netctl::getProfileDescription(const QString profile)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (netctlProfile == 0) {
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
return QString();
}
return netctlProfile->getValueFromProfile(profile, QString("Description"));
} }
/** /**
* @fn getProfileStatus * @fn getProfileStatus
*/ */
QString Netctl::getProfileStatus(const QString profile) const QString Netctl::getProfileStatus(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
QString status = isProfileActive(profile) ? QString("active") : QString("inactive"); QString status;
status += isProfileEnabled(profile) ? QString(" (enabled)") : QString(" (static)"); if (isProfileActive(profile))
status = QString("active");
else
status = QString("inactive");
if (isProfileEnabled(profile))
status += QString(" (enabled)");
else
status += QString(" (static)");
return status; return status;
} }
@ -132,40 +287,42 @@ QString Netctl::getProfileStatus(const QString profile) const
/** /**
* @fn isProfileActive * @fn isProfileActive
*/ */
bool Netctl::isProfileActive(const QString profile) const bool Netctl::isProfileActive(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(false, netctlCommand, QString("status"), profile).status(); QString output = getCmdOutput(false, netctlCommand, QString("status"), profile);
return (output.contains(QString("Active: active")));
} }
/** /**
* @fn isProfileEnabled * @fn isProfileEnabled
*/ */
bool Netctl::isProfileEnabled(const QString profile) const bool Netctl::isProfileEnabled(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(false, netctlCommand, QString("is-enabled"), profile).output == QString("enabled\n"); return cmdCall(false, netctlCommand, QString("is-enabled"), profile);
} }
/** /**
* @fn autoIsProfileActive * @fn autoIsProfileActive
*/ */
bool Netctl::autoIsProfileActive(const QString profile) const bool Netctl::autoIsProfileActive(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
bool status = false; bool status = false;
QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto(); QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto();
foreach(netctlProfileInfo profileInfo, profiles) { for (int i=0; i<profiles.count(); i++) {
if (profileInfo.name != profile) continue; if (profiles[i].name == profile) continue;
status = profileInfo.active; status = profiles[i].active;
break; break;
} }
@ -176,16 +333,16 @@ bool Netctl::autoIsProfileActive(const QString profile) const
/** /**
* @fn autoIsProfileEnabled * @fn autoIsProfileEnabled
*/ */
bool Netctl::autoIsProfileEnabled(const QString profile) const bool Netctl::autoIsProfileEnabled(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
bool status = false; bool status = false;
QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto(); QList<netctlProfileInfo> profiles = getProfileListFromNetctlAuto();
foreach(netctlProfileInfo profileInfo, profiles) { for (int i=0; i<profiles.count(); i++) {
if (profileInfo.name != profile) continue; if (profiles[i].name == profile) continue;
status = profileInfo.enabled; status = profiles[i].enabled;
break; break;
} }
@ -196,7 +353,7 @@ bool Netctl::autoIsProfileEnabled(const QString profile) const
/** /**
* @fn isNetctlAutoEnabled * @fn isNetctlAutoEnabled
*/ */
bool Netctl::isNetctlAutoEnabled() const bool Netctl::isNetctlAutoEnabled()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlAutoService.isEmpty()) { if (netctlAutoService.isEmpty()) {
@ -209,16 +366,16 @@ bool Netctl::isNetctlAutoEnabled() const
return false; return false;
} }
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces.first()); QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
return cmdCall(false, systemctlCommand, QString("is-enabled"), argument).status(); return cmdCall(false, systemctlCommand, QString("is-enabled"), argument);
} }
/** /**
* @fn isNetctlAutoRunning * @fn isNetctlAutoRunning
*/ */
bool Netctl::isNetctlAutoRunning() const bool Netctl::isNetctlAutoRunning()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlAutoService.isEmpty()) { if (netctlAutoService.isEmpty()) {
@ -231,9 +388,9 @@ bool Netctl::isNetctlAutoRunning() const
return false; return false;
} }
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces.first()); QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
return cmdCall(false, systemctlCommand, QString("is-active"), argument).status(); return cmdCall(false, systemctlCommand, QString("is-active"), argument);
} }
@ -251,9 +408,9 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
recommended.clear(); recommended.clear();
recommended.append(QString("netctlgui-helper")); recommended.append(QString("netctlgui-helper"));
recommended.append(QString("netctlgui-helper-suid")); recommended.append(QString("netctlgui-helper-suid"));
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("FORCE_SUDO")] = QString("false"); settings[QString("FORCE_SUDO")] = QString("false");
break; break;
} }
@ -279,9 +436,9 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
settings[QString("NETCTL_PATH")] = QString(""); settings[QString("NETCTL_PATH")] = QString("");
recommended.clear(); recommended.clear();
recommended.append("netctl"); recommended.append("netctl");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("NETCTL_PATH")] = process.output.trimmed(); settings[QString("NETCTL_PATH")] = process.output.trimmed();
break; break;
} }
@ -291,9 +448,9 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
settings[QString("NETCTLAUTO_PATH")] = QString(""); settings[QString("NETCTLAUTO_PATH")] = QString("");
recommended.clear(); recommended.clear();
recommended.append("netctl-auto"); recommended.append("netctl-auto");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("NETCTLAUTO_PATH")] = process.output.trimmed(); settings[QString("NETCTLAUTO_PATH")] = process.output.trimmed();
break; break;
} }
@ -321,9 +478,9 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
recommended.append("sudo"); recommended.append("sudo");
recommended.append("kdesu"); recommended.append("kdesu");
recommended.append("gksu"); recommended.append("gksu");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("SUDO_PATH")] = process.output.trimmed(); settings[QString("SUDO_PATH")] = process.output.trimmed();
break; break;
} }
@ -333,9 +490,9 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
settings[QString("SYSTEMCTL_PATH")] = QString(""); settings[QString("SYSTEMCTL_PATH")] = QString("");
recommended.clear(); recommended.clear();
recommended.append("systemctl"); recommended.append("systemctl");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("SYSTEMCTL_PATH")] = process.output.trimmed(); settings[QString("SYSTEMCTL_PATH")] = process.output.trimmed();
break; break;
} }
@ -348,7 +505,7 @@ QMap<QString, QString> Netctl::getRecommendedConfiguration()
/** /**
* @fn getWirelessInterfaceList * @fn getWirelessInterfaceList
*/ */
QStringList Netctl::getWirelessInterfaceList() const QStringList Netctl::getWirelessInterfaceList()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ifaceDirectory == nullptr) { if (ifaceDirectory == nullptr) {
@ -360,11 +517,11 @@ QStringList Netctl::getWirelessInterfaceList() const
if (!mainInterface.isEmpty()) if (!mainInterface.isEmpty())
interfaces.append(mainInterface); interfaces.append(mainInterface);
QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot); QStringList allInterfaces = ifaceDirectory->entryList(QDir::Dirs | QDir::NoDotAndDotDot);
foreach(QString interface, allInterfaces) { for (int i=0; i<allInterfaces.count(); i++) {
QString dir = QString("%1/%2/wireless").arg(ifaceDirectory->path()).arg(interface); QString dir = QString("%1/%2/wireless").arg(ifaceDirectory->path()).arg(allInterfaces[i]);
if (debug) qDebug() << PDEBUG << ":" << "Check directory" << dir; if (debug) qDebug() << PDEBUG << ":" << "Check directory" << dir;
if (QDir(dir).exists()) if (QDir(dir).exists())
interfaces.append(interface); interfaces.append(allInterfaces[i]);
} }
return interfaces; return interfaces;
@ -375,156 +532,159 @@ QStringList Netctl::getWirelessInterfaceList() const
/** /**
* @fn enableProfile * @fn enableProfile
*/ */
bool Netctl::enableProfile(const QString profile) const bool Netctl::enableProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(true, netctlCommand, if (isProfileEnabled(profile))
isProfileEnabled(profile) ? QString("disable") : QString("enable"), return cmdCall(true, netctlCommand, QString("disable"), profile);
profile).status(); else
return cmdCall(true, netctlCommand, QString("enable"), profile);
} }
/** /**
* @fn forceStartProfile * @fn forceStartProfile
*/ */
bool Netctl::forceStartProfile(const QString profile) const bool Netctl::forceStartProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(true, netctlCommand, QString("start"), profile).status(); return cmdCall(true, netctlCommand, QString("start"), profile);
} }
/** /**
* @fn forceStopProfile * @fn forceStopProfile
*/ */
bool Netctl::forceStopProfile(const QString profile) const bool Netctl::forceStopProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(true, netctlCommand, QString("stop"), profile).status(); return cmdCall(true, netctlCommand, QString("stop"), profile);
} }
/** /**
* @fn reenableProfile * @fn reenableProfile
*/ */
bool Netctl::reenableProfile(const QString profile) const bool Netctl::reenableProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(true, netctlCommand, QString("reenable"), profile).status(); return cmdCall(true, netctlCommand, QString("reenable"), profile);
} }
/** /**
* @fn restartProfile * @fn restartProfile
*/ */
bool Netctl::restartProfile(const QString profile) const bool Netctl::restartProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(true, netctlCommand, QString("restart"), profile).status(); return cmdCall(true, netctlCommand, QString("restart"), profile);
} }
/** /**
* @fn startProfile * @fn startProfile
*/ */
bool Netctl::startProfile(const QString profile) const bool Netctl::startProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(true, netctlCommand, if (isProfileActive(profile))
isProfileActive(profile) ? QString("stop") : QString("start"), return cmdCall(true, netctlCommand, QString("stop"), profile);
profile).status(); else
return cmdCall(true, netctlCommand, QString("start"), profile);
} }
/** /**
* @fn stopAllProfiles * @fn stopAllProfiles
*/ */
bool Netctl::stopAllProfiles() const bool Netctl::stopAllProfiles()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return cmdCall(true, netctlCommand, QString("stop-all")).status(); return cmdCall(true, netctlCommand, QString("stop-all"));
} }
/** /**
* @fn switchToProfile * @fn switchToProfile
*/ */
bool Netctl::switchToProfile(const QString profile) const bool Netctl::switchToProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return ((isProfileActive(profile)) || return ((isProfileActive(profile)) ||
(cmdCall(true, netctlCommand, QString("switch-to"), profile)).status()); (cmdCall(true, netctlCommand, QString("switch-to"), profile)));
} }
/** /**
* @fn autoDisableAllProfiles * @fn autoDisableAllProfiles
*/ */
bool Netctl::autoDisableAllProfiles() const bool Netctl::autoDisableAllProfiles()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return cmdCall(false, netctlAutoCommand, QString("disable-all")).status(); return cmdCall(false, netctlAutoCommand, QString("disable-all"));
} }
/** /**
* @fn autoEnableProfile * @fn autoEnableProfile
*/ */
bool Netctl::autoEnableProfile(const QString profile) const bool Netctl::autoEnableProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return cmdCall(false, netctlAutoCommand, if (autoIsProfileEnabled(profile))
autoIsProfileEnabled(profile) ? QString("disable") : QString("enable"), return cmdCall(false, netctlAutoCommand, QString("disable"), profile);
profile).status(); else
return cmdCall(false, netctlAutoCommand, QString("enable"), profile);
} }
/** /**
* @fn autoEnableAllProfiles * @fn autoEnableAllProfiles
*/ */
bool Netctl::autoEnableAllProfiles() const bool Netctl::autoEnableAllProfiles()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return cmdCall(false, netctlAutoCommand, QString("enable-all")).status(); return cmdCall(false, netctlAutoCommand, QString("enable-all"));
} }
/** /**
* @fn autoStartProfile * @fn autoStartProfile
*/ */
bool Netctl::autoStartProfile(const QString profile) const bool Netctl::autoStartProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
return ((autoIsProfileActive(profile)) || return ((autoIsProfileActive(profile)) ||
(cmdCall(false, netctlAutoCommand, QString("switch-to"), profile)).status()); (cmdCall(false, netctlAutoCommand, QString("switch-to"), profile)));
} }
/** /**
* @fn autoEnableService * @fn autoEnableService
*/ */
bool Netctl::autoEnableService() const bool Netctl::autoEnableService()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlAutoService.isEmpty()) { if (netctlAutoService.isEmpty()) {
@ -537,18 +697,19 @@ bool Netctl::autoEnableService() const
return false; return false;
} }
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces.first()); QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
return cmdCall(true, systemctlCommand, if (isNetctlAutoEnabled())
isNetctlAutoEnabled() ? QString("disable") : QString("enable"), return cmdCall(true, systemctlCommand, QString("disable"), argument);
argument).status(); else
return cmdCall(true, systemctlCommand, QString("enable"), argument);
} }
/** /**
* @fn autoRestartService * @fn autoRestartService
*/ */
bool Netctl::autoRestartService() const bool Netctl::autoRestartService()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlAutoService.isEmpty()) { if (netctlAutoService.isEmpty()) {
@ -561,17 +722,17 @@ bool Netctl::autoRestartService() const
return false; return false;
} }
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces.first()); QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
return ((!isNetctlAutoRunning()) || return ((!isNetctlAutoRunning()) ||
(cmdCall(true, systemctlCommand, QString("restart"), argument)).status()); (cmdCall(true, systemctlCommand, QString("restart"), argument)));
} }
/** /**
* @fn autoStartService * @fn autoStartService
*/ */
bool Netctl::autoStartService() const bool Netctl::autoStartService()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlAutoService.isEmpty()) { if (netctlAutoService.isEmpty()) {
@ -584,87 +745,10 @@ bool Netctl::autoStartService() const
return false; return false;
} }
QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces.first()); QString argument = QString("%1@%2.service").arg(netctlAutoService).arg(interfaces[0]);
return cmdCall(true, systemctlCommand, if (isNetctlAutoRunning())
isNetctlAutoRunning() ? QString("stop") : QString("start"), return cmdCall(true, systemctlCommand, QString("stop"), argument);
argument).status(); else
} return cmdCall(true, systemctlCommand, QString("start"), argument);
// functions
/**
* @fn cmdCall
*/
TaskResult Netctl::cmdCall(const bool sudo, const QString command,
const QString commandLine, const QString argument) const
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Command" << command;
if (debug) qDebug() << PDEBUG << ":" << "Command line" << commandLine;
if (debug) qDebug() << PDEBUG << ":" << "Argument" << argument;
QString cmd = QString("");
if (sudo) cmd = QString("%1 ").arg(sudoCommand);
cmd += QString("%1 %2").arg(command).arg(commandLine);
if (!argument.isEmpty()) cmd += QString(" \"%1\"").arg(argument);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, (useSuid && sudo));
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process;
};
/**
* @fn getActiveProfileTemplate
*/
QStringList Netctl::getActiveProfileTemplate(const QList<netctlProfileInfo> data) const
{
if (debug) qDebug() << PDEBUG;
QStringList profiles;
foreach(netctlProfileInfo profile, data) {
if (!profile.active) continue;
profiles.append(profile.name);
}
return profiles;
}
/**
* @fn getProfileListTemplate
*/
QList<netctlProfileInfo> Netctl::getProfileListTemplate(const bool isAuto) const
{
if (debug) qDebug() << PDEBUG;
QList<netctlProfileInfo> fullProfilesInfo;
QStringList output = QString(cmdCall(false, isAuto ? netctlAutoCommand : netctlCommand,
QString("list")).output)
.split(QChar('\n'), QString::SkipEmptyParts);
foreach(QString profile, output) {
netctlProfileInfo profileInfo;
profileInfo.name = profile.mid(2, -1);
profileInfo.active = (profile[0] == QChar('*'));
profileInfo.enabled = isAuto ? (profile[0] != QChar('!')) : isProfileEnabled(profileInfo.name);
// external
QStringList keys;
keys.append(QString("Connection"));
keys.append(QString("Description"));
keys.append(QString("ESSID"));
keys.append(QString("Interface"));
QStringList profileValues = netctlProfile->getValuesFromProfile(profileInfo.name,
keys);
profileInfo.description = profileValues[1];
profileInfo.essid = profileValues[2];
profileInfo.interface = profileValues[3];
profileInfo.type = profileValues[0];
profileInfo.netctlAuto = isAuto;
fullProfilesInfo.append(profileInfo);
}
return fullProfilesInfo;
} }

View File

@ -60,8 +60,7 @@ NetctlInterface::~NetctlInterface()
/** /**
* @fn connectToEssid * @fn connectToEssid
*/ */
InterfaceAnswer NetctlInterface::connectToEssid(const QString essid, InterfaceAnswer NetctlInterface::connectToEssid(const QString essid, QMap<QString, QString> settings)
QMap<QString, QString> settings) const
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -84,7 +83,7 @@ InterfaceAnswer NetctlInterface::connectToEssid(const QString essid,
/** /**
* @fn connectToKnownEssid * @fn connectToKnownEssid
*/ */
InterfaceAnswer NetctlInterface::connectToKnownEssid(const QString essid) const InterfaceAnswer NetctlInterface::connectToKnownEssid(const QString essid)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -106,8 +105,7 @@ InterfaceAnswer NetctlInterface::connectToKnownEssid(const QString essid) const
/** /**
* @fn connectToUnknownEssid * @fn connectToUnknownEssid
*/ */
InterfaceAnswer NetctlInterface::connectToUnknownEssid(const QString essid, InterfaceAnswer NetctlInterface::connectToUnknownEssid(const QString essid, QMap<QString, QString> settings)
QMap<QString, QString> settings) const
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -123,7 +121,7 @@ InterfaceAnswer NetctlInterface::connectToUnknownEssid(const QString essid,
QStringList interfaces = netctlCommand->getWirelessInterfaceList(); QStringList interfaces = netctlCommand->getWirelessInterfaceList();
if (interfaces.isEmpty()) return InterfaceAnswer::Error; if (interfaces.isEmpty()) return InterfaceAnswer::Error;
settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'"); settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'");
settings[QString("Interface")] = interfaces.first(); settings[QString("Interface")] = interfaces[0];
settings[QString("Connection")] = QString("wireless"); settings[QString("Connection")] = QString("wireless");
settings[QString("ESSID")] = QString("'%1'").arg(essid); settings[QString("ESSID")] = QString("'%1'").arg(essid);
settings[QString("IP")] = QString("dhcp"); settings[QString("IP")] = QString("dhcp");
@ -141,8 +139,7 @@ InterfaceAnswer NetctlInterface::connectToUnknownEssid(const QString essid,
/** /**
* @fn createProfile * @fn createProfile
*/ */
InterfaceAnswer NetctlInterface::createProfile(const QString profile, InterfaceAnswer NetctlInterface::createProfile(const QString profile, const QMap<QString, QString> settings)
const QMap<QString, QString> settings) const
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -160,7 +157,7 @@ InterfaceAnswer NetctlInterface::createProfile(const QString profile,
/** /**
* @fn enableProfile * @fn enableProfile
*/ */
InterfaceAnswer NetctlInterface::enableProfile(const QString profile) const InterfaceAnswer NetctlInterface::enableProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -177,7 +174,7 @@ InterfaceAnswer NetctlInterface::enableProfile(const QString profile) const
/** /**
* @fn removeProfile * @fn removeProfile
*/ */
InterfaceAnswer NetctlInterface::removeProfile(const QString profile) const InterfaceAnswer NetctlInterface::removeProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlProfile == nullptr) { if (netctlProfile == nullptr) {
@ -192,7 +189,7 @@ InterfaceAnswer NetctlInterface::removeProfile(const QString profile) const
/** /**
* @fn restartProfile * @fn restartProfile
*/ */
InterfaceAnswer NetctlInterface::restartProfile(const QString profile) const InterfaceAnswer NetctlInterface::restartProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -209,7 +206,7 @@ InterfaceAnswer NetctlInterface::restartProfile(const QString profile) const
/** /**
* @fn startProfile * @fn startProfile
*/ */
InterfaceAnswer NetctlInterface::startProfile(const QString profile) const InterfaceAnswer NetctlInterface::startProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -230,7 +227,7 @@ InterfaceAnswer NetctlInterface::startProfile(const QString profile) const
/** /**
* @fn stopAllProfiles * @fn stopAllProfiles
*/ */
InterfaceAnswer NetctlInterface::stopAllProfiles() const InterfaceAnswer NetctlInterface::stopAllProfiles()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -245,7 +242,7 @@ InterfaceAnswer NetctlInterface::stopAllProfiles() const
/** /**
* @fn switchToProfile * @fn switchToProfile
*/ */
InterfaceAnswer NetctlInterface::switchToProfile(const QString profile) const InterfaceAnswer NetctlInterface::switchToProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -270,7 +267,7 @@ InterfaceAnswer NetctlInterface::switchToProfile(const QString profile) const
/** /**
* @fn information * @fn information
*/ */
netctlInformation NetctlInterface::information() const netctlInformation NetctlInterface::information()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -291,7 +288,7 @@ netctlInformation NetctlInterface::information() const
/** /**
* @fn profileSettings * @fn profileSettings
*/ */
QMap<QString, QString> NetctlInterface::profileSettings(const QString profile) const QMap<QString, QString> NetctlInterface::profileSettings(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlProfile == nullptr) { if (netctlProfile == nullptr) {
@ -306,7 +303,7 @@ QMap<QString, QString> NetctlInterface::profileSettings(const QString profile) c
/** /**
* @fn status * @fn status
*/ */
netctlCurrent NetctlInterface::status() const netctlCurrent NetctlInterface::status()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (netctlCommand == nullptr) { if (netctlCommand == nullptr) {
@ -321,11 +318,11 @@ netctlCurrent NetctlInterface::status() const
profiles = netctlCommand->getProfileListFromNetctlAuto(); profiles = netctlCommand->getProfileListFromNetctlAuto();
else else
profiles = netctlCommand->getProfileList(); profiles = netctlCommand->getProfileList();
foreach(netctlProfileInfo profile, profiles) { for (int i=0; i<profiles.count(); i++) {
current.profiles.append(profile.name); current.profiles.append(profiles[i].name);
if (!profile.active) continue; if (!profiles[i].active) continue;
current.current.append(profile.name); current.current.append(profiles[i].name);
current.enables.append(profile.enabled); current.enables.append(profiles[i].enabled);
} }
return current; return current;

View File

@ -33,8 +33,6 @@
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <task/taskadds.h> #include <task/taskadds.h>
#include "version.h"
/** /**
* @class NetctlProfile * @class NetctlProfile
@ -45,11 +43,17 @@
NetctlProfile::NetctlProfile(const bool debugCmd, const QMap<QString, QString> settings) NetctlProfile::NetctlProfile(const bool debugCmd, const QMap<QString, QString> settings)
: debug(debugCmd) : debug(debugCmd)
{ {
profileDirectory = new QDir(settings.value(QString("PROFILE_DIR"), QString(PROFILE_DIR))); if (settings.contains(QString("PROFILE_DIR")))
sudoCommand = settings.value(QString("SUDO_PATH"), QString(SUDO_PATH)); profileDirectory = new QDir(settings[QString("PROFILE_DIR")]);
useSuid = (settings.value(QString("FORCE_SUDO"), QString("true")) != QString("true")); else
profileDirectory = new QDir(QString(PROFILE_DIR));
if (settings.contains(QString("SUDO_PATH")))
sudoCommand = settings[QString("SUDO_PATH")];
if (settings.contains(QString("FORCE_SUDO")))
useSuid = (settings[QString("FORCE_SUDO")] != QString("true"));
if (useSuid) sudoCommand = QString(""); if (useSuid)
sudoCommand = QString("");
} }
@ -67,7 +71,7 @@ NetctlProfile::~NetctlProfile()
/** /**
* @fn copyProfile * @fn copyProfile
*/ */
bool NetctlProfile::copyProfile(const QString oldPath) const bool NetctlProfile::copyProfile(const QString oldPath)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Path" << oldPath; if (debug) qDebug() << PDEBUG << ":" << "Path" << oldPath;
@ -83,16 +87,17 @@ bool NetctlProfile::copyProfile(const QString oldPath) const
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, useSuid); TaskResult process = runTask(cmd, useSuid);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process.status(); return (process.exitCode == 0);
} }
/** /**
* @fn createProfile * @fn createProfile
*/ */
QString NetctlProfile::createProfile(const QString profile, const QMap<QString, QString> settings) const QString NetctlProfile::createProfile(const QString profile, const QMap<QString, QString> settings)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
@ -103,22 +108,22 @@ QString NetctlProfile::createProfile(const QString profile, const QMap<QString,
if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text)) if (!profileFile.open(QIODevice::WriteOnly | QIODevice::Text))
return profileTempName; return profileTempName;
QTextStream out(&profileFile); QTextStream out(&profileFile);
foreach(QString key, settings.keys()) { for (int i=0; i<settings.keys().count(); i++) {
out << key << QString("="); out << settings.keys()[i] << QString("=");
if ((key == QString("BindsToInterfaces")) || if ((settings.keys()[i] == QString("BindsToInterfaces")) ||
(key == QString("After")) || (settings.keys()[i] == QString("After")) ||
(key == QString("Address")) || (settings.keys()[i] == QString("Address")) ||
(key == QString("Routes")) || (settings.keys()[i] == QString("Routes")) ||
(key == QString("Address6")) || (settings.keys()[i] == QString("Address6")) ||
(key == QString("Routes6")) || (settings.keys()[i] == QString("Routes6")) ||
(key == QString("IPCustom")) || (settings.keys()[i] == QString("IPCustom")) ||
(key == QString("DNS")) || (settings.keys()[i] == QString("DNS")) ||
(key == QString("DNSOptions")) || (settings.keys()[i] == QString("DNSOptions")) ||
(key == QString("ScanFrequencies")) || (settings.keys()[i] == QString("ScanFrequencies")) ||
(key == QString("WPAConfigSection"))) (settings.keys()[i] == QString("WPAConfigSection")))
out << QString("(%1)").arg(settings[key]) << endl; out << QString("(%1)").arg(settings[settings.keys()[i]]) << endl;
else else
out << settings[key] << endl; out << settings[settings.keys()[i]] << endl;
} }
profileFile.close(); profileFile.close();
@ -140,9 +145,9 @@ QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
recommended.clear(); recommended.clear();
recommended.append(QString("netctlgui-helper")); recommended.append(QString("netctlgui-helper"));
recommended.append(QString("netctlgui-helper-suid")); recommended.append(QString("netctlgui-helper-suid"));
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("FORCE_SUDO")] = QString("false"); settings[QString("FORCE_SUDO")] = QString("false");
break; break;
} }
@ -167,9 +172,9 @@ QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
recommended.append("sudo"); recommended.append("sudo");
recommended.append("kdesu"); recommended.append("kdesu");
recommended.append("gksu"); recommended.append("gksu");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("SUDO_PATH")] = process.output.trimmed(); settings[QString("SUDO_PATH")] = process.output.trimmed();
break; break;
} }
@ -182,7 +187,7 @@ QMap<QString, QString> NetctlProfile::getRecommendedConfiguration()
/** /**
* @fn getSettingsFromProfile * @fn getSettingsFromProfile
*/ */
QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile) const QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
@ -197,12 +202,13 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, false); TaskResult process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
QStringList output = QString(process.output).trimmed().split(QChar('\n')); QStringList output = QString(process.output).trimmed().split(QChar('\n'));
QStringList systemVariables; QStringList systemVariables;
systemVariables.append(QString("PIPESTATUS")); systemVariables.append(QString("PIPESTATUS"));
foreach(QString str, output) for (int i=0; i<output.count(); i++)
systemVariables.append(str.split(QChar('=')).first()); systemVariables.append(output[i].split(QChar('='))[0]);
// profile variables // profile variables
QMap<QString, QString> settings; QMap<QString, QString> settings;
QString profileUrl = QString("%1/%2").arg(profileDirectory->absolutePath()).arg(QFileInfo(profile).fileName()); QString profileUrl = QString("%1/%2").arg(profileDirectory->absolutePath()).arg(QFileInfo(profile).fileName());
@ -210,19 +216,20 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
process = runTask(cmd, false); process = runTask(cmd, false);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
output = QString(process.output).trimmed().split(QChar('\n')); output = QString(process.output).trimmed().split(QChar('\n'));
// read variables // read variables
QStringList keys; QStringList keys;
foreach(QString str, output) for (int i=0; i<output.count(); i++)
if (!systemVariables.contains(str.split(QChar('=')).first())) if (!systemVariables.contains(output[i].split(QChar('='))[0]))
keys.append(str.split(QChar('=')).first()); keys.append(output[i].split(QChar('='))[0]);
foreach(QString key, keys) { for (int i=0; i<keys.count(); i++){
cmd = QString("env -i bash -c \"source '%1'; for i in ${!%2[@]}; do echo ${%2[$i]}; done\"").arg(profileUrl).arg(key); cmd = QString("env -i bash -c \"source '%1'; for i in ${!%2[@]}; do echo ${%2[$i]}; done\"").arg(profileUrl).arg(keys[i]);
process = runTask(cmd, false); process = runTask(cmd, false);
settings[key] = process.output.trimmed(); settings[keys[i]] = process.output.trimmed();
if (debug) qDebug() << PDEBUG << ":" << key << "=" << settings[key]; if (debug) qDebug() << PDEBUG << ":" << keys[i] << "=" << settings[keys[i]];
} }
return settings; return settings;
@ -232,20 +239,20 @@ QMap<QString, QString> NetctlProfile::getSettingsFromProfile(const QString profi
/** /**
* @fn getValueFromProfile * @fn getValueFromProfile
*/ */
QString NetctlProfile::getValueFromProfile(const QString profile, const QString key) const QString NetctlProfile::getValueFromProfile(const QString profile, const QString key)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
if (debug) qDebug() << PDEBUG << ":" << "Key" << key; if (debug) qDebug() << PDEBUG << ":" << "Key" << key;
return getValuesFromProfile(profile, QStringList() << key).first(); return getValuesFromProfile(profile, QStringList() << key)[0];
} }
/** /**
* @fn getValuesFromProfile * @fn getValuesFromProfile
*/ */
QStringList NetctlProfile::getValuesFromProfile(const QString profile, const QStringList keys) const QStringList NetctlProfile::getValuesFromProfile(const QString profile, const QStringList keys)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
@ -253,8 +260,8 @@ QStringList NetctlProfile::getValuesFromProfile(const QString profile, const QSt
QMap<QString, QString> settings = getSettingsFromProfile(profile); QMap<QString, QString> settings = getSettingsFromProfile(profile);
QStringList values; QStringList values;
foreach(QString key, keys) for (int i=0; i<keys.count(); i++)
values.append(settings[key]); values.append(settings[keys[i]]);
return values; return values;
} }
@ -263,7 +270,7 @@ QStringList NetctlProfile::getValuesFromProfile(const QString profile, const QSt
/** /**
* @fn removeProfile * @fn removeProfile
*/ */
bool NetctlProfile::removeProfile(const QString profile) const bool NetctlProfile::removeProfile(const QString profile)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile; if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
@ -277,7 +284,8 @@ bool NetctlProfile::removeProfile(const QString profile) const
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, useSuid); TaskResult process = runTask(cmd, useSuid);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process.status(); return (process.exitCode == 0);
} }

View File

@ -30,8 +30,6 @@
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <task/taskadds.h> #include <task/taskadds.h>
#include "version.h"
/** /**
* @class WpaSup * @class WpaSup
@ -45,16 +43,25 @@ WpaSup::WpaSup(const bool debugCmd, const QMap<QString, QString> settings)
netctlCommand = new Netctl(debug, settings); netctlCommand = new Netctl(debug, settings);
netctlProfile = new NetctlProfile(debug, settings); netctlProfile = new NetctlProfile(debug, settings);
ctrlDir = settings.value(QString("CTRL_DIR"), QString(CTRL_DIR)); if (settings.contains(QString("CTRL_DIR")))
ctrlGroup = settings.value(QString("CTRL_GROUP"), QString(CTRL_GROUP)); ctrlDir = settings[QString("CTRL_DIR")];
pidFile = settings.value(QString("PID_FILE"), QString(PID_FILE)); if (settings.contains(QString("CTRL_GROUP")))
sudoCommand = settings.value(QString("SUDO_PATH"), QString(SUDO_PATH)); ctrlGroup = settings[QString("CTRL_GROUP")];
wpaCliPath = settings.value(QString("WPACLI_PATH"), QString(WPACLI_PATH)); if (settings.contains(QString("PID_FILE")))
wpaDrivers = settings.value(QString("WPA_DRIVERS"), QString(WPA_DRIVERS)); pidFile = settings[QString("PID_FILE")];
wpaSupPath = settings.value(QString("WPASUP_PATH"), QString(WPASUP_PATH)); if (settings.contains(QString("SUDO_PATH")))
useSuid = (settings.value(QString("FORCE_SUDO"), QString("true")) != QString("true")); sudoCommand = settings[QString("SUDO_PATH")];
if (settings.contains(QString("WPACLI_PATH")))
wpaCliPath = settings[QString("WPACLI_PATH")];
if (settings.contains(QString("WPA_DRIVERS")))
wpaDrivers = settings[QString("WPA_DRIVERS")];
if (settings.contains(QString("WPASUP_PATH")))
wpaSupPath = settings[QString("WPASUP_PATH")];
if (settings.contains(QString("FORCE_SUDO")))
useSuid = (settings[QString("FORCE_SUDO")] != QString("true"));
if (useSuid) sudoCommand = QString(""); if (useSuid)
sudoCommand = QString("");
} }
@ -74,7 +81,7 @@ WpaSup::~WpaSup()
/** /**
* @fn existentProfile * @fn existentProfile
*/ */
QString WpaSup::existentProfile(const QString essid) const QString WpaSup::existentProfile(const QString essid)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid; if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
@ -87,11 +94,11 @@ QString WpaSup::existentProfile(const QString essid) const
return QString(); return QString();
} }
QString profileFile; QString profileFile = QString("");
QList<netctlProfileInfo> profileList = netctlCommand->getProfileList(); QList<netctlProfileInfo> profileList = netctlCommand->getProfileList();
foreach(netctlProfileInfo profile, profileList) { for (int i=0; i<profileList.count(); i++) {
if (essid != profile.essid) continue; if (essid != profileList[i].essid) continue;
profileFile = profile.name; profileFile = profileList[i].name;
break; break;
} }
@ -114,16 +121,16 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
// ctrl group // ctrl group
// check group list and find out 'network', 'users', 'root' // check group list and find out 'network', 'users', 'root'
settings[QString("CTRL_GROUP")] = QString(""); settings[QString("CTRL_GROUP")] = QString("");
gid_t gtpList[size]; gid_t gtpList[99];
int grpSize = getgroups(size, gtpList); int grpSize = getgroups(size, gtpList);
recommended.clear(); recommended.clear();
recommended.append("network"); recommended.append("network");
recommended.append("users"); recommended.append("users");
recommended.append("root"); recommended.append("root");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
for (int i=0; i<grpSize; i++) for (int j=0; j<grpSize; j++)
if (rec == QString(getgrgid(gtpList[i])->gr_name)) { if (recommended[i] == QString(getgrgid(gtpList[j])->gr_name)) {
settings[QString("CTRL_GROUP")] = rec; settings[QString("CTRL_GROUP")] = recommended[i];
break; break;
} }
if (!settings[QString("CTRL_GROUP")].isEmpty()) break; if (!settings[QString("CTRL_GROUP")].isEmpty()) break;
@ -134,9 +141,9 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
recommended.clear(); recommended.clear();
recommended.append(QString("netctlgui-helper")); recommended.append(QString("netctlgui-helper"));
recommended.append(QString("netctlgui-helper-suid")); recommended.append(QString("netctlgui-helper-suid"));
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("FORCE_SUDO")] = QString("false"); settings[QString("FORCE_SUDO")] = QString("false");
break; break;
} }
@ -151,9 +158,9 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
recommended.append("sudo"); recommended.append("sudo");
recommended.append("kdesu"); recommended.append("kdesu");
recommended.append("gksu"); recommended.append("gksu");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("SUDO_PATH")] = process.output.trimmed(); settings[QString("SUDO_PATH")] = process.output.trimmed();
break; break;
} }
@ -163,9 +170,9 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
settings[QString("WPACLI_PATH")] = QString("true"); settings[QString("WPACLI_PATH")] = QString("true");
recommended.clear(); recommended.clear();
recommended.append("wpa_cli"); recommended.append("wpa_cli");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("WPACLI_PATH")] = process.output.trimmed(); settings[QString("WPACLI_PATH")] = process.output.trimmed();
break; break;
} }
@ -178,9 +185,9 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
settings[QString("WPASUP_PATH")] = QString("true"); settings[QString("WPASUP_PATH")] = QString("true");
recommended.clear(); recommended.clear();
recommended.append("wpa_supplicant"); recommended.append("wpa_supplicant");
foreach(QString rec, recommended) { for (int i=0; i<recommended.count(); i++) {
process = runTask(QString("which %1").arg(rec), false); process = runTask(QString("which %1").arg(recommended[i]), false);
if (process.status()) { if (process.exitCode == 0) {
settings[QString("WPASUP_PATH")] = process.output.trimmed(); settings[QString("WPASUP_PATH")] = process.output.trimmed();
break; break;
} }
@ -193,7 +200,7 @@ QMap<QString, QString> WpaSup::getRecommendedConfiguration()
/** /**
* @fn isProfileActive * @fn isProfileActive
*/ */
bool WpaSup::isProfileActive(const QString essid) const bool WpaSup::isProfileActive(const QString essid)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid; if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
@ -206,14 +213,50 @@ bool WpaSup::isProfileActive(const QString essid) const
return false; return false;
} }
return netctlCommand->isProfileActive(existentProfile(essid)); QString profileFile;
QList<netctlProfileInfo> profileList = netctlCommand->getProfileList();
for (int i=0; i<profileList.count(); i++) {
if (essid != profileList[i].essid) continue;
profileFile = profileList[i].name;
break;
}
return netctlCommand->isProfileActive(profileFile);
}
/**
* @fn isProfileExists
*/
bool WpaSup::isProfileExists(const QString essid)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "ESSID" << essid;
if (netctlCommand == nullptr) {
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
return false;
}
if (netctlProfile == nullptr) {
if (debug) qDebug() << PDEBUG << ":" << "Could not find library";
return false;
}
bool exists = false;
QList<netctlProfileInfo> profileList = netctlCommand->getProfileList();
for (int i=0; i<profileList.count(); i++) {
if (essid != profileList[i].essid) continue;
exists = true;
break;
}
return exists;
} }
/** /**
* @fn current * @fn current
*/ */
netctlWifiInfo WpaSup::current() const netctlWifiInfo WpaSup::current()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (pidFile.isEmpty()) { if (pidFile.isEmpty()) {
@ -226,7 +269,7 @@ netctlWifiInfo WpaSup::current() const
return netctlWifiInfo(); return netctlWifiInfo();
} }
QString _pidFile = pidFile; QString _pidFile = pidFile;
_pidFile.replace(QString("$i"), interfaces.first()); _pidFile.replace(QString("$i"), interfaces[0]);
if (debug) qDebug() << PDEBUG << ":" << "PID file" << _pidFile << QFile(_pidFile).exists(); if (debug) qDebug() << PDEBUG << ":" << "PID file" << _pidFile << QFile(_pidFile).exists();
netctlWifiInfo current; netctlWifiInfo current;
@ -235,21 +278,21 @@ netctlWifiInfo WpaSup::current() const
if (!rawText.contains(QString("wpa_state=COMPLETED\n"))) return current; if (!rawText.contains(QString("wpa_state=COMPLETED\n"))) return current;
QStringList rawList = rawText.split(QChar('\n'), QString::SkipEmptyParts); QStringList rawList = rawText.split(QChar('\n'), QString::SkipEmptyParts);
foreach(QString element, rawList) { for (int i=0; i<rawList.count(); i++) {
QStringList line = element.split(QChar('=')); QStringList line = rawList[i].split(QChar('='));
if (line.count() != 2) continue; if (line.count() != 2) continue;
if (line.at(0) == QString("bssid")) if (line[0] == QString("bssid"))
current.macs.append(line.at(1)); current.macs.append(line[1]);
else if (line.at(0) == QString("freq")) { else if (line[0] == QString("freq")) {
if ((line.at(1).toInt() >= 5000) && (line.at(1).toInt() < 6000)) if ((line[1].toInt() >= 5000) && (line[1].toInt() < 6000))
current.type = PointType::FiveG; current.type = PointType::FiveG;
else if ((line.at(1).toInt() < 5000) && (line.at(1).toInt() > 2000)) else if ((line[1].toInt() < 5000) && (line[1].toInt() > 2000))
current.type = PointType::TwoG; current.type = PointType::TwoG;
current.frequencies.append(line.at(1).toInt()); current.frequencies.append(line[1].toInt());
} else if (line.at(0) == QString("ssid")) } else if (line[0] == QString("ssid"))
current.name = line.at(1); current.name = line[1];
else if (line.at(0) == QString("key_mgmt")) { else if (line[0] == QString("key_mgmt")) {
QString security = line.at(1); QString security = line[1];
if (security.contains(QString("WPA2"))) if (security.contains(QString("WPA2")))
security = QString("WPA2"); security = QString("WPA2");
else if (security.contains(QString("WPA"))) else if (security.contains(QString("WPA")))
@ -273,7 +316,7 @@ netctlWifiInfo WpaSup::current() const
/** /**
* @fn scanWifi * @fn scanWifi
*/ */
QList<netctlWifiInfo> WpaSup::scanWifi() const QList<netctlWifiInfo> WpaSup::scanWifi()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (pidFile.isEmpty()) { if (pidFile.isEmpty()) {
@ -286,7 +329,7 @@ QList<netctlWifiInfo> WpaSup::scanWifi() const
return QList<netctlWifiInfo>(); return QList<netctlWifiInfo>();
} }
QString _pidFile = pidFile; QString _pidFile = pidFile;
_pidFile.replace(QString("$i"), interfaces.first()); _pidFile.replace(QString("$i"), interfaces[0]);
if (debug) qDebug() << PDEBUG << ":" << "PID file" << _pidFile << QFile(_pidFile).exists(); if (debug) qDebug() << PDEBUG << ":" << "PID file" << _pidFile << QFile(_pidFile).exists();
bool terminateOnExit = (!QFile(_pidFile).exists()); bool terminateOnExit = (!QFile(_pidFile).exists());
@ -310,25 +353,25 @@ QList<netctlWifiInfo> WpaSup::scanWifi() const
else else
profiles = netctlCommand->getProfileList(); profiles = netctlCommand->getProfileList();
// iterate by wifi output // iterate by wifi output
foreach(QString element, rawList) { for (int i=0; i<rawList.count(); i++) {
QStringList line = element.split(QChar('\t')); QStringList line = rawList[i].split(QChar('\t'));
if (line.count() != 5) continue; if (line.count() != 5) continue;
QString name = line.at(4); QString name = line[4];
if (name.isEmpty()) name = QString("<hidden>"); if (name.isEmpty()) name = QString("<hidden>");
// append mac and frequency if exists // append mac and frequency if exists
int index = names.indexOf(name); int index = names.indexOf(name);
if ((name != QString("<hidden>")) && (index > -1)) { if ((name != QString("<hidden>")) && (index > -1)) {
scanResults[index].frequencies.append(line.at(1).toInt()); scanResults[index].frequencies.append(line[1].toInt());
scanResults[index].macs.append(line.at(0)); scanResults[index].macs.append(line[0]);
if (scanResults[index].signal < line.at(2).toInt()) if (scanResults[index].signal < line[2].toInt())
scanResults[index].signal = line.at(2).toInt(); scanResults[index].signal = line[2].toInt();
// check type // check type
if ((line.at(1).toInt() >= 5000) && (line.at(1).toInt() < 6000)) { if ((line[1].toInt() >= 5000) && (line[1].toInt() < 6000)) {
if (scanResults[index].type == PointType::None) if (scanResults[index].type == PointType::None)
scanResults[index].type = PointType::FiveG; scanResults[index].type = PointType::FiveG;
else if (scanResults[index].type == PointType::TwoG) else if (scanResults[index].type == PointType::TwoG)
scanResults[index].type = PointType::TwoAndFiveG; scanResults[index].type = PointType::TwoAndFiveG;
} else if ((line.at(1).toInt() < 5000) && (line.at(1).toInt() > 2000)) { } else if ((line[1].toInt() < 5000) && (line[1].toInt() > 2000)) {
if (scanResults[index].type == PointType::None) if (scanResults[index].type == PointType::None)
scanResults[index].type = PointType::TwoG; scanResults[index].type = PointType::TwoG;
else if (scanResults[index].type == PointType::FiveG) else if (scanResults[index].type == PointType::FiveG)
@ -345,28 +388,28 @@ QList<netctlWifiInfo> WpaSup::scanWifi() const
netctlProfileInfo profile; netctlProfileInfo profile;
profile.name = QString(""); profile.name = QString("");
profile.active = false; profile.active = false;
foreach(netctlProfileInfo pr, profiles) { for (int j=0; j<profiles.count(); j++) {
if (wifiPoint.name != pr.essid) continue; if (wifiPoint.name != profiles[j].essid) continue;
profile = pr; profile = profiles[j];
break; break;
} }
wifiPoint.active = profile.active; wifiPoint.active = profile.active;
wifiPoint.exists = (!profile.name.isEmpty()); wifiPoint.exists = (!profile.name.isEmpty());
// mac // mac
wifiPoint.macs.append(line.at(0)); wifiPoint.macs.append(line[0]);
// frequencies // frequencies
wifiPoint.frequencies.append(line.at(1).toInt()); wifiPoint.frequencies.append(line[1].toInt());
// type // type
// check type // check type
if ((line.at(1).toInt() >= 5000) && (line.at(1).toInt() < 6000)) { if ((line[1].toInt() >= 5000) && (line[1].toInt() < 6000)) {
wifiPoint.type = PointType::FiveG; wifiPoint.type = PointType::FiveG;
} else if ((line.at(1).toInt() < 5000) && (line.at(1).toInt() > 2000)) { } else if ((line[1].toInt() < 5000) && (line[1].toInt() > 2000)) {
wifiPoint.type = PointType::TwoG; wifiPoint.type = PointType::TwoG;
} }
// point signal // point signal
wifiPoint.signal = line.at(2).toInt(); wifiPoint.signal = line[2].toInt();
// point security // point security
QString security = line.at(3); QString security = line[3];
if (security.contains(QString("WPA2"))) if (security.contains(QString("WPA2")))
security = QString("WPA2"); security = QString("WPA2");
else if (security.contains(QString("WPA"))) else if (security.contains(QString("WPA")))
@ -390,7 +433,7 @@ QList<netctlWifiInfo> WpaSup::scanWifi() const
/** /**
* @fn startWpaSupplicant * @fn startWpaSupplicant
*/ */
bool WpaSup::startWpaSupplicant() const bool WpaSup::startWpaSupplicant()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ctrlDir.isEmpty()) { if (ctrlDir.isEmpty()) {
@ -423,27 +466,28 @@ bool WpaSup::startWpaSupplicant() const
return false; return false;
} }
QString _pidFile = pidFile; QString _pidFile = pidFile;
_pidFile.replace(QString("$i"), interfaces.first()); _pidFile.replace(QString("$i"), interfaces[0]);
if (debug) qDebug() << PDEBUG << ":" << "PID file" << _pidFile << QFile(_pidFile).exists(); if (debug) qDebug() << PDEBUG << ":" << "PID file" << _pidFile << QFile(_pidFile).exists();
if (QFile(_pidFile).exists()) return (QFileInfo(ctrlDir).group() == ctrlGroup); if (QFile(_pidFile).exists()) return (QFileInfo(ctrlDir).group() == ctrlGroup);
QString cmd = QString("%1 %2 -B -P \"%3\" -i %4 -D %5 -C \"DIR=%6 GROUP=%7\"") QString cmd = QString("%1 %2 -B -P \"%3\" -i %4 -D %5 -C \"DIR=%6 GROUP=%7\"")
.arg(sudoCommand).arg(wpaSupPath).arg(_pidFile).arg(interfaces.first()) .arg(sudoCommand).arg(wpaSupPath).arg(_pidFile).arg(interfaces[0])
.arg(wpaDrivers).arg(ctrlDir).arg(ctrlGroup); .arg(wpaDrivers).arg(ctrlDir).arg(ctrlGroup);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd, useSuid); TaskResult process = runTask(cmd, useSuid);
waitForProcess(1); waitForProcess(1);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process.status(); return (process.exitCode == 0);
} }
/** /**
* @fn stopWpaSupplicant * @fn stopWpaSupplicant
*/ */
bool WpaSup::stopWpaSupplicant() const bool WpaSup::stopWpaSupplicant()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -455,7 +499,7 @@ bool WpaSup::stopWpaSupplicant() const
/** /**
* @fn getWpaCliOutput * @fn getWpaCliOutput
*/ */
QString WpaSup::getWpaCliOutput(const QString commandLine) const QString WpaSup::getWpaCliOutput(const QString commandLine)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine; if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
@ -473,11 +517,12 @@ QString WpaSup::getWpaCliOutput(const QString commandLine) const
return QString(); return QString();
} }
QString cmd = QString("%1 -i %2 -p %3 %4").arg(wpaCliPath).arg(interfaces.first()).arg(ctrlDir).arg(commandLine); QString cmd = QString("%1 -i %2 -p %3 %4").arg(wpaCliPath).arg(interfaces[0]).arg(ctrlDir).arg(commandLine);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd); TaskResult process = runTask(cmd);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process.output; return process.output;
} }
@ -486,7 +531,7 @@ QString WpaSup::getWpaCliOutput(const QString commandLine) const
/** /**
* @fn waitForProcess * @fn waitForProcess
*/ */
bool WpaSup::waitForProcess(const int sec) const bool WpaSup::waitForProcess(const int sec)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Interval" << sec; if (debug) qDebug() << PDEBUG << ":" << "Interval" << sec;
@ -501,7 +546,7 @@ bool WpaSup::waitForProcess(const int sec) const
/** /**
* @fn wpaCliCall * @fn wpaCliCall
*/ */
bool WpaSup::wpaCliCall(const QString commandLine) const bool WpaSup::wpaCliCall(const QString commandLine)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine; if (debug) qDebug() << PDEBUG << ":" << "Command" << commandLine;
@ -519,12 +564,13 @@ bool WpaSup::wpaCliCall(const QString commandLine) const
return false; return false;
} }
QString cmd = QString("%1 -i %2 -p %3 %4").arg(wpaCliPath).arg(interfaces.first()).arg(ctrlDir).arg(commandLine); QString cmd = QString("%1 -i %2 -p %3 %4").arg(wpaCliPath).arg(interfaces[0]).arg(ctrlDir).arg(commandLine);
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
TaskResult process = runTask(cmd); TaskResult process = runTask(cmd);
waitForProcess(1); waitForProcess(1);
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode; if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error; if (process.exitCode != 0)
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
return process.status(); return (process.exitCode == 0);
} }

View File

@ -12,7 +12,7 @@ X-KDE-PluginInfo-Author=Evgeniy Alekseev
X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=netctl X-KDE-PluginInfo-Name=netctl
X-KDE-PluginInfo-Version=@PROJECT_VERSION@ X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Website=https://arcanis.me/projects/netctl-gui/ X-KDE-PluginInfo-Website=http://arcanis.name/projects/netctl-gui/
X-KDE-PluginInfo-Category=Network X-KDE-PluginInfo-Category=Network
X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3 X-KDE-PluginInfo-License=GPLv3

View File

@ -15,7 +15,7 @@ X-KDE-PluginInfo-Author=Evgeniy Alekseev
X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=org.kde.plasma.netctl X-KDE-PluginInfo-Name=org.kde.plasma.netctl
X-KDE-PluginInfo-Version=@PROJECT_VERSION@ X-KDE-PluginInfo-Version=@PROJECT_VERSION@
X-KDE-PluginInfo-Website=https://arcanis.me/projects/netctl-gui X-KDE-PluginInfo-Website=http://arcanis.name/projects/netctl-gui
X-KDE-PluginInfo-Category=Network X-KDE-PluginInfo-Category=Network
X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3 X-KDE-PluginInfo-License=GPLv3

View File

@ -19,21 +19,17 @@ import QtQuick 2.0
import QtQuick.Controls 1.3 as QtControls import QtQuick.Controls 1.3 as QtControls
import QtQuick.Layouts 1.0 as QtLayouts import QtQuick.Layouts 1.0 as QtLayouts
import org.kde.plasma.private.netctl 1.0 import org.kde.plasma.netctl 1.0
Item { Item {
id: aboutPage id: aboutPage
// backend
NetctlAdds {
id: netctlAdds;
}
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
implicitWidth: pageColumn.implicitWidth implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight implicitHeight: pageColumn.implicitHeight
property bool debug: netctlAdds.isDebugEnabled() property bool debug: NetctlAdds.isDebugEnabled()
Column { Column {
id: pageColumn id: pageColumn
@ -48,20 +44,20 @@ Item {
QtControls.Label { QtControls.Label {
QtLayouts.Layout.fillWidth: true QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
text: netctlAdds.getAboutText("header") text: NetctlAdds.getAboutText("header")
} }
QtControls.Label { QtControls.Label {
QtLayouts.Layout.fillWidth: true QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignJustify horizontalAlignment: Text.AlignJustify
text: netctlAdds.getAboutText("description") text: NetctlAdds.getAboutText("description")
} }
QtControls.Label { QtControls.Label {
QtLayouts.Layout.fillWidth: true QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignLeft horizontalAlignment: Text.AlignLeft
textFormat: Text.RichText textFormat: Text.RichText
text: netctlAdds.getAboutText("links") text: NetctlAdds.getAboutText("links")
onLinkActivated: Qt.openUrlExternally(link); onLinkActivated: Qt.openUrlExternally(link);
} }
@ -70,7 +66,7 @@ Item {
font.capitalization: Font.SmallCaps font.capitalization: Font.SmallCaps
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
textFormat: Text.RichText textFormat: Text.RichText
text: netctlAdds.getAboutText("copy") text: NetctlAdds.getAboutText("copy")
} }
} }
} }
@ -82,14 +78,14 @@ Item {
QtControls.Label { QtControls.Label {
QtLayouts.Layout.fillWidth: true QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignJustify horizontalAlignment: Text.AlignJustify
text: netctlAdds.getAboutText("translators") text: NetctlAdds.getAboutText("translators")
} }
QtControls.Label { QtControls.Label {
QtLayouts.Layout.fillWidth: true QtLayouts.Layout.fillWidth: true
horizontalAlignment: Text.AlignJustify horizontalAlignment: Text.AlignJustify
textFormat: Text.RichText textFormat: Text.RichText
text: netctlAdds.getAboutText("3rdparty") text: NetctlAdds.getAboutText("3rdparty")
onLinkActivated: Qt.openUrlExternally(link); onLinkActivated: Qt.openUrlExternally(link);
} }
} }

View File

@ -21,21 +21,17 @@ import QtQuick.Controls.Styles 1.3 as QtStyles
import QtQuick.Dialogs 1.1 as QtDialogs import QtQuick.Dialogs 1.1 as QtDialogs
import QtQuick.Layouts 1.0 as QtLayouts import QtQuick.Layouts 1.0 as QtLayouts
import org.kde.plasma.private.netctl 1.0 import org.kde.plasma.netctl 1.0
Item { Item {
id: appearancePage id: appearancePage
// backend
NetctlAdds {
id: netctlAdds;
}
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
implicitWidth: pageColumn.implicitWidth implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight implicitHeight: pageColumn.implicitHeight
property bool debug: netctlAdds.isDebugEnabled() property bool debug: NetctlAdds.isDebugEnabled()
property variant weight: { property variant weight: {
25: 0, 25: 0,
50: 1, 50: 1,
@ -114,10 +110,7 @@ Item {
id: selectFont id: selectFont
width: parent.width * 2 / 3 width: parent.width * 2 / 3
text: plasmoid.configuration.fontFamily text: plasmoid.configuration.fontFamily
onClicked: { onClicked: fontDialog.visible = true
fontDialog.setFont()
fontDialog.visible = true
}
} }
} }
@ -315,28 +308,21 @@ Item {
id: colorDialog id: colorDialog
title: i18n("Select a color") title: i18n("Select a color")
color: selectColor.text color: selectColor.text
onAccepted: selectColor.text = colorDialog.color onAccepted: {
selectColor.text = colorDialog.color
}
} }
QtDialogs.FontDialog { QtDialogs.FontDialog {
id: fontDialog id: fontDialog
title: i18n("Select a font") title: i18n("Select a font")
signal setFont font: Qt.font({ family: selectFont.text, pointSize: fontSize.value, weight: Font.Normal })
onAccepted: { onAccepted: {
selectFont.text = fontDialog.font.family selectFont.text = fontDialog.font.family
fontSize.value = fontDialog.font.pointSize fontSize.value = fontDialog.font.pointSize
fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0 fontStyle.currentIndex = fontDialog.font.italic ? 1 : 0
fontWeight.currentIndex = weight[fontDialog.font.weight] fontWeight.currentIndex = weight[fontDialog.font.weight]
} }
onSetFont: {
fontDialog.font = Qt.font({
family: selectFont.text,
pointSize: fontSize.value > 0 ? fontSize.value : 12,
italic: fontStyle.currentIndex == 1,
weight: Font.Normal,
})
}
} }
Component.onCompleted: { Component.onCompleted: {

View File

@ -21,23 +21,19 @@ import QtQuick.Dialogs 1.1 as QtDialogs
import QtQuick.Layouts 1.0 as QtLayouts import QtQuick.Layouts 1.0 as QtLayouts
import QtQuick.Controls.Styles 1.3 as QtStyles import QtQuick.Controls.Styles 1.3 as QtStyles
import org.kde.plasma.private.netctl 1.0 import org.kde.plasma.netctl 1.0
Item { Item {
id: dataenginePage id: dataenginePage
// backend
NetctlAdds {
id: netctlAdds;
}
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
implicitWidth: pageColumn.implicitWidth implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight implicitHeight: pageColumn.implicitHeight
property bool debug: netctlAdds.isDebugEnabled() property bool debug: NetctlAdds.isDebugEnabled()
property variant cfg_dataengine: netctlAdds.readDataEngineConfiguration() property variant cfg_dataengine: NetctlAdds.readDataEngineConfiguration()
Column { Column {
id: pageColumn id: pageColumn
@ -232,6 +228,6 @@ Item {
Component.onDestruction: { Component.onDestruction: {
cfg_dataengine["EXTIP4"] = extIp4.checked ? "true" : "false" cfg_dataengine["EXTIP4"] = extIp4.checked ? "true" : "false"
cfg_dataengine["EXTIP6"] = extIp6.checked ? "true" : "false" cfg_dataengine["EXTIP6"] = extIp6.checked ? "true" : "false"
netctlAdds.writeDataEngineConfiguration(cfg_dataengine) NetctlAdds.writeDataEngineConfiguration(cfg_dataengine)
} }
} }

View File

@ -22,19 +22,15 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.private.netctl 1.0 import org.kde.plasma.netctl 1.0
Item { Item {
id: main id: main
// backend
NetctlAdds {
id: netctlAdds;
}
// variables // variables
// internal // internal
property bool debug: netctlAdds.isDebugEnabled() property bool debug: NetctlAdds.isDebugEnabled()
property variant fontWeight: { property variant fontWeight: {
"light": Font.Light, "light": Font.Light,
"normal": Font.Normal, "normal": Font.Normal,
@ -56,9 +52,8 @@ Item {
} }
property string sudoPath: plasmoid.configuration.useSudo ? plasmoid.configuration.sudoPath : "" property string sudoPath: plasmoid.configuration.useSudo ? plasmoid.configuration.sudoPath : ""
// signals // signals
signal needIconUpdate(string newIcon) signal needUpdate
signal needTextUpdate(string newText, string newToolTip) signal needMenuUpdate
signal needMenuUpdate(string current, string stringStatus, bool status)
// init // init
Plasmoid.icon: iconPath["false"] Plasmoid.icon: iconPath["false"]
@ -76,7 +71,7 @@ Item {
onNewData: { onNewData: {
if (debug) console.log("[main::onNewData] : Update source " + sourceName) if (debug) console.log("[main::onNewData] : Update source " + sourceName)
netctlAdds.setDataBySource(sourceName, data) NetctlAdds.setDataBySource(sourceName, data)
} }
} }
@ -97,7 +92,6 @@ Item {
font.pointSize: plasmoid.configuration.fontSize font.pointSize: plasmoid.configuration.fontSize
font.weight: fontWeight[plasmoid.configuration.fontWeight] font.weight: fontWeight[plasmoid.configuration.fontWeight]
horizontalAlignment: align[plasmoid.configuration.textAlign] horizontalAlignment: align[plasmoid.configuration.textAlign]
renderType: Text.NativeRendering
textFormat: Text.RichText textFormat: Text.RichText
text: "N\\A" text: "N\\A"
} }
@ -115,30 +109,28 @@ Item {
plasmoid.setAction("restartProfile", i18n("Restart profile"), "view-refresh") plasmoid.setAction("restartProfile", i18n("Restart profile"), "view-refresh")
plasmoid.setAction("enableProfile", i18n("Enable profile")) plasmoid.setAction("enableProfile", i18n("Enable profile"))
plasmoid.setAction("startWifi", i18n("Show WiFi menu"), "netctl-gui-wifi") plasmoid.setAction("startWifi", i18n("Show WiFi menu"), "netctl-gui-wifi")
// init submodule // helper
Plasmoid.userConfiguringChanged(false) if (plasmoid.configuration.useHelper) {
NetctlAdds.runCmd(plasmoid.configuration.helperPath)
plasmoid.configuration.useHelper = NetctlAdds.checkHelperStatus()
}
netctlAdds.needIconToBeUpdated.connect(needIconUpdate) NetctlAdds.needToBeUpdated.connect(needUpdate)
netctlAdds.needMenuUpdate.connect(needMenuUpdate)
netctlAdds.needTextToBeUpdated.connect(needTextUpdate)
} }
onNeedIconUpdate: { onNeedUpdate: {
if (debug) console.log("[main::onNeedIconUpdate]") if (debug) console.log("[main::onNeedUpdate]")
icon.source = iconPath[newIcon] var iconStatus = NetctlAdds.valueByKey("active")
Plasmoid.icon = iconPath[newIcon] icon.source = iconPath[iconStatus]
} Plasmoid.icon = iconPath[iconStatus]
text.text = NetctlAdds.parsePattern(plasmoid.configuration.textPattern)
onNeedTextUpdate: { Plasmoid.toolTipSubText = NetctlAdds.valueByKey("info")
if (debug) console.log("[main::onNeedTextUpdate]") needMenuUpdate()
text.text = newText
Plasmoid.toolTipSubText = newToolTip
} }
onNeedMenuUpdate: { onNeedMenuUpdate: {
if (debug) console.log("[main::onNeedMenuUpdate]") if (debug) console.log("[main::onNetctlStateChanged]")
var titleAction = plasmoid.action("titleAction") var titleAction = plasmoid.action("titleAction")
var startAction = plasmoid.action("startProfile") var startAction = plasmoid.action("startProfile")
@ -149,6 +141,10 @@ Item {
var enableAction = plasmoid.action("enableProfile") var enableAction = plasmoid.action("enableProfile")
var wifiAction = plasmoid.action("startWifi") var wifiAction = plasmoid.action("startWifi")
var current = NetctlAdds.valueByKey("current")
var status = NetctlAdds.valueByKey("active") == "true"
var stringStatus = NetctlAdds.valueByKey("status")
titleAction.iconSource = plasmoid.icon titleAction.iconSource = plasmoid.icon
titleAction.text = current + " " + stringStatus titleAction.text = current + " " + stringStatus
@ -190,29 +186,16 @@ Item {
wifiAction.visible = plasmoid.configuration.useWifi wifiAction.visible = plasmoid.configuration.useWifi
} }
Plasmoid.onUserConfiguringChanged: {
if (plasmoid.userConfiguring) return
if (debug) console.log("[main::onUserConfiguringChanged]")
// helper
if (plasmoid.configuration.useHelper) {
netctlAdds.runCmd(plasmoid.configuration.helperPath)
plasmoid.configuration.useHelper = netctlAdds.checkHelperStatus()
}
// init submodule
netctlAdds.setPattern(plasmoid.configuration.textPattern)
}
function action_titleAction() { function action_titleAction() {
if (debug) console.log("[main::action_titleAction]") if (debug) console.log("[main::action_titleAction]")
netctlAdds.runCmd(plasmoid.configuration.guiPath) NetctlAdds.runCmd(plasmoid.configuration.guiPath)
} }
function action_startProfile() { function action_startProfile() {
if (debug) console.log("[main::action_startProfile]") if (debug) console.log("[main::action_startProfile]")
netctlAdds.startProfileSlot(plasmoid.configuration.useHelper, NetctlAdds.startProfileSlot(plasmoid.configuration.useHelper,
plasmoid.configuration.netctlPath, plasmoid.configuration.netctlPath,
sudoPath) sudoPath)
} }
@ -220,7 +203,7 @@ Item {
function action_stopProfile() { function action_stopProfile() {
if (debug) console.log("[main::action_stopProfile]") if (debug) console.log("[main::action_stopProfile]")
netctlAdds.stopProfileSlot(plasmoid.configuration.useHelper, NetctlAdds.stopProfileSlot(plasmoid.configuration.useHelper,
plasmoid.configuration.netctlPath, plasmoid.configuration.netctlPath,
sudoPath) sudoPath)
} }
@ -228,7 +211,7 @@ Item {
function action_stopAllProfiles() { function action_stopAllProfiles() {
if (debug) console.log("[main::action_stopAllProfiles]") if (debug) console.log("[main::action_stopAllProfiles]")
netctlAdds.stopAllProfilesSlot(plasmoid.configuration.useHelper, NetctlAdds.stopAllProfilesSlot(plasmoid.configuration.useHelper,
plasmoid.configuration.netctlPath, plasmoid.configuration.netctlPath,
sudoPath) sudoPath)
} }
@ -236,14 +219,14 @@ Item {
function action_switchToProfile() { function action_switchToProfile() {
if (debug) console.log("[main::action_switchToProfile]") if (debug) console.log("[main::action_switchToProfile]")
netctlAdds.switchToProfileSlot(plasmoid.configuration.useHelper, NetctlAdds.switchToProfileSlot(plasmoid.configuration.useHelper,
plasmoid.configuration.netctlAutoPath) plasmoid.configuration.netctlAutoPath)
} }
function action_restartProfile() { function action_restartProfile() {
if (debug) console.log("[main::action_restartProfile]") if (debug) console.log("[main::action_restartProfile]")
netctlAdds.restartProfileSlot(plasmoid.configuration.useHelper, NetctlAdds.restartProfileSlot(plasmoid.configuration.useHelper,
plasmoid.configuration.netctlPath, plasmoid.configuration.netctlPath,
sudoPath) sudoPath)
} }
@ -251,7 +234,7 @@ Item {
function action_enableProfile() { function action_enableProfile() {
if (debug) console.log("[main::action_enableProfile]") if (debug) console.log("[main::action_enableProfile]")
netctlAdds.enableProfileSlot(plasmoid.configuration.useHelper, NetctlAdds.enableProfileSlot(plasmoid.configuration.useHelper,
plasmoid.configuration.netctlPath, plasmoid.configuration.netctlPath,
sudoPath) sudoPath)
} }
@ -259,6 +242,6 @@ Item {
function action_startWifi() { function action_startWifi() {
if (debug) console.log("[main::action_startWifi]") if (debug) console.log("[main::action_startWifi]")
netctlAdds.runCmd(plasmoid.configuration.wifiPath) NetctlAdds.runCmd(plasmoid.configuration.wifiPath)
} }
} }

View File

@ -21,20 +21,17 @@ import QtQuick.Dialogs 1.1 as QtDialogs
import QtQuick.Layouts 1.0 as QtLayouts import QtQuick.Layouts 1.0 as QtLayouts
import QtQuick.Controls.Styles 1.3 as QtStyles import QtQuick.Controls.Styles 1.3 as QtStyles
import org.kde.plasma.private.netctl 1.0 import org.kde.plasma.netctl 1.0
Item { Item {
id: widgetPage id: widgetPage
NetctlAdds {
id: netctlAdds;
}
width: childrenRect.width width: childrenRect.width
height: childrenRect.height height: childrenRect.height
implicitWidth: pageColumn.implicitWidth implicitWidth: pageColumn.implicitWidth
implicitHeight: pageColumn.implicitHeight implicitHeight: pageColumn.implicitHeight
property bool debug: netctlAdds.isDebugEnabled() property bool debug: NetctlAdds.isDebugEnabled()
property alias cfg_autoUpdateInterval: autoUpdate.value property alias cfg_autoUpdateInterval: autoUpdate.value
property alias cfg_guiPath: guiPath.text property alias cfg_guiPath: guiPath.text

View File

@ -14,8 +14,8 @@ X-Plasma-RemoteLocation=
X-KDE-PluginInfo-Author=Evgeniy Alekseev X-KDE-PluginInfo-Author=Evgeniy Alekseev
X-KDE-PluginInfo-Email=esalexeev@gmail.com X-KDE-PluginInfo-Email=esalexeev@gmail.com
X-KDE-PluginInfo-Name=org.kde.plasma.netctl X-KDE-PluginInfo-Name=org.kde.plasma.netctl
X-KDE-PluginInfo-Version=1.4.9 X-KDE-PluginInfo-Version=1.4.8
X-KDE-PluginInfo-Website=https://arcanis.me/projects/netctl-gui X-KDE-PluginInfo-Website=http://arcanis.name/projects/netctl-gui
X-KDE-PluginInfo-Category=Network X-KDE-PluginInfo-Category=Network
X-KDE-PluginInfo-Depends= X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPLv3 X-KDE-PluginInfo-License=GPLv3

View File

@ -21,12 +21,13 @@ include_directories (${CMAKE_SOURCE_DIR}
${Qt_INCLUDE} ${Qt_INCLUDE}
${Kf5_INCLUDE}) ${Kf5_INCLUDE})
file (GLOB_RECURSE SUBPROJECT_SOURCE *.cpp) file (GLOB_RECURSE SUBPROJECT_SOURCE ${PROJECT_TRDPARTY_DIR}/pdebug/*.cpp
*.cpp)
file (GLOB SUBPROJECT_NOTIFY *.notifyrc) file (GLOB SUBPROJECT_NOTIFY *.notifyrc)
add_library (${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE}) add_library (${PLUGIN_NAME} SHARED ${SUBPROJECT_SOURCE})
target_link_libraries (${PLUGIN_NAME} ${Qt_LIBRARIES} ${Kf5_LIBRARIES}) target_link_libraries (${PLUGIN_NAME} ${Qt_LIBRARIES} ${Kf5_LIBRARIES})
install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/netctl) install (TARGETS ${PLUGIN_NAME} DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/netctl)
install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/private/netctl) install (FILES qmldir DESTINATION ${QML_INSTALL_DIR}/org/kde/plasma/netctl)
install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR}) install (FILES ${SUBPROJECT_NOTIFY} DESTINATION ${KNOTIFYRC_INSTALL_DIR})

View File

@ -21,9 +21,18 @@
#include "netctladds.h" #include "netctladds.h"
static QObject *netctl_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
{
Q_UNUSED(engine);
Q_UNUSED(scriptEngine);
return new NetctlAdds();
}
void NetctlPlugin::registerTypes(const char *uri) void NetctlPlugin::registerTypes(const char *uri)
{ {
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.netctl")); Q_ASSERT(uri == QLatin1String("org.kde.plasma.netctl"));
qmlRegisterType<NetctlAdds>(uri, 1, 0, "NetctlAdds"); qmlRegisterSingletonType<NetctlAdds>(uri, 1, 0, "NetctlAdds", netctl_singletontype_provider);
} }

View File

@ -27,6 +27,7 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <pdebug/pdebug.h> #include <pdebug/pdebug.h>
#include <pdebug/pdebug-time.h>
#include "netctladds.h" #include "netctladds.h"
#include "version.h" #include "version.h"
@ -35,13 +36,13 @@
NetctlAdds::NetctlAdds(QObject *parent) NetctlAdds::NetctlAdds(QObject *parent)
: QObject(parent) : QObject(parent)
{ {
qInstallMessageHandler(debugString);
// debug // debug
QProcessEnvironment environment = QProcessEnvironment::systemEnvironment(); QProcessEnvironment environment = QProcessEnvironment::systemEnvironment();
QString debugEnv = environment.value(QString("DEBUG"), QString("no")); QString debugEnv = environment.value(QString("DEBUG"), QString("no"));
debug = (debugEnv == QString("yes")); debug = (debugEnv == QString("yes"));
connect(this, SIGNAL(needToNotify(bool)), this, SLOT(notifyAboutStatusChanging(bool))); connect(this, SIGNAL(needToNotify(bool)), this, SLOT(notifyAboutStatusChanging(bool)));
connect(this, SIGNAL(needToBeUpdated()), this, SLOT(parsePattern()));
} }
@ -51,7 +52,7 @@ NetctlAdds::~NetctlAdds()
} }
void NetctlAdds::notifyAboutStatusChanging(const bool currentStatus) const void NetctlAdds::notifyAboutStatusChanging(const bool currentStatus)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Status" << currentStatus; if (debug) qDebug() << PDEBUG << ":" << "Status" << currentStatus;
@ -63,21 +64,7 @@ void NetctlAdds::notifyAboutStatusChanging(const bool currentStatus) const
} }
void NetctlAdds::parsePattern() const QList<QVariant> NetctlAdds::sendDBusRequest(const QString cmd, const QList<QVariant> args)
{
if (debug) qDebug() << PDEBUG;
QString parsed = pattern;
foreach(QString value, values.keys())
parsed.replace(QString("$%1").arg(value), values[value]);
// fix newline
parsed.replace(QString("\n"), QString("<br>"));
return emit(needTextToBeUpdated(parsed, values[QString("info")]));
}
QVariantList NetctlAdds::sendDBusRequest(const QString cmd, const QVariantList args) const
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "cmd" << cmd;
@ -86,24 +73,26 @@ QVariantList NetctlAdds::sendDBusRequest(const QString cmd, const QVariantList a
QDBusConnection bus = QDBusConnection::systemBus(); QDBusConnection bus = QDBusConnection::systemBus();
QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, QDBusMessage request = QDBusMessage::createMethodCall(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, cmd); DBUS_HELPER_INTERFACE, cmd);
if (!args.isEmpty()) request.setArguments(args); if (!args.isEmpty())
request.setArguments(args);
QDBusMessage response = bus.call(request, QDBus::BlockWithGui); QDBusMessage response = bus.call(request, QDBus::BlockWithGui);
QVariantList arguments = response.arguments(); QList<QVariant> arguments = response.arguments();
if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage(); if (arguments.size() == 0)
if (debug) qDebug() << PDEBUG << ":" << "Error message" << response.errorMessage();
return arguments; return arguments;
} }
bool NetctlAdds::checkHelperStatus() const bool NetctlAdds::checkHelperStatus()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
return !sendDBusRequest(QString("Active")).isEmpty(); return sendDBusRequest(QString("Active"), QList<QVariant>()).isEmpty();
} }
QString NetctlAdds::getAboutText(const QString type) const QString NetctlAdds::getAboutText(const QString type)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Type" << type; if (debug) qDebug() << PDEBUG << ":" << "Type" << type;
@ -131,9 +120,9 @@ QString NetctlAdds::getAboutText(const QString type) const
QStringList trdPartyList = QString(TRDPARTY_LICENSE).split(QChar(';'), QString::SkipEmptyParts); QStringList trdPartyList = QString(TRDPARTY_LICENSE).split(QChar(';'), QString::SkipEmptyParts);
for (int i=0; i<trdPartyList.count(); i++) for (int i=0; i<trdPartyList.count(); i++)
trdPartyList[i] = QString("<a href=\"%3\">%1</a> (%2 license)") trdPartyList[i] = QString("<a href=\"%3\">%1</a> (%2 license)")
.arg(trdPartyList.at(i).split(QChar(',')).at(0)) .arg(trdPartyList[i].split(QChar(','))[0])
.arg(trdPartyList.at(i).split(QChar(',')).at(1)) .arg(trdPartyList[i].split(QChar(','))[1])
.arg(trdPartyList.at(i).split(QChar(',')).at(2)); .arg(trdPartyList[i].split(QChar(','))[2]);
text = i18n("This software uses: %1", trdPartyList.join(QString(", "))); text = i18n("This software uses: %1", trdPartyList.join(QString(", ")));
} }
@ -141,7 +130,7 @@ QString NetctlAdds::getAboutText(const QString type) const
} }
bool NetctlAdds::isDebugEnabled() const bool NetctlAdds::isDebugEnabled()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -149,7 +138,21 @@ bool NetctlAdds::isDebugEnabled() const
} }
void NetctlAdds::runCmd(const QString cmd) const QString NetctlAdds::parsePattern(const QString pattern)
{
if (debug) qDebug() << PDEBUG;
QString parsed = pattern;
for (int i=0; i<values.keys().count(); i++)
parsed.replace(QString("$%1").arg(values.keys()[i]), valueByKey(values.keys()[i]));
// fix newline
parsed.replace(QString("\n"), QString("<br>"));
return parsed;
}
void NetctlAdds::runCmd(const QString cmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd; if (debug) qDebug() << PDEBUG << ":" << "Cmd" << cmd;
@ -171,26 +174,13 @@ void NetctlAdds::setDataBySource(const QString sourceName, const QVariantMap dat
values[sourceName] = data[QString("value")].toString(); values[sourceName] = data[QString("value")].toString();
if (needUpdate) { if (needUpdate) {
if (sourceName == QString("active")) {
emit(needToNotify(values[QString("active")] == QString("true")));
emit(needIconToBeUpdated(values[QString("active")]));
}
emit(needToBeUpdated()); emit(needToBeUpdated());
emit(needMenuUpdate(values[QString("current")], values[QString("status")], if (sourceName == QString("active"))
values[QString("active")] == QString("true"))); emit(needToNotify(values[QString("active")] == QString("true")));
} }
} }
void NetctlAdds::setPattern(const QString _pattern)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Pattern" << _pattern;
pattern = _pattern;
}
void NetctlAdds::sendNotification(const QString eventId, const QString message) void NetctlAdds::sendNotification(const QString eventId, const QString message)
{ {
// since it is a static method we need to identify is debug enabled again // since it is a static method we need to identify is debug enabled again
@ -207,8 +197,17 @@ void NetctlAdds::sendNotification(const QString eventId, const QString message)
} }
QString NetctlAdds::valueByKey(const QString key)
{
if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Key" << key;
return values[key];
}
// context menu // context menu
void NetctlAdds::enableProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const void NetctlAdds::enableProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -221,75 +220,82 @@ void NetctlAdds::enableProfileSlot(const bool useHelper, const QString cmd, cons
sendNotification(QString("Info"), i18n("Set profile %1 enabled", values[QString("current")])); sendNotification(QString("Info"), i18n("Set profile %1 enabled", values[QString("current")]));
} }
if (useHelper) { if (useHelper) {
QVariantList args; QList<QVariant> args;
args.append(values[QString("current")]); args.append(values[QString("current")]);
sendDBusRequest(QString("Enable"), args); sendDBusRequest(QString("Enable"), args);
} else { } else {
runCmd(QString("%1 %2%3%4").arg(sudoCmd).arg(cmd).arg(enableStatus).arg(values[QString("current")])); QProcess command;
QString commandLine = QString("%1 %2%3%4").arg(sudoCmd).arg(cmd).arg(enableStatus).arg(values[QString("current")]);
command.startDetached(commandLine);
} }
} }
void NetctlAdds::restartProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const void NetctlAdds::restartProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
sendNotification(QString("Info"), i18n("Restart profile %1", values[QString("current")])); sendNotification(QString("Info"), i18n("Restart profile %1", values[QString("current")]));
if (useHelper) { if (useHelper) {
QVariantList args; QList<QVariant> args;
args.append(values[QString("current")]); args.append(values[QString("current")]);
sendDBusRequest(QString("Restart"), args); sendDBusRequest(QString("Restart"), args);
} else { } else {
runCmd(QString("%1 %2 restart %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")])); QProcess command;
QString commandLine = QString("%1 %2 restart %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")]);
command.startDetached(commandLine);
} }
} }
void NetctlAdds::startProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const void NetctlAdds::startProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList profiles = values[QString("profiles")].split(QChar(',')); QStringList profiles = values[QString("profiles")].split(QChar(','));
bool ok; bool ok;
QString profile = QInputDialog::getItem(nullptr, i18n("Select profile"), i18n("Profile:"), QString profile = QInputDialog::getItem(0, i18n("Select profile"), i18n("Profile:"),
profiles, 0, false, &ok); profiles, 0, false, &ok);
if (!ok || profile.isEmpty()) return; if (!ok || profile.isEmpty()) return;
sendNotification(QString("Info"), i18n("Start profile %1", profile)); sendNotification(QString("Info"), i18n("Start profile %1", profile));
if (useHelper) { if (useHelper) {
QVariantList args; QList<QVariant> args;
args.append(profile); args.append(profile);
if (values[QString("active")] == QString("true")) if (values[QString("active")] == QString("true"))
sendDBusRequest(QString("SwitchTo"), args); sendDBusRequest(QString("SwitchTo"), args);
else else
sendDBusRequest(QString("Start"), args); sendDBusRequest(QString("Start"), args);
} else { } else {
QProcess command;
QString commandLine = QString("%1 %2").arg(sudoCmd).arg(cmd); QString commandLine = QString("%1 %2").arg(sudoCmd).arg(cmd);
if (values[QString("active")] == QString("true")) if (values[QString("active")] == QString("true"))
commandLine += QString(" switch-to %1").arg(profile); commandLine += QString(" switch-to %1").arg(profile);
else else
commandLine += QString(" start %1").arg(profile); commandLine += QString(" start %1").arg(profile);
runCmd(commandLine); command.startDetached(commandLine);
} }
} }
void NetctlAdds::stopProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const void NetctlAdds::stopProfileSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
sendNotification(QString("Info"), i18n("Stop profile %1", values[QString("current")])); sendNotification(QString("Info"), i18n("Stop profile %1", values[QString("current")]));
if (useHelper) { if (useHelper) {
QVariantList args; QList<QVariant> args;
args.append(values[QString("current")]); args.append(values[QString("current")]);
sendDBusRequest(QString("Start"), args); sendDBusRequest(QString("Start"), args);
} else { } else {
runCmd(QString("%1 %2 stop %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")])); QProcess command;
QString commandLine = QString("%1 %2 stop %3").arg(sudoCmd).arg(cmd).arg(values[QString("current")]);
command.startDetached(commandLine);
} }
} }
void NetctlAdds::stopAllProfilesSlot(const bool useHelper, const QString cmd, const QString sudoCmd) const void NetctlAdds::stopAllProfilesSlot(const bool useHelper, const QString cmd, const QString sudoCmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -297,33 +303,37 @@ void NetctlAdds::stopAllProfilesSlot(const bool useHelper, const QString cmd, co
if (useHelper) if (useHelper)
sendDBusRequest(QString("StopAll"), QList<QVariant>()); sendDBusRequest(QString("StopAll"), QList<QVariant>());
else { else {
runCmd(QString("%1 %2 stop-all").arg(sudoCmd).arg(cmd)); QProcess command;
QString commandLine = QString("%1 %2 stop-all").arg(sudoCmd).arg(cmd);
command.startDetached(commandLine);
} }
} }
void NetctlAdds::switchToProfileSlot(const bool useHelper, const QString cmd) const void NetctlAdds::switchToProfileSlot(const bool useHelper, const QString cmd)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList profiles = values[QString("profiles")].split(QChar(',')); QStringList profiles = values[QString("profiles")].split(QChar(','));
bool ok; bool ok;
QString profile = QInputDialog::getItem(nullptr, i18n("Select profile"), i18n("Profile:"), QString profile = QInputDialog::getItem(0, i18n("Select profile"), i18n("Profile:"),
profiles, 0, false, &ok); profiles, 0, false, &ok);
if (!ok || profile.isEmpty()) return; if (!ok || profile.isEmpty()) return;
sendNotification(QString("Info"), i18n("Switch to profile %1", profile)); sendNotification(QString("Info"), i18n("Switch to profile %1", profile));
if (useHelper) { if (useHelper) {
QVariantList args; QList<QVariant> args;
args.append(profile); args.append(profile);
sendDBusRequest(QString("autoStart"), args); sendDBusRequest(QString("autoStart"), args);
} else { } else {
runCmd(QString("%1 switch-to %2").arg(cmd).arg(profile)); QProcess command;
QString commandLine = QString("%1 switch-to %2").arg(cmd).arg(profile);
command.startDetached(commandLine);
} }
} }
QVariantMap NetctlAdds::readDataEngineConfiguration() const QVariantMap NetctlAdds::readDataEngineConfiguration()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
@ -349,7 +359,7 @@ QVariantMap NetctlAdds::readDataEngineConfiguration() const
} }
void NetctlAdds::writeDataEngineConfiguration(const QVariantMap configuration) const void NetctlAdds::writeDataEngineConfiguration(const QVariantMap configuration)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;

View File

@ -32,52 +32,47 @@ public:
NetctlAdds(QObject *parent = 0); NetctlAdds(QObject *parent = 0);
~NetctlAdds(); ~NetctlAdds();
Q_INVOKABLE bool checkHelperStatus() const; Q_INVOKABLE bool checkHelperStatus();
Q_INVOKABLE QString getAboutText(const QString type = QString("header")) const; Q_INVOKABLE QString getAboutText(const QString type = "header");
Q_INVOKABLE bool isDebugEnabled() const; Q_INVOKABLE bool isDebugEnabled();
Q_INVOKABLE void runCmd(const QString cmd) const; Q_INVOKABLE QString parsePattern(const QString pattern);
Q_INVOKABLE void runCmd(const QString cmd);
Q_INVOKABLE void setDataBySource(const QString sourceName, const QVariantMap data); Q_INVOKABLE void setDataBySource(const QString sourceName, const QVariantMap data);
Q_INVOKABLE void setPattern(const QString _pattern);
Q_INVOKABLE static void sendNotification(const QString eventId, const QString message); Q_INVOKABLE static void sendNotification(const QString eventId, const QString message);
Q_INVOKABLE QString valueByKey(const QString key);
// context menu // context menu
Q_INVOKABLE void enableProfileSlot(const bool useHelper = true, Q_INVOKABLE void enableProfileSlot(const bool useHelper = true,
const QString cmd = QString("netctl"), const QString cmd = QString("netctl"),
const QString sudoCmd = QString("")) const; const QString sudoCmd = QString(""));
Q_INVOKABLE void restartProfileSlot(const bool useHelper = true, Q_INVOKABLE void restartProfileSlot(const bool useHelper = true,
const QString cmd = QString("netctl"), const QString cmd = QString("netctl"),
const QString sudoCmd = QString("")) const; const QString sudoCmd = QString(""));
Q_INVOKABLE void startProfileSlot(const bool useHelper = true, Q_INVOKABLE void startProfileSlot(const bool useHelper = true,
const QString cmd = QString("netctl"), const QString cmd = QString("netctl"),
const QString sudoCmd = QString("")) const; const QString sudoCmd = QString(""));
Q_INVOKABLE void stopProfileSlot(const bool useHelper = true, Q_INVOKABLE void stopProfileSlot(const bool useHelper = true,
const QString cmd = QString("netctl"), const QString cmd = QString("netctl"),
const QString sudoCmd = QString("")) const; const QString sudoCmd = QString(""));
Q_INVOKABLE void stopAllProfilesSlot(const bool useHelper = true, Q_INVOKABLE void stopAllProfilesSlot(const bool useHelper = true,
const QString cmd = QString("netctl"), const QString cmd = QString("netctl"),
const QString sudoCmd = QString("")) const; const QString sudoCmd = QString(""));
Q_INVOKABLE void switchToProfileSlot(const bool useHelper = true, Q_INVOKABLE void switchToProfileSlot(const bool useHelper = true,
const QString cmd = QString("netctl-auto")) const; const QString cmd = QString("netctl-auto"));
// dataengine // dataengine
Q_INVOKABLE QVariantMap readDataEngineConfiguration() const; Q_INVOKABLE QVariantMap readDataEngineConfiguration();
Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration) const; Q_INVOKABLE void writeDataEngineConfiguration(const QVariantMap configuration);
signals: signals:
void needIconToBeUpdated(const QString newIcon) const; void needToBeUpdated();
void needMenuUpdate(const QString current, const QString status, const bool isActive) const; void needToNotify(const bool currentStatus);
void needTextToBeUpdated(const QString newText, const QString newToolTip) const;
void needToBeUpdated() const;
void needToNotify(const bool currentStatus) const;
private slots: private slots:
void notifyAboutStatusChanging(const bool currentStatus) const; void notifyAboutStatusChanging(const bool currentStatus);
void parsePattern() const;
private: private:
bool debug = false; bool debug = false;
QVariantList sendDBusRequest(const QString cmd, QList<QVariant> sendDBusRequest(const QString cmd, const QList<QVariant> args = QList<QVariant>());
const QVariantList args = QVariantList()) const; QMap<QString, QString> values;
QString pattern;
QHash<QString, QString> values;
}; };

View File

@ -1,3 +1,3 @@
module org.kde.plasma.private.netctl module org.kde.plasma.netctl
plugin netctlplugin plugin netctlplugin

View File

@ -133,7 +133,7 @@ void TestNetctl::test_getActiveProfile()
QStringList result = netctl->getActiveProfile(); QStringList result = netctl->getActiveProfile();
QStringList dbus; QStringList dbus;
if (helper) if (helper)
dbus = sendDBusRequest(QString("/netctl"), QString("netctlActiveProfile"))[0].toStringList(); dbus = sendDBusRequest(QString("/netctl"), QString("netctlActiveProfile"))[0].toString().split(QChar('|'));
netctl->startProfile(QString("netctlgui-test-dummy")); netctl->startProfile(QString("netctlgui-test-dummy"));
delete netctl; delete netctl;

View File

@ -12,7 +12,7 @@
#define DOCS_PATH "@CMAKE_INSTALL_PREFIX@/share/doc/netctl-gui/" #define DOCS_PATH "@CMAKE_INSTALL_PREFIX@/share/doc/netctl-gui/"
// links // links
#define HOMEPAGE "https://arcanis.me/projects/netctl-gui/" #define HOMEPAGE "http://arcanis.name/projects/netctl-gui/"
#define REPOSITORY "https://github.com/arcan1s/netctl-gui" #define REPOSITORY "https://github.com/arcan1s/netctl-gui"
#define BUGTRACKER "https://github.com/arcan1s/netctl-gui/issues" #define BUGTRACKER "https://github.com/arcan1s/netctl-gui/issues"
#define TRANSLATION "https://github.com/arcan1s/netctl-gui/issues/3" #define TRANSLATION "https://github.com/arcan1s/netctl-gui/issues/3"