12#include <com/sun/star/lang/IllegalArgumentException.hpp>
13#include <com/sun/star/security/AccessControlException.hpp>
14#include <com/sun/star/system/SystemShellExecute.hpp>
15#include <com/sun/star/system/SystemShellExecuteException.hpp>
16#include <com/sun/star/system/SystemShellExecuteFlags.hpp>
17#include <com/sun/star/uno/Reference.hxx>
18#include <com/sun/star/uno/RuntimeException.hpp>
20#include <rtl/ustring.hxx>
27#include <LibreOfficeKit/LibreOfficeKitEnums.h>
30#include <sfx2/strings.hrc>
37 Timer aOpenURITimer {
"sfx2::openUriExternallyTimer" };
40 bool mbHandleSystemShellExecuteException;
45 : mpDialogParent(pDialogParent)
46 , mbHandleSystemShellExecuteException(false)
49 void openURI(
const OUString& sURI,
bool bHandleSystemShellExecuteException);
54void URITools::openURI(
const OUString& sURI,
bool bHandleSystemShellExecuteException)
60 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_HYPERLINK_CLICKED,
67 mbHandleSystemShellExecuteException = bHandleSystemShellExecuteException;
71 aOpenURITimer.SetInvokeHandler(
LINK(
this, URITools, onOpenURI));
74 aOpenURITimer.SetTimeout(200);
76 aOpenURITimer.SetTimeout(0);
78 aOpenURITimer.Start();
83 std::unique_ptr<URITools> guard(
this);
84 css::uno::Reference< css::system::XSystemShellExecute > exec(
86 for (sal_Int32 flags = css::system::SystemShellExecuteFlags::URIS_ONLY;;) {
88 exec->execute(msURI, OUString(), flags);
89 }
catch (css::security::AccessControlException & e) {
90 if (e.LackingPermission.hasValue() || flags == 0) {
91 throw css::uno::RuntimeException(
92 "unexpected AccessControlException: " + e.Message);
95 std::unique_ptr<weld::MessageDialog> eb(
97 mpDialogParent, VclMessageType::Warning, VclButtonsType::OkCancel,
100 if (eb->run() ==
RET_OK) {
104 }
catch (css::lang::IllegalArgumentException & e) {
105 if (e.ArgumentPosition != 0) {
106 throw css::uno::RuntimeException(
107 "unexpected IllegalArgumentException: " + e.Message);
111 VclMessageType::Warning, VclButtonsType::Ok,
115 }
catch (css::system::SystemShellExecuteException & e) {
116 if (!mbHandleSystemShellExecuteException) {
121 VclMessageType::Warning, VclButtonsType::Ok,
122 SfxResId(STR_NO_WEBBROWSER_FOUND)));
123 eb->set_primary_text(
124 eb->get_primary_text().replaceFirst(
"$(ARG1)", msURI)
125 .replaceFirst(
"$(ARG2)", OUString::number(e.PosixError))
126 .replaceFirst(
"$(ARG3)", e.Message));
136 URITools* uriTools =
new URITools(pDialogParent);
137 uriTools->openURI(sURI, bHandleSystemShellExecuteException);
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
#define LINK(Instance, Class, Member)
Reference< XComponentContext > getProcessComponentContext()
void openUriExternally(const OUString &sURI, bool bHandleSystemShellExecuteException, weld::Widget *pDialogParent)
Open a URI via com.sun.star.system.SystemShellExecute.
IMPL_LINK_NOARG(URITools, onOpenURI, Timer *, void)
OUString SfxResId(TranslateId aId)