diff options
author | Kurt Zenker <kz@openoffice.org> | 2007-06-19 15:12:44 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2007-06-19 15:12:44 +0000 |
commit | 55c4b666e952c7082b6bba58210ac6498793f60c (patch) | |
tree | aa117da02844ac2c78ba0dd1ef8d70a4756db24d /shell/source/unix/sysshell/systemshell.cxx | |
parent | b054a28658f986737110ccc3296fe8026066c37e (diff) |
INTEGRATION: CWS obr05 (1.7.44); FILE MERGED
2007/06/07 13:46:02 obr 1.7.44.1: #i75190# add support for GtkRecentManager
Diffstat (limited to 'shell/source/unix/sysshell/systemshell.cxx')
-rw-r--r-- | shell/source/unix/sysshell/systemshell.cxx | 113 |
1 files changed, 98 insertions, 15 deletions
diff --git a/shell/source/unix/sysshell/systemshell.cxx b/shell/source/unix/sysshell/systemshell.cxx index ceb1305700..440a7ac940 100644 --- a/shell/source/unix/sysshell/systemshell.cxx +++ b/shell/source/unix/sysshell/systemshell.cxx @@ -4,9 +4,9 @@ * * $RCSfile: systemshell.cxx,v $ * - * $Revision: 1.7 $ + * $Revision: 1.8 $ * - * last change: $Author: obo $ $Date: 2006-09-17 01:42:56 $ + * last change: $Author: kz $ $Date: 2007-06-19 16:12:44 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -40,10 +40,62 @@ #include "systemshell.hxx" #endif +#include <comphelper/processfactory.hxx> + +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_Hpp_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif + +#ifndef _COM_SUN_STAR_URI_XEXTERNALURIREFERENCETRANSLATOR_HPP_ +#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp> +#endif + +#ifndef _COM_SUN_STAR_URI_EXTERNALURIREFERENCETRANSLATOR_HPP_ +#include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp> +#endif + +#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HPP_ +#include <com/sun/star/uno/XComponentContext.hpp> +#endif + #include "osl/module.hxx" -const rtl::OUString SYM_ADD_TO_RECENTLY_USED_FILE_LIST = rtl::OUString::createFromAscii("add_to_recently_used_file_list"); -const rtl::OUString LIB_RECENT_FILE = rtl::OUString::createFromAscii("librecentfile.so"); +using namespace ::com::sun::star; + +#define UNISTRING(s) rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)) + +const rtl::OUString SYM_ADD_TO_RECENTLY_USED_FILE_LIST = UNISTRING("add_to_recently_used_file_list"); +const rtl::OUString LIB_RECENT_FILE = UNISTRING("librecentfile.so"); +const rtl::OUString DEFAULT_CONTEXT = UNISTRING("DefaultContext"); + +void * (* sym_gtk_recent_manager_get_default) () = NULL; +void (* sym_gtk_recent_manager_add_item) (void *, const char *) = NULL; + +// We need to re-encode file urls because osl_getFileURLFromSystemPath converts +// to UTF-8 before encoding non ascii characters, which is not what other apps expect. +static rtl::OUString translateToExternalUrl(const rtl::OUString& internalUrl) +{ + rtl::OUString extUrl; + + uno::Reference< lang::XMultiServiceFactory > sm = comphelper::getProcessServiceFactory(); + if (sm.is()) + { + uno::Reference< beans::XPropertySet > pset; + sm->queryInterface( getCppuType( &pset )) >>= pset; + if (pset.is()) + { + uno::Reference< uno::XComponentContext > context; + pset->getPropertyValue(DEFAULT_CONTEXT) >>= context; + if (context.is()) + extUrl = uri::ExternalUriReferenceTranslator::create(context)->translateToExternal(internalUrl); + } + } + return extUrl; +} namespace SystemShell { @@ -62,24 +114,55 @@ namespace SystemShell { return url; } + bool init_recent_manager_api() + { + oslModule hDefault; + if( osl_getModuleHandle( NULL, &hDefault ) ) + { + sym_gtk_recent_manager_get_default = (void * (*)()) + osl_getAsciiFunctionSymbol(hDefault, "gtk_recent_manager_get_default"); + sym_gtk_recent_manager_add_item = (void (*)(void *, const char *)) + osl_getAsciiFunctionSymbol(hDefault, "gtk_recent_manager_add_item"); + + } + bool ret = (NULL != sym_gtk_recent_manager_get_default) && (NULL != sym_gtk_recent_manager_add_item); + return ret; + } + + //############################## void AddToRecentDocumentList(const rtl::OUString& aFileUrl, const rtl::OUString& aMimeType) { - rtl::OUString librecentfile_url = get_absolute_library_url(LIB_RECENT_FILE); + static bool bIsRecentManagerPresent = init_recent_manager_api(); - if (librecentfile_url.getLength()) + // Convert file URL for external use (see above) + rtl::OUString externalUrl = translateToExternalUrl(aFileUrl); + if( 0 == externalUrl.getLength() ) + externalUrl = aFileUrl; + + if( bIsRecentManagerPresent ) { - osl::Module module(librecentfile_url); - - if (module.is()) + void * recent_manager = sym_gtk_recent_manager_get_default(); + sym_gtk_recent_manager_add_item(recent_manager, rtl::OUStringToOString(aFileUrl, RTL_TEXTENCODING_UTF8).getStr()); + } + else + { + rtl::OUString librecentfile_url = get_absolute_library_url(LIB_RECENT_FILE); + + if (librecentfile_url.getLength()) { - // convert from reinterpret_cast<PFUNC_ADD_TO_RECENTLY_USED_LIST> - // not allowed in gcc 3.3 without permissive. - PFUNC_ADD_TO_RECENTLY_USED_LIST add_to_recently_used_file_list = - reinterpret_cast<PFUNC_ADD_TO_RECENTLY_USED_LIST>(module.getFunctionSymbol(SYM_ADD_TO_RECENTLY_USED_FILE_LIST)); + osl::Module module(librecentfile_url); + + if (module.is()) + { + // convert from reinterpret_cast<PFUNC_ADD_TO_RECENTLY_USED_LIST> + // not allowed in gcc 3.3 without permissive. + PFUNC_ADD_TO_RECENTLY_USED_LIST add_to_recently_used_file_list = + reinterpret_cast<PFUNC_ADD_TO_RECENTLY_USED_LIST>(module.getFunctionSymbol(SYM_ADD_TO_RECENTLY_USED_FILE_LIST)); - if (add_to_recently_used_file_list) - add_to_recently_used_file_list(aFileUrl, aMimeType); + if (add_to_recently_used_file_list) + add_to_recently_used_file_list(aFileUrl, aMimeType); + } } } } |