From 3994ec4176b015c921dc1138b9fbd43ae6388a35 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Thu, 5 Jul 2018 17:54:27 -0700 Subject: [PATCH 1/4] adding potential fix - moving methods to Application --- interface/src/Application.cpp | 23 ++++++++++++++++++++++- interface/src/Application.h | 3 +++ interface/src/Menu.cpp | 5 ++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 4b530dc1d0..3eff06742d 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -1668,7 +1669,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0; }); _applicationStateDevice->setInputVariant(STATE_ADVANCED_MOVEMENT_CONTROLS, []() -> float { - return qApp->getMyAvatar()->useAdvancedMovementControls() ? 1 : 0; + auto isAdvanced = qApp->getMyAvatar()->useAdvancedMovementControls(); + return isAdvanced ? 1 : 0; }); _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float { @@ -8304,6 +8306,25 @@ void Application::saveNextPhysicsStats(QString filename) { _physicsEngine->saveNextPhysicsStats(filename); } +void Application::copyAddress() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "copyAddress"); + return; + } + + // assume that the address is being copied because the user wants a shareable address + QApplication::clipboard()->setText(QString("copyAddress worked!")); +} + +void Application::copyPath() { + if (QThread::currentThread() != thread()) { + QMetaObject::invokeMethod(this, "copyPath"); + return; + } + + QApplication::clipboard()->setText(QString("copyPath worked!")); +} + #if defined(Q_OS_ANDROID) void Application::enterBackground() { QMetaObject::invokeMethod(DependencyManager::get().data(), diff --git a/interface/src/Application.h b/interface/src/Application.h index 346ea258da..13e4d83fd4 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -368,6 +368,9 @@ public slots: void resetSensors(bool andReload = false); void setActiveFaceTracker() const; + void copyAddress(); + void copyPath(); + #if (PR_BUILD || DEV_BUILD) void sendWrongProtocolVersionsSignature(bool checked) { ::sendWrongProtocolVersionsSignature(checked); } #endif diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 646067169f..4554d1efd8 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -268,13 +268,12 @@ Menu::Menu() { locationBookmarks->setupMenus(this, navigateMenu); // Navigate > Copy Address - auto addressManager = DependencyManager::get(); addActionToQMenuAndActionHash(navigateMenu, MenuOption::CopyAddress, 0, - addressManager.data(), SLOT(copyAddress())); + qApp, SLOT(copyAddress())); // Navigate > Copy Path addActionToQMenuAndActionHash(navigateMenu, MenuOption::CopyPath, 0, - addressManager.data(), SLOT(copyPath())); + qApp, SLOT(copyPath())); // Settings menu ---------------------------------- From 0facbedbbc6672c969261d0718b34cc46c752c8e Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 6 Jul 2018 11:03:58 -0700 Subject: [PATCH 2/4] adding Q_INVOKABLE method for copying to Application clipboard --- interface/src/Application.cpp | 17 ++++------------- interface/src/Application.h | 3 +-- interface/src/Menu.cpp | 5 +++-- libraries/networking/src/AddressManager.cpp | 5 ++--- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 3eff06742d..a58af6e623 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -8306,23 +8306,14 @@ void Application::saveNextPhysicsStats(QString filename) { _physicsEngine->saveNextPhysicsStats(filename); } -void Application::copyAddress() { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "copyAddress"); +void Application::copyToClipboard(const QString& text) { + if (QThread::currentThread() != qApp->thread()) { + QMetaObject::invokeMethod(this, "copyToClipboard"); return; } // assume that the address is being copied because the user wants a shareable address - QApplication::clipboard()->setText(QString("copyAddress worked!")); -} - -void Application::copyPath() { - if (QThread::currentThread() != thread()) { - QMetaObject::invokeMethod(this, "copyPath"); - return; - } - - QApplication::clipboard()->setText(QString("copyPath worked!")); + QApplication::clipboard()->setText(text); } #if defined(Q_OS_ANDROID) diff --git a/interface/src/Application.h b/interface/src/Application.h index 13e4d83fd4..4556488f09 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -368,8 +368,7 @@ public slots: void resetSensors(bool andReload = false); void setActiveFaceTracker() const; - void copyAddress(); - void copyPath(); + Q_INVOKABLE void copyToClipboard(const QString& text); #if (PR_BUILD || DEV_BUILD) void sendWrongProtocolVersionsSignature(bool checked) { ::sendWrongProtocolVersionsSignature(checked); } diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 4554d1efd8..646067169f 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -268,12 +268,13 @@ Menu::Menu() { locationBookmarks->setupMenus(this, navigateMenu); // Navigate > Copy Address + auto addressManager = DependencyManager::get(); addActionToQMenuAndActionHash(navigateMenu, MenuOption::CopyAddress, 0, - qApp, SLOT(copyAddress())); + addressManager.data(), SLOT(copyAddress())); // Navigate > Copy Path addActionToQMenuAndActionHash(navigateMenu, MenuOption::CopyPath, 0, - qApp, SLOT(copyPath())); + addressManager.data(), SLOT(copyPath())); // Settings menu ---------------------------------- diff --git a/libraries/networking/src/AddressManager.cpp b/libraries/networking/src/AddressManager.cpp index 3fe75c5495..00e552af89 100644 --- a/libraries/networking/src/AddressManager.cpp +++ b/libraries/networking/src/AddressManager.cpp @@ -852,17 +852,16 @@ void AddressManager::refreshPreviousLookup() { void AddressManager::copyAddress() { if (QThread::currentThread() != qApp->thread()) { - QMetaObject::invokeMethod(this, "copyAddress"); + QMetaObject::invokeMethod(qApp, "copyToClipboard", Q_ARG(QString, currentShareableAddress().toString())); return; } - // assume that the address is being copied because the user wants a shareable address QGuiApplication::clipboard()->setText(currentShareableAddress().toString()); } void AddressManager::copyPath() { if (QThread::currentThread() != qApp->thread()) { - QMetaObject::invokeMethod(this, "copyPath"); + QMetaObject::invokeMethod(qApp, "copyToClipboard", Q_ARG(QString, currentPath())); return; } From eb4704620c5e14c16da4e4b89c736d17c90824ad Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 6 Jul 2018 11:06:16 -0700 Subject: [PATCH 3/4] reverting unintended line from previous debug --- interface/src/Application.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a58af6e623..6448579752 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1669,8 +1669,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo return qApp->getMyAvatar()->getSnapTurn() ? 1 : 0; }); _applicationStateDevice->setInputVariant(STATE_ADVANCED_MOVEMENT_CONTROLS, []() -> float { - auto isAdvanced = qApp->getMyAvatar()->useAdvancedMovementControls(); - return isAdvanced ? 1 : 0; + return qApp->getMyAvatar()->useAdvancedMovementControls() ? 1 : 0; }); _applicationStateDevice->setInputVariant(STATE_GROUNDED, []() -> float { From cb89b046b40e7a8fba135f166284db8a9d6e4d63 Mon Sep 17 00:00:00 2001 From: Wayne Chen Date: Fri, 6 Jul 2018 11:07:35 -0700 Subject: [PATCH 4/4] moving copyToClipboard from slots to functions --- interface/src/Application.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Application.h b/interface/src/Application.h index 4556488f09..e866649079 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -310,6 +310,8 @@ public: void loadAvatarScripts(const QVector& urls); void unloadAvatarScripts(); + Q_INVOKABLE void copyToClipboard(const QString& text); + #if defined(Q_OS_ANDROID) void enterBackground(); void enterForeground(); @@ -368,8 +370,6 @@ public slots: void resetSensors(bool andReload = false); void setActiveFaceTracker() const; - Q_INVOKABLE void copyToClipboard(const QString& text); - #if (PR_BUILD || DEV_BUILD) void sendWrongProtocolVersionsSignature(bool checked) { ::sendWrongProtocolVersionsSignature(checked); } #endif