Merge lp:~marcustomlinson/unity-scopes-shell/oa_loading_bar into lp:unity-scopes-shell

Proposed by Marcus Tomlinson
Status: Merged
Approved by: Paweł Stołowski
Approved revision: 179
Merged at revision: 180
Proposed branch: lp:~marcustomlinson/unity-scopes-shell/oa_loading_bar
Merge into: lp:unity-scopes-shell
Diff against target: 62 lines (+20/-5)
2 files modified
src/Unity/CMakeLists.txt (+1/-1)
src/Unity/scope.cpp (+19/-4)
To merge this branch: bzr merge lp:~marcustomlinson/unity-scopes-shell/oa_loading_bar
Reviewer Review Type Date Requested Status
Paweł Stołowski (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+244335@code.launchpad.net

Commit message

Animate the loading bar on the scope while OA retrieves a token.

To post a comment you must log in.
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

In the case where either:
   1. A new account is added from settings, the scope service is enabled under that account, then the log-in button is pressed in a scope.
   2. The token for a scope expires (bringing the log-in button back), then the log-in button is pressed in the scope.

The call to OA to refresh the token takes some time to return with no UI indication.

This branch uses setSearchInProgress() in order to animate the scope's loading bar while we wait for the token to be returned.

NOTE: The reason I need to use ExcludeUserInputEvents for the event loop here is because we can't allow the user move to another scope / open a preview while this method is busy. This is because the post log-in action needs to be performed from the state the scope was at the time the log-in button was pressed.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Paweł Stołowski (stolowski) wrote :

+ QFuture<void> future = QtConcurrent::run([&]{ service_statuses = oa_client.get_service_statuses(); });

I think oa_client could be created inside the lambda?

Also, please make the lambda return std::vector<scopes::OnlineAccountClient::ServiceStatus>, then the future will be of QFuture<std::vector<...>> type and you can get the result by future's T result() getter instead of modifying the vector by reference (the lambda needs no outer variables then I think).

review: Needs Fixing
179. By Marcus Tomlinson

Addressed review comment

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

> + QFuture<void> future = QtConcurrent::run([&]{ service_statuses =
> oa_client.get_service_statuses(); });
>
> I think oa_client could be created inside the lambda?
>
> Also, please make the lambda return
> std::vector<scopes::OnlineAccountClient::ServiceStatus>, then the future will
> be of QFuture<std::vector<...>> type and you can get the result by future's T
> result() getter instead of modifying the vector by reference (the lambda needs
> no outer variables then I think).

Done

Revision history for this message
Paweł Stołowski (stolowski) wrote :

36 if (status.service_enabled)
37 {
38 - service_enabled = true;
39 - break;
40 + return true;
41 }

Just "return status.service_enabled" ?

review: Needs Fixing
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

> 36 if (status.service_enabled)
> 37 {
> 38 - service_enabled = true;
> 39 - break;
> 40 + return true;
> 41 }
>
> Just "return status.service_enabled" ?

That if statement is within a loop over all accounts. So default is false, the if one is enabled return true

Revision history for this message
Paweł Stołowski (stolowski) wrote :

> > 36 if (status.service_enabled)
> > 37 {
> > 38 - service_enabled = true;
> > 39 - break;
> > 40 + return true;
> > 41 }
> >
> > Just "return status.service_enabled" ?
>
> That if statement is within a loop over all accounts. So default is false, the
> if one is enabled return true

Ah, ok, that wasn't obvious from the diff. Looks good now, thanks!

Revision history for this message
Paweł Stołowski (stolowski) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Unity/CMakeLists.txt'
--- src/Unity/CMakeLists.txt 2014-12-02 12:21:57 +0000
+++ src/Unity/CMakeLists.txt 2014-12-12 11:29:06 +0000
@@ -61,7 +61,7 @@
61 ${ONLINE_ACCOUNTS_CLIENT_LDFLAGS}61 ${ONLINE_ACCOUNTS_CLIENT_LDFLAGS}
62 )62 )
6363
64qt5_use_modules(Unity-qml Qml Gui DBus)64qt5_use_modules(Unity-qml Qml Gui DBus Concurrent)
6565
66# export the qmldir qmltypes and plugin files66# export the qmldir qmltypes and plugin files
67export_qmlfiles(Unity Unity)67export_qmlfiles(Unity Unity)
6868
=== modified file 'src/Unity/scope.cpp'
--- src/Unity/scope.cpp 2014-12-10 11:19:27 +0000
+++ src/Unity/scope.cpp 2014-12-12 11:29:06 +0000
@@ -43,6 +43,7 @@
43#include <QFileInfo>43#include <QFileInfo>
44#include <QDir>44#include <QDir>
45#include <QLocale>45#include <QLocale>
46#include <QtConcurrent>
4647
47#include <libintl.h>48#include <libintl.h>
4849
@@ -1247,7 +1248,7 @@
1247 // calling it from the shell (hence it will use the default UI policy when talking to libsignon).1248 // calling it from the shell (hence it will use the default UI policy when talking to libsignon).
1248 setenv("UNITY_SCOPES_OA_UI_POLICY", "1", 0);1249 setenv("UNITY_SCOPES_OA_UI_POLICY", "1", 0);
12491250
1250 bool service_enabled = false;1251 QFuture<bool> service_enabled_future = QtConcurrent::run([&]
1251 {1252 {
1252 // Check if at least one account has the specified service enabled1253 // Check if at least one account has the specified service enabled
1253 scopes::OnlineAccountClient oa_client(service_name.toStdString(), service_type.toStdString(), provider_name.toStdString());1254 scopes::OnlineAccountClient oa_client(service_name.toStdString(), service_type.toStdString(), provider_name.toStdString());
@@ -1256,11 +1257,25 @@
1256 {1257 {
1257 if (status.service_enabled)1258 if (status.service_enabled)
1258 {1259 {
1259 service_enabled = true;1260 return true;
1260 break;
1261 }1261 }
1262 }1262 }
1263 }1263 return false;
1264 });
1265 QFutureWatcher<bool> future_watcher;
1266 future_watcher.setFuture(service_enabled_future);
1267
1268 // Set SearchInProgress so that the loading bar animates while we waiting for the token to be issued.
1269 setSearchInProgress(true);
1270
1271 QEventLoop loop;
1272 connect(&future_watcher, &QFutureWatcher<void>::finished, &loop, &QEventLoop::quit);
1273 loop.exec(QEventLoop::ProcessEventsFlag::ExcludeUserInputEvents);
1274
1275 // Unset SearchInProgress to stop the loading bar animation.
1276 setSearchInProgress(false);
1277
1278 bool service_enabled = service_enabled_future.result();
12641279
1265 // Start the signon UI if no enabled services were found1280 // Start the signon UI if no enabled services were found
1266 if (!service_enabled)1281 if (!service_enabled)

Subscribers

People subscribed via source and target branches

to all changes: