mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 23:57:19 +02:00
more DRYing up of code
This commit is contained in:
parent
5814a14152
commit
c5314aceac
3 changed files with 31 additions and 34 deletions
|
@ -1452,43 +1452,16 @@ void Application::wheelEvent(QWheelEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::dropEvent(QDropEvent *event) {
|
void Application::dropEvent(QDropEvent *event) {
|
||||||
QString snapshotPath;
|
|
||||||
const QMimeData *mimeData = event->mimeData();
|
const QMimeData *mimeData = event->mimeData();
|
||||||
bool atLeastOneFileAccepted = false;
|
bool atLeastOneFileAccepted = false;
|
||||||
foreach (QUrl url, mimeData->urls()) {
|
foreach (QUrl url, mimeData->urls()) {
|
||||||
auto lower = url.path().toLower();
|
QString urlString = url.toString();
|
||||||
if (lower.endsWith(SNAPSHOT_EXTENSION)) {
|
if (canAcceptURL(urlString)) {
|
||||||
snapshotPath = url.toLocalFile();
|
if (acceptURL(urlString)) {
|
||||||
|
|
||||||
|
|
||||||
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
|
|
||||||
if (snapshotData) {
|
|
||||||
if (!snapshotData->getDomain().isEmpty()) {
|
|
||||||
DependencyManager::get<NodeList>()->getDomainHandler().setHostnameAndPort(snapshotData->getDomain());
|
|
||||||
}
|
|
||||||
|
|
||||||
_myAvatar->setPosition(snapshotData->getLocation());
|
|
||||||
_myAvatar->setOrientation(snapshotData->getOrientation());
|
|
||||||
atLeastOneFileAccepted = true;
|
atLeastOneFileAccepted = true;
|
||||||
break; // don't process further files
|
break;
|
||||||
} else {
|
|
||||||
QMessageBox msgBox;
|
|
||||||
msgBox.setText("No location details were found in the file "
|
|
||||||
+ snapshotPath + ", try dragging in an authentic Hifi snapshot.");
|
|
||||||
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
||||||
msgBox.exec();
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
QString urlString = url.toString();
|
|
||||||
if (canAcceptURL(urlString)) {
|
|
||||||
if (acceptURL(urlString)) {
|
|
||||||
atLeastOneFileAccepted = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (atLeastOneFileAccepted) {
|
if (atLeastOneFileAccepted) {
|
||||||
|
@ -1496,6 +1469,29 @@ void Application::dropEvent(QDropEvent *event) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Application::acceptSnapshot(const QString& urlString) {
|
||||||
|
QUrl url(urlString);
|
||||||
|
QString snapshotPath = url.toLocalFile();
|
||||||
|
|
||||||
|
SnapshotMetaData* snapshotData = Snapshot::parseSnapshotData(snapshotPath);
|
||||||
|
if (snapshotData) {
|
||||||
|
if (!snapshotData->getDomain().isEmpty()) {
|
||||||
|
DependencyManager::get<NodeList>()->getDomainHandler().setHostnameAndPort(snapshotData->getDomain());
|
||||||
|
}
|
||||||
|
|
||||||
|
_myAvatar->setPosition(snapshotData->getLocation());
|
||||||
|
_myAvatar->setOrientation(snapshotData->getOrientation());
|
||||||
|
} else {
|
||||||
|
QMessageBox msgBox;
|
||||||
|
msgBox.setText("No location details were found in the file "
|
||||||
|
+ snapshotPath + ", try dragging in an authentic Hifi snapshot.");
|
||||||
|
|
||||||
|
msgBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
msgBox.exec();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void Application::sendPingPackets() {
|
void Application::sendPingPackets() {
|
||||||
QByteArray pingPacket = DependencyManager::get<NodeList>()->constructPingPacket();
|
QByteArray pingPacket = DependencyManager::get<NodeList>()->constructPingPacket();
|
||||||
controlledBroadcastToNodes(pingPacket, NodeSet()
|
controlledBroadcastToNodes(pingPacket, NodeSet()
|
||||||
|
@ -3600,6 +3596,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
void Application::initializeAcceptedFiles() {
|
void Application::initializeAcceptedFiles() {
|
||||||
if (_acceptedExtensions.size() == 0) {
|
if (_acceptedExtensions.size() == 0) {
|
||||||
qDebug() << "Application::initializeAcceptedFiles()";
|
qDebug() << "Application::initializeAcceptedFiles()";
|
||||||
|
_acceptedExtensions[SNAPSHOT_EXTENSION] = &Application::acceptSnapshot;
|
||||||
_acceptedExtensions[SVO_EXTENSION] = &Application::importSVOFromURL;
|
_acceptedExtensions[SVO_EXTENSION] = &Application::importSVOFromURL;
|
||||||
_acceptedExtensions[JS_EXTENSION] = &Application::askToLoadScript;
|
_acceptedExtensions[JS_EXTENSION] = &Application::askToLoadScript;
|
||||||
_acceptedExtensions[FST_EXTENSION] = &Application::askToSetAvatarUrl;
|
_acceptedExtensions[FST_EXTENSION] = &Application::askToSetAvatarUrl;
|
||||||
|
|
|
@ -348,6 +348,7 @@ public slots:
|
||||||
void loadDialog();
|
void loadDialog();
|
||||||
void loadScriptURLDialog();
|
void loadScriptURLDialog();
|
||||||
void toggleLogDialog();
|
void toggleLogDialog();
|
||||||
|
bool acceptSnapshot(const QString& urlString);
|
||||||
bool askToSetAvatarUrl(const QString& url);
|
bool askToSetAvatarUrl(const QString& url);
|
||||||
bool 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,
|
||||||
|
|
|
@ -170,9 +170,8 @@ void GLCanvas::wheelEvent(QWheelEvent* event) {
|
||||||
void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
|
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 urlString = url.toString();
|
auto urlString = url.toString();
|
||||||
if (lower.endsWith(SNAPSHOT_EXTENSION) || Application::getInstance()->canAcceptURL(urlString)) {
|
if (Application::getInstance()->canAcceptURL(urlString)) {
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue