PageRenderTime 33ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/launchBoxSim/launchboxsim.cpp

https://bitbucket.org/sumant_rapsodo/sourcetree
C++ | 2714 lines | 2408 code | 229 blank | 77 comment | 567 complexity | d041307d184aaffb1d6835c1eb2b6c14 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. /*******************************************************************************
  2. * @attention
  3. *
  4. * AUTHOR: Michael, Kelvin
  5. *
  6. * DATE: 8 March 2016
  7. *
  8. * VERSION: 1.44
  9. *
  10. * COPYRIGHT RAPSODO PTE. LTD. MARCH, 2016
  11. * ALL RIGHTS RESERVED
  12. *
  13. * THE SOFTWARE IS PROVIDED �AS IS�, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTIBILITY,
  14. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. * LIABILITY,. WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  16. * IN SOFTWARE.
  17. * `
  18. * YOU SHOULD HAVE A LICENSE AGREEMENT WITH RAPSODO TO USE THIS SOURCE CODE.
  19. * CONFIDENTIAL AND RELEASED UNDER NDA.
  20. ********************************************************************************************************/
  21. #include "launchboxsim.h"
  22. #include <QScrollBar>
  23. #include <QMovie>
  24. #include "rmdInterface.h"
  25. #include "helper.h"
  26. #define MAIN_APPLICATION_VERSION_MAJOR 1
  27. #define MAIN_APPLICATION_VERSION_MINOR 3
  28. #define MAIN_APPLICATION_VERSION_TAIL 2
  29. #define FW_VERSION_MAJOR 1
  30. #define FW_VERSION_MINOR 3
  31. #define FW_VERSION_TAIL 1
  32. #define HW_VERSION_MAJOR 1
  33. #define HW_VERSION_MINOR 2
  34. #define HW_VERSION_TAIL 0
  35. static unsigned char encrytionKeys[ENCRYPTION_KEY_SIZE]=
  36. {
  37. //G5M5E97O41KNjLpT6kc5vCTLmM0dnLea ProTee to Rapsodo Key
  38. 0x47, 0x35, 0x4d, 0x35, 0x45, 0x39, 0x37, 0x4f, 0x34, 0x31, 0x4b,
  39. 0x4e, 0x6a, 0x4c, 0x70, 0x54, 0x36, 0x6b, 0x63, 0x35, 0x76, 0x43,
  40. 0x54, 0x4c, 0x6d, 0x4d, 0x30, 0x64, 0x6e, 0x4c, 0x65, 0x61
  41. };
  42. static unsigned char encrytionIVLE[ENCRYPTION_KEY_SIZE]=
  43. {
  44. //139tes147rboPO0teze4Xh0W8W7Fb1a1 ProTee to Rapsodo Key
  45. 0x31, 0x33, 0x39, 0x74, 0x65, 0x73, 0x31, 0x34, 0x37, 0x72, 0x62,
  46. 0x6f, 0x50, 0x4f, 0x30, 0x74, 0x65, 0x7a, 0x65, 0x34, 0x58, 0x68,
  47. 0x30, 0x57, 0x38, 0x57, 0x37, 0x46, 0x62, 0x31, 0x61, 0x31
  48. };
  49. extern QString gamePathString;
  50. extern QString ourPathString;
  51. extern QString zipFilePrepend;
  52. extern ball_params ballResult;
  53. extern club_params clubResult;
  54. launchBoxSim::launchBoxSim(QWidget *parent)
  55. : QMainWindow(parent)
  56. {
  57. ui.setupUi(this);
  58. setWindowFlags(Qt::Window);
  59. statusBar()->hide();
  60. windowsTitleString = "R-Motion " + QString::number(MAIN_APPLICATION_VERSION_MAJOR) + "." + QString::number(MAIN_APPLICATION_VERSION_MINOR) +
  61. "." + QString::number(MAIN_APPLICATION_VERSION_TAIL);
  62. setWindowTitle(windowsTitleString);
  63. qDebug() << "Current Version:" << windowsTitleString;
  64. savedData = new QSettings("Rapsodo", "Rmotion");
  65. qDebug() << savedData->fileName();
  66. userLoginStatus = savedData->value("ui/userLoginStatus", QVariant(0)).toInt();
  67. userLicenseStatus = savedData->value("ui/userLicenseStatus", QVariant(0)).toInt();
  68. userEmail = savedData->value("ui/userEmail", QVariant(tr(""))).toString();
  69. dongleIdText = savedData->value("ui/dongleIdText", QVariant(tr(""))).toString();
  70. machineIdText = savedData->value("ui/machineIdText", QVariant(tr(""))).toString();
  71. userLicenseText = savedData->value("ui/userLicenseText", QVariant(tr(""))).toString();
  72. userFullLicenseText = savedData->value("ui/userFullLicenseText", QVariant(tr(""))).toString();
  73. licenseCurState = LICENSE_SM_NONE_VALID;
  74. licenseNewState = LICENSE_SM_MIN;
  75. triedFreeLicense = 0;
  76. triedFullLicense = 0;
  77. settingsEnableShotLog = "OFF";
  78. settingsEnableDebugMode = "OFF";
  79. settingsSendDebugData = "OFF";
  80. settingsSendFalseTrigger = "OFF";
  81. settingsDisableAutoStandby = "OFF";
  82. // read user settings from userSettings.txt file
  83. QFile userSettingsFile(ourPathString + "userSettings.txt");
  84. if ((userSettingsFile.exists()) && (userSettingsFile.open(QFile::ReadOnly | QFile::Text))) // check if the file existed and we can read
  85. {
  86. QTextStream tmpIn(&userSettingsFile);
  87. QString userSettingsText = "";
  88. while ((userSettingsText = tmpIn.readLine()) != "")
  89. {
  90. QList<QString> userSettingsToken = userSettingsText.split('=');
  91. if (userSettingsToken.count() == 2)
  92. {
  93. if ((userSettingsToken[0].contains("USER_ENABLE_SHOT_LOG")) && (userSettingsToken[1].contains("ON")))
  94. settingsEnableShotLog = "ON";
  95. if ((userSettingsToken[0].contains("USER_DISABLE_AUTO_STANDBY")) && (userSettingsToken[1].contains("ON")))
  96. settingsDisableAutoStandby = "ON";
  97. if ((userSettingsToken[0].contains("USER_SEND_DEBUG_DATA")) && (userSettingsToken[1].contains("ON")))
  98. settingsSendDebugData = "ON";
  99. if ((userSettingsToken[0].contains("USER_SEND_FALSE_TRIGGER")) && (userSettingsToken[1].contains("ON")))
  100. settingsSendFalseTrigger = "ON";
  101. if ((userSettingsToken[0].contains("USER_ENABLE_DEBUG_MODE")) && (userSettingsToken[1].contains("ON")))
  102. settingsEnableDebugMode = "ON";
  103. }
  104. }
  105. userSettingsFile.close();
  106. }
  107. qDebug() << "From file: disableAutoStandby" << settingsDisableAutoStandby;
  108. qDebug() << "From file: enableShotLog" << settingsEnableShotLog;
  109. qDebug() << "From file: enableDebugMode" << settingsEnableDebugMode;
  110. qDebug() << "From file: sendDebugData" << settingsSendDebugData;
  111. qDebug() << "From file: sendFalseTrigger" << settingsSendFalseTrigger;
  112. settingsDiagnosticMode = savedData->value("ui/settingsDiagnosticMode", QVariant("DISABLED")).toString();
  113. if (settingsDiagnosticMode == "DISABLED")
  114. {
  115. ui.diagnosticDisabledRadio->setChecked(true);
  116. qDebug() << "Diagnostic mode is disabled";
  117. }
  118. else if (settingsDiagnosticMode == "ENABLED")
  119. {
  120. ui.diagnosticEnabledRadio->setChecked(true);
  121. qDebug() << "Diagnostic mode is enabled";
  122. }
  123. networkManager = new QNetworkAccessManager(this);
  124. connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)), Qt::QueuedConnection);
  125. newAppMajor = MAIN_APPLICATION_VERSION_MAJOR;
  126. newAppMinor = MAIN_APPLICATION_VERSION_MINOR;
  127. newAppTail = MAIN_APPLICATION_VERSION_TAIL;
  128. scanningInProgress = 0;
  129. curClubType = "";
  130. curPlayerHand = "RH";
  131. curPlayerName = "DEFAULT_ADULT";
  132. settingsBallType = savedData->value("ui/settingsBallType", QVariant(tr("HARDBALL"))).toString();
  133. settingsKidMode = savedData->value("ui/settingsKidMode", QVariant(tr("DISABLE"))).toString();
  134. if (settingsBallType == "HARDBALL")
  135. ui.hardBallRadio->setChecked(true);
  136. else if (settingsBallType == "ALMOSTBALL")
  137. ui.almostBallRadio->setChecked(true);
  138. if (settingsKidMode == "ENABLE")
  139. ui.kidModeEnableRadio->setChecked(true);
  140. else if (settingsKidMode == "DISABLE")
  141. ui.kidModeDisableRadio->setChecked(true);
  142. ui.kidModeDisableRadio->setVisible(false);
  143. ui.kidModeEnableRadio->setVisible(false);
  144. deviceList = QList<QByteArray>();
  145. ui.deviceListSelectBox->hide();
  146. monitorGetLicenseRequire = new QTimer(this);
  147. //to fix font size to pixel instead of point
  148. QFont font1 = ui.dongleIdLabel->font();
  149. font1.setPixelSize(13);
  150. font1.setFamily("Arial");
  151. font1.setItalic(1);
  152. font1.setBold(1);
  153. ui.dongleIdLabel->setFont(font1);
  154. QFont font2 = ui.otherInfoLabel->font();
  155. font2.setPixelSize(13);
  156. font2.setFamily("Arial");
  157. font2.setItalic(1);
  158. font2.setBold(1);
  159. ui.otherInfoLabel->setFont(font2);
  160. otherInfoString = "";
  161. QFont font3 = ui.hardwareVersionLabel->font();
  162. font3.setPixelSize(13);
  163. font3.setFamily("Arial");
  164. font3.setItalic(1);
  165. font3.setBold(1);
  166. ui.hardwareVersionLabel->setFont(font3);
  167. QFont font10 = ui.firmwareVersionLabel->font();
  168. font10.setPixelSize(13);
  169. font10.setFamily("Arial");
  170. font10.setItalic(1);
  171. font10.setBold(1);
  172. ui.firmwareVersionLabel->setFont(font10);
  173. QFont font4 = ui.deviceIdLabel->font();
  174. font4.setPixelSize(13);
  175. font4.setFamily("Arial");
  176. font4.setItalic(1);
  177. font4.setBold(1);
  178. ui.deviceIdLabel->setFont(font4);
  179. QFont font5 = ui.applicationVersionLabel->font();
  180. font4.setPixelSize(13);
  181. font4.setFamily("Arial");
  182. font4.setItalic(1);
  183. font4.setBold(1);
  184. ui.applicationVersionLabel->setFont(font4);
  185. ui.applicationVersionLabel->setText(QString::number(MAIN_APPLICATION_VERSION_MAJOR) + "." + QString::number(MAIN_APPLICATION_VERSION_MINOR) +
  186. "." + QString::number(MAIN_APPLICATION_VERSION_TAIL));
  187. QFont font8 = ui.licensekeyText->font();
  188. font8.setPixelSize(11);
  189. font8.setFamily("Arial");
  190. ui.licensekeyText->setFont(font8);
  191. //init side panel window
  192. ui.dashboardPushButton->setFlat(true);
  193. ui.upgradePushbutton->setFlat(true);
  194. ui.helpPushbutton->setFlat(true);
  195. ui.aboutPushButton->setFlat(true);
  196. ui.clubsPushButton->setFlat(true);
  197. ui.settingsPushButton->setFlat(true);
  198. if (userLoginStatus > 0)
  199. {
  200. QPixmap tempPm(":/launchBoxSim/images/logoutButton.png");
  201. ui.loginButtonLabel->setPixmap(tempPm);
  202. ui.loginButtonLabel->show();
  203. ui.loginPushbutton->raise();
  204. }
  205. else
  206. {
  207. QPixmap tempPm(":/launchBoxSim/images/loginButton.png");
  208. ui.loginButtonLabel->setPixmap(tempPm);
  209. ui.loginButtonLabel->show();
  210. ui.loginPushbutton->raise();
  211. }
  212. ui.playGameButton->setDisabled(1);
  213. xmlObject = new xmlParser();
  214. if (gamePathString == QString(""))
  215. {
  216. game = new gameInterface(xmlObject->proteeDirectory, 0);
  217. }
  218. else
  219. {
  220. //system("runas /user:Administrator@domain \"taskkill /F /T /IM server.exe\"");
  221. //system("taskkill /F /T /IM server.exe /IM golf.exe > /dev/null 2>&1 &");
  222. QProcess::execute("taskkill /F /T /IM server.exe /IM golf.exe");
  223. game = new gameInterface(gamePathString, 0);
  224. }
  225. connect(this, SIGNAL(startPlayingGame()), game, SLOT(launchSimGame()), Qt::QueuedConnection);
  226. connect(this, SIGNAL(ui2GameAskForMachineID()), game, SLOT(askForMachineID()), Qt::QueuedConnection);
  227. connect(this, SIGNAL(ui2GameAskForPlayerInfo()), game, SLOT(askForPlayerInfo()), Qt::QueuedConnection);
  228. connect(this, SIGNAL(ui2GameRemoveLicense()), game, SLOT(removeLicense()), Qt::QueuedConnection);
  229. connect(this, SIGNAL(ui2GameConnectLicense(QString)), game, SLOT(connectLicense(QString)), Qt::QueuedConnection);
  230. connect(this, SIGNAL(ballFly2UI(QJsonObject)), game, SLOT(transmitData(QJsonObject)), Qt::QueuedConnection);
  231. connect(game, SIGNAL(gameServerScanStarted()), this, SLOT(scanForGameStatus()), Qt::QueuedConnection);
  232. connect(game, SIGNAL(gameStarted()), this, SLOT(game2UIReady()), Qt::QueuedConnection);
  233. connect(game, SIGNAL(gameFinished()), this, SLOT(game2UIFinished()), Qt::QueuedConnection);
  234. connect(game, SIGNAL(gameIncomingPlayerStatus(QJsonObject)), this, SLOT(game2UIPlayerInfo(QJsonObject)), Qt::QueuedConnection);
  235. connect(game, SIGNAL(gameMIDReady(QString)), this, SLOT(game2UIMachineIDReady(QString)), Qt::QueuedConnection);
  236. connect(game, SIGNAL(gameLicenseAccepted()), this, SLOT(game2UILicenseAccepted()), Qt::QueuedConnection);
  237. connect(game, SIGNAL(gameLicenseNotAccepted(QString)), this, SLOT(game2UILicenseNotAccepted(QString)), Qt::QueuedConnection);
  238. connect(game, SIGNAL(gameGameNotFound()), this, SLOT(game2UINotFound()), Qt::QueuedConnection);
  239. connect(game, SIGNAL(gameServerConnected()), this, SLOT(game2UIServerConnected()), Qt::QueuedConnection);
  240. box = new boxInterface(0);
  241. connect(box, SIGNAL(bleAppReady()), this, SLOT(uiBleAppReady()), Qt::QueuedConnection);
  242. connect(box, SIGNAL(dongleInserted()), this, SLOT(uiDongleInserted()), Qt::QueuedConnection);
  243. connect(box, SIGNAL(dongleRemoved()), this, SLOT(uiDongleRemoved()), Qt::QueuedConnection);
  244. connect(box, SIGNAL(rmotionConnected()), this, SLOT(uiRmotionConnected()), Qt::QueuedConnection);
  245. connect(box, SIGNAL(rmotionDisconnected()), this, SLOT(uiRmotionDisconnected()), Qt::QueuedConnection);
  246. connect(box, SIGNAL(rmotionInfoAvailable()), this, SLOT(uiRmotionInfoUpdate()), Qt::QueuedConnection);
  247. connect(box, SIGNAL(rmotionFwUpgradeSuccess()), this, SLOT(uiRmotionFwUpgradeSuccess()), Qt::QueuedConnection);//fw upgrade success
  248. connect(box, SIGNAL(rmotionFwUpgradeFailure()), this, SLOT(uiRmotionFwUpgradeFailure()), Qt::QueuedConnection);//fw upgrade fail
  249. connect(box, SIGNAL(rmotionFwUpgradeProgress(int)), this, SLOT(uiRmotionFwUpgradeProgress(int)), Qt::QueuedConnection);
  250. connect(box, SIGNAL(deviceListDevice(unsigned char *)), this, SLOT(uiDeviceListDevice(unsigned char *)), Qt::DirectConnection);
  251. connect(box, SIGNAL(deviceListEnd()), this, SLOT(uiDeviceListEnd()), Qt::QueuedConnection);
  252. connect(box, SIGNAL(unableToConnect()), this, SLOT(connectToDeviceTimeout()), Qt::QueuedConnection);
  253. connect(box, SIGNAL(shotDataAvailable()), this, SLOT(wrapLaunchData()), Qt::QueuedConnection);
  254. connect(this, SIGNAL(uiStartFWUpgrade()), box, SLOT(startFWUpgrade()), Qt::QueuedConnection);
  255. connect(this, SIGNAL(uiRestartDevice()), box, SLOT(restartDevice()), Qt::QueuedConnection);
  256. connect(this, SIGNAL(uiDisarmDevice()), box, SLOT(disarmDevice()), Qt::QueuedConnection);
  257. connect(this, SIGNAL(uiConnectDevice(unsigned char *)), box, SLOT(connectDevice(unsigned char *)), Qt::DirectConnection);
  258. connect(this, SIGNAL(uiStartScanning()), box, SLOT(startScanning()), Qt::QueuedConnection);
  259. connect(this, SIGNAL(uiChangePlayingMode(QString, QString, float, QString, QString, float, float, int)),
  260. box, SLOT(changePlayingMode(QString, QString, float, QString, QString, float, float, int)), Qt::QueuedConnection);
  261. connect(this, SIGNAL(uiChangeUserSettings(QString, QString, QString, QString, QString)),
  262. box, SLOT(changeUserSettings(QString, QString, QString, QString, QString)), Qt::QueuedConnection);
  263. if (game->gameStatus == GAMEDISCONNECTED)
  264. {
  265. scanForGameStatus();
  266. }
  267. if (userLicenseStatus == 0)
  268. {
  269. //ask for machine id
  270. emit ui2GameAskForMachineID();
  271. }
  272. curHelpSlide = 1;
  273. int notShowHelpStartUp = savedData->value("ui/notShowHelpStartUp", QVariant(0)).toInt();
  274. if (notShowHelpStartUp == 0)
  275. ui.notShowCheckBox->setCheckState(Qt::Unchecked);
  276. else
  277. ui.notShowCheckBox->setCheckState(Qt::Checked);
  278. if (notShowHelpStartUp == 0)
  279. {
  280. clickedOkHelp();
  281. ui.dashboardPushButton->setDisabled(1);
  282. ui.clubsPushButton->setDisabled(1);
  283. ui.settingsPushButton->setDisabled(1);
  284. ui.upgradePushbutton->setDisabled(1);
  285. ui.aboutPushButton->setDisabled(1);
  286. ui.helpPushbutton->setDisabled(1);
  287. }
  288. else if (userLoginStatus == 0)
  289. {
  290. clickedOkLogin();
  291. }
  292. else if (userLicenseStatus == 0)
  293. {
  294. goToLicenseRequest();
  295. }
  296. else
  297. {
  298. clickedOkDashBoard();
  299. }
  300. //to elevate and show window after splash screen
  301. QTimer::singleShot(2000, this, SLOT(elevateWindow()));
  302. // init player club info list
  303. initPlayerClubInfoList();
  304. for (QMap<QString, PlayerClubs>::const_iterator i = playerClubInfoList.constBegin(); i != playerClubInfoList.constEnd(); i++)
  305. {
  306. QString tmpStr = createPlayerClubInfoLine(i.key());
  307. qDebug() << tmpStr;
  308. }
  309. if (needToSavePlayerClubInfoList == true)
  310. savePlayerClubInfoList();
  311. // display DEFAULT club info
  312. ui.playerListSelectBox->addItem("DEFAULT_ADULT");
  313. ui.playerListSelectBox->addItem("DEFAULT_KID");
  314. for (QMap<QString, PlayerClubs>::const_iterator i = playerClubInfoList.constBegin(); i != playerClubInfoList.constEnd(); i++)
  315. if ((i.key() != "DEFAULT_ADULT") && (i.key() != "DEFAULT_KID"))
  316. ui.playerListSelectBox->addItem(i.key());
  317. selectedPlayerName = "DEFAULT_ADULT";
  318. selectedBaseInfo = "DEFAULT_ADULT";
  319. ui.playerListSelectBox->setCurrentIndex(0);
  320. displayPlayerClubInfo("DEFAULT_ADULT");
  321. ui.saveClubInfoButton->setDisabled(1);
  322. ui.playerListSelectBox->addItem("How To Add New Player And Manage Clubs ...");
  323. // check for new app available
  324. checkAppUpdate();
  325. // shot database
  326. shotDatabase = new ShotDatabase(0);
  327. shotSyncFunc(); // sync when app start
  328. // sync every 5 minutes
  329. QTimer *shotSyncTimer = new QTimer(this);
  330. connect(shotSyncTimer, SIGNAL(timeout()), this, SLOT(shotSyncFunc()));
  331. shotSyncTimer->start(300000); // every 5 minutes
  332. }
  333. launchBoxSim::~launchBoxSim()
  334. {
  335. delete game;
  336. delete box;
  337. delete savedData;
  338. }
  339. void launchBoxSim::uiLicenseUpdateIcon()
  340. {
  341. if (userLicenseStatus > 0)
  342. {
  343. QPixmap tmpPm(":/launchBoxSim/images/statusOK.png");
  344. ui.licenseStatusLabel->setPixmap(tmpPm);
  345. ui.licenseStatusLabel->show();
  346. }
  347. else
  348. {
  349. QPixmap tmpPm(":/launchBoxSim/images/statusNOK.png");
  350. ui.licenseStatusLabel->setPixmap(tmpPm);
  351. ui.licenseStatusLabel->show();
  352. }
  353. }
  354. //load login
  355. void launchBoxSim::clickedOkLogin()
  356. {
  357. // if user is already logged in, this means user wants to logout
  358. if (userLoginStatus > 0)
  359. {
  360. userLoginStatus = 0;
  361. savedData->setValue("ui/userLoginStatus", QVariant(userLoginStatus));
  362. QPixmap tempPm(":/launchBoxSim/images/loginButton.png");
  363. ui.loginButtonLabel->setPixmap(tempPm);
  364. ui.loginButtonLabel->show();
  365. ui.loginPushbutton->raise();
  366. }
  367. // if the timer to monitor license request requirement is running, stop it
  368. if ((monitorGetLicenseRequire != NULL) && (monitorGetLicenseRequire->isActive()))
  369. monitorGetLicenseRequire->stop();
  370. ui.stackedWidget->setCurrentIndex(3);
  371. QPixmap pixmap(":/launchBoxSim/images/loginSkeleton.png");
  372. this->setFixedSize(pixmap.width(), pixmap.height());
  373. QPalette palette;
  374. palette.setBrush(QPalette::Background, pixmap);
  375. this->setPalette(palette);
  376. ui.signinButton->setDisabled(1);
  377. ui.emailText->clear();
  378. ui.passwordText->clear();
  379. ui.loginErrorLabel->clear();
  380. ui.dashboardPushButton->setDisabled(1);
  381. ui.clubsPushButton->setDisabled(1);
  382. ui.settingsPushButton->setDisabled(1);
  383. ui.upgradePushbutton->setDisabled(1);
  384. ui.helpPushbutton->setDisabled(1);
  385. ui.aboutPushButton->setDisabled(1);
  386. }
  387. //load dash board
  388. void launchBoxSim::clickedOkDashBoard()
  389. {
  390. uiLicenseUpdateIcon();
  391. ui.stackedWidget->setCurrentIndex(0);
  392. QPixmap pixmap(":/launchBoxSim/images/dashboardSkeleton.png");
  393. this->setFixedSize(pixmap.width(), pixmap.height());
  394. QPalette palette;
  395. palette.setBrush(QPalette::Background, pixmap);
  396. this->setPalette(palette);
  397. ui.dashboardPushButton->setDisabled(0);
  398. ui.clubsPushButton->setDisabled(0);
  399. ui.settingsPushButton->setDisabled(0);
  400. ui.upgradePushbutton->setDisabled(0);
  401. ui.helpPushbutton->setDisabled(0);
  402. ui.aboutPushButton->setDisabled(0);
  403. ui.batteryStatusLabel->show();
  404. }
  405. void launchBoxSim::clickedOkUpgrade()
  406. {
  407. ui.stackedWidget->setCurrentIndex(1);
  408. QPixmap pixmap(":/launchBoxSim/images/upgradeSkeleton.png");
  409. this->setFixedSize(pixmap.width(), pixmap.height());
  410. QPalette palette;
  411. palette.setBrush(QPalette::Background, pixmap);
  412. this->setPalette(palette);
  413. ui.activateLicense->setDisabled(1);
  414. if (userLicenseStatus == 2)
  415. {
  416. ui.buyNow->setDisabled(1);
  417. ui.notInterested->setDisabled(1);
  418. ui.licensekeyText->setText(userFullLicenseText);
  419. ui.licensekeyText->setReadOnly(true);
  420. ui.activateLicense->setDisabled(1);
  421. QMessageBox msgBox;
  422. msgBox.setWindowTitle("R-Motion");
  423. msgBox.setText("Full TGC license is already activated.");
  424. msgBox.exec();
  425. }
  426. }
  427. //load help
  428. void launchBoxSim::clickedOkHelp()
  429. {
  430. curHelpSlide = 1;
  431. ui.stackedWidget->setCurrentIndex(2);
  432. QPixmap pixmap(":/launchBoxSim/images/helpSkeleton1.png");
  433. this->setFixedSize(pixmap.width(), pixmap.height());
  434. QPalette palette;
  435. palette.setBrush(QPalette::Background, pixmap);
  436. this->setPalette(palette);
  437. ui.prevSlideButton->setDisabled(1);
  438. ui.nextSlideButton->setStyleSheet("QPushButton{border-image: url(:/launchBoxSim/images/nextButton.png); outline: none; }");
  439. }
  440. //load about
  441. void launchBoxSim::clickedOkAbout()
  442. {
  443. ui.stackedWidget->setCurrentIndex(7);
  444. QPixmap pixmap(":/launchBoxSim/images/aboutSkeleton.png");
  445. this->setFixedSize(pixmap.width(), pixmap.height());
  446. QPalette palette;
  447. palette.setBrush(QPalette::Background, pixmap);
  448. this->setPalette(palette);
  449. }
  450. void launchBoxSim::clickedOkSettings()
  451. {
  452. ui.stackedWidget->setCurrentIndex(9);
  453. QPixmap pixmap(":/launchBoxSim/images/settingsSkeleton.png");
  454. this->setFixedSize(pixmap.width(), pixmap.height());
  455. QPalette palette;
  456. palette.setBrush(QPalette::Background, pixmap);
  457. this->setPalette(palette);
  458. }
  459. void launchBoxSim::clickedOkClubs()
  460. {
  461. ui.stackedWidget->setCurrentIndex(8);
  462. QPixmap pixmap(":/launchBoxSim/images/clubsSkeleton.png");
  463. this->setFixedSize(pixmap.width(), pixmap.height());
  464. QPalette palette;
  465. palette.setBrush(QPalette::Background, pixmap);
  466. this->setPalette(palette);
  467. ui.clubLengthExplanation->setVisible(false);
  468. needToSavePlayerClubInfoList = false;
  469. displayPlayerClubInfo(selectedPlayerName);
  470. ui.saveClubInfoButton->setDisabled(1);
  471. }
  472. //start TGC game
  473. void launchBoxSim::clickedPlayGame()
  474. {
  475. emit startPlayingGame();
  476. }
  477. void launchBoxSim::clickedActivateButton()
  478. {
  479. userFullLicenseText = ui.licensekeyText->toPlainText();
  480. licenseNewState = LICENSE_SM_ACTIVATE_FULL;
  481. emit ui2GameConnectLicense(userFullLicenseText);
  482. }
  483. void launchBoxSim::uiBleAppReady()
  484. {
  485. qDebug() << "BLE APP ready, send user settings now";
  486. if (settingsDiagnosticMode == "DISABLED")
  487. emit uiChangeUserSettings(settingsDisableAutoStandby, "OFF", "OFF", "OFF", "OFF");
  488. else if (settingsDiagnosticMode == "ENABLED")
  489. emit uiChangeUserSettings(settingsDisableAutoStandby, settingsEnableShotLog, settingsEnableDebugMode,
  490. settingsSendDebugData, settingsSendFalseTrigger);
  491. }
  492. void launchBoxSim::uiDongleInserted()
  493. {
  494. qDebug() << "Dongle is inserted";
  495. QPixmap dongleStatusOkPm(":/launchBoxSim/images/statusOK.png");
  496. ui.dongleStatusLabel->setPixmap(dongleStatusOkPm);
  497. ui.dongleStatusLabel->show();
  498. uiDongleIdUpdate();
  499. if ((userLoginStatus > 0) && (userLicenseStatus > 0))
  500. {
  501. scanForRmotion();
  502. scanForGameStatus();
  503. }
  504. }
  505. void launchBoxSim::uiDongleRemoved()
  506. {
  507. qDebug() << "Dongle is removed";
  508. QPixmap dongleStatusNokPm(":/launchBoxSim/images/statusNOK.png");
  509. ui.dongleStatusLabel->setPixmap(dongleStatusNokPm);
  510. ui.dongleStatusLabel->show();
  511. uiDongleIdUpdate();
  512. // when the dongle is removed, BLE is also disconnected
  513. box->bleConnectionStatus = 0;
  514. ui.batteryStatusLabel->hide();
  515. QPixmap deviceStatusNokPm(":/launchBoxSim/images/statusNOK.png");
  516. ui.deviceStatusLabel->setPixmap(deviceStatusNokPm);
  517. ui.deviceStatusLabel->show();
  518. // when the dongle is removed, Game Status is also disconnected
  519. QPixmap gameStatusNokPm(":/launchBoxSim/images/statusNOK.png");
  520. ui.gameServerStatusLabel->setPixmap(gameStatusNokPm);
  521. ui.gameServerStatusLabel->show();
  522. uiRmotionIdUpdate();
  523. ui.hardwareVersionLabel->setText("No data. Connect R-Motion first.");
  524. ui.firmwareVersionLabel->setText("No data. Connect R-Motion first.");
  525. otherInfoString = "No data. Connect R-Motion first.";
  526. QString displayStr(otherInfoString);
  527. if (curClubType != "")
  528. displayStr += " Club " + curClubType;
  529. else
  530. displayStr += " Club N/A";
  531. ui.otherInfoLabel->setText(displayStr);
  532. scanningInProgress = 0;
  533. }
  534. void launchBoxSim::uiDongleIdUpdate()
  535. {
  536. if (box->dongleStatus == 0)
  537. {
  538. ui.dongleIdLabel->setText("No data. Insert dongle first.");
  539. }
  540. else
  541. {
  542. qDebug() << "DongleID is received";
  543. QString tempString;
  544. tempString.sprintf("%02X %02X %02X %02X %02X %02X", box->dongleId[5], box->dongleId[4], box->dongleId[3], box->dongleId[2], box->dongleId[1], box->dongleId[0]);
  545. if (dongleIdText != tempString)
  546. {
  547. dongleIdText = tempString;
  548. savedData->setValue("ui/dongleIdText", QVariant(dongleIdText));
  549. }
  550. ui.dongleIdLabel->setText(tempString);
  551. }
  552. }
  553. void launchBoxSim::uiRmotionConnected()
  554. {
  555. qDebug() << "Rmotion is connected";
  556. QPixmap deviceStatusOkPm(":/launchBoxSim/images/statusOK.png");
  557. ui.deviceStatusLabel->setPixmap(deviceStatusOkPm);
  558. ui.deviceStatusLabel->show();
  559. uiRmotionIdUpdate();
  560. // resend the clubType to the device if it was disconnected before
  561. if ((curPlayerName != "") && (curClubType != ""))
  562. {
  563. ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
  564. emit uiChangePlayingMode(curPlayerHand, curClubType, 1.0f, settingsBallType, settingsKidMode,
  565. clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
  566. }
  567. else if (game->gameStatus == GAMECONNECTED)
  568. {
  569. emit ui2GameAskForPlayerInfo();
  570. }
  571. scanningInProgress = 0;
  572. }
  573. void launchBoxSim::uiRmotionDisconnected()
  574. {
  575. qDebug() << "Rmotion is disconnected";
  576. QPixmap deviceStatusNokPm(":/launchBoxSim/images/statusNOK.png");
  577. ui.deviceStatusLabel->setPixmap(deviceStatusNokPm);
  578. ui.deviceStatusLabel->show();
  579. QPixmap gameStatusNokPm(":/launchBoxSim/images/statusNOK.png");
  580. ui.gameServerStatusLabel->setPixmap(gameStatusNokPm);
  581. ui.gameServerStatusLabel->show();
  582. uiRmotionIdUpdate();
  583. ui.hardwareVersionLabel->setText("No data. Connect R-Motion first.");
  584. ui.firmwareVersionLabel->setText("No data. Connect R-Motion first.");
  585. otherInfoString = "No data. Connect R-Motion first.";
  586. QString displayStr(otherInfoString);
  587. if (curClubType != "")
  588. displayStr += " Club " + curClubType;
  589. else
  590. displayStr += " Club N/A";
  591. ui.otherInfoLabel->setText(displayStr);
  592. ui.batteryStatusLabel->hide();
  593. scanForRmotion();
  594. scanForGameStatus();
  595. }
  596. void launchBoxSim::uiRmotionIdUpdate()
  597. {
  598. if (box->bleConnectionStatus == 0)
  599. {
  600. ui.deviceIdLabel->setText("No data. Connect R-Motion first.");
  601. }
  602. else
  603. {
  604. QString tempString;
  605. tempString.sprintf("%02X %02X %02X %02X %02X %02X", box->deviceId[0], box->deviceId[1], box->deviceId[2], box->deviceId[3], box->deviceId[4], box->deviceId[5]);
  606. ui.deviceIdLabel->setText(tempString);
  607. qDebug() << "RmotionID is received " << tempString;
  608. }
  609. }
  610. void launchBoxSim::uiRmotionInfoUpdate()
  611. {
  612. QString hwVerString;
  613. hwVerString.sprintf("%d.%d.%d", HW_VERSION_MAJOR, HW_VERSION_MINOR, HW_VERSION_TAIL);
  614. ui.hardwareVersionLabel->setText(hwVerString);
  615. QString fwVerString;
  616. fwVerString.sprintf("%d.%d.%d", box->fwVerMajor, box->fwVerMinor, box->fwVerTail);
  617. ui.firmwareVersionLabel->setText(fwVerString);
  618. otherInfoString.sprintf("State %d Accx %d Accy %d Accz %d Battery %.1lf Voltage %.2lf",
  619. box->deviceStateMachine, box->accxValue, box->accyValue, box->acczValue, box->curBatteryLevel, box->curVoltageLevel);
  620. QString displayStr(otherInfoString);
  621. if (curClubType != "")
  622. displayStr += " Club " + curClubType;
  623. else
  624. displayStr += " Club N/A";
  625. ui.otherInfoLabel->setText(displayStr);
  626. qDebug() << "DeviceInfo is received " << hwVerString << " " << fwVerString << " " << otherInfoString;
  627. if (box->curBatteryLevel >= 75)
  628. {
  629. QPixmap tmpPm(":/launchBoxSim/images/battery_4.png");
  630. ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
  631. ui.batteryStatusLabel->show();
  632. }
  633. else if (box->curBatteryLevel >= 50)
  634. {
  635. QPixmap tmpPm(":/launchBoxSim/images/battery_3.png");
  636. ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
  637. ui.batteryStatusLabel->show();
  638. }
  639. else if (box->curBatteryLevel >= 25)
  640. {
  641. QPixmap tmpPm(":/launchBoxSim/images/battery_2.png");
  642. ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
  643. ui.batteryStatusLabel->show();
  644. }
  645. else
  646. {
  647. QPixmap tmpPm(":/launchBoxSim/images/battery_1.png");
  648. ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
  649. ui.batteryStatusLabel->show();
  650. }
  651. qDebug() << "Current battery level: " << box->curBatteryLevel << " Current voltage level: " << box->curVoltageLevel << " Is device charging? " << box->isDeviceCharging;
  652. if (ui.stackedWidget->currentIndex() == 0)
  653. {
  654. if (((box->fwVerMajor < FW_VERSION_MAJOR) || ((box->fwVerMajor == FW_VERSION_MAJOR) && (box->fwVerMinor < FW_VERSION_MINOR)) ||
  655. ((box->fwVerMajor == FW_VERSION_MAJOR) && (box->fwVerMinor == FW_VERSION_MINOR) && (box->fwVerTail < FW_VERSION_TAIL)))
  656. &&
  657. (box->fwVerMajor >= 1)) // only update official FW (version 1.0.0 onward)
  658. {
  659. goToFwWaitCharging();
  660. // wait until Rmotion device is charging or voltage level is high enough
  661. QTimer::singleShot(1000, this, SLOT(waitRmotionCharging()));
  662. }
  663. }
  664. }
  665. void launchBoxSim::uiRmotionFwUpgradeSuccess()
  666. {
  667. qDebug() << "Firmware Upgrade Completed";
  668. ui.fwUpgradeLabel->setText("Firmware Upgrade Completed");
  669. ui.fwUpgradeLabel->show();
  670. QTimer::singleShot(2000, this, SLOT(clickedOkDashBoard()));
  671. }
  672. void launchBoxSim::uiRmotionFwUpgradeFailure()
  673. {
  674. qDebug() << "Fimrware Upgrade Failed";
  675. ui.fwUpgradeLabel->setText("Firmware Upgrade Failed");
  676. ui.fwUpgradeLabel->show();
  677. QTimer::singleShot(2000, this, SLOT(clickedOkDashBoard()));
  678. }
  679. void launchBoxSim::uiRmotionFwUpgradeProgress(int percentage)
  680. {
  681. qDebug() << "Firmware Upgrade percentage: " << percentage;
  682. ui.fwUpgradeLabel->setText("Firmware Upgrading " + QString::number(percentage) + "%");
  683. ui.fwUpgradeLabel->show();
  684. }
  685. void launchBoxSim::game2UINotFound()
  686. {
  687. ui.otherInfoLabel->setText("Game not found");
  688. QPalette palette = ui.otherInfoLabel->palette();
  689. palette.setColor(QPalette::WindowText, QColor("Red"));
  690. ui.otherInfoLabel->setPalette(palette);
  691. }
  692. void launchBoxSim::game2UIReady()
  693. {
  694. ui.playGameButton->setDisabled(1);
  695. }
  696. void launchBoxSim::game2UIFinished()
  697. {
  698. if (game->gameStatus == GAMEDISCONNECTED)
  699. {
  700. if ((box->dongleStatus == 1) && (box->bleConnectionStatus == 1))
  701. {
  702. QPixmap gameStatusOkPm(":/launchBoxSim/images/statusOK.png");
  703. ui.gameServerStatusLabel->setPixmap(gameStatusOkPm);
  704. ui.gameServerStatusLabel->show();
  705. ui.playGameButton->setDisabled(0);
  706. qDebug() << "play button is enabled";
  707. }
  708. else
  709. {
  710. ui.playGameButton->setDisabled(1);
  711. qDebug() << "play button is disabled";
  712. }
  713. }
  714. // disarm R-Motion device if connected
  715. if (box->bleConnectionStatus == 1)
  716. emit uiDisarmDevice();
  717. }
  718. void launchBoxSim::game2UIPlayerInfo(QJsonObject object)
  719. {
  720. try {
  721. //read jSon
  722. QString playerName = object["playerName"].toString();
  723. QString courseName = object["courseName"].toString();
  724. QString tourName = object["tourName"].toString();
  725. QString playerClub = object["playerClub"].toString();
  726. QString playerHand = object["playerHand"].toString();
  727. QString playerDistanceToFlag = object["playerDistanceToFlag"].toString();
  728. QString playerSurface = object["playerSurface"].toString();
  729. qDebug() << "Parsing Json " << playerName << " " << playerClub << " " << playerHand << " " << playerDistanceToFlag;
  730. curPlayerName = playerName;
  731. curPlayerHand = playerHand;
  732. curClubType = playerClub;
  733. if (!playerClubInfoList.contains(curPlayerName))
  734. {
  735. addNewPlayerToClubInfoList(curPlayerName);
  736. needToSavePlayerClubInfoList = true;
  737. }
  738. ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
  739. if (box->bleConnectionStatus == 1)
  740. {
  741. qDebug() << "ARM command: " << curPlayerHand << " " << curClubType << " " << settingsBallType << " "
  742. << QString::number(clubInfo.clubLength) << " " << QString::number(clubInfo.clubLoft);
  743. emit uiChangePlayingMode(curPlayerHand, curClubType, playerDistanceToFlag.toFloat(), settingsBallType, settingsKidMode,
  744. clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
  745. }
  746. else
  747. {
  748. qDebug() << "Received player info from game but device is disconnected";
  749. }
  750. if (needToSavePlayerClubInfoList == true)
  751. savePlayerClubInfoList();
  752. // display new selected club type on other information label
  753. QString displayStr(otherInfoString);
  754. if (curClubType != "")
  755. displayStr += " Club " + curClubType;
  756. else
  757. displayStr += " Club N/A";
  758. ui.otherInfoLabel->setText(displayStr);
  759. }
  760. catch(QException qe){
  761. qDebug() << "Parsing JSON exception";
  762. }
  763. }
  764. void launchBoxSim::game2UIMachineIDReady(QString MID)
  765. {
  766. machineIdText = MID;
  767. savedData->setValue("ui/machineIdText", QVariant(machineIdText));
  768. qDebug() << machineIdText;
  769. }
  770. void launchBoxSim::game2UILicenseAccepted()
  771. {
  772. // full license is activating
  773. if (licenseNewState == LICENSE_SM_ACTIVATE_FULL)
  774. {
  775. qDebug() << "Full license activated OK";
  776. licenseNewState = LICENSE_SM_MIN;
  777. licenseCurState = LICENSE_SM_FULL_VALID;
  778. userLicenseStatus = 2;
  779. savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
  780. savedData->setValue("ui/userFullLicenseText", QVariant(userFullLicenseText));
  781. ui.buyNow->setDisabled(1);
  782. ui.notInterested->setDisabled(1);
  783. ui.licensekeyText->setText(userFullLicenseText);
  784. ui.licensekeyText->setReadOnly(true);
  785. ui.activateLicense->setDisabled(1);
  786. QMessageBox msgBox;
  787. msgBox.setWindowTitle("R-Motion");
  788. msgBox.setText("Full License Activation Successful.");
  789. msgBox.exec();
  790. return;
  791. }
  792. // free license is activating
  793. else if (licenseNewState == LICENSE_SM_ACTIVATE_FREE)
  794. {
  795. qDebug() << "Free license activated OK";
  796. freeLicenseRequesting = 0;
  797. licenseNewState = LICENSE_SM_MIN;
  798. licenseCurState = LICENSE_SM_FREE_VALID;
  799. userLicenseStatus = 1;
  800. savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
  801. savedData->setValue("ui/userLicenseText", QVariant(userLicenseText));
  802. QPixmap tmpPm(":/launchBoxSim/images/getLicenseLabelOk.png");
  803. ui.getLicenseLabel->setPixmap(tmpPm);
  804. ui.getLicenseLabel->show();
  805. ui.getLicenseButton->raise();
  806. ui.dashboardPushButton->setDisabled(0);
  807. ui.clubsPushButton->setDisabled(0);
  808. ui.settingsPushButton->setDisabled(0);
  809. ui.upgradePushbutton->setDisabled(0);
  810. ui.aboutPushButton->setDisabled(0);
  811. ui.helpPushbutton->setDisabled(0);
  812. return;
  813. }
  814. // free license is being verified
  815. else if (licenseNewState == LICENSE_SM_VERIFY_FREE)
  816. {
  817. qDebug() << "Free license verified OK";
  818. licenseNewState = LICENSE_SM_MIN;
  819. licenseCurState = LICENSE_SM_FREE_VALID;
  820. triedFreeLicense = 0;
  821. return;
  822. }
  823. // full license is being verified
  824. else if (licenseNewState == LICENSE_SM_VERIFY_FULL)
  825. {
  826. qDebug() << "Full license verified OK";
  827. licenseNewState = LICENSE_SM_MIN;
  828. licenseCurState = LICENSE_SM_FULL_VALID;
  829. triedFullLicense = 0;
  830. return;
  831. }
  832. }
  833. void launchBoxSim::game2UILicenseNotAccepted(QString tgcErrorMsg)
  834. {
  835. if (licenseNewState == LICENSE_SM_ACTIVATE_FULL) // full license entered is invalid
  836. {
  837. qDebug() << "Full license activated NOK";
  838. licenseNewState = LICENSE_SM_MIN;
  839. userFullLicenseText = QString("");
  840. QMessageBox msgBox;
  841. msgBox.setWindowTitle("R-Motion");
  842. msgBox.setText("The TGC License entered is rejected with error: " + tgcErrorMsg);
  843. msgBox.setInformativeText("Please contact Protee Support. Meanwhile, you can continue using the free license.");
  844. msgBox.exec();
  845. return;
  846. }
  847. else if (licenseNewState == LICENSE_SM_ACTIVATE_FREE) // free license request failed
  848. {
  849. qDebug() << "Free license activated NOK";
  850. licenseNewState = LICENSE_SM_MIN;
  851. userLicenseText = QString("");
  852. QMessageBox msgBox;
  853. msgBox.setWindowTitle("R-Motion");
  854. msgBox.setText("New Free License is rejected with error: " + tgcErrorMsg);
  855. msgBox.setInformativeText("Please try again or contact R-Motion support.");
  856. int tempRet = msgBox.exec();
  857. freeLicenseRequesting = 0;
  858. goToLicenseRequest();
  859. return;
  860. }
  861. else if (licenseNewState == LICENSE_SM_VERIFY_FREE) // free license verified NOK
  862. {
  863. qDebug() << "Free license verified NOK";
  864. licenseNewState = LICENSE_SM_MIN;
  865. if (triedFreeLicense < 2)
  866. {
  867. triedFreeLicense++;
  868. licenseNewState = LICENSE_SM_VERIFY_FREE;
  869. emit ui2GameConnectLicense(userLicenseText);
  870. }
  871. else
  872. {
  873. triedFreeLicense = 0;
  874. userLicenseStatus = 0;
  875. savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
  876. QMessageBox msgBox;
  877. msgBox.setWindowTitle("R-Motion");
  878. msgBox.setText("Existing TGC Free License is rejected with error: " + tgcErrorMsg);
  879. msgBox.setInformativeText("Click Cancel to go to License Upgrade to activate your existing full license.\n\n"
  880. "Or click OK to request new free license before playing.");
  881. msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
  882. int tempRet = msgBox.exec();
  883. if (tempRet == QMessageBox::Ok)
  884. {
  885. freeLicenseRequesting = 0;
  886. goToLicenseRequest();
  887. }
  888. else if (tempRet == QMessageBox::Cancel)
  889. {
  890. clickedOkUpgrade();
  891. }
  892. }
  893. return;
  894. }
  895. else if (licenseNewState == LICENSE_SM_VERIFY_FULL) // full license verified NOK
  896. {
  897. qDebug() << "Full license verified NOK";
  898. licenseNewState = LICENSE_SM_MIN;
  899. if (triedFullLicense < 2)
  900. {
  901. triedFullLicense++;
  902. licenseNewState = LICENSE_SM_VERIFY_FULL;
  903. emit ui2GameConnectLicense(userFullLicenseText);
  904. }
  905. else
  906. {
  907. triedFullLicense = 0;
  908. QMessageBox msgBox;
  909. msgBox.setWindowTitle("R-Motion");
  910. msgBox.setText("Existing TGC Full License is rejected with error: " + tgcErrorMsg);
  911. msgBox.setInformativeText("Please contact Protee Support. Meanwhile, you can continue using the free license.");
  912. msgBox.exec();
  913. userLicenseStatus = 1;
  914. savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
  915. licenseNewState = LICENSE_SM_VERIFY_FREE;
  916. emit ui2GameConnectLicense(userLicenseText); // check the free license
  917. }
  918. return;
  919. }
  920. }
  921. void launchBoxSim::elevateWindow()
  922. {
  923. this->activateWindow();
  924. }
  925. void launchBoxSim::clickSigninButton()
  926. {
  927. QString userEmail = ui.emailText->text();
  928. QString userPassword = ui.passwordText->text();
  929. QString urlString = "http://rmotion.rapsodo.com/api/auth/login?username=" + userEmail + "&password=" + userPassword;
  930. QNetworkRequest loginRequest;
  931. loginRequest.setUrl(QUrl(urlString));
  932. loginRequest.setAttribute(QNetworkRequest::User, QVariant("loginRequest"));
  933. networkManager->get(loginRequest);
  934. }
  935. void launchBoxSim::clickBuyNowButton()
  936. {
  937. QString urlString = "http://rmotion.rapsodo.com/api/fullName?username=" + userEmail;
  938. QNetworkRequest getNameInfoRequest;
  939. getNameInfoRequest.setUrl(QUrl(urlString));
  940. getNameInfoRequest.setAttribute(QNetworkRequest::User, QVariant("getNameInfoRequest"));
  941. networkManager->get(getNameInfoRequest);
  942. }
  943. void launchBoxSim::clickNotInterestedButton()
  944. {
  945. ui.licensekeyText->clear();
  946. clickedOkDashBoard();
  947. }
  948. void launchBoxSim::replyFinished(QNetworkReply *networkReply)
  949. {
  950. QString requestAttribute = networkReply->request().attribute(QNetworkRequest::User).toString();
  951. if (requestAttribute.contains("loginRequest")) // login response
  952. {
  953. if (networkReply->error())
  954. {
  955. qDebug() << "Login Error: " << networkReply->errorString();
  956. QMessageBox msgBox;
  957. msgBox.setWindowTitle("R-Motion");
  958. msgBox.setText("Unable to connect to R-Motion server.");
  959. msgBox.setInformativeText("Please try again or contact R-Motion support.");
  960. msgBox.exec();
  961. }
  962. else
  963. {
  964. QByteArray responseData = networkReply->readAll();
  965. qDebug() << networkReply->header(QNetworkRequest::ContentTypeHeader).toString();
  966. qDebug() << networkReply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
  967. qDebug() << networkReply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
  968. qDebug() << responseData;
  969. QList<QByteArray> responses = responseData.split('\n');
  970. if (responses[0].contains("ok"))
  971. {
  972. // update LOGIN button to LOGOUT
  973. QPixmap tempPm(":/launchBoxSim/images/logoutButton.png");
  974. ui.loginButtonLabel->setPixmap(tempPm);
  975. ui.loginButtonLabel->show();
  976. ui.loginPushbutton->raise();
  977. // update login status
  978. userLoginStatus = 1;
  979. savedData->setValue("ui/userLoginStatus", QVariant(userLoginStatus));
  980. userEmail = ui.emailText->text();
  981. savedData->setValue("ui/userEmail", QVariant(userEmail));
  982. // depends on the license status, we should go to the dashboard or the license request page
  983. if (userLicenseStatus == 0)
  984. goToLicenseRequest();
  985. else
  986. {
  987. clickedOkDashBoard();
  988. scanForRmotion();
  989. }
  990. }
  991. else if (responses[0].contains("wrong"))
  992. {
  993. ui.loginErrorLabel->setText("Invalid username/password");
  994. }
  995. }
  996. }
  997. else if (requestAttribute.contains("freeLicenseRequest")) // free license response
  998. {
  999. if (networkReply->error())
  1000. {
  1001. qDebug() << "Free License Request Error: " << networkReply->errorString();
  1002. QMessageBox msgBox;
  1003. msgBox.setWindowTitle("R-Motion");
  1004. msgBox.setText("Unable to connect to R-Motion server.");
  1005. msgBox.setInformativeText("Please try again or contact R-Motion support.");
  1006. msgBox.exec();
  1007. freeLicenseRequesting = 0;
  1008. goToLicenseRequest();
  1009. }
  1010. else
  1011. {
  1012. QByteArray responseData = networkReply->readAll();
  1013. qDebug() << responseData;
  1014. if (responseData.contains("ERROR "))
  1015. {
  1016. QMessageBox msgBox;
  1017. msgBox.setWindowTitle("R-Motion");
  1018. msgBox.setText("Free license request failed with " + responseData);
  1019. msgBox.setInformativeText("Please try again or contact R-Motion support.");
  1020. msgBox.exec();
  1021. freeLicenseRequesting = 0;
  1022. goToLicenseRequest();
  1023. }
  1024. else
  1025. {
  1026. userLicenseText = responseData;
  1027. licenseNewState = LICENSE_SM_ACTIVATE_FREE;
  1028. emit ui2GameConnectLicense(userLicenseText);
  1029. }
  1030. }
  1031. }
  1032. else if (requestAttribute.contains("checkAppUpdate")) // check app update response
  1033. {
  1034. if (!networkReply->error())
  1035. {
  1036. QByteArray responseData = networkReply->readAll();
  1037. qDebug() << responseData;
  1038. responseData.replace("\r\n", "\n");
  1039. QList<QByteArray> responses = responseData.split('\n');
  1040. if (responses.count() != 2)
  1041. return;
  1042. QList<QByteArray> version = responses[0].split('.');
  1043. if (version.count() != 3)
  1044. return;
  1045. newAppMajor = version[0].toInt();
  1046. newAppMinor = version[1].toInt();
  1047. newAppTail = version[2].toInt();
  1048. if ((newAppMajor > MAIN_APPLICATION_VERSION_MAJOR) || ((newAppMajor == MAIN_APPLICATION_VERSION_MAJOR) && (newAppMinor > MAIN_APPLICATION_VERSION_MINOR)) ||
  1049. ((newAppMajor == MAIN_APPLICATION_VERSION_MAJOR) && (newAppMinor == MAIN_APPLICATION_VERSION_MINOR) && (newAppTail > MAIN_APPLICATION_VERSION_TAIL)))
  1050. {
  1051. appHashValue = responses[1];
  1052. bool shouldDownloadNewInstaller = false;
  1053. // check if we have already downloaded the new installer and some permission sanity check
  1054. QString ourDownloadPath = ourPathString + "tmpdwnld\\";
  1055. QString newAppFilename = ourDownloadPath + "R-Motion_v" + QString::number(newAppMajor) + "." +
  1056. QString::number(newAppMinor) + "." + QString::number(newAppTail) + ".exe";
  1057. QFile installerFile(newAppFilename);
  1058. if (installerFile.exists())
  1059. {
  1060. if (installerFile.open(QFile::ReadWrite | QFile::Truncate))
  1061. {
  1062. // verify the integrity of the existed installer
  1063. QByteArray existedInstallerData = installerFile.readAll();
  1064. installerFile.close();
  1065. QCryptographicHash hash(QCryptographicHash::Sha256);
  1066. hash.addData(existedInstallerData);
  1067. QByteArray hashResult = hash.result().toHex();
  1068. qDebug() << "SHA256 hash of existed installer:" << hashResult;
  1069. if (hashResult == appHashValue)
  1070. {
  1071. qDebug() << "Existed installer SHA matched expected SHA, no need to download";
  1072. shouldDownloadNewInstaller = false;
  1073. // inform user about the new application version
  1074. QMessageBox tmpBox;
  1075. tmpBox.setWindowTitle("R-Motion");
  1076. tmpBox.setText("New R-Motion application version v" + QString::number(newAppMajor) + "." + QString::number(newAppMinor) + "." + QString::number(newAppTail) +
  1077. " is available.\nPlease remember to close the application before running the installer.");
  1078. tmpBox.setInformativeText("Do you want to go to the installer now?");
  1079. tmpBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  1080. int ret = tmpBox.exec();
  1081. if (ret == QMessageBox::Yes)
  1082. {
  1083. ourDownloadPath.replace("\\", "/");
  1084. QString urlToTmpDownload = "file:///" + ourDownloadPath;
  1085. qDebug() << "Opening the file url: " << urlToTmpDownload;
  1086. QDesktopServices::openUrl(QUrl(urlToTmpDownload, QUrl::TolerantMode));
  1087. }
  1088. }
  1089. else
  1090. {
  1091. qDebug() << "Existed installer SHA not matched expected SHA, remove and download";
  1092. installerFile.remove();
  1093. shouldDownloadNewInstaller = true;
  1094. }
  1095. }
  1096. else
  1097. {
  1098. qDebug() << "Some permission issue with the existed installer file";
  1099. qDebug() << "We assume there is some permission issue with the folder, so we will not do anything";
  1100. shouldDownloadNewInstaller = false;
  1101. }
  1102. }
  1103. else
  1104. shouldDownloadNewInstaller = true;
  1105. // download new version of app from server
  1106. if (shouldDownloadNewInstaller == true)
  1107. {
  1108. qDebug() << "Download new app version from server";
  1109. QString downloadString = "http://rmotion.rapsodo.com/download/R-Motion.exe";
  1110. QNetworkRequest downloadNewAppRequest;
  1111. downloadNewAppRequest.setUrl(QUrl(downloadString));
  1112. downloadNewAppRequest.setAttribute(QNetworkRequest::User, QVariant("downloadNewApp"));
  1113. QNetworkReply *tmpReply = networkManager->get(downloadNewAppRequest);
  1114. connect(tmpReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateAppDownloadProgress(qint64, qint64)), Qt::QueuedConnection);
  1115. }
  1116. }
  1117. }
  1118. }
  1119. else if (requestAttribute.contains("downloadNewApp")) // download new app
  1120. {
  1121. if (networkReply->error())
  1122. {
  1123. qDebug() << "Error downloading new version of application" << networkReply->errorString();
  1124. }
  1125. else
  1126. {
  1127. QByteArray downloadData = networkReply->readAll();
  1128. // compare checksum
  1129. QCryptographicHash hash(QCryptographicHash::Sha256);
  1130. hash.addData(downloadData);
  1131. QByteArray hashResult = hash.result().toHex();
  1132. qDebug() << "SHA256 hash of downloaded data:" << hashResult;
  1133. if (hashResult == appHashValue)
  1134. {
  1135. qDebug() << "SHA256 hash of downloaded data matched expected SHA";
  1136. // write file to disk
  1137. QString ourDownloadPath = ourPathString + "tmpdwnld\\";
  1138. QString newAppFilename = ourDownloadPath + "R-Motion_v" + QString::number(newAppMajor) + "." +
  1139. QString::number(newAppMinor) + "." + QString::number(newAppTail) + ".exe";
  1140. QFile installerFile(newAppFilename);
  1141. if (installerFile.open(QFile::ReadWrite | QFile::Truncate))
  1142. {
  1143. installerFile.write(downloadData);
  1144. installerFile.flush();
  1145. installerFile.close();
  1146. qDebug() << "New app installer" << newAppFilename << "is saved on disk";
  1147. // inform user about the new application version
  1148. QMessageBox tmpBox;
  1149. tmpBox.setWindowTitle("R-Motion");
  1150. tmpBox.setText("New R-Motion application version v" + QString::number(newAppMajor) + "." + QString::number(newAppMinor) + "." + QString::number(newAppTail) +
  1151. " is available.\nPlease remember to close the application before running the installer.");
  1152. tmpBox.setInformativeText("Do you want to go to the installer now?");
  1153. tmpBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
  1154. int ret = tmpBox.exec();
  1155. if (ret == QMessageBox::Yes)
  1156. {
  1157. ourDownloadPath.replace("\\", "/");
  1158. QString urlToTmpDownload = "file:///" + ourDownloadPath;
  1159. qDebug() << "Opening the file url: " << urlToTmpDownload;
  1160. QDesktopServices::openUrl(QUrl(urlToTmpDownload, QUrl::TolerantMode));
  1161. }
  1162. }
  1163. else
  1164. {
  1165. qDebug() << "Do not have permission to write to the file:" << newAppFilename;
  1166. }
  1167. }
  1168. else
  1169. {
  1170. qDebug() << "Corrupted app downloaded from server";
  1171. }
  1172. }
  1173. }
  1174. else if (requestAttribute.contains("getNameInfoRequest"))
  1175. {
  1176. if (networkReply->error())
  1177. {
  1178. QString extLink = "http://rmotiongolf.com/VB2/payment/tgc-license.php?tgc_email=" + userEmail + "&tgc_machineid=" +
  1179. machineIdText + "&tgc_exist_license=" + userLicenseText;
  1180. QDesktopServices::openUrl(QUrl(extLink));
  1181. }
  1182. else
  1183. {
  1184. QString tmpReply = networkReply->readAll();
  1185. QList<QString> tmpNames = tmpReply.split(" ");
  1186. if (tmpNames.count() == 2)
  1187. {
  1188. QString firstName = tmpNames[0];
  1189. QString lastName = tmpNames[1];
  1190. QString extLink = "http://rmotiongolf.com/VB2/payment/tgc-license.php?tgc_firstname=" + firstName + "&tgc_lastname=" + lastName
  1191. + "&tgc_email=" + userEmail + "&tgc_machineid=" + machineIdText + "&tgc_exist_license=" + userLicenseText;
  1192. QDesktopServices::openUrl(QUrl(extLink));
  1193. }
  1194. else
  1195. {
  1196. QString extLink = "http://rmotiongolf.com/VB2/payment/tgc-license.php?tgc_email=" + userEmail + "&tgc_machineid=" +
  1197. machineIdText + "&tgc_exist_license=" + userLicenseText;
  1198. QDesktopServices::openUrl(QUrl(extLink));
  1199. }
  1200. }
  1201. }
  1202. else if (requestAttribute.contains("dataSyncRequest"))
  1203. {
  1204. if (networkReply->error())
  1205. qDebug() << "Error during sync request";
  1206. else
  1207. {
  1208. QByteArray respByteArray = networkReply->readAll();
  1209. qDebug() << respByteArray;
  1210. QJsonDocument respJsonDoc = QJsonDocument::fromJson(respByteArray);
  1211. QJsonObject respJsonObj = respJsonDoc.object();
  1212. if (respJsonObj["success"].toBool() == true)
  1213. {
  1214. qDebug() << "Sync completed for email" << syncingPlayer.loginName << ". Delete data now";
  1215. int deleteRet = shotDatabase->deleteAllPlayerShots(syncingPlayer);
  1216. if (deleteRet == 0)
  1217. shotSyncFunc();
  1218. }
  1219. else
  1220. qDebug() << "Sync failed for email" << syncingPlayer.loginName << ":" << respJsonObj["message"].toString();
  1221. }
  1222. }
  1223. networkReply->deleteLater();
  1224. }
  1225. void launchBoxSim::goToFwWaitCharging()
  1226. {
  1227. ui.stackedWidget->setCurrentIndex(6);
  1228. ui.fwUpgradeLabel->hide();
  1229. QPixmap pixmap(":/launchBoxSim/images/fwWaitCharging.png");
  1230. this->setFixedSize(pixmap.width(), pixmap.height());
  1231. QPalette palette;
  1232. palette.setBrush(QPalette::Background, pixmap);
  1233. this->setPalette(palette);
  1234. ui.dashboardPushButton->setDisabled(1);
  1235. ui.clubsPushButton->setDisabled(1);
  1236. ui.settingsPushButton->setDisabled(1);
  1237. ui.upgradePushbutton->setDisabled(1);
  1238. ui.helpPushbutton->setDisabled(1);
  1239. ui.aboutPushButton->setDisabled(1);
  1240. }
  1241. void launchBoxSim::goToFwUpgrading()
  1242. {
  1243. ui.stackedWidget->setCurrentIndex(6);
  1244. QPixmap pixmap(":/launchBoxSim/images/fwUpgrading.png");
  1245. this->setFixedSize(pixmap.width(), pixmap.height());
  1246. QPalette palette;
  1247. palette.setBrush(QPalette::Background, pixmap);
  1248. this->setPalette(palette);
  1249. ui.dashboardPushButton->setDisabled(1);
  1250. ui.clubsPushButton->setDisabled(1);
  1251. ui.settingsPushButton->setDisabled(1);
  1252. ui.upgradePushbutton->setDisabled(1);
  1253. ui.helpPushbutton->setDisabled(1);
  1254. ui.aboutPushButton->setDisabled(1);
  1255. }
  1256. void launchBoxSim::goToLicenseRequest()
  1257. {
  1258. ui.stackedWidget->setCurrentIndex(4);
  1259. QPixmap pixmap(":/launchBoxSim/images/licenseRequestSkeleton.png");
  1260. this->setFixedSize(pixmap.width(), pixmap.height());
  1261. QPalette palette;
  1262. palette.setBrush(QPalette::Background, pixmap);
  1263. this->setPalette(palette);
  1264. ui.dashboardPushButton->setDisabled(1);
  1265. ui.clubsPushButton->setDisabled(1);
  1266. ui.settingsPushButton->setDisabled(1);
  1267. ui.upgradePushbutton->setDisabled(1);
  1268. ui.helpPushbutton->setDisabled(1);
  1269. ui.aboutPushButton->setDisabled(1);
  1270. if (box->dongleStatus == 1)
  1271. {
  1272. QPixmap tmpPm(":/launchBoxSim/images/statusOK.png");
  1273. ui.licenseDongleLabel->setPixmap(tmpPm);
  1274. ui.licenseDongleLabel->show();
  1275. }
  1276. else
  1277. {
  1278. QPixmap tmpPm(":/launchBoxSim/images/statusNOK.png");
  1279. ui.licenseDongle

Large files files are truncated, but you can click here to view the full file