mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-04-19 19:15:07 +00:00
feat: add IP history record feature
- Implement IP address history storage - Add mechanism to record connection timestamps - Ensure unique IP entries in history Log: Add functionality to store and track IP address history Issue: https://github.com/barry-ran/QtScrcpy/issues/1075
This commit is contained in:
parent
224f04ffa0
commit
f5cccac0df
5 changed files with 125 additions and 13 deletions
|
@ -82,21 +82,21 @@ Dialog::Dialog(QWidget *parent) : QWidget(parent), ui(new Ui::Widget)
|
|||
log = "ip not find, connect to wifi?";
|
||||
break;
|
||||
}
|
||||
ui->deviceIpEdt->setText(ip);
|
||||
ui->deviceIpEdt->setEditText(ip);
|
||||
} else if (args.contains("ifconfig") && args.contains("wlan0")) {
|
||||
QString ip = m_adb.getDeviceIPFromStdOut();
|
||||
if (ip.isEmpty()) {
|
||||
log = "ip not find, connect to wifi?";
|
||||
break;
|
||||
}
|
||||
ui->deviceIpEdt->setText(ip);
|
||||
ui->deviceIpEdt->setEditText(ip);
|
||||
} else if (args.contains("ip -o a")) {
|
||||
QString ip = m_adb.getDeviceIPByIpFromStdOut();
|
||||
if (ip.isEmpty()) {
|
||||
log = "ip not find, connect to wifi?";
|
||||
break;
|
||||
}
|
||||
ui->deviceIpEdt->setText(ip);
|
||||
ui->deviceIpEdt->setEditText(ip);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -164,6 +164,16 @@ void Dialog::initUI()
|
|||
ui->lockOrientationBox->addItem("180");
|
||||
ui->lockOrientationBox->addItem("270");
|
||||
ui->lockOrientationBox->setCurrentIndex(0);
|
||||
|
||||
// 加载IP历史记录
|
||||
loadIpHistory();
|
||||
|
||||
// 为deviceIpEdt添加右键菜单
|
||||
if (ui->deviceIpEdt->lineEdit()) {
|
||||
ui->deviceIpEdt->lineEdit()->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(ui->deviceIpEdt->lineEdit(), &QWidget::customContextMenuRequested,
|
||||
this, &Dialog::showIpEditMenu);
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::updateBootConfig(bool toView)
|
||||
|
@ -216,6 +226,12 @@ void Dialog::updateBootConfig(bool toView)
|
|||
config.autoUpdateDevice = ui->autoUpdatecheckBox->isChecked();
|
||||
config.showToolbar = ui->showToolbar->isChecked();
|
||||
|
||||
// 保存当前IP到历史记录
|
||||
QString currentIp = ui->deviceIpEdt->currentText().trimmed();
|
||||
if (!currentIp.isEmpty()) {
|
||||
saveIpHistory(currentIp);
|
||||
}
|
||||
|
||||
Config::getInstance().setUserBootConfig(config);
|
||||
}
|
||||
}
|
||||
|
@ -344,7 +360,7 @@ void Dialog::on_wirelessConnectBtn_clicked()
|
|||
if (checkAdbRun()) {
|
||||
return;
|
||||
}
|
||||
QString addr = ui->deviceIpEdt->text().trimmed();
|
||||
QString addr = ui->deviceIpEdt->currentText().trimmed();
|
||||
if (!ui->devicePortEdt->text().isEmpty()) {
|
||||
addr += ":";
|
||||
addr += ui->devicePortEdt->text().trimmed();
|
||||
|
@ -356,6 +372,12 @@ void Dialog::on_wirelessConnectBtn_clicked()
|
|||
return;
|
||||
}
|
||||
|
||||
// 保存IP历史记录 - 只保存IP部分,不包含端口
|
||||
QString ip = addr.split(":").first();
|
||||
if (!ip.isEmpty()) {
|
||||
saveIpHistory(ip);
|
||||
}
|
||||
|
||||
outLog("wireless connect...", false);
|
||||
QStringList adbArgs;
|
||||
adbArgs << "connect";
|
||||
|
@ -516,7 +538,7 @@ void Dialog::on_wirelessDisConnectBtn_clicked()
|
|||
if (checkAdbRun()) {
|
||||
return;
|
||||
}
|
||||
QString addr = ui->deviceIpEdt->text().trimmed();
|
||||
QString addr = ui->deviceIpEdt->currentText().trimmed();
|
||||
outLog("wireless disconnect...", false);
|
||||
QStringList adbArgs;
|
||||
adbArgs << "disconnect";
|
||||
|
@ -767,3 +789,45 @@ void Dialog::on_autoUpdatecheckBox_toggled(bool checked)
|
|||
m_autoUpdatetimer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::loadIpHistory()
|
||||
{
|
||||
QStringList ipList = Config::getInstance().getIpHistory();
|
||||
ui->deviceIpEdt->clear();
|
||||
ui->deviceIpEdt->addItems(ipList);
|
||||
ui->deviceIpEdt->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
if (ui->deviceIpEdt->lineEdit()) {
|
||||
ui->deviceIpEdt->lineEdit()->setMaxLength(128);
|
||||
ui->deviceIpEdt->lineEdit()->setPlaceholderText("192.168.0.1");
|
||||
}
|
||||
}
|
||||
|
||||
void Dialog::saveIpHistory(const QString &ip)
|
||||
{
|
||||
if (ip.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Config::getInstance().saveIpHistory(ip);
|
||||
|
||||
// 更新ComboBox
|
||||
loadIpHistory();
|
||||
ui->deviceIpEdt->setCurrentText(ip);
|
||||
}
|
||||
|
||||
void Dialog::showIpEditMenu(const QPoint &pos)
|
||||
{
|
||||
QMenu *menu = ui->deviceIpEdt->lineEdit()->createStandardContextMenu();
|
||||
menu->addSeparator();
|
||||
|
||||
QAction *clearHistoryAction = new QAction(tr("Clear History"), menu);
|
||||
connect(clearHistoryAction, &QAction::triggered, this, [this]() {
|
||||
Config::getInstance().clearIpHistory();
|
||||
loadIpHistory();
|
||||
});
|
||||
|
||||
menu->addAction(clearHistoryAction);
|
||||
menu->exec(ui->deviceIpEdt->lineEdit()->mapToGlobal(pos));
|
||||
delete menu;
|
||||
}
|
||||
|
|
|
@ -67,6 +67,8 @@ private slots:
|
|||
|
||||
void on_autoUpdatecheckBox_toggled(bool checked);
|
||||
|
||||
void showIpEditMenu(const QPoint &pos);
|
||||
|
||||
private:
|
||||
bool checkAdbRun();
|
||||
void initUI();
|
||||
|
@ -78,6 +80,8 @@ private:
|
|||
int findDeviceFromeSerialBox(bool wifi);
|
||||
quint32 getBitRate();
|
||||
const QString &getServerPath();
|
||||
void loadIpHistory();
|
||||
void saveIpHistory(const QString &ip);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event);
|
||||
|
|
|
@ -1059,22 +1059,25 @@
|
|||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="deviceIpEdt">
|
||||
<widget class="QComboBox" name="deviceIpEdt">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>200</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="editable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="currentText">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="maxLength">
|
||||
<number>128</number>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string notr="true">192.168.0.1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
|
|
|
@ -108,6 +108,11 @@
|
|||
#define SERIAL_NICK_NAME_KEY "NickName"
|
||||
#define SERIAL_NICK_NAME_DEF "Phone"
|
||||
|
||||
// IP history
|
||||
#define IP_HISTORY_KEY "IpHistory"
|
||||
#define IP_HISTORY_DEF ""
|
||||
#define IP_HISTORY_MAX 10
|
||||
|
||||
QString Config::s_configPath = "";
|
||||
|
||||
Config::Config(QObject *parent) : QObject(parent)
|
||||
|
@ -372,3 +377,34 @@ QString Config::getTitle()
|
|||
m_settings->endGroup();
|
||||
return title;
|
||||
}
|
||||
|
||||
void Config::saveIpHistory(const QString &ip)
|
||||
{
|
||||
QStringList ipList = getIpHistory();
|
||||
|
||||
// 移除已存在的相同IP(避免重复)
|
||||
ipList.removeAll(ip);
|
||||
|
||||
// 将新IP添加到开头
|
||||
ipList.prepend(ip);
|
||||
|
||||
// 限制历史记录数量
|
||||
while (ipList.size() > IP_HISTORY_MAX) {
|
||||
ipList.removeLast();
|
||||
}
|
||||
|
||||
m_userData->setValue(IP_HISTORY_KEY, ipList);
|
||||
m_userData->sync();
|
||||
}
|
||||
|
||||
QStringList Config::getIpHistory()
|
||||
{
|
||||
QStringList ipList = m_userData->value(IP_HISTORY_KEY, IP_HISTORY_DEF).toStringList();
|
||||
return ipList;
|
||||
}
|
||||
|
||||
void Config::clearIpHistory()
|
||||
{
|
||||
m_userData->remove(IP_HISTORY_KEY);
|
||||
m_userData->sync();
|
||||
}
|
||||
|
|
|
@ -62,6 +62,11 @@ public:
|
|||
|
||||
void deleteGroup(const QString &serial);
|
||||
|
||||
// IP history methods
|
||||
void saveIpHistory(const QString &ip);
|
||||
QStringList getIpHistory();
|
||||
void clearIpHistory();
|
||||
|
||||
private:
|
||||
explicit Config(QObject *parent = nullptr);
|
||||
const QString &getConfigPath();
|
||||
|
|
Loading…
Add table
Reference in a new issue