Skip to content

Commit

Permalink
discovery: Add discoverable switch
Browse files Browse the repository at this point in the history
  • Loading branch information
yvbbrjdr committed Apr 11, 2021
1 parent cb2edf1 commit 53ff391
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
2 changes: 2 additions & 0 deletions LANDrop/discoveryservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void DiscoveryService::refresh()

void DiscoveryService::sendInfo(const QHostAddress &addr, quint16 port)
{
if (!Settings::discoverable())
return;
QJsonObject obj;
obj.insert("request", false);
obj.insert("machine_name", Settings::machineName());
Expand Down
Binary file modified LANDrop/locales/LANDrop.zh_CN.qm
Binary file not shown.
7 changes: 6 additions & 1 deletion LANDrop/locales/LANDrop.zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,12 @@ Would you like to receive it?</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="60"/>
<location filename="../settingsdialog.ui" line="57"/>
<source>Discoverable</source>
<translation>可被发现</translation>
</message>
<message>
<location filename="../settingsdialog.cpp" line="61"/>
<source>Select Download Path</source>
<translation>选择下载路径</translation>
</message>
Expand Down
10 changes: 10 additions & 0 deletions LANDrop/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ QString Settings::downloadPath()
return QSettings().value("downloadPath", d).toString();
}

bool Settings::discoverable()
{
return QSettings().value("discoverable", true).toBool();
}

void Settings::setMachineName(const QString &machineName)
{
QSettings().setValue("machineName", machineName);
Expand All @@ -60,3 +65,8 @@ void Settings::setDownloadPath(const QString &downloadPath)
{
QSettings().setValue("downloadPath", downloadPath);
}

void Settings::setDiscoverable(bool discoverable)
{
QSettings().setValue("discoverable", discoverable);
}
2 changes: 2 additions & 0 deletions LANDrop/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Settings {
public:
static QString machineName();
static QString downloadPath();
static bool discoverable();
static void setMachineName(const QString &machineName);
static void setDownloadPath(const QString &downloadPath);
static void setDiscoverable(bool discoverable);
};
2 changes: 2 additions & 0 deletions LANDrop/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void SettingsDialog::accept()
{
Settings::setMachineName(ui->machineNameLineEdit->text());
Settings::setDownloadPath(ui->downloadPathLineEdit->text());
Settings::setDiscoverable(ui->discoverableCheckBox->isChecked());
done(Accepted);
}

Expand All @@ -68,5 +69,6 @@ void SettingsDialog::showEvent(QShowEvent *e)
QDialog::showEvent(e);
ui->machineNameLineEdit->setText(Settings::machineName());
ui->downloadPathLineEdit->setText(Settings::downloadPath());
ui->discoverableCheckBox->setChecked(Settings::discoverable());
ui->machineNameLineEdit->setFocus();
}
16 changes: 15 additions & 1 deletion LANDrop/settingsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>115</height>
<height>133</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -51,6 +51,20 @@
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="discoverableLabel">
<property name="text">
<string>Discoverable</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QCheckBox" name="discoverableCheckBox">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 53ff391

Please sign in to comment.