7#include <QDesktopServices>
8#include <QLoggingCategory>
11#include "BackendDesktop.h"
14static Q_LOGGING_CATEGORY(log,
"Backend.Desktop")
15static Q_LOGGING_CATEGORY(logMouse, "Backend.Desktop.Mouse")
17#define TypeRecordVideo (QEvent::User + 1)
38int g_QtKeyboardModifiers = qRegisterMetaType<Qt::KeyboardModifiers>(
"KeyboardModifiers");
39int g_QtMouseButtons = qRegisterMetaType<Qt::MouseButtons>(
"MouseButtons");
40int g_QtMouseButton = qRegisterMetaType<Qt::MouseButton>(
"MouseButton");
41int g_QMessageBox_Icon = qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
43CBackendDesktop::CBackendDesktop(
COperateDesktop *pOperate,
bool bDirectConnection)
46 , m_pParameterRecord(nullptr)
47 , m_VideoFrameInput(this)
48 , m_AudioBufferInput(this)
49 , m_AudioBufferOutput(this)
52 qDebug(log) << Q_FUNC_INFO;
58 SetViewer(pView, pOperate, bDirectConnection);
60 QString szErr = pOperate->metaObject()->className();
61 szErr +=
"::GetViewer() is not CFrmViewer";
62 qWarning(log) << szErr.toStdString().c_str();
65 QString szErr = pOperate->metaObject()->className();
66 szErr +=
"::GetViewer() is not CFrmScroll";
67 qWarning(log) << szErr.toStdString().c_str();
74 &m_Recorder, &QMediaRecorder::errorOccurred,
75 this, [&](QMediaRecorder::Error error,
const QString &errorString) {
76 qDebug(log) <<
"Recorder error occurred:" << error << errorString;
78 emit sigError(error, errorString);
82 &m_Recorder, &QMediaRecorder::recorderStateChanged,
83 this, [&](QMediaRecorder::RecorderState state){
84 qDebug(log) <<
"Recorder state changed:" << state;
85 if(QMediaRecorder::StoppedState == state)
88 if(m_pParameterRecord) {
89 qDebug(log) <<
"End action:"
90 << m_pParameterRecord->GetEndAction()
91 << m_Recorder.actualLocation();
92 switch(m_pParameterRecord->GetEndAction())
94 case CParameterRecord::ENDACTION::OpenFile:
95 QDesktopServices::openUrl(m_Recorder.actualLocation());
97 case CParameterRecord::ENDACTION::OpenFolder: {
98 QFileInfo fi(m_Recorder.actualLocation().toLocalFile());
99 QDesktopServices::openUrl(
100 QUrl::fromLocalFile(fi.absolutePath()));
110 check = connect(&m_Recorder, &QMediaRecorder::actualLocationChanged,
111 this, [&](
const QUrl &location){
112 qInfo(log) <<
"Recorder actual location changed:" << location;
118CBackendDesktop::~CBackendDesktop()
120 qDebug(log) << Q_FUNC_INFO;
127 if(!pOperate)
return -1;
130 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
131 pOperate, SLOT(slotSetServerName(
const QString&)));
133 check = connect(pOperate, SIGNAL(sigClipBoardChanged()),
136 check = connect(
this, SIGNAL(sigSetClipboard(QMimeData*)),
137 pOperate, SLOT(slotSetClipboard(QMimeData*)));
141 m_pParameterRecord = &pOperate->
GetParameter()->m_Record;
142 check = connect(pOperate, SIGNAL(sigRecord(
bool)),
143 this, SLOT(slotRecord(
bool)));
146 check = connect(pOperate, SIGNAL(sigRecordPause(
bool)),
147 this, SLOT(slotRecordPause(
bool)));
151 SIGNAL(recorderStateChanged(QMediaRecorder::RecorderState)),
152 pOperate, SLOT(slotRecorderStateChanged(QMediaRecorder::RecorderState)));
159int CBackendDesktop::SetViewer(
CFrmViewer *pView,
163 if(!pView)
return -1;
166 check = connect(
this, SIGNAL(
sigRunning()), pView, SLOT(slotRunning()));
168 check = connect(
this, SIGNAL(sigSetDesktopSize(
int,
int)),
169 pView, SLOT(slotSetDesktopSize(
int,
int)));
171 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
172 pView, SLOT(slotSetName(
const QString&)));
175 check = connect(
this, SIGNAL(
sigUpdateRect(
const QRect&,
const QImage&)),
176 pView, SLOT(slotUpdateRect(
const QRect&,
const QImage&)));
179 pView, SLOT(slotUpdateRect(
const QImage&)));
181 check = connect(
this, SIGNAL(sigUpdateCursor(
const QCursor&)),
182 pView, SLOT(slotUpdateCursor(
const QCursor&)));
184 check = connect(
this, SIGNAL(sigUpdateCursorPosition(
const QPoint&)),
185 pView, SLOT(slotUpdateCursorPosition(
const QPoint&)));
187 check = connect(
this, SIGNAL(sigUpdateLedState(
unsigned int)),
188 pView, SLOT(slotUpdateLedState(
unsigned int)));
192 check = connect(
this, SIGNAL(sigRecordVideo(
bool, qreal)),
193 pView, SLOT(slotRecordVideo(
bool, qreal)));
195 check = connect(pView, SIGNAL(sigRecordVideo(QImage)),
196 this, SLOT(slotRecordVideo(QImage)),
197 Qt::DirectConnection);
200 if(bDirectConnection)
209 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
210 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)),
211 Qt::DirectConnection);
213 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
214 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)),
215 Qt::DirectConnection);
217 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
218 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)),
219 Qt::DirectConnection);
221 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
222 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)),
223 Qt::DirectConnection);
225 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
226 this, SLOT(slotKeyPressEvent(QKeyEvent*)),
227 Qt::DirectConnection);
229 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
230 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)),
231 Qt::DirectConnection);
233 check = connect(pView, SIGNAL(sigInputMethodEvent(QInputMethodEvent*)),
234 this, SLOT(slotInputMethodEvent(QInputMethodEvent*)),
235 Qt::DirectConnection);
238 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
239 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)));
241 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
242 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)));
244 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
245 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)));
247 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
248 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)));
250 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
251 this, SLOT(slotKeyPressEvent(QKeyEvent*)));
253 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
254 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)));
256 check = connect(pView, SIGNAL(sigInputMethodEvent(QInputMethodEvent*)),
257 this, SLOT(slotInputMethodEvent(QInputMethodEvent*)));
264void CBackendDesktop::slotWheelEvent(QWheelEvent *event, QPoint pos)
266 QWheelEvent* e =
new QWheelEvent(
268#
if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
269 event->globalPosition(),
273 event->pixelDelta(), event->angleDelta(), event->buttons(),
274 event->modifiers(), event->phase(), event->inverted(), event->source());
275 QCoreApplication::postEvent(
this, e);
279void CBackendDesktop::slotMouseMoveEvent(QMouseEvent *event, QPoint pos)
281#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
282 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
283 event->buttons(), event->modifiers());
285 QMouseEvent* e =
new QMouseEvent(event->type(), pos, pos, event->button(),
286 event->buttons(), event->modifiers());
288 QCoreApplication::postEvent(
this, e);
292void CBackendDesktop::slotMousePressEvent(QMouseEvent *event, QPoint pos)
294#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
295 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
296 event->buttons(), event->modifiers());
298 QMouseEvent* e =
new QMouseEvent(event->type(), pos, pos, event->button(),
299 event->buttons(), event->modifiers());
301 QCoreApplication::postEvent(
this, e);
305void CBackendDesktop::slotMouseReleaseEvent(QMouseEvent *event, QPoint pos)
307#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
308 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
309 event->buttons(), event->modifiers());
311 QMouseEvent* e =
new QMouseEvent(event->type(), pos, pos, event->button(),
312 event->buttons(), event->modifiers());
314 QCoreApplication::postEvent(
this, e);
318void CBackendDesktop::slotKeyPressEvent(QKeyEvent *event)
320 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
321 event->modifiers(), event->text());
322 QCoreApplication::postEvent(
this, e);
326void CBackendDesktop::slotKeyReleaseEvent(QKeyEvent *event)
328 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
329 event->modifiers(), event->text());
330 QCoreApplication::postEvent(
this, e);
334void CBackendDesktop::slotInputMethodEvent(QInputMethodEvent *event)
336 if(event->commitString().isEmpty())
return;
337 QInputMethodEvent* e =
new QInputMethodEvent(event->preeditString(), event->attributes());
338 e->setCommitString(event->commitString(), event->replacementStart(), event->replacementLength());
339 QCoreApplication::postEvent(
this, e);
343void CBackendDesktop::mouseMoveEvent(QMouseEvent *event)
345 qDebug(logMouse) <<
"Need to implement CBackendDesktop::mouseMoveEvent";
348void CBackendDesktop::mousePressEvent(QMouseEvent *event)
350 qDebug(logMouse) <<
"Need to implement CBackendDesktop::mousePressEvent";
353void CBackendDesktop::mouseReleaseEvent(QMouseEvent *event)
355 qDebug(logMouse) <<
"Need to implement CBackendDesktop::mouseReleaseEvent";
358void CBackendDesktop::wheelEvent(QWheelEvent *event)
360 qDebug(logMouse) <<
"Need to implement CBackendDesktop::wheelEvent";
363void CBackendDesktop::keyPressEvent(QKeyEvent *event)
365 qDebug(logMouse) <<
"Need to implement CBackendDesktop::keyPressEvent";
368void CBackendDesktop::keyReleaseEvent(QKeyEvent *event)
370 qDebug(logMouse) <<
"Need to implement CBackendDesktop::keyReleaseEvent";
373void CBackendDesktop::InputMethodEvent(QInputMethodEvent *event)
375 qDebug(logMouse) <<
"Need to implement CBackendDesktop::InputMethodEvent";
383bool CBackendDesktop::event(QEvent *event)
386 switch (event->type()) {
387 case QEvent::MouseButtonPress:
388 case QEvent::MouseButtonDblClick:
389 mousePressEvent((QMouseEvent*)event);
391 case QEvent::MouseButtonRelease:
392 mouseReleaseEvent((QMouseEvent*)event);
394 case QEvent::MouseMove:
395 mouseMoveEvent((QMouseEvent*)event);
398 wheelEvent((QWheelEvent*)event);
400 case QEvent::KeyPress:
401 keyPressEvent((QKeyEvent*)event);
403 case QEvent::KeyRelease:
404 keyReleaseEvent((QKeyEvent*)event);
406 case QEvent::InputMethod:
407 InputMethodEvent((QInputMethodEvent*) event);
410 case TypeRecordVideo:
415 return QObject::event(event);
423void CBackendDesktop::slotRecord(
bool bRecord)
425 qDebug(log) << Q_FUNC_INFO << bRecord;
427 if(QMediaRecorder::RecordingState == m_Recorder.recorderState())
429 (*m_pParameterRecord) >> m_Recorder;
430 m_CaptureSession.setVideoFrameInput(&m_VideoFrameInput);
431 m_CaptureSession.setRecorder(&m_Recorder);
435 m_CaptureSession.setVideoFrameInput(
nullptr);
436 m_CaptureSession.setAudioBufferInput(
nullptr);
437 m_CaptureSession.setRecorder(
nullptr);
439 emit sigRecordVideo(bRecord, m_pParameterRecord->GetVideoFrameRate());
442void CBackendDesktop::slotRecordPause(
bool bPause)
444 qDebug(log) << Q_FUNC_INFO << bPause;
446 if(m_Recorder.recorderState() == QMediaRecorder::RecordingState)
449 if(m_Recorder.recorderState() == QMediaRecorder::PausedState)
454void CBackendDesktop::slotRecordVideo(
const QImage &img)
458 QCoreApplication::postEvent(
this, e);
466 if(QMediaRecorder::RecordingState != m_Recorder.recorderState()) {
467 qCritical(log) <<
"Recorder is inavailable";
470 QVideoFrame frame(e->GetImage());
471 bool bRet = m_VideoFrameInput.sendVideoFrame(frame);
475 qDebug(log) <<
"m_VideoFrameInput.sendVideoFrame fail";
void sigUpdateRect(const QRect &r, const QImage &image)
Notify the CFrmView update image.
virtual void slotClipBoardChanged()=0
Be called when the clip board change.
virtual int WakeUp() override
Wake up Backend thread(background thread)
void sigRunning()
Emitted when the plugin is successfully started.
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...
Remote desktop operate interface.
virtual QWidget * GetViewer() override
Get Viewer.
virtual CParameterBase * GetParameter()
Get parameter.