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,
"_");
95 && (
GetParameter()->GetGlobalParameters()->GetNameStyles()
96 & CParameterPlugin::NameStyle::Protocol)
104 QString szSecurityLevel;
106 if((
GetParameter()->GetGlobalParameters()->GetNameStyles()
107 & CParameterPlugin::NameStyle::SecurityLevel)
109 && !sl.GetUnicodeIcon().isEmpty())
110 szSecurityLevel = sl.GetUnicodeIcon().left(2);
112 return szSecurityLevel + szName;
119 QString szDescription;
120 if(!
Name().isEmpty())
121 szDescription = tr(
"Name: ") +
Name() +
"\n";
124 szDescription += tr(
"Type: ") +
GetTypeName() +
"\n";
127 szDescription += tr(
"Protocol: ") +
Protocol();
129 if(!
GetPlugin()->DisplayName().isEmpty())
132 szDescription +=
"\n";
136 szDescription += tr(
"Server name: ") +
ServerName() +
"\n";
140 szDescription += tr(
"Server address: ") +
GetParameter()->m_Net.GetHost() +
":"
141 + QString::number(
GetParameter()->m_Net.GetPort()) +
"\n";
143 QString szProxy(tr(
"Proxy") +
" ");
145 switch(proxy.GetUsedType()) {
146 case CParameterProxy::TYPE::SSHTunnel:
148 auto &sshNet = proxy.m_SSH.m_Net;
149 szProxy +=
"(" + tr(
"SSH tunnel") +
"): " + sshNet.GetHost() +
":"
150 + QString::number(sshNet.GetPort());
153 case CParameterProxy::TYPE::SockesV5:
155 auto &sockesV5 = proxy.m_SockesV5;
156 szProxy +=
"(" + tr(
"Sockes v5") +
"): " + sockesV5.GetHost() +
":"
157 + QString::number(sockesV5.GetPort());
165 if(!szProxy.isEmpty())
166 szDescription += szProxy +
"\n";
171 szDescription += tr(
"Security level: ");
172 if(!sl.GetUnicodeIcon().isEmpty())
173 szDescription += sl.GetUnicodeIcon() +
" ";
174 szDescription += sl.GetString() +
"\n";
180 return szDescription;
191 qDebug(log) << Q_FUNC_INFO;
199 Q_ASSERT(!(m_pFrmViewer && m_pScroll));
207 nRet = InitialMenu();
214 qDebug(log) << Q_FUNC_INFO;
225int COperateDesktop::InitialMenu()
230 QMenu* pMenuZoom =
new QMenu(&m_Menu);
231 pMenuZoom->setTitle(tr(
"Zoom"));
232 pMenuZoom->setIcon(QIcon::fromTheme(
"zoom"));
233 pMenuZoom->setStatusTip(tr(
"Zoom"));
234 m_pMenuZoom = m_Menu.addMenu(pMenuZoom);
235 m_pZoomToWindow = pMenuZoom->addAction(
236 QIcon::fromTheme(
"zoom-fit-best"), tr(
"Zoom to window"));
237 m_pZoomToWindow->setCheckable(
true);
238 m_pZoomToWindow->setStatusTip(tr(
"Zoom to window"));
239 m_pZoomToWindow->setToolTip(tr(
"Zoom to window"));
240 check = connect(m_pZoomToWindow, &QAction::triggered,
this,
242 m_pScroll->slotSetAdaptWindows(
246 m_pZoomAspectRatio = pMenuZoom->addAction(
247 QIcon::fromTheme(
"zoom-aspect-ratio"),
248 tr(
"Keep aspect ratio to window"));
249 m_pZoomAspectRatio->setCheckable(
true);
250 m_pZoomAspectRatio->setStatusTip(tr(
"Keep aspect ratio to window"));
251 m_pZoomAspectRatio->setToolTip(tr(
"Keep aspect ratio to window"));
252 check = connect(m_pZoomAspectRatio, &QAction::triggered,
this,
254 m_pScroll->slotSetAdaptWindows(
258 m_pZoomOriginal = pMenuZoom->addAction(
259 QIcon::fromTheme(
"zoom-original"), tr(
"Original"));
260 m_pZoomOriginal->setCheckable(
true);
261 m_pZoomOriginal->setStatusTip(tr(
"Original"));
262 m_pZoomOriginal->setToolTip(tr(
"Original"));
263 check = connect(m_pZoomOriginal, &QAction::triggered,
this,
265 m_pScroll->slotSetAdaptWindows(
269 m_pZoomIn = pMenuZoom->addAction(QIcon::fromTheme(
"zoom-in"), tr(
"Zoom in"));
270 m_pZoomIn->setCheckable(
true);
271 m_pZoomIn->setStatusTip(tr(
"Zoom in"));
272 m_pZoomIn->setToolTip(tr(
"Zoom in"));
274 m_pZoomIn, &QAction::triggered,
this,
277 if(m_psbZoomFactor) {
279 qDebug(log) <<
"Zoom in:" << factor;
280 m_psbZoomFactor->setValue(factor);
284 m_pZoomOut = pMenuZoom->addAction(
285 QIcon::fromTheme(
"zoom-out"), tr(
"Zoom out"));
286 m_pZoomOut->setCheckable(
true);
287 m_pZoomOut->setStatusTip(tr(
"Zoom out"));
288 m_pZoomOut->setToolTip(tr(
"Zoom out"));
290 m_pZoomOut, &QAction::triggered,
this,
293 if(m_psbZoomFactor) {
295 qDebug(log) <<
"Zoom out:" << factor;
296 m_psbZoomFactor->setValue(factor);
300 QActionGroup* pGBViewZoom =
new QActionGroup(
this);
302 pGBViewZoom->addAction(m_pZoomToWindow);
303 pGBViewZoom->addAction(m_pZoomAspectRatio);
304 pGBViewZoom->addAction(m_pZoomOriginal);
305 pGBViewZoom->addAction(m_pZoomIn);
306 pGBViewZoom->addAction(m_pZoomOut);
307 check = connect(pGBViewZoom, &QActionGroup::triggered,
308 this, [&](QAction* a){
309 if(a == m_pZoomIn || a == m_pZoomOut)
310 m_psbZoomFactor->setEnabled(
true);
312 m_psbZoomFactor->setEnabled(
false);
316 m_psbZoomFactor =
new QSpinBox(pMenuZoom);
317 m_psbZoomFactor->setRange(0, 9999999);
318 m_psbZoomFactor->setValue(100);
319 m_psbZoomFactor->setSuffix(
"%");
320 m_psbZoomFactor->setEnabled(
false);
323 m_psbZoomFactor, SIGNAL(valueChanged(
int)),
326 QWidgetAction* pFactor =
new QWidgetAction(pMenuZoom);
327 pFactor->setDefaultWidget(m_psbZoomFactor);
328 pMenuZoom->insertAction(m_pZoomOut, pFactor);
330 QMenu* pMenuShortCut =
new QMenu(&m_Menu);
331 pMenuShortCut->setTitle(tr(
"Send shortcut key"));
332 m_Menu.addMenu(pMenuShortCut);
333 pMenuShortCut->addAction(
334 tr(
"Send Ctl+Alt+Del"),
this, SLOT(slotShortcutCtlAltDel()));
335 pMenuShortCut->addAction(
336 tr(
"Send lock screen (Win+L)"),
this, SLOT(slotShortcutLock()));
338 m_Menu.addSeparator();
339 m_pScreenShot =
new QAction(QIcon::fromTheme(
"camera-photo"),
340 tr(
"ScreenShot"), &m_Menu);
341 m_pScreenShot->setStatusTip(tr(
"ScreenShot"));
342 m_pScreenShot->setToolTip(tr(
"ScreenShot"));
343 check = connect(m_pScreenShot, SIGNAL(triggered()),
344 this, SLOT(slotScreenShot()));
346 m_Menu.addAction(m_pScreenShot);
348 m_pRecord =
new QAction(
349 QIcon::fromTheme(
"media-record"), tr(
"Start record"), &m_Menu);
350 m_pRecord->setCheckable(
true);
351 m_pRecord->setStatusTip(tr(
"Start record"));
352 m_pRecord->setToolTip(tr(
"Start record"));
353 check = connect(m_pRecord, SIGNAL(triggered(
bool)),
354 this, SLOT(slotRecord(
bool)));
356 m_Menu.addAction(m_pRecord);
357 m_pRecordPause =
new QAction(
358 QIcon::fromTheme(
"media-playback-pause"), tr(
"Record pause"), &m_Menu);
359 m_pRecordPause->setToolTip(tr(
"Record pause"));
360 m_pRecordPause->setStatusTip(tr(
"Record pause"));
361 m_pRecordPause->setCheckable(
true);
362 m_pRecordPause->setEnabled(
false);
363 check = connect(m_pRecordPause, SIGNAL(triggered(
bool)),
364 this, SIGNAL(sigRecordPause(
bool)));
366 m_Menu.addAction(m_pRecordPause);
369 m_Menu.addSeparator();
370 if(m_pActionSettings)
371 m_Menu.addAction(m_pActionSettings);
381int COperateDesktop::Start()
383 qDebug(log) << Q_FUNC_INFO;
387 qCritical(log) <<
"new CBackendThread fail";
396int COperateDesktop::Stop()
398 qDebug(log) << Q_FUNC_INFO;
416 bool check = connect(pPara, SIGNAL(sigNameStylesChanged()),
417 this, SLOT(slotUpdateName()));
424 QString szMsg =
"There is not parameters! "
425 "please first create parameters, "
426 "then call SetParameter() in the ";
427 szMsg += metaObject()->className() + QString(
"::")
428 + metaObject()->className();
429 szMsg += QString(
"() or ") + metaObject()->className()
430 + QString(
"::") +
"Initial()";
431 szMsg +=
" to set the parameters pointer. "
432 "Default set CParameterClient for the parameters of operate "
433 "(CParameterOperate or its derived classes) "
434 "See CManager::CreateOperate. "
435 "If you are sure the parameter of operate "
436 "does not need CParameterClient. "
437 "Please overload the SetGlobalParameters() in the ";
438 szMsg += QString(metaObject()->className()) +
" . don't set it";
439 qCritical(log) << szMsg.toStdString().c_str();
458 check = connect(
GetParameter(), SIGNAL(sigNameChanged()),
459 this, SLOT(slotUpdateName()));
461 check = connect(
GetParameter(), SIGNAL(sigShowServerNameChanged()),
462 this, SLOT(slotUpdateName()));
471 check = connect(
GetParameter(), SIGNAL(sigZoomFactorChanged(
double)),
472 pViewer, SLOT(slotSetZoomFactor(
double)));
479 check = connect(
GetParameter(), SIGNAL(sigEnableInputMethod(
bool)),
480 pViewer, SLOT(slotEnableInputMethod(
bool)));
487int COperateDesktop::LoadAdaptWindows()
491 m_pFrmViewer->slotSetZoomFactor(
GetParameter()->GetZoomFactor());
493 m_psbZoomFactor->setValue(m_pFrmViewer->
GetZoomFactor() * 100);
496 if(m_pZoomToWindow) {
497 m_pZoomToWindow->trigger();
500 if(m_pZoomAspectRatio) {
501 m_pZoomAspectRatio->trigger();
504 if(m_pZoomOriginal) {
505 m_pZoomOriginal->trigger();
509 m_pZoomIn->trigger();
519 Q_ASSERT(m_pFrmViewer);
521 nRet = m_pPara->
Load(set);
523 QString szMsg =
"There is not parameters! "
524 "please first create parameters, "
525 "then call SetParameter() in the ";
526 szMsg += metaObject()->className() + QString(
"::")
527 + metaObject()->className();
528 szMsg += QString(
"() or ") + metaObject()->className()
529 + QString(
"::") +
"Initial()";
530 szMsg +=
" to set the parameters pointer. ";
531 qWarning(log) << szMsg.toStdString().c_str();
532 Q_ASSERT_X(
false,
"COperateDesktop", szMsg.toStdString().c_str());
545 GetParameter()->SetAdaptWindows(m_pFrmViewer->GetAdaptWindows());
549 nRet = m_pPara->
Save(set);
554void COperateDesktop::slotRecord(
bool checked)
556 qDebug(log) << Q_FUNC_INFO << checked;
557 QAction* pRecord = qobject_cast<QAction*>(sender());
562 pRecord->setText(tr(
"Stop record"));
565 pRecord->setText(tr(
"Start record"));
567 m_pRecordPause->setEnabled(checked);
568 emit sigRecord(checked);
572void COperateDesktop::slotRecorderStateChanged(
573 QMediaRecorder::RecorderState state)
575 qDebug(log) << Q_FUNC_INFO << state;
576 if(QMediaRecorder::StoppedState == state)
578 m_pRecord->setChecked(
false);
579 m_pRecordPause->setChecked(
false);
586 qDebug(log) <<
"zoom:" << v;
587 if(!m_pScroll || !m_pFrmViewer)
return;
588 m_pFrmViewer->slotSetZoomFactor(((
double)v) / 100);
592void COperateDesktop::slotScreenShot()
597 QString szFile = record.GetImageFile(
true);
598 bool bRet = m_pFrmViewer->GrabImage().save(szFile);
600 qDebug(log) <<
"Success: save screenshot to" << szFile;
602 qCritical(log) <<
"Fail: save screenshot to" << szFile;
603 if(record.GetEndAction() != CParameterRecord::ENDACTION::No)
604 QDesktopServices::openUrl(QUrl::fromLocalFile(szFile));
607void COperateDesktop::slotShortcutCtlAltDel()
612 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Control, Qt::ControlModifier));
613 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Alt, Qt::AltModifier));
614 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Delete, Qt::ControlModifier | Qt::AltModifier));
615 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Control, Qt::ControlModifier));
616 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Alt, Qt::AltModifier));
617 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Delete, Qt::ControlModifier | Qt::AltModifier));
620void COperateDesktop::slotShortcutLock()
625 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier));
626 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_L, Qt::NoModifier));
627 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier));
628 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_L, Qt::NoModifier));
637 || m_szServerName.isEmpty())
644 && !(
GetParameter()->GetGlobalParameters()->GetNameStyles()
645 & CParameterPlugin::NameStyle::ServerName))
648 +
":" + QString::number(
GetParameter()->m_Net.GetPort());
654 return m_szServerName;
661 if(m_szServerName == szName)
664 m_szServerName = szName;
用于显示从 CConnectDesktop 输出的图像,和向 CConnectDesktop 发送键盘、鼠标事件。
@ Original
原始桌面大小,桌面的左上点与窗口的左上点对齐
@ KeepAspectRationToWindow
保持长宽比缩放到窗口大小,窗口是固定的
@ ZoomToWindow
桌面缩放到窗口大小,窗口是固定的
double GetZoomFactor() const
调整缩放系数。 调整完成后需要调用 SetAdaptWindows(FrmViewer::Zoom) 缩放窗口大小。
virtual QString ServerName()
当前连接服务名(远程桌面的名称,如果没有,则是 IP:端口)。例如:服务名或 IP:端口
virtual CParameterBase * GetParameter() const
Get parameter
virtual int SetParameter(CParameterBase *p)
设置参数指针
virtual void slotSetServerName(const QString &szName)
[Get server name]
virtual Q_INVOKABLE int Save(QSettings &set) override
保存参数
virtual const QString Name() override
[The name of the desktop operate]
virtual const qint16 Version() const override
[The description of the desktop operate]
virtual Q_INVOKABLE int Load(QSettings &set) override
加载参数
virtual const QString Id() override
标识
virtual int Initial() override
Initial parameters and resource
virtual QWidget * GetViewer() override
得到显示视图
void slotValueChanged(int v)
emit by zoom menu in the class
virtual int SetGlobalParameters(CParameterPlugin *pPara) override
Set Global Parameters
virtual const QString Description() override
[The name of the desktop operate]
virtual int Clean() override
Clean parameters and resource
virtual CSecurityLevel::Levels GetSecurityLevel() const
Get Security Level
virtual Q_INVOKABLE int Initial()
Initial parameters and resource
virtual const QString Protocol() const
协议
virtual Q_INVOKABLE int Clean()
Clean parameters and resource
void sigViewerFocusIn(QWidget *pView)
视图获得焦点
Q_INVOKABLE CPlugin * GetPlugin() const
Get plugin
void sigUpdateParameters(COperate *pOperate)
更新参数,通知应用程序保存或显示参数
virtual const QString Id()
标识
virtual const QString GetTypeName() const
类型名
连接基础参数接口。包括基本参数(网络参数等)。 所有插件的连接参数都应从此类派生。
网络连接参数接口。此类仅在插件内有效。 其界面为 CParameterNetUI
virtual int Save(QString szFile=QString(), bool bForce=true)
Save to file
void sigChanged()
当参数改变时,触发 通常如果需要,则相应的参数会对应一个改变事件。
virtual int Load(QString szFile=QString())
Load from file
virtual const QString DisplayName() const
在界面上显示的名称
virtual const QString Description() const =0
描述