summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/profile.cpp49
-rw-r--r--src/profile.h31
-rw-r--r--src/profilesdialog.cpp13
-rw-r--r--src/profilesdialog.h3
-rw-r--r--src/profilesdialog.ui10
5 files changed, 94 insertions, 12 deletions
diff --git a/src/profile.cpp b/src/profile.cpp
index d71b5a0f..9106cebe 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -72,6 +72,8 @@ Profile::Profile(const QString &name, IPluginGame const *gamePlugin, bool useDef
QString profilesDir = Settings::instance().getProfileDirectory();
QDir profileBase(profilesDir);
+ m_Settings = new QSettings(profileBase.absoluteFilePath("settings.ini"));
+
QString fixedName = name;
if (!fixDirectoryName(fixedName)) {
throw MyException(tr("invalid profile name %1").arg(name));
@@ -113,19 +115,18 @@ Profile::Profile(const QDir &directory, IPluginGame const *gamePlugin)
{
assert(gamePlugin != nullptr);
+ m_Settings = new QSettings(directory.absoluteFilePath("settings.ini"),
+ QSettings::IniFormat);
+
if (!QFile::exists(m_Directory.filePath("modlist.txt"))) {
qWarning("missing modlist.txt in %s", qPrintable(directory.path()));
touchFile(m_Directory.filePath("modlist.txt"));
}
- IPluginGame::ProfileSettings settings = IPluginGame::CONFIGURATION
- | IPluginGame::MODS
+ IPluginGame::ProfileSettings settings = IPluginGame::MODS
| IPluginGame::SAVEGAMES;
gamePlugin->initializeProfile(directory, settings);
- if (!QFile::exists(getIniFileName())) {
- reportError(QObject::tr("\"%1\" is missing or inaccessible").arg(getIniFileName()));
- }
refreshModStatus();
}
@@ -136,12 +137,15 @@ Profile::Profile(const Profile &reference)
, m_GamePlugin(reference.m_GamePlugin)
{
+ m_Settings = new QSettings(m_Directory.absoluteFilePath("settings.ini"),
+ QSettings::IniFormat);
refreshModStatus();
}
Profile::~Profile()
{
+ delete m_Settings;
m_ModListWriter.writeImmediately(true);
}
@@ -655,6 +659,30 @@ bool Profile::enableLocalSaves(bool enable)
return true;
}
+bool Profile::localSettingsEnabled() const
+{
+ return m_Directory.exists(getIniFileName());
+}
+
+bool Profile::enableLocalSettings(bool enable)
+{
+ // TODO: this currently assumes game settings are stored in an ini file.
+ // This shall become very interesting when a game stores its settings in the
+ // registry
+ QString backupFile = getIniFileName() + "_";
+ if (enable) {
+ if (m_Directory.exists(backupFile)) {
+ shellRename(backupFile, getIniFileName());
+ } else {
+ IPluginGame *game = qApp->property("managed_game").value<IPluginGame *>();
+ game->initializeProfile(m_Directory, IPluginGame::CONFIGURATION);
+ }
+ } else {
+ shellRename(getIniFileName(), backupFile);
+ }
+
+ return true;
+}
QString Profile::getModlistFileName() const
{
@@ -714,3 +742,14 @@ void Profile::rename(const QString &newName)
m_Directory = profileDir.absoluteFilePath(newName);
}
+QVariant Profile::setting(const QString &section, const QString &name,
+ const QVariant &fallback)
+{
+ return m_Settings->value(section + "/" + name, fallback);
+}
+
+void Profile::storeSetting(const QString &section, const QString &name,
+ const QVariant &value)
+{
+ m_Settings->setValue(section + "/" + name, value);
+}
diff --git a/src/profile.h b/src/profile.h
index 87dd91a5..996e561f 100644
--- a/src/profile.h
+++ b/src/profile.h
@@ -29,6 +29,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QDir>
#include <QObject>
#include <QString>
+#include <QSettings>
#include <boost/shared_ptr.hpp>
@@ -112,20 +113,32 @@ public:
/**
* @return true if this profile uses local save games
*/
- bool localSavesEnabled() const;
+ virtual bool localSavesEnabled() const override;
/**
* @brief enables or disables the use of local save games for this profile
- * disabling this does not delete exising local saves but they will not be visible
- * in the game
+ * when disabling the user will be asked if he wants to remove the save games
+ * in the profile
* @param enable if true, local saves are enabled, otherewise they are disabled
*/
bool enableLocalSaves(bool enable);
/**
+ * @return true if this profile uses local ini files
+ */
+ virtual bool localSettingsEnabled() const override;
+
+ /**
+ * @brief enables or disables the use of local ini files for this profile
+ * disabling this does not delete existing ini files but the global ones will be used
+ * @param enable
+ */
+ bool enableLocalSettings(bool enable);
+
+ /**
* @return name of the profile (this is identical to its directory name)
**/
- QString name() const { return m_Directory.dirName(); }
+ virtual QString name() const override { return m_Directory.dirName(); }
/**
* @return the path of the plugins file in this profile
@@ -267,6 +280,12 @@ public:
void dumpModStatus() const;
+ QVariant setting(const QString &section, const QString &name,
+ const QVariant &fallback = QVariant());
+
+ void storeSetting(const QString &section, const QString &name,
+ const QVariant &value);
+
signals:
/**
@@ -311,7 +330,9 @@ private:
QDir m_Directory;
- MOBase::IPluginGame const * const m_GamePlugin;
+ QSettings *m_Settings;
+
+ const MOBase::IPluginGame *m_GamePlugin;
mutable QByteArray m_LastModlistHash;
std::vector<ModStatus> m_ModStatus;
diff --git a/src/profilesdialog.cpp b/src/profilesdialog.cpp
index 40f01f0e..04c1876d 100644
--- a/src/profilesdialog.cpp
+++ b/src/profilesdialog.cpp
@@ -58,7 +58,6 @@ ProfilesDialog::ProfilesDialog(const QString &profileName, MOBase::IPluginGame c
QDir profilesDir(Settings::instance().getProfileDirectory());
profilesDir.setFilter(QDir::AllDirs | QDir::NoDotAndDotDot);
- m_ProfilesList = findChild<QListWidget*>("profilesList");
QDirIterator profileIter(profilesDir);
@@ -322,7 +321,17 @@ void ProfilesDialog::on_localSavesBox_stateChanged(int state)
void ProfilesDialog::on_transferButton_clicked()
{
- const Profile::Ptr currentProfile = m_ProfilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
+ const Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
TransferSavesDialog transferDialog(*currentProfile, m_Game, this);
transferDialog.exec();
}
+
+void ProfilesDialog::on_localIniFilesBox_stateChanged(int state)
+{
+ Profile::Ptr currentProfile = ui->profilesList->currentItem()->data(Qt::UserRole).value<Profile::Ptr>();
+
+ if (!currentProfile->enableLocalSettings(state == Qt::Checked)) {
+ // revert checkbox-state
+ ui->localIniFilesBox->setChecked(state != Qt::Checked);
+ }
+}
diff --git a/src/profilesdialog.h b/src/profilesdialog.h
index 0e79b94b..cab25f6a 100644
--- a/src/profilesdialog.h
+++ b/src/profilesdialog.h
@@ -61,6 +61,9 @@ protected:
virtual void showEvent(QShowEvent *event);
+private slots:
+ void on_localIniFilesBox_stateChanged(int state);
+
private:
QListWidgetItem *addItem(const QString &name);
diff --git a/src/profilesdialog.ui b/src/profilesdialog.ui
index fe03f466..9b4e7e62 100644
--- a/src/profilesdialog.ui
+++ b/src/profilesdialog.ui
@@ -46,6 +46,16 @@ p, li { white-space: pre-wrap; }
</widget>
</item>
<item>
+ <widget class="QCheckBox" name="localIniFilesBox">
+ <property name="text">
+ <string>Local Game Settings</string>
+ </property>
+ <property name="checked">
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QCheckBox" name="invalidationBox">
<property name="toolTip">
<string>This ensures data files from mods are actually used. You want to enable this unless you use a different tool for Archive Invalidation.</string>