]>
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 // ---------------------------------------------------------------------------- 
  85 IMPLEMENT_ABSTRACT_CLASS(wxPrefConfig
, wxConfigBase
) 
  87 wxPrefConfig::wxPrefConfig(const wxString
& appName
, const wxString
& vendorName
, 
  88                            const wxString
& strLocal
, const wxString
& strGlobal
, 
  90              : wxConfigBase(appName
, vendorName
, strLocal
, strGlobal
, style
) 
  94 // ---------------------------------------------------------------------------- 
  96 // ---------------------------------------------------------------------------- 
  98 void wxPrefConfig::SetPath(const wxString
& strPath
) 
 102 // ---------------------------------------------------------------------------- 
 103 // enumeration (works only with current group) 
 104 // ---------------------------------------------------------------------------- 
 106 bool wxPrefConfig::GetFirstGroup(wxString
& str
, long& lIndex
) const 
 110 bool wxPrefConfig::GetNextGroup(wxString
& str
, long& lIndex
) const 
 116 bool wxPrefConfig::GetFirstEntry(wxString
& str
, long& lIndex
) const 
 122 bool wxPrefConfig::GetNextEntry(wxString
& str
, long& lIndex
) const 
 128 size_t wxPrefConfig::GetNumberOfEntries(bool WXUNUSED(bRecursive
)) const 
 134 size_t wxPrefConfig::GetNumberOfGroups(bool WXUNUSED(bRecursive
)) const 
 140 // ---------------------------------------------------------------------------- 
 141 // tests for existence 
 142 // ---------------------------------------------------------------------------- 
 144 bool wxPrefConfig::HasGroup(const wxString
& key
) const 
 150 bool wxPrefConfig::HasEntry(const wxString
& key
) const 
 156 wxConfigBase::EntryType 
wxPrefConfig::GetEntryType(const wxString
& key
) const 
 159     return wxConfigBase::Type_Unknown
; 
 162 // ---------------------------------------------------------------------------- 
 164 // ---------------------------------------------------------------------------- 
 166 bool wxPrefConfig::DoReadString(const wxString
& key
, wxString 
*pStr
) const 
 172 // this exactly reproduces the string version above except for ExpandEnvVars(), 
 173 // we really should avoid this code duplication somehow... 
 175 bool wxPrefConfig::DoReadLong(const wxString
& key
, long *plResult
) const 
 182 bool wxPrefConfig::DoReadBinary(const wxString
& key
, wxMemoryBuffer 
*buf
) const 
 187 #endif // wxUSE_BASE64 
 189 bool wxPrefConfig::DoWriteString(const wxString
& key
, const wxString
& szValue
) 
 195 bool wxPrefConfig::DoWriteLong(const wxString
& key
, long lValue
) 
 202 bool wxPrefConfig::DoWriteBinary(const wxString
& key
, const wxMemoryBuffer
& buf
) 
 207 #endif // wxUSE_BASE64 
 209 // ---------------------------------------------------------------------------- 
 211 // ---------------------------------------------------------------------------- 
 213 bool wxPrefConfig::RenameEntry(const wxString
& oldName
, const wxString
& newName
) 
 219 bool wxPrefConfig::RenameGroup(const wxString
& oldName
, const wxString
& newName
) 
 225 // ---------------------------------------------------------------------------- 
 227 // ---------------------------------------------------------------------------- 
 229 bool wxPrefConfig::DeleteEntry(const wxString
& value
, bool bGroupIfEmptyAlso
) 
 235 bool wxPrefConfig::DeleteGroup(const wxString
& key
) 
 241 bool wxPrefConfig::DeleteAll() 
 247 #endif // wxUSE_CONFIG && wxUSE_CONFIG_NATIVE