Commit a5c43dd9 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Automatically delete dialogs on close

Let Qt do the work instead of doing it manually
parent 0afbaad1
Pipeline #194470 passed with stage
in 3 minutes and 23 seconds
......@@ -279,6 +279,7 @@ void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const Q
} else if (type == NetworkManager::ConnectionSettings::Gsm) { // launch the mobile broadband wizard, both gsm/cdma
#if WITH_MODEMMANAGER_SUPPORT
QPointer<MobileConnectionWizard> wizard = new MobileConnectionWizard(NetworkManager::ConnectionSettings::Unknown, this);
wizard->setAttribute(Qt::WA_DeleteOnClose);
connect(wizard.data(), &MobileConnectionWizard::accepted, [wizard, this]() {
if (wizard->getError() == MobileProviders::Success) {
qCDebug(PLASMA_NM_KCM_LOG) << "Mobile broadband wizard finished:" << wizard->type() << wizard->args();
......@@ -308,11 +309,6 @@ void KCMNetworkmanagement::onRequestCreateConnection(int connectionType, const Q
}
}
});
connect(wizard.data(), &MobileConnectionWizard::finished, [wizard]() {
if (wizard) {
wizard->deleteLater();
}
});
wizard->setModal(true);
wizard->show();
#endif
......@@ -471,16 +467,12 @@ void KCMNetworkmanagement::onSelectedConnectionChanged(const QString &connection
void KCMNetworkmanagement::addConnection(const NetworkManager::ConnectionSettings::Ptr &connectionSettings)
{
QPointer<ConnectionEditorDialog> editor = new ConnectionEditorDialog(connectionSettings);
editor->setAttribute(Qt::WA_DeleteOnClose);
connect(editor.data(), &ConnectionEditorDialog::accepted, [connectionSettings, editor, this]() {
// We got confirmation so watch this connection and select it once it is created
m_createdConnectionUuid = connectionSettings->uuid();
m_handler->addConnection(editor->setting());
});
connect(editor.data(), &ConnectionEditorDialog::finished, [editor]() {
if (editor) {
editor->deleteLater();
}
});
editor->setModal(true);
editor->show();
}
......
......@@ -89,6 +89,7 @@ void BluetoothMonitor::addBluetoothConnection(const QString &bdAddr, const QStri
#if WITH_MODEMMANAGER_SUPPORT
else if (service == QLatin1String("dun")) {
QPointer<MobileConnectionWizard> mobileConnectionWizard = new MobileConnectionWizard(NetworkManager::ConnectionSettings::Bluetooth);
mobileConnectionWizard->setAttribute(Qt::WA_DeleteOnClose);
connect(mobileConnectionWizard.data(), &MobileConnectionWizard::accepted, [bdAddr, connectionName, mobileConnectionWizard]() {
if (mobileConnectionWizard->getError() == MobileProviders::Success) {
qCDebug(PLASMA_NM_KDED_LOG) << "Mobile broadband wizard finished:" << mobileConnectionWizard->type() << mobileConnectionWizard->args();
......@@ -119,11 +120,6 @@ void BluetoothMonitor::addBluetoothConnection(const QString &bdAddr, const QStri
}
}
});
connect(mobileConnectionWizard.data(), &MobileConnectionWizard::finished, [mobileConnectionWizard]() {
if (mobileConnectionWizard) {
mobileConnectionWizard->deleteLater();
}
});
mobileConnectionWizard->setModal(true);
mobileConnectionWizard->show();
}
......
......@@ -133,8 +133,10 @@ void ModemMonitor::requestPin(MMModemLock lock)
d->dialog = QPointer<PinDialog>(new PinDialog(modem, PinDialog::ModemNetworkSubsetPuk));
}
d->dialog->setAttribute(Qt::WA_DeleteOnClose);
if (d->dialog.data()->exec() != QDialog::Accepted) {
goto OUT;
return;
}
qCDebug(PLASMA_NM_KDED_LOG) << "Sending unlock code";
......@@ -170,12 +172,6 @@ void ModemMonitor::requestPin(MMModemLock lock)
connect(watcher, &QDBusPendingCallWatcher::finished, this, &ModemMonitor::onSendPinArrived);
}
OUT:
if (d->dialog) {
d->dialog.data()->deleteLater();
}
d->dialog.clear();
}
void ModemMonitor::onSendPinArrived(QDBusPendingCallWatcher *watcher)
......
......@@ -166,6 +166,7 @@ void BondWidget::addBond(QAction *action)
connectionSettings->setAutoconnect(false);
QPointer<ConnectionEditorDialog> bondEditor = new ConnectionEditorDialog(connectionSettings);
bondEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(bondEditor.data(), &ConnectionEditorDialog::accepted, [bondEditor, this]() {
qCDebug(PLASMA_NM_EDITOR_LOG) << "Saving slave connection";
// qCDebug(PLASMA_NM_EDITOR_LOG) << bondEditor->setting();
......@@ -173,11 +174,6 @@ void BondWidget::addBond(QAction *action)
auto watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &BondWidget::bondAddComplete);
});
connect(bondEditor.data(), &ConnectionEditorDialog::finished, [bondEditor]() {
if (bondEditor) {
bondEditor->deleteLater();
}
});
bondEditor->setModal(true);
bondEditor->show();
}
......@@ -221,15 +217,11 @@ void BondWidget::editBond()
if (connection) {
// qCDebug(PLASMA_NM_EDITOR_LOG) << "Editing bonded connection" << currentItem->text() << uuid;
QPointer<ConnectionEditorDialog> bondEditor = new ConnectionEditorDialog(connection->settings());
bondEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(bondEditor.data(), &ConnectionEditorDialog::accepted, [connection, bondEditor, this]() {
connection->update(bondEditor->setting());
connect(connection.data(), &NetworkManager::Connection::updated, this, &BondWidget::populateBonds);
});
connect(bondEditor.data(), &ConnectionEditorDialog::finished, [bondEditor]() {
if (bondEditor) {
bondEditor->deleteLater();
}
});
bondEditor->setModal(true);
bondEditor->show();
}
......
......@@ -116,6 +116,7 @@ void BridgeWidget::addBridge(QAction *action)
connectionSettings->setAutoconnect(false);
QPointer<ConnectionEditorDialog> bridgeEditor = new ConnectionEditorDialog(connectionSettings);
bridgeEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(bridgeEditor.data(), &ConnectionEditorDialog::accepted, [bridgeEditor, this]() {
qCDebug(PLASMA_NM_EDITOR_LOG) << "Saving slave connection";
// qCDebug(PLASMA_NM_EDITOR_LOG) << bridgeEditor->setting();
......@@ -123,11 +124,6 @@ void BridgeWidget::addBridge(QAction *action)
auto watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &BridgeWidget::bridgeAddComplete);
});
connect(bridgeEditor.data(), &ConnectionEditorDialog::finished, [bridgeEditor]() {
if (bridgeEditor) {
bridgeEditor->deleteLater();
}
});
bridgeEditor->setModal(true);
bridgeEditor->show();
}
......@@ -171,15 +167,11 @@ void BridgeWidget::editBridge()
if (connection) {
qCDebug(PLASMA_NM_EDITOR_LOG) << "Editing bridged connection" << currentItem->text() << uuid;
QPointer<ConnectionEditorDialog> bridgeEditor = new ConnectionEditorDialog(connection->settings());
bridgeEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(bridgeEditor.data(), &ConnectionEditorDialog::accepted, [connection, bridgeEditor, this]() {
connection->update(bridgeEditor->setting());
connect(connection.data(), &NetworkManager::Connection::updated, this, &BridgeWidget::populateBridges);
});
connect(bridgeEditor.data(), &ConnectionEditorDialog::finished, [bridgeEditor]() {
if (bridgeEditor) {
bridgeEditor->deleteLater();
}
});
bridgeEditor->setModal(true);
bridgeEditor->show();
}
......
......@@ -387,6 +387,7 @@ void IPv4Widget::tableViewItemChanged(QStandardItem *item)
void IPv4Widget::slotRoutesDialog()
{
QPointer<IpV4RoutesWidget> dlg = new IpV4RoutesWidget(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setRoutes(m_tmpIpv4Setting.routes());
dlg->setNeverDefault(m_tmpIpv4Setting.neverDefault());
......@@ -401,11 +402,6 @@ void IPv4Widget::slotRoutesDialog()
m_tmpIpv4Setting.setNeverDefault(dlg->neverDefault());
m_tmpIpv4Setting.setIgnoreAutoRoutes(dlg->ignoreautoroutes());
});
connect(dlg.data(), &QDialog::finished, [dlg]() {
if (dlg) {
dlg->deleteLater();
}
});
dlg->setModal(true);
dlg->show();
}
......@@ -459,6 +455,7 @@ void IPv4Widget::slotAdvancedDialog()
void IPv4Widget::slotDnsServers()
{
QPointer<QDialog> dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(i18n("Edit DNS servers"));
dialog->setLayout(new QVBoxLayout);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog);
......@@ -476,11 +473,6 @@ void IPv4Widget::slotDnsServers()
}
m_ui->dns->setText(text);
});
connect(dialog.data(), &QDialog::finished, [dialog]() {
if (dialog) {
dialog->deleteLater();
}
});
dialog->setModal(true);
dialog->show();
}
......@@ -488,6 +480,7 @@ void IPv4Widget::slotDnsServers()
void IPv4Widget::slotDnsDomains()
{
QPointer<QDialog> dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(i18n("Edit DNS search domains"));
dialog->setLayout(new QVBoxLayout);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog);
......@@ -505,11 +498,6 @@ void IPv4Widget::slotDnsDomains()
}
m_ui->dnsSearch->setText(text);
});
connect(dialog.data(), &QDialog::finished, [dialog]() {
if (dialog) {
dialog->deleteLater();
}
});
dialog->setModal(true);
dialog->show();
}
......
......@@ -379,6 +379,7 @@ void IPv6Widget::tableViewItemChanged(QStandardItem *item)
void IPv6Widget::slotRoutesDialog()
{
QPointer<IpV6RoutesWidget> dlg = new IpV6RoutesWidget(this);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setRoutes(m_tmpIpv6Setting.routes());
dlg->setNeverDefault(m_tmpIpv6Setting.neverDefault());
......@@ -393,11 +394,6 @@ void IPv6Widget::slotRoutesDialog()
m_tmpIpv6Setting.setNeverDefault(dlg->neverDefault());
m_tmpIpv6Setting.setIgnoreAutoRoutes(dlg->ignoreautoroutes());
});
connect(dlg.data(), &QDialog::finished, [dlg]() {
if (dlg) {
dlg->deleteLater();
}
});
dlg->setModal(true);
dlg->show();
}
......@@ -405,6 +401,7 @@ void IPv6Widget::slotRoutesDialog()
void IPv6Widget::slotDnsServers()
{
QPointer<QDialog> dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(i18n("Edit DNS servers"));
dialog->setLayout(new QVBoxLayout);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog);
......@@ -422,11 +419,6 @@ void IPv6Widget::slotDnsServers()
}
m_ui->dns->setText(text);
});
connect(dialog.data(), &QDialog::finished, [dialog]() {
if (dialog) {
dialog->deleteLater();
}
});
dialog->setModal(true);
dialog->show();
}
......@@ -434,6 +426,7 @@ void IPv6Widget::slotDnsServers()
void IPv6Widget::slotDnsDomains()
{
QPointer<QDialog> dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setWindowTitle(i18n("Edit DNS search domains"));
dialog->setLayout(new QVBoxLayout);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog);
......@@ -451,11 +444,6 @@ void IPv6Widget::slotDnsDomains()
}
m_ui->dnsSearch->setText(text);
});
connect(dialog.data(), &QDialog::finished, [dialog]() {
if (dialog) {
dialog->deleteLater();
}
});
dialog->setModal(true);
dialog->show();
}
......
......@@ -511,6 +511,7 @@ QVariantMap Security8021x::setting() const
void Security8021x::altSubjectMatchesButtonClicked()
{
QPointer<EditListDialog> editor = new EditListDialog(this);
editor->setAttribute(Qt::WA_DeleteOnClose);
editor->setItems(m_ui->leTlsSubjectMatch->text().remove(QLatin1Char(' ')).split(QLatin1Char(','), Qt::SkipEmptyParts));
editor->setWindowTitle(i18n("Alternative Subject Matches"));
......@@ -522,11 +523,6 @@ void Security8021x::altSubjectMatchesButtonClicked()
connect(editor.data(), &QDialog::accepted, [editor, this]() {
m_ui->leTlsSubjectMatch->setText(editor->items().join(QLatin1String(", ")));
});
connect(editor.data(), &QDialog::finished, [editor]() {
if (editor) {
editor->deleteLater();
}
});
editor->setModal(true);
editor->show();
}
......@@ -534,6 +530,7 @@ void Security8021x::altSubjectMatchesButtonClicked()
void Security8021x::connectToServersButtonClicked()
{
QPointer<EditListDialog> editor = new EditListDialog(this);
editor->setAttribute(Qt::WA_DeleteOnClose);
editor->setItems(m_ui->leTlsConnectToServers->text().remove(QLatin1Char(' ')).split(QLatin1Char(','), Qt::SkipEmptyParts));
editor->setWindowTitle(i18n("Connect to these servers only"));
......@@ -542,11 +539,6 @@ void Security8021x::connectToServersButtonClicked()
connect(editor.data(), &QDialog::accepted, [editor, this]() {
m_ui->leTlsConnectToServers->setText(editor->items().join(QLatin1String(", ")));
});
connect(editor.data(), &QDialog::finished, [editor]() {
if (editor) {
editor->deleteLater();
}
});
editor->setModal(true);
editor->show();
}
......
......@@ -106,6 +106,7 @@ void TeamWidget::addTeam(QAction *action)
connectionSettings->setAutoconnect(false);
QPointer<ConnectionEditorDialog> teamEditor = new ConnectionEditorDialog(connectionSettings);
teamEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(teamEditor.data(), &ConnectionEditorDialog::accepted, [teamEditor, this]() {
qCDebug(PLASMA_NM_EDITOR_LOG) << "Saving slave connection";
// qCDebug(PLASMA_NM_EDITOR_LOG) << teamEditor->setting();
......@@ -113,11 +114,6 @@ void TeamWidget::addTeam(QAction *action)
auto watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, &TeamWidget::teamAddComplete);
});
connect(teamEditor.data(), &ConnectionEditorDialog::finished, [teamEditor]() {
if (teamEditor) {
teamEditor->deleteLater();
}
});
teamEditor->setModal(true);
teamEditor->show();
}
......@@ -160,15 +156,11 @@ void TeamWidget::editTeam()
if (connection) {
qCDebug(PLASMA_NM_EDITOR_LOG) << "Editing teamed connection" << currentItem->text() << uuid;
QPointer<ConnectionEditorDialog> teamEditor = new ConnectionEditorDialog(connection->settings());
teamEditor->setAttribute(Qt::WA_DeleteOnClose);
connect(teamEditor.data(), &ConnectionEditorDialog::accepted, [connection, teamEditor, this]() {
connection->update(teamEditor->setting());
connect(connection.data(), &NetworkManager::Connection::updated, this, &TeamWidget::populateTeams);
});
connect(teamEditor.data(), &ConnectionEditorDialog::finished, [teamEditor]() {
if (teamEditor) {
teamEditor->deleteLater();
}
});
teamEditor->setModal(true);
teamEditor->show();
}
......
......@@ -332,6 +332,7 @@ QString WireGuardInterfaceWidget::supportedFileExtensions()
void WireGuardInterfaceWidget::showPeers()
{
QPointer<WireGuardTabWidget> peers = new WireGuardTabWidget(d->peers, this);
peers->setAttribute(Qt::WA_DeleteOnClose);
connect(peers.data(), &WireGuardTabWidget::accepted, [peers, this]() {
NMVariantMapList peersData = peers->setting();
......@@ -343,11 +344,6 @@ void WireGuardInterfaceWidget::showPeers()
slotWidgetChanged();
}
});
connect(peers.data(), &WireGuardTabWidget::finished, [peers]() {
if (peers) {
peers->deleteLater();
}
});
peers->setModal(true);
peers->show();
}
......
......@@ -283,17 +283,13 @@ void Handler::addAndActivateConnection(const QString &device, const QString &spe
m_tmpSpecificPath = specificObject;
QPointer<ConnectionEditorDialog> editor = new ConnectionEditorDialog(settings);
editor->setAttribute(Qt::WA_DeleteOnClose);
editor->show();
KWindowSystem::setState(editor->winId(), NET::KeepAbove);
KWindowSystem::forceActiveWindow(editor->winId());
connect(editor.data(), &ConnectionEditorDialog::accepted, [editor, this]() {
addConnection(editor->setting());
});
connect(editor.data(), &ConnectionEditorDialog::finished, [editor]() {
if (editor) {
editor->deleteLater();
}
});
editor->setModal(true);
editor->show();
} else {
......
......@@ -244,6 +244,7 @@ void L2tpWidget::showIpsec()
} else {
ipsec = new L2tpIpsecWidget(m_tmpIpsecSetting, this);
}
ipsec->setAttribute(Qt::WA_DeleteOnClose);
connect(ipsec.data(), &L2tpIpsecWidget::accepted, [ipsec, this]() {
NMStringMap ipsecData = ipsec->setting();
if (!ipsecData.isEmpty()) {
......@@ -253,11 +254,6 @@ void L2tpWidget::showIpsec()
m_tmpIpsecSetting->setData(ipsecData);
}
});
connect(ipsec.data(), &L2tpIpsecWidget::finished, [ipsec]() {
if (ipsec) {
ipsec->deleteLater();
}
});
ipsec->setModal(true);
ipsec->show();
}
......@@ -271,6 +267,7 @@ void L2tpWidget::showPpp()
} else {
ipsec = new L2tpPPPWidget(m_tmpPppSetting, this, need_peer_eap);
}
ipsec->setAttribute(Qt::WA_DeleteOnClose);
connect(ipsec.data(), &L2tpPPPWidget::accepted, [ipsec, this]() {
NMStringMap ipsecData = ipsec->setting();
if (!ipsecData.isEmpty()) {
......@@ -280,11 +277,6 @@ void L2tpWidget::showPpp()
m_tmpPppSetting->setData(ipsecData);
}
});
connect(ipsec.data(), &L2tpPPPWidget::finished, [ipsec]() {
if (ipsec) {
ipsec->deleteLater();
}
});
ipsec->setModal(true);
ipsec->show();
}
......
......@@ -659,6 +659,7 @@ void OpenconnectAuthWidget::validatePeerCert(const QString &fingerprint, const Q
certificate->setText(peerCert);
QPointer<QDialog> dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog.data()->setWindowModality(Qt::WindowModal);
dialog->setLayout(new QVBoxLayout);
auto buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, dialog);
......@@ -675,9 +676,6 @@ void OpenconnectAuthWidget::validatePeerCert(const QString &fingerprint, const Q
} else {
*accepted = false;
}
if (dialog) {
dialog.data()->deleteLater();
}
widget->deleteLater();
} else {
*accepted = true;
......
......@@ -320,6 +320,7 @@ void OpenVpnSettingWidget::handleOnePasswordType(const PasswordField *passwordFi
void OpenVpnSettingWidget::showAdvanced()
{
QPointer<OpenVpnAdvancedWidget> adv = new OpenVpnAdvancedWidget(d->setting, this);
adv->setAttribute(Qt::WA_DeleteOnClose);
adv->init();
connect(adv.data(), &OpenVpnAdvancedWidget::accepted, [adv, this]() {
NetworkManager::VpnSetting::Ptr advData = adv->setting();
......@@ -328,11 +329,6 @@ void OpenVpnSettingWidget::showAdvanced()
d->setting->setSecrets(advData->secrets());
}
});
connect(adv.data(), &OpenVpnAdvancedWidget::finished, [adv]() {
if (adv) {
adv->deleteLater();
}
});
adv->setModal(true);
adv->show();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment