Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
DlgSetFreeRDP.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "DlgSetFreeRDP.h"
4#include "ui_DlgSetFreeRDP.h"
5#include "ParameterNetUI.h"
6
7#include <QApplication>
8#include <QScreen>
9#include <QFileSystemModel>
10
11#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
12 #include <QMediaDevices>
13 #include <QAudioDevice>
14#else
15 #include <QAudioDeviceInfo>
16#endif
17
18#include "DlgDesktopSize.h"
19#include <QLoggingCategory>
20static Q_LOGGING_CATEGORY(log, "FreeRDP.Parameter.Dlg")
21
22CDlgSetFreeRDP::CDlgSetFreeRDP(CParameterFreeRDP *pSettings, QWidget *parent) :
23 QDialog(parent)
24 , ui(new Ui::CDlgSetFreeRDP)
25 , m_pSettings(pSettings)
26 , m_pFileModel(nullptr)
27 , m_pProxyUI(nullptr)
28 , m_pRecordUI(nullptr)
29{
30 setAttribute(Qt::WA_DeleteOnClose);
31 ui->setupUi(this);
32
33 ui->leName->setText(m_pSettings->GetName());
34
35 // Server
36 ui->leDomain->setText(m_pSettings->GetDomain());
37 ui->wNet->SetParameter(&m_pSettings->m_Net);
38
39 ui->cbOnlyView->setChecked(m_pSettings->GetOnlyView());
40 ui->cbClipboard->setChecked(m_pSettings->GetClipboard());
41 ui->cbShowServerName->setChecked(m_pSettings->GetShowServerName());
42
43 m_pProxyUI = new CParameterProxyUI(ui->tabWidget);
44 m_pProxyUI->SetParameter(&m_pSettings->m_Proxy);
45 ui->tabWidget->insertTab(1, m_pProxyUI, m_pProxyUI->windowIcon(), tr("Proxy"));
46
47 m_pRecordUI = new CParameterRecordUI(ui->tabWidget);
48 m_pRecordUI->SetParameter(&m_pSettings->m_Record);
49 ui->tabWidget->addTab(m_pRecordUI, m_pRecordUI->windowIcon(), tr("Record"));
50
51 // Display
52 // It has to be the first. GetScreenGeometry depends on it
53 ui->cbAllMonitor->setChecked(m_pSettings->GetUseMultimon());
54 UpdateDesktopSize();
55 int width = GetScreenGeometry().width();
56 int height = GetScreenGeometry().height();
57 QString curSize = QString::number(width) + "×" + QString::number(height);
58 UINT32 desktopWidth = 0, desktopHeight = 0;
59 desktopWidth = m_pSettings->GetDesktopWidth();
60 desktopHeight = m_pSettings->GetDesktopHeight();
61 if(width == desktopWidth && height == desktopHeight)
62 {
63 ui->rbLocalScreen->setChecked(true);
64 ui->cbDesktopSize->setCurrentText(curSize);
65 } else {
66 ui->rbSelect->setChecked(true);
67 curSize = QString::number(desktopWidth)
68 + "×" + QString::number(desktopHeight);
69 ui->cbDesktopSize->setCurrentText(curSize);
70 }
71
72 ui->cbColorDepth->addItem(tr("8 bits"), 8);
73 ui->cbColorDepth->addItem(tr("16 bits"), 16);
74 ui->cbColorDepth->addItem(tr("24 bits"), 24);
75 ui->cbColorDepth->addItem(tr("32 bits"), 32);
76 int nIndex = ui->cbColorDepth->findData(
77 m_pSettings->GetColorDepth());
78 if(-1 != nIndex)
79 ui->cbColorDepth->setCurrentIndex(nIndex);
80
81 ui->sbReconnect->setValue(m_pSettings->GetReconnectInterval());
82
83 // Redirection printer
84 ui->cbPrinter->setChecked(m_pSettings->GetRedirectionPrinter());
85
86 // Redirection audio output
87 ui->gbAudio->setEnabled(HasAudioOutput() || HasAudioInput());
88 if(m_pSettings->GetRedirectionSound() == CParameterFreeRDP::RedirecionSoundType::Disable)
89 ui->rbAudioDisable->setChecked(true);
90 if(m_pSettings->GetRedirectionSound() == CParameterFreeRDP::RedirecionSoundType::Local)
91 ui->rbAudioLocal->setChecked(true);
92 if(m_pSettings->GetRedirectionSound() == CParameterFreeRDP::RedirecionSoundType::Remote)
93 ui->rbAudioRemote->setChecked(true);
94 QString szRdpSndParameters
95 = tr("- [sys:<sys>,][dev:<dev>,][format:<format>,][rate:<rate>,][channel:<channel>]\n"
96 #if defined (Q_OS_WINDOWS) || defined(Q_OS_WIN) || defined(Q_OS_WIN32) || defined(Q_OS_WINRT)
97 "- sys:winmm"
98 #elif defined(Q_OS_IOS)
99 "- sys:ios\n"
100 "- sys:mac"
101 #elif defined (Q_OS_ANDROID)
102 "- sys:opensles"
103 #elif defined (Q_OS_LINUX) || defined (Q_OS_UNIX)
104 "- sys:alsa\n"
105 "- sys:oss\n"
106 "- sys:oss,dev:1,format:1\n"
107 "- sys:sndio"
108 #endif
109 );
110 QString szRdpSnd = tr("Options for redirection of audio output:\n") + szRdpSndParameters;
111 ui->leRdpSnd->setToolTip(szRdpSnd);
112 ui->leRdpSnd->setStatusTip(szRdpSnd);
113 ui->leRdpSnd->setWhatsThis(szRdpSnd);
114 ui->leRdpSnd->setEnabled(HasAudioOutput());
115 ui->leRdpSnd->setText(m_pSettings->GetRedirectionSoundParameters());
116 // Redirection audio input
117 QString szAudin = tr("Options for redirection of audio input:\n") + szRdpSndParameters;
118 ui->leAudin->setToolTip(szAudin);
119 ui->leAudin->setStatusTip(szAudin);
120 ui->leAudin->setWhatsThis(szAudin);
121 ui->leAudin->setText(m_pSettings->GetRedirectionMicrophoneParameters());
122 if(HasAudioInput()) {
123 ui->cbAudin->setChecked(m_pSettings->GetRedirectionMicrophone());
124 } else {
125 ui->cbAudin->setChecked(false);
126 ui->cbAudin->setEnabled(false);
127 ui->leAudin->setEnabled(false);
128 }
129
130 // Drive
131 m_pFileModel= new QFileSystemModel();
132 m_pFileModel->setNameFilterDisables(false);
133 m_pFileModel->setFilter(QDir::Drives | QDir::Dirs | QDir::NoDotAndDotDot);
134 m_pFileModel->setRootPath("");
135 ui->tvDrive->setModel(m_pFileModel);
136 ui->tvDrive->setEditTriggers(QAbstractItemView::NoEditTriggers);
137 int count = m_pFileModel->columnCount();
138 for(int i = 1; i < count; i++)
139 ui->tvDrive->hideColumn(i);
140 bool check = connect(ui->tvDrive->selectionModel(),
141 SIGNAL(selectionChanged(const QItemSelection &,
142 const QItemSelection &)),
143 this,
144 SLOT(slotSelectionChanged(QItemSelection,QItemSelection)));
145 Q_ASSERT(check);
146 QStringList lstDrives = m_pSettings->GetRedirectionDrives();
147 foreach(auto path, lstDrives)
148 {
149 QModelIndex index;
150 if(!path.isEmpty()) {
151 index = m_pFileModel->index(path);
152 ui->tvDrive->setCurrentIndex(index);
153 }
154 }
155 ShowDriveSelected(lstDrives.size());
156}
157
158CDlgSetFreeRDP::~CDlgSetFreeRDP()
159{
160 delete ui;
161}
162
163void CDlgSetFreeRDP::on_pbOk_clicked()
164{
165 int nRet = 0;
166
167 if(!ui->wNet->CheckValidity(true)) {
168 ui->tabWidget->setCurrentIndex(0);
169 return;
170 }
171 if(!m_pProxyUI->CheckValidity(true)) {
172 ui->tabWidget->setCurrentWidget(m_pProxyUI);
173 return;
174 }
175 if(!m_pRecordUI->CheckValidity(true)) {
176 ui->tabWidget->setCurrentWidget(m_pRecordUI);
177 return;
178 }
179
180 m_pSettings->SetName(ui->leName->text());
181
182 // Server
183 m_pSettings->SetDomain(ui->leDomain->text());
184 nRet = ui->wNet->Accept();
185 if(nRet) return;
186
187 nRet = m_pProxyUI->Accept();
188 if(nRet) return;
189
190 nRet = m_pRecordUI->Accept();
191 if(nRet) return;
192
193 m_pSettings->SetOnlyView(ui->cbOnlyView->isChecked());
194 m_pSettings->SetClipboard(ui->cbClipboard->isChecked());
195 m_pSettings->SetShowServerName(ui->cbShowServerName->isChecked());
196
197 // Display
198 m_pSettings->SetUseMultimon(ui->cbAllMonitor->isChecked());
199 QString szSize = ui->cbDesktopSize->currentText();
200 int index = szSize.indexOf("×");
201 if(-1 < index)
202 {
203 UINT32 width = szSize.left(index).toInt();
204 UINT32 height = szSize.right(szSize.length() - index - 1).toInt();
205 m_pSettings->SetDesktopWidth(width);
206 m_pSettings->SetDesktopHeight(height);
207 }
208 m_pSettings->SetColorDepth(ui->cbColorDepth->currentData().toInt());
209 m_pSettings->SetReconnectInterval(ui->sbReconnect->value());
210
211 // Redirection
212 m_pSettings->SetRedirectionPrinter(ui->cbPrinter->isChecked());
213 if(HasAudioOutput()) {
214 CParameterFreeRDP::RedirecionSoundType tRdirectionSound
215 = CParameterFreeRDP::RedirecionSoundType::Disable;
216 if(ui->rbAudioDisable->isChecked())
217 tRdirectionSound = CParameterFreeRDP::RedirecionSoundType::Disable;
218 else if(ui->rbAudioLocal->isChecked())
219 tRdirectionSound = CParameterFreeRDP::RedirecionSoundType::Local;
220 else if(ui->rbAudioRemote->isChecked())
221 tRdirectionSound = CParameterFreeRDP::RedirecionSoundType::Remote;
222 m_pSettings->SetRedirectionSound(tRdirectionSound);
223 } else {
224 m_pSettings->SetRedirectionSound(
225 CParameterFreeRDP::RedirecionSoundType::Disable);
226 }
227 m_pSettings->SetRedirectionSoundParameters(ui->leRdpSnd->text());
228 if(HasAudioInput())
229 m_pSettings->SetRedirectionMicrophone(ui->cbAudin->isChecked());
230 else
231 m_pSettings->SetRedirectionMicrophone(false);
232 m_pSettings->SetRedirectionMicrophoneParameters(ui->leAudin->text());
233
234 QStringList lstDrives;
235 //获取选中的行,默认获取选中行的第一列数据(0),列的索引值和上面一样0、1、2、3......
236 QModelIndexList selected = ui->tvDrive->selectionModel()->selectedRows(0);
237 QList<QModelIndex>::iterator it;
238 QModelIndex modelIndex;
239 QString szPath;
240 for (it = selected.begin(); it != selected.end(); ++it)
241 {
242 modelIndex = *it;
243 szPath = m_pFileModel->filePath(modelIndex);
244 if(!szPath.isEmpty())
245 lstDrives.append(szPath);
246 }
247 m_pSettings->SetRedirectionDrives(lstDrives);
248
249 accept();
250}
251
252void CDlgSetFreeRDP::on_pbCancel_clicked()
253{
254 reject();
255}
256
257void CDlgSetFreeRDP::on_rbLocalScreen_clicked(bool checked)
258{
259 if(!checked) return;
260 int width = GetScreenGeometry().width();
261 int height = GetScreenGeometry().height();
262 QString curSize = QString::number(width) + "×" + QString::number(height);
263 ui->rbLocalScreen->setText(tr("Local screen") + ": " + curSize);
264 if(ui->cbDesktopSize->findText(curSize) == -1)
265 InsertDesktopSize(width, height);
266 ui->cbDesktopSize->setCurrentText(curSize);
267}
268
269QRect CDlgSetFreeRDP::GetScreenGeometry()
270{
271 QRect r;
272 QScreen* pScreen = QApplication::primaryScreen();
273 if(ui->cbAllMonitor->isChecked())
274 {
275 //TODO: check this is a virtual geometry
276 r = pScreen->virtualGeometry();
277 /*
278 auto lstScreen = QApplication::screens();
279 qDebug(log) << "Screen counts:" << lstScreen.count();
280 int i = 0;
281 foreach(auto pScreen, lstScreen)
282 {
283 //r = r.united(pScreen->geometry());
284 qDebug(log)
285 << "ID:" << i++
286 << "geometry:" << pScreen->geometry()
287 << "availableGeometry:" << pScreen->availableGeometry()
288 << "virtualGeometry" << pScreen->virtualGeometry()
289 << "availableVirtualGeometry" << pScreen->availableVirtualGeometry();
290 }//*/
291 } else {
292 r = pScreen->geometry();
293 }
294 return r;
295}
296
297int CDlgSetFreeRDP::UpdateDesktopSize()
298{
299 ui->cbDesktopSize->clear();
300 QStringList lstDesktopSizes;
301 lstDesktopSizes <<"640×480"
302 <<"800×600"
303 <<"1024×600"
304 <<"1024×768"
305 <<"1280×720"
306 <<"1280×854"
307 <<"1280×960"
308 <<"1280×1024"
309 <<"1366×768"
310 <<"1400×1050"
311 <<"1440×900"
312 <<"1600×900"
313 <<"1600×1024"
314 <<"1600×1200"
315 <<"1680×1050"
316 <<"1920×1080"
317 <<"1920×1200";
318 ui->cbDesktopSize->addItems(lstDesktopSizes);
319
320 int width = GetScreenGeometry().width();
321 int height = GetScreenGeometry().height();
322 QString curSize = QString::number(width) + "×" + QString::number(height);
323 ui->rbLocalScreen->setText(tr("Local screen") + ": " + curSize);
324 if(ui->cbDesktopSize->findText(curSize) == -1)
325 InsertDesktopSize(width, height);
326 return 0;
327}
328
329int CDlgSetFreeRDP::InsertDesktopSize(QString szSize)
330{
331 int w, h;
332 int nIndex = szSize.indexOf("×");
333 if(nIndex > -1)
334 {
335 bool ok = false;
336 w = szSize.left(nIndex).toInt(&ok);
337 if(ok)
338 h = szSize.right(szSize.length() - nIndex - 1).toInt(&ok);
339 if(!ok)
340 return -1;
341 }
342 return InsertDesktopSize(w, h);
343}
344
345int CDlgSetFreeRDP::InsertDesktopSize(int width, int height)
346{
347 QString curSize = QString::number(width) + "×" + QString::number(height);
348 if(ui->cbDesktopSize->findText(curSize) > -1)
349 return 0;
350
351 int nCount = ui->cbDesktopSize->count();
352 for(int i = 0; i < nCount; i++)
353 {
354 QString curText = ui->cbDesktopSize->itemText(i);
355 int nIndex = curText.indexOf("×");
356 if(nIndex > -1)
357 {
358 int w = curText.left(nIndex).toInt();
359 int h = curText.right(curText.length() - nIndex - 1).toInt();
360 if(w > width)
361 {
362 ui->cbDesktopSize->insertItem(i, curSize);
363 return 0;
364 } else if(w == width) {
365 if(h > height)
366 {
367 ui->cbDesktopSize->insertItem(i, curSize);
368 return 0;
369 } if(h == height) {
370 return 0;
371 } else {
372 int j = i + 1;
373 while(j < nCount) {
374 QString curText = ui->cbDesktopSize->itemText(j);
375 int nIndex = curText.indexOf("×");
376 if(-1 >= nIndex) {
377 j++;
378 } else {
379 int w = curText.left(nIndex).toInt();
380 int h = curText.right(curText.length() - nIndex - 1).toInt();
381 if(w != width) {
382 ui->cbDesktopSize->insertItem(j, curSize);
383 return 0;
384 } else {
385 if(h > height)
386 {
387 ui->cbDesktopSize->insertItem(j, curSize);
388 return 0;
389 } else if(h == height)
390 return 0;
391 else
392 j++;
393 }
394 }
395 }
396 }
397 }
398 }
399 }
400
401 if(ui->cbDesktopSize->findText(curSize) == -1)
402 ui->cbDesktopSize->addItem(curSize);
403
404 return 0;
405}
406
407
408void CDlgSetFreeRDP::on_rbAudioDisable_toggled(bool checked)
409{
410 ui->leRdpSnd->setEnabled(!checked);
411}
412
413void CDlgSetFreeRDP::on_rbAudioLocal_toggled(bool checked)
414{
415 ui->leRdpSnd->setEnabled(checked);
416}
417
418void CDlgSetFreeRDP::on_rbAudioRemote_toggled(bool checked)
419{
420 ui->leRdpSnd->setEnabled(!checked);
421 ui->leAudin->setEnabled(!checked);
422 ui->cbAudin->setEnabled(!checked);
423}
424
425bool CDlgSetFreeRDP::HasAudioOutput()
426{
427#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
428 auto d = QMediaDevices::defaultAudioOutput();
429 return !d.isNull();
430#else
431 return !QAudioDeviceInfo::defaultOutputDevice().isNull();
432#endif
433}
434
435bool CDlgSetFreeRDP::HasAudioInput()
436{
437#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
438 auto d = QMediaDevices::defaultAudioInput();
439 return !d.isNull();
440#else
441 return !QAudioDeviceInfo::defaultInputDevice().isNull();
442#endif
443}
444
445void CDlgSetFreeRDP::on_pbSizeEdit_clicked()
446{
447 CDlgDesktopSize dlg;
448 QStringList lstSize;
449 for(int i = 0; i < ui->cbDesktopSize->count(); i++)
450 lstSize << ui->cbDesktopSize->itemText(i);
451 dlg.SetDesktopSizes(lstSize);
452 if(QDialog::Accepted == dlg.exec())
453 {
454 ui->cbDesktopSize->clear();
455 foreach(auto s, dlg.GetDesktopSize())
456 {
457 InsertDesktopSize(s);
458 }
459 }
460}
461
462void CDlgSetFreeRDP::on_pbDriveClearAll_clicked()
463{
464 ui->tvDrive->clearSelection();
465 ShowDriveSelected(0);
466}
467
468void CDlgSetFreeRDP::slotSelectionChanged(const QItemSelection &selected,
469 const QItemSelection &deselected)
470{
471 QModelIndexList s = ui->tvDrive->selectionModel()->selectedRows(0);
472 ShowDriveSelected(s.size());
473}
474
475int CDlgSetFreeRDP::ShowDriveSelected(int counts)
476{
477 ui->lbDriveSelected->setText(tr("Selected counts: ") + QString::number(counts));
478 return 0;
479}
480
481void CDlgSetFreeRDP::on_cbAllMonitor_stateChanged(int arg1)
482{
483 on_rbLocalScreen_clicked(true);
484}
[Declare CParameterFreeRDP]
The proxy parameter UI.
bool CheckValidity(bool validity=false)
Check parameters validity.
int Accept()
Accept parameters.
virtual bool CheckValidity(bool validity=false)
Check parameters validity.