OpenMW
apps/launcher/settings/gamesettings.hpp
Go to the documentation of this file.
00001 #ifndef GAMESETTINGS_HPP
00002 #define GAMESETTINGS_HPP
00003 
00004 #include <QTextStream>
00005 #include <QStringList>
00006 #include <QString>
00007 #include <QMap>
00008 
00009 #include <boost/filesystem/path.hpp>
00010 
00011 namespace Files
00012 {
00013   typedef std::vector<boost::filesystem::path> PathContainer;
00014   struct ConfigurationManager;
00015 }
00016 
00017 namespace Launcher
00018 {
00019     class GameSettings
00020     {
00021     public:
00022         GameSettings(Files::ConfigurationManager &cfg);
00023         ~GameSettings();
00024 
00025         inline QString value(const QString &key, const QString &defaultValue = QString())
00026         {
00027             return mSettings.value(key).isEmpty() ? defaultValue : mSettings.value(key);
00028         }
00029 
00030 
00031         inline void setValue(const QString &key, const QString &value)
00032         {
00033             mSettings.insert(key, value);
00034             mUserSettings.insert(key, value);
00035         }
00036 
00037         inline void setMultiValue(const QString &key, const QString &value)
00038         {
00039             QStringList values = mSettings.values(key);
00040             if (!values.contains(value))
00041                 mSettings.insertMulti(key, value);
00042 
00043             values = mUserSettings.values(key);
00044             if (!values.contains(value))
00045                 mUserSettings.insertMulti(key, value);
00046         }
00047 
00048         inline void remove(const QString &key)
00049         {
00050             mSettings.remove(key);
00051             mUserSettings.remove(key);
00052         }
00053 
00054         inline QStringList getDataDirs() { return mDataDirs; }
00055         inline void addDataDir(const QString &dir) { if(!dir.isEmpty()) mDataDirs.append(dir); }
00056         inline QString getDataLocal() {return mDataLocal; }
00057 
00058         bool hasMaster();
00059 
00060         QStringList values(const QString &key, const QStringList &defaultValues = QStringList());
00061 
00062         bool readFile(QTextStream &stream);
00063         bool readFile(QTextStream &stream, QMap<QString, QString> &settings);
00064         bool readUserFile(QTextStream &stream);
00065 
00066         bool writeFile(QTextStream &stream);
00067 
00068     private:
00069         Files::ConfigurationManager &mCfgMgr;
00070 
00071         void validatePaths();
00072         QMap<QString, QString> mSettings;
00073         QMap<QString, QString> mUserSettings;
00074 
00075         QStringList mDataDirs;
00076         QString mDataLocal;
00077     };
00078 }
00079 #endif // GAMESETTINGS_HPP