This commit is contained in:
arcan1s 2014-08-09 20:19:52 +04:00
parent e64e8810f8
commit 172624b494
15 changed files with 224 additions and 172 deletions

View File

@ -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() {

View File

@ -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<sourcesList.count(); i++)
sourceRequestEvent(sourcesList[i]);
}
void Netctl::setKeys()
{
if (debug) qDebug() << "[DE]" << "[setKeys]";
@ -92,8 +81,6 @@ void Netctl::setKeys()
QStringList sourcesList = sources();
for (int i=0; i<sourcesList.count(); i++)
setData(sourcesList[i], QString("value"), QString(""));
initValues();
}

View File

@ -49,7 +49,6 @@ private:
// configuration
bool debug;
QMap<QString, QString> configuration;
void initValues();
void setKeys();
void readConfiguration();
QMap<QString, QString> updateConfiguration(const QMap<QString, QString> rawConfig);

View File

@ -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 <QDBusConnection>
#include <QDBusMessage>
#include <QDebug>
QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw,
const bool debug)
{
if (debug) qDebug() << "[parseOutputNetctl]";
QList<netctlProfileInfo> profileInfo;
if (raw.size() == 0)
return profileInfo;
for (int i=0; i<raw[0].toStringList().count(); i++) {
netctlProfileInfo profile;
QStringList info = raw[0].toStringList()[i].split(QChar('|'));
profile.name = info[0];
profile.description = info[1];
profile.active = info[2].toInt();
profile.enabled = info[3].toInt();
profileInfo.append(profile);
}
return profileInfo;
}
QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw,
const bool debug)
{
if (debug) qDebug() << "[MainWindow]" << "[parseOutputNetctl]";
QList<netctlWifiInfo> wifiInfo;
if (raw.size() == 0)
return wifiInfo;
for (int i=0; i<raw[0].toStringList().count(); i++) {
netctlWifiInfo wifi;
QStringList info = raw[0].toStringList()[i].split(QChar('|'));
wifi.name = info[0];
wifi.security = info[1];
wifi.signal = info[2];
wifi.active = info[3].toInt();
wifi.exists = info[4].toInt();
wifiInfo.append(wifi);
}
return wifiInfo;
}
QList<QVariant> sendDBusRequest(const QString service, const QString path,
const QString interface, const QString cmd,
const QList<QVariant> 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<QVariant> 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;
}

View File

@ -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 <QList>
#include <QVariant>
#include <netctlgui/netctlgui.h>
QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw,
const bool debug = false);
QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw,
const bool debug = false);
QList<QVariant> sendDBusRequest(const QString service, const QString path,
const QString interface, const QString cmd,
const QList<QVariant> args = QList<QVariant>(),
const bool system = true, const bool debug = false);
#endif /* DBUSOPERATION_H */

View File

@ -26,6 +26,7 @@
#include "aboutwindow.h"
#include "bridgewidget.h"
#include "dbusoperation.h"
#include "errorwindow.h"
#include "ethernetwidget.h"
#include "generalwidget.h"

View File

@ -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<QVariant> MainWindow::sendDBusRequest(const QString service, const QString path,
const QString interface, const QString cmd,
const QList<QVariant> 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<QVariant> 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<QString, QString> MainWindow::parseOptions(const QString options)
}
QList<netctlProfileInfo> MainWindow::parseOutputNetctl(const QList<QVariant> raw)
{
if (debug) qDebug() << "[MainWindow]" << "[parseOutputNetctl]";
QList<netctlProfileInfo> profileInfo;
if (raw.size() == 0)
return profileInfo;
for (int i=0; i<raw[0].toStringList().count(); i++) {
netctlProfileInfo profile;
QStringList info = raw[0].toStringList()[i].split(QChar('|'));
profile.name = info[0];
profile.description = info[1];
profile.active = info[2].toInt();
profile.enabled = info[3].toInt();
profileInfo.append(profile);
}
return profileInfo;
}
QList<netctlWifiInfo> MainWindow::parseOutputWifi(const QList<QVariant> raw)
{
if (debug) qDebug() << "[MainWindow]" << "[parseOutputNetctl]";
QList<netctlWifiInfo> wifiInfo;
if (raw.size() == 0)
return wifiInfo;
for (int i=0; i<raw[0].toStringList().count(); i++) {
netctlWifiInfo wifi;
QStringList info = raw[0].toStringList()[i].split(QChar('|'));
wifi.name = info[0];
wifi.security = info[1];
wifi.signal = info[2];
wifi.active = info[3].toInt();
wifi.exists = info[4].toInt();
wifiInfo.append(wifi);
}
return wifiInfo;
}
// window slots
void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
{
@ -505,8 +421,10 @@ void MainWindow::updateConfiguration(const QMap<QString, QVariant> 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);

View File

@ -145,10 +145,6 @@ private:
void createObjects();
void deleteObjects();
void keyPressEvent(QKeyEvent *pressedKey);
QList<QVariant> sendDBusRequest(const QString service, const QString path,
const QString interface, const QString cmd,
const QList<QVariant> args = QList<QVariant>(),
const bool system = true);
void setIconsToTabs();
QString configPath;
bool debug = false;
@ -159,8 +155,6 @@ private:
// configuration
QMap<QString, QString> configuration;
QMap<QString, QString> parseOptions(const QString options);
QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw);
QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw);
};

View File

@ -22,12 +22,19 @@
#include <netctlgui/netctlgui.h>
#include "dbusoperation.h"
#include "version.h"
NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap<QString, QString> 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<netctlProfileInfo> 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<netctlProfileInfo> 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]";

View File

@ -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();
};

View File

@ -15,13 +15,13 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "trayicon.h"
#include <QDebug>
#include <QMenu>
#include <QMessageBox>
#include "mainwindow.h"
#include "trayicon.h"
TrayIcon::TrayIcon(QObject *parent, const bool debugCmd)

View File

@ -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<QString, QString> configuration)

View File

@ -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);

View File

@ -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();

View File

@ -15,6 +15,7 @@
* along with netctl-gui. If not, see http://www.gnu.org/licenses/ *
***************************************************************************/
#include "netctlhelper.h"
#include <QCoreApplication>
#include <QDBusConnection>
@ -26,7 +27,6 @@
#include "controladaptor.h"
#include "netctladaptor.h"
#include "netctlhelper.h"
#include "version.h"