OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gamesettings.hpp
Go to the documentation of this file.
1 #ifndef GAMESETTINGS_HPP
2 #define GAMESETTINGS_HPP
3 
4 #include <QTextStream>
5 #include <QStringList>
6 #include <QString>
7 #include <QFile>
8 #include <QMap>
9 
10 #include <boost/filesystem/path.hpp>
11 
12 namespace Files
13 {
14  typedef std::vector<boost::filesystem::path> PathContainer;
15  struct ConfigurationManager;
16 }
17 
18 namespace Config
19 {
21  {
22  public:
24  ~GameSettings();
25 
26  inline QString value(const QString &key, const QString &defaultValue = QString())
27  {
28  return mSettings.value(key).isEmpty() ? defaultValue : mSettings.value(key);
29  }
30 
31 
32  inline void setValue(const QString &key, const QString &value)
33  {
34  mSettings.insert(key, value);
35  mUserSettings.insert(key, value);
36  }
37 
38  inline void setMultiValue(const QString &key, const QString &value)
39  {
40  QStringList values = mSettings.values(key);
41  if (!values.contains(value))
42  mSettings.insertMulti(key, value);
43 
44  values = mUserSettings.values(key);
45  if (!values.contains(value))
46  mUserSettings.insertMulti(key, value);
47  }
48 
49  inline void remove(const QString &key)
50  {
51  mSettings.remove(key);
52  mUserSettings.remove(key);
53  }
54 
55  inline QStringList getDataDirs() { return mDataDirs; }
56 
57  inline void removeDataDir(const QString &dir) { if(!dir.isEmpty()) mDataDirs.removeAll(dir); }
58  inline void addDataDir(const QString &dir) { if(!dir.isEmpty()) mDataDirs.append(dir); }
59  inline QString getDataLocal() {return mDataLocal; }
60 
61  bool hasMaster();
62 
63  QStringList values(const QString &key, const QStringList &defaultValues = QStringList()) const;
64 
65  bool readFile(QTextStream &stream);
66  bool readFile(QTextStream &stream, QMap<QString, QString> &settings);
67  bool readUserFile(QTextStream &stream);
68 
69  bool writeFile(QTextStream &stream);
70  bool writeFileWithComments(QFile &file);
71 
72  void setContentList(const QStringList& fileNames);
73  QStringList getContentList() const;
74 
75  void clear();
76 
77  private:
79 
80  void validatePaths();
83 
84  QStringList mDataDirs;
85  QString mDataLocal;
86 
87  static const char sContentKey[];
88 
89  bool isOrderedLine(const QString& line) const;
90  };
91 }
92 #endif // GAMESETTINGS_HPP
QStringList getDataDirs()
Definition: gamesettings.hpp:55
void setContentList(const QStringList &fileNames)
Definition: gamesettings.cpp:442
bool readFile(QTextStream &stream)
Definition: gamesettings.cpp:94
QString mDataLocal
Definition: gamesettings.hpp:85
void setMultiValue(const QString &key, const QString &value)
Definition: gamesettings.hpp:38
void addDataDir(const QString &dir)
Definition: gamesettings.hpp:58
QMap< QString, QString > mUserSettings
Definition: gamesettings.hpp:82
QStringList mDataDirs
Definition: gamesettings.hpp:84
Definition: configurationmanager.hpp:20
QStringList values(const QString &key, const QStringList &defaultValues=QStringList()) const
Definition: gamesettings.cpp:87
Files::ConfigurationManager & mCfgMgr
Definition: gamesettings.hpp:78
static const char sContentKey[]
Definition: gamesettings.hpp:87
bool readUserFile(QTextStream &stream)
Definition: gamesettings.cpp:99
~GameSettings()
Definition: gamesettings.cpp:38
bool isOrderedLine(const QString &line) const
Definition: gamesettings.cpp:177
void validatePaths()
Definition: gamesettings.cpp:42
QString value(const QString &key, const QString &defaultValue=QString())
Definition: gamesettings.hpp:26
GameSettings(Files::ConfigurationManager &cfg)
Definition: gamesettings.cpp:33
void setValue(const QString &key, const QString &value)
Definition: gamesettings.hpp:32
bool hasMaster()
Definition: gamesettings.cpp:428
bool writeFile(QTextStream &stream)
Definition: gamesettings.cpp:146
bool writeFileWithComments(QFile &file)
Definition: gamesettings.cpp:201
QStringList getContentList() const
Definition: gamesettings.cpp:451
QMap< QString, QString > mSettings
Definition: gamesettings.hpp:81
std::vector< boost::filesystem::path > PathContainer
Definition: gamesettings.hpp:14
void clear()
Definition: gamesettings.cpp:457
void removeDataDir(const QString &dir)
Definition: gamesettings.hpp:57
Definition: gamesettings.hpp:20
QString getDataLocal()
Definition: gamesettings.hpp:59