3#include <QLoggingCategory>
4#include <QDesktopServices>
6#include <QWidgetAction>
9#include "OperateDesktop.h"
10#include "BackendThread.h"
13static Q_LOGGING_CATEGORY(log,
"Operate.Desktop")
18 , m_pFrmViewer(
nullptr)
20 , m_pZoomToWindow(
nullptr)
21 , m_pZoomAspectRatio(
nullptr)
22 , m_pZoomOriginal(
nullptr)
25 , m_psbZoomFactor(
nullptr)
26 , m_pScreenShot(
nullptr)
29 , m_pRecordPause(
nullptr)
32 qDebug(log) << Q_FUNC_INFO;
35COperateDesktop::~COperateDesktop()
37 qDebug(log) << Q_FUNC_INFO;
47 +
"_" + QString::number(
GetParameter()->m_Net.GetPort());
52 case CParameterProxy::TYPE::Http: {
57 case CParameterProxy::TYPE::SockesV5:
63 case CParameterProxy::TYPE::SSHTunnel:
72 if(!szType.isEmpty() && !net->GetHost().isEmpty()) {
73 szId +=
"_" + szType +
"_";
74 szId += net->GetHost() +
"_" + QString::number(net->GetPort());
80 static QRegularExpression exp(
"[-@:/#%!^&* \\.]");
81 szId = szId.replace(exp,
"_");
93 &&
GetParameter()->GetGlobalParameters()->GetShowProtocolPrefix()
104 QString szDescription;
105 if(!
Name().isEmpty())
106 szDescription = tr(
"Name: ") +
Name() +
"\n";
109 szDescription += tr(
"Type: ") +
GetTypeName() +
"\n";
112 szDescription += tr(
"Protocol: ") +
Protocol();
114 if(!
GetPlugin()->DisplayName().isEmpty())
117 szDescription +=
"\n";
121 szDescription += tr(
"Server name: ") +
ServerName() +
"\n";
125 szDescription += tr(
"Server address: ") +
GetParameter()->m_Net.GetHost() +
":"
126 + QString::number(
GetParameter()->m_Net.GetPort()) +
"\n";
128 QString szProxy(tr(
"Proxy") +
" ");
130 switch(proxy.GetUsedType()) {
131 case CParameterProxy::TYPE::SSHTunnel:
133 auto &sshNet = proxy.m_SSH.m_Net;
134 szProxy +=
"(" + tr(
"SSH tunnel") +
"): " + sshNet.GetHost() +
":"
135 + QString::number(sshNet.GetPort());
138 case CParameterProxy::TYPE::SockesV5:
140 auto &sockesV5 = proxy.m_SockesV5;
141 szProxy +=
"(" + tr(
"Sockes v5") +
"): " + sockesV5.GetHost() +
":"
142 + QString::number(sockesV5.GetPort());
150 if(!szProxy.isEmpty())
151 szDescription += szProxy +
"\n";
154 if(GetSecurityLevel() != SecurityLevel::No)
155 szDescription += tr(
"Security level: ") + GetSecurityLevelString() +
"\n";
160 return szDescription;
170 qDebug(log) << Q_FUNC_INFO;
178 Q_ASSERT(!(m_pFrmViewer && m_pScroll));
186 nRet = InitialMenu();
193 qDebug(log) << Q_FUNC_INFO;
204int COperateDesktop::InitialMenu()
209 QMenu* pMenuZoom =
new QMenu(&m_Menu);
210 pMenuZoom->setTitle(tr(
"Zoom"));
211 pMenuZoom->setIcon(QIcon::fromTheme(
"zoom"));
212 pMenuZoom->setStatusTip(tr(
"Zoom"));
213 m_pMenuZoom = m_Menu.addMenu(pMenuZoom);
214 m_pZoomToWindow = pMenuZoom->addAction(
215 QIcon::fromTheme(
"zoom-fit-best"), tr(
"Zoom to window"));
216 m_pZoomToWindow->setCheckable(
true);
217 m_pZoomToWindow->setStatusTip(tr(
"Zoom to window"));
218 m_pZoomToWindow->setToolTip(tr(
"Zoom to window"));
219 check = connect(m_pZoomToWindow, &QAction::triggered,
this,
221 m_pScroll->slotSetAdaptWindows(
225 m_pZoomAspectRatio = pMenuZoom->addAction(
226 QIcon::fromTheme(
"zoom-aspect-ratio"),
227 tr(
"Keep aspect ratio to window"));
228 m_pZoomAspectRatio->setCheckable(
true);
229 m_pZoomAspectRatio->setStatusTip(tr(
"Keep aspect ratio to window"));
230 m_pZoomAspectRatio->setToolTip(tr(
"Keep aspect ratio to window"));
231 check = connect(m_pZoomAspectRatio, &QAction::triggered,
this,
233 m_pScroll->slotSetAdaptWindows(
237 m_pZoomOriginal = pMenuZoom->addAction(
238 QIcon::fromTheme(
"zoom-original"), tr(
"Original"));
239 m_pZoomOriginal->setCheckable(
true);
240 m_pZoomOriginal->setStatusTip(tr(
"Original"));
241 m_pZoomOriginal->setToolTip(tr(
"Original"));
242 check = connect(m_pZoomOriginal, &QAction::triggered,
this,
244 m_pScroll->slotSetAdaptWindows(
248 m_pZoomIn = pMenuZoom->addAction(QIcon::fromTheme(
"zoom-in"), tr(
"Zoom in"));
249 m_pZoomIn->setCheckable(
true);
250 m_pZoomIn->setStatusTip(tr(
"Zoom in"));
251 m_pZoomIn->setToolTip(tr(
"Zoom in"));
253 m_pZoomIn, &QAction::triggered,
this,
256 if(m_psbZoomFactor) {
258 qDebug(log) <<
"Zoom in:" << factor;
259 m_psbZoomFactor->setValue(factor);
263 m_pZoomOut = pMenuZoom->addAction(
264 QIcon::fromTheme(
"zoom-out"), tr(
"Zoom out"));
265 m_pZoomOut->setCheckable(
true);
266 m_pZoomOut->setStatusTip(tr(
"Zoom out"));
267 m_pZoomOut->setToolTip(tr(
"Zoom out"));
269 m_pZoomOut, &QAction::triggered,
this,
272 if(m_psbZoomFactor) {
274 qDebug(log) <<
"Zoom out:" << factor;
275 m_psbZoomFactor->setValue(factor);
279 QActionGroup* pGBViewZoom =
new QActionGroup(
this);
281 pGBViewZoom->addAction(m_pZoomToWindow);
282 pGBViewZoom->addAction(m_pZoomAspectRatio);
283 pGBViewZoom->addAction(m_pZoomOriginal);
284 pGBViewZoom->addAction(m_pZoomIn);
285 pGBViewZoom->addAction(m_pZoomOut);
286 check = connect(pGBViewZoom, &QActionGroup::triggered,
287 this, [&](QAction* a){
288 if(a == m_pZoomIn || a == m_pZoomOut)
289 m_psbZoomFactor->setEnabled(
true);
291 m_psbZoomFactor->setEnabled(
false);
295 m_psbZoomFactor =
new QSpinBox(pMenuZoom);
296 m_psbZoomFactor->setRange(0, 9999999);
297 m_psbZoomFactor->setValue(100);
298 m_psbZoomFactor->setSuffix(
"%");
299 m_psbZoomFactor->setEnabled(
false);
302 m_psbZoomFactor, SIGNAL(valueChanged(
int)),
305 QWidgetAction* pFactor =
new QWidgetAction(pMenuZoom);
306 pFactor->setDefaultWidget(m_psbZoomFactor);
307 pMenuZoom->insertAction(m_pZoomOut, pFactor);
309 QMenu* pMenuShortCut =
new QMenu(&m_Menu);
310 pMenuShortCut->setTitle(tr(
"Send shortcut key"));
311 m_Menu.addMenu(pMenuShortCut);
312 pMenuShortCut->addAction(
313 tr(
"Send Ctl+Alt+Del"),
this, SLOT(slotShortcutCtlAltDel()));
314 pMenuShortCut->addAction(
315 tr(
"Send lock screen (Win+L)"),
this, SLOT(slotShortcutLock()));
317 m_Menu.addSeparator();
318 m_pScreenShot =
new QAction(QIcon::fromTheme(
"camera-photo"),
319 tr(
"ScreenShot"), &m_Menu);
320 m_pScreenShot->setStatusTip(tr(
"ScreenShot"));
321 m_pScreenShot->setToolTip(tr(
"ScreenShot"));
322 check = connect(m_pScreenShot, SIGNAL(triggered()),
323 this, SLOT(slotScreenShot()));
325 m_Menu.addAction(m_pScreenShot);
327 m_pRecord =
new QAction(
328 QIcon::fromTheme(
"media-record"), tr(
"Start record"), &m_Menu);
329 m_pRecord->setCheckable(
true);
330 m_pRecord->setStatusTip(tr(
"Start record"));
331 m_pRecord->setToolTip(tr(
"Start record"));
332 check = connect(m_pRecord, SIGNAL(triggered(
bool)),
333 this, SLOT(slotRecord(
bool)));
335 m_Menu.addAction(m_pRecord);
336 m_pRecordPause =
new QAction(
337 QIcon::fromTheme(
"media-playback-pause"), tr(
"Record pause"), &m_Menu);
338 m_pRecordPause->setToolTip(tr(
"Record pause"));
339 m_pRecordPause->setStatusTip(tr(
"Record pause"));
340 m_pRecordPause->setCheckable(
true);
341 m_pRecordPause->setEnabled(
false);
342 check = connect(m_pRecordPause, SIGNAL(triggered(
bool)),
343 this, SIGNAL(sigRecordPause(
bool)));
345 m_Menu.addAction(m_pRecordPause);
348 m_Menu.addSeparator();
349 if(m_pActionSettings)
350 m_Menu.addAction(m_pActionSettings);
360int COperateDesktop::Start()
362 qDebug(log) << Q_FUNC_INFO;
366 qCritical(log) <<
"new CBackendThread fail";
375int COperateDesktop::Stop()
377 qDebug(log) << Q_FUNC_INFO;
396 bool check = connect(pPara, SIGNAL(sigShowProtocolPrefixChanged()),
397 this, SLOT(slotUpdateName()));
399 check = connect(pPara, SIGNAL(sigSHowIpPortInNameChanged()),
400 this, SLOT(slotUpdateName()));
407 QString szMsg =
"There is not parameters! "
408 "please first create parameters, "
409 "then call SetParameter() in the ";
410 szMsg += metaObject()->className() + QString(
"::")
411 + metaObject()->className();
412 szMsg += QString(
"() or ") + metaObject()->className()
413 + QString(
"::") +
"Initial()";
414 szMsg +=
" to set the parameters pointer. "
415 "Default set CParameterClient for the parameters of operate "
416 "(CParameterOperate or its derived classes) "
417 "See CManager::CreateOperate. "
418 "If you are sure the parameter of operate "
419 "does not need CParameterClient. "
420 "Please overload the SetGlobalParameters() in the ";
421 szMsg += QString(metaObject()->className()) +
" . don't set it";
422 qCritical(log) << szMsg.toStdString().c_str();
440 check = connect(
GetParameter(), SIGNAL(sigNameChanged()),
441 this, SLOT(slotUpdateName()));
443 check = connect(
GetParameter(), SIGNAL(sigShowServerNameChanged()),
444 this, SLOT(slotUpdateName()));
453 check = connect(
GetParameter(), SIGNAL(sigZoomFactorChanged(
double)),
454 pViewer, SLOT(slotSetZoomFactor(
double)));
461 check = connect(
GetParameter(), SIGNAL(sigEnableInputMethod(
bool)),
462 pViewer, SLOT(slotEnableInputMethod(
bool)));
469int COperateDesktop::LoadAdaptWindows()
473 m_pFrmViewer->slotSetZoomFactor(
GetParameter()->GetZoomFactor());
475 m_psbZoomFactor->setValue(m_pFrmViewer->
GetZoomFactor() * 100);
478 if(m_pZoomToWindow) {
479 m_pZoomToWindow->trigger();
482 if(m_pZoomAspectRatio) {
483 m_pZoomAspectRatio->trigger();
486 if(m_pZoomOriginal) {
487 m_pZoomOriginal->trigger();
491 m_pZoomIn->trigger();
501 Q_ASSERT(m_pFrmViewer);
503 nRet = m_pPara->
Load(set);
505 QString szMsg =
"There is not parameters! "
506 "please first create parameters, "
507 "then call SetParameter() in the ";
508 szMsg += metaObject()->className() + QString(
"::")
509 + metaObject()->className();
510 szMsg += QString(
"() or ") + metaObject()->className()
511 + QString(
"::") +
"Initial()";
512 szMsg +=
" to set the parameters pointer. ";
513 qWarning(log) << szMsg.toStdString().c_str();
527 GetParameter()->SetAdaptWindows(m_pFrmViewer->GetAdaptWindows());
531 nRet = m_pPara->
Save(set);
536void COperateDesktop::slotRecord(
bool checked)
538 qDebug(log) << Q_FUNC_INFO << checked;
539 QAction* pRecord = qobject_cast<QAction*>(sender());
544 pRecord->setText(tr(
"Stop record"));
547 pRecord->setText(tr(
"Start record"));
549 m_pRecordPause->setEnabled(checked);
550 emit sigRecord(checked);
554void COperateDesktop::slotRecorderStateChanged(
555 QMediaRecorder::RecorderState state)
557 qDebug(log) << Q_FUNC_INFO << state;
558 if(QMediaRecorder::StoppedState == state)
560 m_pRecord->setChecked(
false);
561 m_pRecordPause->setChecked(
false);
568 qDebug(log) <<
"zoom:" << v;
569 if(!m_pScroll || !m_pFrmViewer)
return;
570 m_pFrmViewer->slotSetZoomFactor(((
double)v) / 100);
574void COperateDesktop::slotScreenShot()
579 QString szFile = record.GetImageFile(
true);
580 bool bRet = m_pFrmViewer->GrabImage().save(szFile);
582 qDebug(log) <<
"Success: save screenshot to" << szFile;
584 qCritical(log) <<
"Fail: save screenshot to" << szFile;
585 if(record.GetEndAction() != CParameterRecord::ENDACTION::No)
586 QDesktopServices::openUrl(QUrl::fromLocalFile(szFile));
589void COperateDesktop::slotShortcutCtlAltDel()
594 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Control, Qt::ControlModifier));
595 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Alt, Qt::AltModifier));
596 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Delete, Qt::ControlModifier | Qt::AltModifier));
597 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Control, Qt::ControlModifier));
598 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Alt, Qt::AltModifier));
599 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Delete, Qt::ControlModifier | Qt::AltModifier));
602void COperateDesktop::slotShortcutLock()
607 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier));
608 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_L, Qt::NoModifier));
609 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier));
610 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_L, Qt::NoModifier));
618 || m_szServerName.isEmpty())
625 &&
GetParameter()->GetGlobalParameters()->GetShowIpPortInName())
628 +
":" + QString::number(
GetParameter()->m_Net.GetPort());
632 return m_szServerName;
637 if(m_szServerName == szName)
640 m_szServerName = szName;
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...
ADAPT_WINDOWS
The ADAPT_WINDOWS enum.
@ Original
Original desktop size, the left-top of the desktop is aligned with the left-top of the window.
@ Zoom
zoom windows = desktop size * factor
@ KeepAspectRationToWindow
Keep desktop aspectration adapt to windows.
@ ZoomToWindow
Desktop adapt to windows.
double GetZoomFactor() const
Adjust the zoom factor.
Remote desktop operate interface.
virtual QString ServerName()
Current connect server name (remote desktop name, if not present, then IP:PORT).
virtual int SetParameter(CParameterBase *p)
Set parameter pointer.
virtual void slotSetServerName(const QString &szName)
virtual int Save(QSettings &set) override
Save parameters.
virtual const QString Name() override
Name.
virtual const qint16 Version() const override
Version.
virtual int Load(QSettings &set) override
Load parameters.
virtual const QString Id() override
Identity.
virtual int Initial() override
Initial parameters and resource.
virtual QWidget * GetViewer() override
Get Viewer.
void slotValueChanged(int v)
emit by zoom menu in the class
virtual int SetGlobalParameters(CParameterPlugin *pPara) override
Apply the global parameters of the plug-in.
virtual const QString Description() override
Description.
virtual int Clean() override
Clean parameters and resource.
virtual CParameterBase * GetParameter()
Get parameter.
virtual Q_INVOKABLE int Initial()
Initial parameters and resource.
virtual const QString Protocol() const
Protocol.
virtual Q_INVOKABLE int Clean()
Clean parameters and resource.
void sigViewerFocusIn(QWidget *pView)
The view is focus.
Q_INVOKABLE CPlugin * GetPlugin() const
Get plugin.
void sigUpdateParameters(COperate *pOperate)
Update parameters, notify application to save or show parameters.
virtual const QString Id()
Identity.
virtual const QString GetTypeName() const
Get type name.
The interface of connecter parameters.
Basic network parameters.
Global parameters of plugins.
virtual int Save(QString szFile=QString(), bool bForce=true)
Save to file.
void sigChanged()
emit when the parameter changes Usually if required, the corresponding parameter corresponds to a cha...
virtual int Load(QString szFile=QString())
Load from file.
virtual const QString DisplayName() const
The plugin display name.
virtual const QString Description() const =0
Plugin description.