diff --git a/PKGBUILD b/PKGBUILD index eaef8ee..47056dd 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -13,7 +13,7 @@ license=('GPL3') makedepends=('automoc4' 'cmake' 'kdelibs' 'qt5-base' 'qt5-tools') source=("https://github.com/arcan1s/netctl-gui/releases/download/V.${pkgver}/${pkgbase}-${pkgver}-src.tar.xz") install="${pkgbase}.install" -md5sums=('0cd01301241d3b6c809f98b5d8e88b35') +md5sums=('fe694c52999c0470f5afbab16fc1e6c6') prepare() { diff --git a/sources/dataengine/netctl.cpp b/sources/dataengine/netctl.cpp index be2df76..f7eea88 100644 --- a/sources/dataengine/netctl.cpp +++ b/sources/dataengine/netctl.cpp @@ -74,17 +74,6 @@ QStringList Netctl::sources() const } -void Netctl::initValues() -{ - if (debug) qDebug() << "[DE]" << "[initValues]"; - - netctlAutoStatus = false; - QStringList sourcesList = sources(); - for (int i=0; i configuration; - void initValues(); void setKeys(); void readConfiguration(); QMap updateConfiguration(const QMap rawConfig); diff --git a/sources/gui/src/dbusoperation.cpp b/sources/gui/src/dbusoperation.cpp new file mode 100644 index 0000000..20dd2d4 --- /dev/null +++ b/sources/gui/src/dbusoperation.cpp @@ -0,0 +1,104 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#include "dbusoperation.h" + +#include +#include +#include + + +QList parseOutputNetctl(const QList raw, + const bool debug) +{ + if (debug) qDebug() << "[parseOutputNetctl]"; + + QList profileInfo; + if (raw.size() == 0) + return profileInfo; + for (int i=0; i parseOutputWifi(const QList raw, + const bool debug) +{ + if (debug) qDebug() << "[MainWindow]" << "[parseOutputNetctl]"; + + QList wifiInfo; + if (raw.size() == 0) + return wifiInfo; + for (int i=0; i sendDBusRequest(const QString service, const QString path, + const QString interface, const QString cmd, + const QList args, const bool system, + const bool debug) +{ + if (debug) qDebug() << "[sendDBusRequest]"; + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "Service" << service; + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "Path" << path; + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "Interface" << interface; + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "cmd" << cmd; + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "args" << args; + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "is system bus" << system; + + QList arguments; + QDBusMessage response; + if (system) { + QDBusConnection bus = QDBusConnection::systemBus(); + QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); + if (!args.isEmpty()) + request.setArguments(args); + response = bus.call(request); + } + else { + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); + if (!args.isEmpty()) + request.setArguments(args); + response = bus.call(request); + } + arguments = response.arguments(); + if (arguments.size() == 0) + if (debug) qDebug() << "[sendDBusRequest]" << ":" << "Error message" << response.errorMessage(); + + return arguments; +} diff --git a/sources/gui/src/dbusoperation.h b/sources/gui/src/dbusoperation.h new file mode 100644 index 0000000..947a63d --- /dev/null +++ b/sources/gui/src/dbusoperation.h @@ -0,0 +1,36 @@ +/*************************************************************************** + * This file is part of netctl-gui * + * * + * netctl-gui is free software: you can redistribute it and/or * + * modify it under the terms of the GNU General Public License as * + * published by the Free Software Foundation, either version 3 of the * + * License, or (at your option) any later version. * + * * + * netctl-gui is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * + ***************************************************************************/ + +#ifndef DBUSOPERATION_H +#define DBUSOPERATION_H + +#include +#include + +#include + +QList parseOutputNetctl(const QList raw, + const bool debug = false); +QList parseOutputWifi(const QList raw, + const bool debug = false); +QList sendDBusRequest(const QString service, const QString path, + const QString interface, const QString cmd, + const QList args = QList(), + const bool system = true, const bool debug = false); + + +#endif /* DBUSOPERATION_H */ diff --git a/sources/gui/src/mainactions.cpp b/sources/gui/src/mainactions.cpp index 87ec7fc..ee55050 100644 --- a/sources/gui/src/mainactions.cpp +++ b/sources/gui/src/mainactions.cpp @@ -26,6 +26,7 @@ #include "aboutwindow.h" #include "bridgewidget.h" +#include "dbusoperation.h" #include "errorwindow.h" #include "ethernetwidget.h" #include "generalwidget.h" diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index d4be4d5..8965257 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -25,6 +25,7 @@ #include "aboutwindow.h" #include "bridgewidget.h" +#include "dbusoperation.h" #include "errorwindow.h" #include "ethernetwidget.h" #include "generalwidget.h" @@ -373,48 +374,6 @@ void MainWindow::deleteObjects() } -QList MainWindow::sendDBusRequest(const QString service, const QString path, - const QString interface, const QString cmd, - const QList args, bool system) -{ - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]"; - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Service" << service; - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Path" << path; - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Interface" << interface; - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "cmd" << cmd; - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "args" << args; - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "is system bus" << system; - - QList arguments; - QDBusMessage response; - if (system) { - QDBusConnection bus = QDBusConnection::systemBus(); - QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); - if (!args.isEmpty()) - request.setArguments(args); - response = bus.call(request); - } - else { - QDBusConnection bus = QDBusConnection::sessionBus(); - QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd); - if (!args.isEmpty()) - request.setArguments(args); - response = bus.call(request); - } - arguments = response.arguments(); - if ((arguments.size() == 0) && - (service != DBUS_HELPER_SERVICE) && - (path != DBUS_CONTROL_PATH) && - (interface != DBUS_HELPER_INTERFACE) && - (cmd != QString("Active"))) { - if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Error message" << response.errorMessage(); - errorWin->showWindow(0, QString("[MainWindow] : [sendDBusRequest]"), response.errorMessage()); - } - - return arguments; -} - - void MainWindow::setIconsToTabs() { if (debug) qDebug() << "[MainWindow]" << "[setIconsToTabs]"; @@ -445,49 +404,6 @@ QMap MainWindow::parseOptions(const QString options) } -QList MainWindow::parseOutputNetctl(const QList raw) -{ - if (debug) qDebug() << "[MainWindow]" << "[parseOutputNetctl]"; - - QList profileInfo; - if (raw.size() == 0) - return profileInfo; - for (int i=0; i MainWindow::parseOutputWifi(const QList raw) -{ - if (debug) qDebug() << "[MainWindow]" << "[parseOutputNetctl]"; - - QList wifiInfo; - if (raw.size() == 0) - return wifiInfo; - for (int i=0; i args) { @@ -505,8 +421,10 @@ void MainWindow::updateConfiguration(const QMap args) if ((configuration[QString("USE_HELPER")] == QString("true")) && (checkExternalApps(QString("helper")))) useHelper = true; - else + else { useHelper = false; + configuration[QString("USE_HELPER")] = QString("false"); + } // update translation qApp->removeTranslator(translator); diff --git a/sources/gui/src/mainwindow.h b/sources/gui/src/mainwindow.h index cfc7842..16c47d1 100644 --- a/sources/gui/src/mainwindow.h +++ b/sources/gui/src/mainwindow.h @@ -145,10 +145,6 @@ private: void createObjects(); void deleteObjects(); void keyPressEvent(QKeyEvent *pressedKey); - QList sendDBusRequest(const QString service, const QString path, - const QString interface, const QString cmd, - const QList args = QList(), - const bool system = true); void setIconsToTabs(); QString configPath; bool debug = false; @@ -159,8 +155,6 @@ private: // configuration QMap configuration; QMap parseOptions(const QString options); - QList parseOutputNetctl(const QList raw); - QList parseOutputWifi(const QList raw); }; diff --git a/sources/gui/src/netctlautowindow.cpp b/sources/gui/src/netctlautowindow.cpp index 1b8ead9..fa207d9 100644 --- a/sources/gui/src/netctlautowindow.cpp +++ b/sources/gui/src/netctlautowindow.cpp @@ -22,12 +22,19 @@ #include +#include "dbusoperation.h" +#include "version.h" + NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap settings) : QMainWindow(parent), ui(new Ui::NetctlAutoWindow), debug(debugCmd) { + if (settings[QString("USE_HELPER")] == QString("true")) + useHelper = true; + else + useHelper = false; ui->setupUi(this); ui->tableWidget->setColumnHidden(2, true); ui->tableWidget->setColumnHidden(3, true); @@ -100,13 +107,67 @@ void NetctlAutoWindow::showWindow() } +void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos) +{ + if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]"; + + if (ui->tableWidget->currentItem() == 0) + return; + // create menu + QMenu menu(this); + QAction *startProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Switch to profile")); + startProfile->setIcon(QIcon::fromTheme("system-run")); + QAction *enableProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable profile")); + menu.addSeparator(); + QAction *enableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable all profiles")); + enableAllProfiles->setIcon(QIcon::fromTheme("edit-add")); + QAction *disableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Disable all profiles")); + disableAllProfiles->setIcon(QIcon::fromTheme("edit-delete")); + + // set text + if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 2)->text().isEmpty()) { + enableProfile->setVisible(false); + startProfile->setVisible(false); + } + else { + enableProfile->setVisible(true); + startProfile->setVisible(true); + if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 3)->text().isEmpty()) { + enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Enable")); + enableProfile->setIcon(QIcon::fromTheme("edit-add")); + } + else { + enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Disable")); + enableProfile->setIcon(QIcon::fromTheme("edit-delete")); + } + } + + // actions + QAction *action = menu.exec(ui->tableWidget->viewport()->mapToGlobal(pos)); + if (action == startProfile) { + if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Switch to profile"; + netctlAutoStartProfile(); + } + else if (action == enableProfile) { + if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Enable profile"; + netctlAutoEnableProfile(); + } + else if (action == enableAllProfiles) { + if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Enable all profiles"; + netctlAutoEnableAllProfiles(); + } + else if (action == disableAllProfiles) { + if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Disable all profiles"; + netctlAutoDisableAllProfiles(); + } +} + + void NetctlAutoWindow::netctlAutoUpdateTable() { if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoUpdateTable]"; ui->tableWidget->setDisabled(true); - QList profiles = netctlCommand->getProfileListFromNetctlAuto(); - // actions if (netctlCommand->isNetctlAutoEnabled()) ui->actionEnableService->setText(QApplication::translate("NetctlAutoWindow", "Disable service")); @@ -129,6 +190,7 @@ void NetctlAutoWindow::netctlAutoUpdateTable() netctlAutoRefreshButtons(0, 0); return; } + QList profiles = netctlCommand->getProfileListFromNetctlAuto(); ui->tableWidget->setSortingEnabled(false); ui->tableWidget->selectRow(-1); @@ -190,62 +252,6 @@ void NetctlAutoWindow::netctlAutoUpdateTable() } -void NetctlAutoWindow::netctlAutoContextualMenu(const QPoint &pos) -{ - if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]"; - - if (ui->tableWidget->currentItem() == 0) - return; - // create menu - QMenu menu(this); - QAction *startProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Switch to profile")); - startProfile->setIcon(QIcon::fromTheme("system-run")); - QAction *enableProfile = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable profile")); - menu.addSeparator(); - QAction *enableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Enable all profiles")); - enableAllProfiles->setIcon(QIcon::fromTheme("edit-add")); - QAction *disableAllProfiles = menu.addAction(QApplication::translate("NetctlAutoWindow", "Disable all profiles")); - disableAllProfiles->setIcon(QIcon::fromTheme("edit-delete")); - - // set text - if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 2)->text().isEmpty()) { - enableProfile->setVisible(false); - startProfile->setVisible(false); - } - else { - enableProfile->setVisible(true); - startProfile->setVisible(true); - if (!ui->tableWidget->item(ui->tableWidget->currentItem()->row(), 3)->text().isEmpty()) { - enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Enable")); - enableProfile->setIcon(QIcon::fromTheme("edit-add")); - } - else { - enableProfile->setText(QApplication::translate("NetctlAutoWindow", "Disable")); - enableProfile->setIcon(QIcon::fromTheme("edit-delete")); - } - } - - // actions - QAction *action = menu.exec(ui->tableWidget->viewport()->mapToGlobal(pos)); - if (action == startProfile) { - if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Switch to profile"; - netctlAutoStartProfile(); - } - else if (action == enableProfile) { - if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Enable profile"; - netctlAutoEnableProfile(); - } - else if (action == enableAllProfiles) { - if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Enable all profiles"; - netctlAutoEnableAllProfiles(); - } - else if (action == disableAllProfiles) { - if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoContextualMenu]" << "Disable all profiles"; - netctlAutoDisableAllProfiles(); - } -} - - void NetctlAutoWindow::netctlAutoDisableAllProfiles() { if (debug) qDebug() << "[NetctlAutoWindow]" << "[netctlAutoDisableAllProfiles]"; diff --git a/sources/gui/src/netctlautowindow.h b/sources/gui/src/netctlautowindow.h index 6feccfc..b24d505 100644 --- a/sources/gui/src/netctlautowindow.h +++ b/sources/gui/src/netctlautowindow.h @@ -58,9 +58,10 @@ private slots: void netctlAutoStartService(); private: - Netctl *netctlCommand; - Ui::NetctlAutoWindow *ui; - bool debug; + Netctl *netctlCommand = nullptr; + Ui::NetctlAutoWindow *ui = nullptr; + bool debug = false; + bool useHelper = true; QString checkStatus(const bool statusBool, const bool nullFalse = false); void createActions(); }; diff --git a/sources/gui/src/trayicon.cpp b/sources/gui/src/trayicon.cpp index 64b5bb1..b2ded94 100644 --- a/sources/gui/src/trayicon.cpp +++ b/sources/gui/src/trayicon.cpp @@ -15,13 +15,13 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ +#include "trayicon.h" #include #include #include #include "mainwindow.h" -#include "trayicon.h" TrayIcon::TrayIcon(QObject *parent, const bool debugCmd) diff --git a/sources/helper/src/controladaptor.cpp b/sources/helper/src/controladaptor.cpp index edf75a5..1b2c9f4 100644 --- a/sources/helper/src/controladaptor.cpp +++ b/sources/helper/src/controladaptor.cpp @@ -15,9 +15,9 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ +#include "controladaptor.h" #include "netctlhelper.h" -#include "controladaptor.h" ControlAdaptor::ControlAdaptor(NetctlHelper *parent, const QMap configuration) diff --git a/sources/helper/src/netctladaptor.cpp b/sources/helper/src/netctladaptor.cpp index 8f24d61..0651c98 100644 --- a/sources/helper/src/netctladaptor.cpp +++ b/sources/helper/src/netctladaptor.cpp @@ -15,7 +15,6 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ - #include "netctladaptor.h" @@ -83,6 +82,12 @@ bool NetctlAdaptor::isNetctlAutoActive() } +bool NetctlAdaptor::isNetctlAutoEnabled() +{ + return netctlCommand->isNetctlAutoEnabled(); +} + + bool NetctlAdaptor::isProfileActive(const QString profile) { return netctlCommand->isProfileActive(profile); diff --git a/sources/helper/src/netctladaptor.h b/sources/helper/src/netctladaptor.h index 9c056bb..00ce09f 100644 --- a/sources/helper/src/netctladaptor.h +++ b/sources/helper/src/netctladaptor.h @@ -42,6 +42,7 @@ public slots: bool autoIsProfileEnabled(const QString profile); QStringList Information(); bool isNetctlAutoActive(); + bool isNetctlAutoEnabled(); bool isProfileActive(const QString profile); bool isProfileEnabled(const QString profile); QStringList ProfileList(); diff --git a/sources/helper/src/netctlhelper.cpp b/sources/helper/src/netctlhelper.cpp index d234c86..7cea90c 100644 --- a/sources/helper/src/netctlhelper.cpp +++ b/sources/helper/src/netctlhelper.cpp @@ -15,6 +15,7 @@ * along with netctl-gui. If not, see http://www.gnu.org/licenses/ * ***************************************************************************/ +#include "netctlhelper.h" #include #include @@ -26,7 +27,6 @@ #include "controladaptor.h" #include "netctladaptor.h" -#include "netctlhelper.h" #include "version.h"