History

Add downloads information changed event for JavaScript

David Rowe committed 11 years ago

Commit 40274df1 parent 8b0d8593 files · +84 −19Browse files

Showing the changes to interface/src/scripting/GlobalServicesScriptingInterface.cpp (1 of 3 files). Show all

Unified · Split

interface/src/scripting/GlobalServicesScriptingInterface.cpp+29−11
@@ -10,8 +10,9 @@ · 9 unmodified lines
1010 //
1111
1212 #include "AccountManager.h"
13−#include "XmppClient.h"
13+#include "Application.h"
1414 #include "ResourceCache.h"
15+#include "XmppClient.h"
1516
1617 #include "GlobalServicesScriptingInterface.h"
1718
@@ -26,6 +27,9 @@ GlobalServicesScriptingInterface::GlobalServicesScriptingInterface() { · 8 unmodified lines
2627 const QXmppClient& qxmppClient = XmppClient::getInstance().getXMPPClient();
2728 connect(&qxmppClient, &QXmppClient::messageReceived, this, &GlobalServicesScriptingInterface::messageReceived);
2829 #endif // HAVE_QXMPP
30+
31+ _downloading = false;
32+ connect(Application::getInstance(), &Application::renderingInWorldInterface, this, &GlobalServicesScriptingInterface::checkDownloadInfo);
2933 }
3034
3135 GlobalServicesScriptingInterface::~GlobalServicesScriptingInterface() {
@@ -115,16 +119,6 @@ void GlobalServicesScriptingInterface::messageReceived(const QXmppMessage& messa · 83 unmodified lines
115119 }
116120 #endif // HAVE_QXMPP
117121
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−
128122
129123 DownloadInfoResult::DownloadInfoResult() :
130124 downloading(QList<float>()),
@@ -154,3 +148,27 @@ void DownloadInfoResultFromScriptValue(const QScriptValue& object, DownloadInfoR · 23 unmodified lines
154148
155149 result.pending = object.property("pending").toVariant().toFloat();
156150 }
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+}