mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-05 15:08:39 +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?";
|
log = "ip not find, connect to wifi?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ui->deviceIpEdt->setText(ip);
|
ui->deviceIpEdt->setEditText(ip);
|
||||||
} else if (args.contains("ifconfig") && args.contains("wlan0")) {
|
} else if (args.contains("ifconfig") && args.contains("wlan0")) {
|
||||||
QString ip = m_adb.getDeviceIPFromStdOut();
|
QString ip = m_adb.getDeviceIPFromStdOut();
|
||||||
if (ip.isEmpty()) {
|
if (ip.isEmpty()) {
|
||||||
log = "ip not find, connect to wifi?";
|
log = "ip not find, connect to wifi?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ui->deviceIpEdt->setText(ip);
|
ui->deviceIpEdt->setEditText(ip);
|
||||||
} else if (args.contains("ip -o a")) {
|
} else if (args.contains("ip -o a")) {
|
||||||
QString ip = m_adb.getDeviceIPByIpFromStdOut();
|
QString ip = m_adb.getDeviceIPByIpFromStdOut();
|
||||||
if (ip.isEmpty()) {
|
if (ip.isEmpty()) {
|
||||||
log = "ip not find, connect to wifi?";
|
log = "ip not find, connect to wifi?";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
ui->deviceIpEdt->setText(ip);
|
ui->deviceIpEdt->setEditText(ip);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -164,6 +164,16 @@ void Dialog::initUI()
|
||||||
ui->lockOrientationBox->addItem("180");
|
ui->lockOrientationBox->addItem("180");
|
||||||
ui->lockOrientationBox->addItem("270");
|
ui->lockOrientationBox->addItem("270");
|
||||||
ui->lockOrientationBox->setCurrentIndex(0);
|
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)
|
void Dialog::updateBootConfig(bool toView)
|
||||||
|
@ -216,6 +226,12 @@ void Dialog::updateBootConfig(bool toView)
|
||||||
config.autoUpdateDevice = ui->autoUpdatecheckBox->isChecked();
|
config.autoUpdateDevice = ui->autoUpdatecheckBox->isChecked();
|
||||||
config.showToolbar = ui->showToolbar->isChecked();
|
config.showToolbar = ui->showToolbar->isChecked();
|
||||||
|
|
||||||
|
// 保存当前IP到历史记录
|
||||||
|
QString currentIp = ui->deviceIpEdt->currentText().trimmed();
|
||||||
|
if (!currentIp.isEmpty()) {
|
||||||
|
saveIpHistory(currentIp);
|
||||||
|
}
|
||||||
|
|
||||||
Config::getInstance().setUserBootConfig(config);
|
Config::getInstance().setUserBootConfig(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -344,7 +360,7 @@ void Dialog::on_wirelessConnectBtn_clicked()
|
||||||
if (checkAdbRun()) {
|
if (checkAdbRun()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString addr = ui->deviceIpEdt->text().trimmed();
|
QString addr = ui->deviceIpEdt->currentText().trimmed();
|
||||||
if (!ui->devicePortEdt->text().isEmpty()) {
|
if (!ui->devicePortEdt->text().isEmpty()) {
|
||||||
addr += ":";
|
addr += ":";
|
||||||
addr += ui->devicePortEdt->text().trimmed();
|
addr += ui->devicePortEdt->text().trimmed();
|
||||||
|
@ -356,6 +372,12 @@ void Dialog::on_wirelessConnectBtn_clicked()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 保存IP历史记录 - 只保存IP部分,不包含端口
|
||||||
|
QString ip = addr.split(":").first();
|
||||||
|
if (!ip.isEmpty()) {
|
||||||
|
saveIpHistory(ip);
|
||||||
|
}
|
||||||
|
|
||||||
outLog("wireless connect...", false);
|
outLog("wireless connect...", false);
|
||||||
QStringList adbArgs;
|
QStringList adbArgs;
|
||||||
adbArgs << "connect";
|
adbArgs << "connect";
|
||||||
|
@ -516,7 +538,7 @@ void Dialog::on_wirelessDisConnectBtn_clicked()
|
||||||
if (checkAdbRun()) {
|
if (checkAdbRun()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
QString addr = ui->deviceIpEdt->text().trimmed();
|
QString addr = ui->deviceIpEdt->currentText().trimmed();
|
||||||
outLog("wireless disconnect...", false);
|
outLog("wireless disconnect...", false);
|
||||||
QStringList adbArgs;
|
QStringList adbArgs;
|
||||||
adbArgs << "disconnect";
|
adbArgs << "disconnect";
|
||||||
|
@ -767,3 +789,45 @@ void Dialog::on_autoUpdatecheckBox_toggled(bool checked)
|
||||||
m_autoUpdatetimer.stop();
|
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 on_autoUpdatecheckBox_toggled(bool checked);
|
||||||
|
|
||||||
|
void showIpEditMenu(const QPoint &pos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool checkAdbRun();
|
bool checkAdbRun();
|
||||||
void initUI();
|
void initUI();
|
||||||
|
@ -78,6 +80,8 @@ private:
|
||||||
int findDeviceFromeSerialBox(bool wifi);
|
int findDeviceFromeSerialBox(bool wifi);
|
||||||
quint32 getBitRate();
|
quint32 getBitRate();
|
||||||
const QString &getServerPath();
|
const QString &getServerPath();
|
||||||
|
void loadIpHistory();
|
||||||
|
void saveIpHistory(const QString &ip);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void closeEvent(QCloseEvent *event);
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
|
@ -1059,22 +1059,25 @@
|
||||||
<number>5</number>
|
<number>5</number>
|
||||||
</property>
|
</property>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="deviceIpEdt">
|
<widget class="QComboBox" name="deviceIpEdt">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
|
<sizepolicy hsizetype="MinimumExpanding" 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>200</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="editable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="currentText">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="maxLength">
|
|
||||||
<number>128</number>
|
|
||||||
</property>
|
|
||||||
<property name="placeholderText">
|
|
||||||
<string notr="true">192.168.0.1</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -108,6 +108,11 @@
|
||||||
#define SERIAL_NICK_NAME_KEY "NickName"
|
#define SERIAL_NICK_NAME_KEY "NickName"
|
||||||
#define SERIAL_NICK_NAME_DEF "Phone"
|
#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 = "";
|
QString Config::s_configPath = "";
|
||||||
|
|
||||||
Config::Config(QObject *parent) : QObject(parent)
|
Config::Config(QObject *parent) : QObject(parent)
|
||||||
|
@ -372,3 +377,34 @@ QString Config::getTitle()
|
||||||
m_settings->endGroup();
|
m_settings->endGroup();
|
||||||
return title;
|
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);
|
void deleteGroup(const QString &serial);
|
||||||
|
|
||||||
|
// IP history methods
|
||||||
|
void saveIpHistory(const QString &ip);
|
||||||
|
QStringList getIpHistory();
|
||||||
|
void clearIpHistory();
|
||||||
|
|
||||||
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