Implement XDG file layout
This commit is contained in:
committed by
Vadim Zeitlin
parent
8d5d00db9d
commit
d56d127d3f
@@ -60,6 +60,12 @@ public:
|
||||
Dir_Videos
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
FileLayout_Classic = 0,
|
||||
FileLayout_XDG = 1
|
||||
};
|
||||
|
||||
// return the global standard paths object
|
||||
static wxStandardPaths& Get();
|
||||
|
||||
@@ -168,6 +174,15 @@ public:
|
||||
|
||||
bool UsesAppInfo(int info) const { return (m_usedAppInfo & info) != 0; }
|
||||
|
||||
void SetFileLayout(int layout)
|
||||
{
|
||||
m_usedFileLayout = layout;
|
||||
}
|
||||
|
||||
int GetFileLayout() const
|
||||
{
|
||||
return m_usedFileLayout;
|
||||
}
|
||||
|
||||
protected:
|
||||
// Ctor is protected as this is a base class which should never be created
|
||||
@@ -184,6 +199,7 @@ protected:
|
||||
|
||||
// combination of AppInfo_XXX flags used by AppendAppInfo()
|
||||
int m_usedAppInfo;
|
||||
int m_usedFileLayout;
|
||||
};
|
||||
|
||||
#if wxUSE_STDPATHS
|
||||
|
@@ -135,6 +135,19 @@ public:
|
||||
Dir_Videos
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/**
|
||||
Use the classic file layout
|
||||
*/
|
||||
FileLayout_Classic,
|
||||
|
||||
/**
|
||||
Use a XDG styled file layout (Unix)
|
||||
*/
|
||||
FileLayout_XDG
|
||||
};
|
||||
|
||||
/**
|
||||
MSW-specific function undoing the effect of IgnoreAppSubDir() calls.
|
||||
|
||||
@@ -444,6 +457,19 @@ public:
|
||||
*/
|
||||
void UseAppInfo(int info);
|
||||
|
||||
/**
|
||||
Returns the current file layout
|
||||
Valid values for @a are:
|
||||
- @c FileLayout_Classic,
|
||||
- @c FileLayout_XDG
|
||||
*/
|
||||
void SetFileLayout(int layout);
|
||||
|
||||
/**
|
||||
Returns the current file layout
|
||||
*/
|
||||
int GetFileLayout() const;
|
||||
|
||||
/**
|
||||
Return the file name which would be used by wxFileConfig as local,
|
||||
user-specific, file if it were constructed with @a basename.
|
||||
|
@@ -97,6 +97,7 @@ wxStandardPathsBase::wxStandardPathsBase()
|
||||
// Derived classes can call this in their constructors
|
||||
// to set the platform-specific settings
|
||||
UseAppInfo(AppInfo_AppName);
|
||||
SetFileLayout(FileLayout_Classic);
|
||||
}
|
||||
|
||||
wxStandardPathsBase::~wxStandardPathsBase()
|
||||
|
@@ -53,6 +53,16 @@ void wxStandardPaths::SetInstallPrefix(const wxString& prefix)
|
||||
|
||||
wxString wxStandardPaths::GetUserConfigDir() const
|
||||
{
|
||||
if (GetFileLayout() & FileLayout_XDG)
|
||||
{
|
||||
wxString configPath;
|
||||
if (wxGetenv(wxT("XDG_CONFIG_HOME")))
|
||||
configPath = wxGetenv(wxT("XDG_CONFIG_HOME"));
|
||||
else
|
||||
configPath = wxFileName::GetHomeDir() + wxT("/.config");
|
||||
return configPath;
|
||||
}
|
||||
|
||||
return wxFileName::GetHomeDir();
|
||||
}
|
||||
|
||||
@@ -236,6 +246,7 @@ wxStandardPaths::GetLocalizedResourcesDir(const wxString& lang,
|
||||
|
||||
wxString wxStandardPaths::GetUserDir(Dir userDir) const
|
||||
{
|
||||
if (GetFileLayout() & FileLayout_XDG)
|
||||
{
|
||||
wxLogNull logNull;
|
||||
wxString homeDir = wxFileName::GetHomeDir();
|
||||
@@ -312,7 +323,7 @@ wxString wxStandardPaths::GetUserDir(Dir userDir) const
|
||||
wxString wxStandardPaths::MakeConfigFileName(const wxString& basename, int style) const
|
||||
{
|
||||
wxFileName fn(wxEmptyString, basename);
|
||||
if (style & wxCONFIG_USE_SUBDIR)
|
||||
if (style & wxCONFIG_USE_SUBDIR || GetFileLayout() & FileLayout_XDG)
|
||||
fn.SetExt(wxT("conf"));
|
||||
else
|
||||
fn.SetName(wxT('.') + fn.GetName());
|
||||
|
Reference in New Issue
Block a user