summaryrefslogtreecommitdiff
path: root/shell/source/unix
diff options
context:
space:
mode:
Diffstat (limited to 'shell/source/unix')
-rw-r--r--shell/source/unix/exec/makefile.mk90
-rw-r--r--shell/source/unix/exec/shellexec.cxx331
-rw-r--r--shell/source/unix/exec/shellexec.hxx80
-rw-r--r--shell/source/unix/exec/shellexecentry.cxx137
-rw-r--r--shell/source/unix/exec/syssh.xml33
-rw-r--r--shell/source/unix/exec/urltest.cxx154
-rw-r--r--shell/source/unix/exec/urltest.sh2
-rw-r--r--shell/source/unix/exec/urltest.txt11
-rwxr-xr-xshell/source/unix/misc/cde-open-url.sh13
-rw-r--r--shell/source/unix/misc/gnome-open-url.c148
-rw-r--r--shell/source/unix/misc/gnome-open-url.sh6
-rwxr-xr-xshell/source/unix/misc/kde-open-url.sh10
-rw-r--r--shell/source/unix/misc/makefile.mk90
-rw-r--r--shell/source/unix/misc/open-url.c174
-rw-r--r--shell/source/unix/misc/open-url.def1
-rwxr-xr-xshell/source/unix/misc/open-url.sh93
-rw-r--r--shell/source/unix/misc/senddoc.c206
-rw-r--r--shell/source/unix/misc/senddoc.def1
-rw-r--r--shell/source/unix/misc/senddoc.sh408
-rw-r--r--shell/source/unix/misc/uri-encode.c53
-rw-r--r--shell/source/unix/sysshell/makefile.mk75
-rw-r--r--shell/source/unix/sysshell/recently_used_file.cxx149
-rw-r--r--shell/source/unix/sysshell/recently_used_file.hxx71
-rw-r--r--shell/source/unix/sysshell/recently_used_file_handler.cxx529
-rwxr-xr-xshell/source/unix/sysshell/recfile.map6
25 files changed, 2871 insertions, 0 deletions
diff --git a/shell/source/unix/exec/makefile.mk b/shell/source/unix/exec/makefile.mk
new file mode 100644
index 000000000000..4bf77436f668
--- /dev/null
+++ b/shell/source/unix/exec/makefile.mk
@@ -0,0 +1,90 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJNAME=shell
+TARGET=exec
+
+LIBTARGET=NO
+ENABLE_EXCEPTIONS=TRUE
+
+COMP1TYPELIST=syssh
+
+TESTAPP1=urltest
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+# --- Files --------------------------------------------------------
+
+DLLPRE=
+
+SLOFILES=$(SLO)$/shellexec.obj\
+ $(SLO)$/shellexecentry.obj
+
+SHL1OBJS=$(SLOFILES)
+
+SHL1TARGET=syssh.uno
+.IF "$(GUI)" == "OS2"
+SHL1IMPLIB=i$(TARGET)
+.ELSE
+SHL1IMPLIB=
+.ENDIF
+
+SHL1VERSIONMAP=$(SOLARENV)/src/component.map
+SHL1DEF=$(MISC)$/$(SHL1TARGET).def
+DEF1NAME=$(SHL1TARGET)
+
+SHL1STDLIBS=$(CPPULIB)\
+ $(CPPUHELPERLIB)\
+ $(SALLIB)
+SHL1LIBS=
+SHL1DEPN=
+
+.IF "$(test)" != ""
+
+APP1TARGET=$(TESTAPP1)
+APP1STDLIBS= $(SHL1STDLIBS)
+APP1OBJS= \
+ $(SLO)$/shellexec.obj \
+ $(SLO)$/$(APP1TARGET).obj
+
+.ENDIF # "$(test)" != ""
+
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+run_test : $(BIN)$/$(TESTAPP1).sh
+ dmake test=t
+ $(BIN)$/$(TESTAPP1) urltest.txt
+
+$(BIN)$/$(TESTAPP1).sh : $$(@:f)
+ $(COPY) $< $@
+ -chmod +x $@
diff --git a/shell/source/unix/exec/shellexec.cxx b/shell/source/unix/exec/shellexec.cxx
new file mode 100644
index 000000000000..8d9152ae0c40
--- /dev/null
+++ b/shell/source/unix/exec/shellexec.cxx
@@ -0,0 +1,331 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_shell.hxx"
+#include <osl/diagnose.h>
+#include <osl/thread.h>
+#include <osl/process.h>
+#include <osl/file.hxx>
+#include <rtl/ustrbuf.hxx>
+
+#include <rtl/uri.hxx>
+#include "shellexec.hxx"
+#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
+
+#include <com/sun/star/util/XMacroExpander.hpp>
+#include <com/sun/star/uri/XExternalUriReferenceTranslator.hpp>
+#include <com/sun/star/uri/ExternalUriReferenceTranslator.hpp>
+
+#include "uno/current_context.hxx"
+
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+
+//------------------------------------------------------------------------
+// namespace directives
+//------------------------------------------------------------------------
+
+using com::sun::star::system::XSystemShellExecute;
+using com::sun::star::system::SystemShellExecuteException;
+
+using rtl::OString;
+using rtl::OUString;
+using rtl::OStringBuffer;
+using rtl::OUStringBuffer;
+using osl::FileBase;
+
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::system::SystemShellExecuteFlags;
+using namespace cppu;
+
+//------------------------------------------------------------------------
+// defines
+//------------------------------------------------------------------------
+
+#define SHELLEXEC_IMPL_NAME "com.sun.star.comp.system.SystemShellExecute2"
+
+//------------------------------------------------------------------------
+// helper functions
+//------------------------------------------------------------------------
+
+namespace // private
+{
+ Sequence< OUString > SAL_CALL ShellExec_getSupportedServiceNames()
+ {
+ Sequence< OUString > aRet(1);
+ aRet[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sys.shell.SystemShellExecute"));
+ return aRet;
+ }
+}
+
+void escapeForShell( rtl::OStringBuffer & rBuffer, const rtl::OString & rURL)
+{
+ sal_Int32 nmax = rURL.getLength();
+ for(sal_Int32 n=0; n < nmax; ++n)
+ {
+ // escape every non alpha numeric characters (excluding a few "known good") by prepending a '\'
+ sal_Char c = rURL[n];
+#ifndef OS2 // YD shell does not support escaped chars
+ if( ( c < 'A' || c > 'Z' ) && ( c < 'a' || c > 'z' ) && ( c < '0' || c > '9' ) && c != '/' && c != '.' )
+ rBuffer.append( '\\' );
+#endif
+
+ rBuffer.append( c );
+ }
+}
+
+//-----------------------------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------------------------
+
+ShellExec::ShellExec( const Reference< XComponentContext >& xContext ) :
+ WeakImplHelper2< XSystemShellExecute, XServiceInfo >(),
+ m_xContext(xContext)
+{
+ try {
+ Reference< XCurrentContext > xCurrentContext(getCurrentContext());
+
+ if (xCurrentContext.is())
+ {
+ Any aValue = xCurrentContext->getValueByName(
+ OUString( RTL_CONSTASCII_USTRINGPARAM( "system.desktop-environment" ) ) );
+
+ OUString aDesktopEnvironment;
+ if (aValue >>= aDesktopEnvironment)
+ {
+ m_aDesktopEnvironment = OUStringToOString(aDesktopEnvironment, RTL_TEXTENCODING_ASCII_US);
+ }
+ }
+ } catch (RuntimeException e) {
+ }
+}
+
+//-------------------------------------------------
+//
+//-------------------------------------------------
+
+void SAL_CALL ShellExec::execute( const OUString& aCommand, const OUString& aParameter, sal_Int32 nFlags )
+ throw (IllegalArgumentException, SystemShellExecuteException, RuntimeException)
+{
+ OStringBuffer aBuffer, aLaunchBuffer;
+
+ // DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html
+ static const char *pDesktopLaunch = getenv( "DESKTOP_LAUNCH" );
+
+ // Check wether aCommand contains a document url or not
+ sal_Int32 nIndex = aCommand.indexOf( OUString( RTL_CONSTASCII_USTRINGPARAM(":/") ) );
+
+ if( nIndex > 0 || 0 == aCommand.compareToAscii("mailto:", 7) )
+ {
+ // It seems to be a url ..
+ // 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.
+ OUString aURL(
+ com::sun::star::uri::ExternalUriReferenceTranslator::create(
+ m_xContext)->translateToExternal(aCommand));
+ if ( aURL.getLength() == 0 && aCommand.getLength() != 0 )
+ {
+ throw RuntimeException(
+ (OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "Cannot translate URI reference to external format: "))
+ + aCommand),
+ static_cast< cppu::OWeakObject * >(this));
+ }
+
+#ifdef MACOSX
+ aBuffer.append("open");
+#else
+ // The url launchers are expected to be in the $OOO_BASE_DIR/program
+ // directory:
+ com::sun::star::uno::Reference< com::sun::star::util::XMacroExpander >
+ exp;
+ if (!(m_xContext->getValueByName(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "/singletons/com.sun.star.util.theMacroExpander")))
+ >>= exp)
+ || !exp.is())
+ {
+ throw SystemShellExecuteException(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM(
+ "component context fails to supply singleton"
+ " com.sun.star.util.theMacroExpander of type"
+ " com.sun.star.util.XMacroExpander")),
+ static_cast< XSystemShellExecute * >(this), ENOENT);
+ }
+ OUString aProgramURL;
+ try {
+ aProgramURL = exp->expandMacros(
+ rtl::OUString(
+ RTL_CONSTASCII_USTRINGPARAM("$OOO_BASE_DIR/program/")));
+ } catch (com::sun::star::lang::IllegalArgumentException &)
+ {
+ throw SystemShellExecuteException(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("Could not expand $OOO_BASE_DIR path")),
+ static_cast < XSystemShellExecute * > (this), ENOENT );
+ }
+
+ OUString aProgram;
+ if ( FileBase::E_None != FileBase::getSystemPathFromFileURL(aProgramURL, aProgram))
+ {
+ throw SystemShellExecuteException(
+ OUString(RTL_CONSTASCII_USTRINGPARAM("Cound not convert executable path")),
+ static_cast < XSystemShellExecute * > (this), ENOENT );
+ }
+
+#ifdef OS2
+ OStringBuffer aProg = OUStringToOString(aProgram, osl_getThreadTextEncoding());
+ aProg.append("open-url.exe");
+ OString aUrl = OUStringToOString(aURL, osl_getThreadTextEncoding());
+ if ( -1 == spawnl(P_NOWAIT, aProg.getStr(), aProg.getStr(), aUrl.getStr() , NULL) )
+ {
+ int nerr = errno;
+ throw SystemShellExecuteException(OUString::createFromAscii( strerror( nerr ) ),
+ static_cast < XSystemShellExecute * > (this), nerr );
+ }
+ return;
+#endif
+
+ OString aTmp = OUStringToOString(aProgram, osl_getThreadTextEncoding());
+ escapeForShell(aBuffer, aTmp);
+
+#ifdef SOLARIS
+ if ( m_aDesktopEnvironment.getLength() == 0 )
+ m_aDesktopEnvironment = OString("GNOME");
+#endif
+
+ // Respect the desktop environment - if there is an executable named
+ // <desktop-environement-is>-open-url, pass the url to this one instead
+ // of the default "open-url" script.
+ if ( m_aDesktopEnvironment.getLength() > 0 )
+ {
+ OString aDesktopEnvironment(m_aDesktopEnvironment.toAsciiLowerCase());
+ OStringBuffer aCopy(aTmp);
+
+ aCopy.append(aDesktopEnvironment);
+ aCopy.append("-open-url");
+
+ if ( 0 == access( aCopy.getStr(), X_OK) )
+ {
+ aBuffer.append(aDesktopEnvironment);
+ aBuffer.append("-");
+
+ /* CDE requires file urls to be decoded */
+ if ( m_aDesktopEnvironment.equals("CDE") && 0 == aURL.compareToAscii("file://", 7) )
+ {
+ aURL = rtl::Uri::decode(aURL, rtl_UriDecodeWithCharset, osl_getThreadTextEncoding());
+ }
+ }
+ }
+
+ aBuffer.append("open-url");
+#endif
+ aBuffer.append(" ");
+ escapeForShell(aBuffer, OUStringToOString(aURL, osl_getThreadTextEncoding()));
+
+ if ( pDesktopLaunch && *pDesktopLaunch )
+ {
+ aLaunchBuffer.append( pDesktopLaunch );
+ aLaunchBuffer.append(" ");
+ escapeForShell(aLaunchBuffer, OUStringToOString(aURL, osl_getThreadTextEncoding()));
+ }
+ } else {
+ escapeForShell(aBuffer, OUStringToOString(aCommand, osl_getThreadTextEncoding()));
+ aBuffer.append(" ");
+ if( nFlags != 42 )
+ escapeForShell(aBuffer, OUStringToOString(aParameter, osl_getThreadTextEncoding()));
+ else
+ aBuffer.append(OUStringToOString(aParameter, osl_getThreadTextEncoding()));
+ }
+
+ // Prefer DESKTOP_LAUNCH when available
+ if ( aLaunchBuffer.getLength() > 0 )
+ {
+ FILE *pLaunch = popen( aLaunchBuffer.makeStringAndClear().getStr(), "w" );
+ if ( pLaunch != NULL )
+ {
+ if ( 0 == pclose( pLaunch ) )
+ return;
+ }
+ // Failed, do not try DESKTOP_LAUNCH any more
+ pDesktopLaunch = NULL;
+ }
+
+ OString cmd = aBuffer.makeStringAndClear();
+ if ( 0 != pclose(popen(cmd.getStr(), "w")) )
+ {
+ int nerr = errno;
+ throw SystemShellExecuteException(OUString::createFromAscii( strerror( nerr ) ),
+ static_cast < XSystemShellExecute * > (this), nerr );
+ }
+}
+
+
+// -------------------------------------------------
+// XServiceInfo
+// -------------------------------------------------
+
+OUString SAL_CALL ShellExec::getImplementationName( )
+ throw( RuntimeException )
+{
+ return OUString(RTL_CONSTASCII_USTRINGPARAM( SHELLEXEC_IMPL_NAME ));
+}
+
+// -------------------------------------------------
+// XServiceInfo
+// -------------------------------------------------
+
+sal_Bool SAL_CALL ShellExec::supportsService( const OUString& ServiceName )
+ throw( RuntimeException )
+{
+ Sequence < OUString > SupportedServicesNames = ShellExec_getSupportedServiceNames();
+
+ for ( sal_Int32 n = SupportedServicesNames.getLength(); n--; )
+ if (SupportedServicesNames[n].compareTo(ServiceName) == 0)
+ return sal_True;
+
+ return sal_False;
+}
+
+// -------------------------------------------------
+// XServiceInfo
+// -------------------------------------------------
+
+Sequence< OUString > SAL_CALL ShellExec::getSupportedServiceNames( )
+ throw( RuntimeException )
+{
+ return ShellExec_getSupportedServiceNames();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/exec/shellexec.hxx b/shell/source/unix/exec/shellexec.hxx
new file mode 100644
index 000000000000..ebc729886a26
--- /dev/null
+++ b/shell/source/unix/exec/shellexec.hxx
@@ -0,0 +1,80 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _SHELLEXEC_HXX_
+#define _SHELLEXEC_HXX_
+
+#include <cppuhelper/implbase2.hxx>
+#include <osl/mutex.hxx>
+#include <rtl/strbuf.hxx>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+
+#include <com/sun/star/system/XSystemShellExecute.hpp>
+
+//----------------------------------------------------------
+// class declaration
+//----------------------------------------------------------
+
+class ShellExec : public ::cppu::WeakImplHelper2< com::sun::star::system::XSystemShellExecute, com::sun::star::lang::XServiceInfo >
+{
+ ::rtl::OString m_aDesktopEnvironment;
+ ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >
+ m_xContext;
+
+public:
+ ShellExec(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext);
+
+ //------------------------------------------------
+ // XSystemShellExecute
+ //------------------------------------------------
+
+ virtual void SAL_CALL execute( const ::rtl::OUString& aCommand, const ::rtl::OUString& aParameter, sal_Int32 nFlags )
+ throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::system::SystemShellExecuteException, ::com::sun::star::uno::RuntimeException);
+
+ //------------------------------------------------
+ // XServiceInfo
+ //------------------------------------------------
+
+ virtual ::rtl::OUString SAL_CALL getImplementationName( )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName )
+ throw(::com::sun::star::uno::RuntimeException);
+
+ virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( )
+ throw(::com::sun::star::uno::RuntimeException);
+};
+
+
+// helper function - needed for urltest
+void escapeForShell( rtl::OStringBuffer & rBuffer, const rtl::OString & rURL);
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/exec/shellexecentry.cxx b/shell/source/unix/exec/shellexecentry.cxx
new file mode 100644
index 000000000000..d3125f89cb89
--- /dev/null
+++ b/shell/source/unix/exec/shellexecentry.cxx
@@ -0,0 +1,137 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_shell.hxx"
+
+//-----------------------------------------------------------------------
+// includes of other projects
+//-----------------------------------------------------------------------
+#include <cppuhelper/factory.hxx>
+#include <osl/diagnose.h>
+#include "shellexec.hxx"
+
+//-----------------------------------------------------------------------
+// namespace directives
+//-----------------------------------------------------------------------
+
+using namespace ::rtl;
+using namespace ::com::sun::star::uno;
+using namespace ::com::sun::star::lang;
+using namespace ::com::sun::star::registry;
+using namespace ::cppu;
+using com::sun::star::system::XSystemShellExecute;
+
+//-----------------------------------------------------------------------
+// defines
+//-----------------------------------------------------------------------
+
+#define SHELLEXEC_SERVICE_NAME "com.sun.star.system.SystemShellExecute"
+#define SHELLEXEC_IMPL_NAME "com.sun.star.comp.system.SystemShellExecute"
+#define SHELLEXEC_REGKEY_NAME "/com.sun.star.comp.system.SystemShellExecute/UNO/SERVICES/com.sun.star.system.SystemShellExecute"
+
+//-----------------------------------------------------------------------
+//
+//-----------------------------------------------------------------------
+
+namespace
+{
+ Reference< XInterface > SAL_CALL createInstance(const Reference< XComponentContext >& xContext)
+ {
+ return Reference< XInterface >( static_cast< XSystemShellExecute* >( new ShellExec(xContext) ) );
+ }
+}
+
+//-----------------------------------------------------------------------
+// the 3 important functions which will be exported
+//-----------------------------------------------------------------------
+
+extern "C"
+{
+
+//----------------------------------------------------------------------
+// component_getImplementationEnvironment
+//----------------------------------------------------------------------
+
+void SAL_CALL component_getImplementationEnvironment(
+ const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
+{
+ *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+}
+
+//-----------------------------------------------------------------------
+// component_writeInfo
+//-----------------------------------------------------------------------
+
+sal_Bool SAL_CALL component_writeInfo( void* /*pServiceManager*/, void* pRegistryKey )
+{
+ if (pRegistryKey)
+ {
+ try
+ {
+ Reference< XRegistryKey > pXNewKey( static_cast< XRegistryKey* >( pRegistryKey ) );
+ pXNewKey->createKey( OUString( RTL_CONSTASCII_USTRINGPARAM( SHELLEXEC_REGKEY_NAME ) ) );
+ return sal_True;
+ }
+ catch( InvalidRegistryException& )
+ {
+ OSL_ENSURE(sal_False, "InvalidRegistryException caught");
+ }
+ }
+
+ return sal_False;
+}
+
+//----------------------------------------------------------------------
+// component_getFactory
+//----------------------------------------------------------------------
+
+void* SAL_CALL component_getFactory( const sal_Char* pImplName, uno_Interface* /*pSrvManager*/, uno_Interface* /*pRegistryKey*/ )
+{
+ Reference< XSingleComponentFactory > xFactory;
+
+ if (0 == ::rtl_str_compare( pImplName, SHELLEXEC_IMPL_NAME ))
+ {
+ OUString serviceName( RTL_CONSTASCII_USTRINGPARAM(SHELLEXEC_SERVICE_NAME) );
+
+ xFactory = ::cppu::createSingleComponentFactory(
+ createInstance,
+ OUString( RTL_CONSTASCII_USTRINGPARAM(SHELLEXEC_IMPL_NAME) ),
+ Sequence< OUString >( &serviceName, 1 ) );
+
+ }
+
+ if (xFactory.is())
+ xFactory->acquire();
+
+ return xFactory.get();
+}
+
+} // extern "C"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/exec/syssh.xml b/shell/source/unix/exec/syssh.xml
new file mode 100644
index 000000000000..5c72befa9141
--- /dev/null
+++ b/shell/source/unix/exec/syssh.xml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE module-description PUBLIC "-//StarOffice//DTD ComponentDescription 1.0//EN" "module-description.dtd">
+<module-description xmlns:xlink="http://www.w3.org/1999/xlink">
+ <module-name>syssh</module-name>
+ <component-description>
+ <author> Oliver Braun </author>
+ <name>com.sun.star.comp.system.SystemShellExecute</name>
+ <description> The unix implementation of a SystemShellExecute service. </description>
+ <loader-name>com.sun.star.loader.SharedLibrary</loader-name>
+ <language>c++</language>
+ <status value="beta"/>
+ <supported-service>com.sun.star.system.SystemShellExecute</supported-service>
+ <service-dependency>...</service-dependency>
+ <type>com.sun.star.system.XSystemShellExecute</type>
+ <type>com.sun.star.system.SystemShellExecuteException</type>
+ <type>com.sun.star.system.SystemShellExecuteFlags</type>
+ <type>com.sun.star.lang.IllegalArgumentException</type>
+ <type>com.sun.star.lang.XServiceInfo</type>
+ <type>com.sun.star.lang.XSingleComponentFactory</type>
+ <type>com.sun.star.lang.XTypeProvider</type>
+ <type>com.sun.star.uno.TypeClass</type>
+ <type>com.sun.star.uno.XAggregation</type>
+ <type>com.sun.star.uno.XComponentContext</type>
+ <type>com.sun.star.uno.XWeak</type>
+ <type>com.sun.star.registry.XRegistryKey</type>
+ </component-description>
+ <project-build-dependency>cppuhelper</project-build-dependency>
+ <project-build-dependency>cppu</project-build-dependency>
+ <project-build-dependency>sal</project-build-dependency>
+ <runtime-module-dependency>cppuhelper3$(COM)</runtime-module-dependency>
+ <runtime-module-dependency>cppu3</runtime-module-dependency>
+ <runtime-module-dependency>sal3</runtime-module-dependency>
+</module-description>
diff --git a/shell/source/unix/exec/urltest.cxx b/shell/source/unix/exec/urltest.cxx
new file mode 100644
index 000000000000..e79a321eff36
--- /dev/null
+++ b/shell/source/unix/exec/urltest.cxx
@@ -0,0 +1,154 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "shellexec.hxx"
+
+#include <osl/process.h>
+
+#include <stdio.h>
+#include <limits.h>
+#include <string.h>
+#include <strings.h>
+
+// -----------------------------------------------------------------------
+
+int main(int argc, const char *argv[])
+{
+ int ret = 0;
+
+ if( argc != 2 )
+ {
+ fprintf(stderr, "Usage: urltest <urllist>\n");
+ return -1;
+ }
+
+ FILE * fp = fopen( argv[1], "r" );
+ if( NULL == fp )
+ {
+ perror( argv[1] );
+ return -1;
+ }
+
+ // expect urltest.sh beside this binary
+ char line[LINE_MAX];
+ size_t len = strlen(argv[0]);
+ strcpy( line, argv[0] );
+ strcpy( line + len, ".sh " );
+ len += 4;
+
+ unsigned int errors = 0;
+
+ // read url(s) to test from file
+ char url[512];
+ while( NULL != fgets(url, sizeof(url), fp))
+ {
+ // remove trailing line break
+ strtok( url, "\r\n" );
+
+ printf( "Passing URL: %s\n", url );
+
+ // test the encoding functionality from shellexec.cxx
+ rtl::OString aURL( url );
+ rtl::OStringBuffer aBuffer;
+ escapeForShell(aBuffer, aURL);
+
+ // append encoded URL as (only) parameter to the script
+ strcpy( line + len, aBuffer.getStr() );
+
+ printf( "Command line: %s\n", line );
+
+ FILE * pipe = popen( line, "r" );
+ if( NULL != pipe )
+ {
+ char buffer[BUFSIZ];
+
+ // initialize buffer with '\0'
+ memset(buffer, '\0', BUFSIZ);
+
+ // read the output of the script
+ if(NULL == fgets( buffer, BUFSIZ, pipe))
+ {
+ perror("FAILED: output of script could not be read");
+ printf( "\n");
+ ++errors;
+ continue;
+ }
+
+ // remove trailing line break again
+ strtok( buffer, "\r\n" );
+
+ int n = pclose(pipe);
+ if( 0 != n )
+ {
+ printf("FAILED: fclose returned %d\n\n", n );
+ ++errors;
+ continue;
+ }
+
+ if( 0 == strcmp( url, buffer ) )
+ {
+ // strings are identical: good !
+ printf( "OK\n\n");
+ }
+ else
+ {
+ // compare failed
+ printf( "FAILED: returned string is %s\n\n", buffer);
+ ++errors;
+ }
+
+ }
+ else
+ {
+ perror( line );
+ ret = -2;
+ break;
+ }
+ }
+
+ if( ferror( fp ) )
+ {
+ perror( argv[1] );
+ ret = -1;
+ }
+
+ fclose( fp );
+
+ if( errors )
+ {
+ printf( "Number of tests failing: %d\n", errors);
+ ret = -3;
+ }
+ else
+ printf( "All tests passed OK.\n" );
+
+
+ return ret;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/exec/urltest.sh b/shell/source/unix/exec/urltest.sh
new file mode 100644
index 000000000000..ce55ee694114
--- /dev/null
+++ b/shell/source/unix/exec/urltest.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+echo "$1" \ No newline at end of file
diff --git a/shell/source/unix/exec/urltest.txt b/shell/source/unix/exec/urltest.txt
new file mode 100644
index 000000000000..e69a8cfaf92b
--- /dev/null
+++ b/shell/source/unix/exec/urltest.txt
@@ -0,0 +1,11 @@
+http://www.openoffice.org
+http://en.wiktionary.org/wiki/harmless';CMD=lsx-lx$HOME;IFS=x;$CMD;#'
+http://en.wikipedia.org/wiki/Shell_(computers)
+http://www.google.com/search?hl=$100+bill
+http://unix.t-a-y-l-o-r.com/;clear;ls
+http://www.google.com/;exec mozilla;
+http://www.yahoo.com/<>
+http://www.yahoo.com/\
+http://www.yahoo.com/"
+http://www.yahoo.com/'
+http://www.yahoo.com/;echo 'this'; \ No newline at end of file
diff --git a/shell/source/unix/misc/cde-open-url.sh b/shell/source/unix/misc/cde-open-url.sh
new file mode 100755
index 000000000000..c0c38145d6ee
--- /dev/null
+++ b/shell/source/unix/misc/cde-open-url.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+if [ -x /usr/bin/mktemp ]
+then
+ TMPFILE=`mktemp -t open-url.XXXXXX`
+else
+ DTTMPDIR=`xrdb -query | grep DtTmpDir`
+ TMPFILE=${DTTMPDIR:-$HOME/.dt/tmp}/open-url.$$
+fi
+
+if [ -z "$TMPFILE" ]; then exit 1; fi
+( echo "$1" > "$TMPFILE"; dtaction Open "$TMPFILE"; rm -f "$TMPFILE" ) &
+exit 0
diff --git a/shell/source/unix/misc/gnome-open-url.c b/shell/source/unix/misc/gnome-open-url.c
new file mode 100644
index 000000000000..b914cfcb7b5c
--- /dev/null
+++ b/shell/source/unix/misc/gnome-open-url.c
@@ -0,0 +1,148 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <dlfcn.h>
+#include <string.h>
+#include <unistd.h>
+
+typedef int gboolean;
+typedef char gchar;
+typedef struct _GError GError;
+
+struct _GError
+{
+ int domain;
+ int code;
+ char *message;
+};
+
+typedef enum {
+ GNOME_VFS_OK
+} GnomeVFSResult;
+
+
+/*
+ * HACK: avoid error messages caused by not setting a GNOME program name
+ */
+
+gchar* gnome_gconf_get_gnome_libs_settings_relative (const gchar *subkey)
+{
+ void* handle = dlopen("libglib-2.0.so.0", RTLD_LAZY);
+
+ (void)subkey; /* avoid warning due to unused parameter */
+
+ if( NULL != handle )
+ {
+ gchar* (* g_strdup)(const gchar*) = (gchar* (*)(const gchar*)) dlsym(handle, "g_strdup");
+
+ if( NULL != g_strdup)
+ return g_strdup("/apps/gnome-settings/gnome-open-url");
+ }
+
+ return NULL;
+}
+
+/*
+ * Wrapper function which extracs gnome_url_show from libgnome
+ */
+
+gboolean gnome_url_show (const char *url, GError **error)
+{
+ void* handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
+ gboolean ret = 0;
+
+ (void)error; /* avoid warning due to unused parameter */
+
+ if( NULL != handle )
+ {
+ gboolean (* init) (void) =
+ (gboolean (*) (void)) dlsym(handle, "gnome_vfs_init");
+
+ if( NULL != init && init() )
+ {
+ GnomeVFSResult (* func) (const char *url) =
+ (GnomeVFSResult (*) (const char *)) dlsym(handle, "gnome_vfs_url_show");
+
+ if( NULL != func )
+ ret = (GNOME_VFS_OK == func(url));
+ }
+
+ dlclose(handle);
+ }
+
+ return ret;
+}
+
+/*
+ * The intended use of this tool is to pass the argument to
+ * the gnome_show_url function of libgnome2.
+ */
+
+int main(int argc, char *argv[] )
+{
+ GError *error = NULL;
+ char *fallback;
+ char *index;
+ int retcode = -1;
+
+ if( argc != 2 )
+ {
+ fprintf( stderr, "Usage: gnome-open-url <uri>\n" );
+ return -1;
+ }
+
+ if( gnome_url_show(argv[1], &error) )
+ {
+ return 0;
+ }
+
+ /*
+ * launch open-url command by replacing gnome-open-url from
+ * the command line. This is the fallback when running on
+ * remote machines with no GNOME installed.
+ */
+
+ fallback = strdup(argv[0]);
+ index = strstr(fallback, "gnome-open-url");
+ if ( NULL != index )
+ {
+ char *args[3];
+ strncpy(index, "open-url", 9);
+ args[0] = fallback;
+ args[1] = argv[1];
+ args[2] = NULL;
+ retcode = execv(fallback, args);
+ }
+ free(fallback);
+
+ return retcode;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/misc/gnome-open-url.sh b/shell/source/unix/misc/gnome-open-url.sh
new file mode 100644
index 000000000000..ab730d169a49
--- /dev/null
+++ b/shell/source/unix/misc/gnome-open-url.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+# use xdg-open or gnome-open if available
+xdg-open "$1" 2>/dev/null || gnome-open "$1" 2>/dev/null || "$0.bin" $1
+
+exit 0
diff --git a/shell/source/unix/misc/kde-open-url.sh b/shell/source/unix/misc/kde-open-url.sh
new file mode 100755
index 000000000000..fa05bdecbda4
--- /dev/null
+++ b/shell/source/unix/misc/kde-open-url.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+
+# special handling for mailto: uris
+if echo $1 | grep '^mailto:' > /dev/null; then
+ kmailservice "$1" &
+else
+ kfmclient openURL "$1" &
+fi
+
+exit 0
diff --git a/shell/source/unix/misc/makefile.mk b/shell/source/unix/misc/makefile.mk
new file mode 100644
index 000000000000..c4f3d9c49551
--- /dev/null
+++ b/shell/source/unix/misc/makefile.mk
@@ -0,0 +1,90 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+PRJNAME=shell
+TARGET=misc
+
+LIBTARGET=NO
+TARGETTYPE=CUI
+NO_DEFAULT_STL=TRUE
+LIBSALCPPRT=$(0)
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+# --- Files --------------------------------------------------------
+
+SCRIPTFILES = \
+ $(BIN)$/senddoc \
+ $(BIN)$/open-url \
+ $(BIN)$/cde-open-url \
+ $(BIN)$/gnome-open-url \
+ $(BIN)$/kde-open-url
+
+.IF "$(GUI)" == "OS2"
+
+APP1TARGET = open-url
+APP1OBJS = \
+ $(OBJ)$/open-url.obj \
+ open-url.def
+APP1LIBS =
+
+APP2TARGET = senddoc
+APP2OBJS = \
+ $(OBJ)$/senddoc.obj \
+ senddoc.def
+APP2LIBS =
+APP2STDLIBS =
+
+.ELSE
+
+APP1TARGET = gnome-open-url.bin
+APP1OBJS = \
+ $(OBJ)$/gnome-open-url.obj
+APP1LIBS =
+.IF "$(OS)"!="FREEBSD" && "$(OS)"!="NETBSD" && "$(OS)"!="OPENBSD"
+APP1STDLIBS=-ldl
+.ENDIF
+
+APP2TARGET = uri-encode
+APP2OBJS = $(OBJ)$/uri-encode.obj
+APP2LIBS =
+APP2STDLIBS =
+
+OBJFILES = $(APP1OBJS) $(APP2OBJS)
+.ENDIF
+
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
+
+ALLTAR : $(SCRIPTFILES) $(AWKFILES)
+
+$(SCRIPTFILES) : $$(@:f:+".sh")
+ @tr -d "\015" < $(@:f:+".sh") > $@
diff --git a/shell/source/unix/misc/open-url.c b/shell/source/unix/misc/open-url.c
new file mode 100644
index 000000000000..7d7230f040ff
--- /dev/null
+++ b/shell/source/unix/misc/open-url.c
@@ -0,0 +1,174 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <process.h>
+#include <time.h>
+
+#define INCL_DOS
+#define INCL_DOSERRORS
+#define INCL_PM
+#include <os2.h>
+
+// OOo uses popen() to start us, so we cannot show PM dialogs.
+// log message to disk.
+void logMessage( char* msg)
+{
+ PPIB pib;
+ CHAR szApplicationName[_MAX_PATH];
+ CHAR szDrive[_MAX_PATH];
+ CHAR szDir[_MAX_PATH];
+ CHAR szFileName[_MAX_PATH];
+ CHAR szExt[_MAX_PATH];
+ FILE* log;
+ time_t timeOfDay;
+ struct tm* localTime;
+
+ // get executable fullpath
+ DosGetInfoBlocks(NULL, &pib);
+ DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName);
+ _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt );
+ // log name
+ _makepath( szApplicationName, szDrive, szDir, szFileName, (".LOG") );
+ log = fopen( szApplicationName, "a");
+ if (!log)
+ return;
+ time( &timeOfDay);
+ localTime = localtime( &timeOfDay);
+ fprintf( log, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
+ localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday,
+ localTime->tm_hour, localTime->tm_min, localTime->tm_sec, msg);
+ fclose( log);
+}
+
+// dump comand line arguments
+void dumpArgs( int argc, char *argv[] )
+{
+ int i;
+
+ logMessage( "Start of command line arguments dump:");
+ for( i=0; i<argc; i++)
+ logMessage( argv[i]);
+}
+
+/*
+ * The intended use of this tool is to pass the argument to
+ * the default URL exe.
+ */
+int main(int argc, char *argv[] )
+{
+ APIRET rc;
+ RESULTCODES result = {0};
+ char szAppFromINI[_MAX_PATH];
+ char szDirFromINI[_MAX_PATH];
+ char szCmdLine[1024];
+ char szFail[ _MAX_PATH];
+ ULONG ulSID;
+ PID pid;
+
+ // check parameters
+ if (argc != 2)
+ {
+ logMessage( "Usage: open-url <url>");
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // check configuration
+ rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
+ "DefaultBrowserExe", "",
+ szAppFromINI, sizeof(szAppFromINI));
+ rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
+ "DefaultWorkingDir", "",
+ szDirFromINI, sizeof(szDirFromINI));
+ if (*szAppFromINI == 0 || *szDirFromINI == 0)
+ {
+ logMessage( "Unable to find default url handler in USER.INI; exiting.");
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // get default parameter list
+ rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
+ "DefaultParameters", "",
+ szCmdLine, sizeof(szCmdLine));
+ strcat( szCmdLine, " ");
+ strcat( szCmdLine, argv[1]);
+
+ // change default directory
+ _chdir( szDirFromINI);
+
+ // start default handler
+ STARTDATA SData;
+ CHAR szObjBuf[CCHMAXPATH];
+
+ SData.Length = sizeof(STARTDATA);
+ SData.Related = SSF_RELATED_INDEPENDENT;
+ SData.FgBg = (1) ? SSF_FGBG_FORE : SSF_FGBG_BACK;
+ SData.TraceOpt = SSF_TRACEOPT_NONE;
+
+ SData.PgmTitle = (PSZ)szAppFromINI;
+
+ SData.PgmName = (PSZ)szAppFromINI;
+ SData.PgmInputs = (PSZ)szCmdLine;
+
+ SData.TermQ = NULL;
+ SData.Environment = 0;
+ SData.InheritOpt = SSF_INHERTOPT_PARENT;
+ SData.SessionType = SSF_TYPE_PM;
+ SData.IconFile = 0;
+ SData.PgmHandle = 0;
+
+ SData.PgmControl = SSF_CONTROL_VISIBLE;
+
+ SData.InitXPos = 30;
+ SData.InitYPos = 40;
+ SData.InitXSize = 200;
+ SData.InitYSize = 140;
+ SData.Reserved = 0;
+ SData.ObjectBuffer = szFail;
+ SData.ObjectBuffLen = (ULONG)sizeof(szFail);
+
+ rc = DosStartSession( &SData, &ulSID, &pid);
+ // show error dialog in case of problems
+ if (rc != NO_ERROR && rc != ERROR_SMG_START_IN_BACKGROUND) {
+ char szMessage[ _MAX_PATH*2];
+ sprintf( szMessage, "Execution failed! rc: %d, failing module:%s", rc, szFail);
+ logMessage( szMessage);
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // ok
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/misc/open-url.def b/shell/source/unix/misc/open-url.def
new file mode 100644
index 000000000000..3a26831e2a65
--- /dev/null
+++ b/shell/source/unix/misc/open-url.def
@@ -0,0 +1 @@
+NAME open-url WINDOWAPI
diff --git a/shell/source/unix/misc/open-url.sh b/shell/source/unix/misc/open-url.sh
new file mode 100755
index 000000000000..449af5915ce8
--- /dev/null
+++ b/shell/source/unix/misc/open-url.sh
@@ -0,0 +1,93 @@
+#!/bin/sh
+
+# tries to locate the executable specified
+# as first parameter in the user's path.
+which() {
+ if [ ! -z "$1" ]; then
+ for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
+ if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
+ echo "$i/$1"
+ break;
+ fi
+ done
+ fi
+}
+
+# checks for the original mozilla start script(s)
+# and restrict the "-remote" semantics to those.
+run_mozilla() {
+ if file "$1" | grep "script" > /dev/null && grep "NPL" "$1" > /dev/null; then
+ "$1" -remote 'ping()' 2>/dev/null >/dev/null
+ if [ $? -eq 2 ]; then
+ "$1" "$2" &
+ else
+ "$1" -remote "openURL($2, new-window)" &
+ fi
+ else
+ "$1" "$2" &
+ fi
+}
+
+# checks the browser value for a %s as defined in
+# http://www.catb.org/~esr/BROWSER/index.html
+run_browser() {
+ echo "$1|$2" | awk '
+{
+ FS="|";
+ $syscmd="";
+ if (index($1,"%s") > 0) {
+ $syscmd=sprintf($1,$2);
+ } else {
+ $syscmd=sprintf("%s \"%s\"",$1,$2);
+ }
+ system($syscmd " &");
+}' > /dev/null
+}
+
+# special handling for mailto: uris
+if echo $1 | grep '^mailto:' > /dev/null; then
+ # check for xdg-email
+ mailer=`which xdg-email`
+ if [ ! -z "$mailer" ]; then
+ $mailer "$1" &
+ exit 0
+ fi
+ # check $MAILER variable
+ if [ ! -z "$MAILER" ]; then
+ $MAILER "$1" &
+ exit 0
+ fi
+ # mozilla derivates may need -remote semantics
+ for i in thunderbird mozilla netscape; do
+ mailer=`which $i`
+ if [ ! -z "$mailer" ]; then
+ run_mozilla "$mailer" "$1"
+ exit 0
+ fi
+ done
+ # handle all non mozilla mail clients below
+ # ..
+else
+ # check for xdg-open
+ browser=`which xdg-open`
+ if [ ! -z "$browser" ]; then
+ $browser "$1" &
+ exit 0
+ fi
+ # check $BROWSER variable
+ if [ ! -z "$BROWSER" ]; then
+ $BROWSER "$1" &
+ exit 0
+ fi
+ # mozilla derivates may need -remote semantics
+ for i in firefox mozilla netscape; do
+ browser=`which $i`
+ if [ ! -z "$browser" ]; then
+ run_mozilla "$browser" "$1"
+ exit 0
+ fi
+ done
+ # handle all non mozilla browers below
+ # ..
+fi
+exit 1
diff --git a/shell/source/unix/misc/senddoc.c b/shell/source/unix/misc/senddoc.c
new file mode 100644
index 000000000000..46f5ff825f0b
--- /dev/null
+++ b/shell/source/unix/misc/senddoc.c
@@ -0,0 +1,206 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <process.h>
+#include <time.h>
+
+#define INCL_DOS
+#define INCL_DOSERRORS
+#define INCL_PM
+#include <os2.h>
+
+// OOo uses popen() to start us, so we cannot show PM dialogs.
+// log message to disk.
+void logMessage( char* msg)
+{
+ PPIB pib;
+ CHAR szApplicationName[_MAX_PATH];
+ CHAR szDrive[_MAX_PATH];
+ CHAR szDir[_MAX_PATH];
+ CHAR szFileName[_MAX_PATH];
+ CHAR szExt[_MAX_PATH];
+ FILE* log;
+ time_t timeOfDay;
+ struct tm* localTime;
+
+ // get executable fullpath
+ DosGetInfoBlocks(NULL, &pib);
+ DosQueryModuleName(pib->pib_hmte, sizeof(szApplicationName), szApplicationName);
+ _splitpath( szApplicationName, szDrive, szDir, szFileName, szExt );
+ // log name
+ _makepath( szApplicationName, szDrive, szDir, szFileName, (".LOG") );
+ log = fopen( szApplicationName, "a");
+ if (!log)
+ return;
+ time( &timeOfDay);
+ localTime = localtime( &timeOfDay);
+ fprintf( log, "%04d/%02d/%02d %02d:%02d:%02d %s\n",
+ localTime->tm_year+1900, localTime->tm_mon+1, localTime->tm_mday,
+ localTime->tm_hour, localTime->tm_min, localTime->tm_sec, msg);
+ fclose( log);
+}
+
+// dump comand line arguments
+void dumpArgs( int argc, char *argv[] )
+{
+ int i;
+
+ logMessage( "Start of command line arguments dump:");
+ for( i=0; i<argc; i++)
+ logMessage( argv[i]);
+}
+
+/*
+ * The intended use of this tool is to pass the argument to
+ * the default mail handler.
+ */
+int main(int argc, char *argv[] )
+{
+ APIRET rc;
+ RESULTCODES result = {0};
+ char szAppFromINI[_MAX_PATH];
+ char szDirFromINI[_MAX_PATH];
+ char szCmdLine[1024];
+ char szFail[ _MAX_PATH];
+ ULONG ulSID;
+ PID pid;
+ int i;
+ BOOL bMailClient = FALSE;
+
+ // check parameters
+ if (argc < 5)
+ {
+ logMessage( "Usage: senddoc --mailclient <client> --attach <uri>");
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // check configuration
+ rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
+ "DefaultMailExe", "",
+ szAppFromINI, sizeof(szAppFromINI));
+ rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
+ "DefaultMailWorkingDir", "",
+ szDirFromINI, sizeof(szDirFromINI));
+ if (*szAppFromINI == 0 || *szDirFromINI == 0)
+ {
+ logMessage( "Unable to find default mail handler in USER.INI; exiting.");
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // get default parameter list, at leat -compose is required
+ rc = PrfQueryProfileString(HINI_USER, "WPURLDEFAULTSETTINGS",
+ "DefaultMailParameters", "",
+ szCmdLine, sizeof(szCmdLine));
+ if (strstr( szCmdLine, "-compose") == 0)
+ strcat( szCmdLine, " -compose"); // add if missing!
+
+ // parse cmdline arguments
+ for( i=1; i<argc; i++)
+ {
+ if (!strcmp( argv[i], "--mailclient")) {
+ // we support only Thunderbird/Mozilla command line options, check exe name
+ if (strstr( argv[i+1], "thunderbird") == 0
+ && strstr( argv[i+1], "mozilla") == 0
+ && strstr( argv[i+1], "seamonkey") == 0)
+ {
+ logMessage( "Only Thunderbird/Mozilla is currently supported. Exiting.");
+ dumpArgs( argc, argv);
+ return -1;
+ }
+ // mail client found
+ bMailClient = TRUE;
+ i++;
+ } else if (!strcmp( argv[i], "--attach")) {
+ strcat( szCmdLine, " attachment=file://");
+ strcat( szCmdLine, argv[i+1]);
+ i++;
+ }
+ // ignore other options (BTW currently none)
+ }
+ if (bMailClient == FALSE)
+ {
+ logMessage( "No mail client specified. Exiting.");
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // change default directory
+ _chdir( szDirFromINI);
+
+ // start default handler
+ STARTDATA SData;
+ CHAR szObjBuf[CCHMAXPATH];
+
+ SData.Length = sizeof(STARTDATA);
+ SData.Related = SSF_RELATED_INDEPENDENT;
+ SData.FgBg = (1) ? SSF_FGBG_FORE : SSF_FGBG_BACK;
+ SData.TraceOpt = SSF_TRACEOPT_NONE;
+
+ SData.PgmTitle = (PSZ)szAppFromINI;
+
+ SData.PgmName = (PSZ)szAppFromINI;
+ SData.PgmInputs = (PSZ)szCmdLine;
+
+ SData.TermQ = NULL;
+ SData.Environment = 0;
+ SData.InheritOpt = SSF_INHERTOPT_PARENT;
+ SData.SessionType = SSF_TYPE_PM;
+ SData.IconFile = 0;
+ SData.PgmHandle = 0;
+
+ SData.PgmControl = SSF_CONTROL_VISIBLE;
+
+ SData.InitXPos = 30;
+ SData.InitYPos = 40;
+ SData.InitXSize = 200;
+ SData.InitYSize = 140;
+ SData.Reserved = 0;
+ SData.ObjectBuffer = szFail;
+ SData.ObjectBuffLen = (ULONG)sizeof(szFail);
+
+ rc = DosStartSession( &SData, &ulSID, &pid);
+ // show error dialog in case of problems
+ if (rc != NO_ERROR && rc != ERROR_SMG_START_IN_BACKGROUND) {
+ char szMessage[ _MAX_PATH*2];
+ sprintf( szMessage, "Execution failed! rc: %d, failing module:%s", rc, szFail);
+ logMessage( szMessage);
+ dumpArgs( argc, argv);
+ return -1;
+ }
+
+ // ok
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/misc/senddoc.def b/shell/source/unix/misc/senddoc.def
new file mode 100644
index 000000000000..0abf1553a4a9
--- /dev/null
+++ b/shell/source/unix/misc/senddoc.def
@@ -0,0 +1 @@
+NAME senddoc WINDOWAPI
diff --git a/shell/source/unix/misc/senddoc.sh b/shell/source/unix/misc/senddoc.sh
new file mode 100644
index 000000000000..9d63ae3df63b
--- /dev/null
+++ b/shell/source/unix/misc/senddoc.sh
@@ -0,0 +1,408 @@
+#!/bin/sh
+URI_ENCODE="`dirname $0`/uri-encode"
+FOPTS=""
+sd_platform=`uname -s`
+
+# linux file utility needs -L option to resolve symlinks
+if [ "$sd_platform" = "Linux" ] ; then
+ FOPTS="-L"
+fi
+
+# do not confuse the system mail clients with OOo and Java libraries
+case $sd_platform in
+ AIX)
+ unset LIBPATH
+ ;;
+ *)
+ unset LD_LIBRARY_PATH
+ ;;
+esac
+
+# tries to locate the executable specified
+# as first parameter in the user's path.
+which() {
+ if [ ! -z "$1" ]; then
+ for i in `echo $PATH | sed -e 's/^:/.:/g' -e 's/:$/:./g' -e 's/::/:.:/g' -e 's/:/ /g'`; do
+ if [ -x "$i/$1" -a ! -d "$i/$1" ]; then
+ echo "$i/$1"
+ break;
+ fi
+ done
+ fi
+}
+
+# checks for the original mozilla start script(s)
+# and restrict the "-remote" semantics to those.
+run_mozilla() {
+ # find mozilla script in PATH if necessary
+ if [ "`basename $1`" = "$1" ]; then
+ moz=`which $1`
+ else
+ moz=$1
+ fi
+
+ if file $FOPTS "$moz" | grep "script" > /dev/null && grep "[NM]PL" "$moz" > /dev/null; then
+ "$moz" -remote 'ping()' 2>/dev/null >/dev/null
+ if [ $? -eq 2 ]; then
+ "$1" -compose "$2" &
+ else
+ "$1" -remote "xfeDoCommand(composeMessage,$2)" &
+ fi
+ else
+ "$1" -compose "$2" &
+ fi
+}
+
+if [ "$1" = "--mailclient" ]; then
+ shift
+ MAILER=$1
+ shift
+fi
+
+# autodetect mail client from executable name
+case `basename "$MAILER" | sed 's/-.*$//'` in
+
+ iceape | mozilla | netscape | seamonkey | icedove | thunderbird)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ TO=${TO:-}${TO:+,}$2
+ shift
+ ;;
+ --cc)
+ CC=${CC:-}${CC:+,}$2
+ shift
+ ;;
+ --bcc)
+ BCC=${BCC:-}${BCC:+,}$2
+ shift
+ ;;
+ --subject)
+ SUBJECT=$2
+ shift
+ ;;
+ --body)
+ BODY=$2
+ shift
+ ;;
+ --attach)
+ ATTACH=${ATTACH:-}${ATTACH:+,}`echo "file://$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ if [ "$TO" != "" ]; then
+ COMMAND=${COMMAND:-}${COMMAND:+,}to=${TO}
+ fi
+ if [ "$CC" != "" ]; then
+ COMMAND=${COMMAND:-}${COMMAND:+,}cc=${CC}
+ fi
+ if [ "$BCC" != "" ]; then
+ COMMAND=${COMMAND:-}${COMMAND:+,}bcc=${BCC}
+ fi
+ if [ "$SUBJECT" != "" ]; then
+ COMMAND=${COMMAND:-}${COMMAND:+,}subject=${SUBJECT}
+ fi
+ if [ "$BODY" != "" ]; then
+ COMMAND=${COMMAND:-}${COMMAND:+,}body=${BODY}
+ fi
+ if [ "$ATTACH" != "" ]; then
+ COMMAND=${COMMAND:-}${COMMAND:+,}attachment=${ATTACH}
+ fi
+
+ run_mozilla "$MAILER" "$COMMAND"
+ ;;
+
+ kmail)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ TO="${TO:-}${TO:+,}$2"
+ shift
+ ;;
+ --cc)
+ CC="${CC:-}${CC:+,}$2"
+ shift
+ ;;
+ --bcc)
+ BCC="${BCC:-}${BCC:+,}$2"
+ shift
+ ;;
+ --subject)
+ SUBJECT="$2"
+ shift
+ ;;
+ --body)
+ BODY="$2"
+ shift
+ ;;
+ --attach)
+ ATTACH="$2"
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ ${MAILER} --composer ${CC:+--cc} ${CC:+"${CC}"} ${BCC:+--bcc} ${BCC:+"${BCC}"} \
+ ${SUBJECT:+--subject} ${SUBJECT:+"${SUBJECT}"} ${BODY:+--body} ${BODY:+"${BODY}"} \
+ ${ATTACH:+--attach} ${ATTACH:+"${ATTACH}"} ${TO:+"${TO}"}
+ ;;
+
+ mutt)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --from)
+ FROM="$2"
+ shift
+ ;;
+ --to)
+ TO="${TO:-}${TO:+,}$2"
+ shift
+ ;;
+ --cc)
+ CC="${CC:-}${CC:+,}$2"
+ shift
+ ;;
+ --bcc)
+ BCC="${BCC:-}${BCC:+,}$2"
+ shift
+ ;;
+ --subject)
+ SUBJECT="$2"
+ shift
+ ;;
+ --body)
+ TEMPLATE="`basename $0`.mutt.XXXXXXXX"
+ BODY=`mktemp -q -t ${TEMPLATE}`
+ echo "$2" > $BODY
+ shift
+ ;;
+ --attach)
+ ATTACH="$2"
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ x-terminal-emulator -e ${MAILER} \
+ ${FROM:+-e} ${FROM:+"set from=\"${FROM}\""} \
+ ${CC:+-c} ${CC:+"${CC}"} \
+ ${BCC:+-b} ${BCC:+"${BCC}"} \
+ ${SUBJECT:+-s} ${SUBJECT:+"${SUBJECT}"} \
+ ${BODY:+-i} ${BODY:+"${BODY}"} \
+ ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"} \
+ ${TO:+"${TO}"} &
+ rm -f $BODY
+ ;;
+
+ evolution)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ if [ "${TO}" != "" ]; then
+ MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
+ else
+ TO="$2"
+ fi
+ shift
+ ;;
+ --cc)
+ MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --bcc)
+ MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --subject)
+ MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --body)
+ MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --attach)
+ MAILTO="${MAILTO:-}${MAILTO:+&}attach="`echo "file://$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ MAILTO="mailto:${TO}?${MAILTO}"
+ ${MAILER} "${MAILTO}" &
+ ;;
+
+ groupwise)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ if [ "${TO}" != "" ]; then
+ MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
+ else
+ TO="$2"
+ fi
+ shift
+ ;;
+ --cc)
+ MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --bcc)
+ MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --subject)
+ MAILTO="${MAILTO:-}${MAILTO:+&}subject"=`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --body)
+ MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --attach)
+ MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "file://$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ MAILTO="mailto:${TO}?${MAILTO}"
+ ${MAILER} "${MAILTO}" &
+ ;;
+
+ dtmail)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ TO=${TO:-}${TO:+,}$2
+ shift
+ ;;
+ --attach)
+ ATTACH="$2"
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ ${MAILER} ${TO:+-T} ${TO:-} ${ATTACH:+-a} ${ATTACH:+"${ATTACH}"}
+ ;;
+
+ sylpheed | claws)
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ TO=${TO:-}${TO:+,}$2
+ shift
+ ;;
+ --attach)
+ ATTACH="${ATTACH:-}${ATTACH:+ }$2"
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ ${MAILER} ${TO:+--compose} "${TO:-}" ${ATTACH:+--attach} "${ATTACH:-}"
+ ;;
+
+ Mail | Thunderbird | *.app )
+
+ while [ "$1" != "" ]; do
+ case $1 in
+ --attach)
+ #i95688# fix filenames containing accented chars, whatever alien
+ ATTACH="${ATTACH:-}${ATTACH:+ }"`echo "file://$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+ /usr/bin/open -a "${MAILER}" ${ATTACH}
+ ;;
+
+ "")
+
+ # DESKTOP_LAUNCH, see http://freedesktop.org/pipermail/xdg/2004-August/004489.html
+ if [ -n "$DESKTOP_LAUNCH" ]; then
+ while [ "$1" != "" ]; do
+ case $1 in
+ --to)
+ if [ "${TO}" != "" ]; then
+ MAILTO="${MAILTO:-}${MAILTO:+&}to=$2"
+ else
+ TO="$2"
+ fi
+ shift
+ ;;
+ --cc)
+ MAILTO="${MAILTO:-}${MAILTO:+&}cc="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --bcc)
+ MAILTO="${MAILTO:-}${MAILTO:+&}bcc="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --subject)
+ MAILTO="${MAILTO:-}${MAILTO:+&}subject="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --body)
+ MAILTO="${MAILTO:-}${MAILTO:+&}body="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ --attach)
+ MAILTO="${MAILTO:-}${MAILTO:+&}attachment="`echo "$2" | ${URI_ENCODE}`
+ shift
+ ;;
+ *)
+ ;;
+ esac
+ shift;
+ done
+
+ MAILTO="mailto:${TO}?${MAILTO}"
+ ${DESKTOP_LAUNCH} "${MAILTO}" &
+ else
+ echo "Could not determine a mail client to use."
+ exit 2
+ fi
+ ;;
+
+ *)
+ echo "Unsupported mail client: `basename $MAILER | sed 's/-.*^//'`"
+ exit 2
+ ;;
+esac
+
+exit 0
diff --git a/shell/source/unix/misc/uri-encode.c b/shell/source/unix/misc/uri-encode.c
new file mode 100644
index 000000000000..97ebc4c33755
--- /dev/null
+++ b/shell/source/unix/misc/uri-encode.c
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include <ctype.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main() {
+ for (;;) {
+ int c;
+ errno = 0;
+ c = getchar();
+ if (c == EOF) {
+ exit(errno == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
+ } else if (isalnum(c) || strchr("!$'()*+,-.:=@_~/\n", c) != NULL) {
+ /* valid RFC 2396 pchar characters + '/' + newline */
+ if (putchar(c) == EOF) {
+ exit(EXIT_FAILURE);
+ }
+ } else if (printf("%%%02X", (unsigned char) (char) c) < 0) {
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/sysshell/makefile.mk b/shell/source/unix/sysshell/makefile.mk
new file mode 100644
index 000000000000..3d8a55d4377f
--- /dev/null
+++ b/shell/source/unix/sysshell/makefile.mk
@@ -0,0 +1,75 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..$/..
+
+PRJNAME=shell
+TARGET=sysshell
+LIBTARGET=NO
+ENABLE_EXCEPTIONS=TRUE
+
+# --- Settings -----------------------------------------------------
+
+.INCLUDE : settings.mk
+
+.IF "$(SYSTEM_EXPAT)" == "YES"
+CFLAGS+=-DSYSTEM_EXPAT
+.ENDIF
+
+# --- Files --------------------------------------------------------
+
+.IF "$(OS)" != "MACOSX"
+
+SLOFILES=$(SLO)$/recently_used_file.obj \
+ $(SLO)$/recently_used_file_handler.obj
+
+SHL1TARGET=recentfile
+.IF "$(GUI)" == "OS2"
+SHL1IMPLIB=i$(TARGET)
+SHL1DEF= $(MISC)$/$(SHL1TARGET).def
+DEF1NAME= $(SHL1TARGET)
+
+.ELSE
+#SHL1IMPLIB=
+.ENDIF
+
+SHL1STDLIBS=$(EXPATASCII3RDLIB)\
+ $(SALLIB)
+
+SHL1LIBS=$(SLB)$/xmlparser.lib
+SHL1OBJS=$(SLOFILES)
+SHL1VERSIONMAP=recfile.map
+
+.ELSE
+
+dummy:
+ @echo "Nothing to build for MACOSX"
+
+.ENDIF # MACOSX
+# --- Targets ------------------------------------------------------
+
+.INCLUDE : target.mk
diff --git a/shell/source/unix/sysshell/recently_used_file.cxx b/shell/source/unix/sysshell/recently_used_file.cxx
new file mode 100644
index 000000000000..3f6f7b4d398a
--- /dev/null
+++ b/shell/source/unix/sysshell/recently_used_file.cxx
@@ -0,0 +1,149 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_shell.hxx"
+
+#ifndef INCLUDED_RECENTLY_USED_FILE
+#include "recently_used_file.hxx"
+#endif
+#include <rtl/ustring.hxx>
+#include <osl/process.h>
+#include <osl/security.hxx>
+#include <osl/thread.h>
+#include <osl/file.hxx>
+
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <unistd.h>
+
+const rtl::OUString RECENTLY_USED_FILE_NAME(RTL_CONSTASCII_USTRINGPARAM(".recently-used"));
+const rtl::OUString SLASH(RTL_CONSTASCII_USTRINGPARAM("/"));
+
+namespace /* private */ {
+
+inline void ensure_final_slash(/*inout*/ rtl::OUString& path)
+{
+ if ((path.getLength() > 0) &&
+ (SLASH.pData->buffer[0] != path.pData->buffer[path.getLength() - 1]))
+ path += SLASH;
+}
+
+} // namespace private
+
+//------------------------------------------------
+recently_used_file::recently_used_file() :
+ file_(NULL)
+{
+ osl::Security sec;
+ rtl::OUString homedir_url;
+
+ if (sec.getHomeDir(homedir_url))
+ {
+ rtl::OUString homedir;
+ osl::FileBase::getSystemPathFromFileURL(homedir_url, homedir);
+
+ rtl::OUString rufn = homedir;
+ ensure_final_slash(rufn);
+ rufn += RECENTLY_USED_FILE_NAME;
+
+ rtl::OString tmp =
+ rtl::OUStringToOString(rufn, osl_getThreadTextEncoding());
+
+ file_ = fopen(tmp.getStr(), "r+");
+
+ /* create if not exist */
+ if (NULL == file_) {
+ mode_t umask_ = umask(S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
+ file_ = fopen(tmp.getStr(), "w+");
+ umask(umask_);
+ }
+
+ if (NULL == file_)
+ throw "I/O error opening ~/.recently-used";
+
+ if (lockf(fileno(file_), F_LOCK, 0) != 0)
+ {
+ fclose(file_);
+ throw "Cannot lock ~/.recently-used";
+ }
+ }
+ else
+ throw "Cannot determine user home directory";
+}
+
+//------------------------------------------------
+recently_used_file::~recently_used_file()
+{
+ lockf(fileno(file_), F_ULOCK, 0);
+ fclose(file_);
+}
+
+//------------------------------------------------
+void recently_used_file::reset() const
+{
+ rewind(file_);
+}
+
+//------------------------------------------------
+void recently_used_file::truncate(off_t length)
+{
+ if (ftruncate(fileno(file_), length) == -1)
+ throw "I/O error: ftruncate failed";
+}
+
+//------------------------------------------------
+size_t recently_used_file::read(char* buffer, size_t size) const
+{
+ size_t r = fread(reinterpret_cast<void*>(buffer), sizeof(char), size, file_);
+
+ if ((r < size) && ferror(file_))
+ throw "I/O error: read failed";
+
+ return r;
+}
+
+//----------------------------
+void recently_used_file::write(const char* buffer, size_t size) const
+{
+ if (size != fwrite(reinterpret_cast<const void*>(buffer), sizeof(char), size, file_))
+ throw "I/O error: write failed";
+}
+
+//----------------------------
+bool recently_used_file::eof() const
+{
+ return feof(file_);
+}
+
+
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/sysshell/recently_used_file.hxx b/shell/source/unix/sysshell/recently_used_file.hxx
new file mode 100644
index 000000000000..b34da5bc86ae
--- /dev/null
+++ b/shell/source/unix/sysshell/recently_used_file.hxx
@@ -0,0 +1,71 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_RECENTLY_USED_FILE_HXX
+#define INCLUDED_RECENTLY_USED_FILE_HXX
+
+#include <stdio.h>
+#include <unistd.h>
+
+//##################################
+// simple wrapper around the recently_used_file
+
+class recently_used_file
+{
+public:
+ //----------------------------
+ recently_used_file();
+
+ //----------------------------
+ ~recently_used_file();
+
+ //----------------------------
+ // set file pointer to the start of file
+ void reset() const;
+
+ //----------------------------
+ void truncate(off_t length = 0);
+
+ //----------------------------
+ size_t read(
+ char* buffer,
+ size_t size) const;
+
+ //----------------------------
+ void write(const char* buffer, size_t size) const;
+
+ //----------------------------
+ bool eof() const;
+
+private:
+ FILE* file_;
+};
+
+#endif // INCLUDED_RECENTLY_USED_FILE_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/sysshell/recently_used_file_handler.cxx b/shell/source/unix/sysshell/recently_used_file_handler.cxx
new file mode 100644
index 000000000000..1ef8c621dd3b
--- /dev/null
+++ b/shell/source/unix/sysshell/recently_used_file_handler.cxx
@@ -0,0 +1,529 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_shell.hxx"
+
+#include "osl/process.h"
+#include "rtl/ustring.hxx"
+#include "rtl/string.hxx"
+#include "rtl/strbuf.hxx"
+
+#include "osl/thread.h"
+#include "recently_used_file.hxx"
+
+#include "internal/xml_parser.hxx"
+#include "internal/i_xml_parser_event_handler.hxx"
+
+#include <map>
+#include <vector>
+#include <algorithm>
+#include <functional>
+#include <string.h>
+
+namespace /* private */ {
+ //########################################
+ typedef std::vector<string_t> string_container_t;
+
+ #define TAG_RECENT_FILES "RecentFiles"
+ #define TAG_RECENT_ITEM "RecentItem"
+ #define TAG_URI "URI"
+ #define TAG_MIME_TYPE "Mime-Type"
+ #define TAG_TIMESTAMP "Timestamp"
+ #define TAG_PRIVATE "Private"
+ #define TAG_GROUPS "Groups"
+ #define TAG_GROUP "Group"
+
+ //------------------------------------------------
+ // compare two string_t's case insensitive, may also be done
+ // by specifying special traits for the string type but in this
+ // case it's easier to do it this way
+ struct str_icase_cmp :
+ public std::binary_function<string_t, string_t, bool>
+ {
+ bool operator() (const string_t& s1, const string_t& s2) const
+ { return (0 == strcasecmp(s1.c_str(), s2.c_str())); }
+ };
+
+ //------------------------------------------------
+ struct recently_used_item
+ {
+ recently_used_item() :
+ is_private_(false)
+ {}
+
+ recently_used_item(
+ const string_t& uri,
+ const string_t& mime_type,
+ const string_container_t& groups,
+ bool is_private = false) :
+ uri_(uri),
+ mime_type_(mime_type),
+ is_private_(is_private),
+ groups_(groups)
+ {
+ timestamp_ = time(NULL);
+ }
+
+ void set_uri(const string_t& character)
+ { uri_ = character; }
+
+ void set_mime_type(const string_t& character)
+ { mime_type_ = character; }
+
+ void set_timestamp(const string_t& character)
+ {
+ time_t t;
+ if (sscanf(character.c_str(), "%ld", &t) != 1)
+ timestamp_ = -1;
+ else
+ timestamp_ = t;
+ }
+
+ void set_is_private(const string_t& /*character*/)
+ { is_private_ = true; }
+
+ void set_groups(const string_t& character)
+ { groups_.push_back(character); }
+
+ void set_nothing(const string_t& /*character*/)
+ {}
+
+ bool has_groups() const
+ {
+ return !groups_.empty();
+ }
+
+ bool has_group(const string_t& name) const
+ {
+ string_container_t::const_iterator iter_end = groups_.end();
+ return (has_groups() &&
+ iter_end != std::find_if(
+ groups_.begin(), iter_end,
+ std::bind2nd(str_icase_cmp(), name)));
+ }
+
+ void write_xml(const recently_used_file& file) const
+ {
+ write_xml_start_tag(TAG_RECENT_ITEM, file, true);
+ write_xml_tag(TAG_URI, uri_, file);
+ write_xml_tag(TAG_MIME_TYPE, mime_type_, file);
+
+ rtl::OString ts = rtl::OString::valueOf((sal_sSize)timestamp_);
+ write_xml_tag(TAG_TIMESTAMP, ts.getStr(), file);
+
+ if (is_private_)
+ write_xml_tag(TAG_PRIVATE, file);
+
+ if (has_groups())
+ {
+ write_xml_start_tag(TAG_GROUPS, file, true);
+
+ string_container_t::const_iterator iter = groups_.begin();
+ string_container_t::const_iterator iter_end = groups_.end();
+
+ for ( ; iter != iter_end; ++iter)
+ write_xml_tag(TAG_GROUP, (*iter), file);
+
+ write_xml_end_tag(TAG_GROUPS, file);
+ }
+ write_xml_end_tag(TAG_RECENT_ITEM, file);
+ }
+
+ static rtl::OString escape_content(const string_t &text)
+ {
+ rtl::OStringBuffer aBuf;
+ for (sal_uInt32 i = 0; i < text.length(); i++)
+ {
+# define MAP(a,b) case a: aBuf.append(b); break
+ switch (text[i])
+ {
+ MAP ('&', "&amp;");
+ MAP ('<', "&lt;");
+ MAP ('>', "&gt;");
+ MAP ('\'', "&apos;");
+ MAP ('"', "&quot;");
+ default:
+ aBuf.append(text[i]);
+ break;
+ }
+# undef MAP
+ }
+ return aBuf.makeStringAndClear();
+ }
+
+ void write_xml_tag(const string_t& name, const string_t& value, const recently_used_file& file) const
+ {
+ write_xml_start_tag(name, file);
+ rtl::OString escaped = escape_content (value);
+ file.write(escaped.getStr(), escaped.getLength());
+ write_xml_end_tag(name, file);
+ }
+
+ void write_xml_tag(const string_t& name, const recently_used_file& file) const
+ {
+ file.write("<", 1);
+ file.write(name.c_str(), name.length());
+ file.write("/>\n", 3);
+ }
+
+ void write_xml_start_tag(const string_t& name, const recently_used_file& file, bool linefeed = false) const
+ {
+ file.write("<", 1);
+ file.write(name.c_str(), name.length());
+ if (linefeed)
+ file.write(">\n", 2);
+ else
+ file.write(">", 1);
+ }
+
+ void write_xml_end_tag(const string_t& name, const recently_used_file& file) const
+ {
+ file.write("</", 2);
+ file.write(name.c_str(), name.length());
+ file.write(">\n", 2);
+ }
+
+ string_t uri_;
+ string_t mime_type_;
+ time_t timestamp_;
+ bool is_private_;
+ string_container_t groups_;
+ };
+
+ typedef std::vector<recently_used_item*> recently_used_item_list_t;
+ typedef void (recently_used_item::* SET_COMMAND)(const string_t&);
+
+ //########################################
+ // thrown if we encounter xml tags that we do not know
+ class unknown_xml_format_exception {};
+
+ //########################################
+ class recently_used_file_filter : public i_xml_parser_event_handler
+ {
+ public:
+ recently_used_file_filter(recently_used_item_list_t& item_list) :
+ item_(NULL),
+ item_list_(item_list)
+ {
+ named_command_map_[TAG_RECENT_FILES] = &recently_used_item::set_nothing;
+ named_command_map_[TAG_RECENT_ITEM] = &recently_used_item::set_nothing;
+ named_command_map_[TAG_URI] = &recently_used_item::set_uri;
+ named_command_map_[TAG_MIME_TYPE] = &recently_used_item::set_mime_type;
+ named_command_map_[TAG_TIMESTAMP] = &recently_used_item::set_timestamp;
+ named_command_map_[TAG_PRIVATE] = &recently_used_item::set_is_private;
+ named_command_map_[TAG_GROUPS] = &recently_used_item::set_nothing;
+ named_command_map_[TAG_GROUP] = &recently_used_item::set_groups;
+ }
+
+ virtual void start_element(
+ const string_t& /*raw_name*/,
+ const string_t& local_name,
+ const xml_tag_attribute_container_t& /*attributes*/)
+ {
+ if ((local_name == TAG_RECENT_ITEM) && (NULL == item_))
+ item_ = new recently_used_item;
+ }
+
+ virtual void end_element(const string_t& /*raw_name*/, const string_t& local_name)
+ {
+ // check for end tags w/o start tag
+ if( local_name != TAG_RECENT_FILES && NULL == item_ )
+ return; // will result in an XML parser error anyway
+
+ if (named_command_map_.find(local_name) != named_command_map_.end())
+ (item_->*named_command_map_[local_name])(current_element_);
+ else
+ {
+ delete item_;
+ throw unknown_xml_format_exception();
+ }
+
+ if (local_name == TAG_RECENT_ITEM)
+ {
+ item_list_.push_back(item_);
+ item_ = NULL;
+ }
+ current_element_.clear();
+ }
+
+ virtual void characters(const string_t& character)
+ {
+ if (character != "\n")
+ current_element_ += character;
+ }
+
+ virtual void start_document() {}
+ virtual void end_document() {}
+
+ virtual void ignore_whitespace(const string_t& /*whitespaces*/)
+ {}
+
+ virtual void processing_instruction(
+ const string_t& /*target*/, const string_t& /*data*/)
+ {}
+
+ virtual void comment(const string_t& /*comment*/)
+ {}
+ private:
+ recently_used_item* item_;
+ std::map<string_t, SET_COMMAND> named_command_map_;
+ string_t current_element_;
+ recently_used_item_list_t& item_list_;
+ private:
+ recently_used_file_filter(const recently_used_file_filter&);
+ recently_used_file_filter& operator=(const recently_used_file_filter&);
+ };
+
+ //------------------------------------------------
+ void read_recently_used_items(
+ recently_used_file& file,
+ recently_used_item_list_t& item_list)
+ {
+ xml_parser xparser;
+ recently_used_file_filter ruff(item_list);
+
+ xparser.set_document_handler(&ruff);
+
+ char buff[16384];
+ while (!file.eof())
+ {
+ if (size_t length = file.read(buff, sizeof(buff)))
+ xparser.parse(buff, length, file.eof());
+ }
+ }
+
+ //------------------------------------------------
+ // The file ~/.recently_used shall not contain more than 500
+ // entries (see www.freedesktop.org)
+ const int MAX_RECENTLY_USED_ITEMS = 500;
+
+ class recent_item_writer
+ {
+ public:
+ recent_item_writer(
+ recently_used_file& file,
+ int max_items_to_write = MAX_RECENTLY_USED_ITEMS) :
+ file_(file),
+ max_items_to_write_(max_items_to_write),
+ items_written_(0)
+ {}
+
+ void operator() (const recently_used_item* item)
+ {
+ if (items_written_++ < max_items_to_write_)
+ item->write_xml(file_);
+ }
+ private:
+ recently_used_file& file_;
+ int max_items_to_write_;
+ int items_written_;
+ };
+
+ //------------------------------------------------
+ const char* XML_HEADER = "<?xml version=\"1.0\"?>\n<RecentFiles>\n";
+ const char* XML_FOOTER = "</RecentFiles>";
+
+ //------------------------------------------------
+ // assumes that the list is ordered decreasing
+ void write_recently_used_items(
+ recently_used_file& file,
+ recently_used_item_list_t& item_list)
+ {
+ if (!item_list.empty())
+ {
+ file.truncate();
+ file.reset();
+
+ file.write(XML_HEADER, strlen(XML_HEADER));
+
+ std::for_each(
+ item_list.begin(),
+ item_list.end(),
+ recent_item_writer(file));
+
+ file.write(XML_FOOTER, strlen(XML_FOOTER));
+ }
+ }
+
+ //------------------------------------------------
+ struct delete_recently_used_item
+ {
+ void operator() (const recently_used_item* item) const
+ { delete item; }
+ };
+
+ //------------------------------------------------
+ void recently_used_item_list_clear(recently_used_item_list_t& item_list)
+ {
+ std::for_each(
+ item_list.begin(),
+ item_list.end(),
+ delete_recently_used_item());
+ item_list.clear();
+ }
+
+ //------------------------------------------------
+ class find_item_predicate
+ {
+ public:
+ find_item_predicate(const string_t& uri) :
+ uri_(uri)
+ {}
+
+ bool operator() (const recently_used_item* item) const
+ { return (item->uri_ == uri_); }
+ private:
+ string_t uri_;
+ };
+
+ //------------------------------------------------
+ struct greater_recently_used_item
+ {
+ bool operator ()(const recently_used_item* lhs, const recently_used_item* rhs) const
+ { return (lhs->timestamp_ > rhs->timestamp_); }
+ };
+
+ //------------------------------------------------
+ const char* GROUP_OOO = "openoffice.org";
+ const char* GROUP_STAR_OFFICE = "staroffice";
+ const char* GROUP_STAR_SUITE = "starsuite";
+
+ //------------------------------------------------
+ void recently_used_item_list_add(
+ recently_used_item_list_t& item_list, const rtl::OUString& file_url, const rtl::OUString& mime_type)
+ {
+ rtl::OString f = rtl::OUStringToOString(file_url, RTL_TEXTENCODING_UTF8);
+
+ recently_used_item_list_t::iterator iter =
+ std::find_if(
+ item_list.begin(),
+ item_list.end(),
+ find_item_predicate(f.getStr()));
+
+ if (iter != item_list.end())
+ {
+ (*iter)->timestamp_ = time(NULL);
+
+ if (!(*iter)->has_group(GROUP_OOO))
+ (*iter)->groups_.push_back(GROUP_OOO);
+ if (!(*iter)->has_group(GROUP_STAR_OFFICE))
+ (*iter)->groups_.push_back(GROUP_STAR_OFFICE);
+ if (!(*iter)->has_group(GROUP_STAR_SUITE))
+ (*iter)->groups_.push_back(GROUP_STAR_SUITE);
+ }
+ else
+ {
+ string_container_t groups;
+ groups.push_back(GROUP_OOO);
+ groups.push_back(GROUP_STAR_OFFICE);
+ groups.push_back(GROUP_STAR_SUITE);
+
+ string_t uri(f.getStr());
+ string_t mimetype(rtl::OUStringToOString(mime_type, osl_getThreadTextEncoding()).getStr());
+
+ if (mimetype.length() == 0)
+ mimetype = "application/octet-stream";
+
+ item_list.push_back(new recently_used_item(uri, mimetype, groups));
+ }
+
+ // sort decreasing after the timestamp
+ // so that the newest items appear first
+ std::sort(
+ item_list.begin(),
+ item_list.end(),
+ greater_recently_used_item());
+ }
+
+ //------------------------------------------------
+ struct cleanup_guard
+ {
+ cleanup_guard(recently_used_item_list_t& item_list) :
+ item_list_(item_list)
+ {}
+ ~cleanup_guard()
+ { recently_used_item_list_clear(item_list_); }
+
+ recently_used_item_list_t& item_list_;
+ };
+
+} // namespace private
+
+//###########################################
+/*
+ example (see http::www.freedesktop.org):
+ <?xml version="1.0"?>
+ <RecentFiles>
+ <RecentItem>
+ <URI>file:///home/federico/gedit.txt</URI>
+ <Mime-Type>text/plain</Mime-Type>
+ <Timestamp>1046485966</Timestamp>
+ <Groups>
+ <Group>gedit</Group>
+ </Groups>
+ </RecentItem>
+ <RecentItem>
+ <URI>file:///home/federico/gedit-2.2.0.tar.bz2</URI>
+ <Mime-Type>application/x-bzip</Mime-Type>
+ <Timestamp>1046209851</Timestamp>
+ <Private/>
+ <Groups>
+ </Groups>
+ </RecentItem>
+ </RecentFiles>
+*/
+
+extern "C" void add_to_recently_used_file_list(const rtl::OUString& file_url, const rtl::OUString& mime_type)
+{
+ try
+ {
+ recently_used_file ruf;
+ recently_used_item_list_t item_list;
+ cleanup_guard guard(item_list);
+
+ read_recently_used_items(ruf, item_list);
+ recently_used_item_list_add(item_list, file_url, mime_type);
+ write_recently_used_items(ruf, item_list);
+ }
+ catch(const char* ex)
+ {
+ OSL_ENSURE(false, ex);
+ }
+ catch(const xml_parser_exception&)
+ {
+ OSL_ENSURE(false, "XML parser error");
+ }
+ catch(const unknown_xml_format_exception&)
+ {
+ OSL_ENSURE(false, "XML format unknown");
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/shell/source/unix/sysshell/recfile.map b/shell/source/unix/sysshell/recfile.map
new file mode 100755
index 000000000000..7e454f111896
--- /dev/null
+++ b/shell/source/unix/sysshell/recfile.map
@@ -0,0 +1,6 @@
+UDK_3_0_0 {
+ global:
+ add_to_recently_used_file_list;
+ local:
+ *;
+};