mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 06:03:26 +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());
|
||||
return true; // assume it's accepted
|
||||
}
|
||||
|
||||
bool Application::event(QEvent* event) {
|
||||
|
@ -887,14 +889,9 @@ bool Application::event(QEvent* event) {
|
|||
QUrl url = fileEvent->url();
|
||||
|
||||
if (!url.isEmpty()) {
|
||||
if (url.scheme() == HIFI_URL_SCHEME) {
|
||||
DependencyManager::get<AddressManager>()->handleLookupString(fileEvent->url().toString());
|
||||
} else if (url.path().toLower().endsWith(SVO_EXTENSION)) {
|
||||
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());
|
||||
QString urlString = url.toString();
|
||||
if (canAcceptURL(urlString)) {
|
||||
return acceptURL(urlString);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -1482,17 +1479,16 @@ void Application::dropEvent(QDropEvent *event) {
|
|||
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||
msgBox.exec();
|
||||
}
|
||||
} else if (lower.endsWith(SVO_EXTENSION)) {
|
||||
emit svoImportRequested(url.url());
|
||||
event->acceptProposedAction();
|
||||
atLeastOneFileAccepted = true;
|
||||
} else if (lower.endsWith(JS_EXTENSION)) {
|
||||
askToLoadScript(url.url());
|
||||
atLeastOneFileAccepted = true;
|
||||
} else if (lower.endsWith(FST_EXTENSION)) {
|
||||
askToSetAvatarUrl(url.url());
|
||||
atLeastOneFileAccepted = true;
|
||||
}
|
||||
} else {
|
||||
QString urlString = url.toString();
|
||||
if (canAcceptURL(urlString)) {
|
||||
if (acceptURL(urlString)) {
|
||||
atLeastOneFileAccepted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (atLeastOneFileAccepted) {
|
||||
|
@ -3601,7 +3597,61 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
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);
|
||||
if (realUrl.isLocalFile()) {
|
||||
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.setIcon(QMessageBox::Warning);
|
||||
msgBox.exec();
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
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* bodyButton = msgBox.addButton(tr("Body"), QMessageBox::ActionRole);
|
||||
QPushButton* bodyAndHeadButton = msgBox.addButton(tr("Body + Head"), QMessageBox::ActionRole);
|
||||
QPushButton* cancelButton = msgBox.addButton(QMessageBox::Cancel);
|
||||
msgBox.addButton(QMessageBox::Cancel);
|
||||
|
||||
msgBox.exec();
|
||||
|
||||
|
@ -3650,10 +3700,11 @@ void Application::askToSetAvatarUrl(const QString& url) {
|
|||
} else {
|
||||
qDebug() << "Declined to use the avatar: " << url;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
||||
bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
||||
QMessageBox::StandardButton reply;
|
||||
QString message = "Would you like to run this script:\n" + scriptFilenameOrURL;
|
||||
reply = QMessageBox::question(getWindow(), "Run Script", message, QMessageBox::Yes|QMessageBox::No);
|
||||
|
|
|
@ -128,6 +128,8 @@ class Application;
|
|||
#endif
|
||||
#define qApp (static_cast<Application*>(QCoreApplication::instance()))
|
||||
|
||||
typedef bool (Application::* AcceptURLMethod)(const QString &);
|
||||
|
||||
class Application : public QApplication, public AbstractViewStateInterface, AbstractScriptingServicesInterface {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -222,7 +224,7 @@ public:
|
|||
float getFieldOfView() { return _fieldOfView.get(); }
|
||||
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
|
||||
|
||||
void importSVOFromURL(QUrl url);
|
||||
bool importSVOFromURL(const QString& urlString);
|
||||
|
||||
NodeToOctreeSceneStats* getOcteeSceneStats() { return &_octreeServerSceneStats; }
|
||||
void lockOctreeSceneStats() { _octreeSceneStatsLock.lockForRead(); }
|
||||
|
@ -307,6 +309,10 @@ public:
|
|||
|
||||
QString getScriptsLocation();
|
||||
void setScriptsLocation(const QString& scriptsLocation);
|
||||
|
||||
void initializeAcceptedFiles();
|
||||
bool canAcceptURL(const QString& url);
|
||||
bool acceptURL(const QString& url);
|
||||
|
||||
signals:
|
||||
|
||||
|
@ -342,8 +348,8 @@ public slots:
|
|||
void loadDialog();
|
||||
void loadScriptURLDialog();
|
||||
void toggleLogDialog();
|
||||
void askToSetAvatarUrl(const QString& url);
|
||||
void askToLoadScript(const QString& scriptFilenameOrURL);
|
||||
bool askToSetAvatarUrl(const QString& url);
|
||||
bool askToLoadScript(const QString& scriptFilenameOrURL);
|
||||
ScriptEngine* loadScript(const QString& scriptFilename = QString(), bool isUserLoaded = true,
|
||||
bool loadScriptFromEditor = false, bool activateMainWindow = false);
|
||||
void scriptFinished(const QString& scriptName);
|
||||
|
@ -597,6 +603,8 @@ private:
|
|||
|
||||
QWidget* _fullscreenMenuWidget = new QWidget();
|
||||
int _menuBarHeight;
|
||||
|
||||
QHash<QString, AcceptURLMethod> _acceptedExtensions;
|
||||
};
|
||||
|
||||
#endif // hifi_Application_h
|
||||
|
|
|
@ -171,8 +171,8 @@ void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
|
|||
const QMimeData* mimeData = event->mimeData();
|
||||
foreach (QUrl url, mimeData->urls()) {
|
||||
auto lower = url.path().toLower();
|
||||
if (lower.endsWith(SNAPSHOT_EXTENSION) || lower.endsWith(SVO_EXTENSION)
|
||||
|| lower.endsWith(JS_EXTENSION) || lower.endsWith(FST_EXTENSION)) {
|
||||
auto urlString = url.toString();
|
||||
if (lower.endsWith(SNAPSHOT_EXTENSION) || Application::getInstance()->canAcceptURL(urlString)) {
|
||||
event->acceptProposedAction();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -33,16 +33,11 @@ void DataWebPage::javaScriptConsoleMessage(const QString& message, int lineNumbe
|
|||
|
||||
bool DataWebPage::acceptNavigationRequest(QWebFrame* frame, const QNetworkRequest& request, QWebPage::NavigationType type) {
|
||||
if (!request.url().toString().startsWith(HIFI_URL_SCHEME)) {
|
||||
if (request.url().path().toLower().endsWith(SVO_EXTENSION)) {
|
||||
Application::getInstance()->importSVOFromURL(request.url());
|
||||
return false;
|
||||
} else if (request.url().path().toLower().endsWith(JS_EXTENSION)) {
|
||||
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;
|
||||
QString urlString = request.url().toString();
|
||||
if (Application::getInstance()->canAcceptURL(urlString)) {
|
||||
if (Application::getInstance()->acceptURL(urlString)) {
|
||||
return false; // we handled it, so QWebPage doesn't need to handle it
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue