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 MainWindow::mainTabStopAllProfiles() { if (debug) qDebug() << PDEBUG; if (!checkExternalApps(QString("netctl"))) { ErrorWindow::showWindow(1, QString(PDEBUG), debug); emit(needToBeConfigured()); return; } ui->tabWidget->setDisabled(true); bool status = false; if (useHelper) { QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, DBUS_HELPER_INTERFACE, QString("StopAll"), QList<QVariant>(), true, 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(); if (status) ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); updateMainTab(); }
void MainWindow::mainTabRemoveProfile() { if (debug) qDebug() << PDEBUG; if (ui->tableWidget_main->currentItem() == nullptr) return; 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); QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_CTRL_PATH, DBUS_HELPER_INTERFACE, QString("Remove"), 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 status = netctlProfile->removeProfile(profile); if (status) ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); updateMainTab(); }
void MainWidget::update() { if (debug) qDebug() << PDEBUG; if (mainWindow->currentTab() == 0) { updateMainTab(); updateMenuMain(); } if (timer.interval() != 0) return timer.start(); }
void MainWidget::mainTabStopAllProfiles() { if (debug) qDebug() << PDEBUG; if (!checkExternalApps(QString("netctl"), configuration, debug)) { ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug); return mainWindow->emitNeedToBeConfigured(); } mainWindow->setDisabled(true); InterfaceAnswer answer = stopAllProfilesSlot(mainWindow->netctlInterface, useHelper, debug); mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); }
void MainWidget::mainTabSwitchToProfile() { if (debug) qDebug() << PDEBUG; if (!checkExternalApps(QString("netctl"), configuration, debug)) { ErrorWindow::showWindow(1, externalApps(QString("netctl"), configuration).join(QChar('\n')), debug); return mainWindow->emitNeedToBeConfigured(); } if (ui->tableWidget_main->currentItem() == nullptr) return; mainWindow->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); InterfaceAnswer answer = switchToProfileSlot(profile, mainWindow->netctlInterface, useHelper, debug); mainWindow->showMessage(answer == InterfaceAnswer::True); updateMainTab(); }
void MainWindow::mainTabSwitchToProfile() { if (debug) qDebug() << PDEBUG; if (!checkExternalApps(QString("netctl"))) { ErrorWindow::showWindow(1, QString(PDEBUG), debug); emit(needToBeConfigured()); return; } if (ui->tableWidget_main->currentItem() == nullptr) return; ui->tabWidget->setDisabled(true); QString profile = ui->tableWidget_main->item(ui->tableWidget_main->currentItem()->row(), 0)->text(); if (switchToProfileSlot(profile)) ui->statusBar->showMessage(QApplication::translate("MainWindow", "Done")); else ui->statusBar->showMessage(QApplication::translate("MainWindow", "Error")); updateMainTab(); }
// tab update slots void MainWindow::updateMainTab() { if (debug) qDebug() << PDEBUG; if (!checkExternalApps(QString("netctl"))) { ErrorWindow::showWindow(1, QString(PDEBUG), debug); emit(needToBeConfigured()); return; } ui->tabWidget->setDisabled(true); QList<netctlProfileInfo> profiles; bool netctlAutoStatus = false; if (useHelper) { QList<QVariant> responce = sendDBusRequest(DBUS_HELPER_SERVICE, DBUS_LIB_PATH, DBUS_HELPER_INTERFACE, QString("isNetctlAutoActive"), 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, DBUS_HELPER_INTERFACE, QString("ProfileList"), QList<QVariant>(), true, debug), 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("MainWindow", "Name")); headerList.append(QApplication::translate("MainWindow", "Description")); headerList.append(QApplication::translate("MainWindow", "Active")); headerList.append(QApplication::translate("MainWindow", "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\n").arg(QApplication::translate("MainWindow", "Profile")).arg(profiles[i].name); toolTip += QString("%1: %2\n").arg(QApplication::translate("MainWindow", "Active")).arg(checkStatus(profiles[i].active)); toolTip += QString("%1: %2").arg(QApplication::translate("MainWindow", "Enabled")).arg(checkStatus(profiles[i].enabled)); // 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 ui->tabWidget->setEnabled(true); ui->statusBar->showMessage(QApplication::translate("MainWindow", "Updated")); update(); }