Add wxStandardPaths::GetUserDir() to get Desktop, Download etc

All major supported platforms have well defined per-user directories to store
Downloads, Music, Pictures, Videos and the Desktop files. The new method
wxStandardPaths::GetUserDir() allows for a unified way to access these on MSW,
OS X and Unix (if XDG user dirs specification is implemented for the latter).

See https://github.com/wxWidgets/wxWidgets/pull/89
This commit is contained in:
Tobias Taschner
2015-09-07 22:06:48 +02:00
committed by Vadim Zeitlin
parent cfe4b4fd07
commit a0fb808087
11 changed files with 240 additions and 26 deletions

View File

@@ -26,7 +26,7 @@ public:
virtual wxString GetUserDataDir() const;
virtual wxString GetUserLocalDataDir() const;
virtual wxString GetPluginsDir() const;
virtual wxString GetDocumentsDir() const;
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
// MSW-specific methods
@@ -72,6 +72,8 @@ protected:
// get the path corresponding to the given standard CSIDL_XXX constant
static wxString DoGetDirectory(int csidl);
static wxString DoGetKnownFolder(const GUID& rfid);
// return the directory of the application itself
wxString GetAppDir() const;

View File

@@ -52,7 +52,7 @@ public:
virtual wxString
GetLocalizedResourcesDir(const wxString& lang,
ResourceCat category = ResourceCat_None) const;
virtual wxString GetDocumentsDir() const;
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
protected:
// Ctor is protected, use wxStandardPaths::Get() instead of instantiating

View File

@@ -49,6 +49,15 @@ public:
AppInfo_VendorName = 2 // the vendor name
};
enum Dir
{
Dir_Documents,
Dir_Desktop,
Dir_Downloads,
Dir_Music,
Dir_Pictures,
Dir_Videos
};
// return the global standard paths object
static wxStandardPaths& Get();
@@ -130,7 +139,10 @@ public:
//
// C:\Documents and Settings\username\My Documents under Windows,
// $HOME under Unix and ~/Documents under Mac
virtual wxString GetDocumentsDir() const;
virtual wxString GetDocumentsDir() const
{
return GetUserDir(Dir_Documents);
}
// return the directory for the documents files used by this application:
// it's a subdirectory of GetDocumentsDir() constructed using the
@@ -140,6 +152,7 @@ public:
// return the temporary directory for the current user
virtual wxString GetTempDir() const;
virtual wxString GetUserDir(Dir userDir) const;
// virtual dtor for the base class
virtual ~wxStandardPathsBase();
@@ -205,7 +218,7 @@ public:
virtual wxString GetLocalDataDir() const { return m_prefix; }
virtual wxString GetUserDataDir() const { return m_prefix; }
virtual wxString GetPluginsDir() const { return m_prefix; }
virtual wxString GetDocumentsDir() const { return m_prefix; }
virtual wxString GetUserDir(Dir WXUNUSED(userDir)) const { return m_prefix; }
protected:
// Ctor is protected because wxStandardPaths::Get() should always be used

View File

@@ -47,7 +47,7 @@ public:
virtual wxString GetLocalizedResourcesDir(const wxString& lang,
ResourceCat category) const wxOVERRIDE;
#ifndef __VMS
virtual wxString GetDocumentsDir() const wxOVERRIDE;
virtual wxString GetUserDir(Dir userDir) const wxOVERRIDE;
#endif
protected: