-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathtelegramhost.cpp
119 lines (97 loc) · 2.21 KB
/
telegramhost.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
#include "telegramhost.h"
#include <QDebug>
class TelegramHostPrivate
{
public:
QString hostAddress;
qint32 hostPort;
qint32 hostDcId;
QUrl publicKey;
bool valid;
};
TelegramHost::TelegramHost(QObject *parent) :
QObject(parent)
{
p = new TelegramHostPrivate;
p->hostPort = 0;
p->hostDcId = 0;
p->valid = false;
p->publicKey = QUrl("qrc:/files/tg-server.pub");
}
QString TelegramHost::hostAddress() const
{
return p->hostAddress;
}
void TelegramHost::setHostAddress(const QString &hostAddress)
{
if(p->hostAddress == hostAddress)
return;
p->hostAddress = hostAddress;
Q_EMIT hostAddressChanged();
refreshValid();
}
qint32 TelegramHost::hostPort() const
{
return p->hostPort;
}
void TelegramHost::setHostPort(qint32 hostPort)
{
if(p->hostPort == hostPort)
return;
p->hostPort = hostPort;
Q_EMIT hostPortChanged();
refreshValid();
}
qint32 TelegramHost::hostDcId() const
{
return p->hostDcId;
}
void TelegramHost::setHostDcId(qint32 hostDcId)
{
if(p->hostDcId == hostDcId)
return;
p->hostDcId = hostDcId;
Q_EMIT hostDcIdChanged();
refreshValid();
}
QUrl TelegramHost::publicKey() const
{
return p->publicKey;
}
void TelegramHost::setPublicKey(const QUrl &publicKey)
{
if(p->publicKey == publicKey)
return;
p->publicKey = publicKey;
if(p->publicKey.isValid() && !p->publicKey.isLocalFile())
qDebug() << "Error: The public key is not a local file.";
Q_EMIT publicKeyChanged();
refreshValid();
}
bool TelegramHost::isValid() const
{
return p->hostDcId && p->hostPort &&
!p->hostAddress.isEmpty() &&
p->publicKey.isValid();
}
QStringList TelegramHost::requiredProperties()
{
return QStringList() << FUNCTION_NAME(hostDcId)
<< FUNCTION_NAME(hostPort)
<< FUNCTION_NAME(hostAddress)
<< FUNCTION_NAME(publicKey);
}
void TelegramHost::refreshValid()
{
const bool valid = isValid();
if(valid == p->valid)
return;
p->valid = valid;
Q_EMIT isValidChanged();
}
TelegramHost::~TelegramHost()
{
p->hostAddress.clear();
refreshValid();
delete p;
}