-
Notifications
You must be signed in to change notification settings - Fork 0
/
addserverdialog.cpp
executable file
·82 lines (65 loc) · 2.27 KB
/
addserverdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* This file is part of community judge client project developed by Shervin Kh.
* Copyright (C) 2014 Shervin Kh.
* License: GPLv3 Or Later
* Full license could be found in License file shipped with program or at http://www.gnu.org/licenses/
*/
#include "addserverdialog.h"
#include <QtGui>
#if QT_VERSION >= 0x050000
#include <QtWidgets>
#endif
AddServerDialog::AddServerDialog(QWidget *parent) :
QDialog(parent)
{
nameLabel = new QLabel("Name: ");
nameLE = new QLineEdit;
nameLabel->setBuddy(nameLE);
addressLabel = new QLabel("Address: ");
addressLE = new QLineEdit;
addressLabel->setBuddy(addressLE);
portLabel = new QLabel("Port: ");
portLE = new QLineEdit;
portLabel->setBuddy(portLE);
portLE->setValidator(new QIntValidator(1, 65535));
sslCheck = new QCheckBox("SSL");
fields = new QGridLayout;
fields->addWidget(nameLabel, 0, 0);
fields->addWidget(nameLE, 0, 1);
fields->addWidget(addressLabel, 1, 0);
fields->addWidget(addressLE, 1, 1);
fields->addWidget(portLabel, 2, 0);
fields->addWidget(portLE, 2, 1);
connect(nameLE, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
connect(addressLE, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
connect(portLE, SIGNAL(textChanged(QString)), this, SLOT(validateForm()));
buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
totalLayout = new QVBoxLayout;
totalLayout->addLayout(fields);
totalLayout->addWidget(sslCheck);
totalLayout->addWidget(buttonBox);
setLayout(totalLayout);
validateForm();
}
QString AddServerDialog::name() const
{
return nameLE->text();
}
QUrl AddServerDialog::url() const
{
QUrl URL;
URL.setHost(addressLE->text());
URL.setPort(portLE->text().toInt());
if (sslCheck->isChecked())
URL.setScheme("ssl");
else
URL.setScheme("tcp");
return URL;
}
void AddServerDialog::validateForm()
{
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(!nameLE->text().isEmpty() && !addressLE->text().isEmpty()
&& !portLE->text().isEmpty());
}