diff --git a/QtScrcpy/QtScrcpy.pro b/QtScrcpy/QtScrcpy.pro index 9e31367..001fc79 100644 --- a/QtScrcpy/QtScrcpy.pro +++ b/QtScrcpy/QtScrcpy.pro @@ -52,7 +52,7 @@ include ($$PWD/android/android.pri) include ($$PWD/inputcontrol/inputcontrol.pri) include ($$PWD/uibase/uibase.pri) include ($$PWD/fontawesome/fontawesome.pri) - +include ($$PWD/filehandler/filehandler.pri) # 附加包含路径 INCLUDEPATH += \ @@ -65,6 +65,7 @@ INCLUDEPATH += \ $$PWD/android \ $$PWD/inputcontrol \ $$PWD/uibase \ + $$PWD/filehandler \ $$PWD/fontawesome diff --git a/QtScrcpy/filehandler/filehandler.cpp b/QtScrcpy/filehandler/filehandler.cpp new file mode 100644 index 0000000..548dc88 --- /dev/null +++ b/QtScrcpy/filehandler/filehandler.cpp @@ -0,0 +1,45 @@ +#include "filehandler.h" + +#define DEVICE_SDCARD_PATH "/sdcard/" + +FileHandler::FileHandler(QObject *parent) + : QObject (parent) +{ + connect(&m_adb, &AdbProcess::adbProcessResult, this, [this](AdbProcess::ADB_EXEC_RESULT processResult){ + switch (processResult) { + case AdbProcess::AER_ERROR_START: + case AdbProcess::AER_ERROR_EXEC: + case AdbProcess::AER_ERROR_MISSING_BINARY: + emit fileHandlerResult(FAR_ERROR_EXEC); + break; + case AdbProcess::AER_SUCCESS_EXEC: + emit fileHandlerResult(FAR_SUCCESS_EXEC); + break; + default: + break; + } + }); +} + +FileHandler::~FileHandler() +{ + +} + +void FileHandler::pushFileRequest(const QString &serial, const QString &file) +{ + if (m_adb.isRuning()) { + emit fileHandlerResult(FAR_IS_RUNNING); + return; + } + m_adb.push(serial, file, DEVICE_SDCARD_PATH); +} + +void FileHandler::installApkRequest(const QString &serial, const QString &apkFile) +{ + if (m_adb.isRuning()) { + emit fileHandlerResult(FAR_IS_RUNNING); + return; + } + m_adb.install(serial, apkFile); +} diff --git a/QtScrcpy/filehandler/filehandler.h b/QtScrcpy/filehandler/filehandler.h new file mode 100644 index 0000000..1c67c9c --- /dev/null +++ b/QtScrcpy/filehandler/filehandler.h @@ -0,0 +1,30 @@ +#ifndef FILEHANDLER_H +#define FILEHANDLER_H +#include + +#include "adbprocess.h" + +class FileHandler : public QObject +{ + Q_OBJECT +public: + enum FILE_HANDLER_RESULT { + FAR_IS_RUNNING, // 正在执行 + FAR_SUCCESS_EXEC, // 执行成功 + FAR_ERROR_EXEC, // 执行失败 + }; + + FileHandler(QObject *parent = nullptr); + virtual ~FileHandler(); + + void pushFileRequest(const QString& serial, const QString& file); + void installApkRequest(const QString& serial, const QString& apkFile); + +signals: + void fileHandlerResult(FILE_HANDLER_RESULT processResult); + +private: + AdbProcess m_adb; +}; + +#endif // FILEHANDLER_H diff --git a/QtScrcpy/filehandler/filehandler.pri b/QtScrcpy/filehandler/filehandler.pri new file mode 100644 index 0000000..d74f234 --- /dev/null +++ b/QtScrcpy/filehandler/filehandler.pri @@ -0,0 +1,5 @@ +HEADERS += \ + $$PWD/filehandler.h + +SOURCES += \ + $$PWD/filehandler.cpp diff --git a/QtScrcpy/videoform.cpp b/QtScrcpy/videoform.cpp index e0fd7d3..733d986 100644 --- a/QtScrcpy/videoform.cpp +++ b/QtScrcpy/videoform.cpp @@ -8,6 +8,9 @@ #include #endif #include +#include +#include +#include #include "videoform.h" #include "ui_videoform.h" @@ -25,6 +28,74 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi ui->setupUi(this); initUI(); + m_server = new Server(); + m_frames.init(); + m_decoder.setFrames(&m_frames); + + initSignals(); + + // fix: macos cant recv finished signel, timer is ok + QTimer::singleShot(0, this, [this](){ + // max size support 480p 720p 1080p 设备原生分辨率 + // support wireless connect, example: + //m_server->start("192.168.0.174:5555", 27183, m_maxSize, m_bitRate, ""); + // only one devices, serial can be null + // mark: crop input format: "width:height:x:y" or - for no crop, for example: "100:200:0:0" + m_server->start(m_serial, 27183, m_maxSize, m_bitRate, "-"); + }); + + updateShowSize(size()); + + bool vertical = size().height() > size().width(); + updateStyleSheet(vertical); +} + +VideoForm::~VideoForm() +{ + m_server->stop(); + m_decoder.stopDecode(); + delete m_server; + m_frames.deInit(); + delete ui; +} + +void VideoForm::initUI() +{ + QPixmap phone; + if (phone.load(":/res/phone.png")) { + m_widthHeightRatio = 1.0f * phone.width() / phone.height(); + } + + setAttribute(Qt::WA_DeleteOnClose); + // 去掉标题栏 + setWindowFlags(Qt::FramelessWindowHint); + // 根据图片构造异形窗口 + setAttribute(Qt::WA_TranslucentBackground); + + setMouseTracking(true); + ui->loadingWidget->setAttribute(Qt::WA_DeleteOnClose); + ui->videoWidget->setMouseTracking(true); + ui->videoWidget->hide(); + + // 最后绘制,不设置最后绘制会影响父窗体异形异常(quickWidget的透明通道会形成穿透) + ui->quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop); + // 背景透明 + ui->quickWidget->setClearColor(QColor(Qt::transparent)); +} + +void VideoForm::initSignals() +{ + connect(&m_fileHandler, &FileHandler::fileHandlerResult, this, [this](FileHandler::FILE_HANDLER_RESULT processResult){ + if (FileHandler::FAR_IS_RUNNING == processResult) { + QMessageBox::warning(this, "QtScrcpy", tr("wait current file transfer to complete"), QMessageBox::Ok); + } + if (FileHandler::FAR_SUCCESS_EXEC == processResult) { + QMessageBox::information(this, "QtScrcpy", tr("file transfer complete"), QMessageBox::Ok); + } + if (FileHandler::FAR_ERROR_EXEC == processResult) { + QMessageBox::information(this, "QtScrcpy", tr("file transfer failed"), QMessageBox::Ok); + } + }); connect(&m_inputConvert, &InputConvertGame::grabCursor, this, [this](bool grab){ #ifdef Q_OS_WIN32 if(grab) { @@ -41,14 +112,11 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi } #endif }); - - m_server = new Server(); - m_frames.init(); - m_decoder.setFrames(&m_frames); - connect(m_server, &Server::serverStartResult, this, [this](bool success){ if (success) { - m_server->connectTo(); + m_server->connectTo(); + } else { + close(); } }); @@ -56,7 +124,7 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi if (success) { // update ui setWindowTitle(deviceName); - updateShowSize(size); + updateShowSize(size); // init decode m_decoder.setDeviceSocket(m_server->getDeviceSocket()); @@ -78,12 +146,12 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi }); // must be Qt::QueuedConnection, ui update must be main thread - QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ + connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ if (ui->videoWidget->isHidden()) { ui->loadingWidget->close(); ui->videoWidget->show(); } - m_frames.lock(); + m_frames.lock(); const AVFrame *frame = m_frames.consumeRenderedFrame(); //qDebug() << "widthxheight:" << frame->width << "x" << frame->height; updateShowSize(QSize(frame->width, frame->height)); @@ -91,54 +159,6 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi ui->videoWidget->updateTextures(frame->data[0], frame->data[1], frame->data[2], frame->linesize[0], frame->linesize[1], frame->linesize[2]); m_frames.unLock(); },Qt::QueuedConnection); - - // fix: macos cant recv finished signel, timer is ok - QTimer::singleShot(0, this, [this](){ - // max size support 480p 720p 1080p 设备原生分辨率 - // support wireless connect, example: - //m_server->start("192.168.0.174:5555", 27183, m_maxSize, m_bitRate, ""); - // only one devices, serial can be null - // mark: crop input format: "width:height:x:y" or - for no crop, for example: "100:200:0:0" - m_server->start(m_serial, 27183, m_maxSize, m_bitRate, "-"); - }); - - updateShowSize(size()); - - bool vertical = size().height() > size().width(); - updateStyleSheet(vertical); -} - -VideoForm::~VideoForm() -{ - m_server->stop(); - m_decoder.stopDecode(); - delete m_server; - m_frames.deInit(); - delete ui; -} - -void VideoForm::initUI() -{ - QPixmap phone; - if (phone.load(":/res/phone.png")) { - m_widthHeightRatio = 1.0f * phone.width() / phone.height(); - } - - setAttribute(Qt::WA_DeleteOnClose); - // 去掉标题栏 - setWindowFlags(Qt::FramelessWindowHint); - // 根据图片构造异形窗口 - setAttribute(Qt::WA_TranslucentBackground); - - setMouseTracking(true); - ui->loadingWidget->setAttribute(Qt::WA_DeleteOnClose); - ui->videoWidget->setMouseTracking(true); - ui->videoWidget->hide(); - - // 最后绘制,不设置最后绘制会影响父窗体异形异常(quickWidget的透明通道会形成穿透) - ui->quickWidget->setAttribute(Qt::WA_AlwaysStackOnTop); - // 背景透明 - ui->quickWidget->setClearColor(QColor(Qt::transparent)); } void VideoForm::showToolFrom(bool show) @@ -372,3 +392,36 @@ void VideoForm::showEvent(QShowEvent *event) Q_UNUSED(event); showToolFrom(); } + +void VideoForm::dragEnterEvent(QDragEnterEvent *event) +{ + event->acceptProposedAction(); +} + +void VideoForm::dragMoveEvent(QDragMoveEvent *event) +{ + Q_UNUSED(event); +} + +void VideoForm::dragLeaveEvent(QDragLeaveEvent *event) +{ + Q_UNUSED(event); +} + +void VideoForm::dropEvent(QDropEvent *event) +{ + const QMimeData* qm = event->mimeData(); + QString file = qm->urls()[0].toLocalFile(); + QFileInfo fileInfo(file); + + if (!fileInfo.exists()) { + QMessageBox::warning(this, "QtScrcpy", tr("file does not exist"), QMessageBox::Ok); + return; + } + + if (fileInfo.isFile() && fileInfo.suffix() == "apk") { + m_fileHandler.installApkRequest(m_serial, file); + return; + } + m_fileHandler.pushFileRequest(m_serial, file); +} diff --git a/QtScrcpy/videoform.h b/QtScrcpy/videoform.h index 76b142b..5c1e021 100644 --- a/QtScrcpy/videoform.h +++ b/QtScrcpy/videoform.h @@ -9,6 +9,7 @@ #include "frames.h" #include "inputconvertnormal.h" #include "inputconvertgame.h" +#include "filehandler.h" namespace Ui { class videoForm; @@ -39,6 +40,7 @@ private: void updateShowSize(const QSize &newSize); void updateStyleSheet(bool vertical); void initUI(); + void initSignals(); void showToolFrom(bool show = true); void postKeyCodeClick(AndroidKeycode keycode); @@ -53,6 +55,11 @@ protected: void paintEvent(QPaintEvent *); void showEvent(QShowEvent *event); + void dragEnterEvent(QDragEnterEvent *event); + void dragMoveEvent(QDragMoveEvent *event); + void dragLeaveEvent(QDragLeaveEvent *event); + void dropEvent(QDropEvent *event); + private: Ui::videoForm *ui; QSize frameSize; @@ -61,6 +68,7 @@ private: Frames m_frames; //InputConvertNormal m_inputConvert; InputConvertGame m_inputConvert; + FileHandler m_fileHandler; QString m_serial = ""; quint16 m_maxSize = 720; quint32 m_bitRate = 8000000; diff --git a/QtScrcpy/videoform.ui b/QtScrcpy/videoform.ui index 9864cc2..539e5b5 100644 --- a/QtScrcpy/videoform.ui +++ b/QtScrcpy/videoform.ui @@ -10,6 +10,9 @@ 800 + + true + diff --git a/TODO.txt b/TODO.txt index 0d36d82..a8f8ff8 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,5 +1,4 @@ -serverƳ -Ϸ װapk ļ +ȫ״ֹ̬ mp4¼ չģָȣ