[Libreoffice-commits] core.git: sfx2/source
Samuel Mehrbrodt
Samuel.Mehrbrodt at cib.de
Wed Mar 14 13:33:08 UTC 2018
sfx2/source/appl/openuriexternally.cxx | 58 ++++++++++++++++++++++++++-------
sfx2/source/inc/openuriexternally.hxx | 32 +++++++-----------
sfx2/source/view/viewsh.cxx | 3 +
3 files changed, 62 insertions(+), 31 deletions(-)
New commits:
commit 5d5da77e82b6498dd73123ec0dc36d2315e279a1
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date: Mon Mar 12 09:50:17 2018 +0100
tdf#116305 Add timeout to help Windows bring browsers to the front
Adding a timeout seems to help Windows a lot to actually bring
the browser into the front, especially when it was closed before.
Still no 100% success rate, but much improved now.
Change-Id: I62affee4b837e0a60b1aac2a20be6fe7c3f9d2e0
Reviewed-on: https://gerrit.libreoffice.org/51132
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
diff --git a/sfx2/source/appl/openuriexternally.cxx b/sfx2/source/appl/openuriexternally.cxx
index c412d40aeb39..7ffa980706bd 100644
--- a/sfx2/source/appl/openuriexternally.cxx
+++ b/sfx2/source/appl/openuriexternally.cxx
@@ -30,27 +30,55 @@
#include <sfx2/viewsh.hxx>
#include <sfx2/strings.hrc>
-bool sfx2::openUriExternally(
- OUString const & uri, bool handleSystemShellExecuteException)
+class URITools
+{
+private:
+ Timer aOpenURITimer;
+ OUString msURI;
+ bool mbHandleSystemShellExecuteException;
+ DECL_LINK(onOpenURI, Timer*, void);
+
+public:
+ void openURI(const OUString& sURI, bool bHandleSystemShellExecuteException);
+};
+
+void URITools::openURI(const OUString& sURI, bool bHandleSystemShellExecuteException)
{
if (comphelper::LibreOfficeKit::isActive())
{
- if(SfxViewShell* pViewShell = SfxViewShell::Current())
+ if (SfxViewShell* pViewShell = SfxViewShell::Current())
{
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_HYPERLINK_CLICKED,
- uri.toUtf8().getStr());
- return true;
+ sURI.toUtf8().getStr());
}
- return false;
+ delete this;
+ return;
}
+ mbHandleSystemShellExecuteException = bHandleSystemShellExecuteException;
+ msURI = sURI;
+
+ // tdf#116305 Workaround: Use timer to bring browsers to the front
+ aOpenURITimer.SetInvokeHandler(LINK(this, URITools, onOpenURI));
+#ifdef WNT
+ // 200ms seems to be the the best compromise between responsiveness and success rate
+ aOpenURITimer.SetTimeout(200);
+#else
+ aOpenURITimer.SetTimeout(0);
+#endif
+ aOpenURITimer.SetDebugName("sfx2::openUriExternallyTimer");
+ aOpenURITimer.Start();
+}
+
+IMPL_LINK_NOARG(URITools, onOpenURI, Timer*, void)
+{
css::uno::Reference< css::system::XSystemShellExecute > exec(
css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
try {
exec->execute(
- uri, OUString(),
+ msURI, OUString(),
css::system::SystemShellExecuteFlags::URIS_ONLY);
- return true;
+ return;
} catch (css::lang::IllegalArgumentException & e) {
if (e.ArgumentPosition != 0) {
throw css::uno::RuntimeException(
@@ -61,10 +89,10 @@ bool sfx2::openUriExternally(
std::unique_ptr<weld::MessageDialog> eb(Application::CreateMessageDialog(pWindow ? pWindow->GetFrameWeld() : nullptr,
VclMessageType::Warning, VclButtonsType::Ok,
SfxResId(STR_NO_ABS_URI_REF)));
- eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", uri));
+ eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI));
eb->run();
} catch (css::system::SystemShellExecuteException & e) {
- if (!handleSystemShellExecuteException) {
+ if (!mbHandleSystemShellExecuteException) {
throw;
}
SolarMutexGuard g;
@@ -73,13 +101,19 @@ bool sfx2::openUriExternally(
VclMessageType::Warning, VclButtonsType::Ok,
SfxResId(STR_NO_WEBBROWSER_FOUND)));
eb->set_primary_text(
- eb->get_primary_text().replaceFirst("$(ARG1)", uri)
+ eb->get_primary_text().replaceFirst("$(ARG1)", msURI)
.replaceFirst("$(ARG2)", OUString::number(e.PosixError))
.replaceFirst("$(ARG3)", e.Message));
//TODO: avoid subsequent replaceFirst acting on previous replacement
eb->run();
}
- return false;
+ delete this;
+}
+
+void sfx2::openUriExternally(const OUString& sURI, bool bHandleSystemShellExecuteException)
+{
+ URITools* uriTools = new URITools;
+ uriTools->openURI(sURI, bHandleSystemShellExecuteException);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/inc/openuriexternally.hxx b/sfx2/source/inc/openuriexternally.hxx
index 42013cd70609..b45b2b7a931d 100644
--- a/sfx2/source/inc/openuriexternally.hxx
+++ b/sfx2/source/inc/openuriexternally.hxx
@@ -12,24 +12,20 @@
#include <sal/config.h>
-
-namespace sfx2 {
-
-/// Open a URI via com.sun.star.system.SystemShellExecute
-///
-/// Handles XSystemShellExecute.execute's IllegalArgumentException (throwing a
-/// RuntimeException if it is unexpected, i.e., not caused by the given uri not
-/// being an absolute URI reference).
-///
-/// Handles XSystemShellExecute.execute's SystemShellExecuteException unless the
-/// given handleSystemShellExecuteException is false (in which case the
-/// exception is re-thrown).
-///
-/// @return true iff execution was successful
-bool openUriExternally(
- OUString const & uri, bool handleSystemShellExecuteException);
-
-}
+namespace sfx2
+{
+/** Open a URI via com.sun.star.system.SystemShellExecute
+
+ Handles XSystemShellExecute.execute's IllegalArgumentException (throwing a
+ RuntimeException if it is unexpected, i.e., not caused by the given uri not
+ being an absolute URI reference).
+
+ Handles XSystemShellExecute.execute's SystemShellExecuteException unless the
+ given handleSystemShellExecuteException is false (in which case the
+ exception is re-thrown).
+*/
+void openUriExternally(const OUString& sURI, bool bHandleSystemShellExecuteException);
+};
#endif
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 8925c8aca469..41ac335237ad 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -641,7 +641,8 @@ void SfxViewShell::ExecMisc_Impl( SfxRequest &rReq )
return;
}
- rReq.Done(sfx2::openUriExternally(aFileURL, true));
+ sfx2::openUriExternally(aFileURL, true);
+ rReq.Done(true);
break;
}
else
More information about the Libreoffice-commits
mailing list