/launchBoxSim/launchboxsim.cpp
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
- /*******************************************************************************
- * @attention
- *
- * AUTHOR: Michael, Kelvin
- *
- * DATE: 8 March 2016
- *
- * VERSION: 1.44
- *
- * COPYRIGHT RAPSODO PTE. LTD. MARCH, 2016
- * ALL RIGHTS RESERVED
- *
- * THE SOFTWARE IS PROVIDED �AS IS�, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTIBILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * 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
- * IN SOFTWARE.
- * `
- * YOU SHOULD HAVE A LICENSE AGREEMENT WITH RAPSODO TO USE THIS SOURCE CODE.
- * CONFIDENTIAL AND RELEASED UNDER NDA.
- ********************************************************************************************************/
- #include "launchboxsim.h"
- #include <QScrollBar>
- #include <QMovie>
- #include "rmdInterface.h"
- #include "helper.h"
- #define MAIN_APPLICATION_VERSION_MAJOR 1
- #define MAIN_APPLICATION_VERSION_MINOR 3
- #define MAIN_APPLICATION_VERSION_TAIL 2
- #define FW_VERSION_MAJOR 1
- #define FW_VERSION_MINOR 3
- #define FW_VERSION_TAIL 1
- #define HW_VERSION_MAJOR 1
- #define HW_VERSION_MINOR 2
- #define HW_VERSION_TAIL 0
- static unsigned char encrytionKeys[ENCRYPTION_KEY_SIZE]=
- {
- //G5M5E97O41KNjLpT6kc5vCTLmM0dnLea ProTee to Rapsodo Key
- 0x47, 0x35, 0x4d, 0x35, 0x45, 0x39, 0x37, 0x4f, 0x34, 0x31, 0x4b,
- 0x4e, 0x6a, 0x4c, 0x70, 0x54, 0x36, 0x6b, 0x63, 0x35, 0x76, 0x43,
- 0x54, 0x4c, 0x6d, 0x4d, 0x30, 0x64, 0x6e, 0x4c, 0x65, 0x61
- };
- static unsigned char encrytionIVLE[ENCRYPTION_KEY_SIZE]=
- {
- //139tes147rboPO0teze4Xh0W8W7Fb1a1 ProTee to Rapsodo Key
- 0x31, 0x33, 0x39, 0x74, 0x65, 0x73, 0x31, 0x34, 0x37, 0x72, 0x62,
- 0x6f, 0x50, 0x4f, 0x30, 0x74, 0x65, 0x7a, 0x65, 0x34, 0x58, 0x68,
- 0x30, 0x57, 0x38, 0x57, 0x37, 0x46, 0x62, 0x31, 0x61, 0x31
- };
- extern QString gamePathString;
- extern QString ourPathString;
- extern QString zipFilePrepend;
- extern ball_params ballResult;
- extern club_params clubResult;
- launchBoxSim::launchBoxSim(QWidget *parent)
- : QMainWindow(parent)
- {
- ui.setupUi(this);
- setWindowFlags(Qt::Window);
- statusBar()->hide();
- windowsTitleString = "R-Motion " + QString::number(MAIN_APPLICATION_VERSION_MAJOR) + "." + QString::number(MAIN_APPLICATION_VERSION_MINOR) +
- "." + QString::number(MAIN_APPLICATION_VERSION_TAIL);
- setWindowTitle(windowsTitleString);
- qDebug() << "Current Version:" << windowsTitleString;
- savedData = new QSettings("Rapsodo", "Rmotion");
- qDebug() << savedData->fileName();
- userLoginStatus = savedData->value("ui/userLoginStatus", QVariant(0)).toInt();
- userLicenseStatus = savedData->value("ui/userLicenseStatus", QVariant(0)).toInt();
- userEmail = savedData->value("ui/userEmail", QVariant(tr(""))).toString();
- dongleIdText = savedData->value("ui/dongleIdText", QVariant(tr(""))).toString();
- machineIdText = savedData->value("ui/machineIdText", QVariant(tr(""))).toString();
- userLicenseText = savedData->value("ui/userLicenseText", QVariant(tr(""))).toString();
- userFullLicenseText = savedData->value("ui/userFullLicenseText", QVariant(tr(""))).toString();
- licenseCurState = LICENSE_SM_NONE_VALID;
- licenseNewState = LICENSE_SM_MIN;
- triedFreeLicense = 0;
- triedFullLicense = 0;
- settingsEnableShotLog = "OFF";
- settingsEnableDebugMode = "OFF";
- settingsSendDebugData = "OFF";
- settingsSendFalseTrigger = "OFF";
- settingsDisableAutoStandby = "OFF";
- // read user settings from userSettings.txt file
- QFile userSettingsFile(ourPathString + "userSettings.txt");
- if ((userSettingsFile.exists()) && (userSettingsFile.open(QFile::ReadOnly | QFile::Text))) // check if the file existed and we can read
- {
- QTextStream tmpIn(&userSettingsFile);
- QString userSettingsText = "";
- while ((userSettingsText = tmpIn.readLine()) != "")
- {
- QList<QString> userSettingsToken = userSettingsText.split('=');
- if (userSettingsToken.count() == 2)
- {
- if ((userSettingsToken[0].contains("USER_ENABLE_SHOT_LOG")) && (userSettingsToken[1].contains("ON")))
- settingsEnableShotLog = "ON";
- if ((userSettingsToken[0].contains("USER_DISABLE_AUTO_STANDBY")) && (userSettingsToken[1].contains("ON")))
- settingsDisableAutoStandby = "ON";
- if ((userSettingsToken[0].contains("USER_SEND_DEBUG_DATA")) && (userSettingsToken[1].contains("ON")))
- settingsSendDebugData = "ON";
- if ((userSettingsToken[0].contains("USER_SEND_FALSE_TRIGGER")) && (userSettingsToken[1].contains("ON")))
- settingsSendFalseTrigger = "ON";
- if ((userSettingsToken[0].contains("USER_ENABLE_DEBUG_MODE")) && (userSettingsToken[1].contains("ON")))
- settingsEnableDebugMode = "ON";
- }
- }
- userSettingsFile.close();
- }
- qDebug() << "From file: disableAutoStandby" << settingsDisableAutoStandby;
- qDebug() << "From file: enableShotLog" << settingsEnableShotLog;
- qDebug() << "From file: enableDebugMode" << settingsEnableDebugMode;
- qDebug() << "From file: sendDebugData" << settingsSendDebugData;
- qDebug() << "From file: sendFalseTrigger" << settingsSendFalseTrigger;
- settingsDiagnosticMode = savedData->value("ui/settingsDiagnosticMode", QVariant("DISABLED")).toString();
- if (settingsDiagnosticMode == "DISABLED")
- {
- ui.diagnosticDisabledRadio->setChecked(true);
- qDebug() << "Diagnostic mode is disabled";
- }
- else if (settingsDiagnosticMode == "ENABLED")
- {
- ui.diagnosticEnabledRadio->setChecked(true);
- qDebug() << "Diagnostic mode is enabled";
- }
-
- networkManager = new QNetworkAccessManager(this);
- connect(networkManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)), Qt::QueuedConnection);
- newAppMajor = MAIN_APPLICATION_VERSION_MAJOR;
- newAppMinor = MAIN_APPLICATION_VERSION_MINOR;
- newAppTail = MAIN_APPLICATION_VERSION_TAIL;
- scanningInProgress = 0;
- curClubType = "";
- curPlayerHand = "RH";
- curPlayerName = "DEFAULT_ADULT";
- settingsBallType = savedData->value("ui/settingsBallType", QVariant(tr("HARDBALL"))).toString();
- settingsKidMode = savedData->value("ui/settingsKidMode", QVariant(tr("DISABLE"))).toString();
- if (settingsBallType == "HARDBALL")
- ui.hardBallRadio->setChecked(true);
- else if (settingsBallType == "ALMOSTBALL")
- ui.almostBallRadio->setChecked(true);
- if (settingsKidMode == "ENABLE")
- ui.kidModeEnableRadio->setChecked(true);
- else if (settingsKidMode == "DISABLE")
- ui.kidModeDisableRadio->setChecked(true);
- ui.kidModeDisableRadio->setVisible(false);
- ui.kidModeEnableRadio->setVisible(false);
- deviceList = QList<QByteArray>();
- ui.deviceListSelectBox->hide();
- monitorGetLicenseRequire = new QTimer(this);
-
- //to fix font size to pixel instead of point
- QFont font1 = ui.dongleIdLabel->font();
- font1.setPixelSize(13);
- font1.setFamily("Arial");
- font1.setItalic(1);
- font1.setBold(1);
- ui.dongleIdLabel->setFont(font1);
- QFont font2 = ui.otherInfoLabel->font();
- font2.setPixelSize(13);
- font2.setFamily("Arial");
- font2.setItalic(1);
- font2.setBold(1);
- ui.otherInfoLabel->setFont(font2);
- otherInfoString = "";
- QFont font3 = ui.hardwareVersionLabel->font();
- font3.setPixelSize(13);
- font3.setFamily("Arial");
- font3.setItalic(1);
- font3.setBold(1);
- ui.hardwareVersionLabel->setFont(font3);
- QFont font10 = ui.firmwareVersionLabel->font();
- font10.setPixelSize(13);
- font10.setFamily("Arial");
- font10.setItalic(1);
- font10.setBold(1);
- ui.firmwareVersionLabel->setFont(font10);
- QFont font4 = ui.deviceIdLabel->font();
- font4.setPixelSize(13);
- font4.setFamily("Arial");
- font4.setItalic(1);
- font4.setBold(1);
- ui.deviceIdLabel->setFont(font4);
- QFont font5 = ui.applicationVersionLabel->font();
- font4.setPixelSize(13);
- font4.setFamily("Arial");
- font4.setItalic(1);
- font4.setBold(1);
- ui.applicationVersionLabel->setFont(font4);
- ui.applicationVersionLabel->setText(QString::number(MAIN_APPLICATION_VERSION_MAJOR) + "." + QString::number(MAIN_APPLICATION_VERSION_MINOR) +
- "." + QString::number(MAIN_APPLICATION_VERSION_TAIL));
- QFont font8 = ui.licensekeyText->font();
- font8.setPixelSize(11);
- font8.setFamily("Arial");
- ui.licensekeyText->setFont(font8);
- //init side panel window
- ui.dashboardPushButton->setFlat(true);
- ui.upgradePushbutton->setFlat(true);
- ui.helpPushbutton->setFlat(true);
- ui.aboutPushButton->setFlat(true);
- ui.clubsPushButton->setFlat(true);
- ui.settingsPushButton->setFlat(true);
- if (userLoginStatus > 0)
- {
- QPixmap tempPm(":/launchBoxSim/images/logoutButton.png");
- ui.loginButtonLabel->setPixmap(tempPm);
- ui.loginButtonLabel->show();
- ui.loginPushbutton->raise();
- }
- else
- {
- QPixmap tempPm(":/launchBoxSim/images/loginButton.png");
- ui.loginButtonLabel->setPixmap(tempPm);
- ui.loginButtonLabel->show();
- ui.loginPushbutton->raise();
- }
- ui.playGameButton->setDisabled(1);
- xmlObject = new xmlParser();
- if (gamePathString == QString(""))
- {
- game = new gameInterface(xmlObject->proteeDirectory, 0);
- }
- else
- {
- //system("runas /user:Administrator@domain \"taskkill /F /T /IM server.exe\"");
- //system("taskkill /F /T /IM server.exe /IM golf.exe > /dev/null 2>&1 &");
- QProcess::execute("taskkill /F /T /IM server.exe /IM golf.exe");
- game = new gameInterface(gamePathString, 0);
- }
- connect(this, SIGNAL(startPlayingGame()), game, SLOT(launchSimGame()), Qt::QueuedConnection);
- connect(this, SIGNAL(ui2GameAskForMachineID()), game, SLOT(askForMachineID()), Qt::QueuedConnection);
- connect(this, SIGNAL(ui2GameAskForPlayerInfo()), game, SLOT(askForPlayerInfo()), Qt::QueuedConnection);
- connect(this, SIGNAL(ui2GameRemoveLicense()), game, SLOT(removeLicense()), Qt::QueuedConnection);
- connect(this, SIGNAL(ui2GameConnectLicense(QString)), game, SLOT(connectLicense(QString)), Qt::QueuedConnection);
- connect(this, SIGNAL(ballFly2UI(QJsonObject)), game, SLOT(transmitData(QJsonObject)), Qt::QueuedConnection);
- connect(game, SIGNAL(gameServerScanStarted()), this, SLOT(scanForGameStatus()), Qt::QueuedConnection);
- connect(game, SIGNAL(gameStarted()), this, SLOT(game2UIReady()), Qt::QueuedConnection);
- connect(game, SIGNAL(gameFinished()), this, SLOT(game2UIFinished()), Qt::QueuedConnection);
- connect(game, SIGNAL(gameIncomingPlayerStatus(QJsonObject)), this, SLOT(game2UIPlayerInfo(QJsonObject)), Qt::QueuedConnection);
- connect(game, SIGNAL(gameMIDReady(QString)), this, SLOT(game2UIMachineIDReady(QString)), Qt::QueuedConnection);
- connect(game, SIGNAL(gameLicenseAccepted()), this, SLOT(game2UILicenseAccepted()), Qt::QueuedConnection);
- connect(game, SIGNAL(gameLicenseNotAccepted(QString)), this, SLOT(game2UILicenseNotAccepted(QString)), Qt::QueuedConnection);
- connect(game, SIGNAL(gameGameNotFound()), this, SLOT(game2UINotFound()), Qt::QueuedConnection);
- connect(game, SIGNAL(gameServerConnected()), this, SLOT(game2UIServerConnected()), Qt::QueuedConnection);
- box = new boxInterface(0);
- connect(box, SIGNAL(bleAppReady()), this, SLOT(uiBleAppReady()), Qt::QueuedConnection);
- connect(box, SIGNAL(dongleInserted()), this, SLOT(uiDongleInserted()), Qt::QueuedConnection);
- connect(box, SIGNAL(dongleRemoved()), this, SLOT(uiDongleRemoved()), Qt::QueuedConnection);
- connect(box, SIGNAL(rmotionConnected()), this, SLOT(uiRmotionConnected()), Qt::QueuedConnection);
- connect(box, SIGNAL(rmotionDisconnected()), this, SLOT(uiRmotionDisconnected()), Qt::QueuedConnection);
- connect(box, SIGNAL(rmotionInfoAvailable()), this, SLOT(uiRmotionInfoUpdate()), Qt::QueuedConnection);
- connect(box, SIGNAL(rmotionFwUpgradeSuccess()), this, SLOT(uiRmotionFwUpgradeSuccess()), Qt::QueuedConnection);//fw upgrade success
- connect(box, SIGNAL(rmotionFwUpgradeFailure()), this, SLOT(uiRmotionFwUpgradeFailure()), Qt::QueuedConnection);//fw upgrade fail
- connect(box, SIGNAL(rmotionFwUpgradeProgress(int)), this, SLOT(uiRmotionFwUpgradeProgress(int)), Qt::QueuedConnection);
- connect(box, SIGNAL(deviceListDevice(unsigned char *)), this, SLOT(uiDeviceListDevice(unsigned char *)), Qt::DirectConnection);
- connect(box, SIGNAL(deviceListEnd()), this, SLOT(uiDeviceListEnd()), Qt::QueuedConnection);
- connect(box, SIGNAL(unableToConnect()), this, SLOT(connectToDeviceTimeout()), Qt::QueuedConnection);
- connect(box, SIGNAL(shotDataAvailable()), this, SLOT(wrapLaunchData()), Qt::QueuedConnection);
- connect(this, SIGNAL(uiStartFWUpgrade()), box, SLOT(startFWUpgrade()), Qt::QueuedConnection);
- connect(this, SIGNAL(uiRestartDevice()), box, SLOT(restartDevice()), Qt::QueuedConnection);
- connect(this, SIGNAL(uiDisarmDevice()), box, SLOT(disarmDevice()), Qt::QueuedConnection);
- connect(this, SIGNAL(uiConnectDevice(unsigned char *)), box, SLOT(connectDevice(unsigned char *)), Qt::DirectConnection);
- connect(this, SIGNAL(uiStartScanning()), box, SLOT(startScanning()), Qt::QueuedConnection);
- connect(this, SIGNAL(uiChangePlayingMode(QString, QString, float, QString, QString, float, float, int)),
- box, SLOT(changePlayingMode(QString, QString, float, QString, QString, float, float, int)), Qt::QueuedConnection);
- connect(this, SIGNAL(uiChangeUserSettings(QString, QString, QString, QString, QString)),
- box, SLOT(changeUserSettings(QString, QString, QString, QString, QString)), Qt::QueuedConnection);
- if (game->gameStatus == GAMEDISCONNECTED)
- {
- scanForGameStatus();
- }
- if (userLicenseStatus == 0)
- {
- //ask for machine id
- emit ui2GameAskForMachineID();
- }
- curHelpSlide = 1;
- int notShowHelpStartUp = savedData->value("ui/notShowHelpStartUp", QVariant(0)).toInt();
- if (notShowHelpStartUp == 0)
- ui.notShowCheckBox->setCheckState(Qt::Unchecked);
- else
- ui.notShowCheckBox->setCheckState(Qt::Checked);
- if (notShowHelpStartUp == 0)
- {
- clickedOkHelp();
- ui.dashboardPushButton->setDisabled(1);
- ui.clubsPushButton->setDisabled(1);
- ui.settingsPushButton->setDisabled(1);
- ui.upgradePushbutton->setDisabled(1);
- ui.aboutPushButton->setDisabled(1);
- ui.helpPushbutton->setDisabled(1);
- }
- else if (userLoginStatus == 0)
- {
- clickedOkLogin();
- }
- else if (userLicenseStatus == 0)
- {
- goToLicenseRequest();
- }
- else
- {
- clickedOkDashBoard();
- }
- //to elevate and show window after splash screen
- QTimer::singleShot(2000, this, SLOT(elevateWindow()));
- // init player club info list
- initPlayerClubInfoList();
- for (QMap<QString, PlayerClubs>::const_iterator i = playerClubInfoList.constBegin(); i != playerClubInfoList.constEnd(); i++)
- {
- QString tmpStr = createPlayerClubInfoLine(i.key());
- qDebug() << tmpStr;
- }
- if (needToSavePlayerClubInfoList == true)
- savePlayerClubInfoList();
- // display DEFAULT club info
- ui.playerListSelectBox->addItem("DEFAULT_ADULT");
- ui.playerListSelectBox->addItem("DEFAULT_KID");
- for (QMap<QString, PlayerClubs>::const_iterator i = playerClubInfoList.constBegin(); i != playerClubInfoList.constEnd(); i++)
- if ((i.key() != "DEFAULT_ADULT") && (i.key() != "DEFAULT_KID"))
- ui.playerListSelectBox->addItem(i.key());
- selectedPlayerName = "DEFAULT_ADULT";
- selectedBaseInfo = "DEFAULT_ADULT";
- ui.playerListSelectBox->setCurrentIndex(0);
- displayPlayerClubInfo("DEFAULT_ADULT");
- ui.saveClubInfoButton->setDisabled(1);
- ui.playerListSelectBox->addItem("How To Add New Player And Manage Clubs ...");
- // check for new app available
- checkAppUpdate();
- // shot database
- shotDatabase = new ShotDatabase(0);
- shotSyncFunc(); // sync when app start
- // sync every 5 minutes
- QTimer *shotSyncTimer = new QTimer(this);
- connect(shotSyncTimer, SIGNAL(timeout()), this, SLOT(shotSyncFunc()));
- shotSyncTimer->start(300000); // every 5 minutes
- }
- launchBoxSim::~launchBoxSim()
- {
- delete game;
- delete box;
- delete savedData;
- }
- void launchBoxSim::uiLicenseUpdateIcon()
- {
- if (userLicenseStatus > 0)
- {
- QPixmap tmpPm(":/launchBoxSim/images/statusOK.png");
- ui.licenseStatusLabel->setPixmap(tmpPm);
- ui.licenseStatusLabel->show();
- }
- else
- {
- QPixmap tmpPm(":/launchBoxSim/images/statusNOK.png");
- ui.licenseStatusLabel->setPixmap(tmpPm);
- ui.licenseStatusLabel->show();
- }
- }
- //load login
- void launchBoxSim::clickedOkLogin()
- {
- // if user is already logged in, this means user wants to logout
- if (userLoginStatus > 0)
- {
- userLoginStatus = 0;
- savedData->setValue("ui/userLoginStatus", QVariant(userLoginStatus));
- QPixmap tempPm(":/launchBoxSim/images/loginButton.png");
- ui.loginButtonLabel->setPixmap(tempPm);
- ui.loginButtonLabel->show();
- ui.loginPushbutton->raise();
- }
- // if the timer to monitor license request requirement is running, stop it
- if ((monitorGetLicenseRequire != NULL) && (monitorGetLicenseRequire->isActive()))
- monitorGetLicenseRequire->stop();
- ui.stackedWidget->setCurrentIndex(3);
- QPixmap pixmap(":/launchBoxSim/images/loginSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.signinButton->setDisabled(1);
- ui.emailText->clear();
- ui.passwordText->clear();
- ui.loginErrorLabel->clear();
- ui.dashboardPushButton->setDisabled(1);
- ui.clubsPushButton->setDisabled(1);
- ui.settingsPushButton->setDisabled(1);
- ui.upgradePushbutton->setDisabled(1);
- ui.helpPushbutton->setDisabled(1);
- ui.aboutPushButton->setDisabled(1);
- }
- //load dash board
- void launchBoxSim::clickedOkDashBoard()
- {
- uiLicenseUpdateIcon();
- ui.stackedWidget->setCurrentIndex(0);
- QPixmap pixmap(":/launchBoxSim/images/dashboardSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.dashboardPushButton->setDisabled(0);
- ui.clubsPushButton->setDisabled(0);
- ui.settingsPushButton->setDisabled(0);
- ui.upgradePushbutton->setDisabled(0);
- ui.helpPushbutton->setDisabled(0);
- ui.aboutPushButton->setDisabled(0);
- ui.batteryStatusLabel->show();
- }
- void launchBoxSim::clickedOkUpgrade()
- {
- ui.stackedWidget->setCurrentIndex(1);
- QPixmap pixmap(":/launchBoxSim/images/upgradeSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.activateLicense->setDisabled(1);
- if (userLicenseStatus == 2)
- {
- ui.buyNow->setDisabled(1);
- ui.notInterested->setDisabled(1);
- ui.licensekeyText->setText(userFullLicenseText);
- ui.licensekeyText->setReadOnly(true);
- ui.activateLicense->setDisabled(1);
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Full TGC license is already activated.");
- msgBox.exec();
- }
- }
- //load help
- void launchBoxSim::clickedOkHelp()
- {
- curHelpSlide = 1;
- ui.stackedWidget->setCurrentIndex(2);
- QPixmap pixmap(":/launchBoxSim/images/helpSkeleton1.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.prevSlideButton->setDisabled(1);
- ui.nextSlideButton->setStyleSheet("QPushButton{border-image: url(:/launchBoxSim/images/nextButton.png); outline: none; }");
- }
- //load about
- void launchBoxSim::clickedOkAbout()
- {
- ui.stackedWidget->setCurrentIndex(7);
- QPixmap pixmap(":/launchBoxSim/images/aboutSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- }
- void launchBoxSim::clickedOkSettings()
- {
- ui.stackedWidget->setCurrentIndex(9);
- QPixmap pixmap(":/launchBoxSim/images/settingsSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- }
- void launchBoxSim::clickedOkClubs()
- {
- ui.stackedWidget->setCurrentIndex(8);
- QPixmap pixmap(":/launchBoxSim/images/clubsSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.clubLengthExplanation->setVisible(false);
- needToSavePlayerClubInfoList = false;
- displayPlayerClubInfo(selectedPlayerName);
- ui.saveClubInfoButton->setDisabled(1);
- }
- //start TGC game
- void launchBoxSim::clickedPlayGame()
- {
- emit startPlayingGame();
- }
- void launchBoxSim::clickedActivateButton()
- {
- userFullLicenseText = ui.licensekeyText->toPlainText();
- licenseNewState = LICENSE_SM_ACTIVATE_FULL;
- emit ui2GameConnectLicense(userFullLicenseText);
- }
- void launchBoxSim::uiBleAppReady()
- {
- qDebug() << "BLE APP ready, send user settings now";
- if (settingsDiagnosticMode == "DISABLED")
- emit uiChangeUserSettings(settingsDisableAutoStandby, "OFF", "OFF", "OFF", "OFF");
- else if (settingsDiagnosticMode == "ENABLED")
- emit uiChangeUserSettings(settingsDisableAutoStandby, settingsEnableShotLog, settingsEnableDebugMode,
- settingsSendDebugData, settingsSendFalseTrigger);
- }
- void launchBoxSim::uiDongleInserted()
- {
- qDebug() << "Dongle is inserted";
- QPixmap dongleStatusOkPm(":/launchBoxSim/images/statusOK.png");
- ui.dongleStatusLabel->setPixmap(dongleStatusOkPm);
- ui.dongleStatusLabel->show();
- uiDongleIdUpdate();
- if ((userLoginStatus > 0) && (userLicenseStatus > 0))
- {
- scanForRmotion();
- scanForGameStatus();
- }
- }
- void launchBoxSim::uiDongleRemoved()
- {
- qDebug() << "Dongle is removed";
- QPixmap dongleStatusNokPm(":/launchBoxSim/images/statusNOK.png");
- ui.dongleStatusLabel->setPixmap(dongleStatusNokPm);
- ui.dongleStatusLabel->show();
- uiDongleIdUpdate();
- // when the dongle is removed, BLE is also disconnected
- box->bleConnectionStatus = 0;
- ui.batteryStatusLabel->hide();
- QPixmap deviceStatusNokPm(":/launchBoxSim/images/statusNOK.png");
- ui.deviceStatusLabel->setPixmap(deviceStatusNokPm);
- ui.deviceStatusLabel->show();
- // when the dongle is removed, Game Status is also disconnected
- QPixmap gameStatusNokPm(":/launchBoxSim/images/statusNOK.png");
- ui.gameServerStatusLabel->setPixmap(gameStatusNokPm);
- ui.gameServerStatusLabel->show();
- uiRmotionIdUpdate();
- ui.hardwareVersionLabel->setText("No data. Connect R-Motion first.");
- ui.firmwareVersionLabel->setText("No data. Connect R-Motion first.");
- otherInfoString = "No data. Connect R-Motion first.";
- QString displayStr(otherInfoString);
- if (curClubType != "")
- displayStr += " Club " + curClubType;
- else
- displayStr += " Club N/A";
- ui.otherInfoLabel->setText(displayStr);
- scanningInProgress = 0;
- }
- void launchBoxSim::uiDongleIdUpdate()
- {
- if (box->dongleStatus == 0)
- {
- ui.dongleIdLabel->setText("No data. Insert dongle first.");
- }
- else
- {
- qDebug() << "DongleID is received";
- QString tempString;
- 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]);
- if (dongleIdText != tempString)
- {
- dongleIdText = tempString;
- savedData->setValue("ui/dongleIdText", QVariant(dongleIdText));
- }
-
- ui.dongleIdLabel->setText(tempString);
- }
- }
- void launchBoxSim::uiRmotionConnected()
- {
- qDebug() << "Rmotion is connected";
- QPixmap deviceStatusOkPm(":/launchBoxSim/images/statusOK.png");
- ui.deviceStatusLabel->setPixmap(deviceStatusOkPm);
- ui.deviceStatusLabel->show();
- uiRmotionIdUpdate();
- // resend the clubType to the device if it was disconnected before
- if ((curPlayerName != "") && (curClubType != ""))
- {
- ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
- emit uiChangePlayingMode(curPlayerHand, curClubType, 1.0f, settingsBallType, settingsKidMode,
- clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
- }
- else if (game->gameStatus == GAMECONNECTED)
- {
- emit ui2GameAskForPlayerInfo();
- }
- scanningInProgress = 0;
- }
- void launchBoxSim::uiRmotionDisconnected()
- {
- qDebug() << "Rmotion is disconnected";
- QPixmap deviceStatusNokPm(":/launchBoxSim/images/statusNOK.png");
- ui.deviceStatusLabel->setPixmap(deviceStatusNokPm);
- ui.deviceStatusLabel->show();
- QPixmap gameStatusNokPm(":/launchBoxSim/images/statusNOK.png");
- ui.gameServerStatusLabel->setPixmap(gameStatusNokPm);
- ui.gameServerStatusLabel->show();
- uiRmotionIdUpdate();
-
- ui.hardwareVersionLabel->setText("No data. Connect R-Motion first.");
- ui.firmwareVersionLabel->setText("No data. Connect R-Motion first.");
-
- otherInfoString = "No data. Connect R-Motion first.";
- QString displayStr(otherInfoString);
- if (curClubType != "")
- displayStr += " Club " + curClubType;
- else
- displayStr += " Club N/A";
- ui.otherInfoLabel->setText(displayStr);
- ui.batteryStatusLabel->hide();
- scanForRmotion();
- scanForGameStatus();
- }
- void launchBoxSim::uiRmotionIdUpdate()
- {
- if (box->bleConnectionStatus == 0)
- {
- ui.deviceIdLabel->setText("No data. Connect R-Motion first.");
- }
- else
- {
- QString tempString;
- 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]);
- ui.deviceIdLabel->setText(tempString);
- qDebug() << "RmotionID is received " << tempString;
- }
- }
- void launchBoxSim::uiRmotionInfoUpdate()
- {
- QString hwVerString;
- hwVerString.sprintf("%d.%d.%d", HW_VERSION_MAJOR, HW_VERSION_MINOR, HW_VERSION_TAIL);
- ui.hardwareVersionLabel->setText(hwVerString);
- QString fwVerString;
- fwVerString.sprintf("%d.%d.%d", box->fwVerMajor, box->fwVerMinor, box->fwVerTail);
- ui.firmwareVersionLabel->setText(fwVerString);
-
- otherInfoString.sprintf("State %d Accx %d Accy %d Accz %d Battery %.1lf Voltage %.2lf",
- box->deviceStateMachine, box->accxValue, box->accyValue, box->acczValue, box->curBatteryLevel, box->curVoltageLevel);
- QString displayStr(otherInfoString);
- if (curClubType != "")
- displayStr += " Club " + curClubType;
- else
- displayStr += " Club N/A";
- ui.otherInfoLabel->setText(displayStr);
- qDebug() << "DeviceInfo is received " << hwVerString << " " << fwVerString << " " << otherInfoString;
- if (box->curBatteryLevel >= 75)
- {
- QPixmap tmpPm(":/launchBoxSim/images/battery_4.png");
- ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
- ui.batteryStatusLabel->show();
- }
- else if (box->curBatteryLevel >= 50)
- {
- QPixmap tmpPm(":/launchBoxSim/images/battery_3.png");
- ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
- ui.batteryStatusLabel->show();
- }
- else if (box->curBatteryLevel >= 25)
- {
- QPixmap tmpPm(":/launchBoxSim/images/battery_2.png");
- ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
- ui.batteryStatusLabel->show();
- }
- else
- {
- QPixmap tmpPm(":/launchBoxSim/images/battery_1.png");
- ui.batteryStatusLabel->setPixmap(tmpPm.scaled(ui.batteryStatusLabel->width(), ui.batteryStatusLabel->height(), Qt::KeepAspectRatio));
- ui.batteryStatusLabel->show();
- }
-
- qDebug() << "Current battery level: " << box->curBatteryLevel << " Current voltage level: " << box->curVoltageLevel << " Is device charging? " << box->isDeviceCharging;
- if (ui.stackedWidget->currentIndex() == 0)
- {
- if (((box->fwVerMajor < FW_VERSION_MAJOR) || ((box->fwVerMajor == FW_VERSION_MAJOR) && (box->fwVerMinor < FW_VERSION_MINOR)) ||
- ((box->fwVerMajor == FW_VERSION_MAJOR) && (box->fwVerMinor == FW_VERSION_MINOR) && (box->fwVerTail < FW_VERSION_TAIL)))
- &&
- (box->fwVerMajor >= 1)) // only update official FW (version 1.0.0 onward)
- {
- goToFwWaitCharging();
- // wait until Rmotion device is charging or voltage level is high enough
- QTimer::singleShot(1000, this, SLOT(waitRmotionCharging()));
- }
- }
- }
- void launchBoxSim::uiRmotionFwUpgradeSuccess()
- {
- qDebug() << "Firmware Upgrade Completed";
- ui.fwUpgradeLabel->setText("Firmware Upgrade Completed");
- ui.fwUpgradeLabel->show();
- QTimer::singleShot(2000, this, SLOT(clickedOkDashBoard()));
- }
- void launchBoxSim::uiRmotionFwUpgradeFailure()
- {
- qDebug() << "Fimrware Upgrade Failed";
- ui.fwUpgradeLabel->setText("Firmware Upgrade Failed");
- ui.fwUpgradeLabel->show();
- QTimer::singleShot(2000, this, SLOT(clickedOkDashBoard()));
- }
- void launchBoxSim::uiRmotionFwUpgradeProgress(int percentage)
- {
- qDebug() << "Firmware Upgrade percentage: " << percentage;
- ui.fwUpgradeLabel->setText("Firmware Upgrading " + QString::number(percentage) + "%");
- ui.fwUpgradeLabel->show();
- }
- void launchBoxSim::game2UINotFound()
- {
- ui.otherInfoLabel->setText("Game not found");
- QPalette palette = ui.otherInfoLabel->palette();
- palette.setColor(QPalette::WindowText, QColor("Red"));
- ui.otherInfoLabel->setPalette(palette);
-
- }
- void launchBoxSim::game2UIReady()
- {
- ui.playGameButton->setDisabled(1);
- }
- void launchBoxSim::game2UIFinished()
- {
- if (game->gameStatus == GAMEDISCONNECTED)
- {
- if ((box->dongleStatus == 1) && (box->bleConnectionStatus == 1))
- {
- QPixmap gameStatusOkPm(":/launchBoxSim/images/statusOK.png");
- ui.gameServerStatusLabel->setPixmap(gameStatusOkPm);
- ui.gameServerStatusLabel->show();
- ui.playGameButton->setDisabled(0);
- qDebug() << "play button is enabled";
- }
- else
- {
- ui.playGameButton->setDisabled(1);
- qDebug() << "play button is disabled";
- }
- }
- // disarm R-Motion device if connected
- if (box->bleConnectionStatus == 1)
- emit uiDisarmDevice();
- }
- void launchBoxSim::game2UIPlayerInfo(QJsonObject object)
- {
- try {
- //read jSon
- QString playerName = object["playerName"].toString();
- QString courseName = object["courseName"].toString();
- QString tourName = object["tourName"].toString();
- QString playerClub = object["playerClub"].toString();
- QString playerHand = object["playerHand"].toString();
- QString playerDistanceToFlag = object["playerDistanceToFlag"].toString();
- QString playerSurface = object["playerSurface"].toString();
- qDebug() << "Parsing Json " << playerName << " " << playerClub << " " << playerHand << " " << playerDistanceToFlag;
- curPlayerName = playerName;
- curPlayerHand = playerHand;
- curClubType = playerClub;
- if (!playerClubInfoList.contains(curPlayerName))
- {
- addNewPlayerToClubInfoList(curPlayerName);
- needToSavePlayerClubInfoList = true;
- }
-
- ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
- if (box->bleConnectionStatus == 1)
- {
- qDebug() << "ARM command: " << curPlayerHand << " " << curClubType << " " << settingsBallType << " "
- << QString::number(clubInfo.clubLength) << " " << QString::number(clubInfo.clubLoft);
- emit uiChangePlayingMode(curPlayerHand, curClubType, playerDistanceToFlag.toFloat(), settingsBallType, settingsKidMode,
- clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
- }
- else
- {
- qDebug() << "Received player info from game but device is disconnected";
- }
- if (needToSavePlayerClubInfoList == true)
- savePlayerClubInfoList();
- // display new selected club type on other information label
- QString displayStr(otherInfoString);
- if (curClubType != "")
- displayStr += " Club " + curClubType;
- else
- displayStr += " Club N/A";
- ui.otherInfoLabel->setText(displayStr);
- }
- catch(QException qe){
- qDebug() << "Parsing JSON exception";
- }
- }
- void launchBoxSim::game2UIMachineIDReady(QString MID)
- {
- machineIdText = MID;
- savedData->setValue("ui/machineIdText", QVariant(machineIdText));
- qDebug() << machineIdText;
- }
- void launchBoxSim::game2UILicenseAccepted()
- {
- // full license is activating
- if (licenseNewState == LICENSE_SM_ACTIVATE_FULL)
- {
- qDebug() << "Full license activated OK";
- licenseNewState = LICENSE_SM_MIN;
- licenseCurState = LICENSE_SM_FULL_VALID;
- userLicenseStatus = 2;
- savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
- savedData->setValue("ui/userFullLicenseText", QVariant(userFullLicenseText));
- ui.buyNow->setDisabled(1);
- ui.notInterested->setDisabled(1);
- ui.licensekeyText->setText(userFullLicenseText);
- ui.licensekeyText->setReadOnly(true);
- ui.activateLicense->setDisabled(1);
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Full License Activation Successful.");
- msgBox.exec();
- return;
- }
- // free license is activating
- else if (licenseNewState == LICENSE_SM_ACTIVATE_FREE)
- {
- qDebug() << "Free license activated OK";
- freeLicenseRequesting = 0;
- licenseNewState = LICENSE_SM_MIN;
- licenseCurState = LICENSE_SM_FREE_VALID;
- userLicenseStatus = 1;
- savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
- savedData->setValue("ui/userLicenseText", QVariant(userLicenseText));
- QPixmap tmpPm(":/launchBoxSim/images/getLicenseLabelOk.png");
- ui.getLicenseLabel->setPixmap(tmpPm);
- ui.getLicenseLabel->show();
- ui.getLicenseButton->raise();
- ui.dashboardPushButton->setDisabled(0);
- ui.clubsPushButton->setDisabled(0);
- ui.settingsPushButton->setDisabled(0);
- ui.upgradePushbutton->setDisabled(0);
- ui.aboutPushButton->setDisabled(0);
- ui.helpPushbutton->setDisabled(0);
- return;
- }
- // free license is being verified
- else if (licenseNewState == LICENSE_SM_VERIFY_FREE)
- {
- qDebug() << "Free license verified OK";
- licenseNewState = LICENSE_SM_MIN;
- licenseCurState = LICENSE_SM_FREE_VALID;
- triedFreeLicense = 0;
- return;
- }
- // full license is being verified
- else if (licenseNewState == LICENSE_SM_VERIFY_FULL)
- {
- qDebug() << "Full license verified OK";
- licenseNewState = LICENSE_SM_MIN;
- licenseCurState = LICENSE_SM_FULL_VALID;
- triedFullLicense = 0;
- return;
- }
- }
- void launchBoxSim::game2UILicenseNotAccepted(QString tgcErrorMsg)
- {
- if (licenseNewState == LICENSE_SM_ACTIVATE_FULL) // full license entered is invalid
- {
- qDebug() << "Full license activated NOK";
- licenseNewState = LICENSE_SM_MIN;
- userFullLicenseText = QString("");
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("The TGC License entered is rejected with error: " + tgcErrorMsg);
- msgBox.setInformativeText("Please contact Protee Support. Meanwhile, you can continue using the free license.");
- msgBox.exec();
- return;
- }
- else if (licenseNewState == LICENSE_SM_ACTIVATE_FREE) // free license request failed
- {
- qDebug() << "Free license activated NOK";
- licenseNewState = LICENSE_SM_MIN;
- userLicenseText = QString("");
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("New Free License is rejected with error: " + tgcErrorMsg);
- msgBox.setInformativeText("Please try again or contact R-Motion support.");
- int tempRet = msgBox.exec();
- freeLicenseRequesting = 0;
- goToLicenseRequest();
- return;
- }
- else if (licenseNewState == LICENSE_SM_VERIFY_FREE) // free license verified NOK
- {
- qDebug() << "Free license verified NOK";
- licenseNewState = LICENSE_SM_MIN;
- if (triedFreeLicense < 2)
- {
- triedFreeLicense++;
- licenseNewState = LICENSE_SM_VERIFY_FREE;
- emit ui2GameConnectLicense(userLicenseText);
- }
- else
- {
- triedFreeLicense = 0;
- userLicenseStatus = 0;
- savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Existing TGC Free License is rejected with error: " + tgcErrorMsg);
- msgBox.setInformativeText("Click Cancel to go to License Upgrade to activate your existing full license.\n\n"
- "Or click OK to request new free license before playing.");
- msgBox.setStandardButtons(QMessageBox::Cancel | QMessageBox::Ok);
- int tempRet = msgBox.exec();
- if (tempRet == QMessageBox::Ok)
- {
- freeLicenseRequesting = 0;
- goToLicenseRequest();
- }
- else if (tempRet == QMessageBox::Cancel)
- {
- clickedOkUpgrade();
- }
- }
- return;
- }
- else if (licenseNewState == LICENSE_SM_VERIFY_FULL) // full license verified NOK
- {
- qDebug() << "Full license verified NOK";
- licenseNewState = LICENSE_SM_MIN;
- if (triedFullLicense < 2)
- {
- triedFullLicense++;
- licenseNewState = LICENSE_SM_VERIFY_FULL;
- emit ui2GameConnectLicense(userFullLicenseText);
- }
- else
- {
- triedFullLicense = 0;
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Existing TGC Full License is rejected with error: " + tgcErrorMsg);
- msgBox.setInformativeText("Please contact Protee Support. Meanwhile, you can continue using the free license.");
- msgBox.exec();
- userLicenseStatus = 1;
- savedData->setValue("ui/userLicenseStatus", QVariant(userLicenseStatus));
- licenseNewState = LICENSE_SM_VERIFY_FREE;
- emit ui2GameConnectLicense(userLicenseText); // check the free license
- }
- return;
- }
- }
- void launchBoxSim::elevateWindow()
- {
- this->activateWindow();
- }
- void launchBoxSim::clickSigninButton()
- {
- QString userEmail = ui.emailText->text();
- QString userPassword = ui.passwordText->text();
- QString urlString = "http://rmotion.rapsodo.com/api/auth/login?username=" + userEmail + "&password=" + userPassword;
- QNetworkRequest loginRequest;
- loginRequest.setUrl(QUrl(urlString));
- loginRequest.setAttribute(QNetworkRequest::User, QVariant("loginRequest"));
- networkManager->get(loginRequest);
- }
- void launchBoxSim::clickBuyNowButton()
- {
- QString urlString = "http://rmotion.rapsodo.com/api/fullName?username=" + userEmail;
- QNetworkRequest getNameInfoRequest;
- getNameInfoRequest.setUrl(QUrl(urlString));
- getNameInfoRequest.setAttribute(QNetworkRequest::User, QVariant("getNameInfoRequest"));
- networkManager->get(getNameInfoRequest);
- }
- void launchBoxSim::clickNotInterestedButton()
- {
- ui.licensekeyText->clear();
- clickedOkDashBoard();
- }
- void launchBoxSim::replyFinished(QNetworkReply *networkReply)
- {
- QString requestAttribute = networkReply->request().attribute(QNetworkRequest::User).toString();
- if (requestAttribute.contains("loginRequest")) // login response
- {
- if (networkReply->error())
- {
- qDebug() << "Login Error: " << networkReply->errorString();
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Unable to connect to R-Motion server.");
- msgBox.setInformativeText("Please try again or contact R-Motion support.");
- msgBox.exec();
- }
- else
- {
- QByteArray responseData = networkReply->readAll();
- qDebug() << networkReply->header(QNetworkRequest::ContentTypeHeader).toString();
- qDebug() << networkReply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toString();
- qDebug() << networkReply->header(QNetworkRequest::ContentLengthHeader).toULongLong();
- qDebug() << responseData;
- QList<QByteArray> responses = responseData.split('\n');
- if (responses[0].contains("ok"))
- {
- // update LOGIN button to LOGOUT
- QPixmap tempPm(":/launchBoxSim/images/logoutButton.png");
- ui.loginButtonLabel->setPixmap(tempPm);
- ui.loginButtonLabel->show();
- ui.loginPushbutton->raise();
- // update login status
- userLoginStatus = 1;
- savedData->setValue("ui/userLoginStatus", QVariant(userLoginStatus));
- userEmail = ui.emailText->text();
- savedData->setValue("ui/userEmail", QVariant(userEmail));
- // depends on the license status, we should go to the dashboard or the license request page
- if (userLicenseStatus == 0)
- goToLicenseRequest();
- else
- {
- clickedOkDashBoard();
- scanForRmotion();
- }
- }
- else if (responses[0].contains("wrong"))
- {
- ui.loginErrorLabel->setText("Invalid username/password");
- }
- }
- }
- else if (requestAttribute.contains("freeLicenseRequest")) // free license response
- {
- if (networkReply->error())
- {
- qDebug() << "Free License Request Error: " << networkReply->errorString();
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Unable to connect to R-Motion server.");
- msgBox.setInformativeText("Please try again or contact R-Motion support.");
- msgBox.exec();
- freeLicenseRequesting = 0;
- goToLicenseRequest();
- }
- else
- {
- QByteArray responseData = networkReply->readAll();
- qDebug() << responseData;
- if (responseData.contains("ERROR "))
- {
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("Free license request failed with " + responseData);
- msgBox.setInformativeText("Please try again or contact R-Motion support.");
- msgBox.exec();
- freeLicenseRequesting = 0;
- goToLicenseRequest();
- }
- else
- {
- userLicenseText = responseData;
- licenseNewState = LICENSE_SM_ACTIVATE_FREE;
- emit ui2GameConnectLicense(userLicenseText);
- }
- }
- }
- else if (requestAttribute.contains("checkAppUpdate")) // check app update response
- {
- if (!networkReply->error())
- {
- QByteArray responseData = networkReply->readAll();
- qDebug() << responseData;
- responseData.replace("\r\n", "\n");
- QList<QByteArray> responses = responseData.split('\n');
- if (responses.count() != 2)
- return;
- QList<QByteArray> version = responses[0].split('.');
- if (version.count() != 3)
- return;
- newAppMajor = version[0].toInt();
- newAppMinor = version[1].toInt();
- newAppTail = version[2].toInt();
- if ((newAppMajor > MAIN_APPLICATION_VERSION_MAJOR) || ((newAppMajor == MAIN_APPLICATION_VERSION_MAJOR) && (newAppMinor > MAIN_APPLICATION_VERSION_MINOR)) ||
- ((newAppMajor == MAIN_APPLICATION_VERSION_MAJOR) && (newAppMinor == MAIN_APPLICATION_VERSION_MINOR) && (newAppTail > MAIN_APPLICATION_VERSION_TAIL)))
- {
- appHashValue = responses[1];
- bool shouldDownloadNewInstaller = false;
- // check if we have already downloaded the new installer and some permission sanity check
- QString ourDownloadPath = ourPathString + "tmpdwnld\\";
- QString newAppFilename = ourDownloadPath + "R-Motion_v" + QString::number(newAppMajor) + "." +
- QString::number(newAppMinor) + "." + QString::number(newAppTail) + ".exe";
- QFile installerFile(newAppFilename);
- if (installerFile.exists())
- {
- if (installerFile.open(QFile::ReadWrite | QFile::Truncate))
- {
- // verify the integrity of the existed installer
- QByteArray existedInstallerData = installerFile.readAll();
- installerFile.close();
- QCryptographicHash hash(QCryptographicHash::Sha256);
- hash.addData(existedInstallerData);
- QByteArray hashResult = hash.result().toHex();
- qDebug() << "SHA256 hash of existed installer:" << hashResult;
- if (hashResult == appHashValue)
- {
- qDebug() << "Existed installer SHA matched expected SHA, no need to download";
- shouldDownloadNewInstaller = false;
- // inform user about the new application version
- QMessageBox tmpBox;
- tmpBox.setWindowTitle("R-Motion");
- tmpBox.setText("New R-Motion application version v" + QString::number(newAppMajor) + "." + QString::number(newAppMinor) + "." + QString::number(newAppTail) +
- " is available.\nPlease remember to close the application before running the installer.");
- tmpBox.setInformativeText("Do you want to go to the installer now?");
- tmpBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- int ret = tmpBox.exec();
- if (ret == QMessageBox::Yes)
- {
- ourDownloadPath.replace("\\", "/");
- QString urlToTmpDownload = "file:///" + ourDownloadPath;
- qDebug() << "Opening the file url: " << urlToTmpDownload;
- QDesktopServices::openUrl(QUrl(urlToTmpDownload, QUrl::TolerantMode));
- }
- }
- else
- {
- qDebug() << "Existed installer SHA not matched expected SHA, remove and download";
- installerFile.remove();
- shouldDownloadNewInstaller = true;
- }
- }
- else
- {
- qDebug() << "Some permission issue with the existed installer file";
- qDebug() << "We assume there is some permission issue with the folder, so we will not do anything";
- shouldDownloadNewInstaller = false;
- }
- }
- else
- shouldDownloadNewInstaller = true;
- // download new version of app from server
- if (shouldDownloadNewInstaller == true)
- {
- qDebug() << "Download new app version from server";
- QString downloadString = "http://rmotion.rapsodo.com/download/R-Motion.exe";
- QNetworkRequest downloadNewAppRequest;
- downloadNewAppRequest.setUrl(QUrl(downloadString));
- downloadNewAppRequest.setAttribute(QNetworkRequest::User, QVariant("downloadNewApp"));
- QNetworkReply *tmpReply = networkManager->get(downloadNewAppRequest);
- connect(tmpReply, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(updateAppDownloadProgress(qint64, qint64)), Qt::QueuedConnection);
- }
- }
- }
- }
- else if (requestAttribute.contains("downloadNewApp")) // download new app
- {
- if (networkReply->error())
- {
- qDebug() << "Error downloading new version of application" << networkReply->errorString();
- }
- else
- {
- QByteArray downloadData = networkReply->readAll();
- // compare checksum
- QCryptographicHash hash(QCryptographicHash::Sha256);
- hash.addData(downloadData);
- QByteArray hashResult = hash.result().toHex();
- qDebug() << "SHA256 hash of downloaded data:" << hashResult;
- if (hashResult == appHashValue)
- {
- qDebug() << "SHA256 hash of downloaded data matched expected SHA";
- // write file to disk
- QString ourDownloadPath = ourPathString + "tmpdwnld\\";
- QString newAppFilename = ourDownloadPath + "R-Motion_v" + QString::number(newAppMajor) + "." +
- QString::number(newAppMinor) + "." + QString::number(newAppTail) + ".exe";
- QFile installerFile(newAppFilename);
- if (installerFile.open(QFile::ReadWrite | QFile::Truncate))
- {
- installerFile.write(downloadData);
- installerFile.flush();
- installerFile.close();
- qDebug() << "New app installer" << newAppFilename << "is saved on disk";
- // inform user about the new application version
- QMessageBox tmpBox;
- tmpBox.setWindowTitle("R-Motion");
- tmpBox.setText("New R-Motion application version v" + QString::number(newAppMajor) + "." + QString::number(newAppMinor) + "." + QString::number(newAppTail) +
- " is available.\nPlease remember to close the application before running the installer.");
- tmpBox.setInformativeText("Do you want to go to the installer now?");
- tmpBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
- int ret = tmpBox.exec();
- if (ret == QMessageBox::Yes)
- {
- ourDownloadPath.replace("\\", "/");
- QString urlToTmpDownload = "file:///" + ourDownloadPath;
- qDebug() << "Opening the file url: " << urlToTmpDownload;
- QDesktopServices::openUrl(QUrl(urlToTmpDownload, QUrl::TolerantMode));
- }
- }
- else
- {
- qDebug() << "Do not have permission to write to the file:" << newAppFilename;
- }
- }
- else
- {
- qDebug() << "Corrupted app downloaded from server";
- }
- }
- }
- else if (requestAttribute.contains("getNameInfoRequest"))
- {
- if (networkReply->error())
- {
- QString extLink = "http://rmotiongolf.com/VB2/payment/tgc-license.php?tgc_email=" + userEmail + "&tgc_machineid=" +
- machineIdText + "&tgc_exist_license=" + userLicenseText;
- QDesktopServices::openUrl(QUrl(extLink));
- }
- else
- {
- QString tmpReply = networkReply->readAll();
- QList<QString> tmpNames = tmpReply.split(" ");
- if (tmpNames.count() == 2)
- {
- QString firstName = tmpNames[0];
- QString lastName = tmpNames[1];
- QString extLink = "http://rmotiongolf.com/VB2/payment/tgc-license.php?tgc_firstname=" + firstName + "&tgc_lastname=" + lastName
- + "&tgc_email=" + userEmail + "&tgc_machineid=" + machineIdText + "&tgc_exist_license=" + userLicenseText;
- QDesktopServices::openUrl(QUrl(extLink));
- }
- else
- {
- QString extLink = "http://rmotiongolf.com/VB2/payment/tgc-license.php?tgc_email=" + userEmail + "&tgc_machineid=" +
- machineIdText + "&tgc_exist_license=" + userLicenseText;
- QDesktopServices::openUrl(QUrl(extLink));
- }
- }
- }
- else if (requestAttribute.contains("dataSyncRequest"))
- {
- if (networkReply->error())
- qDebug() << "Error during sync request";
- else
- {
- QByteArray respByteArray = networkReply->readAll();
- qDebug() << respByteArray;
- QJsonDocument respJsonDoc = QJsonDocument::fromJson(respByteArray);
- QJsonObject respJsonObj = respJsonDoc.object();
- if (respJsonObj["success"].toBool() == true)
- {
- qDebug() << "Sync completed for email" << syncingPlayer.loginName << ". Delete data now";
- int deleteRet = shotDatabase->deleteAllPlayerShots(syncingPlayer);
- if (deleteRet == 0)
- shotSyncFunc();
- }
- else
- qDebug() << "Sync failed for email" << syncingPlayer.loginName << ":" << respJsonObj["message"].toString();
- }
- }
-
- networkReply->deleteLater();
- }
- void launchBoxSim::goToFwWaitCharging()
- {
- ui.stackedWidget->setCurrentIndex(6);
- ui.fwUpgradeLabel->hide();
- QPixmap pixmap(":/launchBoxSim/images/fwWaitCharging.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.dashboardPushButton->setDisabled(1);
- ui.clubsPushButton->setDisabled(1);
- ui.settingsPushButton->setDisabled(1);
- ui.upgradePushbutton->setDisabled(1);
- ui.helpPushbutton->setDisabled(1);
- ui.aboutPushButton->setDisabled(1);
- }
- void launchBoxSim::goToFwUpgrading()
- {
- ui.stackedWidget->setCurrentIndex(6);
- QPixmap pixmap(":/launchBoxSim/images/fwUpgrading.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.dashboardPushButton->setDisabled(1);
- ui.clubsPushButton->setDisabled(1);
- ui.settingsPushButton->setDisabled(1);
- ui.upgradePushbutton->setDisabled(1);
- ui.helpPushbutton->setDisabled(1);
- ui.aboutPushButton->setDisabled(1);
- }
- void launchBoxSim::goToLicenseRequest()
- {
- ui.stackedWidget->setCurrentIndex(4);
- QPixmap pixmap(":/launchBoxSim/images/licenseRequestSkeleton.png");
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.dashboardPushButton->setDisabled(1);
- ui.clubsPushButton->setDisabled(1);
- ui.settingsPushButton->setDisabled(1);
- ui.upgradePushbutton->setDisabled(1);
- ui.helpPushbutton->setDisabled(1);
- ui.aboutPushButton->setDisabled(1);
-
- if (box->dongleStatus == 1)
- {
- QPixmap tmpPm(":/launchBoxSim/images/statusOK.png");
- ui.licenseDongleLabel->setPixmap(tmpPm);
- ui.licenseDongleLabel->show();
- }
- else
- {
- QPixmap tmpPm(":/launchBoxSim/images/statusNOK.png");
- ui.licenseDongle…
Large files files are truncated, but you can click here to view the full file