forked from mirror/openmw-tes3mp
Merge remote-tracking branch 'dteviot/Bug811'
This commit is contained in:
commit
7c959c8494
11 changed files with 225 additions and 91 deletions
|
@ -30,7 +30,7 @@ Launcher::DataFilesPage::DataFilesPage(Files::ConfigurationManager &cfg, Config:
|
||||||
setObjectName ("DataFilesPage");
|
setObjectName ("DataFilesPage");
|
||||||
mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget);
|
mSelector = new ContentSelectorView::ContentSelector (ui.contentSelectorWidget);
|
||||||
|
|
||||||
mProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this);
|
mProfileDialog = new TextInputDialog(tr("New Content List"), tr("Content List name:"), this);
|
||||||
|
|
||||||
connect(mProfileDialog->lineEdit(), SIGNAL(textChanged(QString)),
|
connect(mProfileDialog->lineEdit(), SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(updateOkButton(QString)));
|
this, SLOT(updateOkButton(QString)));
|
||||||
|
@ -44,12 +44,12 @@ void Launcher::DataFilesPage::buildView()
|
||||||
ui.verticalLayout->insertWidget (0, mSelector->uiWidget());
|
ui.verticalLayout->insertWidget (0, mSelector->uiWidget());
|
||||||
|
|
||||||
//tool buttons
|
//tool buttons
|
||||||
ui.newProfileButton->setToolTip ("Create a new profile");
|
ui.newProfileButton->setToolTip ("Create a new Content List");
|
||||||
ui.deleteProfileButton->setToolTip ("Delete an existing profile");
|
ui.deleteProfileButton->setToolTip ("Delete an existing Content List");
|
||||||
|
|
||||||
//combo box
|
//combo box
|
||||||
ui.profilesComboBox->addItem ("Default");
|
ui.profilesComboBox->addItem ("Default");
|
||||||
ui.profilesComboBox->setPlaceholderText (QString("Select a profile..."));
|
ui.profilesComboBox->setPlaceholderText (QString("Select a Content List..."));
|
||||||
ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(QLatin1String("Default")));
|
ui.profilesComboBox->setCurrentIndex(ui.profilesComboBox->findText(QLatin1String("Default")));
|
||||||
|
|
||||||
// Add the actions to the toolbuttons
|
// Add the actions to the toolbuttons
|
||||||
|
@ -82,8 +82,8 @@ bool Launcher::DataFilesPage::loadSettings()
|
||||||
paths.insert (0, mDataLocal);
|
paths.insert (0, mDataLocal);
|
||||||
PathIterator pathIterator (paths);
|
PathIterator pathIterator (paths);
|
||||||
|
|
||||||
QStringList profiles = mLauncherSettings.subKeys(QString("Profiles/"));
|
QStringList profiles = mLauncherSettings.getContentLists();
|
||||||
QString currentProfile = mLauncherSettings.getSettings().value("Profiles/currentprofile");
|
QString currentProfile = mLauncherSettings.getCurrentContentListName();
|
||||||
|
|
||||||
qDebug() << "current profile is: " << currentProfile;
|
qDebug() << "current profile is: " << currentProfile;
|
||||||
|
|
||||||
|
@ -101,15 +101,12 @@ bool Launcher::DataFilesPage::loadSettings()
|
||||||
|
|
||||||
QStringList Launcher::DataFilesPage::filesInProfile(const QString& profileName, PathIterator& pathIterator)
|
QStringList Launcher::DataFilesPage::filesInProfile(const QString& profileName, PathIterator& pathIterator)
|
||||||
{
|
{
|
||||||
QStringList files = mLauncherSettings.values(QString("Profiles/") + profileName + QString("/content"), Qt::MatchExactly);
|
QStringList files = mLauncherSettings.getContentListFiles(profileName);
|
||||||
QStringList filepaths;
|
QStringList filepaths;
|
||||||
|
|
||||||
// mLauncherSettings.values() returns the files in reverse load order
|
foreach(const QString& file, files)
|
||||||
QListIterator<QString> i(files);
|
|
||||||
i.toBack();
|
|
||||||
while (i.hasPrevious())
|
|
||||||
{
|
{
|
||||||
QString filepath = pathIterator.findFirstPath(i.previous());
|
QString filepath = pathIterator.findFirstPath(file);
|
||||||
|
|
||||||
if (!filepath.isEmpty())
|
if (!filepath.isEmpty())
|
||||||
filepaths << filepath;
|
filepaths << filepath;
|
||||||
|
@ -128,24 +125,20 @@ void Launcher::DataFilesPage::saveSettings(const QString &profile)
|
||||||
//retrieve the files selected for the profile
|
//retrieve the files selected for the profile
|
||||||
ContentSelectorModel::ContentFileList items = mSelector->selectedFiles();
|
ContentSelectorModel::ContentFileList items = mSelector->selectedFiles();
|
||||||
|
|
||||||
removeProfile (profileName);
|
|
||||||
|
|
||||||
mGameSettings.remove(QString("content"));
|
|
||||||
|
|
||||||
//set the value of the current profile (not necessarily the profile being saved!)
|
//set the value of the current profile (not necessarily the profile being saved!)
|
||||||
mLauncherSettings.setValue(QString("Profiles/currentprofile"), ui.profilesComboBox->currentText());
|
mLauncherSettings.setCurrentContentListName(ui.profilesComboBox->currentText());
|
||||||
|
|
||||||
|
QStringList fileNames;
|
||||||
foreach(const ContentSelectorModel::EsmFile *item, items) {
|
foreach(const ContentSelectorModel::EsmFile *item, items) {
|
||||||
mLauncherSettings.setMultiValue(QString("Profiles/") + profileName + QString("/content"), item->fileName());
|
fileNames.append(item->fileName());
|
||||||
mGameSettings.setMultiValue(QString("content"), item->fileName());
|
|
||||||
}
|
}
|
||||||
|
mLauncherSettings.setContentList(profileName, fileNames);
|
||||||
|
mGameSettings.setContentList(fileNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Launcher::DataFilesPage::removeProfile(const QString &profile)
|
void Launcher::DataFilesPage::removeProfile(const QString &profile)
|
||||||
{
|
{
|
||||||
mLauncherSettings.remove(QString("Profiles/") + profile);
|
mLauncherSettings.removeContentList(profile);
|
||||||
mLauncherSettings.remove(QString("Profiles/") + profile + QString("/content"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QAbstractItemModel *Launcher::DataFilesPage::profilesModel() const
|
QAbstractItemModel *Launcher::DataFilesPage::profilesModel() const
|
||||||
|
@ -233,7 +226,7 @@ void Launcher::DataFilesPage::on_newProfileAction_triggered()
|
||||||
|
|
||||||
saveSettings();
|
saveSettings();
|
||||||
|
|
||||||
mLauncherSettings.setValue(QString("Profiles/currentprofile"), profile);
|
mLauncherSettings.setCurrentContentListName(profile);
|
||||||
|
|
||||||
addProfile(profile, true);
|
addProfile(profile, true);
|
||||||
mSelector->clearCheckStates();
|
mSelector->clearCheckStates();
|
||||||
|
@ -306,10 +299,10 @@ void Launcher::DataFilesPage::checkForDefaultProfile()
|
||||||
bool Launcher::DataFilesPage::showDeleteMessageBox (const QString &text)
|
bool Launcher::DataFilesPage::showDeleteMessageBox (const QString &text)
|
||||||
{
|
{
|
||||||
QMessageBox msgBox(this);
|
QMessageBox msgBox(this);
|
||||||
msgBox.setWindowTitle(tr("Delete Profile"));
|
msgBox.setWindowTitle(tr("Delete Content List"));
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
msgBox.setStandardButtons(QMessageBox::Cancel);
|
msgBox.setStandardButtons(QMessageBox::Cancel);
|
||||||
msgBox.setText(tr("Are you sure you want to delete <b>%0</b>?").arg(text));
|
msgBox.setText(tr("Are you sure you want to delete <b>%1</b>?").arg(text));
|
||||||
|
|
||||||
QAbstractButton *deleteButton =
|
QAbstractButton *deleteButton =
|
||||||
msgBox.addButton(tr("Delete"), QMessageBox::ActionRole);
|
msgBox.addButton(tr("Delete"), QMessageBox::ActionRole);
|
||||||
|
|
|
@ -209,6 +209,8 @@ bool Launcher::MainDialog::setup()
|
||||||
if (!setupGameSettings())
|
if (!setupGameSettings())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
mLauncherSettings.setContentList(mGameSettings);
|
||||||
|
|
||||||
if (!setupGraphicsSettings())
|
if (!setupGraphicsSettings())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -232,6 +234,8 @@ bool Launcher::MainDialog::reloadSettings()
|
||||||
if (!setupGameSettings())
|
if (!setupGameSettings())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
mLauncherSettings.setContentList(mGameSettings);
|
||||||
|
|
||||||
if (!setupGraphicsSettings())
|
if (!setupGraphicsSettings())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -280,8 +284,8 @@ bool Launcher::MainDialog::setupLauncherSettings()
|
||||||
QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str());
|
QString userPath = QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str());
|
||||||
|
|
||||||
QStringList paths;
|
QStringList paths;
|
||||||
paths.append(QString("launcher.cfg"));
|
paths.append(QString(Config::LauncherSettings::sLauncherConfigFileName));
|
||||||
paths.append(userPath + QString("launcher.cfg"));
|
paths.append(userPath + QString(Config::LauncherSettings::sLauncherConfigFileName));
|
||||||
|
|
||||||
foreach (const QString &path, paths) {
|
foreach (const QString &path, paths) {
|
||||||
qDebug() << "Loading config file:" << qPrintable(path);
|
qDebug() << "Loading config file:" << qPrintable(path);
|
||||||
|
@ -562,7 +566,7 @@ bool Launcher::MainDialog::writeSettings()
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
// Launcher settings
|
// Launcher settings
|
||||||
file.setFileName(userPath + QString("launcher.cfg"));
|
file.setFileName(userPath + QString(Config::LauncherSettings::sLauncherConfigFileName));
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
||||||
// File cannot be opened or created
|
// File cannot be opened or created
|
||||||
|
|
|
@ -51,7 +51,7 @@ Launcher::SettingsPage::SettingsPage(Files::ConfigurationManager &cfg,
|
||||||
connect(mImporterInvoker->getProcess(), SIGNAL(finished(int,QProcess::ExitStatus)),
|
connect(mImporterInvoker->getProcess(), SIGNAL(finished(int,QProcess::ExitStatus)),
|
||||||
this, SLOT(importerFinished(int,QProcess::ExitStatus)));
|
this, SLOT(importerFinished(int,QProcess::ExitStatus)));
|
||||||
|
|
||||||
mProfileDialog = new TextInputDialog(tr("New Profile"), tr("Profile name:"), this);
|
mProfileDialog = new TextInputDialog(tr("New Content List"), tr("Content List name:"), this);
|
||||||
|
|
||||||
connect(mProfileDialog->lineEdit(), SIGNAL(textChanged(QString)),
|
connect(mProfileDialog->lineEdit(), SIGNAL(textChanged(QString)),
|
||||||
this, SLOT(updateOkButton(QString)));
|
this, SLOT(updateOkButton(QString)));
|
||||||
|
@ -207,18 +207,9 @@ void Launcher::SettingsPage::importerFinished(int exitCode, QProcess::ExitStatus
|
||||||
if (mProfileDialog->exec() == QDialog::Accepted)
|
if (mProfileDialog->exec() == QDialog::Accepted)
|
||||||
{
|
{
|
||||||
const QString profile(mProfileDialog->lineEdit()->text());
|
const QString profile(mProfileDialog->lineEdit()->text());
|
||||||
const QStringList files(mGameSettings.values(QLatin1String("content")));
|
const QStringList files(mGameSettings.getContentList());
|
||||||
|
mLauncherSettings.setCurrentContentListName(profile);
|
||||||
qDebug() << "Profile " << profile << files;
|
mLauncherSettings.setContentList(profile, files);
|
||||||
|
|
||||||
// Doesn't quite work right now
|
|
||||||
mLauncherSettings.setValue(QLatin1String("Profiles/currentprofile"), profile);
|
|
||||||
|
|
||||||
foreach (const QString &file, files) {
|
|
||||||
mLauncherSettings.setMultiValue(QLatin1String("Profiles/") + profile + QLatin1String("/content"), file);
|
|
||||||
}
|
|
||||||
|
|
||||||
mGameSettings.remove(QLatin1String("content"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,7 +225,7 @@ void Launcher::SettingsPage::updateOkButton(const QString &text)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QStringList profiles(mLauncherSettings.subKeys(QString("Profiles/")));
|
const QStringList profiles(mLauncherSettings.getContentLists());
|
||||||
|
|
||||||
(profiles.contains(text))
|
(profiles.contains(text))
|
||||||
? mProfileDialog->setOkButtonEnabled(false)
|
? mProfileDialog->setOkButtonEnabled(false)
|
||||||
|
|
|
@ -182,7 +182,7 @@ void Wizard::MainWizard::setupGameSettings()
|
||||||
void Wizard::MainWizard::setupLauncherSettings()
|
void Wizard::MainWizard::setupLauncherSettings()
|
||||||
{
|
{
|
||||||
QString path(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
|
QString path(QString::fromUtf8(mCfgMgr.getUserConfigPath().string().c_str()));
|
||||||
path.append(QLatin1String("launcher.cfg"));
|
path.append(QLatin1String(Config::LauncherSettings::sLauncherConfigFileName));
|
||||||
|
|
||||||
QString message(tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \
|
QString message(tr("<html><head/><body><p><b>Could not open %1 for reading</b></p> \
|
||||||
<p>Please make sure you have the right permissions \
|
<p>Please make sure you have the right permissions \
|
||||||
|
@ -427,7 +427,7 @@ void Wizard::MainWizard::writeSettings()
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
// Launcher settings
|
// Launcher settings
|
||||||
file.setFileName(userPath + QLatin1String("launcher.cfg"));
|
file.setFileName(userPath + QLatin1String(Config::LauncherSettings::sLauncherConfigFileName));
|
||||||
|
|
||||||
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
if (!file.open(QIODevice::ReadWrite | QIODevice::Text | QIODevice::Truncate)) {
|
||||||
// File cannot be opened or created
|
// File cannot be opened or created
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "gamesettings.hpp"
|
#include "gamesettings.hpp"
|
||||||
|
#include "launchersettings.hpp"
|
||||||
|
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
@ -26,6 +27,7 @@ namespace boost
|
||||||
} /* namespace boost */
|
} /* namespace boost */
|
||||||
#endif /* (BOOST_VERSION <= 104600) */
|
#endif /* (BOOST_VERSION <= 104600) */
|
||||||
|
|
||||||
|
const char Config::GameSettings::sContentKey[] = "content";
|
||||||
|
|
||||||
Config::GameSettings::GameSettings(Files::ConfigurationManager &cfg)
|
Config::GameSettings::GameSettings(Files::ConfigurationManager &cfg)
|
||||||
: mCfgMgr(cfg)
|
: mCfgMgr(cfg)
|
||||||
|
@ -81,7 +83,7 @@ void Config::GameSettings::validatePaths()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Config::GameSettings::values(const QString &key, const QStringList &defaultValues)
|
QStringList Config::GameSettings::values(const QString &key, const QStringList &defaultValues) const
|
||||||
{
|
{
|
||||||
if (!mSettings.values(key).isEmpty())
|
if (!mSettings.values(key).isEmpty())
|
||||||
return mSettings.values(key);
|
return mSettings.values(key);
|
||||||
|
@ -149,9 +151,6 @@ bool Config::GameSettings::writeFile(QTextStream &stream)
|
||||||
while (i.hasPrevious()) {
|
while (i.hasPrevious()) {
|
||||||
i.previous();
|
i.previous();
|
||||||
|
|
||||||
if (i.key() == QLatin1String("content"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Quote paths with spaces
|
// Quote paths with spaces
|
||||||
if (i.key() == QLatin1String("data")
|
if (i.key() == QLatin1String("data")
|
||||||
|| i.key() == QLatin1String("data-local")
|
|| i.key() == QLatin1String("data-local")
|
||||||
|
@ -171,18 +170,13 @@ bool Config::GameSettings::writeFile(QTextStream &stream)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList content = mUserSettings.values(QString("content"));
|
|
||||||
for (int i = content.count(); i--;) {
|
|
||||||
stream << "content=" << content.at(i) << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Config::GameSettings::hasMaster()
|
bool Config::GameSettings::hasMaster()
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
QStringList content = mSettings.values(QString("content"));
|
QStringList content = mSettings.values(QString(Config::GameSettings::sContentKey));
|
||||||
for (int i = 0; i < content.count(); ++i) {
|
for (int i = 0; i < content.count(); ++i) {
|
||||||
if (content.at(i).contains(".omwgame") || content.at(i).contains(".esm")) {
|
if (content.at(i).contains(".omwgame") || content.at(i).contains(".esm")) {
|
||||||
result = true;
|
result = true;
|
||||||
|
@ -192,3 +186,19 @@ bool Config::GameSettings::hasMaster()
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Config::GameSettings::setContentList(const QStringList& fileNames)
|
||||||
|
{
|
||||||
|
remove(sContentKey);
|
||||||
|
foreach(const QString& fileName, fileNames)
|
||||||
|
{
|
||||||
|
setMultiValue(sContentKey, fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList Config::GameSettings::getContentList() const
|
||||||
|
{
|
||||||
|
// QMap returns multiple rows in LIFO order, so need to reverse
|
||||||
|
return Config::LauncherSettings::reverse(values(sContentKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ namespace Config
|
||||||
|
|
||||||
bool hasMaster();
|
bool hasMaster();
|
||||||
|
|
||||||
QStringList values(const QString &key, const QStringList &defaultValues = QStringList());
|
QStringList values(const QString &key, const QStringList &defaultValues = QStringList()) const;
|
||||||
|
|
||||||
bool readFile(QTextStream &stream);
|
bool readFile(QTextStream &stream);
|
||||||
bool readFile(QTextStream &stream, QMap<QString, QString> &settings);
|
bool readFile(QTextStream &stream, QMap<QString, QString> &settings);
|
||||||
|
@ -67,6 +67,9 @@ namespace Config
|
||||||
|
|
||||||
bool writeFile(QTextStream &stream);
|
bool writeFile(QTextStream &stream);
|
||||||
|
|
||||||
|
void setContentList(const QStringList& fileNames);
|
||||||
|
QStringList getContentList() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
Files::ConfigurationManager &mCfgMgr;
|
||||||
|
|
||||||
|
@ -76,6 +79,8 @@ namespace Config
|
||||||
|
|
||||||
QStringList mDataDirs;
|
QStringList mDataDirs;
|
||||||
QString mDataLocal;
|
QString mDataLocal;
|
||||||
|
|
||||||
|
static const char sContentKey[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // GAMESETTINGS_HPP
|
#endif // GAMESETTINGS_HPP
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
const char Config::LauncherSettings::sCurrentContentListKey[] = "Profiles/currentprofile";
|
||||||
|
const char Config::LauncherSettings::sLauncherConfigFileName[] = "launcher.cfg";
|
||||||
|
const char Config::LauncherSettings::sContentListsSectionPrefix[] = "Profiles/";
|
||||||
|
const char Config::LauncherSettings::sContentListSuffix[] = "/content";
|
||||||
|
|
||||||
Config::LauncherSettings::LauncherSettings()
|
Config::LauncherSettings::LauncherSettings()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -15,27 +20,6 @@ Config::LauncherSettings::~LauncherSettings()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList Config::LauncherSettings::values(const QString &key, Qt::MatchFlags flags)
|
|
||||||
{
|
|
||||||
QMap<QString, QString> settings = SettingsBase::getSettings();
|
|
||||||
|
|
||||||
if (flags == Qt::MatchExactly)
|
|
||||||
return settings.values(key);
|
|
||||||
|
|
||||||
QStringList result;
|
|
||||||
|
|
||||||
if (flags == Qt::MatchStartsWith) {
|
|
||||||
QStringList keys = settings.keys();
|
|
||||||
|
|
||||||
foreach (const QString ¤tKey, keys) {
|
|
||||||
if (currentKey.startsWith(key))
|
|
||||||
result.append(settings.value(currentKey));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList Config::LauncherSettings::subKeys(const QString &key)
|
QStringList Config::LauncherSettings::subKeys(const QString &key)
|
||||||
{
|
{
|
||||||
QMap<QString, QString> settings = SettingsBase::getSettings();
|
QMap<QString, QString> settings = SettingsBase::getSettings();
|
||||||
|
@ -66,6 +50,7 @@ QStringList Config::LauncherSettings::subKeys(const QString &key)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Config::LauncherSettings::writeFile(QTextStream &stream)
|
bool Config::LauncherSettings::writeFile(QTextStream &stream)
|
||||||
{
|
{
|
||||||
QString sectionPrefix;
|
QString sectionPrefix;
|
||||||
|
@ -104,3 +89,110 @@ bool Config::LauncherSettings::writeFile(QTextStream &stream)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList Config::LauncherSettings::getContentLists()
|
||||||
|
{
|
||||||
|
return subKeys(QString(sContentListsSectionPrefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Config::LauncherSettings::makeContentListKey(const QString& contentListName)
|
||||||
|
{
|
||||||
|
return QString(sContentListsSectionPrefix) + contentListName + QString(sContentListSuffix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::LauncherSettings::setContentList(const GameSettings& gameSettings)
|
||||||
|
{
|
||||||
|
// obtain content list from game settings (if present)
|
||||||
|
const QStringList files(gameSettings.getContentList());
|
||||||
|
|
||||||
|
// if any existing profile in launcher matches the content list, make that profile the default
|
||||||
|
foreach(const QString &listName, getContentLists())
|
||||||
|
{
|
||||||
|
if (isEqual(files, getContentListFiles(listName)))
|
||||||
|
{
|
||||||
|
setCurrentContentListName(listName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// otherwise, add content list
|
||||||
|
QString newContentListName(makeNewContentListName());
|
||||||
|
setCurrentContentListName(newContentListName);
|
||||||
|
setContentList(newContentListName, files);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::LauncherSettings::removeContentList(const QString &contentListName)
|
||||||
|
{
|
||||||
|
remove(makeContentListKey(contentListName));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::LauncherSettings::setCurrentContentListName(const QString &contentListName)
|
||||||
|
{
|
||||||
|
remove(QString(sCurrentContentListKey));
|
||||||
|
setValue(QString(sCurrentContentListKey), contentListName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::LauncherSettings::setContentList(const QString& contentListName, const QStringList& fileNames)
|
||||||
|
{
|
||||||
|
removeContentList(contentListName);
|
||||||
|
QString key = makeContentListKey(contentListName);
|
||||||
|
foreach(const QString& fileName, fileNames)
|
||||||
|
{
|
||||||
|
setMultiValue(key, fileName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Config::LauncherSettings::getCurrentContentListName() const
|
||||||
|
{
|
||||||
|
return value(QString(sCurrentContentListKey));
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList Config::LauncherSettings::getContentListFiles(const QString& contentListName) const
|
||||||
|
{
|
||||||
|
// QMap returns multiple rows in LIFO order, so need to reverse
|
||||||
|
return reverse(getSettings().values(makeContentListKey(contentListName)));
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList Config::LauncherSettings::reverse(const QStringList& toReverse)
|
||||||
|
{
|
||||||
|
QStringList result;
|
||||||
|
result.reserve(toReverse.size());
|
||||||
|
std::reverse_copy(toReverse.begin(), toReverse.end(), std::back_inserter(result));
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::LauncherSettings::isEqual(const QStringList& list1, const QStringList& list2)
|
||||||
|
{
|
||||||
|
if (list1.count() != list2.count())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < list1.count(); ++i)
|
||||||
|
{
|
||||||
|
if (list1.at(i) != list2.at(i))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if get here, lists are same
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString Config::LauncherSettings::makeNewContentListName()
|
||||||
|
{
|
||||||
|
// basically, use date and time as the name e.g. YYYY-MM-DDThh:mm:ss
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm * timeinfo;
|
||||||
|
|
||||||
|
time(&rawtime);
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
int base = 10;
|
||||||
|
QChar zeroPad('0');
|
||||||
|
return QString("%1-%2-%3T%4:%5:%6")
|
||||||
|
.arg(timeinfo->tm_year + 1900, 4).arg(timeinfo->tm_mon + 1, 2, base, zeroPad).arg(timeinfo->tm_mday, 2, base, zeroPad)
|
||||||
|
.arg(timeinfo->tm_hour, 2, base, zeroPad).arg(timeinfo->tm_min, 2, base, zeroPad).arg(timeinfo->tm_sec, 2, base, zeroPad);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define LAUNCHERSETTINGS_HPP
|
#define LAUNCHERSETTINGS_HPP
|
||||||
|
|
||||||
#include "settingsbase.hpp"
|
#include "settingsbase.hpp"
|
||||||
|
#include "gamesettings.hpp"
|
||||||
|
|
||||||
namespace Config
|
namespace Config
|
||||||
{
|
{
|
||||||
|
@ -11,11 +12,49 @@ namespace Config
|
||||||
LauncherSettings();
|
LauncherSettings();
|
||||||
~LauncherSettings();
|
~LauncherSettings();
|
||||||
|
|
||||||
QStringList subKeys(const QString &key);
|
|
||||||
QStringList values(const QString &key, Qt::MatchFlags flags = Qt::MatchExactly);
|
|
||||||
|
|
||||||
bool writeFile(QTextStream &stream);
|
bool writeFile(QTextStream &stream);
|
||||||
|
|
||||||
|
/// \return names of all Content Lists in the launcher's .cfg file.
|
||||||
|
QStringList getContentLists();
|
||||||
|
|
||||||
|
/// Set initally selected content list to match values from openmw.cfg, creating if necessary
|
||||||
|
void setContentList(const GameSettings& gameSettings);
|
||||||
|
|
||||||
|
/// Create a Content List (or replace if it already exists)
|
||||||
|
void setContentList(const QString& contentListName, const QStringList& fileNames);
|
||||||
|
|
||||||
|
void removeContentList(const QString &contentListName);
|
||||||
|
|
||||||
|
void setCurrentContentListName(const QString &contentListName);
|
||||||
|
|
||||||
|
QString getCurrentContentListName() const;
|
||||||
|
|
||||||
|
QStringList getContentListFiles(const QString& contentListName) const;
|
||||||
|
|
||||||
|
/// \return new list that is reversed order of input
|
||||||
|
static QStringList reverse(const QStringList& toReverse);
|
||||||
|
|
||||||
|
static const char sLauncherConfigFileName[];
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
/// \return key to use to get/set the files in the specified Content List
|
||||||
|
static QString makeContentListKey(const QString& contentListName);
|
||||||
|
|
||||||
|
/// \return true if both lists are same
|
||||||
|
static bool isEqual(const QStringList& list1, const QStringList& list2);
|
||||||
|
|
||||||
|
static QString makeNewContentListName();
|
||||||
|
|
||||||
|
QStringList subKeys(const QString &key);
|
||||||
|
|
||||||
|
/// name of entry in launcher.cfg that holds name of currently selected Content List
|
||||||
|
static const char sCurrentContentListKey[];
|
||||||
|
|
||||||
|
/// section of launcher.cfg holding the Content Lists
|
||||||
|
static const char sContentListsSectionPrefix[];
|
||||||
|
|
||||||
|
static const char sContentListSuffix[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
#endif // LAUNCHERSETTINGS_HPP
|
#endif // LAUNCHERSETTINGS_HPP
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace Config
|
||||||
SettingsBase() { mMultiValue = false; }
|
SettingsBase() { mMultiValue = false; }
|
||||||
~SettingsBase() {}
|
~SettingsBase() {}
|
||||||
|
|
||||||
inline QString value(const QString &key, const QString &defaultValue = QString())
|
inline QString value(const QString &key, const QString &defaultValue = QString()) const
|
||||||
{
|
{
|
||||||
return mSettings.value(key).isEmpty() ? defaultValue : mSettings.value(key);
|
return mSettings.value(key).isEmpty() ? defaultValue : mSettings.value(key);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ namespace Config
|
||||||
mSettings.remove(key);
|
mSettings.remove(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map getSettings() {return mSettings;}
|
Map getSettings() const {return mSettings;}
|
||||||
|
|
||||||
bool readFile(QTextStream &stream)
|
bool readFile(QTextStream &stream)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<enum>Qt::NoFocus</enum>
|
<enum>Qt::NoFocus</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>Profile</string>
|
<string>Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="flat">
|
<property name="flat">
|
||||||
<bool>false</bool>
|
<bool>false</bool>
|
||||||
|
@ -69,10 +69,10 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="newProfileButton">
|
<widget class="QToolButton" name="newProfileButton">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>New Profile</string>
|
<string>New Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&New Profile</string>
|
<string>&New Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="autoRaise">
|
<property name="autoRaise">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
@ -82,10 +82,10 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QToolButton" name="deleteProfileButton">
|
<widget class="QToolButton" name="deleteProfileButton">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Delete Profile</string>
|
<string>Delete Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Delete Profile</string>
|
<string>Delete Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+D</string>
|
<string>Ctrl+D</string>
|
||||||
|
@ -106,10 +106,10 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>New Profile</string>
|
<string>New Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>New Profile</string>
|
<string>New Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
<property name="shortcut">
|
||||||
<string>Ctrl+N</string>
|
<string>Ctrl+N</string>
|
||||||
|
@ -125,10 +125,10 @@
|
||||||
</iconset>
|
</iconset>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Delete Profile</string>
|
<string>Delete Content List</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Delete Profile</string>
|
<string>Delete Content List</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="checkAction">
|
<action name="checkAction">
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
</string>
|
</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Current Profile:</string>
|
<string>Current Content List:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in a new issue