Mantid
Loading...
Searching...
No Matches
MantidDesktopServices.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9#include <QDesktopServices>
10#include <QUrl>
11
12#ifdef __linux__
13#include <QProcessEnvironment>
14#include <cstdlib>
15
16namespace {
17// String name of LD_PRELOAD environment variable
18constexpr const char *LDPRELOAD_ENV = "LD_PRELOAD";
19} // namespace
20#endif
21
22namespace MantidQt::API {
23
35bool MantidDesktopServices::openUrl(const QUrl &url) {
36#ifndef __linux__
37 return QDesktopServices::openUrl(url);
38#else
39 // Remove LD_PRELOAD if present
40 auto systemEnv = QProcessEnvironment::systemEnvironment();
41 auto ldpreload = systemEnv.value(LDPRELOAD_ENV, QString());
42 if (!ldpreload.isEmpty()) {
43 unsetenv(LDPRELOAD_ENV);
44 }
45 auto status = QDesktopServices::openUrl(url);
46 if (!ldpreload.isEmpty()) {
47 setenv(LDPRELOAD_ENV, qPrintable(ldpreload), 1 /* overwrite*/);
48 }
49 return status;
50#endif
51}
52
53bool MantidDesktopServices::openUrl(const QString &url) { return openUrl(QUrl(url)); }
54
64void MantidDesktopServices::setUrlHandler(const QString &scheme, QObject *receiver, const char *method) {
65 QDesktopServices::setUrlHandler(scheme, receiver, method);
66}
67
74void MantidDesktopServices::unsetUrlHandler(const QString &scheme) { QDesktopServices::unsetUrlHandler(scheme); }
75} // namespace MantidQt::API
static void unsetUrlHandler(const QString &scheme)
Pass through method to MantidDesktopServices::unsetUrlHandler.
static bool openUrl(const QUrl &url)
Opens a url in the appropriate web browser.
static void setUrlHandler(const QString &scheme, QObject *receiver, const char *method)
Pass through method to MantidDesktopServices::setUrlHandler.