update:文件拖拽与apk安装

This commit is contained in:
Barry 2019-01-26 23:40:51 +08:00
commit 6709c10346
8 changed files with 209 additions and 65 deletions

View file

@ -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

View 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);
}

View 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

View file

@ -0,0 +1,5 @@
HEADERS += \
$$PWD/filehandler.h
SOURCES += \
$$PWD/filehandler.cpp

View file

@ -8,6 +8,9 @@
#include <Windows.h>
#endif
#include <QQuickWidget>
#include <QMimeData>
#include <QFileInfo>
#include <QMessageBox>
#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);
}

View file

@ -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;

View file

@ -10,6 +10,9 @@
<height>800</height>
</rect>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="windowTitle">
<string/>
</property>

View file

@ -1,5 +1,4 @@
server移除
拖放 安装apk 推送文件
全屏状态禁止电脑锁屏
mp4录制
工具栏扩展(模拟点击指定次数等)