Updated German translation
[dasher.git] / Src / DasherCore / XmlSettingsStore.h
blob0d6ec046adf8a14aa64fceddf46ceb999c01990e
1 #ifndef XML_SETTING_STORE_H_
2 #define XML_SETTING_STORE_H_
4 #ifdef HAVE_CONFIG_H
5 #include <config.h>
6 #endif
8 #include <string>
9 #include <map>
11 #include "SettingsStore.h"
12 #include "AbstractXMLParser.h"
14 class CFileUtils;
16 namespace Dasher {
17 // This class is not thread-safe.
18 class XmlSettingsStore : public Dasher::CSettingsStore, public AbstractXMLParser {
19 public:
20 XmlSettingsStore(const std::string& filename, CFileUtils* fileUtils, CMessageDisplay* pDisplay);
21 ~XmlSettingsStore() override = default;
22 // Load the XML file and fills in the default values needed.
23 // Returns true on success.
24 void Load();
25 // Saves the XML file, returns true on success.
26 bool Save();
28 private:
29 bool LoadSetting(const std::string& Key, bool* Value) override;
30 bool LoadSetting(const std::string& Key, long* Value) override;
31 bool LoadSetting(const std::string& Key, std::string* Value) override;
33 void SaveSetting(const std::string& Key, bool Value) override;
34 void SaveSetting(const std::string& Key, long Value) override;
35 void SaveSetting(const std::string& Key, const std::string& Value) override;
37 void XmlStartHandler(const XML_Char* name, const XML_Char** atts) override;
38 virtual void XmlEndHandler(const XML_Char* name) override;
40 // Parses the tag attributes expecting exactly one 'value' and one 'name'
41 // attribute.
42 bool GetNameAndValue(const XML_Char** attributes, std::string* name,
43 std::string* value);
45 // Save if the mode is 'SAVE_IMMEDIATELY', otherwise just set 'modified_' to
46 // true.
47 void SaveIfNeeded();
49 enum Mode {
50 // Save each time 'SaveSetting' is called.
51 SAVE_IMMEDIATELY,
52 // Save only when 'Save' is called.
53 EXPLICIT_SAVE
56 Mode mode_ = EXPLICIT_SAVE;
57 std::string filename_;
58 CFileUtils* fileutils_;
59 bool modified_ = false;
60 std::map<std::string, bool> boolean_settings_;
61 std::map<std::string, long> long_settings_;
62 std::map<std::string, std::string> string_settings_;
65 } // namespace Dasher
67 #endif // XML_SETTING_STORE_H_