Merge lp:~jamesh/unity-scope-scopes/online-recommendations into lp:unity-scope-scopes

Proposed by James Henstridge
Status: Merged
Merged at revision: 23
Proposed branch: lp:~jamesh/unity-scope-scopes/online-recommendations
Merge into: lp:unity-scope-scopes
Diff against target: 220 lines (+141/-0)
6 files modified
src/CMakeLists.txt (+1/-0)
src/resultforwarder.cpp (+65/-0)
src/resultforwarder.h (+57/-0)
src/scopes-scope.cpp (+15/-0)
src/scopes-scope.h (+2/-0)
src/scopes.ini (+1/-0)
To merge this branch: bzr merge lp:~jamesh/unity-scope-scopes/online-recommendations
Reviewer Review Type Date Requested Status
Unity Team Pending
Review via email: mp+208073@code.launchpad.net

Commit message

Integrate results from the onlinescopes scope when the user performs a search.

Description of the change

When the user performs a search, integrate results from the com.canonical.scopes.onlinescopes scope.

This may still need a bit of work to ensure it matches design (either on this side or the remote end).

To post a comment you must log in.
22. By James Henstridge

Add Author metadata.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2014-02-06 04:39:29 +0000
3+++ src/CMakeLists.txt 2014-02-25 08:47:57 +0000
4@@ -3,6 +3,7 @@
5 add_library(scopes
6 MODULE
7 scopes-scope.cpp
8+ resultforwarder.cpp
9 )
10 target_link_libraries(scopes ${UNITY_LDFLAGS})
11
12
13=== added file 'src/resultforwarder.cpp'
14--- src/resultforwarder.cpp 1970-01-01 00:00:00 +0000
15+++ src/resultforwarder.cpp 2014-02-25 08:47:57 +0000
16@@ -0,0 +1,65 @@
17+/*
18+ * Copyright (C) 2014 Canonical Ltd
19+ *
20+ * This program is free software: you can redistribute it and/or modify
21+ * it under the terms of the GNU General Public License version 3 as
22+ * published by the Free Software Foundation.
23+ *
24+ * This program is distributed in the hope that it will be useful,
25+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
26+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27+ * GNU General Public License for more details.
28+ *
29+ * You should have received a copy of the GNU General Public License
30+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
31+ *
32+ * Authored by Jussi Pakkanen <jussi.pakkanen@canonical.com>
33+ *
34+ */
35+
36+#include "resultforwarder.h"
37+#include <unity/scopes/SearchReply.h>
38+
39+using namespace unity::scopes;
40+
41+void ResultForwarder::push(Category::SCPtr category) {
42+ upstream->register_category(category);
43+}
44+
45+void ResultForwarder::push(CategorisedResult result) {
46+ upstream->push(result);
47+ if (!ready_)
48+ {
49+ ready_ = true;
50+ notify_observers();
51+ }
52+}
53+
54+void ResultForwarder::finished(ListenerBase::Reason /*reason*/, std::string const& /*error_message*/) {
55+ if (!ready_)
56+ {
57+ ready_ = true;
58+ notify_observers();
59+ }
60+}
61+
62+void ResultForwarder::notify_observers()
63+{
64+ for (auto o: observers_)
65+ {
66+ o->on_forwarder_ready(this);
67+ }
68+}
69+
70+void ResultForwarder::add_observer(std::shared_ptr<ResultForwarder> result_forwarder)
71+{
72+ if (result_forwarder.get() != this)
73+ {
74+ observers_.push_back(result_forwarder);
75+ }
76+}
77+
78+void ResultForwarder::on_forwarder_ready(ResultForwarder*)
79+{
80+ // base impl does nothing
81+}
82
83=== added file 'src/resultforwarder.h'
84--- src/resultforwarder.h 1970-01-01 00:00:00 +0000
85+++ src/resultforwarder.h 2014-02-25 08:47:57 +0000
86@@ -0,0 +1,57 @@
87+/*
88+ * Copyright (C) 2014 Canonical Ltd
89+ *
90+ * This program is free software: you can redistribute it and/or modify
91+ * it under the terms of the GNU General Public License version 3 as
92+ * published by the Free Software Foundation.
93+ *
94+ * This program is distributed in the hope that it will be useful,
95+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
96+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
97+ * GNU General Public License for more details.
98+ *
99+ * You should have received a copy of the GNU General Public License
100+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
101+ *
102+ * Authored by Jussi Pakkanen <jussi.pakkanen@canonical.com>
103+ *
104+ */
105+
106+#ifndef RESULTFORWARDER_H_
107+#define RESULTFORWARDER_H_
108+
109+#include<unity/scopes/SearchListener.h>
110+#include<unity/scopes/ReplyProxyFwd.h>
111+#include<unity/scopes/ListenerBase.h>
112+#include<unity/scopes/CategorisedResult.h>
113+#include<list>
114+
115+class ResultForwarder : public unity::scopes::SearchListener {
116+
117+public:
118+
119+ ResultForwarder(unity::scopes::SearchReplyProxy const& upstream) :
120+ upstream(upstream),
121+ ready_(false) {
122+ }
123+ virtual ~ResultForwarder() {}
124+
125+ virtual void push(unity::scopes::Category::SCPtr category) override;
126+ virtual void push(unity::scopes::CategorisedResult result) override;
127+ void add_observer(std::shared_ptr<ResultForwarder> result_forwarder);
128+
129+ virtual void finished(unity::scopes::ListenerBase::Reason reason,
130+ std::string const& error_message) override;
131+
132+protected:
133+ virtual void on_forwarder_ready(ResultForwarder*);
134+ unity::scopes::SearchReplyProxy upstream;
135+ void notify_observers();
136+
137+private:
138+ std::list<std::shared_ptr<ResultForwarder>> observers_;
139+ bool ready_;
140+};
141+
142+
143+#endif
144
145=== modified file 'src/scopes-scope.cpp'
146--- src/scopes-scope.cpp 2014-02-20 18:11:52 +0000
147+++ src/scopes-scope.cpp 2014-02-25 08:47:57 +0000
148@@ -17,6 +17,7 @@
149 */
150
151 #include <algorithm>
152+#include <iostream>
153 #include <map>
154
155 #include <unity/scopes/Category.h>
156@@ -27,9 +28,12 @@
157 #include <unity/scopes/ScopeExceptions.h>
158 #include <unity/scopes/VariantBuilder.h>
159 #include "scopes-scope.h"
160+#include "resultforwarder.h"
161
162 using namespace unity::scopes;
163
164+static const char ONLINE_SCOPE_ID[] = "com.canonical.scopes.onlinescopes";
165+
166 static const char MISSING_ICON[] = "/usr/share/icons/unity-icon-theme/places/svg/service-generic.svg";
167 static const char SCOPES_CATEGORY_DEFINITION[] = R"(
168 {
169@@ -47,9 +51,15 @@
170 }
171 }
172 )";
173+// unconfuse emacs: "
174
175 int ScopesScope::start(std::string const&, RegistryProxy const &registry) {
176 this->registry = registry;
177+ try {
178+ online_scope = registry->get_metadata(ONLINE_SCOPE_ID).proxy();
179+ } catch (std::exception &e) {
180+ std::cerr << "Could not instantiate online scopes scope: " << e.what() << std::endl;
181+ }
182 return VERSION;
183 }
184
185@@ -226,6 +236,11 @@
186 }
187 reply->push(result);
188 }
189+
190+ if (scope.online_scope && !query.query_string().empty()) {
191+ auto online_reply = std::make_shared<ResultForwarder>(reply);
192+ create_subquery(scope.online_scope, query.query_string(), online_reply);
193+ }
194 }
195
196 ScopesPreview::ScopesPreview(ScopesScope &scope, Result const &result)
197
198=== modified file 'src/scopes-scope.h'
199--- src/scopes-scope.h 2014-02-11 09:51:16 +0000
200+++ src/scopes-scope.h 2014-02-25 08:47:57 +0000
201@@ -38,6 +38,8 @@
202
203 private:
204 unity::scopes::RegistryProxy registry;
205+
206+ unity::scopes::ScopeProxy online_scope;
207 };
208
209 class ScopesQuery : public unity::scopes::SearchQuery
210
211=== modified file 'src/scopes.ini'
212--- src/scopes.ini 2014-02-13 11:24:49 +0000
213+++ src/scopes.ini 2014-02-25 08:47:57 +0000
214@@ -1,5 +1,6 @@
215 [ScopeConfig]
216 DisplayName = Scopes
217+Author = Canonical Ltd.
218 Description = This is an Ubuntu search plugin that enables information from available search plugins to be searched and displayed in the Dash underneath the Dash plugins header. If you do not wish to search this content source, you can disable this search plugin.
219 SearchHint = Search for scopes
220 HotKey =

Subscribers

People subscribed via source and target branches

to all changes: