-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcline.cpp
125 lines (101 loc) · 2.42 KB
/
cline.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "cline.h"
#include <QRegExp>
CLine::CLine(QString server, int port, QString username, QString password)
{
setServer(server);
setPort(port);
setUsername(username);
setPassword(password);
}
QString CLine::toString() const
{
return QString("C: %1 %2 %3 %4").arg(getServer()).arg(getPort()).arg(getUsername()).arg(getPassword());
}
bool CLine::sortOnServerAsc(const CLine &cline1, const CLine &cline2)
{
return cline1.getServer() < cline2.getServer();
}
bool CLine::sortOnServerDesc(const CLine &cline1, const CLine &cline2)
{
return !sortOnServerAsc(cline1, cline2);
}
bool CLine::sortOnPortAsc(const CLine &cline1, const CLine &cline2)
{
return cline1.getPort() < cline2.getPort();
}
bool CLine::sortOnPortDesc(const CLine &cline1, const CLine &cline2)
{
return !sortOnPortAsc(cline1, cline2);
}
bool CLine::sortOnUsernameAsc(const CLine &cline1, const CLine &cline2)
{
return cline1.getUsername() < cline2.getUsername();
}
bool CLine::sortOnUsernameDesc(const CLine &cline1, const CLine &cline2)
{
return !sortOnUsernameAsc(cline1, cline2);
}
bool CLine::sortOnPasswordAsc(const CLine &cline1, const CLine &cline2)
{
return cline1.getPassword() < cline2.getPassword();
}
bool CLine::sortOnPasswordDesc(const CLine &cline1, const CLine &cline2)
{
return !sortOnPasswordAsc(cline1, cline2);
}
bool CLine::isServerValid(QString server)
{
QRegExp re("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$");
return re.exactMatch(server);
}
bool CLine::isPortValid(int port)
{
return port > 0 && port < 65536;
}
bool CLine::isUsernameValid(QString username)
{
QRegExp re("^.{3,20}$");
return re.exactMatch(username);
}
bool CLine::isPasswordValid(QString password)
{
QRegExp re("^.{3,20}$");
return re.exactMatch(password);
}
QDebug operator<<(QDebug dbg, const CLine &cline)
{
dbg << cline.toString();
return dbg;
}
int CLine::getPort() const
{
return port;
}
void CLine::setPort(int value)
{
port = value;
}
QString CLine::getPassword() const
{
return password;
}
void CLine::setPassword(const QString &value)
{
password = value;
}
QString CLine::getUsername() const
{
return username;
}
void CLine::setUsername(const QString &value)
{
username = value;
}
QString CLine::getServer() const
{
return server;
}
void CLine::setServer(const QString &value)
{
server = value;
}