2013-02-25 20:22:07 +00:00
|
|
|
#include "datafilespage.hpp"
|
|
|
|
|
2013-03-12 00:29:13 +00:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QMenu>
|
2013-09-22 04:06:29 +00:00
|
|
|
#include <QSortFilterProxyModel>
|
2011-04-07 22:04:09 +00:00
|
|
|
|
2012-01-21 00:14:35 +00:00
|
|
|
#include <components/files/configurationmanager.hpp>
|
2011-04-07 22:04:09 +00:00
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
#include <components/contentselector/model/esmfile.hpp>
|
2013-02-15 14:21:14 +00:00
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
#include <components/contentselector/view/lineedit.hpp>
|
|
|
|
#include <components/contentselector/model/naturalsort.hpp>
|
|
|
|
#include <components/contentselector/view/profilescombobox.hpp>
|
2012-10-10 20:58:04 +00:00
|
|
|
|
2013-01-27 15:39:51 +00:00
|
|
|
#include "settings/gamesettings.hpp"
|
2013-02-11 14:01:00 +00:00
|
|
|
#include "settings/launchersettings.hpp"
|
2013-01-27 15:39:51 +00:00
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
#include "components/contentselector/view/contentselector.hpp"
|
2012-10-12 00:25:14 +00:00
|
|
|
|
2013-02-11 14:01:00 +00:00
|
|
|
DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, GameSettings &gameSettings, LauncherSettings &launcherSettings, QWidget *parent)
|
2013-01-27 15:39:51 +00:00
|
|
|
: mCfgMgr(cfg)
|
|
|
|
, mGameSettings(gameSettings)
|
2013-02-11 14:01:00 +00:00
|
|
|
, mLauncherSettings(launcherSettings)
|
2013-10-07 02:13:47 +00:00
|
|
|
, QWidget(parent)
|
2011-04-07 22:04:09 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
setObjectName ("DataFilesPage");
|
|
|
|
|
|
|
|
unsigned char flags;
|
2013-08-20 08:53:23 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
flags = ContentSelectorView::Flag_Content | ContentSelectorView::Flag_Profile;
|
2013-08-20 13:16:56 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
ContentSelectorView::ContentSelector::configure(this, flags);
|
|
|
|
mSelector = &ContentSelectorView::ContentSelector::instance();
|
2012-10-22 23:47:07 +00:00
|
|
|
|
2013-01-27 15:39:51 +00:00
|
|
|
setupDataFiles();
|
2013-09-22 04:06:29 +00:00
|
|
|
|
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
connect (mSelector, SIGNAL (signalProfileRenamed (QString, QString)),
|
2013-10-02 02:29:45 +00:00
|
|
|
this, SLOT (slotProfileRenamed (QString, QString)));
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
connect (mSelector, SIGNAL (signalProfileChangedByUser (QString, QString)),
|
|
|
|
this, SLOT (slotProfileChangedByUser (QString, QString)));
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
connect (mSelector, SIGNAL (signalProfileDeleted (QString)),
|
2013-10-02 02:29:45 +00:00
|
|
|
this, SLOT (slotProfileDeleted (QString)));
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
connect (mSelector, SIGNAL (signalAddNewProfile (QString)),
|
|
|
|
this, SLOT (slotAddNewProfile (QString)));
|
2013-02-11 14:01:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataFilesPage::loadSettings()
|
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
QString profileName = mSelector->getProfileText();
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/game"), Qt::MatchExactly);
|
|
|
|
QStringList addons = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/addon"), Qt::MatchExactly);
|
2013-02-15 00:20:48 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->clearCheckStates();
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
if (files.size() > 0)
|
|
|
|
mSelector->setGameFile(files.at(0));
|
|
|
|
else
|
|
|
|
mSelector->setGameFile();
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->setCheckStates(addons);
|
2013-02-11 14:01:00 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::saveSettings(const QString &profile)
|
2013-02-11 14:01:00 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
QString profileName = profile;
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
if (profileName.isEmpty())
|
|
|
|
profileName = mSelector->getProfileText();
|
2013-02-24 02:10:27 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
//retrieve the files selected for the profile
|
|
|
|
ContentSelectorModel::ContentFileList items = mSelector->selectedFiles();
|
2013-02-15 00:20:48 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
removeProfile (profileName);
|
2013-02-15 00:20:48 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
mGameSettings.remove(QString("game"));
|
|
|
|
mGameSettings.remove(QString("addon"));
|
2013-02-11 14:01:00 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
//set the value of the current profile (not necessarily the profile being saved!)
|
|
|
|
mLauncherSettings.setValue(QString("Profiles/currentprofile"), mSelector->getProfileText());
|
2013-02-18 22:10:50 +00:00
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
foreach(const ContentSelectorModel::EsmFile *item, items) {
|
2013-02-11 14:01:00 +00:00
|
|
|
|
2013-09-22 04:06:29 +00:00
|
|
|
if (item->gameFiles().size() == 0) {
|
2013-10-07 02:13:47 +00:00
|
|
|
mLauncherSettings.setMultiValue(QString("Profiles/") + profileName + QString("/game"), item->fileName());
|
|
|
|
mGameSettings.setMultiValue(QString("game"), item->fileName());
|
2013-08-20 08:23:32 +00:00
|
|
|
} else {
|
2013-10-07 02:13:47 +00:00
|
|
|
mLauncherSettings.setMultiValue(QString("Profiles/") + profileName + QString("/addon"), item->fileName());
|
|
|
|
mGameSettings.setMultiValue(QString("addon"), item->fileName());
|
2013-02-18 16:59:08 +00:00
|
|
|
}
|
2013-02-11 14:01:00 +00:00
|
|
|
}
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2011-04-07 22:04:09 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::removeProfile(const QString &profile)
|
2012-10-22 23:47:07 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/game"));
|
|
|
|
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/addon"));
|
2011-06-07 18:21:01 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::changeProfiles(const QString &previous, const QString ¤t, bool savePrevious)
|
2011-04-24 21:29:32 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
//abort if no change (typically a duplicate signal)
|
|
|
|
if (previous == current)
|
2013-02-11 14:01:00 +00:00
|
|
|
return;
|
2012-10-22 23:47:07 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
int index = -1;
|
2013-02-11 14:01:00 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
if (!previous.isEmpty())
|
|
|
|
index = mSelector->getProfileIndex(previous);
|
|
|
|
|
|
|
|
// Store the previous profile if it exists
|
|
|
|
if ( (index != -1) && savePrevious)
|
|
|
|
saveSettings(previous);
|
2012-10-22 23:47:07 +00:00
|
|
|
|
2013-02-11 14:01:00 +00:00
|
|
|
loadSettings();
|
2011-04-24 21:29:32 +00:00
|
|
|
}
|
2011-04-24 21:03:21 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::slotAddNewProfile(const QString &profile)
|
2012-10-22 23:47:07 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
saveSettings();
|
|
|
|
mSelector->clearCheckStates();
|
|
|
|
mSelector->addProfile(profile, true);
|
|
|
|
mSelector->setGameFile();
|
2013-02-11 14:01:00 +00:00
|
|
|
saveSettings();
|
2012-10-22 23:47:07 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
emit signalProfileChanged(mSelector->getProfileIndex(profile));
|
|
|
|
}
|
2012-10-22 23:47:07 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::slotProfileDeleted (const QString &item)
|
|
|
|
{
|
|
|
|
removeProfile (item);
|
|
|
|
}
|
2012-10-22 23:47:07 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::slotProfileChangedByUser(const QString &previous, const QString ¤t)
|
|
|
|
{
|
|
|
|
changeProfiles(previous, current);
|
|
|
|
emit signalProfileChanged(mSelector->getProfileIndex(current));
|
2012-10-22 23:47:07 +00:00
|
|
|
}
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::slotProfileRenamed(const QString &previous, const QString ¤t)
|
2013-09-22 04:06:29 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
if (previous.isEmpty())
|
|
|
|
return;
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
// Save the new profile name
|
|
|
|
saveSettings();
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
// Remove the old one
|
|
|
|
removeProfile (previous);
|
2013-10-02 02:29:45 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
loadSettings();
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
void DataFilesPage::slotProfileChanged(int index)
|
2013-09-22 04:06:29 +00:00
|
|
|
{
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->setProfile(index);
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
void DataFilesPage::setupDataFiles()
|
2013-09-22 04:06:29 +00:00
|
|
|
{
|
2013-10-02 02:29:45 +00:00
|
|
|
QStringList paths = mGameSettings.getDataDirs();
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
foreach (const QString &path, paths)
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->addFiles(path);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
QString dataLocal = mGameSettings.getDataLocal();
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
if (!dataLocal.isEmpty())
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->addFiles(dataLocal);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
|
|
|
|
QString profile = mLauncherSettings.value(QString("Profiles/currentprofile"));
|
2013-09-22 04:06:29 +00:00
|
|
|
|
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
foreach (const QString &item, profiles)
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->addProfile (item);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-07 02:13:47 +00:00
|
|
|
mSelector->addProfile (profile, true);
|
2013-09-22 04:06:29 +00:00
|
|
|
|
2013-10-02 02:29:45 +00:00
|
|
|
loadSettings();
|
2013-09-22 04:06:29 +00:00
|
|
|
}
|
2013-10-07 02:13:47 +00:00
|
|
|
|
|
|
|
QAbstractItemModel *DataFilesPage::profilesModel() const
|
|
|
|
{
|
|
|
|
return mSelector->profilesModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
int DataFilesPage::profilesIndex() const
|
|
|
|
{
|
|
|
|
return mSelector->getProfileIndex(mSelector->getProfileText());
|
|
|
|
}
|