diff options
author | Caolán McNamara <caolanm@redhat.com> | 2016-07-22 09:39:55 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2016-07-22 09:51:31 +0100 |
commit | b5c05876f73c31270bc374e4f481ef1d09a42e5f (patch) | |
tree | 5ab1ba79a5ffd72c33823569d0125838006c5afd /shell | |
parent | 7eed51d0332e16f97789ac638246d6d891348fd9 (diff) |
Related: rhbz#1065807 recover using xdg templates and documents settings
Change-Id: If2c594174a6fa8c524d9664c9f197cb7c6d4641d
Diffstat (limited to 'shell')
-rw-r--r-- | shell/source/backends/desktopbe/desktopbackend.cxx | 119 |
1 files changed, 117 insertions, 2 deletions
diff --git a/shell/source/backends/desktopbe/desktopbackend.cxx b/shell/source/backends/desktopbe/desktopbackend.cxx index 64f06a387f88..f4a21699f094 100644 --- a/shell/source/backends/desktopbe/desktopbackend.cxx +++ b/shell/source/backends/desktopbe/desktopbackend.cxx @@ -42,9 +42,12 @@ #include "cppuhelper/implementationentry.hxx" #include "cppuhelper/weak.hxx" #include "osl/diagnose.h" +#include "osl/file.hxx" +#include "osl/security.hxx" #include "rtl/string.h" #include "rtl/textenc.h" #include "rtl/ustring.h" +#include "rtl/ustrbuf.hxx" #include "rtl/ustring.hxx" #include "sal/types.h" #include "uno/current_context.hxx" @@ -148,17 +151,128 @@ void Default::setPropertyValue(OUString const &, css::uno::Any const &) static_cast< cppu::OWeakObject * >(this), -1); } +static OUString xdg_user_dir_lookup (const char *type) +{ + char *config_home; + char *p; + bool bError = false; + + osl::Security aSecurity; + oslFileHandle handle; + OUString aHomeDirURL; + OUString aDocumentsDirURL; + OUString aConfigFileURL; + OUStringBuffer aUserDirBuf; + + if (!aSecurity.getHomeDir( aHomeDirURL ) ) + { + osl::FileBase::getFileURLFromSystemPath(OUString("/tmp"), aDocumentsDirURL); + return aDocumentsDirURL; + } + + config_home = getenv ("XDG_CONFIG_HOME"); + if (config_home == NULL || config_home[0] == 0) + { + aConfigFileURL = aHomeDirURL + "/.config/user-dirs.dirs"; + } + else + { + aConfigFileURL = OUString::createFromAscii(config_home) + "/user-dirs.dirs"; + } + + if(osl_File_E_None == osl_openFile(aConfigFileURL.pData, &handle, osl_File_OpenFlag_Read)) + { + rtl::ByteSequence seq; + while (osl_File_E_None == osl_readLine(handle , reinterpret_cast<sal_Sequence **>(&seq))) + { + /* Remove newline at end */ + int relative = 0; + int len = seq.getLength(); + if(len>0 && seq[len-1] == '\n') + seq[len-1] = 0; + + p = reinterpret_cast<char *>(seq.getArray()); + while (*p == ' ' || *p == '\t') + p++; + if (strncmp (p, "XDG_", 4) != 0) + continue; + p += 4; + if (strncmp (p, type, strlen (type)) != 0) + continue; + p += strlen (type); + if (strncmp (p, "_DIR", 4) != 0) + continue; + p += 4; + while (*p == ' ' || *p == '\t') + p++; + if (*p != '=') + continue; + p++; + while (*p == ' ' || *p == '\t') + p++; + if (*p != '"') + continue; + p++; + if (strncmp (p, "$HOME/", 6) == 0) + { + p += 6; + relative = 1; + } + else if (*p != '/') + continue; + if (relative) + { + aUserDirBuf = OUStringBuffer(aHomeDirURL + "/"); + } + else + { + aUserDirBuf = OUStringBuffer(); + } + while (*p && *p != '"') + { + if ((*p == '\\') && (*(p+1) != 0)) + p++; + aUserDirBuf.append((sal_Unicode)*p++); + } + }//end of while + osl_closeFile(handle); + } + else + bError = true; + if (aUserDirBuf.getLength()>0 && !bError) + { + aDocumentsDirURL = aUserDirBuf.makeStringAndClear(); + osl::Directory aDocumentsDir( aDocumentsDirURL ); + if( osl::FileBase::E_None == aDocumentsDir.open() ) + return aDocumentsDirURL; + } + /* Use fallbacks historical compatibility if nothing else exists */ + return aHomeDirURL + "/" + OUString::createFromAscii(type); +} + css::uno::Any Default::getPropertyValue(OUString const & PropertyName) throw ( css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) { + if (PropertyName == "TemplatePathVariable") + { + OUString aDirURL = xdg_user_dir_lookup("Templates"); + css::uno::Any aValue(aDirURL); + return css::uno::makeAny(css::beans::Optional<css::uno::Any>(true, aValue)); + } + + if (PropertyName == "WorkPathVariable") + { + OUString aDirURL = xdg_user_dir_lookup("Documents"); + css::uno::Any aValue(aDirURL); + return css::uno::makeAny(css::beans::Optional<css::uno::Any>(true, aValue)); + } + if ( PropertyName == "EnableATToolSupport" || PropertyName == "ExternalMailer" || PropertyName == "SourceViewFontHeight" || PropertyName == "SourceViewFontName" || - PropertyName == "TemplatePathVariable" || - PropertyName == "WorkPathVariable" || PropertyName == "ooInetFTPProxyName" || PropertyName == "ooInetFTPProxyPort" || PropertyName == "ooInetHTTPProxyName" || @@ -172,6 +286,7 @@ css::uno::Any Default::getPropertyValue(OUString const & PropertyName) { return css::uno::makeAny(css::beans::Optional< css::uno::Any >()); } + throw css::beans::UnknownPropertyException( PropertyName, static_cast< cppu::OWeakObject * >(this)); } |