From aa890b432a78b920259d92452dab9e06bb47ea05 Mon Sep 17 00:00:00 2001 From: Rafael Date: Mon, 11 Apr 2016 16:51:32 +0200 Subject: [PATCH] added change folder, Reloading profiles added --- UserInterface.cpp | 116 ++++++++++++++++++++++++++++++---------------- UserInterface.h | 3 ++ UserInterface.ui | 66 ++++++++++++++++++++++++-- main.cpp | 1 + 4 files changed, 144 insertions(+), 42 deletions(-) diff --git a/UserInterface.cpp b/UserInterface.cpp index 6375cab..4b483b0 100755 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -21,7 +21,9 @@ #include "ProfileInterface.h" #include "StandardPaths.h" #include "AboutDialog.h" +#include "IconLoader.h" #include "AppEnv.h" +#include #include #include #include @@ -45,7 +47,10 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D defaultWindowTitle = this->windowTitle(); this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile"))); +} +void UserInterface::setupDirEnv() +{ bool folderExists; GTAV_Folder = AppEnv::getGameFolder(&folderExists); if (folderExists) @@ -54,40 +59,67 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D } else { - QMessageBox::warning(this, tr("gta5sync"), tr("Grand Theft Auto V Folder not found!")); + GTAV_Folder = QFileDialog::getExistingDirectory(this, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); + if (QFileInfo(GTAV_Folder).exists()) + { + folderExists = true; + QDir::setCurrent(GTAV_Folder); + AppEnv::setGameFolder(GTAV_Folder); + } } // profiles init QSettings SyncSettings("Syping", "gta5sync"); SyncSettings.beginGroup("Profile"); QString defaultProfile = SyncSettings.value("Default", "").toString(); - QDir GTAV_ProfilesDir; - GTAV_ProfilesFolder = GTAV_Folder + QDir::separator() + "Profiles"; - GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder); - QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); - setupProfileUi(GTAV_Profiles); - - if (GTAV_Profiles.length() == 1) + if (folderExists) { - openProfile(GTAV_Profiles.at(0)); + QDir GTAV_ProfilesDir; + GTAV_ProfilesFolder = GTAV_Folder + QDir::separator() + "Profiles"; + GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder); + + QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); + setupProfileUi(GTAV_Profiles); + + if (GTAV_Profiles.length() == 1) + { + openProfile(GTAV_Profiles.at(0)); + } + else if(GTAV_Profiles.contains(defaultProfile)) + { + openProfile(defaultProfile); + } } - else if(GTAV_Profiles.contains(defaultProfile)) + else { - openProfile(defaultProfile); + setupProfileUi(QStringList()); } } void UserInterface::setupProfileUi(QStringList GTAV_Profiles) { + bool profilesFound = true; if (GTAV_Profiles.length() == 0) { + profilesFound = false; + QPushButton *reloadBtn = new QPushButton(tr("&Reload"), ui->swSelection); - reloadBtn->setObjectName("Reload"); + reloadBtn->setObjectName("cmdReload"); + reloadBtn->setMinimumSize(0, 40); reloadBtn->setAutoDefault(true); - ui->swSelection->layout()->addWidget(reloadBtn); + ui->vlButtons->addWidget(reloadBtn); + profileBtns.append(reloadBtn); + + QPushButton *changeDirBtn = new QPushButton(tr("Change GTA V &Folder"), ui->swSelection); + changeDirBtn->setObjectName("cmdChangeDir"); + changeDirBtn->setMinimumSize(0, 40); + changeDirBtn->setAutoDefault(true); + ui->vlButtons->addWidget(changeDirBtn); + profileBtns.append(changeDirBtn); QObject::connect(reloadBtn, SIGNAL(clicked(bool)), this, SLOT(reloadProfiles_clicked())); + QObject::connect(changeDirBtn, SIGNAL(clicked(bool)), this, SLOT(changeFolder_clicked())); } else foreach(const QString >AV_Profile, GTAV_Profiles) { @@ -95,43 +127,45 @@ void UserInterface::setupProfileUi(QStringList GTAV_Profiles) profileBtn->setObjectName(GTAV_Profile); profileBtn->setMinimumSize(0, 40); profileBtn->setAutoDefault(true); - ui->swSelection->layout()->addWidget(profileBtn); + ui->vlButtons->addWidget(profileBtn); + profileBtns.append(profileBtn); QObject::connect(profileBtn, SIGNAL(clicked(bool)), this, SLOT(profileButton_clicked())); } - QSpacerItem *buttomSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); - ui->swSelection->layout()->addItem(buttomSpacerItem); + if (profilesFound) + { + QPushButton *reloadBtn = new QPushButton(tr("&Reload"), ui->swSelection); + reloadBtn->setObjectName("cmdReload"); + reloadBtn->setMinimumSize(0, 40); + reloadBtn->setAutoDefault(true); + ui->vlButtons->addWidget(reloadBtn); + profileBtns.append(reloadBtn); - QHBoxLayout *footerLayout = new QHBoxLayout(); - footerLayout->setObjectName("footerLayout"); - ui->swSelection->layout()->addItem(footerLayout); + QObject::connect(reloadBtn, SIGNAL(clicked(bool)), this, SLOT(reloadProfiles_clicked())); + } + profileBtns.at(0)->setFocus(); +} - QSpacerItem *closeButtonSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum); - footerLayout->addSpacerItem(closeButtonSpacer); - - QPushButton *cmdClose = new QPushButton(tr("&Close"), ui->swSelection); - cmdClose->setObjectName("cmdClose"); - cmdClose->setAutoDefault(true); - footerLayout->addWidget(cmdClose); - - QObject::connect(cmdClose, SIGNAL(clicked(bool)), this, SLOT(close())); +void UserInterface::changeFolder_clicked() +{ + GTAV_Folder = QFileDialog::getExistingDirectory(this, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly); + if (QFileInfo(GTAV_Folder).exists()) + { + QDir::setCurrent(GTAV_Folder); + AppEnv::setGameFolder(GTAV_Folder); + reloadProfiles_clicked(); + } } void UserInterface::reloadProfiles_clicked() { - QStringList gta5sync_a = qApp->arguments(); - if (gta5sync_a.length() >= 1) + foreach(QPushButton *profileBtn, profileBtns) { - QProcess gta5sync_p; - QString gta5sync_exe = gta5sync_a.at(0); - gta5sync_a.removeAt(0); - gta5sync_p.startDetached(gta5sync_exe, gta5sync_a); - qApp->exit(0); - } - else - { - QMessageBox::warning(this, tr("Reload profiles"), tr("Not able to reload profiles")); + ui->vlButtons->removeWidget(profileBtn); + profileBtns.removeAll(profileBtn); + delete profileBtn; } + setupDirEnv(); } void UserInterface::profileButton_clicked() @@ -168,6 +202,10 @@ void UserInterface::closeProfile() UserInterface::~UserInterface() { + foreach (QPushButton *profileBtn, profileBtns) + { + delete profileBtn; + } delete ui; } diff --git a/UserInterface.h b/UserInterface.h index 165a702..c73f3f7 100755 --- a/UserInterface.h +++ b/UserInterface.h @@ -36,11 +36,13 @@ class UserInterface : public QMainWindow Q_OBJECT public: explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0); + void setupDirEnv(); ~UserInterface(); private slots: void closeProfile(); void profileLoaded(); + void changeFolder_clicked(); void profileButton_clicked(); void reloadProfiles_clicked(); void on_actionExit_triggered(); @@ -57,6 +59,7 @@ private: DatabaseThread *threadDB; Ui::UserInterface *ui; ProfileInterface *profileUI; + QList profileBtns; bool profileOpen; QString defaultWindowTitle; QString GTAV_Folder; diff --git a/UserInterface.ui b/UserInterface.ui index 36cc9ee..df7cc1c 100755 --- a/UserInterface.ui +++ b/UserInterface.ui @@ -39,7 +39,7 @@ 0 - + @@ -66,6 +66,49 @@ + + + + + + + Qt::Vertical + + + + 0 + 0 + + + + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + + + Close + + + true + + + + + @@ -78,7 +121,7 @@ 0 0 625 - 21 + 25 @@ -182,5 +225,22 @@ - + + + cmdClose + clicked() + UserInterface + close() + + + 572 + 476 + + + 312 + 249 + + + + diff --git a/main.cpp b/main.cpp index 5ac4596..a2e6aa1 100755 --- a/main.cpp +++ b/main.cpp @@ -452,6 +452,7 @@ int main(int argc, char *argv[]) UserInterface *uiWindow = new UserInterface(profileDB, crewDB, threadDB); uiWindow->setWindowIcon(IconLoader::loadingAppIcon()); + uiWindow->setupDirEnv(); uiWindow->show(); return a.exec();