tdf#98407 PathSubstitution: Add substitution for $(username)

This allows to use the username as a placeholder in the config paths (Autotext, Gallery, etc)

Change-Id: I76434e980cd8ec8785a5587d0bc5fdd67dc42de2
Reviewed-on: https://gerrit.libreoffice.org/22901
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Samuel Mehrbrodt
2016-03-07 21:52:20 +01:00
committed by Stephan Bergmann
parent f9ddda3538
commit 16fb0d3d0f
10 changed files with 46 additions and 6 deletions

View File

@@ -54,6 +54,7 @@ public class PathSubstitutionTest
substVars.add("$(home)", true, true); substVars.add("$(home)", true, true);
substVars.add("$(temp)", true, true); substVars.add("$(temp)", true, true);
substVars.add("$(lang)", false, false); substVars.add("$(lang)", false, false);
substVars.add("$(username)", false, false);
substVars.add("$(langid)", false, false); substVars.add("$(langid)", false, false);
substVars.add("$(vlang)", false, false); substVars.add("$(vlang)", false, false);
// path won't resubstitute // path won't resubstitute

View File

@@ -167,6 +167,7 @@ enum PreDefVariable
PREDEFVAR_HOME, PREDEFVAR_HOME,
PREDEFVAR_TEMP, PREDEFVAR_TEMP,
PREDEFVAR_PATH, PREDEFVAR_PATH,
PREDEFVAR_USERNAME,
PREDEFVAR_LANGID, PREDEFVAR_LANGID,
PREDEFVAR_VLANG, PREDEFVAR_VLANG,
PREDEFVAR_INSTPATH, PREDEFVAR_INSTPATH,
@@ -350,6 +351,7 @@ static const FixedVariable aFixedVarTable[] =
{ "$(home)", PREDEFVAR_HOME, true }, { "$(home)", PREDEFVAR_HOME, true },
{ "$(temp)", PREDEFVAR_TEMP, true }, { "$(temp)", PREDEFVAR_TEMP, true },
{ "$(path)", PREDEFVAR_PATH, true }, { "$(path)", PREDEFVAR_PATH, true },
{ "$(username)", PREDEFVAR_USERNAME, false },
{ "$(langid)", PREDEFVAR_LANGID, false }, { "$(langid)", PREDEFVAR_LANGID, false },
{ "$(vlang)", PREDEFVAR_VLANG, false }, { "$(vlang)", PREDEFVAR_VLANG, false },
{ "$(instpath)", PREDEFVAR_INSTPATH, true }, { "$(instpath)", PREDEFVAR_INSTPATH, true },
@@ -1239,6 +1241,12 @@ void SubstitutePathVariables::SetPredefinedPathVariables()
m_aPreDefVars.m_FixedVar[ PREDEFVAR_PROG ] = m_aPreDefVars.m_FixedVar[ PREDEFVAR_PROGPATH ]; m_aPreDefVars.m_FixedVar[ PREDEFVAR_PROG ] = m_aPreDefVars.m_FixedVar[ PREDEFVAR_PROGPATH ];
} }
// Set $(username)
OUString aSystemUser;
::osl::Security aSecurity;
aSecurity.getUserName( aSystemUser, false );
m_aPreDefVars.m_FixedVar[ PREDEFVAR_USERNAME ] = aSystemUser;
// Detect the language type of the current office // Detect the language type of the current office
m_aPreDefVars.m_eLanguageType = LANGUAGE_ENGLISH_US; m_aPreDefVars.m_eLanguageType = LANGUAGE_ENGLISH_US;
OUString aLocaleStr( utl::ConfigManager::getLocale() ); OUString aLocaleStr( utl::ConfigManager::getLocale() );

View File

