File indexing completed on 2024-12-08 08:02:35

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 "connectioneditortabwidget.h"
0008 #include "ui_connectioneditortabwidget.h"
0009 
0010 ConnectionEditorTabWidget::ConnectionEditorTabWidget(const NetworkManager::ConnectionSettings::Ptr &connection, QWidget *parent, Qt::WindowFlags f)
0011     : ConnectionEditorBase(connection, parent, f)
0012     , m_ui(new Ui::ConnectionEditorTabWidget)
0013 {
0014     m_ui->setupUi(this);
0015     m_ui->tabWidget->setUsesScrollButtons(false);
0016 
0017     connect(m_ui->connectionName, &QLineEdit::textChanged, this, &ConnectionEditorTabWidget::settingChanged);
0018 
0019     initialize();
0020 
0021     initializeTabWidget(connection);
0022 }
0023 
0024 void ConnectionEditorTabWidget::setConnection(const NetworkManager::ConnectionSettings::Ptr &connection)
0025 {
0026     // Init tabs first as we need to set current tab after that
0027     ConnectionEditorBase::setConnection(connection);
0028 
0029     initializeTabWidget(connection);
0030 }
0031 
0032 ConnectionEditorTabWidget::~ConnectionEditorTabWidget() = default;
0033 
0034 void ConnectionEditorTabWidget::addWidget(QWidget *widget, const QString &text)
0035 {
0036     m_ui->tabWidget->addTab(widget, text);
0037 }
0038 
0039 QString ConnectionEditorTabWidget::connectionName() const
0040 {
0041     return m_ui->connectionName->text();
0042 }
0043 
0044 void ConnectionEditorTabWidget::initializeTabWidget(const NetworkManager::ConnectionSettings::Ptr &connection)
0045 {
0046     if (connection->id().isEmpty()) {
0047         m_ui->connectionName->setText(i18n("New %1 connection", connection->typeAsString(connection->connectionType())));
0048     } else {
0049         m_ui->connectionName->setText(connection->id());
0050     }
0051 
0052     // Set current tab to the connection specific configuration
0053     m_ui->tabWidget->setCurrentIndex(1);
0054 }
0055 
0056 #include "moc_connectioneditortabwidget.cpp"