PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/FsxWsGUI/fsxwsmainwindowmenu.cpp

http://fsxws.codeplex.com
C++ | 142 lines | 89 code | 15 blank | 38 comment | 13 complexity | 10ae9244779092d6f5e4df0bf8829962 MD5 | raw file
  1. #include "fsxwsmainwindow.h"
  2. #include "ui_fsxwsmainwindow.h"
  3. using namespace FsxWsGUI;
  4. //
  5. // Test FSX configuration
  6. //
  7. void FsxWsMainWindow::onMenuFSXTest()
  8. {
  9. FsxWsMainWindow::slotSetConsoleTab();
  10. if (FsxWsMainWindow::_fsxSimConnect && FsxWsMainWindow::_fsxSimConnect->isRunning()) {
  11. FsxWsMainWindow::slotLogMessage("You are already connected to FSX, nothing to do", QtDebugMsg);
  12. return;
  13. }
  14. FsxWsMainWindow::slotLogMessage("Will try to configure, please be patient ...", QtDebugMsg);
  15. ui->qtbConsole->repaint(); // at least a message before it might hang for a while
  16. // try to connect
  17. if (FsxWsMainWindow::connectFsxSimConnect()) {
  18. FsxWsMainWindow::slotLogMessage("Connected to FSX, all fine", QtDebugMsg);
  19. FsxWsMainWindow::initFsxSimConnectButtons();
  20. return;
  21. }
  22. // last resort
  23. FsxWsMainWindow::slotLogMessage("Cannot connect to FSX, is FSX started / network connected?", QtDebugMsg);
  24. return;
  25. }
  26. //
  27. // Save a file with data as KML
  28. //
  29. void FsxWsMainWindow::onMenuFSXSaveKmlData(bool withReducedResolution) {
  30. int reducedResolutionMs = -1;
  31. if (withReducedResolution) {
  32. bool success;
  33. reducedResolutionMs = QInputDialog::getInteger(this, "Reduce resolution", "Waypoint resolution [ms]",
  34. WPMINREDUCEDRESOLUTION, WPMINREDUCEDRESOLUTION * 5, WPMINREDUCEDRESOLUTION * 20, 1000, &success);
  35. if(!success) return;
  36. }
  37. QString fileName = QFileDialog::getSaveFileName(this, tr("Save KML data (Google Earth)"), "",
  38. tr("KML (*.kml);;All Files (*)"));
  39. if (fileName.length() >0) {
  40. FsxWsMainWindow::saveWaypointsAsKml(fileName, reducedResolutionMs);
  41. }
  42. }
  43. //
  44. // Save a file with data as KML (reduced resolution)
  45. //
  46. void FsxWsMainWindow::onMenuFSXSaveKmlDataReduced() {
  47. FsxWsMainWindow::onMenuFSXSaveKmlData(true);
  48. }
  49. //
  50. // Show configuration dialog for WebServer
  51. //
  52. void FsxWsMainWindow::onMenuWsConfigure()
  53. {
  54. FsxWsMainWindow::showConfigureTab(CONFTABWS);
  55. }
  56. //
  57. // Show coniguration dialog for WebServer
  58. //
  59. void FsxWsMainWindow::onMenuWsShowInBrowser() {
  60. if (!FsxWsMainWindow::_fsxWsSettings) return;
  61. FsxWsMainWindow::onStartWebServiceClicked();
  62. QUrl url(RequestDispatcher::getDocrootUrl());
  63. QDesktopServices::openUrl(url);
  64. }
  65. //
  66. // Show the configuration dialog
  67. //
  68. void FsxWsMainWindow::onMenuFSXConfigure() {
  69. FsxWsMainWindow::showConfigureTab(CONFTABFSX);
  70. }
  71. //
  72. // Show the configuration dialog
  73. //
  74. void FsxWsMainWindow::onMenuAppKmlConfigure() {
  75. FsxWsMainWindow::showConfigureTab(CONFTABKML);
  76. }
  77. //
  78. // About dialog
  79. //
  80. void FsxWsMainWindow::onMenuHelpAbout()
  81. {
  82. if (!FsxWsMainWindow::_aboutDialog) return;
  83. FsxWsMainWindow::_aboutDialog->show();
  84. }
  85. //
  86. // Save a file with data as JSON
  87. //
  88. void FsxWsMainWindow::onMenuFSXSaveJsonData() {
  89. QString fileName = QFileDialog::getSaveFileName(this, tr("Save JSON data"), "",
  90. tr("JSON (*.js *.txt);;All Files (*)"));
  91. if (fileName.length() >0) {
  92. FsxWsMainWindow::saveJsonDataAsFile(fileName);
  93. }
  94. }
  95. //
  96. // Save a SimConnect.cfg file
  97. //
  98. void FsxWsMainWindow::onMenuFSXCreateSimConnectCfg() {
  99. QString fileName = FSXHelper::getLocalSimConnectCfgFilename();
  100. QString ipPort = QString("IP: %1 Port: %2").arg(FsxWsMainWindow::_fsxWsSettings->getFsxIpAddress()).arg(FsxWsMainWindow::_fsxWsSettings->getFsxIpPort());
  101. fileName = QFileDialog::getSaveFileName(this, "Save 'SimConnect.cfg' file " + ipPort, fileName,
  102. tr("SimConnect (*.cfg);;All Files (*)"));
  103. if (fileName.isEmpty()) return;
  104. if (FSXHelper::simConnectCfg(fileName, FsxWsMainWindow::_fsxWsSettings->getFsxIpAddress(), FsxWsMainWindow::_fsxWsSettings->getFsxIpPort())) {
  105. FsxWsMainWindow::slotLogMessage(QString("SimConnect default file written: %1").arg(fileName), QtDebugMsg);
  106. FsxWsMainWindow::slotLogMessage(ipPort, QtDebugMsg);
  107. } else {
  108. FsxWsMainWindow::slotLogMessage(QString("SimConnect NOT(!) written: %1").arg(fileName), QtWarningMsg);
  109. }
  110. }
  111. //
  112. // Delete the local SimConnect.cfg file
  113. //
  114. void FsxWsMainWindow::onMenuFSXDeleteSimConnectCfg()
  115. {
  116. QString fileName = QCoreApplication::applicationDirPath() + "/SimConnect.cfg";
  117. if (QFile::remove(fileName)) {
  118. FsxWsMainWindow::slotLogMessage(QString("SimConnect default file deleted: %1").arg(fileName), QtDebugMsg);
  119. }
  120. }
  121. //
  122. // Help has been called
  123. //
  124. void FsxWsMainWindow::onMenuHelpShowOnlineHelp() {
  125. QUrl url(APPURLHELP);
  126. QDesktopServices::openUrl(url);
  127. }