mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-07-31 04:58:37 +00:00
update:文件拖拽与apk安装
This commit is contained in:
parent
a3f56669f7
commit
6709c10346
8 changed files with 209 additions and 65 deletions
|
@ -52,7 +52,7 @@ include ($$PWD/android/android.pri)
|
||||||
include ($$PWD/inputcontrol/inputcontrol.pri)
|
include ($$PWD/inputcontrol/inputcontrol.pri)
|
||||||
include ($$PWD/uibase/uibase.pri)
|
include ($$PWD/uibase/uibase.pri)
|
||||||
include ($$PWD/fontawesome/fontawesome.pri)
|
include ($$PWD/fontawesome/fontawesome.pri)
|
||||||
|
include ($$PWD/filehandler/filehandler.pri)
|
||||||
|
|
||||||
# 附加包含路径
|
# 附加包含路径
|
||||||
INCLUDEPATH += \
|
INCLUDEPATH += \
|
||||||
|
@ -65,6 +65,7 @@ INCLUDEPATH += \
|
||||||
$$PWD/android \
|
$$PWD/android \
|
||||||
$$PWD/inputcontrol \
|
$$PWD/inputcontrol \
|
||||||
$$PWD/uibase \
|
$$PWD/uibase \
|
||||||
|
$$PWD/filehandler \
|
||||||
$$PWD/fontawesome
|
$$PWD/fontawesome
|
||||||
|
|
||||||
|
|
||||||
|
|
45
QtScrcpy/filehandler/filehandler.cpp
Normal file
45
QtScrcpy/filehandler/filehandler.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
30
QtScrcpy/filehandler/filehandler.h
Normal file
30
QtScrcpy/filehandler/filehandler.h
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef FILEHANDLER_H
|
||||||
|
#define FILEHANDLER_H
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
#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
|
5
QtScrcpy/filehandler/filehandler.pri
Normal file
5
QtScrcpy/filehandler/filehandler.pri
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/filehandler.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/filehandler.cpp
|
|
@ -8,6 +8,9 @@
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#endif
|
#endif
|
||||||
#include <QQuickWidget>
|
#include <QQuickWidget>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "videoform.h"
|
#include "videoform.h"
|
||||||
#include "ui_videoform.h"
|
#include "ui_videoform.h"
|
||||||
|
@ -25,72 +28,11 @@ VideoForm::VideoForm(const QString& serial, quint16 maxSize, quint32 bitRate,QWi
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
initUI();
|
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_server = new Server();
|
||||||
m_frames.init();
|
m_frames.init();
|
||||||
m_decoder.setFrames(&m_frames);
|
m_decoder.setFrames(&m_frames);
|
||||||
|
|
||||||
connect(m_server, &Server::serverStartResult, this, [this](bool success){
|
initSignals();
|
||||||
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);
|
|
||||||
|
|
||||||
// fix: macos cant recv finished signel, timer is ok
|
// fix: macos cant recv finished signel, timer is ok
|
||||||
QTimer::singleShot(0, this, [this](){
|
QTimer::singleShot(0, this, [this](){
|
||||||
|
@ -141,6 +83,84 @@ void VideoForm::initUI()
|
||||||
ui->quickWidget->setClearColor(QColor(Qt::transparent));
|
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)
|
void VideoForm::showToolFrom(bool show)
|
||||||
{
|
{
|
||||||
if (!m_toolForm) {
|
if (!m_toolForm) {
|
||||||
|
@ -372,3 +392,36 @@ void VideoForm::showEvent(QShowEvent *event)
|
||||||
Q_UNUSED(event);
|
Q_UNUSED(event);
|
||||||
showToolFrom();
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "frames.h"
|
#include "frames.h"
|
||||||
#include "inputconvertnormal.h"
|
#include "inputconvertnormal.h"
|
||||||
#include "inputconvertgame.h"
|
#include "inputconvertgame.h"
|
||||||
|
#include "filehandler.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class videoForm;
|
class videoForm;
|
||||||
|
@ -39,6 +40,7 @@ private:
|
||||||
void updateShowSize(const QSize &newSize);
|
void updateShowSize(const QSize &newSize);
|
||||||
void updateStyleSheet(bool vertical);
|
void updateStyleSheet(bool vertical);
|
||||||
void initUI();
|
void initUI();
|
||||||
|
void initSignals();
|
||||||
void showToolFrom(bool show = true);
|
void showToolFrom(bool show = true);
|
||||||
void postKeyCodeClick(AndroidKeycode keycode);
|
void postKeyCodeClick(AndroidKeycode keycode);
|
||||||
|
|
||||||
|
@ -53,6 +55,11 @@ protected:
|
||||||
void paintEvent(QPaintEvent *);
|
void paintEvent(QPaintEvent *);
|
||||||
void showEvent(QShowEvent *event);
|
void showEvent(QShowEvent *event);
|
||||||
|
|
||||||
|
void dragEnterEvent(QDragEnterEvent *event);
|
||||||
|
void dragMoveEvent(QDragMoveEvent *event);
|
||||||
|
void dragLeaveEvent(QDragLeaveEvent *event);
|
||||||
|
void dropEvent(QDropEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::videoForm *ui;
|
Ui::videoForm *ui;
|
||||||
QSize frameSize;
|
QSize frameSize;
|
||||||
|
@ -61,6 +68,7 @@ private:
|
||||||
Frames m_frames;
|
Frames m_frames;
|
||||||
//InputConvertNormal m_inputConvert;
|
//InputConvertNormal m_inputConvert;
|
||||||
InputConvertGame m_inputConvert;
|
InputConvertGame m_inputConvert;
|
||||||
|
FileHandler m_fileHandler;
|
||||||
QString m_serial = "";
|
QString m_serial = "";
|
||||||
quint16 m_maxSize = 720;
|
quint16 m_maxSize = 720;
|
||||||
quint32 m_bitRate = 8000000;
|
quint32 m_bitRate = 8000000;
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
<height>800</height>
|
<height>800</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="acceptDrops">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
|
|
3
TODO.txt
3
TODO.txt
|
@ -1,5 +1,4 @@
|
||||||
server移除
|
全屏状态禁止电脑锁屏
|
||||||
拖放 安装apk 推送文件
|
|
||||||
mp4录制
|
mp4录制
|
||||||
工具栏扩展(模拟点击指定次数等)
|
工具栏扩展(模拟点击指定次数等)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue