allow to optionally use vendor name component in standard paths (slightly modified patch 1831308)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50025 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-11-17 14:59:13 +00:00
parent 180b5b4827
commit 2b147f2e19
8 changed files with 106 additions and 21 deletions

View File

@@ -280,3 +280,24 @@ automatically, portable programs should call this function. Usually the prefix
is set during program configuration if using GNU autotools and so it is enough
to pass its value defined in \texttt{config.h} to this function.
\membersection{wxStandardPaths::UseAppInfo}\label{wxstandardpathsuseappinfo}
\func{void}{UseAppInfo}{\param{int }{info}}
Controls what application information is used when constructing paths that
should be unique to this program, such as the application data directory, the
plugins directory on Unix, etc.
Valid values for \arg{info} are \texttt{AppInfo\_None} and either one or
combination of \texttt{AppInfo\_AppName} and \texttt{AppInfo\_VendorName}. The
first one tells this class to not use neither application nor vendor name in
the paths.
By default, only the application name is used under Unix systems but both
application and vendor names are used under Windows and Mac.
\wxheading{See also}
\helpref{wxApp::SetAppName}{wxappsetappname}, \helpref{wxApp::SetVendorName}{wxappsetvendorname}

View File

@@ -19,6 +19,13 @@
class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
{
public:
wxStandardPaths()
{
UseAppInfo(AppInfo_AppName | AppInfo_VendorName);
}
~wxStandardPaths() { }
// implement base class pure virtuals
virtual wxString GetExecutablePath() const;
virtual wxString GetConfigDir() const;

View File

@@ -39,6 +39,15 @@ public:
ResourceCat_Max
};
// what should we use to construct paths unique to this application:
// (AppInfo_AppName and AppInfo_VendorName can be combined together)
enum
{
AppInfo_None = 0, // nothing
AppInfo_AppName = 1, // the application name
AppInfo_VendorName = 2 // the vendor name
};
// return the global standard paths object
static wxStandardPathsBase& Get();
@@ -126,13 +135,32 @@ public:
virtual wxString GetTempDir() const;
// ctor for the base class
wxStandardPathsBase();
// virtual dtor for the base class
virtual ~wxStandardPathsBase();
// Information used by AppendAppInfo
void UseAppInfo(int info)
{
m_usedAppInfo = info;
}
bool UsesAppInfo(int info) const { return (m_usedAppInfo & info) != 0; }
protected:
// append "/appname" suffix if the app name is set (doesn't append the
// slash if dir already ends with a slash or dot)
static wxString AppendAppName(const wxString& dir);
// append the path component, with a leading path seperator if a
// path seperator or dot (.) is not already at the end of dir
static wxString AppendPathComponent(const wxString& dir, const wxString& component);
// append application information determined by m_usedAppInfo to dir
wxString AppendAppInfo(const wxString& dir) const;
// combination of AppInfo_XXX flags used by AppendAppInfo()
int m_usedAppInfo;
};
#if wxUSE_STDPATHS

View File

@@ -77,6 +77,15 @@ wxStandardPathsBase& wxAppTraitsBase::GetStandardPaths()
return gs_stdPaths;
}
wxStandardPathsBase::wxStandardPathsBase()
{
// Set the default information that is used when
// forming some paths (by AppendAppInfo).
// Derived classes can call this in their constructors
// to set the platform-specific settings
UseAppInfo(AppInfo_AppName);
}
wxStandardPathsBase::~wxStandardPathsBase()
{
// nothing to do here
@@ -104,23 +113,41 @@ wxString wxStandardPathsBase::GetTempDir() const
}
/* static */
wxString wxStandardPathsBase::AppendAppName(const wxString& dir)
wxString wxStandardPathsBase::AppendPathComponent(const wxString& dir, const wxString& component)
{
wxString subdir(dir);
// empty string indicates that an error has occurred, don't touch it then
if ( !subdir.empty() )
{
const wxString appname = wxTheApp->GetAppName();
if ( !appname.empty() )
if ( !component.empty() )
{
const wxChar ch = *(subdir.end() - 1);
if ( !wxFileName::IsPathSeparator(ch) && ch != _T('.') )
subdir += wxFileName::GetPathSeparator();
subdir += appname;
subdir += component;
}
}
return subdir;
}
wxString wxStandardPathsBase::AppendAppInfo(const wxString& dir) const
{
wxString subdir(dir);
if ( UsesAppInfo(AppInfo_VendorName) )
{
subdir = AppendPathComponent(subdir, wxTheApp->GetVendorName());
}
if ( UsesAppInfo(AppInfo_AppName) )
{
subdir = AppendPathComponent(subdir, wxTheApp->GetAppName());
}
return subdir;
}

