MythTV  master
configuration.h
Go to the documentation of this file.
1 // Program Name: configuration.h
3 // Created : Feb. 12, 2007
4 //
5 // Purpose : XML Configuration file Class
6 //
7 // Copyright (c) 2007 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #ifndef __CONFIGURATION_H__
14 #define __CONFIGURATION_H__
15 
16 #include <QDomDocument>
17 #include <QStringList>
18 
19 #include "upnpexp.h"
20 
22 {
23  public:
24 
25  virtual ~Configuration() = default;
26 
27  virtual bool Load ( void ) = 0;
28  virtual bool Save ( void ) = 0;
29 
30  virtual int GetValue( const QString &sSetting, int Default ) = 0;
31  virtual QString GetValue( const QString &sSetting, QString Default ) = 0;
32  virtual bool GetBoolValue( const QString &sSetting, bool Default ) = 0;
33 
34  virtual void SetValue( const QString &sSetting, int value ) = 0;
35  virtual void SetValue( const QString &sSetting, QString value ) = 0;
36  virtual void ClearValue( const QString &sSetting ) = 0;
37  virtual void SetBoolValue( const QString &sSetting, bool value ) = 0;
38 };
39 
40 
42 //
43 // **NOTE: Performance Issue ***
44 //
45 // This class loads an XML file into a QDomDocument. All requests for
46 // getting or setting values navigates the DOM each time. All settings should
47 // only be read/written once if possible.
48 //
50 
52 {
53  protected:
54 
55  QString m_sPath;
56  QString m_sFileName;
57 
58  QDomDocument m_config;
59  QDomNode m_rootNode;
60 
61  QDomNode FindNode( const QString &sName, bool bCreate = false );
62  QDomNode FindNode( QStringList &sParts, QDomNode &curNode, bool bCreate = false );
63 
64  public:
65 
66  explicit XmlConfiguration( const QString &sFileName );
67 
68  virtual ~XmlConfiguration() = default;
69 
70  bool Load ( void ) override; // Configuration
71  bool Save ( void ) override; // Configuration
72 
73  int GetValue( const QString &sSetting, int Default ) override; // Configuration
74  QString GetValue( const QString &sSetting, QString Default ) override; // Configuration
75  bool GetBoolValue( const QString &sSetting, bool Default ) override // Configuration
76  {return static_cast<bool>(GetValue(sSetting, static_cast<int>(Default))); }
77 
78  void SetValue( const QString &sSetting, int value ) override; // Configuration
79  void SetValue( const QString &sSetting, QString value ) override; // Configuration
80  void ClearValue( const QString &sSetting ) override; // Configuration
81  void SetBoolValue( const QString &sSetting, bool value ) override // Configuration
82  {SetValue(sSetting, static_cast<int>(value)); }
83 };
84 
86 //
88 
90 {
91  public:
92 
93  DBConfiguration() = default;
94 
95  virtual ~DBConfiguration() = default;
96 
97  bool Load ( void ) override; // Configuration
98  bool Save ( void ) override; // Configuration
99 
100  int GetValue( const QString &sSetting, int Default ) override; // Configuration
101  QString GetValue( const QString &sSetting, QString Default ) override; // Configuration
102  bool GetBoolValue( const QString &sSetting, bool Default ) override // Configuration
103  {return static_cast<bool>(GetValue(sSetting, static_cast<int>(Default))); }
104 
105  void SetValue( const QString &sSetting, int value ) override; // Configuration
106  void SetValue( const QString &sSetting, QString value ) override; // Configuration
107  void ClearValue( const QString &sSetting ) override; // Configuration
108  void SetBoolValue( const QString &sSetting, bool value ) override // Configuration
109  {SetValue(sSetting, static_cast<int>(value)); }
110 };
111 
112 #endif
113 
bool GetBoolValue(const QString &sSetting, bool Default) override
Definition: configuration.h:75
virtual int GetValue(const QString &sSetting, int Default)=0
virtual void ClearValue(const QString &sSetting)=0
void SetBoolValue(const QString &sSetting, bool value) override
Definition: configuration.h:81
bool GetBoolValue(const QString &sSetting, bool Default) override
virtual bool Load(void)=0
virtual bool Save(void)=0
#define UPNP_PUBLIC
Definition: upnpexp.h:9
QDomNode m_rootNode
Definition: configuration.h:59
QDomDocument m_config
Definition: configuration.h:58
virtual void SetValue(const QString &sSetting, int value)=0
void SetBoolValue(const QString &sSetting, bool value) override