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,72 +28,11 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi ui->setupUi(this); initUI(); - connect(&m_inputConvert, &InputConvertGame::grabCursor, this, [this](bool grab){ -#ifdef Q_OS_WIN32 - if(grab) { - QRect rc(mapToGlobal(ui->videoWidget->pos()) - , ui->videoWidget->size()); - RECT mainRect; - mainRect.left = (LONG)rc.left(); - mainRect.right = (LONG)rc.right(); - mainRect.top = (LONG)rc.top(); - mainRect.bottom = (LONG)rc.bottom(); - ClipCursor(&mainRect); - } else { - ClipCursor(Q_NULLPTR); - } -#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(); - } - }); - - connect(m_server, &Server::connectToResult, this, [this](bool success, const QString &deviceName, const QSize &size){ - if (success) { - // update ui - setWindowTitle(deviceName); - updateShowSize(size); - - // init decode - m_decoder.setDeviceSocket(m_server->getDeviceSocket()); - m_decoder.startDecode(); - - // init controller - m_inputConvert.setDeviceSocket(m_server->getDeviceSocket()); - } - }); - - connect(m_server, &Server::onServerStop, this, [this](){ - close(); - qDebug() << "server process stop"; - }); - - connect(&m_decoder, &Decoder::onDecodeStop, this, [this](){ - close(); - qDebug() << "decoder thread stop"; - }); - - // must be Qt::QueuedConnection, ui update must be main thread - QObject::connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ - if (ui->videoWidget->isHidden()) { - ui->loadingWidget->close(); - ui->videoWidget->show(); - } - m_frames.lock(); - const AVFrame *frame = m_frames.consumeRenderedFrame(); - //qDebug() << "widthxheight:" << frame->width << "x" << frame->height; - updateShowSize(QSize(frame->width, frame->height)); - ui->videoWidget->setFrameSize(QSize(frame->width, frame->height)); - 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); + initSignals(); // fix: macos cant recv finished signel, timer is ok QTimer::singleShot(0, this, [this](){ @@ -141,6 +83,84 @@ void VideoForm::initUI() 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) { + QRect rc(mapToGlobal(ui->videoWidget->pos()) + , ui->videoWidget->size()); + RECT mainRect; + mainRect.left = (LONG)rc.left(); + mainRect.right = (LONG)rc.right(); + mainRect.top = (LONG)rc.top(); + mainRect.bottom = (LONG)rc.bottom(); + ClipCursor(&mainRect); + } else { + ClipCursor(Q_NULLPTR); + } +#endif + }); + connect(m_server, &Server::serverStartResult, this, [this](bool success){ + if (success) { + m_server->connectTo(); + } else { + close(); + } + }); + + connect(m_server, &Server::connectToResult, this, [this](bool success, const QString &deviceName, const QSize &size){ + if (success) { + // update ui + setWindowTitle(deviceName); + updateShowSize(size); + + // init decode + m_decoder.setDeviceSocket(m_server->getDeviceSocket()); + m_decoder.startDecode(); + + // init controller + m_inputConvert.setDeviceSocket(m_server->getDeviceSocket()); + } + }); + + connect(m_server, &Server::onServerStop, this, [this](){ + close(); + qDebug() << "server process stop"; + }); + + connect(&m_decoder, &Decoder::onDecodeStop, this, [this](){ + close(); + qDebug() << "decoder thread stop"; + }); + + // must be Qt::QueuedConnection, ui update must be main thread + connect(&m_decoder, &Decoder::onNewFrame, this, [this](){ + if (ui->videoWidget->isHidden()) { + ui->loadingWidget->close(); + ui->videoWidget->show(); + } + m_frames.lock(); + const AVFrame *frame = m_frames.consumeRenderedFrame(); + //qDebug() << "widthxheight:" << frame->width << "x" << frame->height; + updateShowSize(QSize(frame->width, frame->height)); + ui->videoWidget->setFrameSize(QSize(frame->width, frame->height)); + 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); +} + void VideoForm::showToolFrom(bool show) { if (!m_toolForm) { @@ -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¼ չģָȣ