]>
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "prefconf.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
24 #include "wx/string.h"
27 #if wxUSE_CONFIG && wxUSE_CONFIG_NATIVE
29 #include "wx/config.h"
31 // ============================================================================
33 // ============================================================================
37 http://www.palmos.com/dev/support/docs/protein_books/System_Management/PreferenceConcepts.html
39 This wxPrefConfig class is a wxConfig wrapper around PalmOS Preferences
40 functionality. Preferences allow to write any structure into its database so
41 wxPrefConfig writes there all entries of single group into one Preference.
42 To optimize read/write operations value of preference is cached. Cache is filled
43 after each change of the path (including using path to group names in all
44 operations) and it is flushed on destructor, any path change on or purpose
49 wxCONFIG_USE_LOCAL_FILE => store config in "saved" preferences database
50 (not to be backed up during a HotSync operation)
51 wxCONFIG_USE_GLOBAL_FILE => store config in "unsaved" preferences database
52 (backed up during a HotSync operation)
55 Each Preference is an array of chars. First unsigned char describes
56 number N of chars used for Preference size. Next N chars (string) contains
57 length of rest of Preference. Preference consists in serie of entries which
58 should be read in loop until in reaches end of Preference.
60 Each entry is an set of chars with following structure:
61 1. name (null terminated)
62 2. type (single char): b,s,g,l,d (see value)
64 - for type="b" (bool) it os "0" or "1"
65 - for type="s" (string) it is null terminated set of chars
66 - for type="g" (subgroup) as for "s" but string is converted to
67 uint16_t for id parameter of ::PrefGetAppPreferences()
68 - for type="l" (long) as for "s" but string is converted to long
69 - for type="d" (double) as for "s" but string is converted to double
72 So all together first Read in group needs 3 reading from Preference:
73 1. take the length N of length
74 2. take the length M of the group content
75 3. take the group content
76 and all it is in single Preference to not overload Preferences database.
77 As long as each next Read/Write is performed in the same group then none
78 access to Preferences is performed. Flushing needs only single writing to
79 databease because all 3 parts of Preference can be prepared in memory.
81 NOTE: wxPrefConfig can read/write only its own entries. It is impossible to
82 know structures of Preferences of other non wxW applications.
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 wxPrefConfig::wxPrefConfig(const wxString
& appName
, const wxString
& vendorName
,
91 const wxString
& strLocal
, const wxString
& strGlobal
,
93 : wxConfigBase(appName
, vendorName
, strLocal
, strGlobal
, style
)
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 void wxPrefConfig::SetPath(const wxString
& strPath
)
105 // ----------------------------------------------------------------------------
106 // enumeration (works only with current group)
107 // ----------------------------------------------------------------------------
109 bool wxPrefConfig::GetFirstGroup(wxString
& str
, long& lIndex
) const
113 bool wxPrefConfig::GetNextGroup(wxString
& str
, long& lIndex
) const
119 bool wxPrefConfig::GetFirstEntry(wxString
& str
, long& lIndex
) const
125 bool wxPrefConfig::GetNextEntry(wxString
& str
, long& lIndex
) const
131 size_t wxPrefConfig::GetNumberOfEntries(bool WXUNUSED(bRecursive
)) const
137 size_t wxPrefConfig::GetNumberOfGroups(bool WXUNUSED(bRecursive
)) const
143 // ----------------------------------------------------------------------------
144 // tests for existence
145 // ----------------------------------------------------------------------------
147 bool wxPrefConfig::HasGroup(const wxString
& key
) const
153 bool wxPrefConfig::HasEntry(const wxString
& key
) const
159 wxConfigBase::EntryType
wxPrefConfig::GetEntryType(const wxString
& key
) const
162 return wxConfigBase::Type_Unknown
;
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 bool wxPrefConfig::DoReadString(const wxString
& key
, wxString
*pStr
) const
175 // this exactly reproduces the string version above except for ExpandEnvVars(),
176 // we really should avoid this code duplication somehow...
178 bool wxPrefConfig::DoReadLong(const wxString
& key
, long *plResult
) const
184 bool wxPrefConfig::DoWriteString(const wxString
& key
, const wxString
& szValue
)
190 bool wxPrefConfig::DoWriteLong(const wxString
& key
, long lValue
)
196 // ----------------------------------------------------------------------------
198 // ----------------------------------------------------------------------------
200 bool wxPrefConfig::RenameEntry(const wxString
& oldName
, const wxString
& newName
)
206 bool wxPrefConfig::RenameGroup(const wxString
& oldName
, const wxString
& newName
)
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 bool wxPrefConfig::DeleteEntry(const wxString
& value
, bool bGroupIfEmptyAlso
)
222 bool wxPrefConfig::DeleteGroup(const wxString
& key
)
228 bool wxPrefConfig::DeleteAll()
234 #endif // wxUSE_CONFIG && wxUSE_CONFIG_NATIVE