From 2a831f8252992442b0a7adc5d142442444ac9905 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 15 Nov 2014 01:33:20 +0100 Subject: [PATCH] refs #288, a server form used in login screen and settings --- src/blackgui/serverform.cpp | 82 ++++++++++++++++++ src/blackgui/serverform.h | 57 +++++++++++++ src/blackgui/serverform.ui | 163 ++++++++++++++++++++++++++++++++++++ 3 files changed, 302 insertions(+) create mode 100644 src/blackgui/serverform.cpp create mode 100644 src/blackgui/serverform.h create mode 100644 src/blackgui/serverform.ui diff --git a/src/blackgui/serverform.cpp b/src/blackgui/serverform.cpp new file mode 100644 index 000000000..744d1f8d2 --- /dev/null +++ b/src/blackgui/serverform.cpp @@ -0,0 +1,82 @@ +/* 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 "serverform.h" +#include "ui_serverform.h" + +using namespace BlackMisc::Network; + +namespace BlackGui +{ + + CServerForm::CServerForm(QWidget *parent) : + QFrame(parent), + ui(new Ui::CNetworkServerForm) + { + ui->setupUi(this); + this->ui->le_Port->setValidator(new QIntValidator(1, 65535, this)); + } + + CServerForm::~CServerForm() + { } + + void CServerForm::setServer(const CServer &server) + { + CUser user = server.getUser(); + this->ui->le_NetworkId->setText(user.getId()); + this->ui->le_RealName->setText(user.getRealName()); + this->ui->le_Name->setText(server.getName()); + this->ui->le_Password->setText(user.getPassword()); + this->ui->le_Description->setText(server.getDescription()); + this->ui->le_Address->setText(server.getAddress()); + this->ui->le_Port->setText(QString::number(server.getPort())); + } + + BlackMisc::Network::CServer CServerForm::getServer() const + { + CUser user( + this->ui->le_NetworkId->text().trimmed(), + this->ui->le_RealName->text().trimmed().simplified(), + "", + this->ui->le_Password->text().trimmed() + ); + CServer server( + this->ui->le_Name->text().trimmed().simplified(), + this->ui->le_Description->text().trimmed().simplified(), + this->ui->le_Address->text().trimmed(), + this->ui->le_Port->text().trimmed().toInt(), + user + ); + return server; + } + + void CServerForm::setReadOnly(bool readOnly) + { + this->ui->le_NetworkId->setReadOnly(readOnly); + this->ui->le_RealName->setReadOnly(readOnly); + this->ui->le_Name->setReadOnly(readOnly); + this->ui->le_Description->setReadOnly(readOnly); + this->ui->le_Address->setReadOnly(readOnly); + this->ui->le_Port->setReadOnly(readOnly); + this->ui->le_Password->setReadOnly(readOnly); + } + + void CServerForm::showPasswordField(bool show) + { + this->ui->lbl_Password->setVisible(show); + this->ui->le_Password->setVisible(show); + } + + BlackMisc::CStatusMessageList CServerForm::validate() const + { + CServer server = getServer(); + return server.validate(); + } + +} // namespace diff --git a/src/blackgui/serverform.h b/src/blackgui/serverform.h new file mode 100644 index 000000000..587a7afa9 --- /dev/null +++ b/src/blackgui/serverform.h @@ -0,0 +1,57 @@ +/* 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. + */ + +//! \file + +#ifndef BLACKGUI_NETWORKSERVERFORM_H +#define BLACKGUI_NETWORKSERVERFORM_H + +#include "blackmisc/nwserver.h" +#include "blackmisc/statusmessagelist.h" +#include +#include + +namespace Ui { class CNetworkServerForm; } + +namespace BlackGui +{ + +//! Server form + class CServerForm : public QFrame + { + Q_OBJECT + + public: + //! Constructor + explicit CServerForm(QWidget *parent = nullptr); + + //! Destructor + ~CServerForm(); + + //! Set server + void setServer(const BlackMisc::Network::CServer &server); + + //! Get server + BlackMisc::Network::CServer getServer() const; + + //! Set read only + void setReadOnly(bool readOnly); + + //! Show the password field + void showPasswordField(bool show); + + //! Validate and provide messages (empty means OK) + BlackMisc::CStatusMessageList validate() const; + + private: + QScopedPointer ui; + }; +} + +#endif // guard diff --git a/src/blackgui/serverform.ui b/src/blackgui/serverform.ui new file mode 100644 index 000000000..31c27a643 --- /dev/null +++ b/src/blackgui/serverform.ui @@ -0,0 +1,163 @@ + + + CNetworkServerForm + + + + 0 + 0 + 206 + 190 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QFormLayout::AllNonFixedFieldsGrow + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Name + + + + + + + + + + + + + + Description + + + + + + + + + + Address + + + + + + + + + + Port + + + + + + + 5 + + + + + + + Real name + + + + + + + + + + + + + + Id: + + + + + + + + + + + + + + Password + + + + + + + + + + 32 + + + QLineEdit::Password + + + + + + + + + +