Skip to content

Commit

Permalink
discoverable: Remove an entry when device goes undiscoverable
Browse files Browse the repository at this point in the history
  • Loading branch information
yvbbrjdr committed Apr 23, 2021
1 parent 8a063c9 commit d8239c9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
4 changes: 1 addition & 3 deletions LANDrop/discoveryservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ void DiscoveryService::refresh()

void DiscoveryService::sendInfo(const QHostAddress &addr, quint16 port)
{
if (!Settings::discoverable())
return;
QJsonObject obj;
obj.insert("request", false);
obj.insert("device_name", Settings::deviceName());
obj.insert("device_type", QSysInfo::productType());
obj.insert("port", serverPort);
obj.insert("port", Settings::discoverable() ? serverPort : 0);
socket.writeDatagram(QJsonDocument(obj).toJson(QJsonDocument::Compact), addr, port);
}

Expand Down
4 changes: 2 additions & 2 deletions LANDrop/locales/LANDrop.zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ Would you like to receive it?</source>
<translation>端口</translation>
</message>
<message>
<location filename="../sendtodialog.cpp" line="101"/>
<location filename="../sendtodialog.cpp" line="112"/>
<source>Invalid port. Please enter a number between 1 and 65535.</source>
<translation>无效端口。请输入一个 1 到 65535 的数字。</translation>
</message>
<message>
<location filename="../sendtodialog.cpp" line="146"/>
<location filename="../sendtodialog.cpp" line="157"/>
<source>Connection timed out</source>
<translation>连接超时</translation>
</message>
Expand Down
11 changes: 11 additions & 0 deletions LANDrop/sendtodialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ SendToDialog::~SendToDialog()
void SendToDialog::newHost(const QString &deviceName, const QHostAddress &addr, quint16 port)
{
QStringList l = hostsStringListModel.stringList();
if (port == 0) {
for (int i = 0; i < endpoints.size(); ++i) {
if (endpoints[i].addr.isEqual(addr)) {
endpoints.removeAt(i);
l.removeAt(i);
hostsStringListModel.setStringList(l);
return;
}
}
return;
}
for (int i = 0; i < endpoints.size(); ++i) {
if (endpoints[i].addr.isEqual(addr)) {
if (l.at(i) != deviceName) {
Expand Down

0 comments on commit d8239c9

Please sign in to comment.