/* Copyright (C) 2014 * swift project Community / Contributors * * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, * including this file, may be copied, modified, propagated, or distributed except according to the terms * contained in the LICENSE file. */ #include "blackgui/editors/serverform.h" #include "blackmisc/network/user.h" #include "ui_serverform.h" #include #include #include using namespace BlackMisc::Network; namespace BlackGui { namespace Editors { CServerForm::CServerForm(QWidget *parent) : CForm(parent), ui(new Ui::CNetworkServerForm) { ui->setupUi(this); ui->le_Port->setValidator(new QIntValidator(1, 65535, this)); this->initServerTypes(); connect(ui->cbp_Ecosystem, &CEcosystemComboBox::currentTextChanged, this, &CServerForm::onChangedEcoSystem); connect(ui->cb_ServerType, &QComboBox::currentTextChanged, this, &CServerForm::onChangedServerType); } CServerForm::~CServerForm() { } void CServerForm::setServer(const CServer &server) { const CUser user = server.getUser(); ui->le_NetworkId->setText(user.getId()); ui->le_RealName->setText(user.getRealName()); ui->le_Name->setText(server.getName()); ui->cb_ServerType->setCurrentText(server.getServerTypeAsString()); ui->cbp_Ecosystem->setCurrentEcosystem(server.getEcosystem()); ui->le_Password->setText(user.getPassword()); ui->le_Description->setText(server.getDescription()); ui->le_Address->setText(server.getAddress()); ui->le_Port->setText(QString::number(server.getPort())); ui->form_ServerFsd->setValue(server.getFsdSetup()); } BlackMisc::Network::CServer CServerForm::getServer() const { const CUser user( ui->le_NetworkId->text().trimmed(), ui->le_RealName->text().trimmed().simplified(), QStringLiteral(""), ui->le_Password->text().trimmed() ); const CFsdSetup setup(ui->form_ServerFsd->getValue()); const CServer server( ui->le_Name->text().trimmed().simplified(), ui->le_Description->text().trimmed().simplified(), ui->le_Address->text().trimmed(), ui->le_Port->text().trimmed().toInt(), user, setup, ui->cbp_Ecosystem->getSelectedEcosystem(), this->getServerType(), true ); return server; } CServer::ServerType CServerForm::getServerType() const { return ui->cb_ServerType->currentData().value(); } void CServerForm::setReadOnly(bool readOnly) { ui->le_NetworkId->setReadOnly(readOnly); ui->le_RealName->setReadOnly(readOnly); ui->le_Name->setReadOnly(readOnly); ui->le_Description->setReadOnly(readOnly); ui->le_Address->setReadOnly(readOnly); ui->le_Port->setReadOnly(readOnly); ui->le_Password->setReadOnly(readOnly); ui->form_ServerFsd->setReadOnly(readOnly); ui->cb_ServerType->setEnabled(!readOnly); ui->cbp_Ecosystem->setEnabled(!readOnly); this->forceStyleSheetUpdate(); } void CServerForm::showPasswordField(bool show) { if (ui->le_Password->isVisible() == show) { return; } if (m_passwordNameLabel.isEmpty()) { m_passwordNameLabel = ui->lbl_IdPassword->text(); } ui->lbl_IdPassword->setText(show ? m_passwordNameLabel : "Id"); ui->le_Password->setVisible(show); } void CServerForm::initServerTypes() { // init all server type values int c = 0; ui->cb_ServerType->clear(); for (const int type : CServer::allServerTypes()) { const CServer::ServerType st = static_cast(type); ui->cb_ServerType->insertItem(c++, CServer::serverTypeToString(st), QVariant::fromValue(type)); } } void CServerForm::onChangedServerType(const QString &text) { Q_UNUSED(text); const CServer::ServerType t = this->getServerType(); const CServer dummy(t); const CEcosystem es = dummy.getEcosystem(); if (es.isUnspecified()) { return; } if (es.isSystem(CEcosystem::NoSystem)) { return; } ui->cbp_Ecosystem->setCurrentEcosystem(es); } void CServerForm::onChangedEcoSystem(const QString &text) { Q_UNUSED(text); const CEcosystem es = ui->cbp_Ecosystem->getSelectedEcosystem(); const CServer dummy(es); if (dummy.hasUnspecifiedServerType()) { return; } ui->cb_ServerType->setCurrentText(dummy.getServerTypeAsString()); } BlackMisc::CStatusMessageList CServerForm::validate(bool nested) const { Q_UNUSED(nested); const CServer server = getServer(); return server.validate(); } } // ns } // ns