Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / appl / openuriexternally.cxx
blob77c412bff0e98b55dbd22f34afcfd600ba5397e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <sal/config.h>
12 #include <com/sun/star/lang/IllegalArgumentException.hpp>
13 #include <com/sun/star/system/SystemShellExecute.hpp>
14 #include <com/sun/star/system/SystemShellExecuteException.hpp>
15 #include <com/sun/star/system/SystemShellExecuteFlags.hpp>
16 #include <com/sun/star/uno/Reference.hxx>
17 #include <com/sun/star/uno/RuntimeException.hpp>
18 #include <com/sun/star/uno/XInterface.hpp>
19 #include <comphelper/processfactory.hxx>
20 #include <rtl/ustring.h>
21 #include <rtl/ustring.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/sfxresid.hxx>
24 #include <vcl/layout.hxx>
25 #include <vcl/svapp.hxx>
27 #include "openuriexternally.hxx"
29 #include "app.hrc"
31 bool sfx2::openUriExternally(
32 OUString const & uri, bool handleSystemShellExecuteException)
34 css::uno::Reference< css::system::XSystemShellExecute > exec(
35 css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
36 try {
37 exec->execute(
38 uri, OUString(),
39 css::system::SystemShellExecuteFlags::URIS_ONLY);
40 return true;
41 } catch (css::lang::IllegalArgumentException & e) {
42 if (e.ArgumentPosition != 0) {
43 throw css::uno::RuntimeException(
44 "unexpected IllegalArgumentException: " + e.Message);
46 SolarMutexGuard g;
47 ScopedVclPtrInstance<MessageDialog> eb(
48 SfxGetpApp()->GetTopWindow(), SfxResId(STR_NO_ABS_URI_REF));
49 eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", uri));
50 eb->Execute();
51 } catch (css::system::SystemShellExecuteException &) {
52 if (!handleSystemShellExecuteException) {
53 throw;
55 SolarMutexGuard g;
56 ScopedVclPtrInstance<MessageDialog> eb(
57 SfxGetpApp()->GetTopWindow(),
58 SfxResId(STR_NO_WEBBROWSER_FOUND));
59 eb->Execute();
61 return false;
64 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */