refs #288, a server form used in login screen and settings

This commit is contained in:
Klaus Basan
2014-11-15 01:33:20 +01:00
committed by Roland Winklmeier
parent c6d14c31fd
commit 2a831f8252
3 changed files with 302 additions and 0 deletions

View File

@@ -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

57
src/blackgui/serverform.h Normal file
View File

@@ -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 <QFrame>
#include <QScopedPointer>
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::CNetworkServerForm> ui;
};
}
#endif // guard

163
src/blackgui/serverform.ui Normal file
View File

@@ -0,0 +1,163 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CNetworkServerForm</class>
<widget class="QFrame" name="CNetworkServerForm">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>206</width>
<height>190</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_NetworkServerForm">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QFormLayout" name="fl_NetworkServer">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="lbl_Name">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_Name">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_Description">
<property name="text">
<string>Description</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="le_Description"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_Address">
<property name="text">
<string>Address</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="le_Address"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_Port">
<property name="text">
<string>Port</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="le_Port">
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_RealName">
<property name="text">
<string>Real name</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="le_RealName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="lbl_NetworkId">
<property name="text">
<string>Id:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="le_NetworkId">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lbl_Password">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="le_Password">
<property name="text">
<string/>
</property>
<property name="maxLength">
<number>32</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>