Add wxCONFIG_USE_XDG to use with wxFileConfig
Using this style allows to tell wxFileConfig to use XDG-compliant location for the user configuration file, even when not using XDG file layout for wxStandardPaths, which can be convenient when modifying the existing application using wxStandardPaths for other files locations too. And using it in combination with wxCONFIG_USE_SUBDIR allows to put the config file in a XDG-compliant subdirectory, which wasn't easily possible at all before.
This commit is contained in:
parent
d1e223d531
commit
3093d7ad4f
4 changed files with 80 additions and 17 deletions
|
|
@ -6,14 +6,41 @@
|
|||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// Flags for constructor style parameter
|
||||
/// Flags for wxConfig constructor style parameter.
|
||||
enum
|
||||
{
|
||||
wxCONFIG_USE_LOCAL_FILE = 1,
|
||||
wxCONFIG_USE_GLOBAL_FILE = 2,
|
||||
wxCONFIG_USE_RELATIVE_PATH = 4,
|
||||
wxCONFIG_USE_NO_ESCAPE_CHARACTERS = 8,
|
||||
wxCONFIG_USE_SUBDIR = 16
|
||||
|
||||
/**
|
||||
Use subdirectory for the local configuration file location.
|
||||
|
||||
Specifying this flag changes the default local configuration file
|
||||
location to `~/.appname/appname.conf`. Please note that this path is
|
||||
_not_ affected by layout set using wxStandardPaths::SetFileLayout() and
|
||||
it is recommended to use wxCONFIG_USE_XDG flag in addition to this file
|
||||
on contemporary Linux systems.
|
||||
|
||||
@since 2.8.2
|
||||
*/
|
||||
wxCONFIG_USE_SUBDIR = 16,
|
||||
|
||||
/**
|
||||
Use XDG-compliant file location on Unix systems.
|
||||
|
||||
If wxCONFIG_USE_SUBDIR is not specified, using this flag has the same
|
||||
effect as calling wxStandardPaths::SetFileLayout() with
|
||||
wxStandardPaths::FileLayout_XDG, i.e. it changes the default local
|
||||
configuration file location to `~/.config/appname.conf`.
|
||||
|
||||
In combination with wxCONFIG_USE_SUBDIR, this flag changes the default
|
||||
configuration file location to ~/.config/appname/appname.conf`.
|
||||
|
||||
@since 3.3.0
|
||||
*/
|
||||
wxCONFIG_USE_XDG = 32
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -296,14 +323,16 @@ public:
|
|||
@n For wxFileConfig you can also add @c wxCONFIG_USE_RELATIVE_PATH by
|
||||
logically or'ing it to either of the _FILE options to tell
|
||||
wxFileConfig to use relative instead of absolute paths.
|
||||
@n On non-VMS Unix systems, the default local configuration file is
|
||||
"~/.appname". However, this path may be also used as user data
|
||||
@n On Unix-like systems, the default local configuration file is
|
||||
`~/.appname` unless wxStandardPaths::SetFileLayout() is called with
|
||||
wxStandardPaths::FileLayout_XDG parameter in which case the default
|
||||
becomes `~/.config/appname.conf`.
|
||||
@n Note that this default path may be also used as user data
|
||||
directory (see wxStandardPaths::GetUserDataDir()) if the
|
||||
application has several data files. In this case
|
||||
@c wxCONFIG_USE_SUBDIR flag, which changes the default local
|
||||
configuration file to "~/.appname/appname" should be used. Notice
|
||||
that this flag is ignored if @a localFilename is provided.
|
||||
@c wxCONFIG_USE_SUBDIR is new since wxWidgets version 2.8.2.
|
||||
application has several data files. In this case it is recommended
|
||||
to use ::wxCONFIG_USE_XDG flag (available since wxWidgets 3.3.0)
|
||||
and/or older ::wxCONFIG_USE_SUBDIR (available since 2.8.2) to
|
||||
change the default local configuration file location.
|
||||
@n For wxFileConfig, you can also add
|
||||
@c wxCONFIG_USE_NO_ESCAPE_CHARACTERS which will turn off character
|
||||
escaping for the values of entries stored in the config file: for
|
||||
|
|
|
|||
|
|
@ -18,6 +18,24 @@
|
|||
used explicitly if you want to use files and not the registry even under
|
||||
Windows.
|
||||
|
||||
@section fileconf_paths Configuration Files Paths
|
||||
|
||||
The default path for local (or user) configuration file is `~/.appname`,
|
||||
i.e. it is stored directly in the user home directory. This default
|
||||
path is backwards-compatible but not recommended any more and it is advised
|
||||
to call wxStandardPaths::SetFileLayout() with
|
||||
wxStandardPaths::FileLayout_XDG parameter to change the default path to
|
||||
`~/.config/appname.conf`.
|
||||
|
||||
Alternatively, it is possible to specify ::wxCONFIG_USE_XDG flag in the
|
||||
style parameter of the constructor to use this XDG-compliant path without
|
||||
changing the global file layout.
|
||||
|
||||
And for the programs using multiple configuration files it is recommended
|
||||
to use both ::wxCONFIG_USE_XDG and ::wxCONFIG_USE_SUBDIR which change the
|
||||
default file path to `~/.config/appname/appname.conf` -- and allow the
|
||||
program to store other files in the same `~/.config/appname` directory.
|
||||
|
||||
@library{wxbase}
|
||||
@category{cfg}
|
||||
|
||||
|
|
@ -71,8 +89,8 @@ public:
|
|||
parameter in the constructor.
|
||||
|
||||
@a style has the same meaning as in @ref wxConfigBase::wxConfigBase "wxConfig constructor"
|
||||
and can contain any combination of styles but only wxCONFIG_USE_SUBDIR bit is
|
||||
examined by this function.
|
||||
and can contain any combination of styles but only wxCONFIG_USE_SUBDIR
|
||||
and wxCONFIG_USE_XDG are really used by this function.
|
||||
|
||||
Notice that this function cannot be used if @a basename is already a full path name.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue