mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
rewrite ui (refactoring, simplification, improvement of user expierence)
This commit is contained in:
parent
b90f441fde
commit
275d71d75f
@ -8,7 +8,7 @@ ProjectRootRelative=./
|
||||
|
||||
[CMake][CMake Build Directory 0]
|
||||
Build Directory Path=file:///home/arcanis/Documents/github/netctl-gui/build
|
||||
Build Type=Release
|
||||
Build Type=Debug
|
||||
CMake Binary=file:///usr/bin/cmake
|
||||
Environment Profile=
|
||||
Extra Arguments=
|
||||
|
74
sources/gui/src/commonfunctions.cpp
Normal file
74
sources/gui/src/commonfunctions.cpp
Normal file
@ -0,0 +1,74 @@
|
||||
/***************************************************************************
|
||||
* 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 "commonfunctions.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
#include <task/taskadds.h>
|
||||
|
||||
|
||||
bool checkExternalApps(const QString apps, const QMap<QString, QString> configuration,
|
||||
const bool debug)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Applications" << apps;
|
||||
|
||||
if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true;
|
||||
QStringList cmd;
|
||||
cmd.append("which");
|
||||
// avoid null-lines arguments
|
||||
cmd.append("true");
|
||||
if ((apps == QString("helper")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("HELPER_PATH")]);
|
||||
}
|
||||
if ((apps == QString("netctl")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("NETCTL_PATH")]);
|
||||
cmd.append(configuration[QString("NETCTLAUTO_PATH")]);
|
||||
cmd.append(configuration[QString("SUDO_PATH")]);
|
||||
}
|
||||
if ((apps == QString("sudo")) || (apps == QString("wpasup")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("SUDO_PATH")]);
|
||||
}
|
||||
if ((apps == QString("systemctl")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("SYSTEMCTL_PATH")]);
|
||||
cmd.append(configuration[QString("SUDO_PATH")]);
|
||||
}
|
||||
if ((apps == QString("wpasup")) || (apps == QString("wpasup-only")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("WPACLI_PATH")]);
|
||||
cmd.append(configuration[QString("WPASUP_PATH")]);
|
||||
}
|
||||
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd.join(QChar(' '));
|
||||
TaskResult process = runTask(cmd.join(QChar(' ')), false);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||
if (process.exitCode != 0)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||
|
||||
return (process.exitCode == 0);
|
||||
}
|
||||
|
||||
|
||||
QString checkStatus(const bool statusBool, const bool nullFalse)
|
||||
{
|
||||
if (statusBool) return QApplication::translate("MainWindow", "yes");
|
||||
if (!nullFalse) return QApplication::translate("MainWindow", "no");
|
||||
|
||||
return QString("");
|
||||
}
|
31
sources/gui/src/commonfunctions.h
Normal file
31
sources/gui/src/commonfunctions.h
Normal file
@ -0,0 +1,31 @@
|
||||
/***************************************************************************
|
||||
* 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 COMMONFUNCTIONS_H
|
||||
#define COMMONFUNCTIONS_H
|
||||
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
|
||||
|
||||
bool checkExternalApps(const QString apps = QString("all"),
|
||||
const QMap<QString, QString> configuration = QMap<QString, QString>(),
|
||||
const bool debug = false);
|
||||
QString checkStatus(const bool statusBool, const bool nullFalse = false);
|
||||
|
||||
|
||||
#endif /* COMMONFUNCTIONS_H */
|
File diff suppressed because it is too large
Load Diff
@ -1,495 +0,0 @@
|
||||
/***************************************************************************
|
||||
* 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 "mainwindow.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDesktopServices>
|
||||
#include <QLibraryInfo>
|
||||
#include <QTranslator>
|
||||
#include <QUrl>
|
||||
|
||||
#include <language/language.h>
|
||||
#include <pdebug/pdebug.h>
|
||||
#include <task/taskadds.h>
|
||||
|
||||
#include "aboutwindow.h"
|
||||
#include "dbusoperation.h"
|
||||
#include "errorwindow.h"
|
||||
#include "netctlautowindow.h"
|
||||
#include "passwdwidget.h"
|
||||
#include "settingswindow.h"
|
||||
#include "trayicon.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
void MainWindow::closeMainWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showAboutWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
aboutWin->show();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showMainWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (isHidden()) {
|
||||
updateTabs(ui->tabWidget->currentIndex());
|
||||
show();
|
||||
} else
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showNetctlAutoWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
netctlAutoWin->showWindow();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showSettingsWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
settingsWin->showWindow();
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::enableProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Enable"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->enableProfile(profile);
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::restartProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Restart"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->restartProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::startProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToLib(QString("ActiveProfile"), debug);
|
||||
QStringList currentProfile;
|
||||
if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|'));
|
||||
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
|
||||
sendRequestToCtrlWithArgs(QString("Start"), args, debug);
|
||||
else
|
||||
sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug);
|
||||
responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
QStringList currentProfile = netctlCommand->getActiveProfile();
|
||||
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
|
||||
netctlCommand->startProfile(profile);
|
||||
else
|
||||
netctlCommand->switchToProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::stopAllProfilesSlot()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (useHelper)
|
||||
sendRequestToCtrl(QString("StolAll"), debug);
|
||||
else
|
||||
netctlCommand->stopAllProfiles();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::switchToProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool netctlAutoStatus = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToLib(QString("isNetctlAutoActive"), debug);
|
||||
if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool();
|
||||
} else
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
|
||||
bool current;
|
||||
if (netctlAutoStatus) {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("autoStart"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->autoStartProfile(profile);
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
}
|
||||
} else {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->switchToProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showApi()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-dbus-api.html").arg(QString(DOCS_PATH)))))
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showLibrary()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (QDesktopServices::openUrl(QUrl(QString("%1html/index.html").arg(QString(DOCS_PATH)))))
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showSecurityNotes()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-security-notes.html").arg(QString(DOCS_PATH)))))
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::forceStartHelper()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("helper"))) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(needToBeConfigured());
|
||||
return false;
|
||||
}
|
||||
|
||||
QString cmd = QString("%1 -c %2").arg(configuration[QString("HELPER_PATH")]).arg(configPath);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd, false);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||
if (process.exitCode != 0)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||
|
||||
return (process.exitCode == 0);
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::forceStopHelper()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<QVariant> responce = sendRequestToCtrl(QString("Close"), debug);
|
||||
|
||||
return !responce.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::startHelper()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (isHelperActive())
|
||||
return forceStopHelper();
|
||||
else
|
||||
return forceStartHelper();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setTab(int tab)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Set tab" << tab;
|
||||
|
||||
if ((tab > 2) || (tab < 0)) tab = 0;
|
||||
if (tab == ui->tabWidget->currentIndex())
|
||||
updateTabs(tab);
|
||||
else
|
||||
ui->tabWidget->setCurrentIndex(tab);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
deleteObjects();
|
||||
|
||||
settingsWin = new SettingsWindow(this, debug, configPath);
|
||||
if (args[QString("default")].toBool())
|
||||
settingsWin->setDefault();
|
||||
configuration = settingsWin->getSettings();
|
||||
delete settingsWin;
|
||||
QMap<QString, QString> optionsDict = parseOptions(args[QString("options")].toString());
|
||||
for (int i=0; i<optionsDict.keys().count(); i++)
|
||||
configuration[optionsDict.keys()[i]] = optionsDict[optionsDict.keys()[i]];
|
||||
if ((configuration[QString("USE_HELPER")] == QString("true")) &&
|
||||
(checkExternalApps(QString("helper"))))
|
||||
useHelper = true;
|
||||
else {
|
||||
useHelper = false;
|
||||
configuration[QString("USE_HELPER")] = QString("false");
|
||||
}
|
||||
|
||||
// update translation
|
||||
qApp->removeTranslator(translator);
|
||||
QString language = Language::defineLanguage(configPath, args[QString("options")].toString());
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Language is" << language;
|
||||
qtTranslator->load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
qApp->installTranslator(qtTranslator);
|
||||
translator->load(QString(":/translations/%1").arg(language));
|
||||
qApp->installTranslator(translator);
|
||||
|
||||
createObjects();
|
||||
createActions();
|
||||
createToolBars();
|
||||
|
||||
// tray
|
||||
trayIcon->setVisible(QSystemTrayIcon::isSystemTrayAvailable() && (configuration[QString("SYSTRAY")] == QString("true")));
|
||||
if (trayIcon->isVisible()) {
|
||||
setHidden(configuration[QString("STARTTOTRAY")] == QString("true"));
|
||||
if (args[QString("minimized")].toInt() == 1)
|
||||
show();
|
||||
else if (args[QString("minimized")].toInt() == 2)
|
||||
hide();
|
||||
}
|
||||
else
|
||||
show();
|
||||
|
||||
// update ui
|
||||
setTab(args[QString("tab")].toInt() - 1);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateMenu()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
int tab = ui->tabWidget->currentIndex();
|
||||
setMenuActionsShown(false);
|
||||
|
||||
switch (tab) {
|
||||
case 1:
|
||||
updateMenuProfile();
|
||||
break;
|
||||
case 2:
|
||||
updateMenuWifi();
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
updateMenuMain();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateTabs(const int tab)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Update tab" << tab;
|
||||
|
||||
switch (tab) {
|
||||
case 1:
|
||||
updateProfileTab();
|
||||
break;
|
||||
case 2:
|
||||
updateWifiTab();
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
updateMainTab();
|
||||
break;
|
||||
}
|
||||
updateMenu();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::connectToUnknownEssid(const QString passwd)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (passwdWid != nullptr) delete passwdWid;
|
||||
QStringList interfaces;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToLib(QString("WirelessInterfaces"), debug);
|
||||
if (responce.isEmpty())
|
||||
interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
else
|
||||
interfaces = responce[0].toStringList();
|
||||
} else
|
||||
interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) return;
|
||||
|
||||
QMap<QString, QString> settings;
|
||||
settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'");
|
||||
settings[QString("Interface")] = interfaces[0];
|
||||
settings[QString("Connection")] = QString("wireless");
|
||||
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text();
|
||||
if (security.contains(QString("WPA")))
|
||||
settings[QString("Security")] = QString("wpa");
|
||||
else if (security.contains(QString("WEP")))
|
||||
settings[QString("Security")] = QString("wep");
|
||||
else
|
||||
settings[QString("Security")] = QString("none");
|
||||
settings[QString("ESSID")] = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text());
|
||||
if (!passwd.isEmpty())
|
||||
settings[QString("Key")] = QString("'%1'").arg(passwd);
|
||||
settings[QString("IP")] = QString("dhcp");
|
||||
if (hiddenNetwork)
|
||||
settings[QString("Hidden")] = QString("yes");
|
||||
|
||||
QString profile = QString("netctl-gui-%1").arg(settings[QString("ESSID")]);
|
||||
profile.remove(QChar('"')).remove(QChar('\''));
|
||||
if (useHelper) {
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(QString("%1==%2").arg(settings.keys()[i]).arg(settings[settings.keys()[i]]));
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
args.append(settingsList);
|
||||
sendRequestToCtrlWithArgs(QString("Create"), args, debug);
|
||||
} else {
|
||||
QString profileTempName = netctlProfile->createProfile(profile, settings);
|
||||
netctlProfile->copyProfile(profileTempName);
|
||||
}
|
||||
QString message;
|
||||
if (startProfileSlot(profile)) {
|
||||
message = QApplication::translate("MainWindow", "Connection is successfully.");
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
} else {
|
||||
message = QApplication::translate("MainWindow", "Connection failed.");
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
message += QString("\n");
|
||||
message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile);
|
||||
int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"),
|
||||
message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save);
|
||||
switch (select) {
|
||||
case QMessageBox::Save:
|
||||
break;
|
||||
case QMessageBox::Discard:
|
||||
default:
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Remove"), args, debug);
|
||||
} else
|
||||
netctlProfile->removeProfile(profile);
|
||||
break;
|
||||
}
|
||||
|
||||
updateWifiTab();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setHiddenName(const QString name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Set name" << name;
|
||||
|
||||
ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name);
|
||||
|
||||
wifiTabStart();
|
||||
}
|
502
sources/gui/src/mainwidget.cpp
Normal file
502
sources/gui/src/mainwidget.cpp
Normal file
@ -0,0 +1,502 @@
|
||||
/***************************************************************************
|
||||
* 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 "mainwidget.h"
|
||||
#include "ui_mainwidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "commonfunctions.h"
|
||||
#include "dbusoperation.h"
|
||||
#include "errorwindow.h"
|
||||
#include "mainwindow.h"
|
||||
#include "netctlautowindow.h"
|
||||
|
||||
|
||||
MainWidget::MainWidget(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
|
||||
: QWidget(parent),
|
||||
debug(debugCmd),
|
||||
configuration(settings)
|
||||
{
|
||||
mainWindow = dynamic_cast<MainWindow *>(parent);
|
||||
useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
|
||||
|
||||
createObjects();
|
||||
createToolBars();
|
||||
createActions();
|
||||
}
|
||||
|
||||
|
||||
MainWidget::~MainWidget()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
deleteObjects();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::showNetctlAutoWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
netctlAutoWin->showWindow();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::update()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
updateMainTab();
|
||||
updateMenuMain();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::updateMenuMain()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
bool selected = (ui->tableWidget_main->currentItem() != nullptr);
|
||||
toolBarActions[QString("mainStart")]->setVisible(selected);
|
||||
toolBarActions[QString("mainEnable")]->setVisible(selected);
|
||||
toolBarActions[QString("mainEdit")]->setVisible(selected);
|
||||
toolBarActions[QString("mainRemove")]->setVisible(selected);
|
||||
toolBarActions[QString("mainStopAll")]->setVisible(!mainTabGetActiveProfiles().isEmpty());
|
||||
|
||||
if (selected && !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) {
|
||||
// visible
|
||||
toolBarActions[QString("mainRestart")]->setVisible(true);
|
||||
toolBarActions[QString("mainSwitch")]->setVisible(true);
|
||||
// text
|
||||
toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWidget", "Stop"));
|
||||
toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("process-stop"));
|
||||
} else {
|
||||
// visible
|
||||
toolBarActions[QString("mainRestart")]->setVisible(false);
|
||||
toolBarActions[QString("mainSwitch")]->setVisible(false);
|
||||
// text
|
||||
toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWidget", "Start"));
|
||||
toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("system-run"));
|
||||
}
|
||||
if (selected && !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) {
|
||||
toolBarActions[QString("mainEnable")]->setText(QApplication::translate("MainWidget", "Disable"));
|
||||
toolBarActions[QString("mainEnable")]->setIcon(QIcon::fromTheme("edit-remove"));
|
||||
} else {
|
||||
toolBarActions[QString("mainEnable")]->setText(QApplication::translate("MainWidget", "Enable"));
|
||||
toolBarActions[QString("mainEnable")]->setIcon(QIcon::fromTheme("list-add"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::updateMainTab()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QList<netctlProfileInfo> profiles;
|
||||
bool netctlAutoStatus = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToLib(QString("isNetctlAutoActive"), debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return updateMainTab();
|
||||
}
|
||||
netctlAutoStatus = responce[0].toBool();
|
||||
profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug));
|
||||
} else {
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
profiles = netctlCommand->getProfileList();
|
||||
}
|
||||
ui->widget_netctlAuto->setHidden(!netctlAutoStatus);
|
||||
|
||||
ui->tableWidget_main->setSortingEnabled(false);
|
||||
ui->tableWidget_main->selectRow(-1);
|
||||
ui->tableWidget_main->sortByColumn(0, Qt::AscendingOrder);
|
||||
ui->tableWidget_main->clear();
|
||||
ui->tableWidget_main->setRowCount(profiles.count());
|
||||
|
||||
// create header
|
||||
QStringList headerList;
|
||||
headerList.append(QApplication::translate("MainWidget", "Name"));
|
||||
headerList.append(QApplication::translate("MainWidget", "Description"));
|
||||
headerList.append(QApplication::translate("MainWidget", "Active"));
|
||||
headerList.append(QApplication::translate("MainWidget", "Enabled"));
|
||||
ui->tableWidget_main->setHorizontalHeaderLabels(headerList);
|
||||
// create items
|
||||
for (int i=0; i<profiles.count(); i++) {
|
||||
// font
|
||||
QFont font;
|
||||
font.setBold(profiles[i].active);
|
||||
font.setItalic(profiles[i].enabled);
|
||||
// tooltip
|
||||
QString toolTip = QString("");
|
||||
toolTip += QString("%1: %2@%3\n").arg(QApplication::translate("MainWidget", "Type"))
|
||||
.arg(profiles[i].type).arg(profiles[i].interface);
|
||||
toolTip += QString("%1: %2\n").arg(QApplication::translate("MainWidget", "Active"))
|
||||
.arg(checkStatus(profiles[i].active));
|
||||
toolTip += QString("%1: %2\n").arg(QApplication::translate("MainWidget", "Enabled"))
|
||||
.arg(checkStatus(profiles[i].enabled));
|
||||
toolTip += QString("%1: %2").arg(QApplication::translate("MainWidget", "Is wireless"))
|
||||
.arg(checkStatus(!profiles[i].essid.isEmpty()));
|
||||
// name
|
||||
ui->tableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i].name));
|
||||
ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
ui->tableWidget_main->item(i, 0)->setToolTip(toolTip);
|
||||
ui->tableWidget_main->item(i, 0)->setFont(font);
|
||||
// description
|
||||
ui->tableWidget_main->setItem(i, 1, new QTableWidgetItem(profiles[i].description));
|
||||
ui->tableWidget_main->item(i, 1)->setTextAlignment(Qt::AlignJustify | Qt::AlignVCenter);
|
||||
ui->tableWidget_main->item(i, 1)->setToolTip(toolTip);
|
||||
// active
|
||||
ui->tableWidget_main->setItem(i, 2, new QTableWidgetItem(checkStatus(profiles[i].active, true)));
|
||||
ui->tableWidget_main->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
// enabled
|
||||
ui->tableWidget_main->setItem(i, 3, new QTableWidgetItem(checkStatus(profiles[i].enabled, true)));
|
||||
ui->tableWidget_main->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
ui->tableWidget_main->setSortingEnabled(true);
|
||||
|
||||
ui->tableWidget_main->resizeRowsToContents();
|
||||
ui->tableWidget_main->resizeColumnsToContents();
|
||||
ui->tableWidget_main->resizeRowsToContents();
|
||||
#if QT_VERSION >= 0x050000
|
||||
ui->tableWidget_main->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
ui->tableWidget_main->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
|
||||
mainWindow->setDisabled(false);
|
||||
mainWindow->showMessage(true);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabContextualMenu(const QPoint &pos)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
// create menu
|
||||
QMenu menu(this);
|
||||
QAction *refreshTable = menu.addAction(QApplication::translate("MainWidget", "Refresh"));
|
||||
refreshTable->setIcon(QIcon::fromTheme("view-refresh"));
|
||||
menu.addSeparator();
|
||||
QAction *startProfile = menu.addAction(QApplication::translate("MainWidget", "Start profile"));
|
||||
QAction *restartProfile = menu.addAction(QApplication::translate("MainWidget", "Restart profile"));
|
||||
restartProfile->setIcon(QIcon::fromTheme("view-refresh"));
|
||||
QAction *enableProfile = menu.addAction(QApplication::translate("MainWidget", "Enable profile"));
|
||||
menu.addSeparator();
|
||||
QAction *editProfile = menu.addAction(QApplication::translate("MainWidget", "Edit profile"));
|
||||
editProfile->setIcon(QIcon::fromTheme("document-edit"));
|
||||
QAction *removeProfile = menu.addAction(QApplication::translate("MainWidget", "Remove profile"));
|
||||
removeProfile->setIcon(QIcon::fromTheme("edit-delete"));
|
||||
|
||||
// set text
|
||||
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) {
|
||||
restartProfile->setVisible(true);
|
||||
startProfile->setText(QApplication::translate("MainWidget", "Stop profile"));
|
||||
startProfile->setIcon(QIcon::fromTheme("process-stop"));
|
||||
} else {
|
||||
restartProfile->setVisible(false);
|
||||
startProfile->setText(QApplication::translate("MainWidget", "Start profile"));
|
||||
startProfile->setIcon(QIcon::fromTheme("system-run"));
|
||||
}
|
||||
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) {
|
||||
enableProfile->setText(QApplication::translate("MainWidget", "Disable profile"));
|
||||
enableProfile->setIcon(QIcon::fromTheme("edit-remove"));
|
||||
} else {
|
||||
enableProfile->setText(QApplication::translate("MainWidget", "Enable profile"));
|
||||
enableProfile->setIcon(QIcon::fromTheme("list-add"));
|
||||
}
|
||||
|
||||
// actions
|
||||
QAction *action = menu.exec(ui->tableWidget_main->viewport()->mapToGlobal(pos));
|
||||
if (action == refreshTable) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Refresh table";
|
||||
updateMainTab();
|
||||
} else if (action == startProfile) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Start profile";
|
||||
mainTabStartProfile();
|
||||
} else if (action == restartProfile) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Restart profile";
|
||||
mainTabRestartProfile();
|
||||
} else if (action == enableProfile) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Enable profile";
|
||||
mainTabEnableProfile();
|
||||
} else if (action == editProfile) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Edit profile";
|
||||
mainTabEditProfile();
|
||||
} else if (action == removeProfile) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Remove profile";
|
||||
mainTabRemoveProfile();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabEditProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
mainWindow->setTab(1);
|
||||
mainWindow->openProfileSlot(profile);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabEnableProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
mainWindow->showMessage(mainWindow->enableProfileSlot(profile));
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
|
||||
|
||||
QStringList MainWidget::mainTabGetActiveProfiles()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QStringList profiles;
|
||||
for (int i=0; i<ui->tableWidget_main->rowCount(); i++) {
|
||||
if (ui->tableWidget_main->item(i, 2)->text().isEmpty()) continue;
|
||||
profiles.append(ui->tableWidget_main->item(i, 0)->text());
|
||||
}
|
||||
|
||||
return profiles;
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabRemoveProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return mainTabRemoveProfile();
|
||||
}
|
||||
status = responce[0].toBool();
|
||||
} else
|
||||
status = netctlProfile->removeProfile(profile);
|
||||
mainWindow->showMessage(status);
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabRestartProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
mainWindow->showMessage(mainWindow->restartProfileSlot(profile));
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabStartProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
mainWindow->showMessage(mainWindow->startProfileSlot(profile));
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabStopAllProfiles()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToCtrl(QString("StolAll"), debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return mainTabStopAllProfiles();
|
||||
}
|
||||
status = responce[0].toBool();
|
||||
} else
|
||||
status = netctlCommand->stopAllProfiles();
|
||||
mainWindow->showMessage(status);
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::mainTabSwitchToProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("netctl"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
if (ui->tableWidget_main->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
mainWindow->showMessage(mainWindow->switchToProfileSlot(profile));
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::createActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// main tab events
|
||||
connect(ui->pushButton_netctlAuto, SIGNAL(clicked(bool)), this, SLOT(showNetctlAutoWindow()));
|
||||
connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile()));
|
||||
connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
|
||||
this, SLOT(updateMenuMain()));
|
||||
connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint)));
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::createObjects()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// backend
|
||||
netctlCommand = new Netctl(debug, configuration);
|
||||
netctlProfile = new NetctlProfile(debug, configuration);
|
||||
// windows
|
||||
ui = new Ui::MainWidget;
|
||||
ui->setupUi(this);
|
||||
ui->tableWidget_main->setColumnHidden(2, true);
|
||||
ui->tableWidget_main->setColumnHidden(3, true);
|
||||
netctlAutoWin = new NetctlAutoWindow(this, debug, configuration);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::createToolBars()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
actionToolBar = new QToolBar(this);
|
||||
actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
toolBarActions[QString("netctlAuto")] = actionToolBar->addAction(QApplication::translate("MainWidget", "netctl-auto"),
|
||||
this, SLOT(showNetctlAutoWindow()));
|
||||
toolBarActions[QString("mainRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("MainWidget", "Refresh"),
|
||||
this, SLOT(updateMainTab()));
|
||||
|
||||
actionMenu = new QToolButton(this);
|
||||
actionMenu->setPopupMode(QToolButton::DelayedPopup);
|
||||
actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
QMenu *menu = new QMenu(actionMenu);
|
||||
toolBarActions[QString("mainStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("MainWidget", "Start"),
|
||||
this, SLOT(mainTabStartProfile()));
|
||||
toolBarActions[QString("mainSwitch")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("MainWidget", "Switch"),
|
||||
this, SLOT(mainTabSwitchToProfile()));
|
||||
toolBarActions[QString("mainRestart")] = menu->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("MainWidget", "Restart"),
|
||||
this, SLOT(mainTabRestartProfile()));
|
||||
toolBarActions[QString("mainEnable")] = menu->addAction(QIcon::fromTheme(QString("list-add")),
|
||||
QApplication::translate("MainWidget", "Enable"),
|
||||
this, SLOT(mainTabEnableProfile()));
|
||||
toolBarActions[QString("mainStopAll")] = menu->addAction(QIcon::fromTheme(QString("process-stop")),
|
||||
QApplication::translate("MainWidget", "Stop all"),
|
||||
this, SLOT(mainTabStopAllProfiles()));
|
||||
actionMenu->setMenu(menu);
|
||||
actionToolBar->addWidget(actionMenu);
|
||||
|
||||
toolBarActions[QString("mainEdit")] = actionToolBar->addAction(QIcon::fromTheme(QString("document-edit")),
|
||||
QApplication::translate("MainWidget", "Edit"),
|
||||
this, SLOT(mainTabEditProfile()));
|
||||
toolBarActions[QString("mainRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")),
|
||||
QApplication::translate("MainWidget", "Remove"),
|
||||
this, SLOT(mainTabRemoveProfile()));
|
||||
|
||||
actionMenu->setDefaultAction(toolBarActions[QString("mainStart")]);
|
||||
ui->verticalLayout->insertWidget(0, actionToolBar);
|
||||
}
|
||||
|
||||
|
||||
void MainWidget::deleteObjects()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (netctlCommand != nullptr) delete netctlCommand;
|
||||
if (netctlProfile != nullptr) delete netctlProfile;
|
||||
|
||||
if (netctlAutoWin != nullptr) delete netctlAutoWin;
|
||||
if (actionMenu != nullptr) {
|
||||
actionMenu->menu()->clear();
|
||||
delete actionMenu;
|
||||
}
|
||||
if (actionToolBar != nullptr) {
|
||||
actionToolBar->clear();
|
||||
delete actionToolBar;
|
||||
}
|
||||
if (ui != nullptr) delete ui;
|
||||
}
|
88
sources/gui/src/mainwidget.h
Normal file
88
sources/gui/src/mainwidget.h
Normal file
@ -0,0 +1,88 @@
|
||||
/***************************************************************************
|
||||
* 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 MAINWIDGET_H
|
||||
#define MAINWIDGET_H
|
||||
|
||||
#include <QTableWidgetItem>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
class NetctlAutoWindow;
|
||||
|
||||
namespace Ui {
|
||||
class MainWidget;
|
||||
}
|
||||
|
||||
class MainWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWidget(QWidget *parent = 0,
|
||||
const QMap<QString,QString> settings = QMap<QString,QString>(),
|
||||
const bool debugCmd = false);
|
||||
~MainWidget();
|
||||
|
||||
public slots:
|
||||
void showNetctlAutoWindow();
|
||||
void update();
|
||||
|
||||
private slots:
|
||||
// update slots
|
||||
void updateMenuMain();
|
||||
void updateMainTab();
|
||||
// main tab slots
|
||||
void mainTabContextualMenu(const QPoint &pos);
|
||||
void mainTabEditProfile();
|
||||
void mainTabEnableProfile();
|
||||
QStringList mainTabGetActiveProfiles();
|
||||
void mainTabRemoveProfile();
|
||||
void mainTabRestartProfile();
|
||||
void mainTabStartProfile();
|
||||
void mainTabStopAllProfiles();
|
||||
void mainTabSwitchToProfile();
|
||||
|
||||
private:
|
||||
// ui
|
||||
QMap<QString, QAction *> toolBarActions;
|
||||
QToolButton *actionMenu = nullptr;
|
||||
QToolBar *actionToolBar = nullptr;
|
||||
MainWindow *mainWindow = nullptr;
|
||||
Ui::MainWidget *ui = nullptr;
|
||||
NetctlAutoWindow *netctlAutoWin = nullptr;
|
||||
// backend
|
||||
Netctl *netctlCommand = nullptr;
|
||||
NetctlProfile *netctlProfile = nullptr;
|
||||
void createActions();
|
||||
void createObjects();
|
||||
void createToolBars();
|
||||
void deleteObjects();
|
||||
QString configPath;
|
||||
bool debug = false;
|
||||
bool useHelper = true;
|
||||
// configuration
|
||||
QMap<QString, QString> configuration;
|
||||
};
|
||||
|
||||
|
||||
#endif /* MAINWIDGET_H */
|
93
sources/gui/src/mainwidget.ui
Normal file
93
sources/gui/src/mainwidget.ui
Normal file
@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWidget</class>
|
||||
<widget class="QWidget" name="MainWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>516</width>
|
||||
<height>477</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_netctlAuto" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_netctlAuto">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_netctlAuto">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>netctl-auto is running</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_netctlAuto">
|
||||
<property name="text">
|
||||
<string>Show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_main">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -21,32 +21,29 @@
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
#include <QDebug>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QFileInfo>
|
||||
#include <QLibraryInfo>
|
||||
#include <QTranslator>
|
||||
#include <QUrl>
|
||||
|
||||
#include <language/language.h>
|
||||
#include <pdebug/pdebug.h>
|
||||
#include <task/taskadds.h>
|
||||
|
||||
#include "aboutwindow.h"
|
||||
#include "bridgewidget.h"
|
||||
#include "commonfunctions.h"
|
||||
#include "dbusoperation.h"
|
||||
#include "errorwindow.h"
|
||||
#include "ethernetwidget.h"
|
||||
#include "generalwidget.h"
|
||||
#include "ipwidget.h"
|
||||
#include "macvlanwidget.h"
|
||||
#include "mobilewidget.h"
|
||||
#include "netctlautowindow.h"
|
||||
#include "mainwidget.h"
|
||||
#include "netctlguiadaptor.h"
|
||||
#include "newprofilewidget.h"
|
||||
#include "passwdwidget.h"
|
||||
#include "pppoewidget.h"
|
||||
#include "settingswindow.h"
|
||||
#include "trayicon.h"
|
||||
#include "tunnelwidget.h"
|
||||
#include "tuntapwidget.h"
|
||||
#include "version.h"
|
||||
#include "vlanwidget.h"
|
||||
#include "wirelesswidget.h"
|
||||
#include "wifimenuwidget.h"
|
||||
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent,
|
||||
@ -76,22 +73,22 @@ MainWindow::MainWindow(QWidget *parent,
|
||||
updateConfiguration(args);
|
||||
|
||||
// main actions
|
||||
if (args[QString("essid")].toString() != QString("ESSID")) {
|
||||
for (int i=0; i<ui->tableWidget_wifi->rowCount(); i++)
|
||||
if (ui->tableWidget_wifi->item(i, 0)->text() == args[QString("essid")].toString())
|
||||
ui->tableWidget_wifi->setCurrentCell(i, 0);
|
||||
if (ui->tableWidget_wifi->currentItem() == nullptr)
|
||||
ErrorWindow::showWindow(18, QString(PDEBUG), debug);
|
||||
} else if (args[QString("open")].toString() != QString("PROFILE")) {
|
||||
ui->comboBox_profile->addItem(args[QString("open")].toString());
|
||||
ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count()-1);
|
||||
} else if (args[QString("select")].toString() != QString("PROFILE")) {
|
||||
for (int i=0; i<ui->tableWidget_main->rowCount(); i++)
|
||||
if (ui->tableWidget_main->item(i, 0)->text() == args[QString("select")].toString())
|
||||
ui->tableWidget_main->setCurrentCell(i, 0);
|
||||
if (ui->tableWidget_main->currentItem() == nullptr)
|
||||
ErrorWindow::showWindow(17, QString(PDEBUG), debug);
|
||||
}
|
||||
// if (args[QString("essid")].toString() != QString("ESSID")) {
|
||||
// for (int i=0; i<ui->tableWidget_wifi->rowCount(); i++)
|
||||
// if (ui->tableWidget_wifi->item(i, 0)->text() == args[QString("essid")].toString())
|
||||
// ui->tableWidget_wifi->setCurrentCell(i, 0);
|
||||
// if (ui->tableWidget_wifi->currentItem() == nullptr)
|
||||
// ErrorWindow::showWindow(18, QString(PDEBUG), debug);
|
||||
// } else if (args[QString("open")].toString() != QString("PROFILE")) {
|
||||
// ui->comboBox_profile->addItem(args[QString("open")].toString());
|
||||
// ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count()-1);
|
||||
// } else if (args[QString("select")].toString() != QString("PROFILE")) {
|
||||
// for (int i=0; i<ui->tableWidget_main->rowCount(); i++)
|
||||
// if (ui->tableWidget_main->item(i, 0)->text() == args[QString("select")].toString())
|
||||
// ui->tableWidget_main->setCurrentCell(i, 0);
|
||||
// if (ui->tableWidget_main->currentItem() == nullptr)
|
||||
// ErrorWindow::showWindow(17, QString(PDEBUG), debug);
|
||||
// }
|
||||
|
||||
// show windows
|
||||
if (args[QString("about")].toBool())
|
||||
@ -271,38 +268,237 @@ void MainWindow::closeEvent(QCloseEvent *event)
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::checkExternalApps(const QString apps = QString("all"))
|
||||
// tray icon
|
||||
void MainWindow::closeMainWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Applications" << apps;
|
||||
|
||||
if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true;
|
||||
QStringList cmd;
|
||||
cmd.append("which");
|
||||
// avoid null-lines arguments
|
||||
cmd.append("true");
|
||||
if ((apps == QString("helper")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("HELPER_PATH")]);
|
||||
}
|
||||
if ((apps == QString("netctl")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("NETCTL_PATH")]);
|
||||
cmd.append(configuration[QString("NETCTLAUTO_PATH")]);
|
||||
cmd.append(configuration[QString("SUDO_PATH")]);
|
||||
}
|
||||
if ((apps == QString("sudo")) || (apps == QString("wpasup")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("SUDO_PATH")]);
|
||||
}
|
||||
if ((apps == QString("systemctl")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("SYSTEMCTL_PATH")]);
|
||||
cmd.append(configuration[QString("SUDO_PATH")]);
|
||||
}
|
||||
if ((apps == QString("wpasup")) || (apps == QString("wpasup-only")) || (apps == QString("all"))) {
|
||||
cmd.append(configuration[QString("WPACLI_PATH")]);
|
||||
cmd.append(configuration[QString("WPASUP_PATH")]);
|
||||
qApp->quit();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showAboutWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
aboutWin->show();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showMainWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (isHidden()) {
|
||||
updateTabs(ui->stackedWidget->currentIndex());
|
||||
show();
|
||||
} else
|
||||
hide();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showNetctlAutoWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
mainWidget->showNetctlAutoWindow();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showSettingsWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
settingsWin->showWindow();
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::enableProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Enable"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileEnabled"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->enableProfile(profile);
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
}
|
||||
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd.join(QChar(' '));
|
||||
TaskResult process = runTask(cmd.join(QChar(' ')), false);
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::openProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
newProfileWidget->profileTabOpenProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::restartProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Restart"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->restartProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::startProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToLib(QString("ActiveProfile"), debug);
|
||||
QStringList currentProfile;
|
||||
if (!responce.isEmpty()) currentProfile = responce[0].toString().split(QChar('|'));
|
||||
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
|
||||
sendRequestToCtrlWithArgs(QString("Start"), args, debug);
|
||||
else
|
||||
sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug);
|
||||
responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
QStringList currentProfile = netctlCommand->getActiveProfile();
|
||||
if ((currentProfile.isEmpty()) || (currentProfile.contains(profile)))
|
||||
netctlCommand->startProfile(profile);
|
||||
else
|
||||
netctlCommand->switchToProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::stopAllProfilesSlot()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (useHelper)
|
||||
sendRequestToCtrl(QString("StolAll"), debug);
|
||||
else
|
||||
netctlCommand->stopAllProfiles();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::switchToProfileSlot(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Profile" << profile;
|
||||
|
||||
bool netctlAutoStatus = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToLib(QString("isNetctlAutoActive"), debug);
|
||||
if (!responce.isEmpty()) netctlAutoStatus = responce[0].toBool();
|
||||
} else
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
|
||||
bool current;
|
||||
if (netctlAutoStatus) {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("autoStart"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("autoIsProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->autoStartProfile(profile);
|
||||
current = netctlCommand->autoIsProfileActive(profile);
|
||||
}
|
||||
} else {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("SwitchTo"), args, debug);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("isProfileActive"), args, debug);
|
||||
if (responce.isEmpty())
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
else
|
||||
current = responce[0].toBool();
|
||||
} else {
|
||||
netctlCommand->switchToProfile(profile);
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
}
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showApi()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
showMessage(QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-dbus-api.html").arg(QString(DOCS_PATH)))));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showLibrary()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
showMessage(QDesktopServices::openUrl(QUrl(QString("%1html/index.html").arg(QString(DOCS_PATH)))));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showSecurityNotes()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
showMessage(QDesktopServices::openUrl(QUrl(QString("%1netctl-gui-security-notes.html").arg(QString(DOCS_PATH)))));
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::forceStartHelper()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("helper"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(needToBeConfigured());
|
||||
return false;
|
||||
}
|
||||
|
||||
QString cmd = QString("%1 -c %2").arg(configuration[QString("HELPER_PATH")]).arg(configPath);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Run cmd" << cmd;
|
||||
TaskResult process = runTask(cmd, false);
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Cmd returns" << process.exitCode;
|
||||
if (process.exitCode != 0)
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Error" << process.error;
|
||||
@ -311,6 +507,166 @@ bool MainWindow::checkExternalApps(const QString apps = QString("all"))
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::forceStopHelper()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QList<QVariant> responce = sendRequestToCtrl(QString("Close"), debug);
|
||||
|
||||
return !responce.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
bool MainWindow::startHelper()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (isHelperActive())
|
||||
return forceStopHelper();
|
||||
else
|
||||
return forceStartHelper();
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setDisabled(const bool disabled)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->toolBar->setDisabled(disabled);
|
||||
ui->stackedWidget->setDisabled(disabled);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setTab(int tab)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Set tab" << tab;
|
||||
|
||||
if ((tab > 2) || (tab < 0)) tab = 0;
|
||||
if (tab == ui->stackedWidget->currentIndex())
|
||||
updateTabs(tab);
|
||||
else
|
||||
ui->stackedWidget->setCurrentIndex(tab);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::showMessage(const bool status)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Status" << status;
|
||||
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
deleteObjects();
|
||||
|
||||
settingsWin = new SettingsWindow(this, debug, configPath);
|
||||
if (args[QString("default")].toBool())
|
||||
settingsWin->setDefault();
|
||||
configuration = settingsWin->getSettings();
|
||||
delete settingsWin;
|
||||
QMap<QString, QString> optionsDict = parseOptions(args[QString("options")].toString());
|
||||
for (int i=0; i<optionsDict.keys().count(); i++)
|
||||
configuration[optionsDict.keys()[i]] = optionsDict[optionsDict.keys()[i]];
|
||||
if ((configuration[QString("USE_HELPER")] == QString("true")) &&
|
||||
(checkExternalApps(QString("helper"), configuration, debug)))
|
||||
useHelper = true;
|
||||
else {
|
||||
useHelper = false;
|
||||
configuration[QString("USE_HELPER")] = QString("false");
|
||||
}
|
||||
|
||||
// update translation
|
||||
qApp->removeTranslator(translator);
|
||||
QString language = Language::defineLanguage(configPath, args[QString("options")].toString());
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Language is" << language;
|
||||
qtTranslator->load(QString("qt_%1").arg(language), QLibraryInfo::location(QLibraryInfo::TranslationsPath));
|
||||
qApp->installTranslator(qtTranslator);
|
||||
translator->load(QString(":/translations/%1").arg(language));
|
||||
qApp->installTranslator(translator);
|
||||
|
||||
createObjects();
|
||||
createActions();
|
||||
|
||||
// tray
|
||||
trayIcon->setVisible(QSystemTrayIcon::isSystemTrayAvailable() && (configuration[QString("SYSTRAY")] == QString("true")));
|
||||
if (trayIcon->isVisible()) {
|
||||
setHidden(configuration[QString("STARTTOTRAY")] == QString("true"));
|
||||
if (args[QString("minimized")].toInt() == 1)
|
||||
show();
|
||||
else if (args[QString("minimized")].toInt() == 2)
|
||||
hide();
|
||||
}
|
||||
else
|
||||
show();
|
||||
|
||||
// update ui
|
||||
setTab(args[QString("tab")].toInt() - 1);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::updateTabs(const int tab)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Update tab" << tab;
|
||||
|
||||
switch (tab) {
|
||||
case 1:
|
||||
newProfileWidget->update();
|
||||
break;
|
||||
case 2:
|
||||
wifiMenuWidget->update();
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
mainWidget->update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// private slots
|
||||
void MainWindow::setMainTab()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return setTab(0);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setProfileTab()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return setTab(1);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::setWifiTab()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
return setTab(2);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::reportABug()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
showMessage(QDesktopServices::openUrl(QUrl(QString(BUGTRACKER))));
|
||||
}
|
||||
|
||||
|
||||
// window signals
|
||||
bool MainWindow::checkHelperStatus()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -327,25 +683,14 @@ bool MainWindow::checkHelperStatus()
|
||||
}
|
||||
|
||||
|
||||
QString MainWindow::checkStatus(const bool statusBool, const bool nullFalse)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Status" << statusBool;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Return null on false" << nullFalse;
|
||||
|
||||
if (statusBool) return QApplication::translate("MainWindow", "yes");
|
||||
if (!nullFalse) return QApplication::translate("MainWindow", "no");
|
||||
|
||||
return QString("");
|
||||
}
|
||||
|
||||
|
||||
// window signals
|
||||
void MainWindow::createActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
connect(ui->tabWidget, SIGNAL(currentChanged(int)), this, SLOT(updateTabs(int)));
|
||||
connect(ui->actionConnect_to_profile, SIGNAL(triggered()), this, SLOT(setMainTab()));
|
||||
connect(ui->actionCreate_a_new_profile, SIGNAL(triggered()), this, SLOT(setProfileTab()));
|
||||
connect(ui->actionWiFi_menu, SIGNAL(triggered()), this, SLOT(setWifiTab()));
|
||||
connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(setTab(int)));
|
||||
connect(this, SIGNAL(needToBeConfigured()), this, SLOT(showSettingsWindow()));
|
||||
|
||||
// menu
|
||||
@ -356,25 +701,6 @@ void MainWindow::createActions()
|
||||
connect(ui->actionReport_a_bug, SIGNAL(triggered()), this, SLOT(reportABug()));
|
||||
connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAboutWindow()));
|
||||
connect(ui->actionQuit, SIGNAL(triggered()), this, SLOT(closeMainWindow()));
|
||||
|
||||
// main tab events
|
||||
connect(ui->pushButton_netctlAuto, SIGNAL(clicked(bool)), this, SLOT(showNetctlAutoWindow()));
|
||||
connect(ui->tableWidget_main, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(mainTabStartProfile()));
|
||||
connect(ui->tableWidget_main, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
|
||||
this, SLOT(updateMenuMain()));
|
||||
connect(ui->tableWidget_main, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(mainTabContextualMenu(QPoint)));
|
||||
|
||||
// profile tab events
|
||||
connect(ui->comboBox_profile, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabLoadProfile()));
|
||||
connect(ui->comboBox_profile, SIGNAL(editTextChanged(QString)), this, SLOT(updateMenuProfile()));
|
||||
connect(ui->comboBox_profile->lineEdit(), SIGNAL(returnPressed()), this, SLOT(profileTabLoadProfile()));
|
||||
connect(generalWid->connectionType, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabChangeState(QString)));
|
||||
|
||||
// wifi tab events
|
||||
connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart()));
|
||||
connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
|
||||
this, SLOT(updateMenuWifi()));
|
||||
connect(ui->tableWidget_wifi, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(wifiTabContextualMenu(QPoint)));
|
||||
}
|
||||
|
||||
|
||||
@ -409,107 +735,19 @@ void MainWindow::createObjects()
|
||||
checkHelperStatus();
|
||||
|
||||
netctlCommand = new Netctl(debug, configuration);
|
||||
netctlProfile = new NetctlProfile(debug, configuration);
|
||||
wpaCommand = new WpaSup(debug, configuration);
|
||||
// frontend
|
||||
mainWidget = new MainWidget(this, configuration, debug);
|
||||
newProfileWidget = new NewProfileWidget(this, configuration, debug);
|
||||
wifiMenuWidget = new WiFiMenuWidget(this, configuration, debug);
|
||||
trayIcon = new TrayIcon(this, debug);
|
||||
// windows
|
||||
ui = new Ui::MainWindow;
|
||||
ui->setupUi(this);
|
||||
ui->tableWidget_main->setColumnHidden(2, true);
|
||||
ui->tableWidget_main->setColumnHidden(3, true);
|
||||
ui->tableWidget_wifi->setColumnHidden(5, true);
|
||||
ui->tableWidget_wifi->setColumnHidden(6, true);
|
||||
ui->layout_main->addWidget(mainWidget);
|
||||
ui->layout_new->addWidget(newProfileWidget);
|
||||
ui->layout_wifi->addWidget(wifiMenuWidget);
|
||||
aboutWin = new AboutWindow(this, debug);
|
||||
netctlAutoWin = new NetctlAutoWindow(this, debug, configuration);
|
||||
settingsWin = new SettingsWindow(this, debug, configPath);
|
||||
// profile widgets
|
||||
generalWid = new GeneralWidget(this, configuration);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(generalWid);
|
||||
ipWid = new IpWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(ipWid);
|
||||
bridgeWid = new BridgeWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid);
|
||||
ethernetWid = new EthernetWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid);
|
||||
macvlanWid = new MacvlanWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid);
|
||||
mobileWid = new MobileWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid);
|
||||
pppoeWid = new PppoeWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(pppoeWid);
|
||||
tunnelWid = new TunnelWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(tunnelWid);
|
||||
tuntapWid = new TuntapWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid);
|
||||
vlanWid = new VlanWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid);
|
||||
wirelessWid = new WirelessWidget(this, configuration);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::createToolBars()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
actionToolBar = new QToolBar(this);
|
||||
actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
toolBarActions[QString("netctlAuto")] = actionToolBar->addAction(QApplication::translate("MainWindow", "netctl-auto"),
|
||||
this, SLOT(showNetctlAutoWindow()));
|
||||
toolBarActions[QString("mainRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("MainWindow", "Refresh"),
|
||||
this, SLOT(updateMainTab()));
|
||||
toolBarActions[QString("profileClear")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-clear")),
|
||||
QApplication::translate("MainWindow", "Clear"),
|
||||
this, SLOT(profileTabClear()));
|
||||
toolBarActions[QString("wifiRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("MainWindow", "Refresh"),
|
||||
this, SLOT(updateWifiTab()));
|
||||
|
||||
actionMenu = new QToolButton(this);
|
||||
actionMenu->setPopupMode(QToolButton::DelayedPopup);
|
||||
actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
QMenu *menu = new QMenu(actionMenu);
|
||||
toolBarActions[QString("mainStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("MainWindow", "Start"),
|
||||
this, SLOT(mainTabStartProfile()));
|
||||
toolBarActions[QString("mainSwitch")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("MainWindow", "Switch"),
|
||||
this, SLOT(mainTabSwitchToProfile()));
|
||||
toolBarActions[QString("mainRestart")] = menu->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("MainWindow", "Restart"),
|
||||
this, SLOT(mainTabRestartProfile()));
|
||||
toolBarActions[QString("mainEnable")] = menu->addAction(QIcon::fromTheme(QString("list-add")),
|
||||
QApplication::translate("MainWindow", "Enable"),
|
||||
this, SLOT(mainTabEnableProfile()));
|
||||
toolBarActions[QString("mainStopAll")] = menu->addAction(QIcon::fromTheme(QString("process-stop")),
|
||||
QApplication::translate("MainWindow", "Stop all"),
|
||||
this, SLOT(mainTabStopAllProfiles()));
|
||||
toolBarActions[QString("profileLoad")] = menu->addAction(QIcon::fromTheme(QString("document-open")),
|
||||
QApplication::translate("MainWindow", "Load"),
|
||||
this, SLOT(profileTabLoadProfile()));
|
||||
toolBarActions[QString("profileSave")] = menu->addAction(QIcon::fromTheme(QString("document-save")),
|
||||
QApplication::translate("MainWindow", "Save"),
|
||||
this, SLOT(profileTabCreateProfile()));
|
||||
toolBarActions[QString("wifiStart")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("MainWindow", "Start"),
|
||||
this, SLOT(wifiTabStart()));
|
||||
actionMenu->setMenu(menu);
|
||||
actionToolBar->addWidget(actionMenu);
|
||||
|
||||
toolBarActions[QString("mainEdit")] = actionToolBar->addAction(QIcon::fromTheme(QString("document-edit")),
|
||||
QApplication::translate("MainWindow", "Edit"),
|
||||
this, SLOT(mainTabEditProfile()));
|
||||
toolBarActions[QString("mainRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")),
|
||||
QApplication::translate("MainWindow", "Remove"),
|
||||
this, SLOT(mainTabRemoveProfile()));
|
||||
toolBarActions[QString("profileRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")),
|
||||
QApplication::translate("MainWindow", "Remove"),
|
||||
this, SLOT(profileTabRemoveProfile()));
|
||||
|
||||
setMenuActionsShown(false);
|
||||
ui->centralLayout->insertWidget(0, actionToolBar);
|
||||
}
|
||||
|
||||
|
||||
@ -520,33 +758,13 @@ void MainWindow::deleteObjects()
|
||||
QDBusConnection::sessionBus().unregisterObject(DBUS_OBJECT_PATH);
|
||||
QDBusConnection::sessionBus().unregisterService(DBUS_SERVICE);
|
||||
if (netctlCommand != nullptr) delete netctlCommand;
|
||||
if (netctlProfile != nullptr) delete netctlProfile;
|
||||
if (wpaCommand != nullptr) delete wpaCommand;
|
||||
|
||||
if (bridgeWid != nullptr) delete bridgeWid;
|
||||
if (ethernetWid != nullptr) delete ethernetWid;
|
||||
if (generalWid != nullptr) delete generalWid;
|
||||
if (ipWid != nullptr) delete ipWid;
|
||||
if (macvlanWid != nullptr) delete macvlanWid;
|
||||
if (mobileWid != nullptr) delete mobileWid;
|
||||
if (pppoeWid != nullptr) delete pppoeWid;
|
||||
if (tunnelWid != nullptr) delete tunnelWid;
|
||||
if (tuntapWid != nullptr) delete tuntapWid;
|
||||
if (vlanWid != nullptr) delete vlanWid;
|
||||
if (wirelessWid != nullptr) delete wirelessWid;
|
||||
|
||||
if (aboutWin != nullptr) delete aboutWin;
|
||||
if (netctlAutoWin != nullptr) delete netctlAutoWin;
|
||||
if (settingsWin != nullptr) delete settingsWin;
|
||||
if (actionMenu != nullptr) {
|
||||
actionMenu->menu()->clear();
|
||||
delete actionMenu;
|
||||
}
|
||||
if (actionToolBar != nullptr) {
|
||||
actionToolBar->clear();
|
||||
delete actionToolBar;
|
||||
}
|
||||
if (trayIcon != nullptr) delete trayIcon;
|
||||
if (mainWidget != nullptr) delete mainWidget;
|
||||
if (newProfileWidget != nullptr) delete newProfileWidget;
|
||||
if (wifiMenuWidget != nullptr) delete wifiMenuWidget;
|
||||
if (ui != nullptr) delete ui;
|
||||
}
|
||||
|
||||
|
@ -20,29 +20,17 @@
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
class AboutWindow;
|
||||
class BridgeWidget;
|
||||
class EthernetWidget;
|
||||
class GeneralWidget;
|
||||
class IpWidget;
|
||||
class MacvlanWidget;
|
||||
class MobileWidget;
|
||||
class NetctlAutoWindow;
|
||||
class PasswdWidget;
|
||||
class PppoeWidget;
|
||||
class MainWidget;
|
||||
class NewProfileWidget;
|
||||
class SettingsWindow;
|
||||
class TrayIcon;
|
||||
class TunnelWidget;
|
||||
class TuntapWidget;
|
||||
class VlanWidget;
|
||||
class WirelessWidget;
|
||||
class WiFiMenuWidget;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
@ -76,6 +64,7 @@ public slots:
|
||||
void showSettingsWindow();
|
||||
// trayicon control slots
|
||||
bool enableProfileSlot(const QString profile);
|
||||
void openProfileSlot(const QString profile);
|
||||
bool startProfileSlot(const QString profile);
|
||||
bool stopAllProfilesSlot();
|
||||
bool switchToProfileSlot(const QString profile);
|
||||
@ -89,86 +78,39 @@ public slots:
|
||||
bool forceStopHelper();
|
||||
bool startHelper();
|
||||
// main
|
||||
void setDisabled(const bool disabled = true);
|
||||
void setTab(int tab);
|
||||
void showMessage(const bool status);
|
||||
void updateConfiguration(const QMap<QString, QVariant> args = QMap<QString, QVariant>());
|
||||
void updateMenu();
|
||||
void updateTabs(const int tab);
|
||||
// wifi tab slots
|
||||
void connectToUnknownEssid(const QString passwd);
|
||||
void setHiddenName(const QString name);
|
||||
|
||||
signals:
|
||||
void needToBeConfigured();
|
||||
|
||||
private slots:
|
||||
void setMainTab();
|
||||
void setProfileTab();
|
||||
void setWifiTab();
|
||||
void reportABug();
|
||||
// menu update slots
|
||||
void setMenuActionsShown(const bool state = true);
|
||||
void updateMenuMain();
|
||||
void updateMenuProfile();
|
||||
void updateMenuWifi();
|
||||
// tab update slots
|
||||
void updateMainTab();
|
||||
void updateProfileTab();
|
||||
void updateWifiTab();
|
||||
// main tab slots
|
||||
void mainTabContextualMenu(const QPoint &pos);
|
||||
void mainTabEditProfile();
|
||||
void mainTabEnableProfile();
|
||||
QStringList mainTabGetActiveProfiles();
|
||||
void mainTabRemoveProfile();
|
||||
void mainTabRestartProfile();
|
||||
void mainTabStartProfile();
|
||||
void mainTabStopAllProfiles();
|
||||
void mainTabSwitchToProfile();
|
||||
// profile tab slots
|
||||
void profileTabChangeState(const QString current);
|
||||
void profileTabClear();
|
||||
void profileTabCreateProfile();
|
||||
void profileTabLoadProfile();
|
||||
void profileTabRemoveProfile();
|
||||
// wifi tab slots
|
||||
void wifiTabContextualMenu(const QPoint &pos);
|
||||
void wifiTabSetEnabled(const bool state);
|
||||
void wifiTabStart();
|
||||
|
||||
private:
|
||||
// ui
|
||||
TrayIcon *trayIcon = nullptr;
|
||||
QMap<QString, QAction *> toolBarActions;
|
||||
QToolButton *actionMenu = nullptr;
|
||||
QToolBar *actionToolBar = nullptr;
|
||||
Ui::MainWindow *ui = nullptr;
|
||||
AboutWindow *aboutWin = nullptr;
|
||||
NetctlAutoWindow *netctlAutoWin = nullptr;
|
||||
PasswdWidget *passwdWid = nullptr;
|
||||
MainWidget *mainWidget = nullptr;
|
||||
NewProfileWidget *newProfileWidget = nullptr;
|
||||
SettingsWindow *settingsWin = nullptr;
|
||||
BridgeWidget *bridgeWid = nullptr;
|
||||
EthernetWidget *ethernetWid = nullptr;
|
||||
GeneralWidget *generalWid = nullptr;
|
||||
IpWidget *ipWid = nullptr;
|
||||
MacvlanWidget *macvlanWid = nullptr;
|
||||
MobileWidget *mobileWid = nullptr;
|
||||
PppoeWidget *pppoeWid = nullptr;
|
||||
TunnelWidget *tunnelWid = nullptr;
|
||||
TuntapWidget *tuntapWid = nullptr;
|
||||
VlanWidget *vlanWid = nullptr;
|
||||
WirelessWidget *wirelessWid = nullptr;
|
||||
WiFiMenuWidget *wifiMenuWidget = nullptr;
|
||||
// backend
|
||||
Netctl *netctlCommand = nullptr;
|
||||
NetctlProfile *netctlProfile = nullptr;
|
||||
WpaSup *wpaCommand = nullptr;
|
||||
bool checkExternalApps(const QString apps);
|
||||
bool checkHelperStatus();
|
||||
QString checkStatus(const bool statusBool, const bool nullFalse = false);
|
||||
void createActions();
|
||||
void createDBusSession();
|
||||
void createObjects();
|
||||
void createToolBars();
|
||||
void deleteObjects();
|
||||
QString configPath;
|
||||
bool debug = false;
|
||||
bool hiddenNetwork;
|
||||
bool useHelper = true;
|
||||
QTranslator *qtTranslator = nullptr;
|
||||
QTranslator *translator = nullptr;
|
||||
|
@ -16,261 +16,21 @@
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QVBoxLayout" name="centralLayout">
|
||||
<item>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<widget class="QStackedWidget" name="stackedWidget">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab_main">
|
||||
<attribute name="icon">
|
||||
<iconset resource="../../resources/resources.qrc">
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>Connect to profile</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_netctlAuto" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_netctlAuto">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_netctlAuto">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>netctl-auto is running</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_netctlAuto">
|
||||
<property name="text">
|
||||
<string>Show</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_main">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Description</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QWidget" name="page_main">
|
||||
<layout class="QVBoxLayout" name="layout_main"/>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_new">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<attribute name="icon">
|
||||
<iconset theme="document-new">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>Create a new profile</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_profile">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_profile">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Profile</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_profile">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>518</width>
|
||||
<height>369</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="scrollArea_layout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QWidget" name="page_new">
|
||||
<layout class="QVBoxLayout" name="layout_new"/>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_wifi">
|
||||
<attribute name="icon">
|
||||
<iconset resource="../../resources/resources.qrc">
|
||||
<normaloff>:/wifi.png</normaloff>:/wifi.png</iconset>
|
||||
</attribute>
|
||||
<attribute name="title">
|
||||
<string>WiFi menu</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_wifi">
|
||||
<property name="text">
|
||||
<string>Please install 'wpa_supplicant' before using it</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_wifi">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>7</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string># of points</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Signal</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Security</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
<widget class="QWidget" name="page_wifi">
|
||||
<layout class="QVBoxLayout" name="layout_wifi"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
@ -303,6 +63,23 @@
|
||||
</widget>
|
||||
<addaction name="menuMenu"/>
|
||||
</widget>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="movable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonFollowStyle</enum>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionConnect_to_profile"/>
|
||||
<addaction name="actionCreate_a_new_profile"/>
|
||||
<addaction name="actionWiFi_menu"/>
|
||||
</widget>
|
||||
<action name="actionSecurity">
|
||||
<property name="icon">
|
||||
<iconset theme="security-medium">
|
||||
@ -369,13 +146,45 @@
|
||||
<string>Ctrl+S</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionConnect_to_profile">
|
||||
<property name="icon">
|
||||
<iconset resource="../../resources/resources.qrc">
|
||||
<normaloff>:/icon.png</normaloff>:/icon.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Connect to profile</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+P</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionCreate_a_new_profile">
|
||||
<property name="icon">
|
||||
<iconset theme="document-new"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Create a new profile</string>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Create a new profile</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+N</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionWiFi_menu">
|
||||
<property name="icon">
|
||||
<iconset resource="../../resources/resources.qrc">
|
||||
<normaloff>:/wifi.png</normaloff>:/wifi.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>WiFi menu</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+W</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>tableWidget_main</tabstop>
|
||||
<tabstop>scrollArea</tabstop>
|
||||
<tabstop>tableWidget_wifi</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="../../resources/resources.qrc"/>
|
||||
</resources>
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "dbusoperation.h"
|
||||
// #include "version.h"
|
||||
|
||||
|
||||
NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const QMap<QString, QString> settings)
|
||||
@ -38,7 +37,6 @@ NetctlAutoWindow::NetctlAutoWindow(QWidget *parent, const bool debugCmd, const Q
|
||||
ui->tableWidget->setColumnHidden(3, true);
|
||||
netctlCommand = new Netctl(debug, settings);
|
||||
|
||||
createToolBars();
|
||||
createActions();
|
||||
ui->statusBar->showMessage(QApplication::translate("NetctlAutoWindow", "Ready"));
|
||||
}
|
||||
@ -50,14 +48,6 @@ NetctlAutoWindow::~NetctlAutoWindow()
|
||||
|
||||
delete netctlCommand;
|
||||
|
||||
if (actionMenu != nullptr) {
|
||||
actionMenu->menu()->clear();
|
||||
delete actionMenu;
|
||||
}
|
||||
if (actionToolBar != nullptr) {
|
||||
actionToolBar->clear();
|
||||
delete actionToolBar;
|
||||
}
|
||||
delete ui;
|
||||
}
|
||||
|
||||
@ -85,6 +75,7 @@ void NetctlAutoWindow::createActions()
|
||||
connect(ui->actionEnable, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableProfile()));
|
||||
connect(ui->actionEnableAll, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableAllProfiles()));
|
||||
connect(ui->actionSwitch, SIGNAL(triggered(bool)), this, SLOT(netctlAutoStartProfile()));
|
||||
connect(ui->actionRefresh, SIGNAL(triggered(bool)), this, SLOT(netctlAutoUpdateTable()));
|
||||
// service
|
||||
connect(ui->actionEnableService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoEnableService()));
|
||||
connect(ui->actionRestartService, SIGNAL(triggered(bool)), this, SLOT(netctlAutoRestartService()));
|
||||
@ -97,32 +88,6 @@ void NetctlAutoWindow::createActions()
|
||||
}
|
||||
|
||||
|
||||
void NetctlAutoWindow::createToolBars()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
actionToolBar = new QToolBar(this);
|
||||
actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
toolBarActions[QString("refresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("NetctlAutoWindow", "Refresh"),
|
||||
this, SLOT(netctlAutoUpdateTable()));
|
||||
|
||||
actionMenu = new QToolButton(this);
|
||||
actionMenu->setPopupMode(QToolButton::DelayedPopup);
|
||||
actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
QMenu *menu = new QMenu(actionMenu);
|
||||
toolBarActions[QString("enable")] = menu->addAction(QApplication::translate("NetctlAutoWindow", "Enable"),
|
||||
this, SLOT(netctlAutoEnableProfile()));
|
||||
toolBarActions[QString("switch")] = menu->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("NetctlAutoWindow", "Switch"),
|
||||
this, SLOT(netctlAutoStartProfile()));
|
||||
actionMenu->setDefaultAction(toolBarActions[QString("switch")]);
|
||||
actionMenu->setMenu(menu);
|
||||
actionToolBar->addWidget(actionMenu);
|
||||
ui->centralLayout->insertWidget(0, actionToolBar);
|
||||
}
|
||||
|
||||
|
||||
void NetctlAutoWindow::showWindow()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
@ -477,31 +442,18 @@ void NetctlAutoWindow::netctlAutoRefreshButtons(QTableWidgetItem *current, QTabl
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (current == nullptr) {
|
||||
// buttons
|
||||
toolBarActions[QString("enable")]->setDisabled(true);
|
||||
toolBarActions[QString("switch")]->setDisabled(true);
|
||||
// menu
|
||||
ui->actionEnable->setVisible(false);
|
||||
ui->actionSwitch->setVisible(false);
|
||||
ui->actionEnable->setEnabled(false);
|
||||
ui->actionSwitch->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
toolBarActions[QString("switch")]->setEnabled(ui->tableWidget->item(current->row(), 2)->text().isEmpty());
|
||||
ui->actionSwitch->setVisible(ui->tableWidget->item(current->row(), 2)->text().isEmpty());
|
||||
toolBarActions[QString("enable")]->setEnabled(true);
|
||||
ui->actionEnable->setVisible(true);
|
||||
ui->actionSwitch->setEnabled(ui->tableWidget->item(current->row(), 2)->text().isEmpty());
|
||||
ui->actionEnable->setEnabled(true);
|
||||
if (!ui->tableWidget->item(current->row(), 3)->text().isEmpty()) {
|
||||
// buttons
|
||||
toolBarActions[QString("enable")]->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
|
||||
toolBarActions[QString("enable")]->setIcon(QIcon::fromTheme("list-add"));
|
||||
// menu
|
||||
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable profile"));
|
||||
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Enable"));
|
||||
ui->actionEnable->setIcon(QIcon::fromTheme("list-add"));
|
||||
} else {
|
||||
// buttons
|
||||
toolBarActions[QString("enable")]->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
|
||||
toolBarActions[QString("enable")]->setIcon(QIcon::fromTheme("edit-delete"));
|
||||
// menu
|
||||
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable profile"));
|
||||
ui->actionEnable->setText(QApplication::translate("NetctlAutoWindow", "Disable"));
|
||||
ui->actionEnable->setIcon(QIcon::fromTheme("edit-delete"));
|
||||
}
|
||||
}
|
||||
|
@ -18,11 +18,8 @@
|
||||
#ifndef NETCTLAUTOWINDOW_H
|
||||
#define NETCTLAUTOWINDOW_H
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMainWindow>
|
||||
#include <QTableWidgetItem>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
|
||||
|
||||
class Netctl;
|
||||
@ -61,15 +58,11 @@ private slots:
|
||||
|
||||
private:
|
||||
// ui
|
||||
QMap<QString, QAction *> toolBarActions;
|
||||
QToolButton *actionMenu = nullptr;
|
||||
QToolBar *actionToolBar = nullptr;
|
||||
Ui::NetctlAutoWindow *ui = nullptr;
|
||||
// backend
|
||||
Netctl *netctlCommand = nullptr;
|
||||
QString checkStatus(const bool statusBool, const bool nullFalse = false);
|
||||
void createActions();
|
||||
void createToolBars();
|
||||
bool debug = false;
|
||||
bool useHelper = true;
|
||||
};
|
||||
|
@ -64,6 +64,24 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<widget class="QToolBar" name="toolBar">
|
||||
<property name="movable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonFollowStyle</enum>
|
||||
</property>
|
||||
<attribute name="toolBarArea">
|
||||
<enum>TopToolBarArea</enum>
|
||||
</attribute>
|
||||
<attribute name="toolBarBreak">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<addaction name="actionRefresh"/>
|
||||
<addaction name="actionSwitch"/>
|
||||
<addaction name="actionEnable"/>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -77,9 +95,6 @@
|
||||
<property name="title">
|
||||
<string>Menu</string>
|
||||
</property>
|
||||
<addaction name="actionSwitch"/>
|
||||
<addaction name="actionEnable"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionEnableAll"/>
|
||||
<addaction name="actionDisableAll"/>
|
||||
<addaction name="separator"/>
|
||||
@ -91,27 +106,6 @@
|
||||
</widget>
|
||||
<addaction name="menuMenu"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusBar"/>
|
||||
<action name="actionEnable">
|
||||
<property name="icon">
|
||||
<iconset theme="list-add">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable profile</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSwitch">
|
||||
<property name="icon">
|
||||
<iconset theme="system-run">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Switch to profile</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionClose">
|
||||
<property name="icon">
|
||||
<iconset theme="exit">
|
||||
@ -160,6 +154,39 @@
|
||||
<string>Enable service</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRefresh">
|
||||
<property name="icon">
|
||||
<iconset theme="view-refresh">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Refresh</string>
|
||||
</property>
|
||||
<property name="shortcut">
|
||||
<string>Ctrl+R</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionEnable">
|
||||
<property name="icon">
|
||||
<iconset theme="list-add">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Enable</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionSwitch">
|
||||
<property name="icon">
|
||||
<iconset theme="system-run">
|
||||
<normaloff/>
|
||||
</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Switch</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
|
534
sources/gui/src/newprofilewidget.cpp
Normal file
534
sources/gui/src/newprofilewidget.cpp
Normal file
@ -0,0 +1,534 @@
|
||||
/***************************************************************************
|
||||
* 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 "newprofilewidget.h"
|
||||
#include "ui_newprofilewidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QLineEdit>
|
||||
#include <QMenu>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "bridgewidget.h"
|
||||
#include "commonfunctions.h"
|
||||
#include "dbusoperation.h"
|
||||
#include "errorwindow.h"
|
||||
#include "ethernetwidget.h"
|
||||
#include "generalwidget.h"
|
||||
#include "ipwidget.h"
|
||||
#include "mainwindow.h"
|
||||
#include "macvlanwidget.h"
|
||||
#include "mobilewidget.h"
|
||||
#include "pppoewidget.h"
|
||||
#include "tunnelwidget.h"
|
||||
#include "tuntapwidget.h"
|
||||
#include "vlanwidget.h"
|
||||
#include "wirelesswidget.h"
|
||||
|
||||
|
||||
NewProfileWidget::NewProfileWidget(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
|
||||
: QWidget(parent),
|
||||
debug(debugCmd),
|
||||
configuration(settings)
|
||||
{
|
||||
mainWindow = dynamic_cast<MainWindow *>(parent);
|
||||
useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
|
||||
|
||||
createObjects();
|
||||
createToolBars();
|
||||
createActions();
|
||||
}
|
||||
|
||||
|
||||
NewProfileWidget::~NewProfileWidget()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
deleteObjects();
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::profileTabOpenProfile(const QString profile)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->comboBox_profile->addItem(profile);
|
||||
ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count() - 1);
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::update()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
updateProfileTab();
|
||||
updateMenuProfile();
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::updateMenuProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]);
|
||||
|
||||
bool selected = !ui->comboBox_profile->currentText().isEmpty();
|
||||
toolBarActions[QString("profileLoad")]->setVisible(selected);
|
||||
toolBarActions[QString("profileRemove")]->setVisible(selected);
|
||||
toolBarActions[QString("profileSave")]->setVisible(selected);
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::updateProfileTab()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
profileTabClear();
|
||||
mainWindow->setDisabled(false);
|
||||
mainWindow->showMessage(true);
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::profileTabChangeState(const QString current)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Current type" << current;
|
||||
|
||||
generalWid->setVisible(true);
|
||||
ipWid->setVisible((current != QString("pppoe")) && (current != QString("mobile_ppp")));
|
||||
bridgeWid->setVisible(current == QString("bridge"));
|
||||
ethernetWid->setVisible((current == QString("ethernet")) ||
|
||||
(current == QString("vlan")) ||
|
||||
(current == QString("macvlan")));
|
||||
macvlanWid->setVisible(current == QString("macvlan"));
|
||||
mobileWid->setVisible(current == QString("mobile_ppp"));
|
||||
pppoeWid->setVisible(current == QString("pppoe"));
|
||||
tunnelWid->setVisible(current == QString("tunnel"));
|
||||
tuntapWid->setVisible(current == QString("tuntap"));
|
||||
vlanWid->setVisible(current == QString("vlan"));
|
||||
wirelessWid->setVisible(current == QString("wireless"));
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::profileTabClear()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
ui->comboBox_profile->clear();
|
||||
QList<netctlProfileInfo> profiles;
|
||||
if (useHelper)
|
||||
profiles = parseOutputNetctl(sendRequestToLib(QString("netctlVerboseProfileList"), debug));
|
||||
else
|
||||
profiles = netctlCommand->getProfileList();
|
||||
for (int i=0; i<profiles.count(); i++)
|
||||
ui->comboBox_profile->addItem(profiles[i].name);
|
||||
ui->comboBox_profile->setCurrentIndex(-1);
|
||||
|
||||
generalWid->clear();
|
||||
ipWid->clear();
|
||||
bridgeWid->clear();
|
||||
ethernetWid->clear();
|
||||
macvlanWid->clear();
|
||||
mobileWid->clear();
|
||||
pppoeWid->clear();
|
||||
tunnelWid->clear();
|
||||
tuntapWid->clear();
|
||||
vlanWid->clear();
|
||||
wirelessWid->clear();
|
||||
|
||||
profileTabChangeState(generalWid->connectionType->currentText());
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::profileTabCreateProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// error checking
|
||||
if (ui->comboBox_profile->currentText().isEmpty())
|
||||
return ErrorWindow::showWindow(3, QString(PDEBUG), debug);
|
||||
if (generalWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(4, QString(PDEBUG), debug);
|
||||
else if (generalWid->isOk() == 2)
|
||||
return ErrorWindow::showWindow(5, QString(PDEBUG), debug);
|
||||
if ((generalWid->connectionType->currentText() == QString("ethernet")) ||
|
||||
(generalWid->connectionType->currentText() == QString("wireless")) ||
|
||||
(generalWid->connectionType->currentText() == QString("bond")) ||
|
||||
(generalWid->connectionType->currentText() == QString("dummy")) ||
|
||||
(generalWid->connectionType->currentText() == QString("bridge")) ||
|
||||
(generalWid->connectionType->currentText() == QString("tunnel")) ||
|
||||
(generalWid->connectionType->currentText() == QString("tuntap")) ||
|
||||
(generalWid->connectionType->currentText() == QString("vlan")) ||
|
||||
(generalWid->connectionType->currentText() == QString("macvlan")) ||
|
||||
(generalWid->connectionType->currentText() == QString("openvswitch"))) {
|
||||
if (ipWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(6, QString(PDEBUG), debug);
|
||||
else if (ipWid->isOk() == 2)
|
||||
return ErrorWindow::showWindow(6, QString(PDEBUG), debug);
|
||||
}
|
||||
if (generalWid->connectionType->currentText() == QString("ethernet")) {
|
||||
if (ethernetWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
|
||||
} else if (generalWid->connectionType->currentText() == QString("wireless")) {
|
||||
if (wirelessWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(8, QString(PDEBUG), debug);
|
||||
else if (wirelessWid->isOk() == 2)
|
||||
return ErrorWindow::showWindow(9, QString(PDEBUG), debug);
|
||||
else if (wirelessWid->isOk() == 3)
|
||||
return ErrorWindow::showWindow(10, QString(PDEBUG), debug);
|
||||
else if (wirelessWid->isOk() == 4)
|
||||
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
|
||||
else if (wirelessWid->isOk() == 5)
|
||||
return ErrorWindow::showWindow(11, QString(PDEBUG), debug);
|
||||
} else if (generalWid->connectionType->currentText() == QString("bridge")) {
|
||||
} else if (generalWid->connectionType->currentText() == QString("pppoe")) {
|
||||
if (pppoeWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
|
||||
else if (pppoeWid->isOk() == 2)
|
||||
return ErrorWindow::showWindow(12, QString(PDEBUG), debug);
|
||||
else if (pppoeWid->isOk() == 3)
|
||||
return ErrorWindow::showWindow(13, QString(PDEBUG), debug);
|
||||
else if (pppoeWid->isOk() == 4)
|
||||
return ErrorWindow::showWindow(12, QString(PDEBUG), debug);
|
||||
} else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) {
|
||||
if (mobileWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(15, QString(PDEBUG), debug);
|
||||
if (mobileWid->isOk() == 2)
|
||||
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
|
||||
}
|
||||
else if (generalWid->connectionType->currentText() == QString("tunnel")) {
|
||||
if (tunnelWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(20, QString(PDEBUG), debug);
|
||||
}
|
||||
else if (generalWid->connectionType->currentText() == QString("tuntap")) {
|
||||
if (tuntapWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(15, QString(PDEBUG), debug);
|
||||
if (tuntapWid->isOk() == 2)
|
||||
return ErrorWindow::showWindow(15, QString(PDEBUG), debug);
|
||||
}
|
||||
else if (generalWid->connectionType->currentText() == QString("vlan")) {
|
||||
if (ethernetWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
|
||||
}
|
||||
else if (generalWid->connectionType->currentText() == QString("macvlan")) {
|
||||
if (ethernetWid->isOk() == 1)
|
||||
return ErrorWindow::showWindow(7, QString(PDEBUG), debug);
|
||||
}
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
// read settings
|
||||
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
|
||||
QMap<QString, QString> settings;
|
||||
settings = generalWid->getSettings();
|
||||
if (generalWid->connectionType->currentText() == QString("ethernet")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = ethernetWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("wireless")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = wirelessWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if ((generalWid->connectionType->currentText() == QString("bond")) ||
|
||||
(generalWid->connectionType->currentText() == QString("dummy")) ||
|
||||
(generalWid->connectionType->currentText() == QString("openvswitch"))) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("bridge")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = bridgeWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("pppoe")) {
|
||||
QMap<QString, QString> addSettings = pppoeWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) {
|
||||
QMap<QString, QString> addSettings = mobileWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("tunnel")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = tunnelWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("tuntap")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = tuntapWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("vlan")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = ethernetWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = vlanWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
} else if (generalWid->connectionType->currentText() == QString("macvlan")) {
|
||||
QMap<QString, QString> addSettings = ipWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = ethernetWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
addSettings = macvlanWid->getSettings();
|
||||
for (int i=0; i<addSettings.keys().count(); i++)
|
||||
settings.insert(addSettings.keys()[i], addSettings[addSettings.keys()[i]]);
|
||||
}
|
||||
|
||||
// call netctlprofile
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(QString("%1==%2").arg(settings.keys()[i]).arg(settings[settings.keys()[i]]));
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
args.append(settingsList);
|
||||
QList<QVariant> responce = sendRequestToCtrlWithArgs(QString("Create"), args, debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return profileTabCreateProfile();
|
||||
}
|
||||
status = responce[0].toBool();
|
||||
|
||||
} else {
|
||||
QString profileTempName = netctlProfile->createProfile(profile, settings);
|
||||
status = netctlProfile->copyProfile(profileTempName);
|
||||
}
|
||||
mainWindow->showMessage(status);
|
||||
|
||||
updateProfileTab();
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::profileTabLoadProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
|
||||
if (profile.isEmpty()) return;
|
||||
QMap<QString, QString> settings;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("Profile"), args, debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return profileTabLoadProfile();
|
||||
}
|
||||
QStringList settingsList = responce[0].toStringList();
|
||||
for (int i=0; i<settingsList.count(); i++) {
|
||||
if (!settingsList[i].contains(QString("=="))) continue;
|
||||
QString key = settingsList[i].split(QString("=="))[0];
|
||||
QString value = settingsList[i].split(QString("=="))[1];
|
||||
settings[key] = value;
|
||||
}
|
||||
} else
|
||||
settings = netctlProfile->getSettingsFromProfile(profile);
|
||||
|
||||
if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug);
|
||||
|
||||
generalWid->setSettings(settings);
|
||||
if (generalWid->connectionType->currentText() == QString("ethernet")) {
|
||||
ipWid->setSettings(settings);
|
||||
ethernetWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("wireless")) {
|
||||
ipWid->setSettings(settings);
|
||||
wirelessWid->setSettings(settings);
|
||||
} else if ((generalWid->connectionType->currentText() == QString("bond")) ||
|
||||
(generalWid->connectionType->currentText() == QString("dummy")) ||
|
||||
(generalWid->connectionType->currentText() == QString("openvswitch"))) {
|
||||
ipWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("bridge")) {
|
||||
ipWid->setSettings(settings);
|
||||
bridgeWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("pppoe")) {
|
||||
pppoeWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("mobile_ppp")) {
|
||||
mobileWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("tunnel")) {
|
||||
ipWid->setSettings(settings);
|
||||
tunnelWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("tuntap")) {
|
||||
ipWid->setSettings(settings);
|
||||
tuntapWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("vlan")) {
|
||||
ipWid->setSettings(settings);
|
||||
ethernetWid->setSettings(settings);
|
||||
vlanWid->setSettings(settings);
|
||||
} else if (generalWid->connectionType->currentText() == QString("macvlan")) {
|
||||
ipWid->setSettings(settings);
|
||||
ethernetWid->setSettings(settings);
|
||||
macvlanWid->setSettings(settings);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::profileTabRemoveProfile()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
|
||||
if (profile.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug);
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToCtrlWithArgs(QString("Remove"), args, debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return profileTabLoadProfile();
|
||||
}
|
||||
status = responce[0].toBool();
|
||||
} else
|
||||
status = netctlProfile->removeProfile(profile);
|
||||
mainWindow->showMessage(status);
|
||||
|
||||
updateProfileTab();
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::createActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// main tab events
|
||||
connect(ui->comboBox_profile, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabLoadProfile()));
|
||||
connect(ui->comboBox_profile, SIGNAL(editTextChanged(QString)), this, SLOT(updateMenuProfile()));
|
||||
connect(ui->comboBox_profile->lineEdit(), SIGNAL(returnPressed()), this, SLOT(profileTabLoadProfile()));
|
||||
connect(generalWid->connectionType, SIGNAL(currentIndexChanged(QString)), this, SLOT(profileTabChangeState(QString)));
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::createObjects()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// backend
|
||||
netctlCommand = new Netctl(debug, configuration);
|
||||
netctlProfile = new NetctlProfile(debug, configuration);
|
||||
// windows
|
||||
ui = new Ui::NewProfileWidget;
|
||||
ui->setupUi(this);
|
||||
// profile widgets
|
||||
generalWid = new GeneralWidget(this, configuration);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(generalWid);
|
||||
ipWid = new IpWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(ipWid);
|
||||
bridgeWid = new BridgeWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(bridgeWid);
|
||||
ethernetWid = new EthernetWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(ethernetWid);
|
||||
macvlanWid = new MacvlanWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(macvlanWid);
|
||||
mobileWid = new MobileWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(mobileWid);
|
||||
pppoeWid = new PppoeWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(pppoeWid);
|
||||
tunnelWid = new TunnelWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(tunnelWid);
|
||||
tuntapWid = new TuntapWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(tuntapWid);
|
||||
vlanWid = new VlanWidget(this);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(vlanWid);
|
||||
wirelessWid = new WirelessWidget(this, configuration);
|
||||
ui->scrollAreaWidgetContents->layout()->addWidget(wirelessWid);
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::createToolBars()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
actionToolBar = new QToolBar(this);
|
||||
actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
toolBarActions[QString("profileClear")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-clear")),
|
||||
QApplication::translate("NewProfileWidget", "Clear"),
|
||||
this, SLOT(profileTabClear()));
|
||||
|
||||
actionMenu = new QToolButton(this);
|
||||
actionMenu->setPopupMode(QToolButton::DelayedPopup);
|
||||
actionMenu->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
QMenu *menu = new QMenu(actionMenu);
|
||||
toolBarActions[QString("profileLoad")] = menu->addAction(QIcon::fromTheme(QString("document-open")),
|
||||
QApplication::translate("NewProfileWidget", "Load"),
|
||||
this, SLOT(profileTabLoadProfile()));
|
||||
toolBarActions[QString("profileSave")] = menu->addAction(QIcon::fromTheme(QString("document-save")),
|
||||
QApplication::translate("NewProfileWidget", "Save"),
|
||||
this, SLOT(profileTabCreateProfile()));
|
||||
actionMenu->setMenu(menu);
|
||||
actionToolBar->addWidget(actionMenu);
|
||||
|
||||
toolBarActions[QString("profileRemove")] = actionToolBar->addAction(QIcon::fromTheme(QString("edit-delete")),
|
||||
QApplication::translate("NewProfileWidget", "Remove"),
|
||||
this, SLOT(profileTabRemoveProfile()));
|
||||
|
||||
actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]);
|
||||
ui->verticalLayout->insertWidget(0, actionToolBar);
|
||||
}
|
||||
|
||||
|
||||
void NewProfileWidget::deleteObjects()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (netctlCommand != nullptr) delete netctlCommand;
|
||||
if (netctlProfile != nullptr) delete netctlProfile;
|
||||
|
||||
if (bridgeWid != nullptr) delete bridgeWid;
|
||||
if (ethernetWid != nullptr) delete ethernetWid;
|
||||
if (generalWid != nullptr) delete generalWid;
|
||||
if (ipWid != nullptr) delete ipWid;
|
||||
if (macvlanWid != nullptr) delete macvlanWid;
|
||||
if (mobileWid != nullptr) delete mobileWid;
|
||||
if (pppoeWid != nullptr) delete pppoeWid;
|
||||
if (tunnelWid != nullptr) delete tunnelWid;
|
||||
if (tuntapWid != nullptr) delete tuntapWid;
|
||||
if (vlanWid != nullptr) delete vlanWid;
|
||||
if (wirelessWid != nullptr) delete wirelessWid;
|
||||
|
||||
if (actionMenu != nullptr) {
|
||||
actionMenu->menu()->clear();
|
||||
delete actionMenu;
|
||||
}
|
||||
if (actionToolBar != nullptr) {
|
||||
actionToolBar->clear();
|
||||
delete actionToolBar;
|
||||
}
|
||||
if (ui != nullptr) delete ui;
|
||||
}
|
102
sources/gui/src/newprofilewidget.h
Normal file
102
sources/gui/src/newprofilewidget.h
Normal file
@ -0,0 +1,102 @@
|
||||
/***************************************************************************
|
||||
* 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 NEWPROFILEWIDGET_H
|
||||
#define NEWPROFILEWIDGET_H
|
||||
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
class BridgeWidget;
|
||||
class EthernetWidget;
|
||||
class GeneralWidget;
|
||||
class IpWidget;
|
||||
class MainWindow;
|
||||
class MacvlanWidget;
|
||||
class MobileWidget;
|
||||
class PppoeWidget;
|
||||
class TunnelWidget;
|
||||
class TuntapWidget;
|
||||
class VlanWidget;
|
||||
class WirelessWidget;
|
||||
|
||||
namespace Ui {
|
||||
class NewProfileWidget;
|
||||
}
|
||||
|
||||
class NewProfileWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit NewProfileWidget(QWidget *parent = 0,
|
||||
const QMap<QString,QString> settings = QMap<QString,QString>(),
|
||||
const bool debugCmd = false);
|
||||
~NewProfileWidget();
|
||||
|
||||
public slots:
|
||||
void profileTabOpenProfile(const QString profile);
|
||||
void update();
|
||||
|
||||
private slots:
|
||||
// update slots
|
||||
void updateMenuProfile();
|
||||
void updateProfileTab();
|
||||
// profile tab slots
|
||||
void profileTabChangeState(const QString current);
|
||||
void profileTabClear();
|
||||
void profileTabCreateProfile();
|
||||
void profileTabLoadProfile();
|
||||
void profileTabRemoveProfile();
|
||||
|
||||
private:
|
||||
// ui
|
||||
QMap<QString, QAction *> toolBarActions;
|
||||
QToolButton *actionMenu = nullptr;
|
||||
QToolBar *actionToolBar = nullptr;
|
||||
MainWindow *mainWindow;
|
||||
Ui::NewProfileWidget *ui = nullptr;
|
||||
BridgeWidget *bridgeWid = nullptr;
|
||||
EthernetWidget *ethernetWid = nullptr;
|
||||
GeneralWidget *generalWid = nullptr;
|
||||
IpWidget *ipWid = nullptr;
|
||||
MacvlanWidget *macvlanWid = nullptr;
|
||||
MobileWidget *mobileWid = nullptr;
|
||||
PppoeWidget *pppoeWid = nullptr;
|
||||
TunnelWidget *tunnelWid = nullptr;
|
||||
TuntapWidget *tuntapWid = nullptr;
|
||||
VlanWidget *vlanWid = nullptr;
|
||||
WirelessWidget *wirelessWid = nullptr;
|
||||
// backend
|
||||
Netctl *netctlCommand = nullptr;
|
||||
NetctlProfile *netctlProfile = nullptr;
|
||||
void createActions();
|
||||
void createObjects();
|
||||
void createToolBars();
|
||||
void deleteObjects();
|
||||
bool debug = false;
|
||||
bool useHelper = true;
|
||||
// configuration
|
||||
QMap<QString, QString> configuration;
|
||||
};
|
||||
|
||||
|
||||
#endif /* NEWPROFILEWIDGET_H */
|
81
sources/gui/src/newprofilewidget.ui
Normal file
81
sources/gui/src/newprofilewidget.ui
Normal file
@ -0,0 +1,81 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>NewProfileWidget</class>
|
||||
<widget class="QWidget" name="NewProfileWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>473</width>
|
||||
<height>410</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_profile">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_profile">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>1</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Profile</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_profile">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>2</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="acceptDrops">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>457</width>
|
||||
<height>363</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="scrollArea_layout"/>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -20,10 +20,10 @@
|
||||
|
||||
#include <QLineEdit>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "wifimenuwidget.h"
|
||||
|
||||
|
||||
PasswdWidget::PasswdWidget(MainWindow *wid)
|
||||
PasswdWidget::PasswdWidget(WiFiMenuWidget *wid)
|
||||
: QWidget(wid),
|
||||
parent(wid),
|
||||
ui(new Ui::PasswdWidget)
|
||||
@ -79,7 +79,7 @@ void PasswdWidget::setPassword(const bool mode)
|
||||
void PasswdWidget::cancel()
|
||||
{
|
||||
hide();
|
||||
parent->updateTabs(2);
|
||||
parent->update();
|
||||
this->~PasswdWidget();
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
#include <QWidget>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
class WiFiMenuWidget;
|
||||
|
||||
namespace Ui {
|
||||
class PasswdWidget;
|
||||
@ -34,7 +34,7 @@ class PasswdWidget : public QWidget
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit PasswdWidget(MainWindow *wid = 0);
|
||||
explicit PasswdWidget(WiFiMenuWidget *wid = 0);
|
||||
~PasswdWidget();
|
||||
|
||||
public slots:
|
||||
@ -47,7 +47,7 @@ private slots:
|
||||
void setEchoMode(const int mode);
|
||||
|
||||
private:
|
||||
MainWindow *parent;
|
||||
WiFiMenuWidget *parent;
|
||||
Ui::PasswdWidget *ui;
|
||||
// ESC pressed event
|
||||
void keyPressEvent(QKeyEvent *pressedKey);
|
||||
|
@ -112,7 +112,7 @@ void TrayIcon::updateMenu()
|
||||
}
|
||||
QStringList profiles;
|
||||
for (int i=0; i<currentProfiles.count(); i++)
|
||||
profiles.append(QString("%1 (%2)").arg(currentProfiles[i]).arg(status[i]));
|
||||
profiles.append(QString("%1 %2").arg(currentProfiles[i]).arg(status[i]));
|
||||
contextMenu[QString("title")]->setText(profiles.join(QString(" | ")));
|
||||
}
|
||||
|
||||
|
451
sources/gui/src/wifimenuwidget.cpp
Normal file
451
sources/gui/src/wifimenuwidget.cpp
Normal file
@ -0,0 +1,451 @@
|
||||
/***************************************************************************
|
||||
* 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 "wifimenuwidget.h"
|
||||
#include "ui_wifimenuwidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
|
||||
#include <pdebug/pdebug.h>
|
||||
|
||||
#include "commonfunctions.h"
|
||||
#include "dbusoperation.h"
|
||||
#include "errorwindow.h"
|
||||
#include "mainwindow.h"
|
||||
#include "passwdwidget.h"
|
||||
|
||||
|
||||
WiFiMenuWidget::WiFiMenuWidget(QWidget *parent, const QMap<QString, QString> settings, const bool debugCmd)
|
||||
: QWidget(parent),
|
||||
debug(debugCmd),
|
||||
configuration(settings)
|
||||
{
|
||||
mainWindow = dynamic_cast<MainWindow *>(parent);
|
||||
useHelper = (configuration[QString("USE_HELPER")] == QString("true"));
|
||||
|
||||
createObjects();
|
||||
createToolBars();
|
||||
createActions();
|
||||
}
|
||||
|
||||
|
||||
WiFiMenuWidget::~WiFiMenuWidget()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
deleteObjects();
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::update()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
updateWifiTab();
|
||||
updateMenuWifi();
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::connectToUnknownEssid(const QString passwd)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (passwdWid != nullptr) delete passwdWid;
|
||||
QStringList interfaces;
|
||||
if (useHelper) {
|
||||
QList<QVariant> responce = sendRequestToLib(QString("WirelessInterfaces"), debug);
|
||||
if (responce.isEmpty())
|
||||
interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
else
|
||||
interfaces = responce[0].toStringList();
|
||||
} else
|
||||
interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) return;
|
||||
|
||||
QMap<QString, QString> settings;
|
||||
settings[QString("Description")] = QString("'Automatically generated profile by Netctl GUI'");
|
||||
settings[QString("Interface")] = interfaces[0];
|
||||
settings[QString("Connection")] = QString("wireless");
|
||||
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 2)->text();
|
||||
if (security.contains(QString("WPA")))
|
||||
settings[QString("Security")] = QString("wpa");
|
||||
else if (security.contains(QString("WEP")))
|
||||
settings[QString("Security")] = QString("wep");
|
||||
else
|
||||
settings[QString("Security")] = QString("none");
|
||||
settings[QString("ESSID")] = QString("'%1'").arg(ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text());
|
||||
if (!passwd.isEmpty())
|
||||
settings[QString("Key")] = QString("'%1'").arg(passwd);
|
||||
settings[QString("IP")] = QString("dhcp");
|
||||
if (hiddenNetwork)
|
||||
settings[QString("Hidden")] = QString("yes");
|
||||
|
||||
QString profile = QString("netctl-gui-%1").arg(settings[QString("ESSID")]);
|
||||
profile.remove(QChar('"')).remove(QChar('\''));
|
||||
if (useHelper) {
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(QString("%1==%2").arg(settings.keys()[i]).arg(settings[settings.keys()[i]]));
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
args.append(settingsList);
|
||||
sendRequestToCtrlWithArgs(QString("Create"), args, debug);
|
||||
} else {
|
||||
QString profileTempName = netctlProfile->createProfile(profile, settings);
|
||||
netctlProfile->copyProfile(profileTempName);
|
||||
}
|
||||
QString message;
|
||||
if (mainWindow->startProfileSlot(profile)) {
|
||||
message = QApplication::translate("MainWindow", "Connection is successfully.");
|
||||
mainWindow->showMessage(true);
|
||||
} else {
|
||||
message = QApplication::translate("MainWindow", "Connection failed.");
|
||||
mainWindow->showMessage(false);
|
||||
}
|
||||
message += QString("\n");
|
||||
message += QApplication::translate("MainWindow", "Do you want to save profile %1?").arg(profile);
|
||||
int select = QMessageBox::question(this, QApplication::translate("MainWindow", "WiFi menu"),
|
||||
message, QMessageBox::Save | QMessageBox::Discard, QMessageBox::Save);
|
||||
switch (select) {
|
||||
case QMessageBox::Save:
|
||||
break;
|
||||
case QMessageBox::Discard:
|
||||
default:
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendRequestToCtrlWithArgs(QString("Remove"), args, debug);
|
||||
} else
|
||||
netctlProfile->removeProfile(profile);
|
||||
break;
|
||||
}
|
||||
|
||||
updateWifiTab();
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::setHiddenName(const QString name)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Set name" << name;
|
||||
|
||||
ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->setText(name);
|
||||
|
||||
wifiTabStart();
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::updateMenuWifi()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
bool selected = (ui->tableWidget_wifi->currentItem() != nullptr);
|
||||
toolBarActions[QString("wifiStart")]->setVisible(selected);
|
||||
if (selected && ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) {
|
||||
toolBarActions[QString("wifiStart")]->setText(QApplication::translate("WiFiMenuWidget", "Start"));
|
||||
toolBarActions[QString("wifiStart")]->setIcon(QIcon::fromTheme("system-run"));
|
||||
} else {
|
||||
toolBarActions[QString("wifiStart")]->setText(QApplication::translate("WiFiMenuWidget", "Stop"));
|
||||
toolBarActions[QString("wifiStart")]->setIcon(QIcon::fromTheme("process-stop"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::updateWifiTab()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
wifiTabSetEnabled(checkExternalApps(QString("wpasup-only"), configuration, debug));
|
||||
if (!checkExternalApps(QString("wpasup"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
QList<netctlWifiInfo> scanResults;
|
||||
if (useHelper)
|
||||
scanResults = parseOutputWifi(sendRequestToCtrl(QString("VerboseWiFi"), debug));
|
||||
else
|
||||
scanResults = wpaCommand->scanWifi();
|
||||
|
||||
ui->tableWidget_wifi->setSortingEnabled(false);
|
||||
ui->tableWidget_wifi->selectRow(-1);
|
||||
ui->tableWidget_wifi->sortByColumn(3, Qt::AscendingOrder);
|
||||
ui->tableWidget_wifi->clear();
|
||||
ui->tableWidget_wifi->setRowCount(scanResults.count());
|
||||
|
||||
// create header
|
||||
QStringList headerList;
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "Name"));
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "Type"));
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "# of points"));
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "Signal"));
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "Security"));
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "Active"));
|
||||
headerList.append(QApplication::translate("WiFiMenuWidget", "Exists"));
|
||||
ui->tableWidget_wifi->setHorizontalHeaderLabels(headerList);
|
||||
// create items
|
||||
for (int i=0; i<scanResults.count(); i++) {
|
||||
// font
|
||||
QFont font;
|
||||
font.setBold(scanResults[i].active);
|
||||
font.setItalic(scanResults[i].exists);
|
||||
// type
|
||||
QString type;
|
||||
switch (scanResults[i].type) {
|
||||
case PointType::TwoG:
|
||||
type = QApplication::translate("WiFiMenuWidget", "2GHz");
|
||||
break;
|
||||
case PointType::FiveG:
|
||||
type = QApplication::translate("WiFiMenuWidget", "5GHz");
|
||||
break;
|
||||
case PointType::TwoAndFiveG:
|
||||
type = QApplication::translate("WiFiMenuWidget", "2GHz and 5GHz");
|
||||
break;
|
||||
case PointType::None:
|
||||
default:
|
||||
type = QApplication::translate("WiFiMenuWidget", "N\\A");
|
||||
break;
|
||||
}
|
||||
// tooltip
|
||||
QString toolTip = QString("");
|
||||
for (int j=0; j<scanResults[i].macs.count(); j++)
|
||||
toolTip += QString("%1 %2: %3 (%4 %5)\n").arg(QApplication::translate("WiFiMenuWidget", "Point"))
|
||||
.arg(j + 1)
|
||||
.arg(scanResults[i].macs[j])
|
||||
.arg(scanResults[i].frequencies[j])
|
||||
.arg(QApplication::translate("WiFiMenuWidget", "MHz"));
|
||||
toolTip += QString("%1: %2\n").arg(QApplication::translate("WiFiMenuWidget", "Type"))
|
||||
.arg(type);
|
||||
toolTip += QString("%1: %2\n").arg(QApplication::translate("WiFiMenuWidget", "Active"))
|
||||
.arg(checkStatus(scanResults[i].active));
|
||||
toolTip += QString("%1: %2").arg(QApplication::translate("WiFiMenuWidget", "Exists"))
|
||||
.arg(checkStatus(scanResults[i].exists));
|
||||
// name
|
||||
ui->tableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i].name));
|
||||
ui->tableWidget_wifi->item(i, 0)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
ui->tableWidget_wifi->item(i, 0)->setToolTip(toolTip);
|
||||
ui->tableWidget_wifi->item(i, 0)->setFont(font);
|
||||
// type
|
||||
ui->tableWidget_wifi->setItem(i, 1, new QTableWidgetItem(type));
|
||||
ui->tableWidget_wifi->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui->tableWidget_wifi->item(i, 1)->setToolTip(toolTip);
|
||||
// count
|
||||
ui->tableWidget_wifi->setItem(i, 2, new QTableWidgetItem(QString::number(scanResults[i].frequencies.count())));
|
||||
ui->tableWidget_wifi->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui->tableWidget_wifi->item(i, 2)->setToolTip(toolTip);
|
||||
// signal
|
||||
ui->tableWidget_wifi->setItem(i, 3, new QTableWidgetItem(QString::number(scanResults[i].signal)));
|
||||
ui->tableWidget_wifi->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui->tableWidget_wifi->item(i, 3)->setToolTip(toolTip);
|
||||
// security
|
||||
ui->tableWidget_wifi->setItem(i, 4, new QTableWidgetItem(scanResults[i].security));
|
||||
ui->tableWidget_wifi->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
ui->tableWidget_wifi->item(i, 4)->setToolTip(toolTip);
|
||||
// active
|
||||
ui->tableWidget_wifi->setItem(i, 5, new QTableWidgetItem(checkStatus(scanResults[i].active, true)));
|
||||
ui->tableWidget_wifi->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
// exists
|
||||
ui->tableWidget_wifi->setItem(i, 6, new QTableWidgetItem(checkStatus(scanResults[i].exists, true)));
|
||||
ui->tableWidget_wifi->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
|
||||
}
|
||||
|
||||
ui->tableWidget_wifi->setSortingEnabled(true);
|
||||
|
||||
ui->tableWidget_wifi->resizeRowsToContents();
|
||||
ui->tableWidget_wifi->resizeColumnsToContents();
|
||||
ui->tableWidget_wifi->resizeRowsToContents();
|
||||
#if QT_VERSION >= 0x050000
|
||||
ui->tableWidget_wifi->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
|
||||
#else
|
||||
ui->tableWidget_wifi->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
|
||||
#endif
|
||||
|
||||
mainWindow->setDisabled(false);
|
||||
mainWindow->showMessage(true);
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::wifiTabContextualMenu(const QPoint &pos)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (ui->tableWidget_wifi->currentItem() == nullptr) return;
|
||||
|
||||
// create menu
|
||||
QMenu menu(this);
|
||||
QAction *refreshTable = menu.addAction(QApplication::translate("WiFiMenuWidget", "Refresh"));
|
||||
refreshTable->setIcon(QIcon::fromTheme("view-refresh"));
|
||||
menu.addSeparator();
|
||||
QAction *startWifi = menu.addAction(QApplication::translate("WiFiMenuWidget", "Start WiFi"));
|
||||
|
||||
// set text
|
||||
if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 5)->text().isEmpty()) {
|
||||
startWifi->setText(QApplication::translate("WiFiMenuWidget", "Start WiFi"));
|
||||
startWifi->setIcon(QIcon::fromTheme("system-run"));
|
||||
|
||||
} else {
|
||||
startWifi->setText(QApplication::translate("WiFiMenuWidget", "Stop WiFi"));
|
||||
startWifi->setIcon(QIcon::fromTheme("process-stop"));
|
||||
}
|
||||
|
||||
// actions
|
||||
QAction *action = menu.exec(ui->tableWidget_wifi->viewport()->mapToGlobal(pos));
|
||||
if (action == refreshTable) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Refresh WiFi";
|
||||
updateWifiTab();
|
||||
} else if (action == startWifi) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Start WiFi";
|
||||
wifiTabStart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::wifiTabSetEnabled(const bool state)
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (debug) qDebug() << PDEBUG << ":" << "State" << state;
|
||||
|
||||
ui->tableWidget_wifi->setHidden(!state);
|
||||
ui->label_wifi->setHidden(state);
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::wifiTabStart()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
if (!checkExternalApps(QString("wpasup"), configuration, debug)) {
|
||||
ErrorWindow::showWindow(1, QString(PDEBUG), debug);
|
||||
emit(mainWindow->needToBeConfigured());
|
||||
return;
|
||||
}
|
||||
if (ui->tableWidget_wifi->currentItem() == nullptr) return;
|
||||
|
||||
mainWindow->setDisabled(true);
|
||||
// name is hidden
|
||||
if (ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text() == QString("<hidden>")) {
|
||||
hiddenNetwork = true;
|
||||
passwdWid = new PasswdWidget(this);
|
||||
passwdWid->setPassword(false);
|
||||
int widgetWidth = 2 * width() / 3;
|
||||
int widgetHeight = 110;
|
||||
int x = (width() - widgetWidth) / 2;
|
||||
int y = (height() - widgetHeight) / 2;
|
||||
passwdWid->setGeometry(x, y, widgetWidth, widgetHeight);
|
||||
passwdWid->show();
|
||||
passwdWid->setFocusToLineEdit();
|
||||
return;
|
||||
}
|
||||
|
||||
// name isn't hidden
|
||||
hiddenNetwork = false;
|
||||
QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text();
|
||||
QString profileName = QString("");
|
||||
if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 6)->text().isEmpty()) {
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QList<QVariant> responce = sendRequestToLibWithArgs(QString("ProfileByEssid"), args, debug);
|
||||
if (responce.isEmpty()) {
|
||||
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
|
||||
useHelper = false;
|
||||
return wifiTabStart();
|
||||
}
|
||||
profileName = responce[0].toString();
|
||||
} else
|
||||
profileName = wpaCommand->existentProfile(profile);
|
||||
mainWindow->showMessage(mainWindow->startProfileSlot(profileName));
|
||||
} else {
|
||||
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text();
|
||||
if (security == QString("none")) return connectToUnknownEssid(QString(""));
|
||||
else {
|
||||
passwdWid = new PasswdWidget(this);
|
||||
passwdWid->setPassword(true);
|
||||
int widgetWidth = 2 * width() / 3;
|
||||
int widgetHeight = 110;
|
||||
int x = (width() - widgetWidth) / 2;
|
||||
int y = (height() - widgetHeight) / 2;
|
||||
passwdWid->setGeometry(x, y, widgetWidth, widgetHeight);
|
||||
passwdWid->show();
|
||||
passwdWid->setFocusToLineEdit();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
updateWifiTab();
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::createActions()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// wifi tab events
|
||||
connect(ui->tableWidget_wifi, SIGNAL(itemActivated(QTableWidgetItem *)), this, SLOT(wifiTabStart()));
|
||||
connect(ui->tableWidget_wifi, SIGNAL(currentItemChanged(QTableWidgetItem *, QTableWidgetItem *)),
|
||||
this, SLOT(updateMenuWifi()));
|
||||
connect(ui->tableWidget_wifi, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(wifiTabContextualMenu(QPoint)));
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::createObjects()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
// backend
|
||||
netctlCommand = new Netctl(debug, configuration);
|
||||
netctlProfile = new NetctlProfile(debug, configuration);
|
||||
wpaCommand = new WpaSup(debug, configuration);
|
||||
// windows
|
||||
ui = new Ui::WiFiMenuWidget;
|
||||
ui->setupUi(this);
|
||||
ui->tableWidget_wifi->setColumnHidden(5, true);
|
||||
ui->tableWidget_wifi->setColumnHidden(6, true);
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::createToolBars()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
actionToolBar = new QToolBar(this);
|
||||
actionToolBar->setToolButtonStyle(Qt::ToolButtonFollowStyle);
|
||||
toolBarActions[QString("wifiRefresh")] = actionToolBar->addAction(QIcon::fromTheme(QString("view-refresh")),
|
||||
QApplication::translate("WiFiMenuWidget", "Refresh"),
|
||||
this, SLOT(updateWifiTab()));
|
||||
toolBarActions[QString("wifiStart")] = actionToolBar->addAction(QIcon::fromTheme(QString("system-run")),
|
||||
QApplication::translate("WiFiMenuWidget", "Start"),
|
||||
this, SLOT(wifiTabStart()));
|
||||
|
||||
ui->verticalLayout->insertWidget(0, actionToolBar);
|
||||
}
|
||||
|
||||
|
||||
void WiFiMenuWidget::deleteObjects()
|
||||
{
|
||||
if (debug) qDebug() << PDEBUG;
|
||||
|
||||
if (netctlCommand != nullptr) delete netctlCommand;
|
||||
if (netctlProfile != nullptr) delete netctlProfile;
|
||||
if (wpaCommand != nullptr) delete wpaCommand;
|
||||
|
||||
if (actionToolBar != nullptr) {
|
||||
actionToolBar->clear();
|
||||
delete actionToolBar;
|
||||
}
|
||||
if (ui != nullptr) delete ui;
|
||||
}
|
84
sources/gui/src/wifimenuwidget.h
Normal file
84
sources/gui/src/wifimenuwidget.h
Normal file
@ -0,0 +1,84 @@
|
||||
/***************************************************************************
|
||||
* 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 WIFIMENUWIDGET_H
|
||||
#define WIFIMENUWIDGET_H
|
||||
|
||||
#include <QApplication>
|
||||
#include <QToolBar>
|
||||
#include <QToolButton>
|
||||
#include <QWidget>
|
||||
|
||||
#include <netctlgui/netctlgui.h>
|
||||
|
||||
|
||||
class MainWindow;
|
||||
class PasswdWidget;
|
||||
|
||||
namespace Ui {
|
||||
class WiFiMenuWidget;
|
||||
}
|
||||
|
||||
class WiFiMenuWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WiFiMenuWidget(QWidget *parent = 0,
|
||||
const QMap<QString,QString> settings = QMap<QString,QString>(),
|
||||
const bool debugCmd = false);
|
||||
~WiFiMenuWidget();
|
||||
|
||||
public slots:
|
||||
void update();
|
||||
// wifi tab slots
|
||||
void connectToUnknownEssid(const QString passwd);
|
||||
void setHiddenName(const QString name);
|
||||
|
||||
private slots:
|
||||
// update slots
|
||||
void updateMenuWifi();
|
||||
void updateWifiTab();
|
||||
// wifi tab slots
|
||||
void wifiTabContextualMenu(const QPoint &pos);
|
||||
void wifiTabSetEnabled(const bool state);
|
||||
void wifiTabStart();
|
||||
|
||||
private:
|
||||
// ui
|
||||
QMap<QString, QAction *> toolBarActions;
|
||||
QToolBar *actionToolBar = nullptr;
|
||||
MainWindow *mainWindow = nullptr;
|
||||
Ui::WiFiMenuWidget *ui = nullptr;
|
||||
PasswdWidget *passwdWid = nullptr;
|
||||
// backend
|
||||
Netctl *netctlCommand = nullptr;
|
||||
NetctlProfile *netctlProfile = nullptr;
|
||||
WpaSup *wpaCommand = nullptr;
|
||||
void createActions();
|
||||
void createObjects();
|
||||
void createToolBars();
|
||||
void deleteObjects();
|
||||
bool debug = false;
|
||||
bool hiddenNetwork;
|
||||
bool useHelper = true;
|
||||
// configuration
|
||||
QMap<QString, QString> configuration;
|
||||
};
|
||||
|
||||
|
||||
#endif /* WIFIMENUWIDGET_H */
|
101
sources/gui/src/wifimenuwidget.ui
Normal file
101
sources/gui/src/wifimenuwidget.ui
Normal file
@ -0,0 +1,101 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>WiFiMenuWidget</class>
|
||||
<widget class="QWidget" name="WiFiMenuWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>571</width>
|
||||
<height>467</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_wifi">
|
||||
<property name="text">
|
||||
<string>Please install 'wpa_supplicant' before using it</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QTableWidget" name="tableWidget_wifi">
|
||||
<property name="contextMenuPolicy">
|
||||
<enum>Qt::CustomContextMenu</enum>
|
||||
</property>
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>7</number>
|
||||
</property>
|
||||
<attribute name="horizontalHeaderStretchLastSection">
|
||||
<bool>true</bool>
|
||||
</attribute>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Type</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string># of points</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Signal</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string>Security</string>
|
||||
</property>
|
||||
<property name="textAlignment">
|
||||
<set>AlignHCenter|AlignVCenter|AlignCenter</set>
|
||||
</property>
|
||||
</column>
|
||||
<column/>
|
||||
<column/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
@ -182,6 +182,8 @@ QStringList NetctlAdaptor::VerboseProfileList()
|
||||
QStringList profileInfo;
|
||||
profileInfo.append(profilesInfo[i].name);
|
||||
profileInfo.append(profilesInfo[i].description);
|
||||
profileInfo.append(profilesInfo[i].type);
|
||||
profileInfo.append(profilesInfo[i].interface);
|
||||
profileInfo.append(profilesInfo[i].essid);
|
||||
profileInfo.append(QString::number(profilesInfo[i].active));
|
||||
profileInfo.append(QString::number(profilesInfo[i].enabled));
|
||||
|
Loading…
Reference in New Issue
Block a user