View File

@@ -49,12 +49,14 @@ wxStandardPathsCF::wxStandardPathsCF()
: m_bundle(CFBundleGetMainBundle())
{
CFRetain(m_bundle);
UseAppInfo(AppInfo_AppName | AppInfo_VendorName);
}
wxStandardPathsCF::wxStandardPathsCF(wxCFBundleRef bundle)
: m_bundle(bundle)
{
CFRetain(m_bundle);
UseAppInfo(AppInfo_AppName | AppInfo_VendorName);
}
wxStandardPathsCF::~wxStandardPathsCF()
@@ -170,18 +172,18 @@ wxString wxStandardPathsCF::GetExecutablePath() const
wxString wxStandardPathsCF::GetLocalDataDir() const
{
#ifdef __WXMAC__
return AppendAppName(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
return AppendAppInfo(wxMacFindFolder((short)kLocalDomain, kApplicationSupportFolderType, kCreateFolder));
#else
return AppendAppName(wxT("/Library/Application Support"));
return AppendAppInfo(wxT("/Library/Application Support"));
#endif
}
wxString wxStandardPathsCF::GetUserDataDir() const
{
#ifdef __WXMAC__
return AppendAppName(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
return AppendAppInfo(wxMacFindFolder((short)kUserDomain, kApplicationSupportFolderType, kCreateFolder));
#else
return AppendAppName(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
return AppendAppInfo(wxFileName::GetHomeDir() + _T("/Library/Application Support"));
#endif
}

View File

@@ -281,7 +281,7 @@ wxString wxStandardPaths::GetExecutablePath() const
wxString wxStandardPaths::GetConfigDir() const
{
return AppendAppName(DoGetDirectory(CSIDL_COMMON_APPDATA));
return AppendAppInfo(DoGetDirectory(CSIDL_COMMON_APPDATA));
}
wxString wxStandardPaths::GetUserConfigDir() const
@@ -298,12 +298,12 @@ wxString wxStandardPaths::GetDataDir() const
wxString wxStandardPaths::GetUserDataDir() const
{
return AppendAppName(GetUserConfigDir());
return AppendAppInfo(GetUserConfigDir());
}
wxString wxStandardPaths::GetUserLocalDataDir() const
{
return AppendAppName(DoGetDirectory(CSIDL_LOCAL_APPDATA));
return AppendAppInfo(DoGetDirectory(CSIDL_LOCAL_APPDATA));
}
wxString wxStandardPaths::GetPluginsDir() const

View File

@@ -82,7 +82,7 @@ wxString wxStandardPaths::GetDataDir() const
wxString wxStandardPaths::GetUserDataDir() const
{
return AppendAppName(wxFileName::GetHomeDir() + _T("\\."));
return AppendAppInfo(wxFileName::GetHomeDir() + _T("\\."));
}
wxString wxStandardPaths::GetPluginsDir() const

View File

@@ -75,12 +75,12 @@ wxString wxStandardPaths::GetConfigDir() const
wxString wxStandardPaths::GetDataDir() const
{
return AppendAppName(GetInstallPrefix() + _T("/sys$share"));
return AppendAppInfo(GetInstallPrefix() + _T("/sys$share"));
}
wxString wxStandardPaths::GetLocalDataDir() const
{
return AppendAppName(_T("/sys$manager"));
return AppendAppInfo(_T("/sys$manager"));
}
wxString wxStandardPaths::GetUserDataDir() const
@@ -187,22 +187,22 @@ wxString wxStandardPaths::GetConfigDir() const
wxString wxStandardPaths::GetDataDir() const
{
return AppendAppName(GetInstallPrefix() + _T("/share"));
return AppendAppInfo(GetInstallPrefix() + _T("/share"));
}
wxString wxStandardPaths::GetLocalDataDir() const
{
return AppendAppName(_T("/etc"));
return AppendAppInfo(_T("/etc"));
}
wxString wxStandardPaths::GetUserDataDir() const
{
return AppendAppName(wxFileName::GetHomeDir() + _T("/."));
return AppendAppInfo(wxFileName::GetHomeDir() + _T("/."));
}
wxString wxStandardPaths::GetPluginsDir() const
{
return AppendAppName(GetInstallPrefix() + _T("/lib"));
return AppendAppInfo(GetInstallPrefix() + _T("/lib"));
}
wxString