mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-21 10:23:52 +00:00
Implemented UserSettings as a singleton.
This commit is contained in:
parent
d0b23a4786
commit
88df3b980f
5 changed files with 21 additions and 11 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include "view/doc/viewmanager.hpp"
|
#include "view/doc/viewmanager.hpp"
|
||||||
#include "view/doc/startup.hpp"
|
#include "view/doc/startup.hpp"
|
||||||
#include "view/doc/filedialog.hpp"
|
#include "view/doc/filedialog.hpp"
|
||||||
|
#include "model/settings/usersettings.hpp"
|
||||||
|
|
||||||
namespace CS
|
namespace CS
|
||||||
{
|
{
|
||||||
|
@ -23,7 +24,6 @@ namespace CS
|
||||||
FileDialog mFileDialog;
|
FileDialog mFileDialog;
|
||||||
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
|
|
||||||
void setupDataFiles();
|
void setupDataFiles();
|
||||||
|
|
||||||
// not implemented
|
// not implemented
|
||||||
|
|
|
@ -30,9 +30,9 @@ namespace boost
|
||||||
#endif /* (BOOST_VERSION <= 104600) */
|
#endif /* (BOOST_VERSION <= 104600) */
|
||||||
|
|
||||||
|
|
||||||
CSMSettings::UserSettings::UserSettings(Files::ConfigurationManager &cfg)
|
CSMSettings::UserSettings::UserSettings()
|
||||||
: mCfgMgr(cfg)
|
|
||||||
{
|
{
|
||||||
|
mUserSettingsInstance = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSMSettings::UserSettings::~UserSettings()
|
CSMSettings::UserSettings::~UserSettings()
|
||||||
|
|
|
@ -17,18 +17,29 @@ class QFile;
|
||||||
|
|
||||||
namespace CSMSettings {
|
namespace CSMSettings {
|
||||||
|
|
||||||
class UserSettings
|
struct UserSettings
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UserSettings(Files::ConfigurationManager &cfg);
|
|
||||||
~UserSettings();
|
static UserSettings &instance()
|
||||||
|
{
|
||||||
|
static UserSettings instance;
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
QFile *openFile (const QString &);
|
QFile *openFile (const QString &);
|
||||||
bool writeFile(QFile *file, QMap<QString, SettingList *> §ions);
|
bool writeFile(QFile *file, QMap<QString, SettingList *> §ions);
|
||||||
void getSettings (QTextStream &stream, SectionMap &settings);
|
void getSettings (QTextStream &stream, SectionMap &settings);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Files::ConfigurationManager &mCfgMgr;
|
|
||||||
|
UserSettings *mUserSettingsInstance;
|
||||||
|
UserSettings();
|
||||||
|
~UserSettings();
|
||||||
|
|
||||||
|
UserSettings (UserSettings const &); //not implemented
|
||||||
|
void operator= (UserSettings const &); //not implemented
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) :
|
CSVSettings::UserSettingsDialog::UserSettingsDialog(QMainWindow *parent) :
|
||||||
QMainWindow (parent), mUserSettings (mCfgMgr), mStackedWidget (0)
|
QMainWindow (parent), mStackedWidget (0)
|
||||||
{
|
{
|
||||||
setWindowTitle(QString::fromUtf8 ("User Settings"));
|
setWindowTitle(QString::fromUtf8 ("User Settings"));
|
||||||
buildPages();
|
buildPages();
|
||||||
|
@ -135,7 +135,7 @@ CSMSettings::SectionMap CSVSettings::UserSettingsDialog::loadSettings ()
|
||||||
QTextStream stream(&file);
|
QTextStream stream(&file);
|
||||||
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
stream.setCodec(QTextCodec::codecForName("UTF-8"));
|
||||||
|
|
||||||
mUserSettings.getSettings(stream, settingsMap);
|
CSMSettings::UserSettings::instance().getSettings(stream, settingsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
file.close();
|
file.close();
|
||||||
|
@ -154,7 +154,7 @@ void CSVSettings::UserSettingsDialog::writeSettings()
|
||||||
settings [page->objectName()] = page->getSettings();
|
settings [page->objectName()] = page->getSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
mUserSettings.writeFile(mUserSettings.openFile(mPaths.back()), settings);
|
CSMSettings::UserSettings::instance().writeFile(CSMSettings::UserSettings::instance().openFile(mPaths.back()), settings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ namespace CSVSettings {
|
||||||
QStringList mPaths;
|
QStringList mPaths;
|
||||||
QListWidget *mListWidget;
|
QListWidget *mListWidget;
|
||||||
QStackedWidget *mStackedWidget;
|
QStackedWidget *mStackedWidget;
|
||||||
CSMSettings::UserSettings mUserSettings;
|
|
||||||
Files::ConfigurationManager mCfgMgr;
|
Files::ConfigurationManager mCfgMgr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue