Showing the changes to interface/src/scripting/GlobalServicesScriptingInterface.cpp (1 of 3 files). Show all
Unified · Split
| @@ -10,8 +10,9 @@ · 9 unmodified lines | |||
| 10 | // | 10 | // |
| 11 | 11 | ||
| 12 | #include "AccountManager.h" | 12 | #include "AccountManager.h" |
| 13 | #include "XmppClient.h" | 13 | #include "Application.h" |
| 14 | #include "ResourceCache.h" | 14 | #include "ResourceCache.h" |
| 15 | #include "XmppClient.h" | ||
| 15 | 16 | ||
| 16 | #include "GlobalServicesScriptingInterface.h" | 17 | #include "GlobalServicesScriptingInterface.h" |
| 17 | 18 | ||
| @@ -26,6 +27,9 @@ GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { · 8 unmodified lines | |||
| 26 | const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient(); | 27 | const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient(); |
| 27 | connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived); | 28 | connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived); |
| 28 | #endif // HAVE_QXMPP | 29 | #endif // HAVE_QXMPP |
| 30 | |||
| 31 | _downloading = false; | ||
| 32 | connect(Application::getInstance(), &Application::renderingInWorldInterface, this, &GlobalServicesScriptingInterface::checkDownloadInfo); | ||
| 29 | } | 33 | } |
| 30 | 34 | ||
| 31 | GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { | 35 | GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() { |
| @@ -115,16 +119,6 @@ void GlobalServicesScriptingInterface::messageReceived(const QXmppMessage& messa · 83 unmodified lines | |||
| 115 | } | 119 | } |
| 116 | #endif // HAVE_QXMPP | 120 | #endif // HAVE_QXMPP |
| 117 | 121 | ||
| 118 | DownloadInfoResult GlobalServicesScriptingInterface::getDownloadInfo() { | ||
| 119 | DownloadInfoResult result; | ||
| 120 | foreach(Resource* resource, ResourceCache::getLoadingRequests()) { | ||
| 121 | result.downloading.append(resource->getProgress() * 100.0f); | ||
| 122 | } | ||
| 123 | result.pending = ResourceCache::getPendingRequestCount(); | ||
| 124 | |||
| 125 | return result; | ||
| 126 | } | ||
| 127 | |||
| 128 | 122 | ||
| 129 | DownloadInfoResult::DownloadInfoResult() : | 123 | DownloadInfoResult::DownloadInfoResult() : |
| 130 | downloading(QList<float>()), | 124 | downloading(QList<float>()), |
| @@ -154,3 +148,27 @@ void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoR · 23 unmodified lines | |||
| 154 | 148 | ||
| 155 | result.pending = object.property("pending").toVariant().toFloat(); | 149 | result.pending = object.property("pending").toVariant().toFloat(); |
| 156 | } | 150 | } |
| 151 | |||
| 152 | DownloadInfoResult GlobalServicesScriptingInterface::getDownloadInfo() { | ||
| 153 | DownloadInfoResult result; | ||
| 154 | foreach(Resource* resource, ResourceCache::getLoadingRequests()) { | ||
| 155 | result.downloading.append(resource->getProgress() * 100.0f); | ||
| 156 | } | ||
| 157 | result.pending = ResourceCache::getPendingRequestCount(); | ||
| 158 | return result; | ||
| 159 | } | ||
| 160 | |||
| 161 | void GlobalServicesScriptingInterface::checkDownloadInfo() { | ||
| 162 | DownloadInfoResult downloadInfo = getDownloadInfo(); | ||
| 163 | bool downloading = downloadInfo.downloading.count() > 0 || downloadInfo.pending > 0; | ||
| 164 | |||
| 165 | // Emit signal if downloading or have just finished. | ||
| 166 | if (downloading || _downloading) { | ||
| 167 | _downloading = downloading; | ||
| 168 | emit downloadInfoChanged(downloadInfo); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | void GlobalServicesScriptingInterface::updateDownloadInfo() { | ||
| 173 | emit downloadInfoChanged(getDownloadInfo()); | ||
| 174 | } | ||