/launchBoxSim/launchboxsim.cpp
C++ | 2714 lines | 2408 code | 229 blank | 77 comment | 567 complexity | d041307d184aaffb1d6835c1eb2b6c14 MD5 | raw 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.licenseDongleLabel->setPixmap(tmpPm);
- ui.licenseDongleLabel->show();
- }
- if (box->dongleStatus == 1)
- {
- QPixmap tmpPm(":/launchBoxSim/images/getLicenseLabelActive.png");
- ui.getLicenseLabel->setPixmap(tmpPm);
- ui.getLicenseLabel->show();
- ui.getLicenseButton->raise();
- }
- else
- {
- QPixmap tmpPm(":/launchBoxSim/images/getLicenseLabelInActive.png");
- ui.getLicenseLabel->setPixmap(tmpPm);
- ui.getLicenseLabel->show();
- }
- monitorGetLicenseRequire = new QTimer(this);
- monitorGetLicenseRequire->setInterval(1000);
- monitorGetLicenseRequire->setSingleShot(true);
- connect(monitorGetLicenseRequire, SIGNAL(timeout()), this, SLOT(goToLicenseRequest()), Qt::QueuedConnection);
- monitorGetLicenseRequire->start();
- }
- void launchBoxSim::clickGetLicense()
- {
- if ((monitorGetLicenseRequire != NULL) && (monitorGetLicenseRequire->isActive()))
- monitorGetLicenseRequire->stop();
- if (freeLicenseRequesting == 1)
- return;
- if (userLicenseStatus == 0)
- {
- freeLicenseRequesting = 1; // prevent multiple continuous free license request
- QPixmap tmpPm(":/launchBoxSim/images/getLicenseLabelWaiting.png");
- ui.getLicenseLabel->setPixmap(tmpPm);
- ui.getLicenseLabel->show();
- QString tmpDongleId;
- tmpDongleId.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]);
- QString licenseServerString;
- QNetworkRequest freeLicenseRequest;
- licenseServerString = "http://rmotion.rapsodo.com/api/licence?username=" + userEmail + "&dongleID=" + tmpDongleId + "&machineID=" + machineIdText;
- qDebug() << licenseServerString;
- freeLicenseRequest.setUrl(QUrl(licenseServerString));
- freeLicenseRequest.setAttribute(QNetworkRequest::User, QVariant("freeLicenseRequest"));
- networkManager->get(freeLicenseRequest);
- }
- else
- {
- clickedOkDashBoard();
- scanForRmotion();
- }
- }
- void launchBoxSim::emailPasswordChanged()
- {
- ui.loginErrorLabel->clear();
- if ((ui.emailText->text().isEmpty()) || (ui.passwordText->text().isEmpty()))
- ui.signinButton->setDisabled(1);
- else
- ui.signinButton->setDisabled(0);
- }
- void launchBoxSim::licenseTextChanged()
- {
- if ((ui.licensekeyText->toPlainText().isEmpty()) || (userLicenseStatus == 2))
- ui.activateLicense->setDisabled(1);
- else
- ui.activateLicense->setDisabled(0);
- }
- void launchBoxSim::clickForgotPassword()
- {
- if (ui.emailText->text().isEmpty())
- {
- QMessageBox noEmailPopup;
- noEmailPopup.setText("Please fill in your email ID before clicking Forgot Password button.");
- noEmailPopup.setStandardButtons(QMessageBox::Ok);
- noEmailPopup.setDefaultButton(QMessageBox::Ok);
- noEmailPopup.exec();
- }
- else
- {
- QString forgotPasswordString = "http://rmotion.rapsodo.com/api/auth/forgetpassword?username=" + ui.emailText->text();
- QNetworkRequest forgotPasswordRequest;
- qDebug() << forgotPasswordString;
- forgotPasswordRequest.setUrl(QUrl(forgotPasswordString));
- forgotPasswordRequest.setAttribute(QNetworkRequest::User, QVariant("forgotPasswordRequest"));
- networkManager->get(forgotPasswordRequest);
- QMessageBox forgotPasswordPopup;
- forgotPasswordPopup.setText("An email with your password information will be sent to you soon. Please check your mailbox.");
- forgotPasswordPopup.setStandardButtons(QMessageBox::Ok);
- forgotPasswordPopup.setDefaultButton(QMessageBox::Ok);
- forgotPasswordPopup.exec();
- }
- }
- void launchBoxSim::updateAppDownloadProgress(qint64 bytesReceived, qint64 bytesTotal)
- {
- qDebug() << "Downloading new application version:" << bytesReceived << "bytes over total" << bytesTotal << "bytes";
- }
- void launchBoxSim::checkAppUpdate()
- {
- QString checkAppUpdateString = "http://rmotion.rapsodo.com/build/version.txt";
- QNetworkRequest checkAppUpdateReq;
- checkAppUpdateReq.setUrl(QUrl(checkAppUpdateString));
- checkAppUpdateReq.setAttribute(QNetworkRequest::User, QVariant("checkAppUpdate"));
- networkManager->get(checkAppUpdateReq);
- }
- void launchBoxSim::waitRmotionCharging()
- {
- if ((box->isDeviceCharging == 1) || (box->curVoltageLevel >= 3.8))
- {
- goToFwUpgrading();
- emit uiStartFWUpgrade();
- }
- else
- QTimer::singleShot(1000, this, SLOT(waitRmotionCharging()));
- }
- void launchBoxSim::clickRestartDevice()
- {
- // anything to do before restart device?
- emit uiRestartDevice();
- }
- void launchBoxSim::uiDeviceListDevice(unsigned char *deviceId)
- {
- QString tempString;
- tempString.sprintf("%02X %02X %02X %02X %02X %02X", deviceId[0], deviceId[1], deviceId[2], deviceId[3], deviceId[4], deviceId[5]);
- qDebug() << "bleapp found R-Motion device ID" << tempString;
- QByteArray newDevice;
- newDevice.resize(6);
- newDevice[0] = deviceId[0];
- newDevice[1] = deviceId[1];
- newDevice[2] = deviceId[2];
- newDevice[3] = deviceId[3];
- newDevice[4] = deviceId[4];
- newDevice[5] = deviceId[5];
- for (int i = 0; i < deviceList.count(); i++)
- if (deviceList[i] == newDevice)
- return;
- deviceList.append(newDevice);
- }
- void launchBoxSim::uiDeviceListEnd()
- {
- ui.deviceListSelectBox->clear();
- ui.deviceListSelectBox->hide();
- int deviceListCount = deviceList.count();
- if (deviceListCount == 0)
- {
- deviceList.clear();
- ui.deviceStatusLabel->setText("No Device Found");
- ui.deviceStatusLabel->show();
- scanningInProgress = 0;
- QTimer::singleShot(2000, this, SLOT(scanForRmotion()));
- }
- else if (deviceListCount == 1) // auto connect if there is only 1 device available after 5 seconds of scanning
- {
- unsigned char selectedDevice[6];
- selectedDevice[0] = deviceList[0][0];
- selectedDevice[1] = deviceList[0][1];
- selectedDevice[2] = deviceList[0][2];
- selectedDevice[3] = deviceList[0][3];
- selectedDevice[4] = deviceList[0][4];
- selectedDevice[5] = deviceList[0][5];
- emit uiConnectDevice(selectedDevice);
- deviceList.clear();
- }
- else
- {
- ui.deviceStatusLabel->setText("Multiple Devices Found");
- ui.deviceStatusLabel->show();
- ui.deviceListSelectBox->show();
- ui.deviceListSelectBox->insertItem(0, "Select Your Device");
- ui.deviceListSelectBox->setCurrentIndex(0);
- for (int i = 0; i < deviceListCount; i++)
- {
- QString tmpString = QString(deviceList[i].toHex());
- tmpString.insert(10, " ");
- tmpString.insert(8, " ");
- tmpString.insert(6, " ");
- tmpString.insert(4, " ");
- tmpString.insert(2, " ");
- tmpString.prepend("R-Motion ");
- tmpString.truncate(14);
- ui.deviceListSelectBox->insertItem(i+1, tmpString);
- }
- connect(ui.deviceListSelectBox, SIGNAL(activated(int)), this, SLOT(handleDeviceSelected(int)), Qt::QueuedConnection);
- }
- }
- void launchBoxSim::handleDeviceSelected(int index)
- {
- if ((index >= 1) && (index <= deviceList.count()))
- {
- int row = index - 1;
- unsigned char selectedDevice[6];
- selectedDevice[0] = deviceList[row][0];
- selectedDevice[1] = deviceList[row][1];
- selectedDevice[2] = deviceList[row][2];
- selectedDevice[3] = deviceList[row][3];
- selectedDevice[4] = deviceList[row][4];
- selectedDevice[5] = deviceList[row][5];
- emit uiConnectDevice(selectedDevice);
- ui.deviceListSelectBox->clear();
- ui.deviceListSelectBox->hide();
- deviceList.clear();
- }
- }
- void launchBoxSim::connectToDeviceTimeout()
- {
- ui.deviceStatusLabel->setText("Unable To Connect");
- ui.deviceStatusLabel->show();
- scanningInProgress = 0;
- QTimer::singleShot(2000, this, SLOT(scanForRmotion()));
- }
- void launchBoxSim::closeEvent(QCloseEvent *event)
- {
- delete box;
- delete game;
- delete savedData;
- zipFilePrepend = userEmail;
- qApp->quit();
- }
- void launchBoxSim::wrapLaunchData()
- {
- QJsonObject jsonObj;
- QJsonObject jsonObjData;
-
- #ifdef ENCRYPT
- int aesStatus;
- QJsonObject jsonObjEnc;
- #endif
- // dampen the result and limit launch direction with in [-7 7]
- float launch_dir = ballResult.launch_direction; // degree
- float face_ang = clubResult.face_angle;
- float club_pat = clubResult.club_path;
- float face_relative_to_path = clubResult.face_to_path_at_hit;
- if ((curClubType == "DR") || (curClubType == "W3") || (curClubType == "W5"))
- {
- launch_dir = launch_dir / 1.5;
- face_ang = face_ang / 1.5;
- club_pat = club_pat / 1.5;
- face_relative_to_path = face_relative_to_path / 1.5;
- }
- else
- {
- launch_dir = launch_dir / 1.2;
- face_ang = face_ang / 1.2;
- club_pat = club_pat / 1.2;
- face_relative_to_path = face_relative_to_path / 1.2;
- }
- if (launch_dir < -10.0)
- launch_dir = -10.0;
- else if (launch_dir > 10.0)
- launch_dir = 10.0;
- // reverse club path and face angle if the player is left-handed
- if (curPlayerHand == "LH")
- {
- face_ang = face_ang * (-1.0);
- club_pat = club_pat * (-1.0);
- }
- QString protocol = "PTLAUNCH";
-
- jsonObj["protocol"] = protocol;
- jsonObjData["ballSpeedMPH"] = QString::number(ballResult.ball_speed/0.44704,'f',1);
- jsonObjData["ballDirection"] = QString::number(launch_dir,'f',1);
- jsonObjData["ballAngle"] = QString::number(ballResult.launch_angle,'f',1);
- jsonObjData["spinAxis"] = QString::number(ballResult.spin_axis,'f',1);
- jsonObjData["backSpin"] = QString::number(ballResult.spin_rate * 60,'f',0);
- if (curClubType == "PT") // in PUTTER mode just send 1000rpm back spin to the game
- jsonObjData["backSpin"] = QString::number(1000,'f',0);
- jsonObjData["clubSpeedMPH"] = QString::number(clubResult.club_speed * 2.23694, 'f', 1);
- jsonObjData["clubFace"] = QString::number(face_ang, 'f', 1);
- jsonObjData["swingPath"] = QString::number(club_pat, 'f', 1);
- jsonObjData["swingTempo"] = QString::number(clubResult.tempo, 'f', 1);
- jsonObjData["faceRelative"] = QString::number(face_relative_to_path, 'f', 1);
-
- #ifdef ENCRYPT
- jsonObj["DATA"] = jsonObjData;
- // convert to string
- QJsonDocument doc(jsonObj);
- QByteArray encryptedBytes = doc.toJson(QJsonDocument::Compact);
- QString qstr = "";
- qstr.append(encryptedBytes);
- qDebug() << qstr;
- //int byteCount = encryptedBytes.size();
- int byteCount = encryptedBytes.size() + 1; // Thomas: add in the null-terminated character
- int effectiveByteCount;
- char residue;
- char *data = encryptedBytes.data();
- unsigned char buffer[MAX_LAUNCH_DATA_SIZE];// = (unsigned char *)new(sizeof(char), MAX_LAUNCH_DATA_SIZE);
-
- QByteArray encOutput;
- float factor = (float)byteCount/(float)ENCRYPTION_BLOCK_SIZE;
- if(byteCount<=128)
- {
- factor = 5;//force to 160 at least
- effectiveByteCount = (int)(factor)*ENCRYPTION_BLOCK_SIZE;
- residue = effectiveByteCount - byteCount;
- }
- else
- {
- if(byteCount%ENCRYPTION_BLOCK_SIZE==0)
- {
- effectiveByteCount = byteCount;
- residue = 0;
- }
- else
- {
- effectiveByteCount = (int)(factor+1)*ENCRYPTION_BLOCK_SIZE;
- residue = effectiveByteCount - byteCount;
- }
- }
- memset(buffer,residue,sizeof(char)*MAX_LAUNCH_DATA_SIZE);
- memcpy(buffer,data,sizeof(char)*byteCount);
- MCRYPT cModule;
- cModule = mcrypt_module_open(MCRYPT_RIJNDAEL_256, NULL, MCRYPT_CBC, NULL );
-
- mcrypt_generic_init(cModule, &encrytionKeys[0], ENCRYPTION_BLOCK_SIZE, &encrytionIVLE[0]);
- mcrypt_generic(cModule, buffer, effectiveByteCount);
- // encode base 64
- encOutput.prepend((char *)buffer,effectiveByteCount);
- QString encB64(encOutput.toBase64());
- QString protocolEnc = "PTLAUNCHENC";
- jsonObjEnc["protocol"] = protocolEnc;
- jsonObjEnc["WO"] = "2";
- jsonObjEnc["ENCDATA"] = encB64;
- emit ballFly2UI(jsonObjEnc);
- shotDatabaseEntry entry;
- entry.timeHappened = QDateTime::currentDateTime().toMSecsSinceEpoch();
- entry.loginName = userEmail;
- entry.playerName = curPlayerName;
- entry.clubType = curClubType;
- entry.ballSpeedMPH = ballResult.ball_speed / 0.44704;
- entry.ballDirection = launch_dir;
- entry.ballAngle = ballResult.launch_angle;
- entry.spinAxis = ballResult.spin_axis;
- entry.backSpin = ballResult.spin_rate * 60;
- entry.clubSpeedMPH = clubResult.club_speed * 2.23694;
- entry.clubFace = face_ang;
- entry.swingPath = club_pat;
- entry.swingTempo = clubResult.tempo;
- entry.faceRelative = face_relative_to_path;
- shotDatabase->insertShotDatabaseEntry(entry);
- #else
- jsonObj["DATA"] = jsonObjData;
- emit ballFly2UI(jsonObj);
- #endif
-
- }
- void launchBoxSim::clickGoToHomepage()
- {
- QString extLink = "http://rmotiongolf.com";
- QDesktopServices::openUrl(QUrl(extLink));
- }
- void launchBoxSim::game2UIServerConnected()
- {
- if (userLicenseStatus == 2)
- {
- licenseNewState = LICENSE_SM_VERIFY_FULL;
- emit ui2GameConnectLicense(userFullLicenseText);
- }
- else if (userLicenseStatus == 1)
- {
- licenseNewState = LICENSE_SM_VERIFY_FREE;
- emit ui2GameConnectLicense(userLicenseText);
- }
- }
- void launchBoxSim::ballTypeGroupChanged(int radio)
- {
- if (ui.hardBallRadio->isChecked())
- settingsBallType = "HARDBALL";
- else if (ui.almostBallRadio->isChecked())
- settingsBallType = "ALMOSTBALL";
- savedData->setValue("ui/settingsBallType", QVariant(settingsBallType));
- // resend ARM command if the ball type is changed in the middle of playing
- if ((curPlayerName != "") && (curClubType != "") && (box->bleConnectionStatus == 1))
- {
- ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
- emit uiChangePlayingMode(curPlayerHand, curClubType, 1.0f, settingsBallType, settingsKidMode,
- clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
- }
- }
- void launchBoxSim::kidModeGroupChanged(int radio)
- {
- if (ui.kidModeEnableRadio->isChecked())
- settingsKidMode = "ENABLE";
- else if (ui.kidModeDisableRadio->isChecked())
- settingsKidMode = "DISABLE";
- savedData->setValue("ui/settingsKidMode", QVariant(settingsKidMode));
- // resend ARM command if kid mode is changed in the middle of playing
- if ((curPlayerName != "") && (curClubType != "") && (box->bleConnectionStatus == 1))
- {
- ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
- emit uiChangePlayingMode(curPlayerHand, curClubType, 1.0f, settingsBallType, settingsKidMode,
- clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
- }
- }
- void launchBoxSim::diagnosticModeGroupChanged(int)
- {
- if (ui.diagnosticDisabledRadio->isChecked())
- {
- settingsDiagnosticMode = "DISABLED";
- savedData->setValue("ui/settingsDiagnosticMode", QVariant("DISABLED"));
- qDebug() << "User disabled diagnostic mode";
- emit uiChangeUserSettings(settingsDisableAutoStandby, "OFF", "OFF", "OFF", "OFF");
- }
-
- else if (ui.diagnosticEnabledRadio->isChecked())
- {
- settingsDiagnosticMode = "ENABLED";
- savedData->setValue("ui/settingsDiagnosticMode", QVariant("ENABLED"));
- qDebug() << "User enabled diagnostic mode";
- emit uiChangeUserSettings(settingsDisableAutoStandby, settingsEnableShotLog, settingsEnableDebugMode,
- settingsSendDebugData, settingsSendFalseTrigger);
- }
- // resend ARM command if the diagnostic mode is changed in the middle of playing
- if ((curPlayerName != "") && (curClubType != "") && (box->bleConnectionStatus == 1))
- {
- ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
- emit uiChangePlayingMode(curPlayerHand, curClubType, 1.0f, settingsBallType, settingsKidMode,
- clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
- }
- }
- QString launchBoxSim::createPlayerClubInfoLine(QString playerName)
- {
- QString tmpStr;
- tmpStr = "playerName=" + playerName + ";";
- PlayerClubs tmpClubs = playerClubInfoList[playerName];
- tmpStr += "base_info=" + tmpClubs.baseInfo + ";";
- for (QMap<QString, ClubInfo>::const_iterator i = tmpClubs.clubInfo.constBegin(); i != tmpClubs.clubInfo.constEnd(); i++)
- {
- QString clubStr = QString("%1=%2,%3,%4,%5;")
- .arg(i.key())
- .arg(i.value().clubType)
- .arg(QString::number(i.value().clubLength))
- .arg(QString::number(i.value().clubLoft))
- .arg(QString::number(i.value().isHybrid));
- //tmpStr += i.key() + "=" + i.value().clubType + "," + QString::number(i.value().clubLength) + "," + QString::number(i.value().clubLoft) + ";";
- tmpStr += clubStr;
- }
- return tmpStr;
- }
- void launchBoxSim::savePlayerClubInfoList()
- {
- QString playerClubFilename = ourPathString + "playerClubs.txt";
- QFile playerClubFile(playerClubFilename);
- if (playerClubFile.open(QIODevice::WriteOnly))
- {
- QTextStream out(&playerClubFile);
- for (QMap<QString, PlayerClubs>::const_iterator i = playerClubInfoList.constBegin(); i != playerClubInfoList.constEnd(); i++)
- {
- QString tmpStr = createPlayerClubInfoLine(i.key());
- out << tmpStr << endl;
- }
- }
- playerClubFile.flush();
- playerClubFile.close();
- needToSavePlayerClubInfoList = false;
- }
- void launchBoxSim::initPlayerClubInfoList()
- {
- QString playerClubFilename = ourPathString + "playerClubs.txt";
- QFile playerClubFile(playerClubFilename);
-
- // if the file is not found, initialize default and default_kid clubs with static information
- if ((!playerClubFile.exists()) || (!playerClubFile.open(QIODevice::ReadOnly)))
- {
- initDefaultPlayerClubInfoList();
- initDefaultKidPlayerClubInfoList();
- needToSavePlayerClubInfoList = true;
- return;
- }
- // parse the file to create playerClubInfoList
- QTextStream in(&playerClubFile);
- while (!in.atEnd())
- {
- QString tmpLine = in.readLine();
- QList<QString> entries = tmpLine.split(';');
- if (entries.size() < 3) // there must be playerName, base_info and at least one custom club entry
- continue;
- QList<QString> nameEntry = entries[0].split('='); // playerName=DEFAULT;
- if (nameEntry.size() != 2)
- continue;
- QString tmpName = nameEntry[1];
- QList<QString> baseEntry = entries[1].split('='); // base_info=DEFAULT;
- if (baseEntry.size() != 2)
- continue;
- PlayerClubs tmpClubs;
- tmpClubs.playerName = tmpName;
- tmpClubs.baseInfo = baseEntry[1];
- for (int i = 2; i < entries.size(); i++)
- {
- QList<QString> tmpInfo = entries[i].split('='); // I3=IRON_3,length,loft;
- if (tmpInfo.size() != 2)
- continue;
- QList<QString> tmpProp = tmpInfo[1].split(',');
- if ((tmpProp.size() != 3) && (tmpProp.size() != 4))
- continue;
- tmpClubs.clubInfo[tmpInfo[0]].clubType = tmpProp[0];
- tmpClubs.clubInfo[tmpInfo[0]].clubLength = tmpProp[1].toFloat();
- tmpClubs.clubInfo[tmpInfo[0]].clubLoft = tmpProp[2].toFloat();
- if (tmpProp.size() == 3)
- tmpClubs.clubInfo[tmpInfo[0]].isHybrid = 0;
- else
- tmpClubs.clubInfo[tmpInfo[0]].isHybrid = tmpProp[3].toInt();
- }
- playerClubInfoList[tmpName] = tmpClubs;
- }
- needToSavePlayerClubInfoList = false;
- playerClubFile.close();
- }
- void launchBoxSim::initDefaultPlayerClubInfoList()
- {
- PlayerClubs defaultPlayerClubs;
- defaultPlayerClubs.playerName = "DEFAULT_ADULT";
- defaultPlayerClubs.baseInfo = "DEFAULT_ADULT";
- defaultPlayerClubs.clubInfo["I3"] = { "IRON_3", 27.6, 23, 0 };
- defaultPlayerClubs.clubInfo["I4"] = { "IRON_4", 27.1, 25, 0 };
- defaultPlayerClubs.clubInfo["I5"] = { "IRON_5", 26.6, 27, 0 };
- defaultPlayerClubs.clubInfo["I6"] = { "IRON_6", 26.1, 31, 0 };
- defaultPlayerClubs.clubInfo["I7"] = { "IRON_7", 25.6, 35, 0 };
- defaultPlayerClubs.clubInfo["I8"] = { "IRON_8", 25.1, 39, 0 };
- defaultPlayerClubs.clubInfo["I9"] = { "IRON_9", 24.6, 43, 0 };
- defaultPlayerClubs.clubInfo["PW"] = { "PITCH_WEDGE", 24.6, 47, 0 };
- defaultPlayerClubs.clubInfo["SW"] = { "SAND_WEDGE", 24.6, 55, 0 };
- defaultPlayerClubs.clubInfo["LW"] = { "LOFT_WEDGE", 24.6, 60, 0 };
- defaultPlayerClubs.clubInfo["W3"] = { "WOOD_3", 30.5, 17, 0 };
- defaultPlayerClubs.clubInfo["W5"] = { "WOOD_5", 29.5, 23, 0 };
- defaultPlayerClubs.clubInfo["DR"] = { "DRIVER", 31.9, 12, 0 };
- defaultPlayerClubs.clubInfo["PT"] = { "PUTTER", 23.8, 0.1, 0 };
- playerClubInfoList["DEFAULT_ADULT"] = defaultPlayerClubs;
- }
- void launchBoxSim::initDefaultKidPlayerClubInfoList()
- {
- PlayerClubs defaultKidPlayerClubs;
- defaultKidPlayerClubs.playerName = "DEFAULT_KID";
- defaultKidPlayerClubs.baseInfo = "DEFAULT_KID";
- defaultKidPlayerClubs.clubInfo["I3"] = { "IRON_3", 25.0, 23, 0 };
- defaultKidPlayerClubs.clubInfo["I4"] = { "IRON_4", 24.0, 25, 0 };
- defaultKidPlayerClubs.clubInfo["I5"] = { "IRON_5", 23.0, 27, 0 };
- defaultKidPlayerClubs.clubInfo["I6"] = { "IRON_6", 22.0, 31, 0 };
- defaultKidPlayerClubs.clubInfo["I7"] = { "IRON_7", 21.1, 35, 0 };
- defaultKidPlayerClubs.clubInfo["I8"] = { "IRON_8", 19.1, 39, 0 };
- defaultKidPlayerClubs.clubInfo["I9"] = { "IRON_9", 18.1, 43, 0 };
- defaultKidPlayerClubs.clubInfo["PW"] = { "PITCH_WEDGE", 18.1, 47, 0 };
- defaultKidPlayerClubs.clubInfo["SW"] = { "SAND_WEDGE", 18.1, 55, 0 };
- defaultKidPlayerClubs.clubInfo["LW"] = { "LOFT_WEDGE", 18.1, 60, 0 };
- defaultKidPlayerClubs.clubInfo["W3"] = { "WOOD_3", 25.6, 17, 0 };
- defaultKidPlayerClubs.clubInfo["W5"] = { "WOOD_5", 24.6, 23, 0 };
- defaultKidPlayerClubs.clubInfo["DR"] = { "DRIVER", 26.6, 11, 0 };
- defaultKidPlayerClubs.clubInfo["PT"] = { "PUTTER", 18.1, 0.1, 0 };
- playerClubInfoList["DEFAULT_KID"] = defaultKidPlayerClubs;
- }
- ClubInfo launchBoxSim::getPlayerClubInfo(QString playerName, QString clubType)
- {
- if (!playerClubInfoList.contains(playerName)) // this should not happen, but check anyway
- {
- return playerClubInfoList["DEFAULT_ADULT"].clubInfo[clubType];
- }
- else
- {
- QMap<QString, ClubInfo> tmpMap = playerClubInfoList[playerName].clubInfo;
- QString tmpBase = playerClubInfoList[playerName].baseInfo;
- if (tmpMap.contains(clubType)) // this clubType was customized for this player
- return tmpMap[clubType];
- else // this player uses the default info for this clubType
- return playerClubInfoList[tmpBase].clubInfo[clubType];
- }
- }
- ClubInfo launchBoxSim::getPlayerClubInfoNewBase(QString playerName, QString clubType, QString newBase)
- {
- if (!playerClubInfoList.contains(playerName)) // this should not happen, but check anyway
- {
- return playerClubInfoList[newBase].clubInfo[clubType];
- }
- else
- {
- QMap<QString, ClubInfo> tmpMap = playerClubInfoList[playerName].clubInfo;
- if (tmpMap.contains(clubType)) // this clubType was customized for this player
- return tmpMap[clubType];
- else
- return playerClubInfoList[newBase].clubInfo[clubType];
- }
- }
- void launchBoxSim::addNewPlayerToClubInfoList(QString playerName)
- {
- PlayerClubs tmpClubs;
- tmpClubs.playerName = playerName;
- tmpClubs.baseInfo = "DEFAULT_ADULT";
- QMap<QString, ClubInfo> tmpInfo;
- tmpClubs.clubInfo = tmpInfo;
- playerClubInfoList[playerName] = tmpClubs;
- ui.playerListSelectBox->addItem(playerName);
- }
- void launchBoxSim::displayPlayerClubInfo(QString playerName)
- {
- ClubInfo tmpInfo;
- tmpInfo = getPlayerClubInfo(playerName, "I3");
- ui.iron3LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron3LoftText->setText(QString::number(tmpInfo.clubLoft));
- ui.hybrid3CheckBox->setChecked(tmpInfo.isHybrid);
- tmpInfo = getPlayerClubInfo(playerName, "I4");
- ui.iron4LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron4LoftText->setText(QString::number(tmpInfo.clubLoft));
- ui.hybrid4CheckBox->setChecked(tmpInfo.isHybrid);
- tmpInfo = getPlayerClubInfo(playerName, "I5");
- ui.iron5LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron5LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "I6");
- ui.iron6LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron6LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "I7");
- ui.iron7LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron7LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "I8");
- ui.iron8LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron8LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "I9");
- ui.iron9LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron9LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "PW");
- ui.pWedgeLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.pWedgeLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "SW");
- ui.sWedgeLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.sWedgeLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "LW");
- ui.lWedgeLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.lWedgeLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "W3");
- ui.wood3LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.wood3LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "W5");
- ui.wood5LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.wood5LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "DR");
- ui.driverLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.driverLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfo(playerName, "PT");
- ui.putterLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.putterLoftText->setText(QString::number(tmpInfo.clubLoft));
- selectedBaseInfo = playerClubInfoList[playerName].baseInfo;
- if (playerClubInfoList[playerName].baseInfo == "DEFAULT_ADULT")
- {
- ui.useAdultButton->setDisabled(1);
- ui.useKidButton->setDisabled(0);
- }
- else
- {
- ui.useAdultButton->setDisabled(0);
- ui.useKidButton->setDisabled(1);
- }
- if ((playerName == "DEFAULT_ADULT") || (playerName == "DEFAULT_KID"))
- {
- ui.useAdultButton->setVisible(false);
- ui.useKidButton->setVisible(false);
- }
- else
- {
- ui.useAdultButton->setVisible(true);
- ui.useKidButton->setVisible(true);
- }
- }
- void launchBoxSim::displayPlayerClubInfoNewBase(QString playerName, QString newBase)
- {
- ClubInfo tmpInfo;
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I3", newBase);
- ui.iron3LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron3LoftText->setText(QString::number(tmpInfo.clubLoft));
- ui.hybrid3CheckBox->setChecked(tmpInfo.isHybrid);
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I4", newBase);
- ui.iron4LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron4LoftText->setText(QString::number(tmpInfo.clubLoft));
- ui.hybrid4CheckBox->setChecked(tmpInfo.isHybrid);
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I5", newBase);
- ui.iron5LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron5LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I6", newBase);
- ui.iron6LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron6LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I7", newBase);
- ui.iron7LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron7LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I8", newBase);
- ui.iron8LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron8LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "I9", newBase);
- ui.iron9LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.iron9LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "PW", newBase);
- ui.pWedgeLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.pWedgeLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "SW", newBase);
- ui.sWedgeLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.sWedgeLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "LW", newBase);
- ui.lWedgeLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.lWedgeLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "W3", newBase);
- ui.wood3LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.wood3LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "W5", newBase);
- ui.wood5LengthText->setText(QString::number(tmpInfo.clubLength));
- ui.wood5LoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "DR", newBase);
- ui.driverLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.driverLoftText->setText(QString::number(tmpInfo.clubLoft));
- tmpInfo = getPlayerClubInfoNewBase(playerName, "PT", newBase);
- ui.putterLengthText->setText(QString::number(tmpInfo.clubLength));
- ui.putterLoftText->setText(QString::number(tmpInfo.clubLoft));
- }
- void launchBoxSim::playerListSelectPlayer(QString playerName)
- {
- if (playerName == "How To Add New Player And Manage Clubs ...")
- {
- QMessageBox mb;
- mb.setWindowTitle("R-Motion");
- QString tmpStr = "R-Motion application retrieves player names from The Golf Club game, therefore you can only add players here via the game interface.\n\n"
- "Please add a player in the game and hit a ball, once the shot is registered, you can see the player name and start customizing clubs here. The application remembers the player name, therefore next time if you use the same player name, no action is necessary, your previously customized clubs will be used.\n\n"
- "You can click Adult/Kid to set the initial club parameters and start customizing. Please note that the length is calculated from the head of the club to sensor. If you click Information, you can see how the measurement is done.\n\n";
- mb.setText(tmpStr);
- mb.exec();
- ui.playerListSelectBox->setCurrentIndex(ui.playerListSelectBox->findText(selectedPlayerName));
- return;
- }
- if (playerName == selectedPlayerName)
- return;
- if (needToSavePlayerClubInfoList == true)
- {
-
- needToSavePlayerClubInfoList = false;
- selectedPlayerName = playerName;
- displayPlayerClubInfo(selectedPlayerName);
- ui.saveClubInfoButton->setDisabled(1);
- }
- else
- {
- selectedPlayerName = playerName;
- displayPlayerClubInfo(selectedPlayerName);
- }
- }
- void launchBoxSim::clubInfoTextEdited(QString tmpText)
- {
- needToSavePlayerClubInfoList = true;
- ui.saveClubInfoButton->setDisabled(0);
- }
- void launchBoxSim::clickSaveClubInfo()
- {
- bool userInputValidate = validateUserInputLengthLoft();
- if (userInputValidate == false)
- {
- QMessageBox mb;
- mb.setWindowTitle("R-Motion");
- mb.setText("Invalid club data detected in the table. Please double check your input.");
- mb.setInformativeText("Clubs length and loft must be number.\n"
- "Clubs length must be between 10 and 40 inches.\n"
- "Clubs loft must be within 5 degrees deviated from the default value.\n");
- mb.exec();
- return;
- }
- // update player club info list on memory
- playerClubInfoList[selectedPlayerName].playerName = selectedPlayerName;
- playerClubInfoList[selectedPlayerName].baseInfo = selectedBaseInfo;
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I3"].clubLength != ui.iron3LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I3"].clubLoft != ui.iron3LoftText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I3"].isHybrid != ui.hybrid3CheckBox->isChecked()))
- playerClubInfoList[selectedPlayerName].clubInfo["I3"] = { "IRON_3", ui.iron3LengthText->text().toFloat(), ui.iron3LoftText->text().toFloat(), ui.hybrid3CheckBox->isChecked() };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I3");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I4"].clubLength != ui.iron4LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I4"].clubLoft != ui.iron4LoftText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I4"].isHybrid != ui.hybrid4CheckBox->isChecked()))
- playerClubInfoList[selectedPlayerName].clubInfo["I4"] = { "IRON_4", ui.iron4LengthText->text().toFloat(), ui.iron4LoftText->text().toFloat(), ui.hybrid4CheckBox->isChecked() };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I4");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I5"].clubLength != ui.iron5LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I5"].clubLoft != ui.iron5LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["I5"] = { "IRON_5", ui.iron5LengthText->text().toFloat(), ui.iron5LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I5");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I6"].clubLength != ui.iron6LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I6"].clubLoft != ui.iron6LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["I6"] = { "IRON_6", ui.iron6LengthText->text().toFloat(), ui.iron6LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I6");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I7"].clubLength != ui.iron7LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I7"].clubLoft != ui.iron7LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["I7"] = { "IRON_7", ui.iron7LengthText->text().toFloat(), ui.iron7LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I7");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I8"].clubLength != ui.iron8LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I8"].clubLoft != ui.iron8LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["I8"] = { "IRON_8", ui.iron8LengthText->text().toFloat(), ui.iron8LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I8");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["I9"].clubLength != ui.iron9LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["I9"].clubLoft != ui.iron9LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["I9"] = { "IRON_9", ui.iron9LengthText->text().toFloat(), ui.iron9LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("I9");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["PW"].clubLength != ui.pWedgeLengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["PW"].clubLoft != ui.pWedgeLoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["PW"] = { "PITCH_WEDGE", ui.pWedgeLengthText->text().toFloat(), ui.pWedgeLoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("PW");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["SW"].clubLength != ui.sWedgeLengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["SW"].clubLoft != ui.sWedgeLoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["SW"] = { "SAND_WEDGE", ui.sWedgeLengthText->text().toFloat(), ui.sWedgeLoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("SW");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["LW"].clubLength != ui.lWedgeLengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["LW"].clubLoft != ui.lWedgeLoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["LW"] = { "LOFT_WEDGE", ui.lWedgeLengthText->text().toFloat(), ui.lWedgeLoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("LW");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["W3"].clubLength != ui.wood3LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["W3"].clubLoft != ui.wood3LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["W3"] = { "WOOD_3", ui.wood3LengthText->text().toFloat(), ui.wood3LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("W3");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["W5"].clubLength != ui.wood5LengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["W5"].clubLoft != ui.wood5LoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["W5"] = { "WOOD_5", ui.wood5LengthText->text().toFloat(), ui.wood5LoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("W5");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["DR"].clubLength != ui.driverLengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["DR"].clubLoft != ui.driverLoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["DR"] = { "DRIVER", ui.driverLengthText->text().toFloat(), ui.driverLoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("DR");
- if ((playerClubInfoList[selectedBaseInfo].clubInfo["PT"].clubLength != ui.putterLengthText->text().toFloat()) ||
- (playerClubInfoList[selectedBaseInfo].clubInfo["PT"].clubLoft != ui.putterLoftText->text().toFloat()))
- playerClubInfoList[selectedPlayerName].clubInfo["PT"] = { "PUTTER", ui.putterLengthText->text().toFloat(), ui.putterLoftText->text().toFloat(), 0 };
- else
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- playerClubInfoList[selectedPlayerName].clubInfo.remove("PT");
- // save the data into file
- savePlayerClubInfoList();
- ui.saveClubInfoButton->setDisabled(1);
- // resend ARM command if club info is changed in the middle of playing
- if ((curPlayerName != "") && (curClubType != "") && (box->bleConnectionStatus == 1))
- {
- ClubInfo clubInfo = getPlayerClubInfo(curPlayerName, curClubType);
- emit uiChangePlayingMode(curPlayerHand, curClubType, 1.0f, settingsBallType, settingsKidMode,
- clubInfo.clubLength, clubInfo.clubLoft, clubInfo.isHybrid);
- }
- QMessageBox tmpBox;
- tmpBox.setWindowTitle("R-Motion");
- tmpBox.setText("Changes in club information for player " + selectedPlayerName + " is saved.");
- tmpBox.exec();
- }
- void launchBoxSim::changeToUseAdult()
- {
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- {
- selectedBaseInfo = "DEFAULT_ADULT";
- ui.useAdultButton->setDisabled(1);
- ui.useKidButton->setDisabled(0);
- displayPlayerClubInfoNewBase(selectedPlayerName, selectedBaseInfo);
- needToSavePlayerClubInfoList = true;
- ui.saveClubInfoButton->setDisabled(0);
- }
- else
- {
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("You cannot change the base profile of default players.");
- msgBox.exec();
- }
- }
- void launchBoxSim::changeToUseKid()
- {
- if ((selectedPlayerName != "DEFAULT_ADULT") && (selectedPlayerName != "DEFAULT_KID"))
- {
- selectedBaseInfo = "DEFAULT_KID";
- ui.useAdultButton->setDisabled(0);
- ui.useKidButton->setDisabled(1);
- displayPlayerClubInfoNewBase(selectedPlayerName, selectedBaseInfo);
- needToSavePlayerClubInfoList = true;
- ui.saveClubInfoButton->setDisabled(0);
- }
- else
- {
- QMessageBox msgBox;
- msgBox.setWindowTitle("R-Motion");
- msgBox.setText("You cannot change the base profile of default players.");
- msgBox.exec();
- }
- }
- void launchBoxSim::clickDefaultClubButton()
- {
- if (selectedPlayerName == "DEFAULT_ADULT")
- {
- // fill all the text field with built-in club information
- ui.iron3LengthText->setText(QString::number(27.6));
- ui.iron3LoftText->setText(QString::number(23));
- ui.hybrid3CheckBox->setChecked(false);
- ui.iron4LengthText->setText(QString::number(27.1));
- ui.iron4LoftText->setText(QString::number(25));
- ui.hybrid4CheckBox->setChecked(false);
- ui.iron5LengthText->setText(QString::number(26.6));
- ui.iron5LoftText->setText(QString::number(27));
- ui.iron6LengthText->setText(QString::number(26.1));
- ui.iron6LoftText->setText(QString::number(31));
- ui.iron7LengthText->setText(QString::number(25.6));
- ui.iron7LoftText->setText(QString::number(35));
- ui.iron8LengthText->setText(QString::number(25.1));
- ui.iron8LoftText->setText(QString::number(39));
- ui.iron9LengthText->setText(QString::number(24.6));
- ui.iron9LoftText->setText(QString::number(43));
- ui.pWedgeLengthText->setText(QString::number(24.6));
- ui.pWedgeLoftText->setText(QString::number(47));
- ui.sWedgeLengthText->setText(QString::number(24.6));
- ui.sWedgeLoftText->setText(QString::number(55));
- ui.lWedgeLengthText->setText(QString::number(24.6));
- ui.lWedgeLoftText->setText(QString::number(60));
- ui.wood3LengthText->setText(QString::number(30.5));
- ui.wood3LoftText->setText(QString::number(17));
- ui.wood5LengthText->setText(QString::number(29.5));
- ui.wood5LoftText->setText(QString::number(23));
- ui.driverLengthText->setText(QString::number(31.9));
- ui.driverLoftText->setText(QString::number(12));
- ui.putterLengthText->setText(QString::number(23.8));
- ui.putterLoftText->setText(QString::number(0.1));
- }
- else if (selectedPlayerName == "DEFAULT_KID")
- {
- // fill all the text field with built-in club information
- ui.iron3LengthText->setText(QString::number(25.0));
- ui.iron3LoftText->setText(QString::number(23));
- ui.hybrid3CheckBox->setChecked(false);
- ui.iron4LengthText->setText(QString::number(24.0));
- ui.iron4LoftText->setText(QString::number(25));
- ui.hybrid4CheckBox->setChecked(false);
- ui.iron5LengthText->setText(QString::number(23.0));
- ui.iron5LoftText->setText(QString::number(27));
- ui.iron6LengthText->setText(QString::number(22.0));
- ui.iron6LoftText->setText(QString::number(31));
- ui.iron7LengthText->setText(QString::number(21.1));
- ui.iron7LoftText->setText(QString::number(35));
- ui.iron8LengthText->setText(QString::number(19.1));
- ui.iron8LoftText->setText(QString::number(39));
- ui.iron9LengthText->setText(QString::number(18.1));
- ui.iron9LoftText->setText(QString::number(43));
- ui.pWedgeLengthText->setText(QString::number(18.1));
- ui.pWedgeLoftText->setText(QString::number(47));
- ui.sWedgeLengthText->setText(QString::number(18.1));
- ui.sWedgeLoftText->setText(QString::number(55));
- ui.lWedgeLengthText->setText(QString::number(18.1));
- ui.lWedgeLoftText->setText(QString::number(60));
- ui.wood3LengthText->setText(QString::number(25.6));
- ui.wood3LoftText->setText(QString::number(17));
- ui.wood5LengthText->setText(QString::number(24.6));
- ui.wood5LoftText->setText(QString::number(23));
- ui.driverLengthText->setText(QString::number(26.6));
- ui.driverLoftText->setText(QString::number(11));
- ui.putterLengthText->setText(QString::number(18.1));
- ui.putterLoftText->setText(QString::number(0.1));
- }
- else
- {
- // simply fill all the text field with default club information from the selected base
- displayPlayerClubInfoNewBase(selectedBaseInfo, selectedBaseInfo);
- }
- ui.saveClubInfoButton->setDisabled(0);
- }
- void launchBoxSim::toggleClubLengthExplanation()
- {
- if (ui.clubLengthExplanation->isVisible())
- ui.clubLengthExplanation->setVisible(false);
- else
- ui.clubLengthExplanation->setVisible(true);
- }
- bool launchBoxSim::validateUserInputLengthLoft()
- {
- bool convertRes;
- float userLength;
- float userLoft, defaultLoft;
- userLength = ui.iron3LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.iron4LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.iron5LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.iron6LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.iron7LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.iron8LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.iron9LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.pWedgeLengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.sWedgeLengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.lWedgeLengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.wood3LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.wood5LengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.driverLengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLength = ui.putterLengthText->text().toFloat(&convertRes);
- if ((convertRes == false) || (userLength < 10) || (userLength > 40))
- return false;
- userLoft = ui.iron3LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I3").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft > (defaultLoft + 5)))
- return false;
- userLoft = ui.iron4LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I4").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.iron5LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I5").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.iron6LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I6").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.iron7LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I7").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.iron8LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I8").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.iron9LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "I9").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.pWedgeLoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "PW").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.sWedgeLoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "SW").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.lWedgeLoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "LW").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.wood3LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "W3").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.wood5LoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "W5").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.driverLoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "DR").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- userLoft = ui.putterLoftText->text().toFloat(&convertRes);
- if (convertRes == false)
- return false;
- defaultLoft = getPlayerClubInfo(selectedPlayerName, "PT").clubLoft;
- if ((userLoft < (defaultLoft - 5)) || (userLoft >(defaultLoft + 5)))
- return false;
- return true;
- }
- void launchBoxSim::clickHybridClubNoticeButton()
- {
- QMessageBox tmpBox;
- tmpBox.setWindowTitle("R-Motion");
- tmpBox.setText("Please click on the button besides the club to switch between Iron (I) and Hybrid (H) club.");
- tmpBox.exec();
- }
- void launchBoxSim::hybridCheckBoxChanged()
- {
- needToSavePlayerClubInfoList = true;
- ui.saveClubInfoButton->setDisabled(0);
- }
- void launchBoxSim::scanForRmotion()
- {
- if ((box->dongleStatus == 1) && (box->bleConnectionStatus == 0) && (scanningInProgress == 0))
- {
- scanningInProgress = 1;
- QMovie *swirlingMovie = new QMovie(":/launchBoxSim/images/swirling.gif");
- swirlingMovie->setScaledSize(QSize(26, 27));
- swirlingMovie->setSpeed(80);
- ui.deviceStatusLabel->setMovie(swirlingMovie);
- swirlingMovie->start();
- ui.deviceStatusLabel->show();
- deviceList.clear();
- ui.deviceListSelectBox->clear();
- ui.deviceListSelectBox->hide();
- emit uiStartScanning();
- }
- }
- void launchBoxSim::scanForGameStatus()
- {
- QMovie *swirlingMovie = new QMovie(":/launchBoxSim/images/swirling.gif");
- swirlingMovie->setScaledSize(QSize(26, 27));
- swirlingMovie->setSpeed(80);
- ui.gameServerStatusLabel->setMovie(swirlingMovie);
- swirlingMovie->start();
- ui.gameServerStatusLabel->show();
- }
- void launchBoxSim::notShowCheckBoxChanged(int state)
- {
- if (state == Qt::Checked)
- savedData->setValue("ui/notShowHelpStartUp", QVariant(1));
- else
- savedData->setValue("ui/notShowHelpStartUp", QVariant(0));
- }
- void launchBoxSim::nextSlideClicked()
- {
- if (curHelpSlide < 5)
- {
- curHelpSlide++;
- ui.stackedWidget->setCurrentIndex(2);
- QString imagePath = ":/launchBoxSim/images/helpSkeleton" + QString::number(curHelpSlide) + ".png";
- QPixmap pixmap(imagePath);
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.prevSlideButton->setDisabled(0);
- if (curHelpSlide == 5)
- ui.nextSlideButton->setStyleSheet("QPushButton{border-image: url(:/launchBoxSim/images/nextButtonDone.png); outline: none; }");
- }
- else
- {
- if (userLoginStatus == 0)
- clickedOkLogin();
- else if (userLicenseStatus == 0)
- goToLicenseRequest();
- else
- clickedOkDashBoard();
- }
- }
- void launchBoxSim::prevSlideClicked()
- {
- curHelpSlide--;
- ui.stackedWidget->setCurrentIndex(2);
- QString imagePath = ":/launchBoxSim/images/helpSkeleton" + QString::number(curHelpSlide) + ".png";
- QPixmap pixmap(imagePath);
- this->setFixedSize(pixmap.width(), pixmap.height());
- QPalette palette;
- palette.setBrush(QPalette::Background, pixmap);
- this->setPalette(palette);
- ui.nextSlideButton->setStyleSheet("QPushButton{border-image: url(:/launchBoxSim/images/nextButton.png); outline: none; }");
- if (curHelpSlide == 1)
- ui.prevSlideButton->setDisabled(1);
- }
- void launchBoxSim::shotSyncFunc()
- {
- QList<playerDatabaseEntry> listOfPlayers;
- int numOfPlayers = shotDatabase->retrieveAllPlayers(listOfPlayers);
- if ((numOfPlayers <= 0) || (listOfPlayers.isEmpty()))
- return;
- syncingPlayer = listOfPlayers.first();
- QByteArray dataToSync;
- int numOfShots = shotDatabase->retrieveAllPlayerShots(syncingPlayer, dataToSync);
- if (numOfShots <= 0) // should not happen
- return;
- QUrl dataSyncUrl("http://rmotion.rapsodo.com/api/push/new");
- QNetworkRequest dataSyncRequest;
- dataSyncRequest.setUrl(dataSyncUrl);
- dataSyncRequest.setAttribute(QNetworkRequest::User, QVariant("dataSyncRequest"));
- dataSyncRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
- qDebug() << "Syncing shot data for email" << syncingPlayer.loginName;
- networkManager->post(dataSyncRequest, dataToSync);
- }