mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-08 08:28:39 +00:00
feat: add Port history record feature
- Implement Port history storage - Ensure unique Port entries in history - Remove empty ip history config Log: Add the ability to save the history of previously connected ports when using wireless connections.
This commit is contained in:
parent
cd63e84f4e
commit
f0a500bfc0
5 changed files with 123 additions and 13 deletions
|
@ -168,12 +168,22 @@ void Dialog::initUI()
|
||||||
// 加载IP历史记录
|
// 加载IP历史记录
|
||||||
loadIpHistory();
|
loadIpHistory();
|
||||||
|
|
||||||
|
// 加载端口历史记录
|
||||||
|
loadPortHistory();
|
||||||
|
|
||||||
// 为deviceIpEdt添加右键菜单
|
// 为deviceIpEdt添加右键菜单
|
||||||
if (ui->deviceIpEdt->lineEdit()) {
|
if (ui->deviceIpEdt->lineEdit()) {
|
||||||
ui->deviceIpEdt->lineEdit()->setContextMenuPolicy(Qt::CustomContextMenu);
|
ui->deviceIpEdt->lineEdit()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
connect(ui->deviceIpEdt->lineEdit(), &QWidget::customContextMenuRequested,
|
connect(ui->deviceIpEdt->lineEdit(), &QWidget::customContextMenuRequested,
|
||||||
this, &Dialog::showIpEditMenu);
|
this, &Dialog::showIpEditMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 为devicePortEdt添加右键菜单
|
||||||
|
if (ui->devicePortEdt->lineEdit()) {
|
||||||
|
ui->devicePortEdt->lineEdit()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
connect(ui->devicePortEdt->lineEdit(), &QWidget::customContextMenuRequested,
|
||||||
|
this, &Dialog::showPortEditMenu);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::updateBootConfig(bool toView)
|
void Dialog::updateBootConfig(bool toView)
|
||||||
|
@ -361,12 +371,14 @@ void Dialog::on_wirelessConnectBtn_clicked()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString addr = ui->deviceIpEdt->currentText().trimmed();
|
QString addr = ui->deviceIpEdt->currentText().trimmed();
|
||||||
if (!ui->devicePortEdt->text().isEmpty()) {
|
if (addr.isEmpty()) {
|
||||||
|
outLog("error: device ip is null", false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ui->devicePortEdt->currentText().isEmpty()) {
|
||||||
addr += ":";
|
addr += ":";
|
||||||
addr += ui->devicePortEdt->text().trimmed();
|
addr += ui->devicePortEdt->currentText().trimmed();
|
||||||
} else if (!ui->devicePortEdt->placeholderText().isEmpty()) {
|
|
||||||
addr += ":";
|
|
||||||
addr += ui->devicePortEdt->placeholderText().trimmed();
|
|
||||||
} else {
|
} else {
|
||||||
outLog("error: device port is null", false);
|
outLog("error: device port is null", false);
|
||||||
return;
|
return;
|
||||||
|
@ -377,6 +389,12 @@ void Dialog::on_wirelessConnectBtn_clicked()
|
||||||
if (!ip.isEmpty()) {
|
if (!ip.isEmpty()) {
|
||||||
saveIpHistory(ip);
|
saveIpHistory(ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存端口历史记录
|
||||||
|
QString port = addr.split(":").last();
|
||||||
|
if (!port.isEmpty() && port != ip) {
|
||||||
|
savePortHistory(port);
|
||||||
|
}
|
||||||
|
|
||||||
outLog("wireless connect...", false);
|
outLog("wireless connect...", false);
|
||||||
QStringList adbArgs;
|
QStringList adbArgs;
|
||||||
|
@ -831,3 +849,45 @@ void Dialog::showIpEditMenu(const QPoint &pos)
|
||||||
menu->exec(ui->deviceIpEdt->lineEdit()->mapToGlobal(pos));
|
menu->exec(ui->deviceIpEdt->lineEdit()->mapToGlobal(pos));
|
||||||
delete menu;
|
delete menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dialog::loadPortHistory()
|
||||||
|
{
|
||||||
|
QStringList portList = Config::getInstance().getPortHistory();
|
||||||
|
ui->devicePortEdt->clear();
|
||||||
|
ui->devicePortEdt->addItems(portList);
|
||||||
|
ui->devicePortEdt->setContentsMargins(0, 0, 0, 0);
|
||||||
|
|
||||||
|
if (ui->devicePortEdt->lineEdit()) {
|
||||||
|
ui->devicePortEdt->lineEdit()->setMaxLength(6);
|
||||||
|
ui->devicePortEdt->lineEdit()->setPlaceholderText("5555");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dialog::savePortHistory(const QString &port)
|
||||||
|
{
|
||||||
|
if (port.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Config::getInstance().savePortHistory(port);
|
||||||
|
|
||||||
|
// 更新ComboBox
|
||||||
|
loadPortHistory();
|
||||||
|
ui->devicePortEdt->setCurrentText(port);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dialog::showPortEditMenu(const QPoint &pos)
|
||||||
|
{
|
||||||
|
QMenu *menu = ui->devicePortEdt->lineEdit()->createStandardContextMenu();
|
||||||
|
menu->addSeparator();
|
||||||
|
|
||||||
|
QAction *clearHistoryAction = new QAction(tr("Clear History"), menu);
|
||||||
|
connect(clearHistoryAction, &QAction::triggered, this, [this]() {
|
||||||
|
Config::getInstance().clearPortHistory();
|
||||||
|
loadPortHistory();
|
||||||
|
});
|
||||||
|
|
||||||
|
menu->addAction(clearHistoryAction);
|
||||||
|
menu->exec(ui->devicePortEdt->lineEdit()->mapToGlobal(pos));
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
|
|
|
@ -82,6 +82,10 @@ private:
|
||||||
const QString &getServerPath();
|
const QString &getServerPath();
|
||||||
void loadIpHistory();
|
void loadIpHistory();
|
||||||
void saveIpHistory(const QString &ip);
|
void saveIpHistory(const QString &ip);
|
||||||
|
void loadPortHistory();
|
||||||
|
void savePortHistory(const QString &port);
|
||||||
|
|
||||||
|
void showPortEditMenu(const QPoint &pos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
|
@ -1094,22 +1094,25 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="devicePortEdt">
|
<widget class="QComboBox" name="devicePortEdt">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
|
||||||
<horstretch>0</horstretch>
|
<horstretch>0</horstretch>
|
||||||
<verstretch>0</verstretch>
|
<verstretch>0</verstretch>
|
||||||
</sizepolicy>
|
</sizepolicy>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>100</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="currentText">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="maxLength">
|
|
||||||
<number>6</number>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string notr="true">5555</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -116,6 +116,11 @@
|
||||||
#define IP_HISTORY_DEF ""
|
#define IP_HISTORY_DEF ""
|
||||||
#define IP_HISTORY_MAX 10
|
#define IP_HISTORY_MAX 10
|
||||||
|
|
||||||
|
// Port history
|
||||||
|
#define PORT_HISTORY_KEY "PortHistory"
|
||||||
|
#define PORT_HISTORY_DEF ""
|
||||||
|
#define PORT_HISTORY_MAX 10
|
||||||
|
|
||||||
QString Config::s_configPath = "";
|
QString Config::s_configPath = "";
|
||||||
|
|
||||||
Config::Config(QObject *parent) : QObject(parent)
|
Config::Config(QObject *parent) : QObject(parent)
|
||||||
|
@ -412,6 +417,7 @@ void Config::saveIpHistory(const QString &ip)
|
||||||
QStringList Config::getIpHistory()
|
QStringList Config::getIpHistory()
|
||||||
{
|
{
|
||||||
QStringList ipList = m_userData->value(IP_HISTORY_KEY, IP_HISTORY_DEF).toStringList();
|
QStringList ipList = m_userData->value(IP_HISTORY_KEY, IP_HISTORY_DEF).toStringList();
|
||||||
|
ipList.removeAll("");
|
||||||
return ipList;
|
return ipList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,3 +426,35 @@ void Config::clearIpHistory()
|
||||||
m_userData->remove(IP_HISTORY_KEY);
|
m_userData->remove(IP_HISTORY_KEY);
|
||||||
m_userData->sync();
|
m_userData->sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Config::savePortHistory(const QString &port)
|
||||||
|
{
|
||||||
|
QStringList portList = getPortHistory();
|
||||||
|
|
||||||
|
// 移除已存在的相同Port(避免重复)
|
||||||
|
portList.removeAll(port);
|
||||||
|
|
||||||
|
// 将新Port添加到开头
|
||||||
|
portList.prepend(port);
|
||||||
|
|
||||||
|
// 限制历史记录数量
|
||||||
|
while (portList.size() > PORT_HISTORY_MAX) {
|
||||||
|
portList.removeLast();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_userData->setValue(PORT_HISTORY_KEY, portList);
|
||||||
|
m_userData->sync();
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList Config::getPortHistory()
|
||||||
|
{
|
||||||
|
QStringList portList = m_userData->value(PORT_HISTORY_KEY, PORT_HISTORY_DEF).toStringList();
|
||||||
|
portList.removeAll("");
|
||||||
|
return portList;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::clearPortHistory()
|
||||||
|
{
|
||||||
|
m_userData->remove(PORT_HISTORY_KEY);
|
||||||
|
m_userData->sync();
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,11 @@ public:
|
||||||
QStringList getIpHistory();
|
QStringList getIpHistory();
|
||||||
void clearIpHistory();
|
void clearIpHistory();
|
||||||
|
|
||||||
|
// Port history methods
|
||||||
|
void savePortHistory(const QString &port);
|
||||||
|
QStringList getPortHistory();
|
||||||
|
void clearPortHistory();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
explicit Config(QObject *parent = nullptr);
|
explicit Config(QObject *parent = nullptr);
|
||||||
const QString &getConfigPath();
|
const QString &getConfigPath();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue