]>
git.saurik.com Git - wxWidgets.git/blob - src/palmos/prefconf.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/prefconf.cpp
3 // Purpose: wxPrefConfig implementation
4 // Author: Wlodzimierz ABX Skiba
8 // Copyright: (c) Wlodzimierz Skiba
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/string.h"
23 #if wxUSE_CONFIG && wxUSE_CONFIG_NATIVE
25 #include "wx/config.h"
27 // ============================================================================
29 // ============================================================================
33 http://www.palmos.com/dev/support/docs/protein_books/System_Management/PreferenceConcepts.html
35 This wxPrefConfig class is a wxConfig wrapper around PalmOS Preferences
36 functionality. Preferences allow to write any structure into its database so
37 wxPrefConfig writes there all entries of single group into one Preference.
38 To optimize read/write operations value of preference is cached. Cache is filled
39 after each change of the path (including using path to group names in all
40 operations) and it is flushed on destructor, any path change on or purpose
45 wxCONFIG_USE_LOCAL_FILE => store config in "saved" preferences database
46 (not to be backed up during a HotSync operation)
47 wxCONFIG_USE_GLOBAL_FILE => store config in "unsaved" preferences database
48 (backed up during a HotSync operation)
51 Each Preference is an array of chars. First unsigned char describes
52 number N of chars used for Preference size. Next N chars (string) contains
53 length of rest of Preference. Preference consists in serie of entries which
54 should be read in loop until in reaches end of Preference.
56 Each entry is an set of chars with following structure:
57 1. name (null terminated)
58 2. type (single char): b,s,g,l,d (see value)
60 - for type="b" (bool) it os "0" or "1"
61 - for type="s" (string) it is null terminated set of chars
62 - for type="g" (subgroup) as for "s" but string is converted to
63 uint16_t for id parameter of ::PrefGetAppPreferences()
64 - for type="l" (long) as for "s" but string is converted to long
65 - for type="d" (double) as for "s" but string is converted to double
68 So all together first Read in group needs 3 reading from Preference:
69 1. take the length N of length
70 2. take the length M of the group content
71 3. take the group content
72 and all it is in single Preference to not overload Preferences database.
73 As long as each next Read/Write is performed in the same group then none
74 access to Preferences is performed. Flushing needs only single writing to
75 databease because all 3 parts of Preference can be prepared in memory.
77 NOTE: wxPrefConfig can read/write only its own entries. It is impossible to
78 know structures of Preferences of other non wxW applications.
82 // ----------------------------------------------------------------------------
84 // ----------------------------------------------------------------------------
86 wxPrefConfig::wxPrefConfig(const wxString
& appName
, const wxString
& vendorName
,
87 const wxString
& strLocal
, const wxString
& strGlobal
,
89 : wxConfigBase(appName
, vendorName
, strLocal
, strGlobal
, style
)
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 void wxPrefConfig::SetPath(const wxString
& strPath
)
101 // ----------------------------------------------------------------------------
102 // enumeration (works only with current group)
103 // ----------------------------------------------------------------------------
105 bool wxPrefConfig::GetFirstGroup(wxString
& str
, long& lIndex
) const
109 bool wxPrefConfig::GetNextGroup(wxString
& str
, long& lIndex
) const
115 bool wxPrefConfig::GetFirstEntry(wxString
& str
, long& lIndex
) const
121 bool wxPrefConfig::GetNextEntry(wxString
& str
, long& lIndex
) const
127 size_t wxPrefConfig::GetNumberOfEntries(bool WXUNUSED(bRecursive
)) const
133 size_t wxPrefConfig::GetNumberOfGroups(bool WXUNUSED(bRecursive
)) const
139 // ----------------------------------------------------------------------------
140 // tests for existence
141 // ----------------------------------------------------------------------------
143 bool wxPrefConfig::HasGroup(const wxString
& key
) const
149 bool wxPrefConfig::HasEntry(const wxString
& key
) const
155 wxConfigBase::EntryType
wxPrefConfig::GetEntryType(const wxString
& key
) const
158 return wxConfigBase::Type_Unknown
;
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 bool wxPrefConfig::DoReadString(const wxString
& key
, wxString
*pStr
) const
171 // this exactly reproduces the string version above except for ExpandEnvVars(),
172 // we really should avoid this code duplication somehow...
174 bool wxPrefConfig::DoReadLong(const wxString
& key
, long *plResult
) const
180 bool wxPrefConfig::DoWriteString(const wxString
& key
, const wxString
& szValue
)
186 bool wxPrefConfig::DoWriteLong(const wxString
& key
, long lValue
)
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
196 bool wxPrefConfig::RenameEntry(const wxString
& oldName
, const wxString
& newName
)
202 bool wxPrefConfig::RenameGroup(const wxString
& oldName
, const wxString
& newName
)
208 // ----------------------------------------------------------------------------
210 // ----------------------------------------------------------------------------
212 bool wxPrefConfig::DeleteEntry(const wxString
& value
, bool bGroupIfEmptyAlso
)
218 bool wxPrefConfig::DeleteGroup(const wxString
& key
)
224 bool wxPrefConfig::DeleteAll()
230 #endif // wxUSE_CONFIG && wxUSE_CONFIG_NATIVE