Merge lp:~marcustomlinson/unity-scope-click/without-crashing into lp:unity-scope-click

Proposed by Marcus Tomlinson on 2016-04-15
Status: Merged
Approved by: dobey on 2016-04-15
Approved revision: 447
Merged at revision: 441
Proposed branch: lp:~marcustomlinson/unity-scope-click/without-crashing
Merge into: lp:unity-scope-click
Prerequisite: lp:~dobey/unity-scope-click/really-we-want-to-sign-all-the-requests
Diff against target: 113 lines (+16/-0)
4 files modified
scope/clickapps/apps-scope.cpp (+4/-0)
scope/clickapps/apps-scope.h (+4/-0)
scope/clickstore/store-scope.cpp (+4/-0)
scope/clickstore/store-scope.h (+4/-0)
To merge this branch: bzr merge lp:~marcustomlinson/unity-scope-click/without-crashing
Reviewer Review Type Date Requested Status
dobey (community) Approve on 2016-04-15
Paweł Stołowski 2016-04-15 Approve on 2016-04-15
PS Jenkins bot continuous-integration Needs Fixing on 2016-04-15
Review via email: mp+291987@code.launchpad.net

Commit message

Wait for the qt main loop to be ready before allowing execution of search or preview methods

To post a comment you must log in.
Paweł Stołowski (stolowski) wrote :

Yeah, totally makes sense! +1

review: Approve
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scope/clickapps/apps-scope.cpp'
2--- scope/clickapps/apps-scope.cpp 2016-04-15 10:12:40 +0000
3+++ scope/clickapps/apps-scope.cpp 2016-04-15 10:12:40 +0000
4@@ -49,6 +49,7 @@
5
6 click::Scope::Scope()
7 {
8+ qt_ready_f = qt_ready_p.get_future();
9 nam.reset(new click::network::AccessManager());
10 client.reset(new click::web::Client(nam));
11 index.reset(new click::Index(client));
12@@ -84,6 +85,7 @@
13 sso.reset(new click::CredentialsService());
14 client->setCredentialsService(sso);
15 dm.reset(Ubuntu::DownloadManager::Manager::createSessionManager());
16+ qt_ready_p.set_value();
17 };
18
19 qt::core::world::build_and_run(zero, nullptr, emptyCb);
20@@ -96,12 +98,14 @@
21
22 scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata)
23 {
24+ qt_ready_f.wait();
25 return scopes::SearchQueryBase::UPtr(new click::apps::Query(q, depts_db, metadata));
26 }
27
28
29 unity::scopes::PreviewQueryBase::UPtr click::Scope::preview(const unity::scopes::Result& result,
30 const unity::scopes::ActionMetadata& metadata) {
31+ qt_ready_f.wait();
32 qDebug() << "Scope::preview() called.";
33 auto preview = new click::Preview(result, metadata);
34 preview->choose_strategy(client, pay_package, dm, depts_db);
35
36=== modified file 'scope/clickapps/apps-scope.h'
37--- scope/clickapps/apps-scope.h 2016-04-15 10:12:40 +0000
38+++ scope/clickapps/apps-scope.h 2016-04-15 10:12:40 +0000
39@@ -30,6 +30,8 @@
40 #ifndef APPS_SCOPE_H
41 #define APPS_SCOPE_H
42
43+#include <future>
44+
45 #include <click/index.h>
46 #include <click/network_access_manager.h>
47 #include <click/pay.h>
48@@ -66,6 +68,8 @@
49 virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override;
50
51 private:
52+ std::promise<void> qt_ready_p;
53+ std::future<void> qt_ready_f;
54 QSharedPointer<click::network::AccessManager> nam;
55 QSharedPointer<click::web::Client> client;
56 QSharedPointer<click::Index> index;
57
58=== modified file 'scope/clickstore/store-scope.cpp'
59--- scope/clickstore/store-scope.cpp 2016-04-15 10:12:40 +0000
60+++ scope/clickstore/store-scope.cpp 2016-04-15 10:12:40 +0000
61@@ -47,6 +47,7 @@
62
63 click::Scope::Scope()
64 {
65+ qt_ready_f = qt_ready_p.get_future();
66 nam.reset(new click::network::AccessManager());
67 client.reset(new click::web::Client(nam));
68 index.reset(new click::Index(client));
69@@ -86,6 +87,7 @@
70 sso.reset(new click::CredentialsService());
71 client->setCredentialsService(sso);
72 dm.reset(Ubuntu::DownloadManager::Manager::createSessionManager());
73+ qt_ready_p.set_value();
74 };
75
76 qt::core::world::build_and_run(zero, nullptr, emptyCb);
77@@ -98,12 +100,14 @@
78
79 scopes::SearchQueryBase::UPtr click::Scope::search(unity::scopes::CannedQuery const& q, scopes::SearchMetadata const& metadata)
80 {
81+ qt_ready_f.wait();
82 return scopes::SearchQueryBase::UPtr(new click::Query(q, *index, *depts, depts_db, *highlights, metadata, *pay_package));
83 }
84
85
86 unity::scopes::PreviewQueryBase::UPtr click::Scope::preview(const unity::scopes::Result& result,
87 const unity::scopes::ActionMetadata& metadata) {
88+ qt_ready_f.wait();
89 qDebug() << "Scope::preview() called.";
90 auto preview = new click::Preview(result, metadata);
91 preview->choose_strategy(client, pay_package, dm, depts_db);
92
93=== modified file 'scope/clickstore/store-scope.h'
94--- scope/clickstore/store-scope.h 2016-04-15 10:12:40 +0000
95+++ scope/clickstore/store-scope.h 2016-04-15 10:12:40 +0000
96@@ -33,6 +33,8 @@
97 #include <click/pay.h>
98
99 #include <memory>
100+#include <future>
101+
102 #include <click/network_access_manager.h>
103 #include <click/webclient.h>
104
105@@ -69,6 +71,8 @@
106 virtual unity::scopes::ActivationQueryBase::UPtr perform_action(unity::scopes::Result const& result, unity::scopes::ActionMetadata const& metadata, std::string const& widget_id, std::string const& action_id) override;
107
108 private:
109+ std::promise<void> qt_ready_p;
110+ std::future<void> qt_ready_f;
111 QSharedPointer<click::network::AccessManager> nam;
112 QSharedPointer<click::web::Client> client;
113 QSharedPointer<click::Index> index;

Subscribers

People subscribed via source and target branches