File indexing completed on 2024-04-14 09:06:54

0001 /*
0002     SPDX-FileCopyrightText: 2016 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "connectioneditordialog.h"
0008 
0009 #include <QPushButton>
0010 #include <QVBoxLayout>
0011 
0012 #include <KLocalizedString>
0013 
0014 ConnectionEditorDialog::ConnectionEditorDialog(const NetworkManager::ConnectionSettings::Ptr &connection, QWidget *parent, Qt::WindowFlags f)
0015     : QDialog(parent, f)
0016     , m_buttonBox(new QDialogButtonBox(this))
0017     , m_connectionEditorTabWidget(new ConnectionEditorTabWidget(connection, parent, f))
0018 {
0019     auto layout = new QVBoxLayout(this);
0020     layout->addWidget(m_connectionEditorTabWidget);
0021 
0022     m_buttonBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
0023     m_buttonBox->button(QDialogButtonBox::Save)->setEnabled(m_connectionEditorTabWidget->isValid());
0024     layout->addWidget(m_buttonBox);
0025 
0026     setLayout(layout);
0027 
0028     connect(m_buttonBox, &QDialogButtonBox::accepted, this, &ConnectionEditorDialog::accept);
0029     connect(m_buttonBox, &QDialogButtonBox::rejected, this, &ConnectionEditorDialog::reject);
0030     connect(m_connectionEditorTabWidget, &ConnectionEditorTabWidget::validityChanged, this, &ConnectionEditorDialog::onValidityChanged);
0031 
0032     if (connection->id().isEmpty()) {
0033         setWindowTitle(i18n("New Connection (%1)", connection->typeAsString(connection->connectionType())));
0034     } else {
0035         setWindowTitle(i18n("Edit Connection '%1'", connection->id()));
0036     }
0037 }
0038 
0039 ConnectionEditorDialog::~ConnectionEditorDialog() = default;
0040 
0041 NMVariantMapMap ConnectionEditorDialog::setting() const
0042 {
0043     return m_connectionEditorTabWidget->setting();
0044 }
0045 
0046 void ConnectionEditorDialog::onValidityChanged(bool valid)
0047 {
0048     m_buttonBox->button(QDialogButtonBox::Save)->setEnabled(valid);
0049 }
0050 
0051 #include "moc_connectioneditordialog.cpp"