added change folder, Reloading profiles added
This commit is contained in:
parent
a7a6d5a1a0
commit
aa890b432a
4 changed files with 144 additions and 42 deletions
|
@ -21,7 +21,9 @@
|
||||||
#include "ProfileInterface.h"
|
#include "ProfileInterface.h"
|
||||||
#include "StandardPaths.h"
|
#include "StandardPaths.h"
|
||||||
#include "AboutDialog.h"
|
#include "AboutDialog.h"
|
||||||
|
#include "IconLoader.h"
|
||||||
#include "AppEnv.h"
|
#include "AppEnv.h"
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QSpacerItem>
|
#include <QSpacerItem>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
@ -45,7 +47,10 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
|
||||||
defaultWindowTitle = this->windowTitle();
|
defaultWindowTitle = this->windowTitle();
|
||||||
|
|
||||||
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
|
this->setWindowTitle(defaultWindowTitle.arg(tr("Select Profile")));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UserInterface::setupDirEnv()
|
||||||
|
{
|
||||||
bool folderExists;
|
bool folderExists;
|
||||||
GTAV_Folder = AppEnv::getGameFolder(&folderExists);
|
GTAV_Folder = AppEnv::getGameFolder(&folderExists);
|
||||||
if (folderExists)
|
if (folderExists)
|
||||||
|
@ -54,40 +59,67 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, D
|
||||||
}
|
}
|
||||||
else
|
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
|
// profiles init
|
||||||
QSettings SyncSettings("Syping", "gta5sync");
|
QSettings SyncSettings("Syping", "gta5sync");
|
||||||
SyncSettings.beginGroup("Profile");
|
SyncSettings.beginGroup("Profile");
|
||||||
QString defaultProfile = SyncSettings.value("Default", "").toString();
|
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);
|
if (folderExists)
|
||||||
setupProfileUi(GTAV_Profiles);
|
|
||||||
|
|
||||||
if (GTAV_Profiles.length() == 1)
|
|
||||||
{
|
{
|
||||||
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)
|
void UserInterface::setupProfileUi(QStringList GTAV_Profiles)
|
||||||
{
|
{
|
||||||
|
bool profilesFound = true;
|
||||||
if (GTAV_Profiles.length() == 0)
|
if (GTAV_Profiles.length() == 0)
|
||||||
{
|
{
|
||||||
|
profilesFound = false;
|
||||||
|
|
||||||
QPushButton *reloadBtn = new QPushButton(tr("&Reload"), ui->swSelection);
|
QPushButton *reloadBtn = new QPushButton(tr("&Reload"), ui->swSelection);
|
||||||
reloadBtn->setObjectName("Reload");
|
reloadBtn->setObjectName("cmdReload");
|
||||||
|
reloadBtn->setMinimumSize(0, 40);
|
||||||
reloadBtn->setAutoDefault(true);
|
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(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)
|
else foreach(const QString >AV_Profile, GTAV_Profiles)
|
||||||
{
|
{
|
||||||
|
@ -95,43 +127,45 @@ void UserInterface::setupProfileUi(QStringList GTAV_Profiles)
|
||||||
profileBtn->setObjectName(GTAV_Profile);
|
profileBtn->setObjectName(GTAV_Profile);
|
||||||
profileBtn->setMinimumSize(0, 40);
|
profileBtn->setMinimumSize(0, 40);
|
||||||
profileBtn->setAutoDefault(true);
|
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()));
|
QObject::connect(profileBtn, SIGNAL(clicked(bool)), this, SLOT(profileButton_clicked()));
|
||||||
}
|
}
|
||||||
QSpacerItem *buttomSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
if (profilesFound)
|
||||||
ui->swSelection->layout()->addItem(buttomSpacerItem);
|
{
|
||||||
|
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();
|
QObject::connect(reloadBtn, SIGNAL(clicked(bool)), this, SLOT(reloadProfiles_clicked()));
|
||||||
footerLayout->setObjectName("footerLayout");
|
}
|
||||||
ui->swSelection->layout()->addItem(footerLayout);
|
profileBtns.at(0)->setFocus();
|
||||||
|
}
|
||||||
|
|
||||||
QSpacerItem *closeButtonSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
void UserInterface::changeFolder_clicked()
|
||||||
footerLayout->addSpacerItem(closeButtonSpacer);
|
{
|
||||||
|
GTAV_Folder = QFileDialog::getExistingDirectory(this, tr("Select GTA V Folder..."), StandardPaths::documentsLocation(), QFileDialog::ShowDirsOnly);
|
||||||
QPushButton *cmdClose = new QPushButton(tr("&Close"), ui->swSelection);
|
if (QFileInfo(GTAV_Folder).exists())
|
||||||
cmdClose->setObjectName("cmdClose");
|
{
|
||||||
cmdClose->setAutoDefault(true);
|
QDir::setCurrent(GTAV_Folder);
|
||||||
footerLayout->addWidget(cmdClose);
|
AppEnv::setGameFolder(GTAV_Folder);
|
||||||
|
reloadProfiles_clicked();
|
||||||
QObject::connect(cmdClose, SIGNAL(clicked(bool)), this, SLOT(close()));
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInterface::reloadProfiles_clicked()
|
void UserInterface::reloadProfiles_clicked()
|
||||||
{
|
{
|
||||||
QStringList gta5sync_a = qApp->arguments();
|
foreach(QPushButton *profileBtn, profileBtns)
|
||||||
if (gta5sync_a.length() >= 1)
|
|
||||||
{
|
{
|
||||||
QProcess gta5sync_p;
|
ui->vlButtons->removeWidget(profileBtn);
|
||||||
QString gta5sync_exe = gta5sync_a.at(0);
|
profileBtns.removeAll(profileBtn);
|
||||||
gta5sync_a.removeAt(0);
|
delete profileBtn;
|
||||||
gta5sync_p.startDetached(gta5sync_exe, gta5sync_a);
|
|
||||||
qApp->exit(0);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::warning(this, tr("Reload profiles"), tr("Not able to reload profiles"));
|
|
||||||
}
|
}
|
||||||
|
setupDirEnv();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserInterface::profileButton_clicked()
|
void UserInterface::profileButton_clicked()
|
||||||
|
@ -168,6 +202,10 @@ void UserInterface::closeProfile()
|
||||||
|
|
||||||
UserInterface::~UserInterface()
|
UserInterface::~UserInterface()
|
||||||
{
|
{
|
||||||
|
foreach (QPushButton *profileBtn, profileBtns)
|
||||||
|
{
|
||||||
|
delete profileBtn;
|
||||||
|
}
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,11 +36,13 @@ class UserInterface : public QMainWindow
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
|
explicit UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent = 0);
|
||||||
|
void setupDirEnv();
|
||||||
~UserInterface();
|
~UserInterface();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void closeProfile();
|
void closeProfile();
|
||||||
void profileLoaded();
|
void profileLoaded();
|
||||||
|
void changeFolder_clicked();
|
||||||
void profileButton_clicked();
|
void profileButton_clicked();
|
||||||
void reloadProfiles_clicked();
|
void reloadProfiles_clicked();
|
||||||
void on_actionExit_triggered();
|
void on_actionExit_triggered();
|
||||||
|
@ -57,6 +59,7 @@ private:
|
||||||
DatabaseThread *threadDB;
|
DatabaseThread *threadDB;
|
||||||
Ui::UserInterface *ui;
|
Ui::UserInterface *ui;
|
||||||
ProfileInterface *profileUI;
|
ProfileInterface *profileUI;
|
||||||
|
QList<QPushButton*> profileBtns;
|
||||||
bool profileOpen;
|
bool profileOpen;
|
||||||
QString defaultWindowTitle;
|
QString defaultWindowTitle;
|
||||||
QString GTAV_Folder;
|
QString GTAV_Folder;
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="swSelection">
|
<widget class="QWidget" name="swSelection">
|
||||||
<layout class="QVBoxLayout" name="verticalLayout">
|
<layout class="QVBoxLayout" name="vlUserInterface">
|
||||||
<item>
|
<item>
|
||||||
<spacer name="vsUpper">
|
<spacer name="vsUpper">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -66,6 +66,49 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="vlButtons"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="vsFooter">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="hlButtons">
|
||||||
|
<item>
|
||||||
|
<spacer name="hsButtons">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="cmdClose">
|
||||||
|
<property name="text">
|
||||||
|
<string>Close</string>
|
||||||
|
</property>
|
||||||
|
<property name="autoDefault">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
|
@ -78,7 +121,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>625</width>
|
<width>625</width>
|
||||||
<height>21</height>
|
<height>25</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -182,5 +225,22 @@
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>cmdClose</sender>
|
||||||
|
<signal>clicked()</signal>
|
||||||
|
<receiver>UserInterface</receiver>
|
||||||
|
<slot>close()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>572</x>
|
||||||
|
<y>476</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>312</x>
|
||||||
|
<y>249</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
1
main.cpp
1
main.cpp
|
@ -452,6 +452,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
UserInterface *uiWindow = new UserInterface(profileDB, crewDB, threadDB);
|
UserInterface *uiWindow = new UserInterface(profileDB, crewDB, threadDB);
|
||||||
uiWindow->setWindowIcon(IconLoader::loadingAppIcon());
|
uiWindow->setWindowIcon(IconLoader::loadingAppIcon());
|
||||||
|
uiWindow->setupDirEnv();
|
||||||
uiWindow->show();
|
uiWindow->show();
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
|
|
Loading…
Reference in a new issue