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
1=== modified file 'src/Unity/CMakeLists.txt'
2--- src/Unity/CMakeLists.txt 2014-12-02 12:21:57 +0000
3+++ src/Unity/CMakeLists.txt 2014-12-12 11:29:06 +0000
4@@ -61,7 +61,7 @@
5 ${ONLINE_ACCOUNTS_CLIENT_LDFLAGS}
6 )
7
8-qt5_use_modules(Unity-qml Qml Gui DBus)
9+qt5_use_modules(Unity-qml Qml Gui DBus Concurrent)
10
11 # export the qmldir qmltypes and plugin files
12 export_qmlfiles(Unity Unity)
13
14=== modified file 'src/Unity/scope.cpp'
15--- src/Unity/scope.cpp 2014-12-10 11:19:27 +0000
16+++ src/Unity/scope.cpp 2014-12-12 11:29:06 +0000
17@@ -43,6 +43,7 @@
18 #include <QFileInfo>
19 #include <QDir>
20 #include <QLocale>
21+#include <QtConcurrent>
22
23 #include <libintl.h>
24
25@@ -1247,7 +1248,7 @@
26 // calling it from the shell (hence it will use the default UI policy when talking to libsignon).
27 setenv("UNITY_SCOPES_OA_UI_POLICY", "1", 0);
28
29- bool service_enabled = false;
30+ QFuture<bool> service_enabled_future = QtConcurrent::run([&]
31 {
32 // Check if at least one account has the specified service enabled
33 scopes::OnlineAccountClient oa_client(service_name.toStdString(), service_type.toStdString(), provider_name.toStdString());
34@@ -1256,11 +1257,25 @@
35 {
36 if (status.service_enabled)
37 {
38- service_enabled = true;
39- break;
40+ return true;
41 }
42 }
43- }
44+ return false;
45+ });
46+ QFutureWatcher<bool> future_watcher;
47+ future_watcher.setFuture(service_enabled_future);
48+
49+ // Set SearchInProgress so that the loading bar animates while we waiting for the token to be issued.
50+ setSearchInProgress(true);
51+
52+ QEventLoop loop;
53+ connect(&future_watcher, &QFutureWatcher<void>::finished, &loop, &QEventLoop::quit);
54+ loop.exec(QEventLoop::ProcessEventsFlag::ExcludeUserInputEvents);
55+
56+ // Unset SearchInProgress to stop the loading bar animation.
57+ setSearchInProgress(false);
58+
59+ bool service_enabled = service_enabled_future.result();
60
61 // Start the signon UI if no enabled services were found
62 if (!service_enabled)

Subscribers

People subscribed via source and target branches

to all changes: