From 23f4a7f141ce2bba8756067370b3cc3f1203c265 Mon Sep 17 00:00:00 2001 From: arcan1s Date: Sat, 9 Aug 2014 12:56:05 +0400 Subject: [PATCH] rewrite mainwindow.cpp to use helper --- sources/gui/src/mainactions.cpp | 3 --- sources/gui/src/mainwindow.cpp | 29 ++++++++++++++++++---------- sources/helper/src/netctladaptor.cpp | 16 ++++++++++----- sources/helper/src/netctladaptor.h | 1 + 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/sources/gui/src/mainactions.cpp b/sources/gui/src/mainactions.cpp index 8867751..fbbabbe 100644 --- a/sources/gui/src/mainactions.cpp +++ b/sources/gui/src/mainactions.cpp @@ -18,13 +18,10 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include -#include #include #include #include #include -#include #include #include "aboutwindow.h" diff --git a/sources/gui/src/mainwindow.cpp b/sources/gui/src/mainwindow.cpp index 40b4603..9bcfa27 100644 --- a/sources/gui/src/mainwindow.cpp +++ b/sources/gui/src/mainwindow.cpp @@ -21,11 +21,7 @@ #include #include #include -#include -#include -#include #include -#include #include "aboutwindow.h" #include "bridgewidget.h" @@ -125,13 +121,21 @@ QString MainWindow::getInformation() QString profile; QString status; - if (netctlCommand->isNetctlAutoRunning()) { - profile = netctlCommand->autoGetActiveProfile(); - status = QString("netctl-auto"); + if (useHelper) { + QStringList request = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, + DBUS_HELPER_INTERFACE, QString("Information"))[0].toStringList(); + profile = request[0]; + status = request[1]; } else { - profile = netctlCommand->getActiveProfile(); - status = netctlCommand->getProfileStatus(profile); + if (netctlCommand->isNetctlAutoRunning()) { + profile = netctlCommand->autoGetActiveProfile(); + status = QString("netctl-auto"); + } + else { + profile = netctlCommand->getActiveProfile(); + status = netctlCommand->getProfileStatus(profile); + } } QString output = QString("%1: %2\n").arg(QApplication::translate("MainWindow", "Profile")).arg(profile); output += QString("%1: %2").arg(QApplication::translate("MainWindow", "Status")).arg(status); @@ -753,7 +757,12 @@ void MainWindow::updateWifiTab() return errorWin->showWindow(1, QString("[MainWindow] : [updateWifiTab]")); ui->tabWidget->setDisabled(true); - QList scanResults = wpaCommand->scanWifi(); + QList scanResults; + if (useHelper) + scanResults = parseOutputWifi(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, + DBUS_HELPER_INTERFACE, QString("WiFi"))); + else + scanResults = wpaCommand->scanWifi(); ui->tableWidget_wifi->setSortingEnabled(false); ui->tableWidget_wifi->selectRow(-1); diff --git a/sources/helper/src/netctladaptor.cpp b/sources/helper/src/netctladaptor.cpp index e2b2a93..5353fee 100644 --- a/sources/helper/src/netctladaptor.cpp +++ b/sources/helper/src/netctladaptor.cpp @@ -39,7 +39,7 @@ NetctlAdaptor::~NetctlAdaptor() // netctlCommand QString NetctlAdaptor::ActiveProfile() { - if (netctlCommand->isNetctlAutoRunning()) + if (isNetctlAutoActive()) return netctlCommand->autoGetActiveProfile(); else return netctlCommand->getActiveProfile(); @@ -48,7 +48,7 @@ QString NetctlAdaptor::ActiveProfile() QString NetctlAdaptor::ActiveProfileStatus() { - if (netctlCommand->isNetctlAutoRunning()) + if (isNetctlAutoActive()) return QString("netctl-auto"); else return netctlCommand->getProfileStatus(ActiveProfile()); @@ -70,13 +70,19 @@ bool NetctlAdaptor::autoIsProfileEnabled(const QString profile) QStringList NetctlAdaptor::Information() { QStringList output; - output.append(QString("Profile: %1").arg(ActiveProfile())); - output.append(QString("Status: %1").arg(ActiveProfileStatus())); + output.append(ActiveProfile()); + output.append(ActiveProfileStatus()); return output; } +bool NetctlAdaptor::isNetctlAutoActive() +{ + return netctlCommand->isNetctlAutoRunning(); +} + + bool NetctlAdaptor::isProfileActive(const QString profile) { return netctlCommand->isProfileActive(profile); @@ -92,7 +98,7 @@ bool NetctlAdaptor::isProfileEnabled(const QString profile) QStringList NetctlAdaptor::ProfileList() { QList profilesInfo; - if (netctlCommand->isNetctlAutoRunning()) + if (isNetctlAutoActive()) profilesInfo = netctlCommand->getProfileListFromNetctlAuto(); else profilesInfo = netctlCommand->getProfileList(); diff --git a/sources/helper/src/netctladaptor.h b/sources/helper/src/netctladaptor.h index ac6983b..e2f197f 100644 --- a/sources/helper/src/netctladaptor.h +++ b/sources/helper/src/netctladaptor.h @@ -41,6 +41,7 @@ public slots: bool autoIsProfileActive(const QString profile); bool autoIsProfileEnabled(const QString profile); QStringList Information(); + bool isNetctlAutoActive(); bool isProfileActive(const QString profile); bool isProfileEnabled(const QString profile); QStringList ProfileList();