// Modified by:
// Created: 07.04.98 (adapted from appconf.cpp)
// RCS-ID: $Id$
-// Copyright: (c) 1997 Karsten BallΓΌder & Vadim Zeitlin
+// Copyright: (c) 1997 Karsten Ballueder & Vadim Zeitlin
// Ballueder@usa.net <zeitlin@dptmaths.ens-cachan.fr>
-// Licence: wxWindows license
+// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _FILECONF_H
#define _FILECONF_H
-#ifdef __GNUG__
-#pragma interface "fileconf.h"
-#endif
-
#include "wx/defs.h"
#if wxUSE_CONFIG
#include "wx/textfile.h"
#include "wx/string.h"
+#include "wx/confbase.h"
+#include "wx/filename.h"
// ----------------------------------------------------------------------------
// wxFileConfig
in the entries it reads: for example, if you have an entry
score_file = $HOME/.score
a call to Read(&str, "score_file") will return a complete path to .score file
- unless the expansion was previousle disabled with SetExpandEnvVars(FALSE) call
+ unless the expansion was previously disabled with SetExpandEnvVars(false) call
(it's on by default, the current status can be retrieved with
IsExpandingEnvVars function).
*/
-class WXDLLEXPORT wxFileConfigGroup;
-class WXDLLEXPORT wxFileConfigEntry;
-class WXDLLEXPORT wxFileConfigLineList;
-class WXDLLEXPORT wxInputStream;
+class WXDLLIMPEXP_FWD_BASE wxFileConfigGroup;
+class WXDLLIMPEXP_FWD_BASE wxFileConfigEntry;
+class WXDLLIMPEXP_FWD_BASE wxFileConfigLineList;
+
+#if wxUSE_STREAMS
+class WXDLLIMPEXP_FWD_BASE wxInputStream;
+class WXDLLIMPEXP_FWD_BASE wxOutputStream;
+#endif // wxUSE_STREAMS
-class WXDLLEXPORT wxFileConfig : public wxConfigBase
+class WXDLLIMPEXP_BASE wxFileConfig : public wxConfigBase
{
public:
// construct the "standard" full name for global (system-wide) and
// Unix /etc/file.ext ~/.file
// Win %windir%\file.ext %USERPROFILE%\file.ext
//
- // where file is the basename of szFile, ext is it's extension
+ // where file is the basename of szFile, ext is its extension
// or .conf (Unix) or .ini (Win) if it has none
- static wxString GetGlobalFileName(const wxChar *szFile);
- static wxString GetLocalFileName(const wxChar *szFile);
+ static wxFileName GetGlobalFile(const wxString& szFile);
+ static wxFileName GetLocalFile(const wxString& szFile, int style = 0);
+
+ static wxString GetGlobalFileName(const wxString& szFile)
+ {
+ return GetGlobalFile(szFile).GetFullPath();
+ }
+
+ static wxString GetLocalFileName(const wxString& szFile, int style = 0)
+ {
+ return GetLocalFile(szFile, style).GetFullPath();
+ }
// ctor & dtor
// New constructor: one size fits all. Specify wxCONFIG_USE_LOCAL_FILE or
// wxCONFIG_USE_GLOBAL_FILE to say which files should be used.
- wxFileConfig(const wxString& appName,
- const wxString& vendorName = wxT(""),
- const wxString& localFilename = wxT(""),
- const wxString& globalFilename = wxT(""),
- long style = wxCONFIG_USE_LOCAL_FILE);
+ wxFileConfig(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());
#if wxUSE_STREAMS
// ctor that takes an input stream.
- wxFileConfig(wxInputStream &inStream);
+ wxFileConfig(wxInputStream &inStream, const wxMBConv& conv = wxConvAuto());
#endif // wxUSE_STREAMS
// dtor will save unsaved data
virtual bool GetFirstEntry(wxString& str, long& lIndex) const;
virtual bool GetNextEntry (wxString& str, long& lIndex) const;
- virtual size_t GetNumberOfEntries(bool bRecursive = FALSE) const;
- virtual size_t GetNumberOfGroups(bool bRecursive = FALSE) const;
+ virtual size_t GetNumberOfEntries(bool bRecursive = false) const;
+ virtual size_t GetNumberOfGroups(bool bRecursive = false) const;
virtual bool HasGroup(const wxString& strName) const;
virtual bool HasEntry(const wxString& strName) const;
- virtual bool Flush(bool bCurrentOnly = FALSE);
+ virtual bool Flush(bool bCurrentOnly = false);
virtual bool RenameEntry(const wxString& oldName, const wxString& newName);
virtual bool RenameGroup(const wxString& oldName, const wxString& newName);
- virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso = TRUE);
+ virtual bool DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso = true);
virtual bool DeleteGroup(const wxString& szKey);
virtual bool DeleteAll();
+ // additional, wxFileConfig-specific, functionality
+#if wxUSE_STREAMS
+ // save the entire config file text to the given stream, note that the text
+ // won't be saved again in dtor when Flush() is called if you use this method
+ // as it won't be "changed" any more
+ virtual bool Save(wxOutputStream& os, const wxMBConv& conv = wxConvAuto());
+#endif // wxUSE_STREAMS
+
public:
// functions to work with this list
wxFileConfigLineList *LineListAppend(const wxString& str);
protected:
virtual bool DoReadString(const wxString& key, wxString *pStr) const;
virtual bool DoReadLong(const wxString& key, long *pl) const;
+#if wxUSE_BASE64
+ virtual bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const;
+#endif // wxUSE_BASE64
virtual bool DoWriteString(const wxString& key, const wxString& szValue);
virtual bool DoWriteLong(const wxString& key, long lValue);
+#if wxUSE_BASE64
+ virtual bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf);
+#endif // wxUSE_BASE64
private:
// GetXXXFileName helpers: return ('/' terminated) directory names
static wxString GetGlobalDir();
- static wxString GetLocalDir();
+ static wxString GetLocalDir(int style = 0);
// common part of all ctors (assumes that m_str{Local|Global}File are already
// initialized
void CleanUp();
// parse the whole file
- void Parse(wxTextBuffer& buffer, bool bLocal);
+ void Parse(const wxTextBuffer& buffer, bool bLocal);
// the same as SetPath("/")
void SetRootPath();
+ // real SetPath() implementation, returns true if path could be set or false
+ // if path doesn't exist and createMissingComponents == false
+ bool DoSetPath(const wxString& strPath, bool createMissingComponents);
+
+ // set/test the dirty flag
+ void SetDirty() { m_isDirty = true; }
+ void ResetDirty() { m_isDirty = false; }
+ bool IsDirty() const { return m_isDirty; }
+
+
// member variables
// ----------------
- wxFileConfigLineList *m_linesHead, // head of the linked list
- *m_linesTail; // tail
+ wxFileConfigLineList *m_linesHead, // head of the linked list
+ *m_linesTail; // tail
- wxString m_strLocalFile, // local file name passed to ctor
- m_strGlobalFile; // global
- wxString m_strPath; // current path (not '/' terminated)
+ wxFileName m_fnLocalFile, // local file name passed to ctor
+ m_fnGlobalFile; // global
+ wxString m_strPath; // current path (not '/' terminated)
wxFileConfigGroup *m_pRootGroup, // the top (unnamed) group
*m_pCurrentGroup; // the current group
+ wxMBConv *m_conv;
+
#ifdef __UNIX__
- int m_umask; // the umask to use for file creation
+ int m_umask; // the umask to use for file creation
#endif // __UNIX__
+
+ bool m_isDirty; // if true, we have unsaved changes
+
+ wxDECLARE_NO_COPY_CLASS(wxFileConfig);
+ DECLARE_ABSTRACT_CLASS(wxFileConfig)
};
#endif
// wxUSE_CONFIG
-#endif
+#endif
//_FILECONF_H