rewrite private slots

TODO: add more methods to dbusinteraction, check dbus calls
This commit is contained in:
arcan1s
2015-03-02 06:00:42 +03:00
parent 1333967535
commit 25ca2ef1d9
5 changed files with 116 additions and 117 deletions

View File

@ -30,7 +30,7 @@ QList<netctlProfileInfo> parseOutputNetctl(const QList<QVariant> raw,
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QList<netctlProfileInfo> profileInfo; QList<netctlProfileInfo> profileInfo;
if (raw.count() == 0) return profileInfo; if (raw.isEmpty()) return profileInfo;
QStringList list = raw[0].toStringList(); QStringList list = raw[0].toStringList();
for (int i=0; i<list.count(); i++) { for (int i=0; i<list.count(); i++) {
QStringList info = list[i].split(QChar('|')); QStringList info = list[i].split(QChar('|'));
@ -53,7 +53,7 @@ QList<netctlWifiInfo> parseOutputWifi(const QList<QVariant> raw,
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QList<netctlWifiInfo> wifiInfo; QList<netctlWifiInfo> wifiInfo;
if (raw.count() == 0) return wifiInfo; if (raw.isEmpty()) return wifiInfo;
QStringList list = raw[0].toStringList(); QStringList list = raw[0].toStringList();
for (int i=0; i<list.count(); i++) { for (int i=0; i<list.count(); i++) {
QStringList info = list[i].split(QChar('|')); QStringList info = list[i].split(QChar('|'));

View File

@ -90,7 +90,7 @@ void MainWindow::updateMenuMain()
toolBarActions[QString("netctlAuto")]->setVisible(true); toolBarActions[QString("netctlAuto")]->setVisible(true);
toolBarActions[QString("mainRefresh")]->setVisible(true); toolBarActions[QString("mainRefresh")]->setVisible(true);
if (ui->tableWidget_main->currentItem() == 0) return; if (ui->tableWidget_main->currentItem() == nullptr) return;
if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) { if (!ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty()) {
toolBarActions[QString("mainRestart")]->setVisible(true); toolBarActions[QString("mainRestart")]->setVisible(true);
toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWindow", "Stop")); toolBarActions[QString("mainStart")]->setText(QApplication::translate("MainWindow", "Stop"));
@ -100,8 +100,7 @@ void MainWindow::updateMenuMain()
toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("system-run")); toolBarActions[QString("mainStart")]->setIcon(QIcon::fromTheme("system-run"));
} }
if (!mainTabGetActiveProfiles().isEmpty()) { if (!mainTabGetActiveProfiles().isEmpty()) {
if (!mainTabGetActiveProfiles() if (!mainTabGetActiveProfiles().contains(ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text()))
.contains(ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text()))
toolBarActions[QString("mainSwitch")]->setVisible(true); toolBarActions[QString("mainSwitch")]->setVisible(true);
toolBarActions[QString("mainStopAll")]->setVisible(true); toolBarActions[QString("mainStopAll")]->setVisible(true);
} }
@ -126,15 +125,9 @@ void MainWindow::updateMenuProfile()
actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]); actionMenu->setDefaultAction(toolBarActions[QString("profileSave")]);
toolBarActions[QString("profileClear")]->setVisible(true); toolBarActions[QString("profileClear")]->setVisible(true);
if (ui->comboBox_profile->currentText().isEmpty()) { toolBarActions[QString("profileLoad")]->setVisible(!ui->comboBox_profile->currentText().isEmpty());
toolBarActions[QString("profileLoad")]->setVisible(false); toolBarActions[QString("profileRemove")]->setVisible(!ui->comboBox_profile->currentText().isEmpty());
toolBarActions[QString("profileRemove")]->setVisible(false); toolBarActions[QString("profileSave")]->setVisible(!ui->comboBox_profile->currentText().isEmpty());
toolBarActions[QString("profileSave")]->setVisible(false);
} else {
toolBarActions[QString("profileLoad")]->setVisible(true);
toolBarActions[QString("profileRemove")]->setVisible(true);
toolBarActions[QString("profileSave")]->setVisible(true);
}
} }
@ -145,7 +138,7 @@ void MainWindow::updateMenuWifi()
actionMenu->setDefaultAction(toolBarActions[QString("wifiStart")]); actionMenu->setDefaultAction(toolBarActions[QString("wifiStart")]);
toolBarActions[QString("wifiRefresh")]->setVisible(true); toolBarActions[QString("wifiRefresh")]->setVisible(true);
if (ui->tableWidget_wifi->currentItem() == 0) return; if (ui->tableWidget_wifi->currentItem() == nullptr) return;
if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 4)->text().isEmpty()) { if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 4)->text().isEmpty()) {
if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 3)->text().isEmpty()) { if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 3)->text().isEmpty()) {
toolBarActions[QString("wifiStart")]->setText(QApplication::translate("MainWindow", "Stop")); toolBarActions[QString("wifiStart")]->setText(QApplication::translate("MainWindow", "Stop"));
@ -176,9 +169,15 @@ void MainWindow::updateMainTab()
QList<netctlProfileInfo> profiles; QList<netctlProfileInfo> profiles;
bool netctlAutoStatus = false; bool netctlAutoStatus = false;
if (useHelper) { if (useHelper) {
netctlAutoStatus = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"), DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"),
QList<QVariant>(), true, debug)[0].toBool(); QList<QVariant>(), true, 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(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, profiles = parseOutputNetctl(sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("ProfileList"), DBUS_HELPER_INTERFACE, QString("ProfileList"),
QList<QVariant>(), true, debug), debug); QList<QVariant>(), true, debug), debug);
@ -214,7 +213,7 @@ void MainWindow::updateMainTab()
toolTip += QString("%1: %2").arg(QApplication::translate("MainWindow", "Enabled")).arg(checkStatus(profiles[i].enabled)); toolTip += QString("%1: %2").arg(QApplication::translate("MainWindow", "Enabled")).arg(checkStatus(profiles[i].enabled));
// name // name
ui->tableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i].name)); ui->tableWidget_main->setItem(i, 0, new QTableWidgetItem(profiles[i].name));
ui->tableWidget_main->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); 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)->setToolTip(toolTip);
ui->tableWidget_main->item(i, 0)->setFont(font); ui->tableWidget_main->item(i, 0)->setFont(font);
// description // description
@ -306,7 +305,7 @@ void MainWindow::updateWifiTab()
toolTip += QString("%1: %2").arg(QApplication::translate("MainWindow", "Exists")).arg(checkStatus(scanResults[i].exists)); toolTip += QString("%1: %2").arg(QApplication::translate("MainWindow", "Exists")).arg(checkStatus(scanResults[i].exists));
// name // name
ui->tableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i].name)); ui->tableWidget_wifi->setItem(i, 0, new QTableWidgetItem(scanResults[i].name));
ui->tableWidget_wifi->item(i, 0)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); 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)->setToolTip(toolTip);
ui->tableWidget_wifi->item(i, 0)->setFont(font); ui->tableWidget_wifi->item(i, 0)->setFont(font);
// signal // signal
@ -347,8 +346,7 @@ void MainWindow::updateWifiTab()
void MainWindow::mainTabContextualMenu(const QPoint &pos) void MainWindow::mainTabContextualMenu(const QPoint &pos)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_main->currentItem() == 0) if (ui->tableWidget_main->currentItem() == nullptr) return;
return;
// create menu // create menu
QMenu menu(this); QMenu menu(this);
@ -410,12 +408,13 @@ void MainWindow::mainTabContextualMenu(const QPoint &pos)
void MainWindow::mainTabEditProfile() void MainWindow::mainTabEditProfile()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_main->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
ui->tabWidget->setCurrentIndex(1); ui->tabWidget->setCurrentIndex(1);
ui->comboBox_profile->addItem(profile); ui->comboBox_profile->addItem(profile);
ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count()-1); ui->comboBox_profile->setCurrentIndex(ui->comboBox_profile->count() - 1);
} }
@ -427,13 +426,11 @@ void MainWindow::mainTabEnableProfile()
emit(needToBeConfigured()); emit(needToBeConfigured());
return; return;
} }
if (ui->tableWidget_main->currentItem() == 0) return; if (ui->tableWidget_main->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 3)->text().isEmpty(); if (enableProfileSlot(profile))
bool current = enableProfileSlot(profile);
if (current != previous)
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
@ -447,9 +444,10 @@ QStringList MainWindow::mainTabGetActiveProfiles()
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QStringList profiles; QStringList profiles;
for (int i=0; i<ui->tableWidget_main->rowCount(); i++) for (int i=0; i<ui->tableWidget_main->rowCount(); i++) {
if (!ui->tableWidget_main->item(i, 2)->text().isEmpty()) if (ui->tableWidget_main->item(i, 2)->text().isEmpty()) continue;
profiles.append(ui->tableWidget_main->item(i, 0)->text()); profiles.append(ui->tableWidget_main->item(i, 0)->text());
}
return profiles; return profiles;
} }
@ -458,16 +456,23 @@ QStringList MainWindow::mainTabGetActiveProfiles()
void MainWindow::mainTabRemoveProfile() void MainWindow::mainTabRemoveProfile()
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_main->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
bool status; bool status = false;
if (useHelper) { if (useHelper) {
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Remove"), DBUS_HELPER_INTERFACE, QString("Remove"),
args, true, debug)[0].toBool(); args, true, debug);
if (responce.isEmpty()) {
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
useHelper = false;
return mainTabRemoveProfile();
}
status = responce[0].toBool();
} else } else
status = netctlProfile->removeProfile(profile); status = netctlProfile->removeProfile(profile);
if (status) if (status)
@ -487,12 +492,11 @@ void MainWindow::mainTabRestartProfile()
emit(needToBeConfigured()); emit(needToBeConfigured());
return; return;
} }
if (ui->tableWidget_main->currentItem() == 0) return; if (ui->tableWidget_main->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
bool status = restartProfileSlot(profile); if (restartProfileSlot(profile))
if (status)
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
@ -509,13 +513,11 @@ void MainWindow::mainTabStartProfile()
emit(needToBeConfigured()); emit(needToBeConfigured());
return; return;
} }
if (ui->tableWidget_main->currentItem() == 0) return; if (ui->tableWidget_main->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty(); if (startProfileSlot(profile))
bool current = startProfileSlot(profile);
if (current != previous)
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
@ -534,12 +536,18 @@ void MainWindow::mainTabStopAllProfiles()
} }
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
bool status; bool status = false;
if (useHelper) if (useHelper) {
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("StopAll"), DBUS_HELPER_INTERFACE, QString("StopAll"),
QList<QVariant>(), true, debug)[0].toBool(); QList<QVariant>(), true, debug);
else 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(); status = netctlCommand->stopAllProfiles();
if (status) if (status)
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
@ -558,13 +566,11 @@ void MainWindow::mainTabSwitchToProfile()
emit(needToBeConfigured()); emit(needToBeConfigured());
return; return;
} }
if (ui->tableWidget_main->currentItem() == 0) return; if (ui->tableWidget_main->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text();
bool previous = !ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 2)->text().isEmpty(); if (switchToProfileSlot(profile))
bool current = switchToProfileSlot(profile);
if (current != previous)
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
@ -783,13 +789,20 @@ void MainWindow::profileTabCreateProfile()
if (useHelper) { if (useHelper) {
QStringList settingsList; QStringList settingsList;
for (int i=0; i<settings.keys().count(); i++) for (int i=0; i<settings.keys().count(); i++)
settingsList.append(settings.keys()[i] + QString("==") + settings[settings.keys()[i]]); settingsList.append(QString("%1==%2").arg(settings.keys()[i]).arg(settings[settings.keys()[i]]));
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
args.append(settingsList); args.append(settingsList);
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Create"), DBUS_HELPER_INTERFACE, QString("Create"),
args, true, debug)[0].toBool(); args, true, debug);
if (responce.isEmpty()) {
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
useHelper = false;
return profileTabCreateProfile();
}
status = responce[0].toBool();
} else { } else {
QString profileTempName = netctlProfile->createProfile(profile, settings); QString profileTempName = netctlProfile->createProfile(profile, settings);
status = netctlProfile->copyProfile(profileTempName); status = netctlProfile->copyProfile(profileTempName);
@ -808,15 +821,20 @@ void MainWindow::profileTabLoadProfile()
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
if (profile.isEmpty()) if (profile.isEmpty()) return;
return;
QMap<QString, QString> settings; QMap<QString, QString> settings;
if (useHelper) { if (useHelper) {
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
QStringList settingsList = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Profile"), DBUS_HELPER_INTERFACE, QString("Profile"),
args, true, debug)[0].toStringList(); args, true, 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++) { for (int i=0; i<settingsList.count(); i++) {
if (!settingsList[i].contains(QString("=="))) continue; if (!settingsList[i].contains(QString("=="))) continue;
QString key = settingsList[i].split(QString("=="))[0]; QString key = settingsList[i].split(QString("=="))[0];
@ -826,8 +844,7 @@ void MainWindow::profileTabLoadProfile()
} else } else
settings = netctlProfile->getSettingsFromProfile(profile); settings = netctlProfile->getSettingsFromProfile(profile);
if (settings.isEmpty()) if (settings.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug);
return ErrorWindow::showWindow(17, QString(PDEBUG), debug);
generalWid->setSettings(settings); generalWid->setSettings(settings);
if (generalWid->connectionType->currentText() == QString("ethernet")) { if (generalWid->connectionType->currentText() == QString("ethernet")) {
@ -870,15 +887,21 @@ void MainWindow::profileTabRemoveProfile()
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
// call netctlprofile
QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName(); QString profile = QFileInfo(ui->comboBox_profile->currentText()).fileName();
if (profile.isEmpty()) return ErrorWindow::showWindow(17, QString(PDEBUG), debug);
bool status = false; bool status = false;
if (useHelper) { if (useHelper) {
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
status = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Remove"), DBUS_HELPER_INTERFACE, QString("Remove"),
args, true, debug)[0].toBool(); args, true, debug);
if (responce.isEmpty()) {
if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
useHelper = false;
return profileTabLoadProfile();
}
status = responce[0].toBool();
} else } else
status = netctlProfile->removeProfile(profile); status = netctlProfile->removeProfile(profile);
if (status) if (status)
@ -894,7 +917,7 @@ void MainWindow::profileTabRemoveProfile()
void MainWindow::wifiTabContextualMenu(const QPoint &pos) void MainWindow::wifiTabContextualMenu(const QPoint &pos)
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (ui->tableWidget_wifi->currentItem() == 0) return; if (ui->tableWidget_wifi->currentItem() == nullptr) return;
// create menu // create menu
QMenu menu(this); QMenu menu(this);
@ -934,13 +957,8 @@ void MainWindow::wifiTabSetEnabled(const bool state)
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "State" << state; if (debug) qDebug() << PDEBUG << ":" << "State" << state;
if (state) { ui->tableWidget_wifi->setHidden(!state);
ui->tableWidget_wifi->show(); ui->label_wifi->setHidden(state);
ui->label_wifi->hide();
} else {
ui->tableWidget_wifi->hide();
ui->label_wifi->show();
}
} }
@ -952,7 +970,7 @@ void MainWindow::wifiTabStart()
emit(needToBeConfigured()); emit(needToBeConfigured());
return; return;
} }
if (ui->tableWidget_wifi->currentItem() == 0) return; if (ui->tableWidget_wifi->currentItem() == nullptr) return;
ui->tabWidget->setDisabled(true); ui->tabWidget->setDisabled(true);
// name is hidden // name is hidden
@ -960,8 +978,8 @@ void MainWindow::wifiTabStart()
hiddenNetwork = true; hiddenNetwork = true;
passwdWid = new PasswdWidget(this); passwdWid = new PasswdWidget(this);
passwdWid->setPassword(false); passwdWid->setPassword(false);
int widgetWidth = 270; int widgetWidth = 2 * width() / 3;
int widgetHeight = 86; int widgetHeight = 110;
int x = (width() - widgetWidth) / 2; int x = (width() - widgetWidth) / 2;
int y = (height() - widgetHeight) / 2; int y = (height() - widgetHeight) / 2;
passwdWid->setGeometry(x, y, widgetWidth, widgetHeight); passwdWid->setGeometry(x, y, widgetWidth, widgetHeight);
@ -973,41 +991,34 @@ void MainWindow::wifiTabStart()
// name isn't hidden // name isn't hidden
hiddenNetwork = false; hiddenNetwork = false;
QString profile = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 0)->text(); 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(), 4)->text().isEmpty()) { if (!ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 4)->text().isEmpty()) {
bool previous = !ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 3)->text().isEmpty();
bool current;
if (useHelper) { if (useHelper) {
QList<QVariant> args; QList<QVariant> args;
args.append(profile); args.append(profile);
QString profileName = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("ProfileByEssid"), DBUS_HELPER_INTERFACE, QString("ProfileByEssid"),
args, true, debug)[0].toString();
args.clear();
args.append(profileName);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Start"),
args, true, debug); args, true, debug);
current = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, if (responce.isEmpty()) {
DBUS_HELPER_INTERFACE, QString("isProfileActive"), if (debug) qDebug() << PDEBUG << ":" << "Could not interact with helper, disable it";
args, true, debug)[0].toBool(); useHelper = false;
} else { return wifiTabStart();
QString profileName = wpaCommand->existentProfile(profile);
netctlCommand->startProfile(profileName);
current = netctlCommand->isProfileActive(profileName);
} }
if (current != previous) profileName = responce[0].toString();
} else
profileName = wpaCommand->existentProfile(profile);
if (startProfileSlot(profileName))
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
else else
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error"));
} else { } else {
QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text(); QString security = ui->tableWidget_wifi->item(ui->tableWidget_wifi->currentItem()->row(), 1)->text();
if (security.contains(QString("none"))) if (security == QString("none")) return connectToUnknownEssid(QString(""));
return connectToUnknownEssid(QString(""));
else { else {
passwdWid = new PasswdWidget(this); passwdWid = new PasswdWidget(this);
passwdWid->setPassword(true); passwdWid->setPassword(true);
int widgetWidth = 270; int widgetWidth = 2 * width() / 3;
int widgetHeight = 86; int widgetHeight = 110;
int x = (width() - widgetWidth) / 2; int x = (width() - widgetWidth) / 2;
int y = (height() - widgetHeight) / 2; int y = (height() - widgetHeight) / 2;
passwdWid->setGeometry(x, y, widgetWidth, widgetHeight); passwdWid->setGeometry(x, y, widgetWidth, widgetHeight);

View File

@ -467,7 +467,6 @@ void MainWindow::connectToUnknownEssid(const QString passwd)
QString profile = QString("netctl-gui-") + settings[QString("ESSID")]; QString profile = QString("netctl-gui-") + settings[QString("ESSID")];
profile.remove(QChar('"')).remove(QChar('\'')); profile.remove(QChar('"')).remove(QChar('\''));
bool status = false;
if (useHelper) { if (useHelper) {
QStringList settingsList; QStringList settingsList;
for (int i=0; i<settings.keys().count(); i++) for (int i=0; i<settings.keys().count(); i++)
@ -478,26 +477,12 @@ void MainWindow::connectToUnknownEssid(const QString passwd)
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Create"), DBUS_HELPER_INTERFACE, QString("Create"),
args, true, debug); args, true, debug);
args.clear();
args.append(profile);
sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH,
DBUS_HELPER_INTERFACE, QString("Start"),
args, true, debug);
QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH,
DBUS_HELPER_INTERFACE, QString("isProfileActive"),
args, true, debug);
if (responce.isEmpty())
status = netctlCommand->isProfileActive(profile);
else
status = responce[0].toBool();
} else { } else {
QString profileTempName = netctlProfile->createProfile(profile, settings); QString profileTempName = netctlProfile->createProfile(profile, settings);
netctlProfile->copyProfile(profileTempName); netctlProfile->copyProfile(profileTempName);
netctlCommand->startProfile(profile);
status = netctlCommand->isProfileActive(profile);
} }
QString message; QString message;
if (status) { if (startProfileSlot(profile)) {
message = QApplication::translate("MainWindow", "Connection is successfully."); message = QApplication::translate("MainWindow", "Connection is successfully.");
ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done"));
} else { } else {

View File

@ -268,10 +268,13 @@ void MainWindow::closeEvent(QCloseEvent *event)
bool MainWindow::checkExternalApps(const QString apps = QString("all")) bool MainWindow::checkExternalApps(const QString apps = QString("all"))
{ {
if (debug) qDebug() << PDEBUG; if (debug) qDebug() << PDEBUG;
if (debug) qDebug() << PDEBUG << ":" << "Applications" << apps;
if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true; if (configuration[QString("SKIPCOMPONENTS")] == QString("true")) return true;
QStringList cmd; QStringList cmd;
cmd.append("which"); cmd.append("which");
// avoid null-lines arguments
cmd.append("true");
if ((apps == QString("helper")) || (apps == QString("all"))) { if ((apps == QString("helper")) || (apps == QString("all"))) {
cmd.append(configuration[QString("HELPER_PATH")]); cmd.append(configuration[QString("HELPER_PATH")]);
} }

View File

@ -97,7 +97,7 @@ void PasswdWidget::passwdApply()
void PasswdWidget::setEchoMode(const int mode) void PasswdWidget::setEchoMode(const int mode)
{ {
if (mode == 0) if (mode == 0)
ui->lineEdit->setEchoMode(QLineEdit::Normal);
else
ui->lineEdit->setEchoMode(QLineEdit::Password); ui->lineEdit->setEchoMode(QLineEdit::Password);
else
ui->lineEdit->setEchoMode(QLineEdit::Normal);
} }