2016-03-23 06:29:49 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* gta5sync GRAND THEFT AUTO V SYNC
|
2016-03-27 09:52:23 +02:00
|
|
|
* Copyright (C) 2016 Syping
|
2016-03-23 06:29:49 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "UserInterface.h"
|
|
|
|
#include "ui_UserInterface.h"
|
|
|
|
#include "ProfileInterface.h"
|
2016-03-28 12:23:50 +02:00
|
|
|
#include "StandardPaths.h"
|
2016-03-27 18:22:22 +02:00
|
|
|
#include "AboutDialog.h"
|
2016-03-27 15:53:32 +02:00
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QSpacerItem>
|
|
|
|
#include <QPushButton>
|
2016-03-25 07:07:58 +01:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QSettings>
|
|
|
|
#include <QFileInfo>
|
2016-03-26 08:53:37 +01:00
|
|
|
#include <QDebug>
|
2016-03-25 07:07:58 +01:00
|
|
|
#include <QFile>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QMap>
|
|
|
|
|
2016-03-27 15:53:32 +02:00
|
|
|
UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, DatabaseThread *threadDB, QWidget *parent) :
|
|
|
|
QMainWindow(parent), profileDB(profileDB), crewDB(crewDB), threadDB(threadDB),
|
2016-03-23 06:29:49 +01:00
|
|
|
ui(new Ui::UserInterface)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
2016-03-27 13:19:50 +02:00
|
|
|
profileOpen = 0;
|
|
|
|
profileUI = 0;
|
2016-03-28 14:10:59 +02:00
|
|
|
defaultWindowTitle = this->windowTitle();
|
|
|
|
|
|
|
|
this->setWindowIcon(QIcon(":/img/5sync.png"));
|
|
|
|
this->setWindowTitle(defaultWindowTitle.arg(tr("Select profile")));
|
2016-03-25 07:07:58 +01:00
|
|
|
|
|
|
|
// init settings
|
2016-03-27 09:52:23 +02:00
|
|
|
QSettings SyncSettings("Syping", "gta5sync");
|
2016-03-25 07:07:58 +01:00
|
|
|
SyncSettings.beginGroup("dir");
|
|
|
|
bool forceDir = SyncSettings.value("force", false).toBool();
|
|
|
|
|
|
|
|
// init folder
|
2016-03-28 13:18:39 +02:00
|
|
|
QString GTAV_defaultFolder = StandardPaths::documentsLocation() + "/Rockstar Games/GTA V";
|
2016-03-25 07:07:58 +01:00
|
|
|
QDir GTAV_Dir;
|
|
|
|
if (forceDir)
|
|
|
|
{
|
|
|
|
GTAV_Folder = SyncSettings.value("dir", GTAV_defaultFolder).toString();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GTAV_Folder = GTAV_defaultFolder;
|
|
|
|
}
|
|
|
|
GTAV_Dir.setPath(GTAV_Folder);
|
|
|
|
if (GTAV_Dir.exists())
|
|
|
|
{
|
|
|
|
QDir::setCurrent(GTAV_Folder);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-27 13:19:50 +02:00
|
|
|
QMessageBox::warning(this, tr("gta5sync"), tr("GTA V Folder not found!"));
|
2016-03-25 07:07:58 +01:00
|
|
|
}
|
2016-03-27 13:19:50 +02:00
|
|
|
SyncSettings.endGroup();
|
2016-03-25 07:07:58 +01:00
|
|
|
|
|
|
|
// profiles init
|
2016-03-27 13:19:50 +02:00
|
|
|
SyncSettings.beginGroup("Profile");
|
|
|
|
QString defaultProfile = SyncSettings.value("Default", "").toString();
|
2016-03-25 07:07:58 +01:00
|
|
|
QDir GTAV_ProfilesDir;
|
2016-03-26 08:53:37 +01:00
|
|
|
GTAV_ProfilesFolder = GTAV_Folder + "/Profiles";
|
2016-03-25 07:07:58 +01:00
|
|
|
GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder);
|
|
|
|
|
2016-03-26 08:53:37 +01:00
|
|
|
QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort);
|
2016-03-27 15:53:32 +02:00
|
|
|
setupProfileUi(GTAV_Profiles);
|
2016-03-25 07:07:58 +01:00
|
|
|
|
2016-03-27 13:19:50 +02:00
|
|
|
if (GTAV_Profiles.length() == 1)
|
2016-03-26 08:53:37 +01:00
|
|
|
{
|
2016-03-27 13:19:50 +02:00
|
|
|
openProfile(GTAV_Profiles.at(0));
|
|
|
|
}
|
|
|
|
else if(GTAV_Profiles.contains(defaultProfile))
|
|
|
|
{
|
|
|
|
openProfile(defaultProfile);
|
|
|
|
}
|
|
|
|
SyncSettings.endGroup();
|
|
|
|
}
|
|
|
|
|
2016-03-27 15:53:32 +02:00
|
|
|
void UserInterface::setupProfileUi(QStringList GTAV_Profiles)
|
|
|
|
{
|
|
|
|
foreach(const QString >AV_Profile, GTAV_Profiles)
|
|
|
|
{
|
|
|
|
QPushButton *profileBtn = new QPushButton(GTAV_Profile, ui->swSelection);
|
|
|
|
profileBtn->setObjectName(GTAV_Profile);
|
|
|
|
profileBtn->setMinimumSize(0, 40);
|
|
|
|
profileBtn->setAutoDefault(true);
|
|
|
|
ui->swSelection->layout()->addWidget(profileBtn);
|
|
|
|
|
|
|
|
QObject::connect(profileBtn, SIGNAL(clicked(bool)), this, SLOT(on_profileButton_clicked()));
|
|
|
|
}
|
|
|
|
QSpacerItem *buttomSpacerItem = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
|
|
|
|
ui->swSelection->layout()->addItem(buttomSpacerItem);
|
|
|
|
|
|
|
|
QHBoxLayout *footerLayout = new QHBoxLayout();
|
|
|
|
footerLayout->setObjectName("footerLayout");
|
|
|
|
ui->swSelection->layout()->addItem(footerLayout);
|
|
|
|
|
|
|
|
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::on_profileButton_clicked()
|
|
|
|
{
|
|
|
|
QPushButton *profileBtn = (QPushButton*)sender();
|
|
|
|
openProfile(profileBtn->objectName());
|
|
|
|
}
|
|
|
|
|
2016-03-27 13:19:50 +02:00
|
|
|
void UserInterface::openProfile(QString profileName)
|
|
|
|
{
|
|
|
|
profileOpen = true;
|
2016-03-27 15:53:32 +02:00
|
|
|
profileUI = new ProfileInterface(profileDB, crewDB, threadDB);
|
2016-03-27 13:19:50 +02:00
|
|
|
ui->swProfile->addWidget(profileUI);
|
|
|
|
ui->swProfile->setCurrentWidget(profileUI);
|
|
|
|
profileUI->setProfileFolder(GTAV_ProfilesFolder + "/" + profileName, profileName);
|
|
|
|
profileUI->setupProfileInterface();
|
|
|
|
QObject::connect(profileUI, SIGNAL(profileClosed()), this, SLOT(closeProfile()));
|
2016-03-28 14:10:59 +02:00
|
|
|
this->setWindowTitle(defaultWindowTitle.arg(profileName));
|
2016-03-27 13:19:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void UserInterface::closeProfile()
|
|
|
|
{
|
|
|
|
if (profileOpen)
|
|
|
|
{
|
|
|
|
profileOpen = false;
|
|
|
|
ui->swProfile->removeWidget(profileUI);
|
|
|
|
profileUI->deleteLater();
|
|
|
|
delete profileUI;
|
2016-03-26 08:53:37 +01:00
|
|
|
}
|
2016-03-28 14:10:59 +02:00
|
|
|
this->setWindowTitle(defaultWindowTitle.arg(tr("Select profile")));
|
2016-03-23 06:29:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
UserInterface::~UserInterface()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserInterface::on_actionExit_triggered()
|
|
|
|
{
|
|
|
|
this->close();
|
|
|
|
}
|
2016-03-27 15:53:32 +02:00
|
|
|
|
|
|
|
void UserInterface::on_actionSelect_profile_triggered()
|
|
|
|
{
|
|
|
|
closeProfile();
|
|
|
|
openSelectProfile();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UserInterface::openSelectProfile()
|
|
|
|
{
|
|
|
|
// not needed right now
|
|
|
|
}
|
2016-03-27 18:22:22 +02:00
|
|
|
|
|
|
|
void UserInterface::on_actionAbout_gta5sync_triggered()
|
|
|
|
{
|
|
|
|
AboutDialog *aboutDialog = new AboutDialog(this);
|
|
|
|
aboutDialog->setWindowFlags(aboutDialog->windowFlags()^Qt::WindowContextHelpButtonHint);
|
|
|
|
aboutDialog->show();
|
|
|
|
aboutDialog->exec();
|
|
|
|
aboutDialog->deleteLater();
|
|
|
|
delete aboutDialog;
|
|
|
|
}
|