File indexing completed on 2024-12-15 03:45:03

0001 /*
0002     SPDX-FileCopyrightText: 2016 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "connectdialog.h"
0008 #include "ui_connectdialog.h"
0009 
0010 #include <rest/serverinfo.h>
0011 
0012 #include <QDebug>
0013 #include <QIcon>
0014 #include <QPushButton>
0015 #include <QUrl>
0016 
0017 using namespace KUserFeedback::Console;
0018 
0019 ConnectDialog::ConnectDialog(QWidget *parent) :
0020     QDialog(parent),
0021     ui(new Ui::ConnectDialog)
0022 {
0023     ui->setupUi(this);
0024 
0025     ui->buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Connect"));
0026     connect(ui->serverName, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &ConnectDialog::serverSelected);
0027 
0028     setWindowIcon(QIcon::fromTheme(QStringLiteral("network-connect")));
0029 }
0030 
0031 ConnectDialog::~ConnectDialog()
0032 {
0033 }
0034 
0035 ServerInfo ConnectDialog::serverInfo() const
0036 {
0037     ServerInfo info;
0038     info.setName(ui->serverName->currentText());
0039     info.setUrl(QUrl(ui->serverUrl->text()));
0040     info.setUserName(ui->userName->text());
0041     info.setPassword(ui->password->text());
0042     return info;
0043 }
0044 
0045 void ConnectDialog::setServerInfo(const ServerInfo& serverInfo)
0046 {
0047     ui->serverName->setCurrentText(serverInfo.name());
0048     ui->serverUrl->setText(serverInfo.url().toString());
0049     ui->userName->setText(serverInfo.userName());
0050     ui->password->setText(serverInfo.password());
0051 }
0052 
0053 void ConnectDialog::addRecentServerInfos(const QStringList& serverInfoNames)
0054 {
0055     ui->serverName->addItems(serverInfoNames);
0056 }
0057 
0058 void ConnectDialog::serverSelected()
0059 {
0060     auto info = ServerInfo::load(ui->serverName->currentText());
0061     if (info.isValid())
0062         setServerInfo(info);
0063 }
0064 
0065 #include "moc_connectdialog.cpp"