diff --git a/src/OptionsDialog.cpp b/src/OptionsDialog.cpp index af47fed..1c4ce1b 100644 --- a/src/OptionsDialog.cpp +++ b/src/OptionsDialog.cpp @@ -185,12 +185,7 @@ void OptionsDialog::setupLanguageBox(QSettings *settings) ui->cbLanguage->addItem(cbLangStr, lang); } if (currentLanguage == lang) { -#if QT_VERSION >= 0x050000 ui->cbLanguage->setCurrentText(cbLangStr); -#else - int indexOfLang = ui->cbLanguage->findText(cbLangStr); - ui->cbLanguage->setCurrentIndex(indexOfLang); -#endif } } @@ -352,11 +347,31 @@ void OptionsDialog::applySettings() newContentMode++; } settings.setValue("ContentMode", newContentMode); -#if QT_VERSION >= 0x050000 - settings.setValue("Default", ui->cbProfiles->currentData()); +#if QT_VERSION >= 0x060000 + if (ui->cbProfiles->currentData().typeId() == QMetaType::QString) #else - settings->setValue("Default", ui->cbProfiles->itemData(ui->cbProfiles->currentIndex())); + if (ui->cbProfiles->currentData().type() == QVariant::String) #endif + { + settings.setValue("Default", ui->cbProfiles->currentData()); + settings.remove("DefaultGame"); + } +#if QT_VERSION >= 0x060000 + if (ui->cbProfiles->currentData().typeId() == QMetaType::QStringList) +#else + if (ui->cbProfiles->currentData().type() == QVariant::StringList) +#endif + { + const QStringList dataList = ui->cbProfiles->currentData().toStringList(); + if (dataList.length() == 2) { + settings.setValue("Default", dataList.at(0)); + settings.setValue("DefaultGame", dataList.at(1)); + } + else { + settings.setValue("Default", QVariant()); + settings.remove("DefaultGame"); + } + } settings.endGroup(); const bool forceCustomFolder = ui->cbForceCustomFolder->isChecked(); @@ -417,13 +432,8 @@ void OptionsDialog::applySettings() } #endif -#if QT_VERSION >= 0x050000 - bool languageChanged = ui->cbLanguage->currentData().toString() != currentLanguage; - bool languageAreaChanged = ui->cbAreaLanguage->currentData().toString() != currentAreaLanguage; -#else - bool languageChanged = ui->cbLanguage->itemData(ui->cbLanguage->currentIndex()).toString() != currentLanguage; - bool languageAreaChanged = ui->cbAreaLanguage->itemData(ui->cbLanguage->currentIndex()).toString() != currentAreaLanguage; -#endif + const bool languageChanged = ui->cbLanguage->currentData().toString() != currentLanguage; + const bool languageAreaChanged = ui->cbAreaLanguage->currentData().toString() != currentAreaLanguage; if (languageChanged) { Translator->unloadTranslation(qApp); Translator->initUserLanguage(); @@ -436,7 +446,7 @@ void OptionsDialog::applySettings() settings.sync(); emit settingsApplied(newContentMode, languageChanged); - if ((forceCustomFolder && ui->txtFolder->text() != currentCFolder) || (forceCustomFolder != currentFFolder && forceCustomFolder)) { + if ((forceCustomFolder && ui->txtFolder->text() != currentCFolder) || (forceCustomFolder != currentFFolder && forceCustomFolder) || (forceCustomFolder_RDR2 && ui->txtFolder_RDR2->text() != currentCFolderR) || (forceCustomFolder_RDR2 != currentFFolderR && forceCustomFolder_RDR2)) { QMessageBox::information(this, tr("%1", "%1").arg(GTA5SYNC_APPSTR), tr("The new Custom Folder will initialise after you restart %1.").arg(GTA5SYNC_APPSTR)); } } @@ -445,23 +455,19 @@ void OptionsDialog::setupDefaultProfile(QSettings *settings) { settings->beginGroup("Profile"); defaultProfile = settings->value("Default", QString()).toString(); + defaultGame = settings->value("DefaultGame", QStringLiteral("GTA V")).toString(); settings->endGroup(); QString cbNoneStr = tr("No Profile", "No Profile, as default"); ui->cbProfiles->addItem(cbNoneStr, QString()); } -void OptionsDialog::commitProfiles(const QStringList &profiles) +void OptionsDialog::commitProfiles(const QStringList &profiles, const QString &game) { for (const QString &profile : profiles) { - ui->cbProfiles->addItem(tr("Profile: %1").arg(profile), profile); - if (defaultProfile == profile) { -#if QT_VERSION >= 0x050000 - ui->cbProfiles->setCurrentText(tr("Profile: %1").arg(profile)); -#else - int indexOfProfile = ui->cbProfiles->findText(tr("Profile: %1").arg(profile)); - ui->cbProfiles->setCurrentIndex(indexOfProfile); -#endif + ui->cbProfiles->addItem(tr("%2: %1").arg(profile, game), QStringList() << profile << game); + if (defaultGame == game && defaultProfile == profile) { + ui->cbProfiles->setCurrentText(tr("%2: %1").arg(profile, game)); } } } @@ -607,6 +613,14 @@ void OptionsDialog::on_cmdExploreFolder_clicked() } } +void OptionsDialog::on_cmdExploreFolder_RDR2_clicked() +{ + const QString RDR2_Folder = QFileDialog::getExistingDirectory(this, UserInterface::tr("Select RDR 2 Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); + if (!RDR2_Folder.isEmpty() && QDir(RDR2_Folder).exists()) { + ui->txtFolder_RDR2->setText(RDR2_Folder); + } +} + void OptionsDialog::on_cbDefaultStyle_toggled(bool checked) { ui->cbStyleList->setDisabled(checked); diff --git a/src/OptionsDialog.h b/src/OptionsDialog.h index cb2ba1a..72e833f 100644 --- a/src/OptionsDialog.h +++ b/src/OptionsDialog.h @@ -36,12 +36,13 @@ class OptionsDialog : public QDialog public: explicit OptionsDialog(ProfileDatabase *profileDB, QWidget *parent = 0); - void commitProfiles(const QStringList &profiles); + void commitProfiles(const QStringList &profiles, const QString &game); ~OptionsDialog(); private slots: void on_cmdOK_clicked(); void on_cmdExploreFolder_clicked(); + void on_cmdExploreFolder_RDR2_clicked(); void on_cbDefaultStyle_toggled(bool checked); void on_cbDefaultFont_toggled(bool checked); void on_cmdCopyStatsID_clicked(); @@ -61,6 +62,7 @@ private: QString currentCFolder; QString currentCFolderR; QString defaultProfile; + QString defaultGame; QString percentString; bool withoutPlayers; bool currentFFolder; diff --git a/src/UserInterface.cpp b/src/UserInterface.cpp index b239cf1..a67d982 100644 --- a/src/UserInterface.cpp +++ b/src/UserInterface.cpp @@ -32,12 +32,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include #include #include @@ -108,10 +110,10 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D // Set Icon for Choose GTA V Folder Menu Item if (QIcon::hasThemeIcon("document-open-folder")) { - ui->actionSelect_GTA_Folder->setIcon(QIcon::fromTheme("document-open-folder")); + ui->actionSelect_Game_Folder->setIcon(QIcon::fromTheme("document-open-folder")); } else if (QIcon::hasThemeIcon("gtk-directory")) { - ui->actionSelect_GTA_Folder->setIcon(QIcon::fromTheme("gtk-directory")); + ui->actionSelect_Game_Folder->setIcon(QIcon::fromTheme("gtk-directory")); } // Set Icon for Open File Menu Item @@ -302,6 +304,10 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D #endif #endif + // Profile UI defaults + ui->labGTAV->setVisible(false); + ui->labRDR2->setVisible(false); + // DPI calculation qreal screenRatio = AppEnv::screenRatio(); resize(625 * screenRatio, 500 * screenRatio); @@ -309,18 +315,23 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D ui->vlUserInterface->setContentsMargins(9 * screenRatio, 9 * screenRatio, 9 * screenRatio, 9 * screenRatio); } -void UserInterface::setupDirEnv(bool showFolderWindow) +void UserInterface::setupDirEnv() { - // settings init QSettings settings(GTA5SYNC_APPVENDOR, GTA5SYNC_APPSTR); bool folderExists_GTAV, folderExists_RDR2; - GTAV_Folder = AppEnv::getGTAVFolder(&folderExists_GTAV); - RDR2_Folder = AppEnv::getRDR2Folder(&folderExists_RDR2); + if (GTAV_Folder.isEmpty()) + GTAV_Folder = AppEnv::getGTAVFolder(&folderExists_GTAV); + else + folderExists_GTAV = QDir(GTAV_Folder).exists(); + if (RDR2_Folder.isEmpty()) + RDR2_Folder = AppEnv::getRDR2Folder(&folderExists_RDR2); + else + folderExists_RDR2 = QDir(RDR2_Folder).exists(); - // profiles init settings.beginGroup("Profile"); - QString defaultProfile = settings.value("Default", QString()).toString(); + const QString defaultProfile = settings.value("Default", QString()).toString(); + const QString defaultGame = settings.value("DefaultGame", QStringLiteral("GTA V")).toString(); settings.endGroup(); contentMode = settings.value("ContentMode", 0).toInt(); @@ -351,19 +362,23 @@ void UserInterface::setupDirEnv(bool showFolderWindow) setupProfileUi(); - if (GTAV_Profiles.contains(defaultProfile)) { - openProfile(defaultProfile, RagePhoto::PhotoFormat::GTA5); - } - else if (GTAV_Profiles.length() == 1 && RDR2_Profiles.length() == 0) { + if (GTAV_Profiles.length() == 1 && RDR2_Profiles.length() == 0) { openProfile(GTAV_Profiles.at(0), RagePhoto::PhotoFormat::GTA5); } else if (GTAV_Profiles.length() == 0 && RDR2_Profiles.length() == 1) { openProfile(RDR2_Profiles.at(0), RagePhoto::PhotoFormat::RDR2); } + else if (defaultGame == QStringLiteral("GTA V") && GTAV_Profiles.contains(defaultProfile)) { + openProfile(defaultProfile, RagePhoto::PhotoFormat::GTA5); + } + else if (defaultGame == QStringLiteral("RDR 2") && RDR2_Profiles.contains(defaultProfile)) { + openProfile(defaultProfile, RagePhoto::PhotoFormat::RDR2); + } } void UserInterface::setupProfileUi() { + bool profileFound = false; qreal screenRatio = AppEnv::screenRatio(); if (!GTAV_Profiles.isEmpty()) { int row = 1; @@ -380,6 +395,7 @@ void UserInterface::setupProfileUi() }); } ui->labGTAV->setVisible(true); + profileFound = true; } else { ui->labGTAV->setVisible(false); @@ -399,15 +415,23 @@ void UserInterface::setupProfileUi() }); } ui->labRDR2->setVisible(true); + profileFound = true; } else { ui->labRDR2->setVisible(false); } + if (profileFound) { + ui->cmdSelectGameFolder->setVisible(false); + } + else { + ui->cmdSelectGameFolder->setVisible(true); + ui->cmdSelectGameFolder->setFocus(); + } } void UserInterface::changeFolder_clicked() { - on_actionSelect_GTA_Folder_triggered(); + on_actionSelect_Game_Folder_triggered(); } void UserInterface::on_cmdReload_clicked() @@ -497,12 +521,11 @@ void UserInterface::openSelectProfile() void UserInterface::on_actionAbout_gta5sync_triggered() { - AboutDialog *aboutDialog = new AboutDialog(this); - aboutDialog->setWindowIcon(windowIcon()); - aboutDialog->setModal(true); - aboutDialog->show(); - aboutDialog->exec(); - delete aboutDialog; + AboutDialog aboutDialog(this); + aboutDialog.setWindowIcon(windowIcon()); + aboutDialog.setModal(true); + aboutDialog.show(); + aboutDialog.exec(); } void UserInterface::profileLoaded() @@ -539,7 +562,8 @@ void UserInterface::on_actionOptions_triggered() { OptionsDialog optionsDialog(profileDB, this); optionsDialog.setWindowIcon(windowIcon()); - optionsDialog.commitProfiles(GTAV_Profiles); // TODO: Diff. GTA V and RDR 2 profiles + optionsDialog.commitProfiles(GTAV_Profiles, QStringLiteral("GTA V")); + optionsDialog.commitProfiles(RDR2_Profiles, QStringLiteral("RDR 2")); QObject::connect(&optionsDialog, &OptionsDialog::settingsApplied, this, &UserInterface::settingsApplied); optionsDialog.setModal(true); optionsDialog.show(); @@ -807,15 +831,92 @@ void UserInterface::updateCacheId(uint cacheId) } #endif -void UserInterface::on_actionSelect_GTA_Folder_triggered() +void UserInterface::on_actionSelect_Game_Folder_triggered() { - const QString GTAV_Folder_Temp = QFileDialog::getExistingDirectory(this, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); - if (!GTAV_Folder_Temp.isEmpty() && QDir(GTAV_Folder_Temp).exists()) { - if (profileOpen) { - closeProfile_p(); + QDialog gameFolderDialog; + gameFolderDialog.setWindowTitle(tr("Select Game Folder...")); + gameFolderDialog.setWindowFlag(Qt::WindowContextHelpButtonHint, false); + + QVBoxLayout *gameFolderLayout = new QVBoxLayout(&gameFolderDialog); + + QHBoxLayout gtaFolderLayout; + gameFolderLayout->addLayout(>aFolderLayout); + QLabel *gtaLabel = new QLabel(tr("GTA V:"), &gameFolderDialog); + gtaFolderLayout.addWidget(gtaLabel); + QLineEdit *gtaLocation = new QLineEdit(AppEnv::getGTAVFolder(), &gameFolderDialog); + gtaLocation->setMinimumWidth(400); + gtaLocation->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); + gtaFolderLayout.addWidget(gtaLocation); + QToolButton *gtaSelectButton = new QToolButton(&gameFolderDialog); + gtaSelectButton->setText(QStringLiteral("...")); + QObject::connect(gtaSelectButton, &QPushButton::clicked, &gameFolderDialog, [&](){ + const QString GTAV_Folder_Temp = QFileDialog::getExistingDirectory(&gameFolderDialog, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); + if (!GTAV_Folder_Temp.isEmpty() && QDir(GTAV_Folder_Temp).exists()) + gtaLocation->setText(GTAV_Folder_Temp); + }); + gtaFolderLayout.addWidget(gtaSelectButton); + + QHBoxLayout rdrFolderLayout; + gameFolderLayout->addLayout(&rdrFolderLayout); + QLabel *rdrLabel = new QLabel(tr("RDR 2:"), &gameFolderDialog); + rdrFolderLayout.addWidget(rdrLabel); + QLineEdit *rdrLocation = new QLineEdit(AppEnv::getRDR2Folder(), &gameFolderDialog); + rdrLocation->setMinimumWidth(400); + rdrLocation->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); + rdrFolderLayout.addWidget(rdrLocation); + QToolButton *rdrSelectButton = new QToolButton(&gameFolderDialog); + rdrSelectButton->setText(QStringLiteral("...")); + QObject::connect(rdrSelectButton, &QPushButton::clicked, &gameFolderDialog, [&](){ + const QString RDR2_Folder_Temp = QFileDialog::getExistingDirectory(&gameFolderDialog, tr("Select RDR 2 Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); + if (!RDR2_Folder_Temp.isEmpty() && QDir(RDR2_Folder_Temp).exists()) + rdrLocation->setText(RDR2_Folder_Temp); + }); + rdrFolderLayout.addWidget(rdrSelectButton); + + QSpacerItem *gameFolderSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + gameFolderLayout->addSpacerItem(gameFolderSpacer); + + QHBoxLayout buttonLayout; + gameFolderLayout->addLayout(&buttonLayout); + QSpacerItem *buttonSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); + buttonLayout.addSpacerItem(buttonSpacer); + QPushButton *selectButton = new QPushButton(tr("&Select"), &gameFolderDialog); + QObject::connect(selectButton, &QPushButton::clicked, &gameFolderDialog, &QDialog::accept); + selectButton->setFocus(); + buttonLayout.addWidget(selectButton); + QPushButton *closeButton = new QPushButton(tr("&Close"), &gameFolderDialog); + QObject::connect(closeButton, &QPushButton::clicked, &gameFolderDialog, &QDialog::reject); + buttonLayout.addWidget(closeButton); + + gameFolderDialog.setMinimumSize(gameFolderDialog.sizeHint()); + gameFolderDialog.setMaximumSize(gameFolderDialog.sizeHint()); + + if (gameFolderDialog.exec() == QDialog::Accepted) { + const QString GTAV_Folder_Temp = gtaLocation->text(); + const QString RDR2_Folder_Temp = rdrLocation->text(); + const bool folderExists_GTAV = (!GTAV_Folder_Temp.isEmpty() && QDir(GTAV_Folder_Temp).exists()); + const bool folderExists_RDR2 = (!RDR2_Folder_Temp.isEmpty() && QDir(RDR2_Folder_Temp).exists()); + if (folderExists_GTAV && folderExists_RDR2) { + GTAV_Folder = GTAV_Folder_Temp; + RDR2_Folder = RDR2_Folder_Temp; + if (profileOpen) + closeProfile_p(); + on_cmdReload_clicked(); + } + else if (folderExists_GTAV && !folderExists_RDR2) { + GTAV_Folder = GTAV_Folder_Temp; + RDR2_Folder = QString(); + if (profileOpen) + closeProfile_p(); + on_cmdReload_clicked(); + } + else if (folderExists_RDR2 && !folderExists_GTAV) { + GTAV_Folder = QString(); + RDR2_Folder = RDR2_Folder_Temp; + if (profileOpen) + closeProfile_p(); + on_cmdReload_clicked(); } - GTAV_Folder = GTAV_Folder_Temp; - on_cmdReload_clicked(); } } diff --git a/src/UserInterface.h b/src/UserInterface.h index 6989c1d..e444177 100644 --- a/src/UserInterface.h +++ b/src/UserInterface.h @@ -48,7 +48,7 @@ public: #else explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); #endif - void setupDirEnv(bool showFolderWindow = true); + void setupDirEnv(); ~UserInterface(); private slots: @@ -66,7 +66,7 @@ private slots: void on_actionOptions_triggered(); void on_action_Import_triggered(); void on_actionOpen_File_triggered(); - void on_actionSelect_GTA_Folder_triggered(); + void on_actionSelect_Game_Folder_triggered(); void on_action_Enable_In_game_triggered(); void on_action_Disable_In_game_triggered(); void on_actionQualify_as_Avatar_triggered(); diff --git a/src/UserInterface.ui b/src/UserInterface.ui index ee66d28..00f98ed 100644 --- a/src/UserInterface.ui +++ b/src/UserInterface.ui @@ -92,6 +92,22 @@ + + + + + 0 + 40 + + + + Select &Game Folder... + + + true + + + @@ -186,7 +202,7 @@ &File - + @@ -322,9 +338,9 @@ Ctrl+O - + - Select &GTA V Folder... + Select &Game Folder... Select GTA V Folder... @@ -400,5 +416,21 @@ + + cmdSelectGameFolder + clicked() + actionSelect_Game_Folder + trigger() + + + 312 + 256 + + + 312 + 249 + + + diff --git a/src/main.cpp b/src/main.cpp index 131a786..208cbc6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -150,15 +150,15 @@ int main(int argc, char *argv[]) telemetryCheckBox->setObjectName(QStringLiteral("TelemetryCheckBox")); telemetryCheckBox->setText(QApplication::translate("TelemetryDialog", "Yes, I want include personal usage data.")); telemetryLayout->addWidget(telemetryCheckBox); - QHBoxLayout *telemetryButtonLayout = new QHBoxLayout(); - telemetryButtonLayout->setObjectName(QStringLiteral("TelemetryButtonLayout")); - telemetryLayout->addLayout(telemetryButtonLayout); + QHBoxLayout telemetryButtonLayout; + telemetryButtonLayout.setObjectName(QStringLiteral("TelemetryButtonLayout")); + telemetryLayout->addLayout(&telemetryButtonLayout); QSpacerItem *telemetryButtonSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); - telemetryButtonLayout->addSpacerItem(telemetryButtonSpacer); + telemetryButtonLayout.addSpacerItem(telemetryButtonSpacer); QPushButton *telemetryButton = new QPushButton(&telemetryDialog); telemetryButton->setObjectName(QStringLiteral("TelemetryButton")); telemetryButton->setText(QApplication::translate("TelemetryDialog", "&OK")); - telemetryButtonLayout->addWidget(telemetryButton); + telemetryButtonLayout.addWidget(telemetryButton); QObject::connect(telemetryButton, &QPushButton::clicked, &telemetryDialog, &QDialog::close); telemetryDialog.setFixedSize(telemetryDialog.sizeHint()); telemetryDialog.exec(); @@ -287,11 +287,7 @@ int main(int argc, char *argv[]) UserInterface uiWindow(&profileDB, &crewDB, &threadDB); #endif uiWindow.setWindowIcon(IconLoader::loadingAppIcon()); -#ifdef GTA5SYNC_FLATPAK - uiWindow.setupDirEnv(false); -#else uiWindow.setupDirEnv(); -#endif uiWindow.show(); return a.exec();