File: FileConfig.h

package info (click to toggle)
audacity 3.2.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 106,704 kB
  • sloc: cpp: 277,038; ansic: 73,623; lisp: 7,761; python: 3,305; sh: 2,715; perl: 821; xml: 275; makefile: 119
file content (103 lines) | stat: -rw-r--r-- 3,783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**********************************************************************

  Audacity: A Digital Audio Editor

  FileConfig.h

  Leland Lucius

**********************************************************************/

#ifndef __AUDACITY_WIDGETS_FILECONFIG__
#define __AUDACITY_WIDGETS_FILECONFIG__

#include <memory>

#include <wx/defs.h>
#include <wx/fileconf.h>
#include "Identifier.h"

class PREFERENCES_API FileConfig : public wxConfigBase
{
public:
   FileConfig(const wxString& appName = wxEmptyString,
              const wxString& vendorName = wxEmptyString,
              const wxString& localFilename = wxEmptyString,
              const wxString& globalFilename = wxEmptyString,
              long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE,
              const wxMBConv& conv = wxConvAuto());
   void Init();
   virtual ~FileConfig();

   virtual void SetPath(const wxString& strPath) wxOVERRIDE;
   virtual const wxString& GetPath() const wxOVERRIDE;
   virtual bool GetFirstGroup(wxString& str, long& lIndex) const wxOVERRIDE;
   virtual bool GetNextGroup(wxString& str, long& lIndex) const wxOVERRIDE;
   virtual bool GetFirstEntry(wxString& str, long& lIndex) const wxOVERRIDE;
   virtual bool GetNextEntry(wxString& str, long& lIndex) const wxOVERRIDE;
   virtual size_t GetNumberOfEntries(bool bRecursive = false) const wxOVERRIDE;
   virtual size_t GetNumberOfGroups(bool bRecursive = false) const wxOVERRIDE;
   virtual bool HasGroup(const wxString& strName) const wxOVERRIDE;
   virtual bool HasEntry(const wxString& strName) const wxOVERRIDE;
   virtual bool Flush(bool bCurrentOnly = false) wxOVERRIDE;
   virtual bool RenameEntry(const wxString& oldName, const wxString& newName) wxOVERRIDE;
   virtual bool RenameGroup(const wxString& oldName, const wxString& newName) wxOVERRIDE;
   virtual bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = true) wxOVERRIDE;
   virtual bool DeleteGroup(const wxString& key) wxOVERRIDE;
   virtual bool DeleteAll() wxOVERRIDE;

   // Set and Get values of the version major/minor/micro keys in audacity.cfg when Audacity first opens
   void SetVersionKeysInit( int major, int minor, int micro)
   {
      mVersionMajorKeyInit = major;
      mVersionMinorKeyInit = minor;
      mVersionMicroKeyInit = micro;
   }
   void GetVersionKeysInit( int& major, int& minor, int& micro) const
   {
      major = mVersionMajorKeyInit;
      minor = mVersionMinorKeyInit;
      micro = mVersionMicroKeyInit;
   }

protected:
   virtual bool DoReadString(const wxString& key, wxString *pStr) const wxOVERRIDE;
   virtual bool DoReadLong(const wxString& key, long *pl) const wxOVERRIDE;
#if wxUSE_BASE64
   virtual bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const wxOVERRIDE;
#endif // wxUSE_BASE64

   virtual bool DoWriteString(const wxString& key, const wxString& szValue) wxOVERRIDE;
   virtual bool DoWriteLong(const wxString& key, long lValue) wxOVERRIDE;
#if wxUSE_BASE64
   virtual bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf) wxOVERRIDE;
#endif // wxUSE_BASE64

protected:
   //! Override to notify the user of error conditions involving writability of
   //! config files.  Default implementation does nothing
   virtual void Warn();

   const FilePath &GetFilePath() const { return mLocalFilename; }

private:
   const wxString mAppName;
   const wxString mVendorName;
   const wxString mLocalFilename;
   const wxString mGlobalFilename;
   const long mStyle;
   std::unique_ptr<wxMBConv> mConv;

   std::unique_ptr<wxFileConfig> mConfig;

   // values of the version major/minor/micro keys in audacity.cfg
   // when Audacity first opens
   int mVersionMajorKeyInit{};
   int mVersionMinorKeyInit{};
   int mVersionMicroKeyInit{};

   bool mDirty;
};

#endif