1 Star 1 Fork 0

liuhao/QtScrcpy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
dialog.cpp 3.24 KB
一键复制 编辑 原始数据 按行查看 历史
liuhao 提交于 2022-05-30 22:17 . c++ tail
#include <QDebug>
#include <QDir>
#include <QBuffer>
#include <QTimer>
#include "input.h"
#include "keycodes.h"
#include "dialog.h"
#include "ui_dialog.h"
#include "controlevent.h"
#include "videoform.h"
Dialog::Dialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog)
{
ui->setupUi(this);
connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){
QString log = "";
bool newLine = true;
switch (processResult) {
case AdbProcess::AER_SUCCESS_START:
log = "adb run";
newLine = false;
break;
case AdbProcess::AER_ERROR_EXEC:
log = m_adb.getErrorOut();
break;
case AdbProcess::AER_ERROR_MISSING_BINARY:
log = "adb not find";
break;
case AdbProcess::AER_SUCCESS_EXEC:
QStringList args = m_adb.arguments();
if (args.contains("devices")) {
QStringList devices = m_adb.getDeviceSerialFromStdOut();
if (!devices.isEmpty()) {
ui->serialEdt->setText(devices.at(0));
}
}
if (args.contains("show") && args.contains("wlan0")) {
QString ip = m_adb.getDeviceIPFromStdOut();
if (!ip.isEmpty()) {
ui->deviceIpEdt->setText(ip);
}
}
break;
}
if (!log.isEmpty()) {
outLog(log, newLine);
}
});
}
Dialog::~Dialog()
{
delete ui;
}
void Dialog::outLog(const QString &log, bool newLine)
{
QString tmpLog = log;
bool tmpNewLine = newLine;
QTimer::singleShot(0, this, [this, tmpLog, tmpNewLine](){
ui->outEdt->append(tmpLog);
if (tmpNewLine) {
ui->outEdt->append("<br/>");
}
});
}
void Dialog::on_startServerBtn_clicked()
{
if (!m_videoForm) {
m_videoForm = new VideoForm(ui->serialEdt->text().trimmed());
}
m_videoForm->show();
}
void Dialog::on_stopServerBtn_clicked()
{
if (m_videoForm) {
m_videoForm->close();
}
}
void Dialog::on_updateDevice_clicked()
{
outLog("update devices...", false);
m_adb.execute("", QStringList() << "devices");
}
void Dialog::on_startAdbdBtn_clicked()
{
outLog("start devices adbd...", false);
// adb tcpip 5555
QStringList adbArgs;
adbArgs << "tcpip";
adbArgs << "5555";
m_adb.execute(ui->serialEdt->text().trimmed(), adbArgs);
}
void Dialog::on_getIPBtn_clicked()
{
outLog("get ip...", false);
// adb shell ip -f inet addr show wlan0
QStringList adbArgs;
adbArgs << "shell";
adbArgs << "ip";
adbArgs << "-f";
adbArgs << "inet";
adbArgs << "addr";
adbArgs << "show";
adbArgs << "wlan0";
m_adb.execute(ui->serialEdt->text().trimmed(), adbArgs);
}
void Dialog::on_wirelessConnectBtn_clicked()
{
outLog("wireless connect...", false);
QString addr = ui->deviceIpEdt->text().trimmed();
if (!ui->devicePortEdt->text().isEmpty()) {
addr += ":";
addr += ui->devicePortEdt->text().trimmed();
}
// connect ip:port
QStringList adbArgs;
adbArgs << "connect";
adbArgs << addr;
m_adb.execute(ui->serialEdt->text().trimmed(), adbArgs);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/lzxdgitt/qt-scrcpy.git
git@gitee.com:lzxdgitt/qt-scrcpy.git
lzxdgitt
qt-scrcpy
QtScrcpy
master

搜索帮助