From 129c0da0a2707e2e08c7ed7f1b8503019424d5e7 Mon Sep 17 00:00:00 2001 From: Barry <870709864@qq.com> Date: Mon, 19 Nov 2018 22:36:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=B8=BB=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E7=9A=84log=E6=98=BE=E7=A4=BA=EF=BC=88=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=EF=BC=8C=E6=A0=87=E5=87=86=E8=BE=93=E5=87=BA?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=A4=9A=E6=AC=A1=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E7=AD=89=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- QtScrcpy/adb/adbprocess.cpp | 13 +++- QtScrcpy/adb/adbprocess.h | 2 + QtScrcpy/dialog.cpp | 81 ++++++++++++++++------- QtScrcpy/dialog.h | 9 ++- QtScrcpy/dialog.ui | 128 ++++++++++++++++-------------------- 5 files changed, 134 insertions(+), 99 deletions(-) diff --git a/QtScrcpy/adb/adbprocess.cpp b/QtScrcpy/adb/adbprocess.cpp index 53af9a3..2ca0b72 100644 --- a/QtScrcpy/adb/adbprocess.cpp +++ b/QtScrcpy/adb/adbprocess.cpp @@ -60,13 +60,14 @@ void AdbProcess::initSignals() connect(this, &QProcess::readyReadStandardError, this, [this](){ - qDebug() << QString::fromLocal8Bit(readAllStandardError()); + m_errorOutput = QString::fromLocal8Bit(readAllStandardError()).trimmed(); + qDebug() << "AdbProcess::error:" << m_errorOutput; }); connect(this, &QProcess::readyReadStandardOutput, this, [this](){ - m_standardOutput = QString::fromLocal8Bit(readAllStandardOutput()); - qDebug() << m_standardOutput; + m_standardOutput = QString::fromLocal8Bit(readAllStandardOutput()).trimmed(); + qDebug() << "AdbProcess::std out:" << m_standardOutput; }); connect(this, &QProcess::started, this, @@ -78,6 +79,7 @@ void AdbProcess::initSignals() void AdbProcess::execute(const QString& serial, const QStringList& args) { m_standardOutput = ""; + m_errorOutput = ""; QStringList adbArgs; if (!serial.isEmpty()) { adbArgs << "-s" << serial; @@ -123,6 +125,11 @@ QString AdbProcess::getStdOut() return m_standardOutput; } +QString AdbProcess::getErrorOut() +{ + return m_errorOutput; +} + void AdbProcess::forward(const QString& serial, quint16 localPort, const QString& deviceSocketName) { QStringList adbArgs; diff --git a/QtScrcpy/adb/adbprocess.h b/QtScrcpy/adb/adbprocess.h index 4c415f0..f09d098 100644 --- a/QtScrcpy/adb/adbprocess.h +++ b/QtScrcpy/adb/adbprocess.h @@ -31,6 +31,7 @@ public: void setShowTouchesEnabled(const QString& serial, bool enabled); QStringList getDevicesSerialFromStdOut(); QString getStdOut(); + QString getErrorOut(); static const QString& getAdbPath(); @@ -42,6 +43,7 @@ private: private: QString m_standardOutput = ""; + QString m_errorOutput = ""; static QString s_adbPath; }; diff --git a/QtScrcpy/dialog.cpp b/QtScrcpy/dialog.cpp index 9a659d2..d40ffe1 100644 --- a/QtScrcpy/dialog.cpp +++ b/QtScrcpy/dialog.cpp @@ -4,7 +4,6 @@ #include "dialog.h" #include "ui_dialog.h" -#include "adbprocess.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), @@ -13,6 +12,27 @@ Dialog::Dialog(QWidget *parent) : ui->setupUi(this); setAttribute(Qt::WA_DeleteOnClose); //setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); + + connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + QString log = ""; + switch (processResult) { + case AdbProcess::AER_SUCCESS_START: + log = "adb run"; + 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: + log = m_adb.getStdOut(); + break; + } + if (!log.isEmpty()) { + outLog(log); + } + }); } Dialog::~Dialog() @@ -23,17 +43,11 @@ Dialog::~Dialog() void Dialog::on_updateDevice_clicked() { - AdbProcess* adb = new AdbProcess(); - connect(adb, &AdbProcess::adbProcessResult, this, [this, adb](AdbProcess::ADB_EXEC_RESULT processResult){ - if (AdbProcess::AER_SUCCESS_EXEC == processResult) { - ui->outEdit->append(adb->getDevicesSerialFromStdOut().join("*")); - } - if (AdbProcess::AER_SUCCESS_START != processResult) { - sender()->deleteLater(); - } - }); - adb->execute("", QStringList() << "devices"); - //adb->setShowTouchesEnabled("P7C0218510000537", true); + if (checkAdbRun()) { + return; + } + outLog("update devices..."); + m_adb.execute("", QStringList() << "devices"); } void Dialog::on_startServerBtn_clicked() @@ -53,19 +67,38 @@ void Dialog::on_stopServerBtn_clicked() void Dialog::on_wirelessConnectBtn_clicked() { - AdbProcess* adb = new AdbProcess(); - connect(adb, &AdbProcess::adbProcessResult, this, [this, adb](AdbProcess::ADB_EXEC_RESULT processResult){ - if (AdbProcess::AER_SUCCESS_EXEC == processResult) { - ui->outEdit->append(adb->getStdOut()); - } - if (AdbProcess::AER_SUCCESS_START != processResult) { - sender()->deleteLater(); - } - }); - - //adb connect 172.16.8.197:5555 + if (checkAdbRun()) { + return; + } + outLog("wireless connect..."); QStringList adbArgs; adbArgs << "connect"; adbArgs << ui->deviceIpEdt->text().trimmed(); - adb->execute("", adbArgs); + m_adb.execute("", adbArgs); +} + +void Dialog::on_startAdbdBtn_clicked() +{ + if (checkAdbRun()) { + return; + } + outLog("start devices adbd..."); + // adb tcpip 5555 + QStringList adbArgs; + adbArgs << "tcpip"; + adbArgs << "5555"; + m_adb.execute("", adbArgs); +} + +void Dialog::outLog(const QString &log) +{ + ui->outEdit->append(log); +} + +bool Dialog::checkAdbRun() +{ + if (m_adb.isRuning()) { + outLog("wait for the end of the current command to run"); + } + return m_adb.isRuning(); } diff --git a/QtScrcpy/dialog.h b/QtScrcpy/dialog.h index ddf5d35..29fb5b6 100644 --- a/QtScrcpy/dialog.h +++ b/QtScrcpy/dialog.h @@ -5,6 +5,7 @@ #include #include "videoform.h" +#include "adbprocess.h" namespace Ui { class Dialog; @@ -28,9 +29,15 @@ private slots: void on_wirelessConnectBtn_clicked(); + void on_startAdbdBtn_clicked(); + +private: + void outLog(const QString& log); + bool checkAdbRun(); + private: Ui::Dialog *ui; - + AdbProcess m_adb; QPointer m_videoForm; }; diff --git a/QtScrcpy/dialog.ui b/QtScrcpy/dialog.ui index 8528255..9f5343e 100644 --- a/QtScrcpy/dialog.ui +++ b/QtScrcpy/dialog.ui @@ -6,15 +6,68 @@ 0 0 - 373 - 329 + 442 + 412 QtScrcpy - - + + + + + + + + true + + + + + + + Wireless + + + + + + 192.168.0.1:5555 + + + + + + + wireless connect + + + + + + + start device adbd + + + + + + + run through USB line: + + + Qt::PlainText + + + false + + + + + + + @@ -51,73 +104,6 @@ - - - - - - - - 45 - 0 - - - - - 45 - 16777215 - - - - ip:port - - - Qt::PlainText - - - false - - - - - - - - 145 - 0 - - - - - 145 - 16777215 - - - - 192.168.0.1:5555 - - - - - - - wireless connect - - - - - - - - - - - - - true - - -