mirror of
https://github.com/arcan1s/netctl-gui.git
synced 2025-04-24 15:37:23 +00:00
rewrite mainwindow to use helper
This commit is contained in:
parent
23f4a7f141
commit
e64e8810f8
@ -35,10 +35,11 @@ ErrorWindow::~ErrorWindow()
|
||||
}
|
||||
|
||||
|
||||
QStringList ErrorWindow::getMessage(const int mess)
|
||||
QStringList ErrorWindow::getMessage(const int mess, const QString custom)
|
||||
{
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[getMessage]";
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[getMessage]" << ":" << "Message" << mess;
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[getMessage]" << ":" << "Custom message" << custom;
|
||||
|
||||
QString message, title;
|
||||
switch(mess) {
|
||||
@ -123,6 +124,8 @@ QStringList ErrorWindow::getMessage(const int mess)
|
||||
message = QApplication::translate("ErrorWindow", "Unknown error");
|
||||
break;
|
||||
}
|
||||
if (!custom.isEmpty())
|
||||
message = custom;
|
||||
|
||||
QStringList fullMessage;
|
||||
fullMessage.append(title);
|
||||
@ -168,13 +171,14 @@ QMessageBox::Icon ErrorWindow::getIcon(const int mess)
|
||||
}
|
||||
|
||||
|
||||
void ErrorWindow::showWindow(const int mess, const QString sender)
|
||||
void ErrorWindow::showWindow(const int mess, const QString sender, const QString custom)
|
||||
{
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[showWindow]";
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[showWindow]" << ":" << "Message" << mess;
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[showWindow]" << ":" << "Sender" << sender;
|
||||
if (debug) qDebug() << "[ErrorWindow]" << "[showWindow]" << ":" << "Custom message" << custom;
|
||||
|
||||
QStringList message = getMessage(mess);
|
||||
QStringList message = getMessage(mess, custom);
|
||||
QMessageBox messageBox;
|
||||
messageBox.setText(message[0]);
|
||||
messageBox.setInformativeText(message[1]);
|
||||
|
@ -33,11 +33,12 @@ public:
|
||||
|
||||
public slots:
|
||||
void showWindow(const int mess = 0,
|
||||
const QString sender = QString());
|
||||
const QString sender = QString(),
|
||||
const QString custom = QString());
|
||||
|
||||
private:
|
||||
bool debug;
|
||||
QStringList getMessage(const int mess);
|
||||
QStringList getMessage(const int mess, const QString custom = QString());
|
||||
QMessageBox::Icon getIcon(const int mess);
|
||||
};
|
||||
|
||||
|
@ -42,7 +42,7 @@ bool restoreExistSession()
|
||||
QString("Restore"));
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
return ((arguments.size() == 1) && arguments[0].toBool());
|
||||
return !arguments.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,7 +129,10 @@ bool MainWindow::forceStartHelper()
|
||||
TaskResult process = runTask(cmd, false);
|
||||
if (debug) qDebug() << "[MainWindow]" << "[checkExternalApps]" << ":" << "Cmd returns" << process.exitCode;
|
||||
|
||||
return isHelperActive();
|
||||
if (process.exitCode == 0)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -138,12 +141,10 @@ bool MainWindow::forceStopHelper()
|
||||
if (debug) qDebug() << "[MainWindow]" << "[forceStartHelper]";
|
||||
|
||||
QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Close"));
|
||||
DBUS_HELPER_INTERFACE, QString("Close"),
|
||||
QList<QVariant>(), true);
|
||||
|
||||
if (responce.size() == 1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return !responce.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@ -184,12 +185,19 @@ void MainWindow::connectToUnknownEssid(const QString passwd)
|
||||
|
||||
if (passwdWid != 0)
|
||||
delete passwdWid;
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty())
|
||||
QStringList interfaces;
|
||||
if (useHelper)
|
||||
interfaces = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("WirelessInterfaces"),
|
||||
QList<QVariant>(), true)[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")] = netctlCommand->getWirelessInterfaceList()[0];
|
||||
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")))
|
||||
@ -209,10 +217,33 @@ void MainWindow::connectToUnknownEssid(const QString passwd)
|
||||
|
||||
QString profile = QString("netctl-gui-") + settings[QString("ESSID")];
|
||||
profile.remove(QChar('"')).remove(QChar('\''));
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(settings.keys()[i] + QString("==") + settings[settings.keys()[i]]);
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
args.append(settingsList);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Create"),
|
||||
args, true);
|
||||
args.clear();
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Start"),
|
||||
args, true);
|
||||
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else {
|
||||
QString profileTempName = netctlProfile->createProfile(profile, settings);
|
||||
if (netctlProfile->copyProfile(profileTempName))
|
||||
netctlProfile->copyProfile(profileTempName);
|
||||
netctlCommand->startProfile(profile);
|
||||
if (netctlCommand->isProfileActive(profile))
|
||||
status = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
@ -335,20 +366,27 @@ void MainWindow::mainTabEnableProfile()
|
||||
return;
|
||||
|
||||
ui->tabWidget->setDisabled(true);
|
||||
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty();
|
||||
bool current;
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
netctlCommand->enableProfile(profile);
|
||||
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty()) {
|
||||
if (netctlCommand->isProfileEnabled(profile))
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Enable"),
|
||||
args, true);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileEnabled"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else {
|
||||
if (netctlCommand->isProfileEnabled(profile))
|
||||
netctlCommand->enableProfile(profile);
|
||||
current = netctlCommand->isProfileEnabled(profile);
|
||||
}
|
||||
if (current != previous)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
@ -361,7 +399,17 @@ void MainWindow::mainTabRemoveProfile()
|
||||
ui->tabWidget->setDisabled(true);
|
||||
// call netctlprofile
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
if (netctlProfile->removeProfile(profile))
|
||||
bool status;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Remove"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else
|
||||
status = netctlProfile->removeProfile(profile);
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
@ -380,8 +428,22 @@ void MainWindow::mainTabRestartProfile()
|
||||
|
||||
ui->tabWidget->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);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Restart"),
|
||||
args, true)[0].toBool();
|
||||
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else {
|
||||
netctlCommand->restartProfile(profile);
|
||||
if (netctlCommand->isProfileActive(profile))
|
||||
status = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
@ -399,24 +461,27 @@ void MainWindow::mainTabStartProfile()
|
||||
return;
|
||||
|
||||
ui->tabWidget->setDisabled(true);
|
||||
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty();
|
||||
bool current;
|
||||
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
|
||||
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) {
|
||||
netctlCommand->startProfile(profile);
|
||||
if (netctlCommand->isProfileActive(profile))
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Start"),
|
||||
args, true);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else {
|
||||
if (netctlCommand->getActiveProfile().isEmpty())
|
||||
netctlCommand->startProfile(profile);
|
||||
else
|
||||
netctlCommand->switchToProfile(profile);
|
||||
if (netctlCommand->isProfileActive(profile))
|
||||
current = netctlCommand->isProfileActive(profile);
|
||||
}
|
||||
if (current != previous)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
|
||||
updateMainTab();
|
||||
}
|
||||
@ -594,7 +659,13 @@ void MainWindow::profileTabClear()
|
||||
if (debug) qDebug() << "[MainWindow]" << "[profileTabClear]";
|
||||
|
||||
ui->comboBox_profile->clear();
|
||||
QList<netctlProfileInfo> profiles = netctlCommand->getProfileList();
|
||||
QList<netctlProfileInfo> profiles;
|
||||
if (useHelper)
|
||||
profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ProfileList"),
|
||||
QList<QVariant>(), true));
|
||||
else
|
||||
profiles = netctlCommand->getProfileList();
|
||||
for (int i=0; i<profiles.count(); i++)
|
||||
ui->comboBox_profile->addItem(profiles[i].name);
|
||||
ui->comboBox_profile->setCurrentIndex(-1);
|
||||
@ -776,8 +847,23 @@ void MainWindow::profileTabCreateProfile()
|
||||
}
|
||||
|
||||
// call netctlprofile
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(settings.keys()[i] + QString("==") + settings[settings.keys()[i]]);
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
args.append(settingsList);
|
||||
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Create"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else {
|
||||
QString profileTempName = netctlProfile->createProfile(profile, settings);
|
||||
if (netctlProfile->copyProfile(profileTempName))
|
||||
status = netctlProfile->copyProfile(profileTempName);
|
||||
}
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
@ -793,7 +879,24 @@ void MainWindow::profileTabLoadProfile()
|
||||
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
|
||||
if (profile.isEmpty())
|
||||
return;
|
||||
QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile);
|
||||
QMap<QString, QString> settings;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QStringList settingsList = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Profile"),
|
||||
args, true)[0].toStringList();
|
||||
for (int i=0; i<settingsList.count(); i++) {
|
||||
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 errorWin->showWindow(17, QString("[MainWindow] : [profileTabLoadProfile]"));
|
||||
|
||||
@ -848,7 +951,17 @@ void MainWindow::profileTabRemoveProfile()
|
||||
ui->tabWidget->setDisabled(true);
|
||||
// call netctlprofile
|
||||
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
|
||||
if (netctlProfile->removeProfile(profile))
|
||||
bool status = false;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Remove"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else
|
||||
status = netctlProfile->removeProfile(profile);
|
||||
if (status)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
@ -947,21 +1060,33 @@ void MainWindow::wifiTabStart()
|
||||
hiddenNetwork = false;
|
||||
QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text();
|
||||
if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 4)->text().isEmpty()) {
|
||||
QString profileName = wpaCommand->existentProfile(profile);
|
||||
netctlCommand->startProfile(profileName);
|
||||
if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 3)->text().isEmpty()) {
|
||||
if (netctlCommand->isProfileActive(profileName))
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
bool previous = !ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 3)->text().isEmpty();
|
||||
bool current;
|
||||
if (useHelper) {
|
||||
QList<QVariant> args;
|
||||
args.append(profile);
|
||||
QString profileName = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ProfileByEssid"),
|
||||
args, true)[0].toString();
|
||||
args.clear();
|
||||
args.append(profileName);
|
||||
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Start"),
|
||||
args, true);
|
||||
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
|
||||
args, true)[0].toBool();
|
||||
}
|
||||
else {
|
||||
if (netctlCommand->isProfileActive(profileName))
|
||||
QString profileName = wpaCommand->existentProfile(profile);
|
||||
netctlCommand->startProfile(profileName);
|
||||
current = netctlCommand->isProfileActive(profileName);
|
||||
}
|
||||
if (current != previous)
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
|
||||
else
|
||||
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
|
||||
}
|
||||
}
|
||||
else {
|
||||
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text();
|
||||
if (security.contains(QString("none")))
|
||||
|
@ -123,7 +123,8 @@ QString MainWindow::getInformation()
|
||||
QString status;
|
||||
if (useHelper) {
|
||||
QStringList request = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Information"))[0].toStringList();
|
||||
DBUS_HELPER_INTERFACE, QString("Information"),
|
||||
QList<QVariant>(), true)[0].toStringList();
|
||||
profile = request[0];
|
||||
status = request[1];
|
||||
}
|
||||
@ -162,12 +163,10 @@ bool MainWindow::isHelperActive()
|
||||
if (debug) qDebug() << "[MainWindow]" << "[isHelperActive]";
|
||||
|
||||
QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("Active"));
|
||||
DBUS_HELPER_INTERFACE, QString("Active"),
|
||||
QList<QVariant>(), true);
|
||||
|
||||
if (responce.size() == 1)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
return (!responce.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
@ -376,27 +375,40 @@ void MainWindow::deleteObjects()
|
||||
|
||||
QList<QVariant> MainWindow::sendDBusRequest(const QString service, const QString path,
|
||||
const QString interface, const QString cmd,
|
||||
bool system)
|
||||
const QList<QVariant> args, bool system)
|
||||
{
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]";
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Service" << service;
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Path" << path;
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Interface" << interface;
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "cmd" << cmd;
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "args" << args;
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "is system bus" << system;
|
||||
|
||||
QList<QVariant> arguments;
|
||||
QDBusMessage response;
|
||||
if (system) {
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd);
|
||||
QDBusMessage response = bus.call(request);
|
||||
arguments = response.arguments();
|
||||
if (!args.isEmpty())
|
||||
request.setArguments(args);
|
||||
response = bus.call(request);
|
||||
}
|
||||
else {
|
||||
QDBusConnection bus = QDBusConnection::sessionBus();
|
||||
QDBusMessage request = QDBusMessage::createMethodCall(service, path, interface, cmd);
|
||||
QDBusMessage response = bus.call(request);
|
||||
if (!args.isEmpty())
|
||||
request.setArguments(args);
|
||||
response = bus.call(request);
|
||||
}
|
||||
arguments = response.arguments();
|
||||
if ((arguments.size() == 0) &&
|
||||
(service != DBUS_HELPER_SERVICE) &&
|
||||
(path != DBUS_CONTROL_PATH) &&
|
||||
(interface != DBUS_HELPER_INTERFACE) &&
|
||||
(cmd != QString("Active"))) {
|
||||
if (debug) qDebug() << "[MainWindow]" << "[sendDBusRequest]" << ":" << "Error message" << response.errorMessage();
|
||||
errorWin->showWindow(0, QString("[MainWindow] : [sendDBusRequest]"), response.errorMessage());
|
||||
}
|
||||
|
||||
return arguments;
|
||||
@ -506,6 +518,7 @@ void MainWindow::updateConfiguration(const QMap<QString, QVariant> args)
|
||||
delete settingsWin;
|
||||
|
||||
createObjects();
|
||||
if (useHelper) useHelper = isHelperActive();
|
||||
setTab(args[QString("tab")].toInt() - 1);
|
||||
createActions();
|
||||
setIconsToTabs();
|
||||
@ -669,13 +682,21 @@ void MainWindow::updateMainTab()
|
||||
return errorWin->showWindow(1, QString("[MainWindow] : [updateMainTab]"));
|
||||
|
||||
ui->tabWidget->setDisabled(true);
|
||||
ui->widget_netctlAuto->setHidden(!netctlCommand->isNetctlAutoRunning());
|
||||
QList<netctlProfileInfo> profiles;
|
||||
if (useHelper)
|
||||
bool netctlAutoStatus = false;
|
||||
if (useHelper) {
|
||||
netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
|
||||
QList<QVariant>(), true)[0].toBool();
|
||||
profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("ProfileList")));
|
||||
else
|
||||
DBUS_HELPER_INTERFACE, QString("ProfileList"),
|
||||
QList<QVariant>(), true));
|
||||
}
|
||||
else {
|
||||
netctlAutoStatus = netctlCommand->isNetctlAutoRunning();
|
||||
profiles = netctlCommand->getProfileList();
|
||||
}
|
||||
ui->widget_netctlAuto->setHidden(!netctlAutoStatus);
|
||||
|
||||
ui->tableWidget_main->setSortingEnabled(false);
|
||||
ui->tableWidget_main->selectRow(-1);
|
||||
@ -759,8 +780,9 @@ void MainWindow::updateWifiTab()
|
||||
ui->tabWidget->setDisabled(true);
|
||||
QList<netctlWifiInfo> scanResults;
|
||||
if (useHelper)
|
||||
scanResults = parseOutputWifi(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("WiFi")));
|
||||
scanResults = parseOutputWifi(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CONTROL_PATH,
|
||||
DBUS_HELPER_INTERFACE, QString("WiFi"),
|
||||
QList<QVariant>(), true));
|
||||
else
|
||||
scanResults = wpaCommand->scanWifi();
|
||||
|
||||
|
@ -147,6 +147,7 @@ private:
|
||||
void keyPressEvent(QKeyEvent *pressedKey);
|
||||
QList<QVariant> sendDBusRequest(const QString service, const QString path,
|
||||
const QString interface, const QString cmd,
|
||||
const QList<QVariant> args = QList<QVariant>(),
|
||||
const bool system = true);
|
||||
void setIconsToTabs();
|
||||
QString configPath;
|
||||
|
@ -27,6 +27,7 @@ ControlAdaptor::ControlAdaptor(NetctlHelper *parent, const QMap<QString, QString
|
||||
{
|
||||
netctlCommand = new Netctl(false, configuration);
|
||||
netctlProfile = new NetctlProfile(false, configuration);
|
||||
wpaCommand = new WpaSup(false, configuration);
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +35,7 @@ ControlAdaptor::~ControlAdaptor()
|
||||
{
|
||||
delete netctlCommand;
|
||||
delete netctlProfile;
|
||||
delete wpaCommand;
|
||||
}
|
||||
|
||||
|
||||
@ -119,7 +121,40 @@ bool ControlAdaptor::SwitchTo(const QString profile)
|
||||
|
||||
|
||||
// netctlProfile
|
||||
bool ControlAdaptor::Create(const QString profile, const QStringList settingsList)
|
||||
{
|
||||
QMap<QString, QString> settings;
|
||||
for (int i=0; i<settingsList.count(); i++) {
|
||||
QString key = settingsList[i].split(QString("=="))[0];
|
||||
QString value = settingsList[i].split(QString("=="))[1];
|
||||
settings[key] = value;
|
||||
}
|
||||
QString temporaryProfile = netctlProfile->createProfile(profile, settings);
|
||||
|
||||
return netctlProfile->copyProfile(temporaryProfile);
|
||||
}
|
||||
|
||||
|
||||
bool ControlAdaptor::Remove(const QString profile)
|
||||
{
|
||||
return netctlProfile->removeProfile(profile);
|
||||
}
|
||||
|
||||
|
||||
// wpaCommand
|
||||
QStringList ControlAdaptor::WiFi()
|
||||
{
|
||||
QList<netctlWifiInfo> wifiPoints = wpaCommand->scanWifi();
|
||||
QStringList info;
|
||||
for (int i=0; i<wifiPoints.count(); i++) {
|
||||
QStringList point;
|
||||
point.append(wifiPoints[i].name);
|
||||
point.append(wifiPoints[i].security);
|
||||
point.append(wifiPoints[i].signal);
|
||||
point.append(QString::number(wifiPoints[i].active));
|
||||
point.append(QString::number(wifiPoints[i].exists));
|
||||
info.append(point.join(QChar('|')));
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
@ -52,12 +52,16 @@ public slots:
|
||||
bool Start(const QString profile);
|
||||
bool SwitchTo(const QString profile);
|
||||
// netctlProfile
|
||||
bool Create(const QString profile, const QStringList settingsList);
|
||||
bool Remove(const QString profile);
|
||||
// wpaCommand
|
||||
QStringList WiFi();
|
||||
|
||||
private:
|
||||
NetctlHelper *helper;
|
||||
Netctl *netctlCommand;
|
||||
NetctlProfile *netctlProfile;
|
||||
WpaSup *wpaCommand;
|
||||
};
|
||||
|
||||
|
||||
|
@ -41,15 +41,12 @@ bool checkExistSession()
|
||||
QString("Active"));
|
||||
QDBusMessage response = bus.call(request);
|
||||
QList<QVariant> arguments = response.arguments();
|
||||
return ((arguments.size() == 1) && arguments[0].toBool());
|
||||
return !arguments.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// setuid(getuid());
|
||||
// qDebug() << getuid();
|
||||
// qDebug() << geteuid();
|
||||
// detach from console
|
||||
bool isDaemon = true;
|
||||
for (int i=0; i<argc; i++)
|
||||
|
@ -122,7 +122,7 @@ QStringList NetctlAdaptor::Profile(const QString profile)
|
||||
QMap<QString, QString> settings = netctlProfile->getSettingsFromProfile(profile);
|
||||
QStringList settingsList;
|
||||
for (int i=0; i<settings.keys().count(); i++)
|
||||
settingsList.append(settings.keys()[i] + QString("=") +
|
||||
settingsList.append(settings.keys()[i] + QString("==") +
|
||||
settings[settings.keys()[i]]);
|
||||
|
||||
return settingsList;
|
||||
@ -142,19 +142,7 @@ QString NetctlAdaptor::ProfileByEssid(const QString essid)
|
||||
}
|
||||
|
||||
|
||||
QStringList NetctlAdaptor::WiFi()
|
||||
QStringList NetctlAdaptor::WirelessInterfaces()
|
||||
{
|
||||
QList<netctlWifiInfo> wifiPoints = wpaCommand->scanWifi();
|
||||
QStringList info;
|
||||
for (int i=0; i<wifiPoints.count(); i++) {
|
||||
QStringList point;
|
||||
point.append(wifiPoints[i].name);
|
||||
point.append(wifiPoints[i].security);
|
||||
point.append(wifiPoints[i].signal);
|
||||
point.append(QString::number(wifiPoints[i].active));
|
||||
point.append(QString::number(wifiPoints[i].exists));
|
||||
info.append(point.join(QChar('|')));
|
||||
}
|
||||
|
||||
return info;
|
||||
return netctlCommand->getWirelessInterfaceList();
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public slots:
|
||||
QString ProfileValue(const QString profile, const QString key);
|
||||
// wpaCommand
|
||||
QString ProfileByEssid(const QString essid);
|
||||
QStringList WiFi();
|
||||
QStringList WirelessInterfaces();
|
||||
|
||||
private:
|
||||
Netctl *netctlCommand;
|
||||
|
@ -114,7 +114,7 @@ void NetctlHelper::quitHelper()
|
||||
{
|
||||
if (debug) qDebug() << "[NetctlHelper]" << "[quitHelper]";
|
||||
|
||||
QCoreApplication::quit();
|
||||
QCoreApplication::instance()->quit();
|
||||
}
|
||||
|
||||
|
||||
|
@ -364,12 +364,13 @@ bool Netctl::isNetctlAutoRunning()
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[isNetctlAutoRunning]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
return cmdCall(false, systemctlCommand, QString("is-active"), argument);
|
||||
@ -523,12 +524,13 @@ bool Netctl::autoEnableService()
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableService]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoEnableService]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
if (isNetctlAutoEnabled())
|
||||
@ -548,12 +550,13 @@ bool Netctl::autoRestartService()
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoRestartService]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoRestartService]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
if (isNetctlAutoRunning())
|
||||
@ -573,12 +576,13 @@ bool Netctl::autoStartService()
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoStartService]" << ":" << "Could not find service";
|
||||
return false;
|
||||
}
|
||||
if (getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[Netctl]" << "[autoStartService]" << ":" << "Could not interface";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString argument = netctlAutoService + QString("@") + interface + QString(".service");
|
||||
|
||||
if (isNetctlAutoRunning())
|
||||
|
@ -253,14 +253,15 @@ bool WpaSup::startWpaSupplicant()
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find library";
|
||||
return false;
|
||||
}
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[startWpaSupplicant]" << ":" << "Could not find interfaces";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (QFile(pidFile).exists())
|
||||
return true;
|
||||
QString interface = netctlCommand->getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString cmd = sudoCommand + QString(" ") + wpaSupPath + QString(" -B -P ") + pidFile +
|
||||
QString(" -i ") + interface + QString(" -D ") + wpaDrivers +
|
||||
QString(" -C \"DIR=") + ctrlDir + QString(" GROUP=") + ctrlGroup + QString("\"");
|
||||
@ -311,12 +312,13 @@ QString WpaSup::getWpaCliOutput(const QString commandLine)
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find library";
|
||||
return QString();
|
||||
}
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Could not find interfaces";
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString interface = netctlCommand->getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine;
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd;
|
||||
@ -365,12 +367,13 @@ bool WpaSup::wpaCliCall(const QString commandLine)
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find library";
|
||||
return false;
|
||||
}
|
||||
if (netctlCommand->getWirelessInterfaceList().isEmpty()) {
|
||||
QStringList interfaces = netctlCommand->getWirelessInterfaceList();
|
||||
if (interfaces.isEmpty()) {
|
||||
if (debug) qDebug() << "[WpaSup]" << "[wpaCliCall]" << ":" << "Could not find interfaces";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString interface = netctlCommand->getWirelessInterfaceList()[0];
|
||||
QString interface = interfaces[0];
|
||||
QString cmd = wpaCliPath + QString(" -i ") + interface + QString(" -p ") + ctrlDir +
|
||||
QString(" -P ") + pidFile + QString(" ") + commandLine;
|
||||
if (debug) qDebug() << "[WpaSup]" << "[getWpaCliOutput]" << ":" << "Run cmd" << cmd;
|
||||
|
Loading…
Reference in New Issue
Block a user