mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-26 04:15:14 +02:00
Merge pull request #15456 from SamGondelman/openurl
Case 22334: openUrl fix
This commit is contained in:
commit
26a0eb3993
12 changed files with 71 additions and 32 deletions
|
@ -398,7 +398,7 @@ Item {
|
||||||
lineHeight: 1
|
lineHeight: 1
|
||||||
lineHeightMode: Text.ProportionalHeight
|
lineHeightMode: Text.ProportionalHeight
|
||||||
|
|
||||||
onLinkActivated: loginDialog.openUrl(link);
|
onLinkActivated: Window.openUrl(link);
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (termsTextMetrics.width > root.bannerWidth) {
|
if (termsTextMetrics.width > root.bannerWidth) {
|
||||||
|
|
|
@ -363,7 +363,7 @@ Item {
|
||||||
linkColor: hifi.colors.blueAccent
|
linkColor: hifi.colors.blueAccent
|
||||||
onLinkActivated: {
|
onLinkActivated: {
|
||||||
Tablet.playSound(TabletEnums.ButtonClick);
|
Tablet.playSound(TabletEnums.ButtonClick);
|
||||||
loginDialog.openUrl(link);
|
Window.openUrl(link);
|
||||||
lightboxPopup.titleText = "Can't Access Account";
|
lightboxPopup.titleText = "Can't Access Account";
|
||||||
lightboxPopup.bodyText = lightboxPopup.cantAccessBodyText;
|
lightboxPopup.bodyText = lightboxPopup.cantAccessBodyText;
|
||||||
lightboxPopup.button2text = "CLOSE";
|
lightboxPopup.button2text = "CLOSE";
|
||||||
|
|
|
@ -411,7 +411,7 @@ Item {
|
||||||
lineHeight: 1
|
lineHeight: 1
|
||||||
lineHeightMode: Text.ProportionalHeight
|
lineHeightMode: Text.ProportionalHeight
|
||||||
|
|
||||||
onLinkActivated: loginDialog.openUrl(link);
|
onLinkActivated: Window.openUrl(link);
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (termsTextMetrics.width > root.bannerWidth) {
|
if (termsTextMetrics.width > root.bannerWidth) {
|
||||||
|
|
|
@ -234,7 +234,7 @@ Item {
|
||||||
lineHeight: 1
|
lineHeight: 1
|
||||||
lineHeightMode: Text.ProportionalHeight
|
lineHeightMode: Text.ProportionalHeight
|
||||||
|
|
||||||
onLinkActivated: loginDialog.openUrl(link);
|
onLinkActivated: Window.openUrl(link);
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
if (termsTextMetrics.width > root.bannerWidth) {
|
if (termsTextMetrics.width > root.bannerWidth) {
|
||||||
|
|
|
@ -2437,6 +2437,14 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
|
||||||
DependencyManager::get<TabletScriptingInterface>()->preloadSounds();
|
DependencyManager::get<TabletScriptingInterface>()->preloadSounds();
|
||||||
DependencyManager::get<Keyboard>()->createKeyboard();
|
DependencyManager::get<Keyboard>()->createKeyboard();
|
||||||
|
|
||||||
|
FileDialogHelper::setOpenDirectoryOperator([this](const QString& path) { openDirectory(path); });
|
||||||
|
QDesktopServices::setUrlHandler("file", this, "showUrlHandler");
|
||||||
|
QDesktopServices::setUrlHandler("", this, "showUrlHandler");
|
||||||
|
auto drives = QDir::drives();
|
||||||
|
for (auto drive : drives) {
|
||||||
|
QDesktopServices::setUrlHandler(QUrl(drive.absolutePath()).scheme(), this, "showUrlHandler");
|
||||||
|
}
|
||||||
|
|
||||||
_pendingIdleEvent = false;
|
_pendingIdleEvent = false;
|
||||||
_graphicsEngine.startup();
|
_graphicsEngine.startup();
|
||||||
|
|
||||||
|
@ -8262,19 +8270,6 @@ void Application::packageModel() {
|
||||||
ModelPackager::package();
|
ModelPackager::package();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::openUrl(const QUrl& url) const {
|
|
||||||
if (!url.isEmpty()) {
|
|
||||||
if (url.scheme() == URL_SCHEME_HIFI) {
|
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
|
||||||
} else if (url.scheme() == URL_SCHEME_HIFIAPP) {
|
|
||||||
DependencyManager::get<QmlCommerce>()->openSystemApp(url.path());
|
|
||||||
} else {
|
|
||||||
// address manager did not handle - ask QDesktopServices to handle
|
|
||||||
QDesktopServices::openUrl(url);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Application::loadDialog() {
|
void Application::loadDialog() {
|
||||||
ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"),
|
ModalDialogListener* dlg = OffscreenUi::getOpenFileNameAsync(_glWidget, tr("Open Script"),
|
||||||
getPreviousScriptLocation(),
|
getPreviousScriptLocation(),
|
||||||
|
@ -9156,7 +9151,7 @@ void Application::readArgumentsFromLocalSocket() const {
|
||||||
|
|
||||||
// If we received a message, try to open it as a URL
|
// If we received a message, try to open it as a URL
|
||||||
if (message.length() > 0) {
|
if (message.length() > 0) {
|
||||||
qApp->openUrl(QString::fromUtf8(message));
|
DependencyManager::get<WindowScriptingInterface>()->openUrl(QString::fromUtf8(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9273,6 +9268,44 @@ QString Application::getGraphicsCardType() {
|
||||||
return GPUIdent::getInstance()->getName();
|
return GPUIdent::getInstance()->getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Application::openDirectory(const QString& path) {
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
QMetaObject::invokeMethod(this, "openDirectory", Q_ARG(const QString&, path));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString dirPath = path;
|
||||||
|
const QString FILE_SCHEME = "file:///";
|
||||||
|
if (dirPath.startsWith(FILE_SCHEME)) {
|
||||||
|
dirPath.remove(0, FILE_SCHEME.length());
|
||||||
|
}
|
||||||
|
QFileInfo fileInfo(dirPath);
|
||||||
|
if (fileInfo.isDir()) {
|
||||||
|
auto scheme = QUrl(path).scheme();
|
||||||
|
QDesktopServices::unsetUrlHandler(scheme);
|
||||||
|
QDesktopServices::openUrl(path);
|
||||||
|
QDesktopServices::setUrlHandler(scheme, this, "showUrlHandler");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Application::showUrlHandler(const QUrl& url) {
|
||||||
|
if (QThread::currentThread() != thread()) {
|
||||||
|
QMetaObject::invokeMethod(this, "showUrlHandler", Q_ARG(const QUrl&, url));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ModalDialogListener* dlg = OffscreenUi::asyncQuestion("Confirm openUrl", "Do you recognize this path or code and want to open or execute it: " + url.toDisplayString());
|
||||||
|
QObject::connect(dlg, &ModalDialogListener::response, this, [=](QVariant answer) {
|
||||||
|
QObject::disconnect(dlg, &ModalDialogListener::response, this, nullptr);
|
||||||
|
if (QMessageBox::Yes == static_cast<QMessageBox::StandardButton>(answer.toInt())) {
|
||||||
|
// Unset the handler, open the URL, and the reset the handler
|
||||||
|
QDesktopServices::unsetUrlHandler(url.scheme());
|
||||||
|
QDesktopServices::openUrl(url);
|
||||||
|
QDesktopServices::setUrlHandler(url.scheme(), this, "showUrlHandler");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
void Application::beforeEnterBackground() {
|
void Application::beforeEnterBackground() {
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
|
@ -349,6 +349,8 @@ public:
|
||||||
void addSnapshotOperator(const SnapshotOperator& snapshotOperator);
|
void addSnapshotOperator(const SnapshotOperator& snapshotOperator);
|
||||||
bool takeSnapshotOperators(std::queue<SnapshotOperator>& snapshotOperators);
|
bool takeSnapshotOperators(std::queue<SnapshotOperator>& snapshotOperators);
|
||||||
|
|
||||||
|
void openDirectory(const QString& path);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
|
|
||||||
|
@ -408,8 +410,6 @@ public slots:
|
||||||
|
|
||||||
static void packageModel();
|
static void packageModel();
|
||||||
|
|
||||||
void openUrl(const QUrl& url) const;
|
|
||||||
|
|
||||||
void resetSensors(bool andReload = false);
|
void resetSensors(bool andReload = false);
|
||||||
void setActiveFaceTracker() const;
|
void setActiveFaceTracker() const;
|
||||||
|
|
||||||
|
@ -476,6 +476,8 @@ public slots:
|
||||||
|
|
||||||
QString getGraphicsCardType();
|
QString getGraphicsCardType();
|
||||||
|
|
||||||
|
void showUrlHandler(const QUrl& url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
void onDesktopRootItemCreated(QQuickItem* qmlContext);
|
||||||
void onDesktopRootContextCreated(QQmlContext* qmlContext);
|
void onDesktopRootContextCreated(QQmlContext* qmlContext);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "OffscreenUi.h"
|
#include "OffscreenUi.h"
|
||||||
|
#include "commerce/QmlCommerce.h"
|
||||||
|
|
||||||
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
static const QString DESKTOP_LOCATION = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||||
static const QString LAST_BROWSE_LOCATION_SETTING = "LastBrowseLocation";
|
static const QString LAST_BROWSE_LOCATION_SETTING = "LastBrowseLocation";
|
||||||
|
@ -134,15 +135,17 @@ void WindowScriptingInterface::disconnectedFromDomain() {
|
||||||
|
|
||||||
void WindowScriptingInterface::openUrl(const QUrl& url) {
|
void WindowScriptingInterface::openUrl(const QUrl& url) {
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
if (url.scheme() == URL_SCHEME_HIFI) {
|
auto scheme = url.scheme();
|
||||||
|
if (scheme == URL_SCHEME_HIFI) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||||
|
} else if (scheme == URL_SCHEME_HIFIAPP) {
|
||||||
|
DependencyManager::get<QmlCommerce>()->openSystemApp(url.path());
|
||||||
} else {
|
} else {
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
QMap<QString, QString> args;
|
QMap<QString, QString> args;
|
||||||
args["url"] = url.toString();
|
args["url"] = url.toString();
|
||||||
AndroidHelper::instance().requestActivity("WebView", true, args);
|
AndroidHelper::instance().requestActivity("WebView", true, args);
|
||||||
#else
|
#else
|
||||||
// address manager did not handle - ask QDesktopServices to handle
|
|
||||||
QDesktopServices::openUrl(url);
|
QDesktopServices::openUrl(url);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -535,9 +535,10 @@ public slots:
|
||||||
int openMessageBox(QString title, QString text, int buttons, int defaultButton);
|
int openMessageBox(QString title, QString text, int buttons, int defaultButton);
|
||||||
|
|
||||||
/**jsdoc
|
/**jsdoc
|
||||||
* Open a URL in the Interface window or other application, depending on the URL's scheme. If the URL starts with
|
* Open a URL in the Interface window or other application, depending on the URL's scheme. The following schemes are supported:
|
||||||
* <code>hifi://</code> then that URL is navigated to in Interface, otherwise the URL is opened in the application the OS
|
* <code>hifi</code> (navigate to the URL in Interface), <code>hifiapp<code> (open a system app in Interface). Other schemes will either be handled by the OS
|
||||||
* associates with the URL's scheme (e.g., a Web browser for <code>http://</code>).
|
* (e.g. <code>http</code>, <code>https</code>, <code>mailto</code>) or will create a confirmation dialog asking the user to confirm that they want to try to open
|
||||||
|
* the URL.
|
||||||
* @function Window.openUrl
|
* @function Window.openUrl
|
||||||
* @param {string} url - The URL to open.
|
* @param {string} url - The URL to open.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -279,10 +279,6 @@ void LoginDialog::createAccountFromSteam(QString username) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoginDialog::openUrl(const QString& url) const {
|
|
||||||
QDesktopServices::openUrl(QUrl(url));
|
|
||||||
}
|
|
||||||
|
|
||||||
void LoginDialog::linkCompleted(QNetworkReply* reply) {
|
void LoginDialog::linkCompleted(QNetworkReply* reply) {
|
||||||
emit handleLinkCompleted();
|
emit handleLinkCompleted();
|
||||||
}
|
}
|
||||||
|
|
|
@ -80,8 +80,6 @@ protected slots:
|
||||||
|
|
||||||
Q_INVOKABLE void signup(const QString& email, const QString& username, const QString& password);
|
Q_INVOKABLE void signup(const QString& email, const QString& username, const QString& password);
|
||||||
|
|
||||||
Q_INVOKABLE void openUrl(const QString& url) const;
|
|
||||||
|
|
||||||
Q_INVOKABLE bool getLoginDialogPoppedUp() const;
|
Q_INVOKABLE bool getLoginDialogPoppedUp() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <QtCore/QRegularExpression>
|
#include <QtCore/QRegularExpression>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
std::function<void(const QString&)> FileDialogHelper::_openDirectoryOperator = nullptr;
|
||||||
|
|
||||||
QUrl FileDialogHelper::home() {
|
QUrl FileDialogHelper::home() {
|
||||||
return pathToUrl(QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);
|
return pathToUrl(QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);
|
||||||
|
@ -111,7 +112,9 @@ QStringList FileDialogHelper::drives() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDialogHelper::openDirectory(const QString& path) {
|
void FileDialogHelper::openDirectory(const QString& path) {
|
||||||
QDesktopServices::openUrl(path);
|
if (_openDirectoryOperator) {
|
||||||
|
_openDirectoryOperator(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<QUrl> FileDialogHelper::urlToList(const QUrl& url) {
|
QList<QUrl> FileDialogHelper::urlToList(const QUrl& url) {
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include <QtCore/QStringList>
|
#include <QtCore/QStringList>
|
||||||
#include <QtCore/QUrl>
|
#include <QtCore/QUrl>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
class FileDialogHelper : public QObject {
|
class FileDialogHelper : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -62,6 +63,7 @@ public:
|
||||||
Q_INVOKABLE QUrl saveHelper(const QString& saveText, const QUrl& currentFolder, const QStringList& selectionFilters);
|
Q_INVOKABLE QUrl saveHelper(const QString& saveText, const QUrl& currentFolder, const QStringList& selectionFilters);
|
||||||
Q_INVOKABLE QList<QUrl> urlToList(const QUrl& url);
|
Q_INVOKABLE QList<QUrl> urlToList(const QUrl& url);
|
||||||
|
|
||||||
|
static void setOpenDirectoryOperator(std::function<void(const QString&)> openDirectoryOperator) { _openDirectoryOperator = openDirectoryOperator; }
|
||||||
Q_INVOKABLE void openDirectory(const QString& path);
|
Q_INVOKABLE void openDirectory(const QString& path);
|
||||||
|
|
||||||
Q_INVOKABLE void monitorDirectory(const QString& path);
|
Q_INVOKABLE void monitorDirectory(const QString& path);
|
||||||
|
@ -72,6 +74,7 @@ signals:
|
||||||
private:
|
private:
|
||||||
QFileSystemWatcher _fsWatcher;
|
QFileSystemWatcher _fsWatcher;
|
||||||
QString _fsWatcherPath;
|
QString _fsWatcherPath;
|
||||||
|
static std::function<void(const QString&)> _openDirectoryOperator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue