6#include <QLoggingCategory>
9#include <QDesktopServices>
11#include "ConnectDesktop.h"
12#include "ConnecterThread.h"
14static Q_LOGGING_CATEGORY(log,
"Client.Connect.Desktop")
15static Q_LOGGING_CATEGORY(logMouse, "Client.Connect.Desktop.Mouse")
17#define TypeRecordVideo (QEvent::User + 1)
33int g_QtKeyboardModifiers = qRegisterMetaType<Qt::KeyboardModifiers>(
"KeyboardModifiers");
34int g_QtMouseButtons = qRegisterMetaType<Qt::MouseButtons>(
"MouseButtons");
35int g_QtMouseButton = qRegisterMetaType<Qt::MouseButton>(
"MouseButton");
36int g_QMessageBox_Icon = qRegisterMetaType<Qt::MouseButton>(
"QMessageBox::Icon");
41 , m_pParameterRecord(nullptr)
42 , m_VideoFrameInput(this)
43 , m_AudioBufferInput(this)
44 , m_AudioBufferOutput(this)
52 SetViewer(pView, bDirectConnection);
54 QString szErr = pConnecter->metaObject()->className();
55 szErr +=
"::GetViewer() is not CFrmViewer";
56 qWarning(log) << szErr.toStdString().c_str();
59 QString szErr = pConnecter->metaObject()->className();
60 szErr +=
"::GetViewer() is not CFrmScroll";
61 qWarning(log) << szErr.toStdString().c_str();
63 SetConnecter(pConnecter);
68 &m_Recorder, &QMediaRecorder::errorOccurred,
69 this, [&](QMediaRecorder::Error error,
const QString &errorString) {
70 qDebug(log) <<
"Recorder error occurred:" << error << errorString;
76 &m_Recorder, &QMediaRecorder::recorderStateChanged,
77 this, [&](QMediaRecorder::RecorderState state){
78 qDebug(log) <<
"Recorder state changed:" << state;
79 if(QMediaRecorder::StoppedState == state)
82 if(m_pParameterRecord) {
83 qDebug(log) <<
"End action:"
84 << m_pParameterRecord->GetEndAction()
85 << m_Recorder.actualLocation();
86 switch(m_pParameterRecord->GetEndAction())
88 case CParameterRecord::ENDACTION::OpenFile:
89 QDesktopServices::openUrl(m_Recorder.actualLocation());
91 case CParameterRecord::ENDACTION::OpenFolder: {
92 QFileInfo fi(m_Recorder.actualLocation().toLocalFile());
93 QDesktopServices::openUrl(
94 QUrl::fromLocalFile(fi.absolutePath()));
104 check = connect(&m_Recorder, &QMediaRecorder::actualLocationChanged,
105 this, [&](
const QUrl &location){
106 qInfo(log) <<
"Recorder actual location changed:" << location;
112CConnectDesktop::~CConnectDesktop()
114 qDebug(log) <<
"CConnectDesktop::~CConnectDesktop()";
117int CConnectDesktop::SetConnecter(
CConnecter* pConnecter)
119 qDebug(log) <<
"CConnectDesktop::SetConnecter" << pConnecter;
120 Q_ASSERT(pConnecter);
121 if(!pConnecter)
return -1;
124 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
125 pConnecter, SLOT(slotSetServerName(
const QString&)));
127 check = connect(pConnecter, SIGNAL(sigClipBoardChanged()),
130 check = connect(
this, SIGNAL(sigSetClipboard(QMimeData*)),
131 pConnecter, SLOT(slotSetClipboard(QMimeData*)));
137 check = connect(p, SIGNAL(sigRecord(
bool)),
138 this, SLOT(slotRecord(
bool)));
141 check = connect(p, SIGNAL(sigRecordPause(
bool)),
142 this, SLOT(slotRecordPause(
bool)));
146 SIGNAL(recorderStateChanged(QMediaRecorder::RecorderState)),
147 p, SLOT(slotRecorderStateChanged(QMediaRecorder::RecorderState)));
154int CConnectDesktop::SetViewer(
CFrmViewer *pView,
bool bDirectConnection)
157 if(!pView)
return -1;
160 check = connect(
this, SIGNAL(
sigConnected()), pView, SLOT(slotConnected()));
162 check = connect(
this, SIGNAL(sigSetDesktopSize(
int,
int)),
163 pView, SLOT(slotSetDesktopSize(
int,
int)));
165 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
166 pView, SLOT(slotSetName(
const QString&)));
169 check = connect(
this, SIGNAL(
sigUpdateRect(
const QRect&,
const QImage&)),
170 pView, SLOT(slotUpdateRect(
const QRect&,
const QImage&)));
173 pView, SLOT(slotUpdateRect(
const QImage&)));
175 check = connect(
this, SIGNAL(sigUpdateCursor(
const QCursor&)),
176 pView, SLOT(slotUpdateCursor(
const QCursor&)));
178 check = connect(
this, SIGNAL(sigUpdateCursorPosition(
const QPoint&)),
179 pView, SLOT(slotUpdateCursorPosition(
const QPoint&)));
181 check = connect(
this, SIGNAL(sigUpdateLedState(
unsigned int)),
182 pView, SLOT(slotUpdateLedState(
unsigned int)));
185 check = connect(
this, SIGNAL(sigRecordVideo(
bool)),
186 pView, SLOT(slotRecordVideo(
bool)));
188 check = connect(pView, SIGNAL(sigRecordVideo(QImage)),
189 this, SLOT(slotRecordVideo(QImage)),
190 Qt::DirectConnection);
193 if(bDirectConnection)
202 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
203 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)),
204 Qt::DirectConnection);
206 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
207 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)),
208 Qt::DirectConnection);
210 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
211 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)),
212 Qt::DirectConnection);
214 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
215 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)),
216 Qt::DirectConnection);
218 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
219 this, SLOT(slotKeyPressEvent(QKeyEvent*)),
220 Qt::DirectConnection);
222 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
223 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)),
224 Qt::DirectConnection);
227 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
228 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)));
230 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
231 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)));
233 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
234 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)));
236 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
237 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)));
239 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
240 this, SLOT(slotKeyPressEvent(QKeyEvent*)));
242 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
243 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)));
250void CConnectDesktop::slotWheelEvent(QWheelEvent *event, QPoint pos)
252 QWheelEvent* e =
new QWheelEvent(
254#
if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
255 event->globalPosition(),
259 event->pixelDelta(), event->angleDelta(), event->buttons(),
260 event->modifiers(), event->phase(), event->inverted(), event->source());
261 QCoreApplication::postEvent(
this, e);
265void CConnectDesktop::slotMouseMoveEvent(QMouseEvent *event, QPoint pos)
267 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
268 event->buttons(), event->modifiers());
269 QCoreApplication::postEvent(
this, e);
273void CConnectDesktop::slotMousePressEvent(QMouseEvent *event, QPoint pos)
275 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
276 event->buttons(), event->modifiers());
277 QCoreApplication::postEvent(
this, e);
281void CConnectDesktop::slotMouseReleaseEvent(QMouseEvent *event, QPoint pos)
283 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
284 event->buttons(), event->modifiers());
285 QCoreApplication::postEvent(
this, e);
289void CConnectDesktop::slotKeyPressEvent(QKeyEvent *event)
291 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
292 event->modifiers(), event->text());
293 QCoreApplication::postEvent(
this, e);
297void CConnectDesktop::slotKeyReleaseEvent(QKeyEvent *event)
299 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
300 event->modifiers(), event->text());
301 QCoreApplication::postEvent(
this, e);
305void CConnectDesktop::mouseMoveEvent(QMouseEvent *event)
307 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mouseMoveEvent";
310void CConnectDesktop::mousePressEvent(QMouseEvent *event)
312 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mousePressEvent";
315void CConnectDesktop::mouseReleaseEvent(QMouseEvent *event)
317 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mouseReleaseEvent";
320void CConnectDesktop::wheelEvent(QWheelEvent *event)
322 qDebug(logMouse) <<
"Need to implement CConnectDesktop::wheelEvent";
325void CConnectDesktop::keyPressEvent(QKeyEvent *event)
327 qDebug(logMouse) <<
"Need to implement CConnectDesktop::keyPressEvent";
330void CConnectDesktop::keyReleaseEvent(QKeyEvent *event)
332 qDebug(logMouse) <<
"Need to implement CConnectDesktop::keyReleaseEvent";
340bool CConnectDesktop::event(QEvent *event)
343 switch (event->type()) {
344 case QEvent::MouseButtonPress:
345 case QEvent::MouseButtonDblClick:
346 mousePressEvent((QMouseEvent*)event);
348 case QEvent::MouseButtonRelease:
349 mouseReleaseEvent((QMouseEvent*)event);
351 case QEvent::MouseMove:
352 mouseMoveEvent((QMouseEvent*)event);
355 wheelEvent((QWheelEvent*)event);
357 case QEvent::KeyPress:
358 keyPressEvent((QKeyEvent*)event);
360 case QEvent::KeyRelease:
361 keyReleaseEvent((QKeyEvent*)event);
364 case TypeRecordVideo:
369 return QObject::event(event);
377void CConnectDesktop::slotRecord(
bool bRecord)
379 qDebug(log) << Q_FUNC_INFO << bRecord;
381 if(QMediaRecorder::RecordingState == m_Recorder.recorderState())
383 (*m_pParameterRecord) >> m_Recorder;
384 m_CaptureSession.setVideoFrameInput(&m_VideoFrameInput);
385 m_CaptureSession.setRecorder(&m_Recorder);
389 m_CaptureSession.setVideoFrameInput(
nullptr);
390 m_CaptureSession.setAudioBufferInput(
nullptr);
391 m_CaptureSession.setRecorder(
nullptr);
393 emit sigRecordVideo(bRecord);
396void CConnectDesktop::slotRecordPause(
bool bPause)
398 qDebug(log) << Q_FUNC_INFO << bPause;
400 if(m_Recorder.recorderState() == QMediaRecorder::RecordingState)
403 if(m_Recorder.recorderState() == QMediaRecorder::PausedState)
408void CConnectDesktop::slotRecordVideo(
const QImage &img)
412 QCoreApplication::postEvent(
this, e);
418 qDebug(log) <<
"Update image";
420 if(QMediaRecorder::RecordingState != m_Recorder.recorderState()) {
421 qCritical(log) <<
"Recorder is inavailable";
424 QVideoFrame frame(e->GetImage());
425 bool bRet = m_VideoFrameInput.sendVideoFrame(frame);
429 qDebug(log) <<
"m_VideoFrameInput.sendVideoFrame fail";
CConnectDesktop(CConnecter *pConnecter, bool bDirectConnection=true)
void sigUpdateRect(const QRect &r, const QImage &image)
通知视图,图像更新
virtual int WakeUp()
唤醒连接线程(后台线程)
virtual void slotClipBoardChanged()=0
当剪切板发生改变时调用
连接接口。它由协议插件实现。 它默认启动一个定时器来开启一个非 Qt 事件循环(就是普通的循环处理)。 详见: Connect()、 slotTimeOut()、 OnProcess() 。 当然,它仍...
void sigError(const int nError, const QString &szError=QString())
当有错误产生时触发
void sigConnected()
当插件连接成功后触发。仅由插件触发
virtual int Disconnect()
断开
virtual CParameterBase * GetParameter()
Get parameter
默认启动一个后台线程。实现一个后台线程处理一个连接。 可与插件接口从 CPluginClient 派生的插件一起使用,用于连接是阻塞模型的。
virtual QWidget * GetViewer()=0
得到显示视图
用于显示从 CConnectDesktop 输出的图像,和向 CConnectDesktop 发送键盘、鼠标事件。