mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 02:49:59 +02:00
cleanup accepted files implementation
This commit is contained in:
parent
8e0141b8e9
commit
3c41ecd091
4 changed files with 93 additions and 39 deletions
|
@ -873,8 +873,10 @@ void Application::controlledBroadcastToNodes(const QByteArray& packet, const Nod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::importSVOFromURL(QUrl url) {
|
bool Application::importSVOFromURL(const QString& urlString) {
|
||||||
|
QUrl url(urlString);
|
||||||
emit svoImportRequested(url.url());
|
emit svoImportRequested(url.url());
|
||||||
|
return true; // assume it's accepted
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Application::event(QEvent* event) {
|
bool Application::event(QEvent* event) {
|
||||||
|
@ -887,14 +889,9 @@ bool Application::event(QEvent* event) {
|
||||||
QUrl url = fileEvent->url();
|
QUrl url = fileEvent->url();
|
||||||
|
|
||||||
if (!url.isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
if (url.scheme() == HIFI_URL_SCHEME) {
|
QString urlString = url.toString();
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(fileEvent->url().toString());
|
if (canAcceptURL(urlString)) {
|
||||||
} else if (url.path().toLower().endsWith(SVO_EXTENSION)) {
|
return acceptURL(urlString);
|
||||||
emit svoImportRequested(url.url());
|
|
||||||
} else if (url.path().toLower().endsWith(JS_EXTENSION)) {
|
|
||||||
askToLoadScript(url.toString());
|
|
||||||
//} else if (url.path().toLower().endsWith(FST_EXTENSION)) {
|
|
||||||
// askToSetAvatarUrl(url.toString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -1482,17 +1479,16 @@ void Application::dropEvent(QDropEvent *event) {
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
} else if (lower.endsWith(SVO_EXTENSION)) {
|
} else {
|
||||||
emit svoImportRequested(url.url());
|
QString urlString = url.toString();
|
||||||
event->acceptProposedAction();
|
if (canAcceptURL(urlString)) {
|
||||||
atLeastOneFileAccepted = true;
|
if (acceptURL(urlString)) {
|
||||||
} else if (lower.endsWith(JS_EXTENSION)) {
|
atLeastOneFileAccepted = true;
|
||||||
askToLoadScript(url.url());
|
break;
|
||||||
atLeastOneFileAccepted = true;
|
}
|
||||||
} else if (lower.endsWith(FST_EXTENSION)) {
|
}
|
||||||
askToSetAvatarUrl(url.url());
|
|
||||||
atLeastOneFileAccepted = true;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atLeastOneFileAccepted) {
|
if (atLeastOneFileAccepted) {
|
||||||
|
@ -3601,7 +3597,61 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
workerThread->start();
|
workerThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::askToSetAvatarUrl(const QString& url) {
|
void Application::initializeAcceptedFiles() {
|
||||||
|
if (_acceptedExtensions.size() == 0) {
|
||||||
|
qDebug() << "Application::initializeAcceptedFiles()";
|
||||||
|
_acceptedExtensions[SVO_EXTENSION] = &Application::importSVOFromURL;
|
||||||
|
_acceptedExtensions[JS_EXTENSION] = &Application::askToLoadScript;
|
||||||
|
_acceptedExtensions[FST_EXTENSION] = &Application::askToSetAvatarUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::canAcceptURL(const QString& urlString) {
|
||||||
|
qDebug() << "Application::canAcceptURL() urlString:" << urlString;
|
||||||
|
initializeAcceptedFiles();
|
||||||
|
|
||||||
|
QUrl url(urlString);
|
||||||
|
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
QHashIterator<QString, AcceptURLMethod> i(_acceptedExtensions);
|
||||||
|
QString lowerPath = url.path().toLower();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
if (lowerPath.endsWith(i.key())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Application::acceptURL(const QString& urlString) {
|
||||||
|
qDebug() << "Application::acceptURL() urlString:" << urlString;
|
||||||
|
initializeAcceptedFiles();
|
||||||
|
|
||||||
|
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||||
|
// this is a hifi URL - have the AddressManager handle it
|
||||||
|
QMetaObject::invokeMethod(DependencyManager::get<AddressManager>().data(), "handleLookupString",
|
||||||
|
Qt::AutoConnection, Q_ARG(const QString&, urlString));
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
QUrl url(urlString);
|
||||||
|
QHashIterator<QString, AcceptURLMethod> i(_acceptedExtensions);
|
||||||
|
QString lowerPath = url.path().toLower();
|
||||||
|
while (i.hasNext()) {
|
||||||
|
i.next();
|
||||||
|
if (lowerPath.endsWith(i.key())) {
|
||||||
|
AcceptURLMethod method = i.value();
|
||||||
|
(this->*method)(urlString);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Application::askToSetAvatarUrl(const QString& url) {
|
||||||
QUrl realUrl(url);
|
QUrl realUrl(url);
|
||||||
if (realUrl.isLocalFile()) {
|
if (realUrl.isLocalFile()) {
|
||||||
QString message = "You can not use local files for avatar components.";
|
QString message = "You can not use local files for avatar components.";
|
||||||
|
@ -3611,7 +3661,7 @@ void Application::askToSetAvatarUrl(const QString& url) {
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
msgBox.setIcon(QMessageBox::Warning);
|
msgBox.setIcon(QMessageBox::Warning);
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString message = "Would you like to use this model for part of avatar:\n" + url;
|
QString message = "Would you like to use this model for part of avatar:\n" + url;
|
||||||
|
@ -3624,7 +3674,7 @@ void Application::askToSetAvatarUrl(const QString& url) {
|
||||||
QPushButton* headButton = msgBox.addButton(tr("Head"), QMessageBox::ActionRole);
|
QPushButton* headButton = msgBox.addButton(tr("Head"), QMessageBox::ActionRole);
|
||||||
QPushButton* bodyButton = msgBox.addButton(tr("Body"), QMessageBox::ActionRole);
|
QPushButton* bodyButton = msgBox.addButton(tr("Body"), QMessageBox::ActionRole);
|
||||||
QPushButton* bodyAndHeadButton = msgBox.addButton(tr("Body + Head"), QMessageBox::ActionRole);
|
QPushButton* bodyAndHeadButton = msgBox.addButton(tr("Body + Head"), QMessageBox::ActionRole);
|
||||||
QPushButton* cancelButton = msgBox.addButton(QMessageBox::Cancel);
|
msgBox.addButton(QMessageBox::Cancel);
|
||||||
|
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
|
|
||||||
|
@ -3650,10 +3700,11 @@ void Application::askToSetAvatarUrl(const QString& url) {
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "Declined to use the avatar: " << url;
|
qDebug() << "Declined to use the avatar: " << url;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
||||||
QMessageBox::StandardButton reply;
|
QMessageBox::StandardButton reply;
|
||||||
QString message = "Would you like to run this script:\n" + scriptFilenameOrURL;
|
QString message = "Would you like to run this script:\n" + scriptFilenameOrURL;
|
||||||
reply = QMessageBox::question(getWindow(), "Run Script", message, QMessageBox::Yes|QMessageBox::No);
|
reply = QMessageBox::question(getWindow(), "Run Script", message, QMessageBox::Yes|QMessageBox::No);
|
||||||
|
|
|
@ -128,6 +128,8 @@ class Application;
|
||||||
#endif
|
#endif
|
||||||
#define qApp (static_cast<Application*>(QCoreApplication::instance()))
|
#define qApp (static_cast<Application*>(QCoreApplication::instance()))
|
||||||
|
|
||||||
|
typedef bool (Application::* AcceptURLMethod)(const QString &);
|
||||||
|
|
||||||
class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface {
|
class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -222,7 +224,7 @@ public:
|
||||||
float getFieldOfView() { return _fieldOfView.get(); }
|
float getFieldOfView() { return _fieldOfView.get(); }
|
||||||
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
|
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
|
||||||
|
|
||||||
void importSVOFromURL(QUrl url);
|
bool importSVOFromURL(const QString& urlString);
|
||||||
|
|
||||||
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
|
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
|
||||||
void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); }
|
void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); }
|
||||||
|
@ -307,6 +309,10 @@ public:
|
||||||
|
|
||||||
QString getScriptsLocation();
|
QString getScriptsLocation();
|
||||||
void setScriptsLocation(const QString& scriptsLocation);
|
void setScriptsLocation(const QString& scriptsLocation);
|
||||||
|
|
||||||
|
void initializeAcceptedFiles();
|
||||||
|
bool canAcceptURL(const QString& url);
|
||||||
|
bool acceptURL(const QString& url);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
@ -342,8 +348,8 @@ public slots:
|
||||||
void loadDialog();
|
void loadDialog();
|
||||||
void loadScriptURLDialog();
|
void loadScriptURLDialog();
|
||||||
void toggleLogDialog();
|
void toggleLogDialog();
|
||||||
void askToSetAvatarUrl(const QString& url);
|
bool askToSetAvatarUrl(const QString& url);
|
||||||
void askToLoadScript(const QString& scriptFilenameOrURL);
|
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
||||||
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
|
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
|
||||||
bool loadScriptFromEditor = false, bool activateMainWindow = false);
|
bool loadScriptFromEditor = false, bool activateMainWindow = false);
|
||||||
void scriptFinished(const QString& scriptName);
|
void scriptFinished(const QString& scriptName);
|
||||||
|
@ -597,6 +603,8 @@ private:
|
||||||
|
|
||||||
QWidget* _fullscreenMenuWidget = new QWidget();
|
QWidget* _fullscreenMenuWidget = new QWidget();
|
||||||
int _menuBarHeight;
|
int _menuBarHeight;
|
||||||
|
|
||||||
|
QHash<QString, AcceptURLMethod> _acceptedExtensions;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Application_h
|
#endif // hifi_Application_h
|
||||||
|
|
|
@ -171,8 +171,8 @@ void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
|
||||||
const QMimeData* mimeData = event->mimeData();
|
const QMimeData* mimeData = event->mimeData();
|
||||||
foreach (QUrl url, mimeData->urls()) {
|
foreach (QUrl url, mimeData->urls()) {
|
||||||
auto lower = url.path().toLower();
|
auto lower = url.path().toLower();
|
||||||
if (lower.endsWith(SNAPSHOT_EXTENSION) || lower.endsWith(SVO_EXTENSION)
|
auto urlString = url.toString();
|
||||||
|| lower.endsWith(JS_EXTENSION) || lower.endsWith(FST_EXTENSION)) {
|
if (lower.endsWith(SNAPSHOT_EXTENSION) || Application::getInstance()->canAcceptURL(urlString)) {
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,16 +33,11 @@ void DataWebPage::javaScriptConsoleMessage(const QString& message, int lineNumbe
|
||||||
|
|
||||||
bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) {
|
bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) {
|
||||||
if (!request.url().toString().startsWith(HIFI_URL_SCHEME)) {
|
if (!request.url().toString().startsWith(HIFI_URL_SCHEME)) {
|
||||||
if (request.url().path().toLower().endsWith(SVO_EXTENSION)) {
|
QString urlString = request.url().toString();
|
||||||
Application::getInstance()->importSVOFromURL(request.url());
|
if (Application::getInstance()->canAcceptURL(urlString)) {
|
||||||
return false;
|
if (Application::getInstance()->acceptURL(urlString)) {
|
||||||
} else if (request.url().path().toLower().endsWith(JS_EXTENSION)) {
|
return false; // we handled it, so QWebPage doesn't need to handle it
|
||||||
Application::getInstance()->askToLoadScript(request.url().toString());
|
}
|
||||||
return false;
|
|
||||||
} else if (request.url().path().toLower().endsWith(FST_EXTENSION)) {
|
|
||||||
|
|
||||||
Application::getInstance()->askToSetAvatarUrl(request.url().toString());
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue