mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 08:49:05 +02:00
fix openDirectory
(cherry picked from commit 609e58a0ddcff0ace1d75a85fafd73bfa4a5eacd)
This commit is contained in:
parent
5f3a37d40e
commit
b9ba764e0f
4 changed files with 29 additions and 8 deletions
|
@ -2443,6 +2443,7 @@ 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("file", this, "showUrlHandler");
|
||||||
QDesktopServices::setUrlHandler("", this, "showUrlHandler");
|
QDesktopServices::setUrlHandler("", this, "showUrlHandler");
|
||||||
auto drives = QDir::drives();
|
auto drives = QDir::drives();
|
||||||
|
@ -9251,6 +9252,26 @@ 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) {
|
void Application::showUrlHandler(const QUrl& url) {
|
||||||
if (QThread::currentThread() != thread()) {
|
if (QThread::currentThread() != thread()) {
|
||||||
QMetaObject::invokeMethod(this, "showUrlHandler", Q_ARG(const QUrl&, url));
|
QMetaObject::invokeMethod(this, "showUrlHandler", Q_ARG(const QUrl&, url));
|
||||||
|
|
|
@ -344,6 +344,8 @@ public:
|
||||||
void toggleAwayMode();
|
void toggleAwayMode();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void openDirectory(const QString& path);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void svoImportRequested(const QString& url);
|
void svoImportRequested(const QString& url);
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include <QtCore/QRegularExpression>
|
#include <QtCore/QRegularExpression>
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
|
|
||||||
|
std::function<void(const QString&)> FileDialogHelper::_openDiretoryOperator = nullptr;
|
||||||
|
|
||||||
QUrl FileDialogHelper::home() {
|
QUrl FileDialogHelper::home() {
|
||||||
return pathToUrl(QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);
|
return pathToUrl(QStandardPaths::standardLocations(QStandardPaths::HomeLocation)[0]);
|
||||||
|
@ -111,14 +112,8 @@ QStringList FileDialogHelper::drives() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileDialogHelper::openDirectory(const QString& path) {
|
void FileDialogHelper::openDirectory(const QString& path) {
|
||||||
QString dirPath = path;
|
if (_openDiretoryOperator) {
|
||||||
const QString FILE_SCHEME = "file://";
|
_openDiretoryOperator(path);
|
||||||
if (dirPath.startsWith(FILE_SCHEME)) {
|
|
||||||
dirPath.remove(0, FILE_SCHEME.length());
|
|
||||||
}
|
|
||||||
QFileInfo fileInfo(dirPath);
|
|
||||||
if (fileInfo.isDir()) {
|
|
||||||
QDesktopServices::openUrl(path);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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&)> openDiretoryOperator) { _openDiretoryOperator = openDiretoryOperator; }
|
||||||
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&)> _openDiretoryOperator;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue