tdf#128969: Let the user explicitly decide to execute an external program
...bringing up a warning dialog now in cases where it would have before only brought up a failure message Change-Id: I850badf5927517f16f965950df699979887dbdc0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124422 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
parent
a5cea74034
commit
70009098fd
2 changed files with 44 additions and 30 deletions
|
@ -103,6 +103,7 @@
|
|||
#define STR_GB NC_("STR_GB", "GB")
|
||||
#define STR_QUERY_LASTVERSION NC_("STR_QUERY_LASTVERSION", "Cancel all changes?")
|
||||
#define STR_NO_WEBBROWSER_FOUND NC_("STR_NO_WEBBROWSER_FOUND", "Opening \"$(ARG1)\" failed with error code $(ARG2) and message: \"$(ARG3)\"\nMaybe no web browser could be found on your system. In that case, please check your Desktop Preferences or install a web browser (for example, Firefox) in the default location requested during the browser installation.")
|
||||
#define STR_DANGEROUS_TO_OPEN NC_("STR_DANGEROUS_TO_OPEN", "It might be dangerous to open \"$(ARG1)\".\nDo you really want to open it?")
|
||||
#define STR_NO_ABS_URI_REF NC_("STR_NO_ABS_URI_REF", "\"$(ARG1)\" cannot be passed to an external application to open it (e.g., it might not be an absolute URL, or might denote no existing file).")
|
||||
#define STR_GID_INTERN NC_("STR_GID_INTERN", "Internal")
|
||||
#define STR_GID_APPLICATION NC_("STR_GID_APPLICATION", "Application")
|
||||
|
|
|
@ -80,37 +80,50 @@ IMPL_LINK_NOARG(URITools, onOpenURI, Timer*, void)
|
|||
std::unique_ptr<URITools> guard(this);
|
||||
css::uno::Reference< css::system::XSystemShellExecute > exec(
|
||||
css::system::SystemShellExecute::create(comphelper::getProcessComponentContext()));
|
||||
try {
|
||||
exec->execute(
|
||||
msURI, OUString(),
|
||||
css::system::SystemShellExecuteFlags::URIS_ONLY);
|
||||
} catch (css::lang::IllegalArgumentException & e) {
|
||||
if (e.ArgumentPosition != 0) {
|
||||
throw css::uno::RuntimeException(
|
||||
"unexpected IllegalArgumentException: " + e.Message);
|
||||
for (sal_Int32 flags = css::system::SystemShellExecuteFlags::URIS_ONLY;;) {
|
||||
try {
|
||||
exec->execute(msURI, OUString(), flags);
|
||||
} catch (css::lang::IllegalArgumentException & e) {
|
||||
if (e.ArgumentPosition != 0) {
|
||||
throw css::uno::RuntimeException(
|
||||
"unexpected IllegalArgumentException: " + e.Message);
|
||||
}
|
||||
SolarMutexGuard g;
|
||||
weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
|
||||
if (flags == css::system::SystemShellExecuteFlags::URIS_ONLY) {
|
||||
std::unique_ptr<weld::MessageDialog> eb(
|
||||
Application::CreateMessageDialog(
|
||||
pWindow, VclMessageType::Warning, VclButtonsType::OkCancel,
|
||||
SfxResId(STR_DANGEROUS_TO_OPEN)));
|
||||
eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI));
|
||||
if (eb->run() == RET_OK) {
|
||||
flags = 0;
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
std::unique_ptr<weld::MessageDialog> eb(Application::CreateMessageDialog(pWindow,
|
||||
VclMessageType::Warning, VclButtonsType::Ok,
|
||||
SfxResId(STR_NO_ABS_URI_REF)));
|
||||
eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI));
|
||||
eb->run();
|
||||
}
|
||||
} catch (css::system::SystemShellExecuteException & e) {
|
||||
if (!mbHandleSystemShellExecuteException) {
|
||||
throw;
|
||||
}
|
||||
SolarMutexGuard g;
|
||||
weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
|
||||
std::unique_ptr<weld::MessageDialog> eb(Application::CreateMessageDialog(pWindow,
|
||||
VclMessageType::Warning, VclButtonsType::Ok,
|
||||
SfxResId(STR_NO_WEBBROWSER_FOUND)));
|
||||
eb->set_primary_text(
|
||||
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();
|
||||
}
|
||||
SolarMutexGuard g;
|
||||
weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
|
||||
std::unique_ptr<weld::MessageDialog> eb(Application::CreateMessageDialog(pWindow,
|
||||
VclMessageType::Warning, VclButtonsType::Ok,
|
||||
SfxResId(STR_NO_ABS_URI_REF)));
|
||||
eb->set_primary_text(eb->get_primary_text().replaceFirst("$(ARG1)", msURI));
|
||||
eb->run();
|
||||
} catch (css::system::SystemShellExecuteException & e) {
|
||||
if (!mbHandleSystemShellExecuteException) {
|
||||
throw;
|
||||
}
|
||||
SolarMutexGuard g;
|
||||
weld::Window *pWindow = SfxGetpApp()->GetTopWindow();
|
||||
std::unique_ptr<weld::MessageDialog> eb(Application::CreateMessageDialog(pWindow,
|
||||
VclMessageType::Warning, VclButtonsType::Ok,
|
||||
SfxResId(STR_NO_WEBBROWSER_FOUND)));
|
||||
eb->set_primary_text(
|
||||
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();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue