-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcandyitem.cc
More file actions
58 lines (51 loc) · 1.84 KB
/
Copy pathcandyitem.cc
File metadata and controls
58 lines (51 loc) · 1.84 KB
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
#include "candyitem.h"
#include "candy/candy.h"
#include <Poco/JSON/Object.h>
#include <Poco/JSON/Stringifier.h>
#include <QSettings>
CandyItem::CandyItem(const QString &name)
: m_name(name)
, id(name.toStdString()) {}
CandyItem::~CandyItem()
{
if (started) {
candy::client::shutdown(id);
if (clientThread.joinable()) {
clientThread.join();
}
}
}
void CandyItem::update()
{
QSettings settings;
QString vmac = settings.value("vmac").toString();
settings.beginGroup(m_name);
Poco::JSON::Object config;
config.set("name", id);
config.set("vmac", vmac.toStdString());
config.set("password", settings.value("password").toString().toStdString());
config.set("websocket", settings.value("websocket").toString().toStdString());
config.set("tun", settings.value("tun").toString().toStdString());
config.set("stun", settings.value("stun").toString().toStdString());
config.set("discovery", settings.value("discovery", "300").toInt());
config.set("route", settings.value("route", "5").toInt());
config.set("port", settings.value("port", "0").toInt());
config.set("localhost", settings.value("localhost").toString().toStdString());
config.set("mtu", settings.value("mtu", "1400").toInt());
QString expt = settings.value("expt", settings.value("expected")).toString();
config.set("expt", expt.toStdString());
if (settings.contains("expected") && !settings.contains("expt")) {
settings.setValue("expt", settings.value("expected"));
settings.remove("expected");
}
settings.endGroup();
settings.sync();
if (started) {
candy::client::shutdown(id);
if (clientThread.joinable()) {
clientThread.join();
}
}
started = true;
clientThread = std::thread([=]() { candy::client::run(id, config); });
}