@@ -118,6 +118,16 @@ SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserIdent(
SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserName( SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getUserName(
oslSecurity Security, rtl_uString **strName); oslSecurity Security, rtl_uString **strName);
/** Get the login name for the user of this security handle,
excluding the domain name on Windows.
@param[in] Security the security handle.
@param[out] strName the string that receives the user name on success.
@return True, if the security handle is valid, otherwise False.
@since LibreOffice 5.2
*/
SAL_DLLPUBLIC sal_Bool SAL_CALL osl_getShortUserName(
oslSecurity Security, rtl_uString **strName);
/** Get the home directory of the user of this security handle. /** Get the home directory of the user of this security handle.
@param[in] Security the security handle. @param[in] Security the security handle.
@param[out] strDirectory the string that receives the directory path on success. @param[out] strDirectory the string that receives the directory path on success.

View File

@@ -69,9 +69,11 @@ inline bool Security::getUserIdent( rtl::OUString& strIdent) const
} }
inline bool Security::getUserName( rtl::OUString& strName ) const inline bool Security::getUserName( rtl::OUString& strName, bool bIncludeDomain ) const
{ {
return osl_getUserName( m_handle, &strName.pData ); if (bIncludeDomain)
return osl_getUserName( m_handle, &strName.pData );
return osl_getShortUserName( m_handle, &strName.pData );
} }

View File

@@ -76,9 +76,11 @@ public:
/** get the name of the logged in user. /** get the name of the logged in user.
@param[out] strName is the OUString which returns the name @param[out] strName is the OUString which returns the name
@param[in] bIncludeDomain Include the Domain name (like "ORG\username"). Affects Windows only.
This parameter is available since LibreOffice 5.2.
@return True, if any user is successfully logged in, otherwise False @return True, if any user is successfully logged in, otherwise False
*/ */
inline bool SAL_CALL getUserName( rtl::OUString& strName) const; inline bool SAL_CALL getUserName( rtl::OUString& strName, bool bIncludeDomain=true ) const;
/** get the home directory of the logged in user. /** get the home directory of the logged in user.
@param[out] strDirectory is the OUString which returns the directory name @param[out] strDirectory is the OUString which returns the directory name

View File

@@ -44,7 +44,7 @@ public class PathSubstitutionTest {
* the path substitution service. * the path substitution service.
*/ */
private static String[] predefinedPathVariables = { private static String[] predefinedPathVariables = {
"$(home)","$(inst)","$(prog)","$(temp)","$(user)", "$(home)","$(inst)","$(prog)","$(temp)","$(user)", "$(username)",
"$(work)","$(path)","$(langid)","$(vlang)" "$(work)","$(path)","$(langid)","$(vlang)"
}; };

View File

@@ -58,6 +58,8 @@ module com { module sun { module star { module util {
<dd>The current temporary directory.</dd> <dd>The current temporary directory.</dd>
<dt>\$(path)</dt> <dt>\$(path)</dt>
<dd>The value of PATH environment variable.</dd> <dd>The value of PATH environment variable.</dd>
<dt>\$(username)</dt>
<dd>The username (login name) of the currently active user, excluding the domain name on Windows. (Available since LibreOffice 5.2)</dd>
<dt>\$(langid)</dt> <dt>\$(langid)</dt>
<dd>The language code used by the Office, like 0x0009=English, 0x0409=English US.</dd> <dd>The language code used by the Office, like 0x0009=English, 0x0409=English US.</dd>
<dt>\$(vlang)</dt> <dt>\$(vlang)</dt>
@@ -65,7 +67,7 @@ module com { module sun { module star { module util {
</dl> </dl>
<p> <p>
Attention: Most predefined variables describe an absolute path. Attention: Most predefined variables describe an absolute path.
The only exceptions are: \$(langid) and \$(vlang). The only exceptions are: \$(username), \$(langid) and \$(vlang).
Therefore the service implementation should only substitute variables which Therefore the service implementation should only substitute variables which
are located at the start of a provided path string or are part of a multi-path. are located at the start of a provided path string or are part of a multi-path.
This special service is not designed to be a text substiution but shall This special service is not designed to be a text substiution but shall

View File

@@ -66,7 +66,7 @@ static bool sysconf_SC_GETPW_R_SIZE_MAX(std::size_t * value) {
way and always set EINVAL, so be resilient here: */ way and always set EINVAL, so be resilient here: */
return false; return false;
} else { } else {
SAL_WARN_IF( m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max(), "sal.osl", SAL_WARN_IF( m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max(), "sal.osl",
"m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max()"); "m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max()");
*value = (std::size_t) m; *value = (std::size_t) m;
return true; return true;
@@ -261,6 +261,11 @@ sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **ustrName)
return bRet; return bRet;
} }
sal_Bool SAL_CALL osl_getShortUserName(oslSecurity Security, rtl_uString **ustrName)
{
return osl_getUserName(Security, ustrName); // No domain name on unix
}
static bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* pszName, sal_uInt32 nMax) static bool SAL_CALL osl_psz_getUserName(oslSecurity Security, sal_Char* pszName, sal_uInt32 nMax)
{ {
oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl *>(Security); oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl *>(Security);

View File

@@ -424,6 +424,11 @@ sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **strName)
return getUserNameImpl(Security, strName, sal_True); return getUserNameImpl(Security, strName, sal_True);
} }
sal_Bool SAL_CALL osl_getShortUserName(oslSecurity Security, rtl_uString **strName)
{
return getUserNameImpl(Security, strName, sal_False);
}
sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory) sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory)
{ {
rtl_uString *ustrSysDir = NULL; rtl_uString *ustrSysDir = NULL;

View File

@@ -690,6 +690,11 @@ LIBO_UDK_5.1 { # symbols available in >= LibO 5.1
rtl_uString_newReplaceFirstToAsciiL; rtl_uString_newReplaceFirstToAsciiL;
} LIBO_UDK_5.0; } LIBO_UDK_5.0;
LIBO_UDK_5.2 { # symbols available in >= LibO 5.2
global:
osl_getShortUserName;
} LIBO_UDK_5.1;
PRIVATE_1.0 { PRIVATE_1.0 {
global: global:
osl_detail_ObjectRegistry_storeAddresses; osl_detail_ObjectRegistry_storeAddresses;