diff --git a/ProfileInterface.cpp b/ProfileInterface.cpp index e944dd5..f202ce8 100755 --- a/ProfileInterface.cpp +++ b/ProfileInterface.cpp @@ -40,6 +40,14 @@ ProfileInterface::ProfileInterface(ProfileDatabase *profileDB, CrewDatabase *cre ProfileInterface::~ProfileInterface() { + foreach(SavegameData *savegame, savegames) + { + delete savegame; + } + foreach(SnapmaticPicture *picture, pictures) + { + delete picture; + } delete ui; } @@ -64,6 +72,7 @@ void ProfileInterface::on_savegameLoaded(SavegameData *savegame, QString savegam SavegameWidget *sgdWidget = new SavegameWidget(); sgdWidget->setSavegameData(savegame, savegamePath); ui->vlSavegame->addWidget(sgdWidget); + savegames.append(savegame); } void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString picturePath) @@ -71,6 +80,7 @@ void ProfileInterface::on_pictureLoaded(SnapmaticPicture *picture, QString pictu SnapmaticWidget *picWidget = new SnapmaticWidget(profileDB); picWidget->setSnapmaticPicture(picture, picturePath); ui->vlSnapmatic->addWidget(picWidget); + pictures.append(picture); } void ProfileInterface::on_loadingProgress(int value, int maximum) @@ -90,5 +100,5 @@ void ProfileInterface::on_profileLoaded() void ProfileInterface::on_cmdCloseProfile_clicked() { - this->close(); + emit profileClosed(); } diff --git a/ProfileInterface.h b/ProfileInterface.h index 68b1ee4..4c71f6f 100755 --- a/ProfileInterface.h +++ b/ProfileInterface.h @@ -24,6 +24,7 @@ #include "SavegameData.h" #include "CrewDatabase.h" #include +#include namespace Ui { class ProfileInterface; @@ -52,6 +53,11 @@ private: QString profileFolder; QString profileName; QString loadingStr; + QList savegames; + QList pictures; + +signals: + void profileClosed(); }; #endif // PROFILEINTERFACE_H diff --git a/ProfileInterface.ui b/ProfileInterface.ui index 1ee8dd1..3dcaefb 100755 --- a/ProfileInterface.ui +++ b/ProfileInterface.ui @@ -172,6 +172,9 @@ Close Profile + + true + diff --git a/SavegameWidget.ui b/SavegameWidget.ui index 95a00d7..97f845c 100755 --- a/SavegameWidget.ui +++ b/SavegameWidget.ui @@ -45,6 +45,9 @@ Copy + + true + @@ -52,6 +55,9 @@ Delete + + true + diff --git a/SnapmaticWidget.ui b/SnapmaticWidget.ui index f2fcd92..572bc36 100755 --- a/SnapmaticWidget.ui +++ b/SnapmaticWidget.ui @@ -60,6 +60,9 @@ View + + true + @@ -67,6 +70,9 @@ Delete + + true + diff --git a/UserInterface.cpp b/UserInterface.cpp index 244b3ac..32bcb2c 100755 --- a/UserInterface.cpp +++ b/UserInterface.cpp @@ -38,6 +38,8 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, Q ui(new Ui::UserInterface) { ui->setupUi(this); + profileOpen = 0; + profileUI = 0; // init settings QSettings SyncSettings("Syping", "gta5sync"); @@ -66,24 +68,49 @@ UserInterface::UserInterface(ProfileDatabase *profileDB, CrewDatabase *crewDB, Q } else { - QMessageBox::warning(this, tr("GTA V Sync"), tr("GTA V Folder not found!")); + QMessageBox::warning(this, tr("gta5sync"), tr("GTA V Folder not found!")); } + SyncSettings.endGroup(); // profiles init + SyncSettings.beginGroup("Profile"); + QString defaultProfile = SyncSettings.value("Default", "").toString(); QDir GTAV_ProfilesDir; GTAV_ProfilesFolder = GTAV_Folder + "/Profiles"; GTAV_ProfilesDir.setPath(GTAV_ProfilesFolder); QStringList GTAV_Profiles = GTAV_ProfilesDir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::NoSort); - if (GTAV_Profiles.length() >= 1) + if (GTAV_Profiles.length() == 1) { - QString profileName = GTAV_Profiles.at(0); - ProfileInterface *profile1 = new ProfileInterface(profileDB, crewDB); - ui->swProfile->addWidget(profile1); - ui->swProfile->setCurrentWidget(profile1); - profile1->setProfileFolder(GTAV_ProfilesFolder + "/" + profileName, profileName); - profile1->setupProfileInterface(); + openProfile(GTAV_Profiles.at(0)); + } + else if(GTAV_Profiles.contains(defaultProfile)) + { + openProfile(defaultProfile); + } + SyncSettings.endGroup(); +} + +void UserInterface::openProfile(QString profileName) +{ + profileOpen = true; + profileUI = new ProfileInterface(profileDB, crewDB); + ui->swProfile->addWidget(profileUI); + ui->swProfile->setCurrentWidget(profileUI); + profileUI->setProfileFolder(GTAV_ProfilesFolder + "/" + profileName, profileName); + profileUI->setupProfileInterface(); + QObject::connect(profileUI, SIGNAL(profileClosed()), this, SLOT(closeProfile())); +} + +void UserInterface::closeProfile() +{ + if (profileOpen) + { + profileOpen = false; + ui->swProfile->removeWidget(profileUI); + profileUI->deleteLater(); + delete profileUI; } } diff --git a/UserInterface.h b/UserInterface.h index 85dfe0e..cef0990 100755 --- a/UserInterface.h +++ b/UserInterface.h @@ -19,6 +19,7 @@ #ifndef USERINTERFACE_H #define USERINTERFACE_H +#include "ProfileInterface.h" #include "ProfileDatabase.h" #include "CrewDatabase.h" #include @@ -38,14 +39,17 @@ public: private slots: void on_actionExit_triggered(); + void closeProfile(); private: ProfileDatabase *profileDB; CrewDatabase *crewDB; Ui::UserInterface *ui; + ProfileInterface *profileUI; + bool profileOpen; QString GTAV_Folder; QString GTAV_ProfilesFolder; - QMap GTAV_ProfileMap; + void openProfile(QString profileName); }; #endif // USERINTERFACE_H