Skip to content

Commit

Permalink
Support 'Max bitreate' setting
Browse files Browse the repository at this point in the history
  • Loading branch information
numbaa committed Mar 25, 2024
1 parent d6eeb2c commit 035f15c
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 47 deletions.
97 changes: 54 additions & 43 deletions app/i18n/lt-zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,78 +43,78 @@
<translation type="vanished">连接已断开</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="290"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="295"/>
<source>New Connection</source>
<translation>连接请求</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="292"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="297"/>
<source>Device %s is requesting connection</source>
<translation>设备 %s 正在请求连接</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="296"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="301"/>
<source>Accept</source>
<translation>同意</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="298"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="303"/>
<source>Accept, as well as next time</source>
<translation>同意,下次不再提醒</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="299"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="304"/>
<source>Reject</source>
<translation>拒绝</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="464"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="469"/>
<source>The new version %s has been released, please download it&lt;br&gt;from &lt;a href=&apos;%s&apos;&gt;Github&lt;/a&gt;.</source>
<translation>新版本%s已经发布,请到&lt;a href=&apos;%s&apos;&gt;Github&lt;/a&gt;或QQ群89746161下载。</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="472"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="477"/>
<source>Version: </source>
<translation>版本: </translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="474"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="479"/>
<source>Released date: </source>
<translation>发布日期: </translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="475"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="480"/>
<source>New features:</source>
<translation>新特性:</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="481"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="486"/>
<source>Bug fix:</source>
<translation>修复:</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="458"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="489"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="463"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="494"/>
<source>New Version</source>
<translation>新版本</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="450"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="455"/>
<source>The new version %s has been released, this is a force update version, please download it from &lt;a href=&apos;%s&apos;&gt;Github&lt;/a&gt;.</source>
<translation>新版本%s已经发布,该版本与旧版不兼容,请到&lt;a href=&apos;%s&apos;&gt;Github&lt;/a&gt;或QQ群89746161下载。</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="688"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="719"/>
<source>🟢Connected to server</source>
<translation>🟢已连接服务器</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="700"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="731"/>
<source>🔴Disconnected from server</source>
<translation>🔴与服务器断开</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="711"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="742"/>
<source>🟢Controlled module up</source>
<translation>🟢被控模块正常</translation>
</message>
Expand All @@ -123,49 +123,49 @@
<translation type="vanished">🟡正在启动被控模块</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="715"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="746"/>
<source>🔴Controlled module down</source>
<translation>🔴被控模块掉线</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="734"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="765"/>
<source>gamepad</source>
<translation>手柄</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="735"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="766"/>
<source>keyboard</source>
<translation>键盘</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="736"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="767"/>
<source>mouse</source>
<translation>鼠标</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="737"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="768"/>
<source>audio</source>
<translation>声音</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="738"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="769"/>
<source>kick</source>
<translation>断开</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="892"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="923"/>
<source>DeviceID or AccessToken invalid</source>
<translation>设备码或验证码错误</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="1032"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="1063"/>
<source>delete</source>
<translation>删除</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="14"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="233"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2163"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2208"/>
<source>Lanthing</source>
<translation></translation>
</message>
Expand Down Expand Up @@ -271,8 +271,9 @@
<location filename="../src/views/mainwindow/mainwindow.ui" line="1776"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1868"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1913"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1987"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2048"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1958"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2032"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2093"/>
<source>Confirm</source>
<translation>确认</translation>
</message>
Expand All @@ -281,7 +282,7 @@
<translation type="vanished">鼠标模式(暂不生效)</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="694"/>
<location filename="../src/views/mainwindow/mainwindow.cpp" line="725"/>
<source>🟡Connecting...</source>
<translation>🟡正在连接服务器</translation>
</message>
Expand Down Expand Up @@ -370,24 +371,34 @@
<translation></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1926"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1944"/>
<source>Max Mbps</source>
<translation>最大码率Mbps</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1951"/>
<source>1-100</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1971"/>
<source>Misc</source>
<translation>杂项</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1959"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2004"/>
<source>Status Color</source>
<translation>状态颜色</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1966"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1973"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="1980"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2011"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2018"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2025"/>
<source>0-255</source>
<translation></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2034"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2079"/>
<source>Mouse Accel</source>
<translation>鼠标加速</translation>
</message>
Expand All @@ -396,47 +407,47 @@
<translation type="vanished">鼠标加速</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2041"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2086"/>
<source>0.1-3.0</source>
<translation></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2097"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2142"/>
<source>Shotcut key</source>
<translation>快捷键</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2106"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2151"/>
<source>Switch Fullscreen</source>
<translation>切换全屏</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2113"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2158"/>
<source>Win+Shift+Z</source>
<translation></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2124"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2169"/>
<source>Mouse mode</source>
<translation>鼠标模式</translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2131"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2176"/>
<source>Win+Shift+X</source>
<translation></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2170"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2215"/>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Lanthing is a remote control tool created by &lt;a href=&quot;https://github.com/pjlt&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;Project Lanthing&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2195"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2240"/>
<source>License</source>
<translation></translation>
</message>
<message>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2202"/>
<location filename="../src/views/mainwindow/mainwindow.ui" line="2247"/>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Lanthing release under &lt;a href=&quot;https://github.com/pjlt/lanthing-pc/blob/master/LICENSE&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;BSD-3-Clause license&lt;/span&gt;&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;Thirdparty software licenses are listed in&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/pjlt/lanthing-pc/blob/master/third-party-licenses.txt&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#007af4;&quot;&gt;https://github.com/pjlt/lanthing-pc/blob/master/third-party-licenses.txt&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation type="unfinished"></translation>
</message>
Expand Down
8 changes: 8 additions & 0 deletions app/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ bool App::init() {
ignored_nic_ = settings_->getString("ignored_nic").value_or("");
enable_444_ = settings_->getBoolean("enable_444").value_or(false);
enable_tcp_ = settings_->getBoolean("enable_tcp").value_or(false);
max_mbps_ = static_cast<uint32_t>(settings_->getInteger("max_mbps").value_or(0));

std::optional<std::string> access_token = settings_->getString("access_token");
if (access_token.has_value()) {
Expand Down Expand Up @@ -185,6 +186,7 @@ int App::exec(int argc, char** argv) {
params.set_ignored_nic = std::bind(&App::setIgnoredNIC, this, std::placeholders::_1);
params.enable_tcp = std::bind(&App::enableTCP, this, std::placeholders::_1);
params.on_clipboard_text = std::bind(&App::syncClipboardText, this, std::placeholders::_1);
params.set_max_mbps = std::bind(&App::setMaxMbps, this, std::placeholders::_1);

gui_.init(params, argc, argv);
thread_ = ltlib::BlockingThread::create(
Expand Down Expand Up @@ -240,6 +242,7 @@ GUI::Settings App::getSettings() const {
settings.rel_mouse_accel = rel_mouse_accel_;
settings.ignored_nic = ignored_nic_;
settings.tcp = enable_tcp_;
settings.max_mbps = max_mbps_;

return settings;
}
Expand Down Expand Up @@ -392,6 +395,11 @@ void App::syncClipboardText(const std::string& text) {
});
}

void App::setMaxMbps(uint32_t mbps) {
max_mbps_ = mbps;
settings_->setInteger("max_mbps", mbps);
}

void App::ioLoop(const std::function<void()>& i_am_alive) {
LOG(INFO) << "App enter io loop";
ioloop_->run(i_am_alive);
Expand Down
2 changes: 2 additions & 0 deletions app/src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class App {
void setIgnoredNIC(const std::string& nic_list);
void enableTCP(bool enable);
void syncClipboardText(const std::string& text);
void setMaxMbps(uint32_t mbps);

void createAndStartService();
void stopService();
Expand Down Expand Up @@ -153,6 +154,7 @@ class App {
std::string ignored_nic_;
bool enable_444_ = false;
bool enable_tcp_ = false;
uint32_t max_mbps_ = 0;
std::optional<bool> windowed_fullscreen_;
std::string relay_server_;
std::mt19937 rand_engine_;
Expand Down
2 changes: 2 additions & 0 deletions app/src/views/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class GUI {
std::optional<uint32_t> status_color;
uint8_t rel_mouse_accel;
std::string ignored_nic;
uint32_t max_mbps;
};

struct TrustedDevice {
Expand Down Expand Up @@ -101,6 +102,7 @@ class GUI {
std::function<void(const std::string&)> set_ignored_nic;
std::function<void(bool)> enable_tcp;
std::function<void(const std::string&)> on_clipboard_text;
std::function<void(uint32_t)> set_max_mbps;
};

public:
Expand Down
31 changes: 31 additions & 0 deletions app/src/views/mainwindow/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ MainWindow::MainWindow(const lt::GUI::Params& params, QWidget* parent)
if (!settings.ignored_nic.empty()) {
ui->leditIgnoredNIC->setText(QString::fromStdString(settings.ignored_nic));
}
ui->btnMaxMbps->setEnabled(false);
ui->leditMaxMbps->setValidator(new QIntValidator(1, 100, this));
if (settings.max_mbps != 0) {
ui->leditMaxMbps->setText(QString::number(settings.max_mbps));
}
ui->btnStatusColor->setEnabled(false);
ui->leditRed->setValidator(new QIntValidator(0, 255, this));
ui->leditGreen->setValidator(new QIntValidator(0, 255, this));
Expand Down Expand Up @@ -622,6 +627,32 @@ void MainWindow::setupOtherCallbacks() {
ui->btnPortRange->setEnabled(false);
}
});
connect(ui->leditMaxMbps, &QLineEdit::textChanged, [this](const QString& _text) {
if (_text.trimmed().isEmpty()) {
ui->btnMaxMbps->setEnabled(true);
return;
}
int mbps = _text.trimmed().toInt();
if (mbps >= 1 && mbps <= 100) {
ui->btnMaxMbps->setEnabled(true);
}
else {
ui->btnMaxMbps->setEnabled(false);
}
});
connect(ui->btnMaxMbps, &QPushButton::clicked, [this]() {
if (ui->leditMaxMbps->text().trimmed().isEmpty()) {
params_.set_max_mbps(0);
ui->btnMaxMbps->setEnabled(false);
}
else {
int mbps = ui->leditMaxMbps->text().trimmed().toInt();
if (mbps >= 1 && mbps <= 100) {
params_.set_max_mbps(static_cast<uint32_t>(mbps));
ui->btnMaxMbps->setEnabled(false);
}
}
});
connect(ui->leditIgnoredNIC, &QLineEdit::textChanged,
[this](const QString&) { ui->btnIgnoredNIC->setEnabled(true); });
connect(ui->btnIgnoredNIC, &QPushButton::clicked, [this]() {
Expand Down
Loading

0 comments on commit 035f15c

Please sign in to comment.