Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / appl / openuriexternally.cxx
blob381946987844f75d6a70b87a700651e2c8df39c4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * Version: MPL 1.1 / GPLv3+ / LGPLv3+
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * Major Contributor(s):
16 * [ Copyright (C) 2012 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
17 * (initial developer) ]
19 * All Rights Reserved.
21 * For minor contributions see the git repository.
23 * Alternatively, the contents of this file may be used under the terms of
24 * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 * instead of those above.
30 #include "sal/config.h"
32 #include "com/sun/star/lang/IllegalArgumentException.hpp"
33 #include "com/sun/star/system/XSystemShellExecute.hpp"
34 #include "com/sun/star/system/SystemShellExecuteException.hpp"
35 #include "com/sun/star/system/SystemShellExecuteFlags.hpp"
36 #include "com/sun/star/uno/Reference.hxx"
37 #include "com/sun/star/uno/RuntimeException.hpp"
38 #include "com/sun/star/uno/XInterface.hpp"
39 #include "comphelper/processfactory.hxx"
40 #include "rtl/ustring.h"
41 #include "rtl/ustring.hxx"
42 #include "sfx2/app.hxx"
43 #include "sfx2/sfxresid.hxx"
44 #include "tools/string.hxx"
45 #include "vcl/msgbox.hxx"
46 #include "vcl/svapp.hxx"
48 #include "openuriexternally.hxx"
50 #include "app.hrc"
52 namespace {
54 namespace css = com::sun::star;
58 bool sfx2::openUriExternally(
59 rtl::OUString const & uri, bool handleSystemShellExecuteException)
61 css::uno::Reference< css::system::XSystemShellExecute > exec(
62 comphelper::getProcessServiceFactory()->createInstance(
63 rtl::OUString(
64 RTL_CONSTASCII_USTRINGPARAM(
65 "com.sun.star.system.SystemShellExecute"))),
66 css::uno::UNO_QUERY_THROW);
67 try {
68 exec->execute(
69 uri, rtl::OUString(),
70 css::system::SystemShellExecuteFlags::URIS_ONLY);
71 return true;
72 } catch (css::lang::IllegalArgumentException & e) {
73 if (e.ArgumentPosition != 0) {
74 throw css::uno::RuntimeException(
75 (rtl::OUString(
76 RTL_CONSTASCII_USTRINGPARAM(
77 "unexpected IllegalArgumentException: "))
78 + e.Message),
79 css::uno::Reference< css::uno::XInterface >());
81 SolarMutexGuard g;
82 ErrorBox eb(
83 SfxGetpApp()->GetTopWindow(), SfxResId(MSG_ERR_NO_ABS_URI_REF));
84 String msg(eb.GetMessText());
85 msg.SearchAndReplaceAscii("$(ARG1)", uri);
86 eb.SetMessText(msg);
87 eb.Execute();
88 } catch (css::system::SystemShellExecuteException &) {
89 if (!handleSystemShellExecuteException) {
90 throw;
92 SolarMutexGuard g;
93 ErrorBox(
94 SfxGetpApp()->GetTopWindow(),
95 SfxResId(MSG_ERR_NO_WEBBROWSER_FOUND)).
96 Execute();
98 return false;
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */