Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

maindialog.cpp 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include <QApplication>
  2. #include <QDesktopWidget>
  3. #include <QDebug>
  4. #include "maindialog.h"
  5. #include "ui_maindialog.h"
  6. #include "rdesktoplauncher.h"
  7. #include "rdpoptionshelper.h"
  8. MainDialog::MainDialog(QWidget *parent) :
  9. QDialog(parent),
  10. ui(new Ui::MainDialog)
  11. {
  12. ui->setupUi(this);
  13. connect(ui->lineComputer->lineEdit(), SIGNAL(returnPressed()), ui->btnConnect, SLOT(animateClick()));
  14. connect(ui->lineComputer->lineEdit(), SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
  15. computeResolutions();
  16. QStringList layouts;
  17. for (int l = QLocale::Abkhazian; l <= QLocale::Shambala; ++l)
  18. {
  19. QString name = QLocale((QLocale::Language)l).name().replace("_", "-").toLower();
  20. if (!layouts.contains(name))
  21. layouts.append(name);
  22. }
  23. layouts.sort();
  24. ui->comboKeyboard->addItems(layouts);
  25. ui->comboKeyboard->lineEdit()->setText("en-us");
  26. loadAll();
  27. }
  28. MainDialog::~MainDialog()
  29. {
  30. delete ui;
  31. }
  32. RdpOptions MainDialog::getRdpOptions() const
  33. {
  34. RdpOptions opt;
  35. opt.setHost(ui->lineComputer->currentText());
  36. opt.setUsername(ui->lineUsername->text());
  37. opt.setPassword(ui->linePassword->text());
  38. opt.setFullscreen(ui->slidResolution->value() == m_resolutions.size());
  39. if (!opt.fullscreen())
  40. opt.setResolution(m_resolutions.at(m_resolutions.size() - 1));
  41. opt.setUseAllMonitors(ui->checkAllDisplays->isChecked());
  42. int colors = ui->comboColors->currentIndex();
  43. RdpOptions::Colors c;
  44. if (colors == 0)
  45. c = RdpOptions::HighColor_15;
  46. else if (colors == 1)
  47. c = RdpOptions::HighColor_16;
  48. else if (colors == 2)
  49. c = RdpOptions::TrueColor;
  50. else if (colors == 3)
  51. c = RdpOptions::HighestQuality;
  52. opt.setColors(c);
  53. opt.setFullscreenBar(ui->checkFullscreenBar->isChecked());
  54. int meta = ui->comboMetaKeys->currentIndex();
  55. opt.setMetaKeys(meta == 0 || (opt.fullscreen() && meta == 2));
  56. opt.setUseShell(ui->checkShell->isChecked());
  57. if (opt.useShell())
  58. {
  59. opt.setShell(ui->lineShellPath->text());
  60. opt.setShellWorkingDir(ui->lineShellWorkingDir->text());
  61. }
  62. opt.setExperience((RdpOptions::Experience)ui->comboExperience->currentIndex());
  63. opt.setBitmapCache(ui->checkCacheBitmap->isChecked());
  64. opt.setAutoReconnect(ui->checkAutoReconnect->isChecked());
  65. opt.setKeymap(ui->comboKeyboard->currentText());
  66. return opt;
  67. }
  68. void MainDialog::setRdpOptions(const RdpOptions &opt)
  69. {
  70. ui->lineComputer->lineEdit()->setText(opt.host());
  71. ui->lineUsername->setText(opt.username());
  72. ui->linePassword->setText(opt.password());
  73. if (opt.fullscreen())
  74. {
  75. ui->slidResolution->setValue(ui->slidResolution->maximum());
  76. }
  77. else
  78. {
  79. ui->slidResolution->setValue(ui->slidResolution->maximum() - 1);
  80. }
  81. ui->checkAllDisplays->setChecked(opt.useAllMonitors());
  82. int index = 0;
  83. RdpOptions::Colors c = opt.colors();
  84. if (c == RdpOptions::HighColor_15)
  85. index = 0;
  86. else if (c == RdpOptions::HighColor_16)
  87. index = 1;
  88. else if (c == RdpOptions::TrueColor)
  89. index = 2;
  90. else if (c == RdpOptions::HighestQuality)
  91. index = 3;
  92. ui->comboColors->setCurrentIndex(index);
  93. ui->checkFullscreenBar->setChecked(opt.fullscreenBar());
  94. ui->comboMetaKeys->setCurrentIndex(opt.metaKeys() ? 2 : 1);
  95. ui->checkShell->setChecked(opt.useShell());
  96. ui->lineShellPath->setText(opt.shell());
  97. ui->lineShellWorkingDir->setText(opt.shellWorkingDir());
  98. ui->comboExperience->setCurrentIndex((int)opt.experience());
  99. ui->checkCacheBitmap->setChecked(opt.bitmapCache());
  100. ui->checkAutoReconnect->setChecked(opt.autoReconnect());
  101. ui->comboKeyboard->lineEdit()->setText(opt.keymap());
  102. }
  103. void MainDialog::loadAll()
  104. {
  105. m_rdpOptions = RdpOptionsHelper::loadAll();
  106. ui->lineComputer->clear();
  107. ui->lineComputer->addItem("");
  108. for (int i = 1; i < m_rdpOptions.size(); ++i)
  109. {
  110. RdpOptions opt = m_rdpOptions.at(i);
  111. ui->lineComputer->addItem(opt.host());
  112. }
  113. ui->lineComputer->setFocus();
  114. }
  115. void MainDialog::on_btnConnect_clicked()
  116. {
  117. RdpOptions opt = getRdpOptions();
  118. RdpOptionsHelper::save(opt);
  119. RDesktopLauncher launcher;
  120. launcher.start(opt);
  121. }
  122. void MainDialog::textChanged(QString)
  123. {
  124. ui->btnConnect->setEnabled(!ui->lineComputer->lineEdit()->text().isEmpty());
  125. }
  126. void MainDialog::computeResolutions()
  127. {
  128. m_resolutions.append(QApplication::desktop()->availableGeometry().size());
  129. ui->slidResolution->setMinimum(0);
  130. ui->slidResolution->setMaximum(m_resolutions.size());
  131. ui->slidResolution->setValue(m_resolutions.size());
  132. }
  133. void MainDialog::on_slidResolution_valueChanged(int value)
  134. {
  135. if (value < m_resolutions.size())
  136. {
  137. QSize reso = m_resolutions.at(value);
  138. ui->lblResolution->setText(QString("%1x%2").arg(reso.width()).arg(reso.height()));
  139. }
  140. else
  141. {
  142. ui->lblResolution->setText(tr("Plein écran"));
  143. }
  144. }
  145. void MainDialog::on_btnSaveSession_clicked()
  146. {
  147. RdpOptionsHelper::save(getRdpOptions());
  148. loadAll();
  149. }
  150. void MainDialog::on_btnSaveAsSession_clicked()
  151. {
  152. on_btnSaveSession_clicked();
  153. }
  154. void MainDialog::on_btnOpenSession_clicked()
  155. {
  156. }
  157. void MainDialog::on_lineComputer_currentIndexChanged(int index)
  158. {
  159. if (index >= 0 && index < m_rdpOptions.size())
  160. {
  161. setRdpOptions(m_rdpOptions.at(index));
  162. }
  163. }
  164. void MainDialog::on_btnRemoveSession_clicked()
  165. {
  166. RdpOptionsHelper::remove(getRdpOptions());
  167. loadAll();
  168. }