Merge lp:~azzar1/unity/lp-1152733 into lp:unity
- lp-1152733
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Brandon Schaefer |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3211 |
Proposed branch: | lp:~azzar1/unity/lp-1152733 |
Merge into: | lp:unity |
Diff against target: |
1365 lines (+570/-348) 17 files modified
UnityCore/FilesystemLenses.h (+4/-4) UnityCore/HomeLens.cpp (+8/-3) UnityCore/HomeLens.h (+5/-4) UnityCore/Lenses.h (+3/-0) dash/ApplicationStarter.h (+40/-0) dash/ApplicationStarterImp.cpp (+72/-0) dash/ApplicationStarterImp.h (+34/-0) dash/CMakeLists.txt (+1/-0) dash/DashController.cpp (+2/-1) dash/DashView.cpp (+21/-66) dash/DashView.h (+6/-3) dash/ResultViewGrid.cpp (+2/-1) dash/StandaloneDash.cpp (+3/-1) tests/CMakeLists.txt (+1/-0) tests/mock-lenses.h (+271/-0) tests/test_dash_view.cpp (+67/-0) tests/test_home_lens.cpp (+30/-265) |
To merge this branch: | bzr merge lp:~azzar1/unity/lp-1152733 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Brandon Schaefer (community) | Approve | ||
Review via email: mp+153020@code.launchpad.net |
Commit message
Export the event timestamp on dash icon click.
Description of the change
== Problem ==
Nautilus windows don't get the the focus when opened via the dash.
== Fix ==
Export the event timestamp on dash icon click. Please keep in mind that the diff is not so small but I just moved code for the most.
== Test ==
Unit test added. Just tests ApplicationStar
PS Jenkins bot (ps-jenkins) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
Unapproved changes made after approval.
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
Brandon Schaefer (brandontschaefer) wrote : | # |
Approved!
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'UnityCore/FilesystemLenses.h' | |||
2 | --- UnityCore/FilesystemLenses.h 2012-03-29 04:40:53 +0000 | |||
3 | +++ UnityCore/FilesystemLenses.h 2013-03-12 22:36:20 +0000 | |||
4 | @@ -82,10 +82,10 @@ | |||
5 | 82 | 82 | ||
6 | 83 | ~FilesystemLenses(); | 83 | ~FilesystemLenses(); |
7 | 84 | 84 | ||
12 | 85 | LensList GetLenses() const; | 85 | LensList GetLenses() const override; |
13 | 86 | Lens::Ptr GetLens(std::string const& lens_id) const; | 86 | Lens::Ptr GetLens(std::string const& lens_id) const override; |
14 | 87 | Lens::Ptr GetLensAtIndex(std::size_t index) const; | 87 | Lens::Ptr GetLensAtIndex(std::size_t index) const override; |
15 | 88 | Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const; | 88 | Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const override; |
16 | 89 | 89 | ||
17 | 90 | sigc::signal<void> lenses_loaded; | 90 | sigc::signal<void> lenses_loaded; |
18 | 91 | 91 | ||
19 | 92 | 92 | ||
20 | === modified file 'UnityCore/HomeLens.cpp' | |||
21 | --- UnityCore/HomeLens.cpp 2012-11-14 08:57:56 +0000 | |||
22 | +++ UnityCore/HomeLens.cpp 2013-03-12 22:36:20 +0000 | |||
23 | @@ -1116,14 +1116,14 @@ | |||
24 | 1116 | delete pimpl; | 1116 | delete pimpl; |
25 | 1117 | } | 1117 | } |
26 | 1118 | 1118 | ||
28 | 1119 | void HomeLens::AddLenses(Lenses& lenses) | 1119 | void HomeLens::AddLenses(Lenses::Ptr const& lenses) |
29 | 1120 | { | 1120 | { |
31 | 1121 | for (auto lens : lenses.GetLenses()) | 1121 | for (auto lens : lenses->GetLenses()) |
32 | 1122 | { | 1122 | { |
33 | 1123 | pimpl->OnLensAdded(lens); | 1123 | pimpl->OnLensAdded(lens); |
34 | 1124 | } | 1124 | } |
35 | 1125 | 1125 | ||
37 | 1126 | lenses.lens_added.connect(sigc::mem_fun(pimpl, &HomeLens::Impl::OnLensAdded)); | 1126 | lenses->lens_added.connect(sigc::mem_fun(pimpl, &HomeLens::Impl::OnLensAdded)); |
38 | 1127 | } | 1127 | } |
39 | 1128 | 1128 | ||
40 | 1129 | Lenses::LensList HomeLens::GetLenses() const | 1129 | Lenses::LensList HomeLens::GetLenses() const |
41 | @@ -1158,6 +1158,11 @@ | |||
42 | 1158 | return Lens::Ptr(); | 1158 | return Lens::Ptr(); |
43 | 1159 | } | 1159 | } |
44 | 1160 | 1160 | ||
45 | 1161 | Lens::Ptr HomeLens::GetLensForShortcut(std::string const& lens_shortcut) const | ||
46 | 1162 | { | ||
47 | 1163 | return Lens::Ptr(); | ||
48 | 1164 | } | ||
49 | 1165 | |||
50 | 1161 | void HomeLens::GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb) | 1166 | void HomeLens::GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb) |
51 | 1162 | { | 1167 | { |
52 | 1163 | LOG_WARN(logger) << "Global search not enabled for HomeLens class." | 1168 | LOG_WARN(logger) << "Global search not enabled for HomeLens class." |
53 | 1164 | 1169 | ||
54 | === modified file 'UnityCore/HomeLens.h' | |||
55 | --- UnityCore/HomeLens.h 2012-11-12 11:07:23 +0000 | |||
56 | +++ UnityCore/HomeLens.h 2013-03-12 22:36:20 +0000 | |||
57 | @@ -63,11 +63,12 @@ | |||
58 | 63 | MergeMode merge_mode = MergeMode::OWNER_LENS); | 63 | MergeMode merge_mode = MergeMode::OWNER_LENS); |
59 | 64 | virtual ~HomeLens(); | 64 | virtual ~HomeLens(); |
60 | 65 | 65 | ||
62 | 66 | void AddLenses(Lenses& lenses); | 66 | void AddLenses(Lenses::Ptr const& lenses); |
63 | 67 | 67 | ||
67 | 68 | Lenses::LensList GetLenses() const; | 68 | Lenses::LensList GetLenses() const override; |
68 | 69 | Lens::Ptr GetLens(std::string const& lens_id) const; | 69 | Lens::Ptr GetLens(std::string const& lens_id) const override; |
69 | 70 | Lens::Ptr GetLensAtIndex(std::size_t index) const; | 70 | Lens::Ptr GetLensAtIndex(std::size_t index) const override; |
70 | 71 | Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const override; | ||
71 | 71 | 72 | ||
72 | 72 | void GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb); | 73 | void GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb); |
73 | 73 | void Search(std::string const& search_string, SearchFinishedCallback const& cb); | 74 | void Search(std::string const& search_string, SearchFinishedCallback const& cb); |
74 | 74 | 75 | ||
75 | === modified file 'UnityCore/Lenses.h' | |||
76 | --- UnityCore/Lenses.h 2011-07-27 17:35:31 +0000 | |||
77 | +++ UnityCore/Lenses.h 2013-03-12 22:36:20 +0000 | |||
78 | @@ -20,6 +20,7 @@ | |||
79 | 20 | #ifndef UNITY_LENSES_H | 20 | #ifndef UNITY_LENSES_H |
80 | 21 | #define UNITY_LENSES_H | 21 | #define UNITY_LENSES_H |
81 | 22 | 22 | ||
82 | 23 | #include <memory> | ||
83 | 23 | #include <sigc++/trackable.h> | 24 | #include <sigc++/trackable.h> |
84 | 24 | #include <sigc++/signal.h> | 25 | #include <sigc++/signal.h> |
85 | 25 | 26 | ||
86 | @@ -33,6 +34,7 @@ | |||
87 | 33 | class Lenses : public sigc::trackable, boost::noncopyable | 34 | class Lenses : public sigc::trackable, boost::noncopyable |
88 | 34 | { | 35 | { |
89 | 35 | public: | 36 | public: |
90 | 37 | typedef std::shared_ptr<Lenses> Ptr; | ||
91 | 36 | typedef std::vector<Lens::Ptr> LensList; | 38 | typedef std::vector<Lens::Ptr> LensList; |
92 | 37 | 39 | ||
93 | 38 | /** | 40 | /** |
94 | @@ -45,6 +47,7 @@ | |||
95 | 45 | virtual LensList GetLenses() const = 0; | 47 | virtual LensList GetLenses() const = 0; |
96 | 46 | virtual Lens::Ptr GetLens(std::string const& lens_id) const = 0; | 48 | virtual Lens::Ptr GetLens(std::string const& lens_id) const = 0; |
97 | 47 | virtual Lens::Ptr GetLensAtIndex(std::size_t index) const = 0; | 49 | virtual Lens::Ptr GetLensAtIndex(std::size_t index) const = 0; |
98 | 50 | virtual Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const = 0; | ||
99 | 48 | 51 | ||
100 | 49 | nux::ROProperty<std::size_t> count; | 52 | nux::ROProperty<std::size_t> count; |
101 | 50 | 53 | ||
102 | 51 | 54 | ||
103 | === added file 'dash/ApplicationStarter.h' | |||
104 | --- dash/ApplicationStarter.h 1970-01-01 00:00:00 +0000 | |||
105 | +++ dash/ApplicationStarter.h 2013-03-12 22:36:20 +0000 | |||
106 | @@ -0,0 +1,40 @@ | |||
107 | 1 | /* | ||
108 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
109 | 3 | * | ||
110 | 4 | * This program is free software: you can redistribute it and/or modify | ||
111 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
112 | 6 | * published by the Free Software Foundation. | ||
113 | 7 | * | ||
114 | 8 | * This program is distributed in the hope that it will be useful, | ||
115 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
116 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
117 | 11 | * GNU General Public License for more details. | ||
118 | 12 | * | ||
119 | 13 | * You should have received a copy of the GNU General Public License | ||
120 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
121 | 15 | * | ||
122 | 16 | * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> | ||
123 | 17 | */ | ||
124 | 18 | |||
125 | 19 | #ifndef UNITY_SHARED_APPLICATION_STARTER_H | ||
126 | 20 | #define UNITY_SHARED_APPLICATION_STARTER_H | ||
127 | 21 | |||
128 | 22 | #include <boost/noncopyable.hpp> | ||
129 | 23 | #include <memory> | ||
130 | 24 | #include <string> | ||
131 | 25 | |||
132 | 26 | #include <X11/X.h> | ||
133 | 27 | |||
134 | 28 | namespace unity { | ||
135 | 29 | |||
136 | 30 | class ApplicationStarter : boost::noncopyable | ||
137 | 31 | { | ||
138 | 32 | public: | ||
139 | 33 | typedef std::shared_ptr<ApplicationStarter> Ptr; | ||
140 | 34 | |||
141 | 35 | virtual bool Launch(std::string const& application_name, Time timestamp) = 0; | ||
142 | 36 | }; | ||
143 | 37 | |||
144 | 38 | } | ||
145 | 39 | |||
146 | 40 | #endif | ||
147 | 0 | 41 | ||
148 | === added file 'dash/ApplicationStarterImp.cpp' | |||
149 | --- dash/ApplicationStarterImp.cpp 1970-01-01 00:00:00 +0000 | |||
150 | +++ dash/ApplicationStarterImp.cpp 2013-03-12 22:36:20 +0000 | |||
151 | @@ -0,0 +1,72 @@ | |||
152 | 1 | /* | ||
153 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
154 | 3 | * | ||
155 | 4 | * This program is free software: you can redistribute it and/or modify | ||
156 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
157 | 6 | * published by the Free Software Foundation. | ||
158 | 7 | * | ||
159 | 8 | * This program is distributed in the hope that it will be useful, | ||
160 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
161 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
162 | 11 | * GNU General Public License for more details. | ||
163 | 12 | * | ||
164 | 13 | * You should have received a copy of the GNU General Public License | ||
165 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
166 | 15 | * | ||
167 | 16 | * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> | ||
168 | 17 | */ | ||
169 | 18 | |||
170 | 19 | #include "ApplicationStarterImp.h" | ||
171 | 20 | |||
172 | 21 | #include <gdk/gdk.h> | ||
173 | 22 | #include <gio/gdesktopappinfo.h> | ||
174 | 23 | |||
175 | 24 | #include <NuxCore/Logger.h> | ||
176 | 25 | #include <UnityCore/GLibWrapper.h> | ||
177 | 26 | |||
178 | 27 | namespace unity { | ||
179 | 28 | |||
180 | 29 | DECLARE_LOGGER(logger, "unity.applicationstarterimp"); | ||
181 | 30 | |||
182 | 31 | bool ApplicationStarterImp::Launch(std::string const& application_name, Time timestamp) | ||
183 | 32 | { | ||
184 | 33 | std::string id = application_name; | ||
185 | 34 | |||
186 | 35 | LOG_DEBUG(logger) << "Launching " << id; | ||
187 | 36 | |||
188 | 37 | GdkDisplay* display = gdk_display_get_default(); | ||
189 | 38 | glib::Object<GdkAppLaunchContext> app_launch_context(gdk_display_get_app_launch_context(display)); | ||
190 | 39 | |||
191 | 40 | if (timestamp >= 0) | ||
192 | 41 | gdk_app_launch_context_set_timestamp(app_launch_context, timestamp); | ||
193 | 42 | |||
194 | 43 | while (true) | ||
195 | 44 | { | ||
196 | 45 | glib::Object<GDesktopAppInfo> info(g_desktop_app_info_new(id.c_str())); | ||
197 | 46 | |||
198 | 47 | if (info) | ||
199 | 48 | { | ||
200 | 49 | glib::Error error; | ||
201 | 50 | g_app_info_launch(glib::object_cast<GAppInfo>(info), nullptr, | ||
202 | 51 | glib::object_cast<GAppLaunchContext>(app_launch_context), &error); | ||
203 | 52 | |||
204 | 53 | if (error) | ||
205 | 54 | LOG_WARNING(logger) << "Unable to launch " << id << ":" << error; | ||
206 | 55 | else | ||
207 | 56 | return true; | ||
208 | 57 | |||
209 | 58 | break; | ||
210 | 59 | } | ||
211 | 60 | |||
212 | 61 | // Try to replace the next - with a / and do the lookup again. | ||
213 | 62 | auto pos = id.find_first_of('-'); | ||
214 | 63 | if (pos != std::string::npos) | ||
215 | 64 | id.replace(pos, 1, "/"); | ||
216 | 65 | else | ||
217 | 66 | break; | ||
218 | 67 | } | ||
219 | 68 | |||
220 | 69 | return false; | ||
221 | 70 | } | ||
222 | 71 | |||
223 | 72 | } | ||
224 | 0 | 73 | ||
225 | === added file 'dash/ApplicationStarterImp.h' | |||
226 | --- dash/ApplicationStarterImp.h 1970-01-01 00:00:00 +0000 | |||
227 | +++ dash/ApplicationStarterImp.h 2013-03-12 22:36:20 +0000 | |||
228 | @@ -0,0 +1,34 @@ | |||
229 | 1 | /* | ||
230 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
231 | 3 | * | ||
232 | 4 | * This program is free software: you can redistribute it and/or modify | ||
233 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
234 | 6 | * published by the Free Software Foundation. | ||
235 | 7 | * | ||
236 | 8 | * This program is distributed in the hope that it will be useful, | ||
237 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
238 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
239 | 11 | * GNU General Public License for more details. | ||
240 | 12 | * | ||
241 | 13 | * You should have received a copy of the GNU General Public License | ||
242 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
243 | 15 | * | ||
244 | 16 | * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> | ||
245 | 17 | */ | ||
246 | 18 | |||
247 | 19 | #ifndef UNITY_SHARED_APPLICATION_STARTER_IMP_H | ||
248 | 20 | #define UNITY_SHARED_APPLICATION_STARTER_IMP_H | ||
249 | 21 | |||
250 | 22 | #include "ApplicationStarter.h" | ||
251 | 23 | |||
252 | 24 | namespace unity { | ||
253 | 25 | |||
254 | 26 | class ApplicationStarterImp : public ApplicationStarter | ||
255 | 27 | { | ||
256 | 28 | public: | ||
257 | 29 | bool Launch(std::string const& application_name, Time timestamp) override; | ||
258 | 30 | }; | ||
259 | 31 | |||
260 | 32 | } | ||
261 | 33 | |||
262 | 34 | #endif | ||
263 | 0 | 35 | ||
264 | === modified file 'dash/CMakeLists.txt' | |||
265 | --- dash/CMakeLists.txt 2013-01-28 23:57:38 +0000 | |||
266 | +++ dash/CMakeLists.txt 2013-03-12 22:36:20 +0000 | |||
267 | @@ -19,6 +19,7 @@ | |||
268 | 19 | # Headers & Sources | 19 | # Headers & Sources |
269 | 20 | # | 20 | # |
270 | 21 | set (DASH_SOURCES | 21 | set (DASH_SOURCES |
271 | 22 | ApplicationStarterImp.cpp | ||
272 | 22 | CoverflowResultView.cpp | 23 | CoverflowResultView.cpp |
273 | 23 | DashController.cpp | 24 | DashController.cpp |
274 | 24 | DashView.cpp | 25 | DashView.cpp |
275 | 25 | 26 | ||
276 | === modified file 'dash/DashController.cpp' | |||
277 | --- dash/DashController.cpp 2013-03-06 13:13:37 +0000 | |||
278 | +++ dash/DashController.cpp 2013-03-12 22:36:20 +0000 | |||
279 | @@ -23,6 +23,7 @@ | |||
280 | 23 | #include <Nux/HLayout.h> | 23 | #include <Nux/HLayout.h> |
281 | 24 | #include <UnityCore/GLibWrapper.h> | 24 | #include <UnityCore/GLibWrapper.h> |
282 | 25 | 25 | ||
283 | 26 | #include "ApplicationStarterImp.h" | ||
284 | 26 | #include "unity-shared/DashStyle.h" | 27 | #include "unity-shared/DashStyle.h" |
285 | 27 | #include "unity-shared/PanelStyle.h" | 28 | #include "unity-shared/PanelStyle.h" |
286 | 28 | #include "unity-shared/UBusMessages.h" | 29 | #include "unity-shared/UBusMessages.h" |
287 | @@ -139,7 +140,7 @@ | |||
288 | 139 | 140 | ||
289 | 140 | void Controller::SetupDashView() | 141 | void Controller::SetupDashView() |
290 | 141 | { | 142 | { |
292 | 142 | view_ = new DashView(); | 143 | view_ = new DashView(std::make_shared<FilesystemLenses>(), std::make_shared<ApplicationStarterImp>()); |
293 | 143 | AddChild(view_); | 144 | AddChild(view_); |
294 | 144 | 145 | ||
295 | 145 | nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION); | 146 | nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION); |
296 | 146 | 147 | ||
297 | === modified file 'dash/DashView.cpp' | |||
298 | --- dash/DashView.cpp 2013-02-26 12:57:59 +0000 | |||
299 | +++ dash/DashView.cpp 2013-03-12 22:36:20 +0000 | |||
300 | @@ -24,7 +24,6 @@ | |||
301 | 24 | 24 | ||
302 | 25 | #include <math.h> | 25 | #include <math.h> |
303 | 26 | 26 | ||
304 | 27 | #include <gio/gdesktopappinfo.h> | ||
305 | 28 | #include <glib/gi18n-lib.h> | 27 | #include <glib/gi18n-lib.h> |
306 | 29 | #include <gtk/gtk.h> | 28 | #include <gtk/gtk.h> |
307 | 30 | 29 | ||
308 | @@ -110,13 +109,16 @@ | |||
309 | 110 | 109 | ||
310 | 111 | NUX_IMPLEMENT_OBJECT_TYPE(DashView); | 110 | NUX_IMPLEMENT_OBJECT_TYPE(DashView); |
311 | 112 | 111 | ||
313 | 113 | DashView::DashView() | 112 | DashView::DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter) |
314 | 114 | : nux::View(NUX_TRACKER_LOCATION) | 113 | : nux::View(NUX_TRACKER_LOCATION) |
315 | 114 | , lenses_(lenses) | ||
316 | 115 | , home_lens_(new HomeLens(_("Home"), _("Home screen"), _("Search your computer and online sources"))) | 115 | , home_lens_(new HomeLens(_("Home"), _("Home screen"), _("Search your computer and online sources"))) |
317 | 116 | , application_starter_(application_starter) | ||
318 | 116 | , preview_container_(nullptr) | 117 | , preview_container_(nullptr) |
319 | 117 | , preview_displaying_(false) | 118 | , preview_displaying_(false) |
320 | 118 | , preview_navigation_mode_(previews::Navigation::NONE) | 119 | , preview_navigation_mode_(previews::Navigation::NONE) |
321 | 119 | , last_activated_uri_("") | 120 | , last_activated_uri_("") |
322 | 121 | , last_activated_timestamp_(0) | ||
323 | 120 | , search_in_progress_(false) | 122 | , search_in_progress_(false) |
324 | 121 | , activate_on_finish_(false) | 123 | , activate_on_finish_(false) |
325 | 122 | , visible_(false) | 124 | , visible_(false) |
326 | @@ -137,11 +139,14 @@ | |||
327 | 137 | SetupViews(); | 139 | SetupViews(); |
328 | 138 | SetupUBusConnections(); | 140 | SetupUBusConnections(); |
329 | 139 | 141 | ||
331 | 140 | lenses_.lens_added.connect(sigc::mem_fun(this, &DashView::OnLensAdded)); | 142 | lenses_->lens_added.connect(sigc::mem_fun(this, &DashView::OnLensAdded)); |
332 | 141 | mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown)); | 143 | mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown)); |
333 | 142 | preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview)); | 144 | preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview)); |
334 | 143 | Relayout(); | 145 | Relayout(); |
335 | 144 | 146 | ||
336 | 147 | for (auto lens : lenses_->GetLenses()) | ||
337 | 148 | lenses_->lens_added.emit(lens); | ||
338 | 149 | |||
339 | 145 | home_lens_->AddLenses(lenses_); | 150 | home_lens_->AddLenses(lenses_); |
340 | 146 | lens_bar_->Activate("home.lens"); | 151 | lens_bar_->Activate("home.lens"); |
341 | 147 | 152 | ||
342 | @@ -195,7 +200,8 @@ | |||
343 | 195 | int row_height = 0; | 200 | int row_height = 0; |
344 | 196 | int results_to_the_left = 0; | 201 | int results_to_the_left = 0; |
345 | 197 | int results_to_the_right = 0; | 202 | int results_to_the_right = 0; |
347 | 198 | g_variant_get(data, "(iiiiii)", &column_x, &row_y, &column_width, &row_height, &results_to_the_left, &results_to_the_right); | 203 | g_variant_get(data, "(iiiiiii)", &last_activated_timestamp_, &column_x, &row_y, &column_width, &row_height, &results_to_the_left, &results_to_the_right); |
348 | 204 | |||
349 | 199 | preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, row_y); | 205 | preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, row_y); |
350 | 200 | preview_state_machine_.left_results = results_to_the_left; | 206 | preview_state_machine_.left_results = results_to_the_left; |
351 | 201 | preview_state_machine_.right_results = results_to_the_right; | 207 | preview_state_machine_.right_results = results_to_the_right; |
352 | @@ -470,7 +476,7 @@ | |||
353 | 470 | 476 | ||
354 | 471 | if (active_lens_view_->lens()->id() == "home.lens") | 477 | if (active_lens_view_->lens()->id() == "home.lens") |
355 | 472 | { | 478 | { |
357 | 473 | for (auto lens : lenses_.GetLenses()) | 479 | for (auto lens : lenses_->GetLenses()) |
358 | 474 | { | 480 | { |
359 | 475 | lens->view_type = ViewType::HOME_VIEW; | 481 | lens->view_type = ViewType::HOME_VIEW; |
360 | 476 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HOME_VIEW | 482 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HOME_VIEW |
361 | @@ -508,7 +514,7 @@ | |||
362 | 508 | visible_ = false; | 514 | visible_ = false; |
363 | 509 | renderer_.AboutToHide(); | 515 | renderer_.AboutToHide(); |
364 | 510 | 516 | ||
366 | 511 | for (auto lens : lenses_.GetLenses()) | 517 | for (auto lens : lenses_->GetLenses()) |
367 | 512 | { | 518 | { |
368 | 513 | lens->view_type = ViewType::HIDDEN; | 519 | lens->view_type = ViewType::HIDDEN; |
369 | 514 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN | 520 | LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN |
370 | @@ -1152,9 +1158,9 @@ | |||
371 | 1152 | 1158 | ||
372 | 1153 | void DashView::UpdateLensFilter(std::string lens_id, std::string filter_name, std::string value) | 1159 | void DashView::UpdateLensFilter(std::string lens_id, std::string filter_name, std::string value) |
373 | 1154 | { | 1160 | { |
375 | 1155 | if (lenses_.GetLens(lens_id)) | 1161 | if (lenses_->GetLens(lens_id)) |
376 | 1156 | { | 1162 | { |
378 | 1157 | Lens::Ptr lens = lenses_.GetLens(lens_id); | 1163 | Lens::Ptr lens = lenses_->GetLens(lens_id); |
379 | 1158 | 1164 | ||
380 | 1159 | Filters::Ptr filters = lens->filters; | 1165 | Filters::Ptr filters = lens->filters; |
381 | 1160 | 1166 | ||
382 | @@ -1219,7 +1225,6 @@ | |||
383 | 1219 | 1225 | ||
384 | 1220 | void DashView::OnLensAdded(Lens::Ptr& lens) | 1226 | void DashView::OnLensAdded(Lens::Ptr& lens) |
385 | 1221 | { | 1227 | { |
386 | 1222 | std::string id = lens->id; | ||
387 | 1223 | lens_bar_->AddLens(lens); | 1228 | lens_bar_->AddLens(lens); |
388 | 1224 | 1229 | ||
389 | 1225 | nux::ObjectPtr<LensView> view(new LensView(lens, search_bar_->show_filters())); | 1230 | nux::ObjectPtr<LensView> view(new LensView(lens, search_bar_->show_filters())); |
390 | @@ -1366,70 +1371,20 @@ | |||
391 | 1366 | 1371 | ||
392 | 1367 | if (g_str_has_prefix(uri.c_str(), "application://")) | 1372 | if (g_str_has_prefix(uri.c_str(), "application://")) |
393 | 1368 | { | 1373 | { |
396 | 1369 | std::string appname = uri.substr(14); | 1374 | std::string const& appname = uri.substr(14); |
397 | 1370 | return LaunchApp(appname); | 1375 | return application_starter_->Launch(appname, last_activated_timestamp_); |
398 | 1371 | } | 1376 | } |
399 | 1372 | else if (g_str_has_prefix(uri.c_str(), "unity-runner://")) | 1377 | else if (g_str_has_prefix(uri.c_str(), "unity-runner://")) |
400 | 1373 | { | 1378 | { |
403 | 1374 | std::string appname = uri.substr(15); | 1379 | std::string const& appname = uri.substr(15); |
404 | 1375 | return LaunchApp(appname); | 1380 | return application_starter_->Launch(appname, last_activated_timestamp_); |
405 | 1376 | } | 1381 | } |
406 | 1377 | else | 1382 | else |
408 | 1378 | return gtk_show_uri(NULL, uri.c_str(), CurrentTime, NULL); | 1383 | return gtk_show_uri(NULL, uri.c_str(), last_activated_timestamp_, NULL); |
409 | 1379 | 1384 | ||
410 | 1380 | return false; | 1385 | return false; |
411 | 1381 | } | 1386 | } |
412 | 1382 | 1387 | ||
413 | 1383 | bool DashView::LaunchApp(std::string const& appname) | ||
414 | 1384 | { | ||
415 | 1385 | GDesktopAppInfo* info; | ||
416 | 1386 | bool ret = false; | ||
417 | 1387 | char *id = g_strdup(appname.c_str()); | ||
418 | 1388 | int i = 0; | ||
419 | 1389 | |||
420 | 1390 | LOG_DEBUG(logger) << "Launching " << appname; | ||
421 | 1391 | |||
422 | 1392 | while (id != NULL) | ||
423 | 1393 | { | ||
424 | 1394 | info = g_desktop_app_info_new(id); | ||
425 | 1395 | if (info != NULL) | ||
426 | 1396 | { | ||
427 | 1397 | GError* error = NULL; | ||
428 | 1398 | |||
429 | 1399 | g_app_info_launch(G_APP_INFO(info), NULL, NULL, &error); | ||
430 | 1400 | if (error) | ||
431 | 1401 | { | ||
432 | 1402 | g_warning("Unable to launch %s: %s", id, error->message); | ||
433 | 1403 | g_error_free(error); | ||
434 | 1404 | } | ||
435 | 1405 | else | ||
436 | 1406 | ret = true; | ||
437 | 1407 | g_object_unref(info); | ||
438 | 1408 | break; | ||
439 | 1409 | } | ||
440 | 1410 | |||
441 | 1411 | /* Try to replace the next - with a / and do the lookup again. | ||
442 | 1412 | * If we set id=NULL we'll exit the outer loop */ | ||
443 | 1413 | for (i = 0; ; i++) | ||
444 | 1414 | { | ||
445 | 1415 | if (id[i] == '-') | ||
446 | 1416 | { | ||
447 | 1417 | id[i] = '/'; | ||
448 | 1418 | break; | ||
449 | 1419 | } | ||
450 | 1420 | else if (id[i] == '\0') | ||
451 | 1421 | { | ||
452 | 1422 | g_free(id); | ||
453 | 1423 | id = NULL; | ||
454 | 1424 | break; | ||
455 | 1425 | } | ||
456 | 1426 | } | ||
457 | 1427 | } | ||
458 | 1428 | |||
459 | 1429 | g_free(id); | ||
460 | 1430 | return ret; | ||
461 | 1431 | } | ||
462 | 1432 | |||
463 | 1433 | void DashView::DisableBlur() | 1388 | void DashView::DisableBlur() |
464 | 1434 | { | 1389 | { |
465 | 1435 | renderer_.DisableBlur(); | 1390 | renderer_.DisableBlur(); |
466 | @@ -1452,7 +1407,7 @@ | |||
467 | 1452 | 1407 | ||
468 | 1453 | std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const | 1408 | std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const |
469 | 1454 | { | 1409 | { |
471 | 1455 | Lens::Ptr lens = lenses_.GetLensForShortcut(shortcut); | 1410 | Lens::Ptr lens = lenses_->GetLensForShortcut(shortcut); |
472 | 1456 | if (lens) | 1411 | if (lens) |
473 | 1457 | return lens->id; | 1412 | return lens->id; |
474 | 1458 | return ""; | 1413 | return ""; |
475 | @@ -1462,7 +1417,7 @@ | |||
476 | 1462 | { | 1417 | { |
477 | 1463 | std::vector<char> result; | 1418 | std::vector<char> result; |
478 | 1464 | 1419 | ||
480 | 1465 | for (Lens::Ptr lens: lenses_.GetLenses()) | 1420 | for (Lens::Ptr lens: lenses_->GetLenses()) |
481 | 1466 | { | 1421 | { |
482 | 1467 | std::string shortcut = lens->shortcut; | 1422 | std::string shortcut = lens->shortcut; |
483 | 1468 | if(shortcut.size() > 0) | 1423 | if(shortcut.size() > 0) |
484 | 1469 | 1424 | ||
485 | === modified file 'dash/DashView.h' | |||
486 | --- dash/DashView.h 2013-01-28 23:57:38 +0000 | |||
487 | +++ dash/DashView.h 2013-03-12 22:36:20 +0000 | |||
488 | @@ -28,6 +28,7 @@ | |||
489 | 28 | #include <UnityCore/HomeLens.h> | 28 | #include <UnityCore/HomeLens.h> |
490 | 29 | #include <UnityCore/GLibSource.h> | 29 | #include <UnityCore/GLibSource.h> |
491 | 30 | 30 | ||
492 | 31 | #include "ApplicationStarter.h" | ||
493 | 31 | #include "LensBar.h" | 32 | #include "LensBar.h" |
494 | 32 | #include "LensView.h" | 33 | #include "LensView.h" |
495 | 33 | #include "previews/PreviewContainer.h" | 34 | #include "previews/PreviewContainer.h" |
496 | @@ -58,7 +59,7 @@ | |||
497 | 58 | typedef std::map<std::string, nux::ObjectPtr<LensView>> LensViews; | 59 | typedef std::map<std::string, nux::ObjectPtr<LensView>> LensViews; |
498 | 59 | 60 | ||
499 | 60 | public: | 61 | public: |
501 | 61 | DashView(); | 62 | DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter); |
502 | 62 | ~DashView(); | 63 | ~DashView(); |
503 | 63 | 64 | ||
504 | 64 | void AboutToShow(); | 65 | void AboutToShow(); |
505 | @@ -131,10 +132,12 @@ | |||
506 | 131 | nux::Area* KeyNavIteration(nux::KeyNavDirection direction); | 132 | nux::Area* KeyNavIteration(nux::KeyNavDirection direction); |
507 | 132 | 133 | ||
508 | 133 | UBusManager ubus_manager_; | 134 | UBusManager ubus_manager_; |
510 | 134 | FilesystemLenses lenses_; | 135 | Lenses::Ptr lenses_; |
511 | 135 | HomeLens::Ptr home_lens_; | 136 | HomeLens::Ptr home_lens_; |
512 | 136 | LensViews lens_views_; | 137 | LensViews lens_views_; |
513 | 137 | 138 | ||
514 | 139 | ApplicationStarter::Ptr application_starter_; | ||
515 | 140 | |||
516 | 138 | // View related | 141 | // View related |
517 | 139 | PreviewStateMachine preview_state_machine_; | 142 | PreviewStateMachine preview_state_machine_; |
518 | 140 | previews::PreviewContainer::Ptr preview_container_; | 143 | previews::PreviewContainer::Ptr preview_container_; |
519 | @@ -159,7 +162,7 @@ | |||
520 | 159 | OverlayRenderer renderer_; | 162 | OverlayRenderer renderer_; |
521 | 160 | 163 | ||
522 | 161 | std::string last_activated_uri_; | 164 | std::string last_activated_uri_; |
524 | 162 | // we're passing this back to g_* functions, so we'll keep the g* type | 165 | Time last_activated_timestamp_; |
525 | 163 | bool search_in_progress_; | 166 | bool search_in_progress_; |
526 | 164 | bool activate_on_finish_; | 167 | bool activate_on_finish_; |
527 | 165 | 168 | ||
528 | 166 | 169 | ||
529 | === modified file 'dash/ResultViewGrid.cpp' | |||
530 | --- dash/ResultViewGrid.cpp 2013-01-09 13:33:36 +0000 | |||
531 | +++ dash/ResultViewGrid.cpp 2013-03-12 22:36:20 +0000 | |||
532 | @@ -208,7 +208,8 @@ | |||
533 | 208 | } | 208 | } |
534 | 209 | 209 | ||
535 | 210 | active_index_ = index; | 210 | active_index_ = index; |
537 | 211 | glib::Variant data(g_variant_new("(iiiiii)", column_x, row_y, column_width, row_height, left_results, right_results)); | 211 | auto timestamp = nux::GetWindowThread()->GetGraphicsDisplay().GetCurrentEvent().x11_timestamp; |
538 | 212 | glib::Variant data(g_variant_new("(iiiiiii)", timestamp, column_x, row_y, column_width, row_height, left_results, right_results)); | ||
539 | 212 | UriActivated.emit(uri, type, data); | 213 | UriActivated.emit(uri, type, data); |
540 | 213 | } | 214 | } |
541 | 214 | 215 | ||
542 | 215 | 216 | ||
543 | === modified file 'dash/StandaloneDash.cpp' | |||
544 | --- dash/StandaloneDash.cpp 2012-11-29 10:19:01 +0000 | |||
545 | +++ dash/StandaloneDash.cpp 2013-03-12 22:36:20 +0000 | |||
546 | @@ -28,6 +28,7 @@ | |||
547 | 28 | #include <NuxCore/AnimationController.h> | 28 | #include <NuxCore/AnimationController.h> |
548 | 29 | #include <NuxCore/Logger.h> | 29 | #include <NuxCore/Logger.h> |
549 | 30 | 30 | ||
550 | 31 | #include "ApplicationStarterImp.h" | ||
551 | 31 | #include "unity-shared/BGHash.h" | 32 | #include "unity-shared/BGHash.h" |
552 | 32 | #include "unity-shared/FontSettings.h" | 33 | #include "unity-shared/FontSettings.h" |
553 | 33 | #include "DashView.h" | 34 | #include "DashView.h" |
554 | @@ -64,7 +65,8 @@ | |||
555 | 64 | { | 65 | { |
556 | 65 | layout = new nux::HLayout(NUX_TRACKER_LOCATION); | 66 | layout = new nux::HLayout(NUX_TRACKER_LOCATION); |
557 | 66 | 67 | ||
559 | 67 | DashView* view = new DashView(); | 68 | DashView* view = new DashView(std::make_shared<unity::dash::FilesystemLenses>(), |
560 | 69 | std::make_shared<unity::ApplicationStarterImp>()); | ||
561 | 68 | view->DisableBlur(); | 70 | view->DisableBlur(); |
562 | 69 | view->SetMinMaxSize(WIDTH, HEIGHT); | 71 | view->SetMinMaxSize(WIDTH, HEIGHT); |
563 | 70 | layout->AddView (view, 1, nux::MINOR_POSITION_CENTER); | 72 | layout->AddView (view, 1, nux::MINOR_POSITION_CENTER); |
564 | 71 | 73 | ||
565 | === modified file 'tests/CMakeLists.txt' | |||
566 | --- tests/CMakeLists.txt 2013-03-08 12:46:41 +0000 | |||
567 | +++ tests/CMakeLists.txt 2013-03-12 22:36:20 +0000 | |||
568 | @@ -202,6 +202,7 @@ | |||
569 | 202 | test_application_launcher_icon.cpp | 202 | test_application_launcher_icon.cpp |
570 | 203 | test_bamf_application.cpp | 203 | test_bamf_application.cpp |
571 | 204 | test_bfb_launcher_icon.cpp | 204 | test_bfb_launcher_icon.cpp |
572 | 205 | test_dash_view.cpp | ||
573 | 205 | test_dashview_impl.cpp | 206 | test_dashview_impl.cpp |
574 | 206 | test_dash_controller.cpp | 207 | test_dash_controller.cpp |
575 | 207 | test_desktop_launcher_icon.cpp | 208 | test_desktop_launcher_icon.cpp |
576 | 208 | 209 | ||
577 | === added file 'tests/mock-lenses.h' | |||
578 | --- tests/mock-lenses.h 1970-01-01 00:00:00 +0000 | |||
579 | +++ tests/mock-lenses.h 2013-03-12 22:36:20 +0000 | |||
580 | @@ -0,0 +1,271 @@ | |||
581 | 1 | // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- | ||
582 | 2 | /* | ||
583 | 3 | * Copyright (C) 2013 Canonical Ltd | ||
584 | 4 | * | ||
585 | 5 | * This program is free software: you can redistribute it and/or modify | ||
586 | 6 | * it under the terms of the GNU General Public License version 3 as | ||
587 | 7 | * published by the Free Software Foundation. | ||
588 | 8 | * | ||
589 | 9 | * This program is distributed in the hope that it will be useful, | ||
590 | 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
591 | 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
592 | 12 | * GNU General Public License for more details. | ||
593 | 13 | * | ||
594 | 14 | * You should have received a copy of the GNU General Public License | ||
595 | 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
596 | 16 | * | ||
597 | 17 | */ | ||
598 | 18 | |||
599 | 19 | #ifndef UNITY_TESTS_MOCK_LENSES_H | ||
600 | 20 | #define UNITY_TESTS_MOCK_LENSES_H | ||
601 | 21 | |||
602 | 22 | #include <dee.h> | ||
603 | 23 | |||
604 | 24 | #include <UnityCore/GLibWrapper.h> | ||
605 | 25 | #include <UnityCore/GLibSource.h> | ||
606 | 26 | #include <UnityCore/Lens.h> | ||
607 | 27 | #include <UnityCore/Lenses.h> | ||
608 | 28 | |||
609 | 29 | namespace testmocks { | ||
610 | 30 | |||
611 | 31 | /* | ||
612 | 32 | * FORWARDS | ||
613 | 33 | */ | ||
614 | 34 | |||
615 | 35 | class MockTestLens; | ||
616 | 36 | |||
617 | 37 | /* | ||
618 | 38 | * Mock Lens instance that does not use DBus. The default search does like this: | ||
619 | 39 | * For input "bar" output: | ||
620 | 40 | * | ||
621 | 41 | * i = 0 | ||
622 | 42 | * for letter in "bar": | ||
623 | 43 | * put result row [ "uri+$letter+$lens_id", "icon+$letter+$lens_id", i % 3, "mime+$letter+$lens_id", ...] | ||
624 | 44 | * i++ | ||
625 | 45 | * | ||
626 | 46 | * The mock lens has 3 categories: | ||
627 | 47 | * | ||
628 | 48 | * 0) "cat0+$lens_id" | ||
629 | 49 | * 1) "cat1+$lens_id" | ||
630 | 50 | * 2) "Shared cat" | ||
631 | 51 | */ | ||
632 | 52 | class MockTestLens : public unity::dash::Lens | ||
633 | 53 | { | ||
634 | 54 | public: | ||
635 | 55 | typedef std::shared_ptr<MockTestLens> Ptr; | ||
636 | 56 | |||
637 | 57 | MockTestLens(std::string const& id, std::string const& name, std::string const& description, std::string const& search_hint) | ||
638 | 58 | : Lens(id, "", "", name, "lens-icon.png", | ||
639 | 59 | description, search_hint, true, "", | ||
640 | 60 | unity::dash::ModelType::LOCAL) | ||
641 | 61 | , num_results_(-1) | ||
642 | 62 | , provides_personal_results_(true) | ||
643 | 63 | { | ||
644 | 64 | search_in_global(true); | ||
645 | 65 | connected.SetGetterFunction(sigc::mem_fun(this, &MockTestLens::force_connected)); | ||
646 | 66 | provides_personal_content.SetGetterFunction(sigc::mem_fun(this, &MockTestLens::get_provides_personal_results)); | ||
647 | 67 | |||
648 | 68 | DeeModel* cats = categories()->model(); | ||
649 | 69 | DeeModel* results = global_results()->model(); | ||
650 | 70 | DeeModel* flters = filters()->model(); | ||
651 | 71 | |||
652 | 72 | // Set model schemas | ||
653 | 73 | dee_model_set_schema(cats, "s", "s", "s", "a{sv}", NULL); | ||
654 | 74 | dee_model_set_schema(results, "s", "s", "u", "s", "s", "s", "s", NULL); | ||
655 | 75 | dee_model_set_schema(flters, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL); | ||
656 | 76 | |||
657 | 77 | // Populate categories model | ||
658 | 78 | std::ostringstream cat0, cat1; | ||
659 | 79 | cat0 << "cat0+" << id; | ||
660 | 80 | cat1 << "cat1+" << id; | ||
661 | 81 | GVariantBuilder b; | ||
662 | 82 | g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT); | ||
663 | 83 | GVariant *asv = g_variant_builder_end(&b); | ||
664 | 84 | |||
665 | 85 | dee_model_append(cats, cat0.str().c_str(), "icon.png", "tile-vertical", asv); | ||
666 | 86 | dee_model_append(cats, cat1.str().c_str(), "icon.png", "tile-vertical", asv); | ||
667 | 87 | dee_model_append(cats, "Shared cat", "icon.png", "tile-vertical", asv); | ||
668 | 88 | } | ||
669 | 89 | |||
670 | 90 | virtual ~MockTestLens() {} | ||
671 | 91 | |||
672 | 92 | bool force_connected() | ||
673 | 93 | { | ||
674 | 94 | return true; | ||
675 | 95 | } | ||
676 | 96 | |||
677 | 97 | bool get_provides_personal_results() | ||
678 | 98 | { | ||
679 | 99 | return provides_personal_results_; | ||
680 | 100 | } | ||
681 | 101 | |||
682 | 102 | virtual void DoGlobalSearch(std::string const& search_string) | ||
683 | 103 | { | ||
684 | 104 | DeeModel* model = global_results()->model(); | ||
685 | 105 | GVariant** row_buf = g_new(GVariant*, 8); | ||
686 | 106 | |||
687 | 107 | row_buf[1] = g_variant_new_string(""); | ||
688 | 108 | row_buf[3] = g_variant_new_string(""); | ||
689 | 109 | row_buf[5] = g_variant_new_string(""); | ||
690 | 110 | row_buf[6] = g_variant_new_string(""); | ||
691 | 111 | row_buf[7] = NULL; | ||
692 | 112 | |||
693 | 113 | unsigned int i; | ||
694 | 114 | unsigned int results_count = search_string.size(); | ||
695 | 115 | if (num_results_ >= 0) results_count = static_cast<unsigned>(num_results_); | ||
696 | 116 | for (i = 0; i < results_count; i++) | ||
697 | 117 | { | ||
698 | 118 | std::ostringstream uri; | ||
699 | 119 | char res_id(i >= search_string.size() ? '-' : search_string.at(i)); | ||
700 | 120 | uri << "uri+" << res_id << "+" << id(); | ||
701 | 121 | row_buf[0] = g_variant_new_string(uri.str().c_str()); | ||
702 | 122 | row_buf[2] = g_variant_new_uint32(i % 3); | ||
703 | 123 | unity::glib::String name(g_strdup_printf("%s - %d", | ||
704 | 124 | results_base_name_.empty() ? | ||
705 | 125 | search_string.c_str() : results_base_name_.c_str(), | ||
706 | 126 | i)); | ||
707 | 127 | row_buf[4] = g_variant_new_string(name); | ||
708 | 128 | |||
709 | 129 | dee_model_append_row(model, row_buf); | ||
710 | 130 | } | ||
711 | 131 | |||
712 | 132 | g_free(row_buf); | ||
713 | 133 | } | ||
714 | 134 | |||
715 | 135 | void GlobalSearch(std::string const& search_string, | ||
716 | 136 | SearchFinishedCallback const& cb) | ||
717 | 137 | { | ||
718 | 138 | /* Dispatch search async, because that's what it'd normally do */ | ||
719 | 139 | source_manager_.Add(new unity::glib::Idle([this, search_string, cb] () | ||
720 | 140 | { | ||
721 | 141 | DoGlobalSearch(search_string); | ||
722 | 142 | cb(Lens::Hints(), unity::glib::Error()); | ||
723 | 143 | return false; | ||
724 | 144 | })); | ||
725 | 145 | } | ||
726 | 146 | |||
727 | 147 | void Search(std::string const& search_string, SearchFinishedCallback const& cb) | ||
728 | 148 | { | ||
729 | 149 | /* Dispatch search async, because that's what it'd normally do */ | ||
730 | 150 | source_manager_.Add(new unity::glib::Idle([search_string, cb] () | ||
731 | 151 | { | ||
732 | 152 | cb(Lens::Hints(), unity::glib::Error()); | ||
733 | 153 | return false; | ||
734 | 154 | })); | ||
735 | 155 | } | ||
736 | 156 | |||
737 | 157 | void Activate(std::string const& uri) | ||
738 | 158 | { | ||
739 | 159 | |||
740 | 160 | } | ||
741 | 161 | |||
742 | 162 | void Preview(std::string const& uri) | ||
743 | 163 | { | ||
744 | 164 | |||
745 | 165 | } | ||
746 | 166 | |||
747 | 167 | void SetResultsBaseName(std::string const& name) | ||
748 | 168 | { | ||
749 | 169 | results_base_name_ = name; | ||
750 | 170 | } | ||
751 | 171 | |||
752 | 172 | void SetNumResults(int count) | ||
753 | 173 | { | ||
754 | 174 | num_results_ = count; | ||
755 | 175 | } | ||
756 | 176 | |||
757 | 177 | void SetProvidesPersonalResults(bool value) | ||
758 | 178 | { | ||
759 | 179 | provides_personal_results_ = value; | ||
760 | 180 | } | ||
761 | 181 | |||
762 | 182 | private: | ||
763 | 183 | std::string results_base_name_; | ||
764 | 184 | int num_results_; | ||
765 | 185 | bool provides_personal_results_; | ||
766 | 186 | unity::glib::SourceManager source_manager_; | ||
767 | 187 | }; | ||
768 | 188 | |||
769 | 189 | /* | ||
770 | 190 | * Mock Lenses class | ||
771 | 191 | */ | ||
772 | 192 | class MockTestLenses : public unity::dash::Lenses | ||
773 | 193 | { | ||
774 | 194 | public: | ||
775 | 195 | typedef std::shared_ptr<MockTestLenses> Ptr; | ||
776 | 196 | |||
777 | 197 | MockTestLenses() | ||
778 | 198 | { | ||
779 | 199 | count.SetGetterFunction(sigc::mem_fun(&list_, &unity::dash::Lenses::LensList::size)); | ||
780 | 200 | } | ||
781 | 201 | |||
782 | 202 | virtual ~MockTestLenses() {} | ||
783 | 203 | |||
784 | 204 | unity::dash::Lenses::LensList GetLenses() const | ||
785 | 205 | { | ||
786 | 206 | return list_; | ||
787 | 207 | } | ||
788 | 208 | |||
789 | 209 | unity::dash::Lens::Ptr GetLens(std::string const& lens_id) const | ||
790 | 210 | { | ||
791 | 211 | for (auto lens : list_) | ||
792 | 212 | { | ||
793 | 213 | if (lens->id() == lens_id) | ||
794 | 214 | return lens; | ||
795 | 215 | } | ||
796 | 216 | return unity::dash::Lens::Ptr(); | ||
797 | 217 | } | ||
798 | 218 | |||
799 | 219 | unity::dash::Lens::Ptr GetLensAtIndex(std::size_t index) const | ||
800 | 220 | { | ||
801 | 221 | return list_.at(index); | ||
802 | 222 | } | ||
803 | 223 | |||
804 | 224 | unity::dash::Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const override | ||
805 | 225 | { | ||
806 | 226 | return unity::dash::Lens::Ptr(); | ||
807 | 227 | } | ||
808 | 228 | |||
809 | 229 | |||
810 | 230 | protected: | ||
811 | 231 | unity::dash::Lenses::LensList list_; | ||
812 | 232 | }; | ||
813 | 233 | |||
814 | 234 | class TwoMockTestLenses : public MockTestLenses | ||
815 | 235 | { | ||
816 | 236 | public: | ||
817 | 237 | TwoMockTestLenses() | ||
818 | 238 | : lens_1_(new MockTestLens("first.lens", "First Lens", "The very first lens", "First search hint")) | ||
819 | 239 | , lens_2_(new MockTestLens("second.lens", "Second Lens", "The second lens", "Second search hint")) | ||
820 | 240 | { | ||
821 | 241 | list_.push_back(lens_1_); | ||
822 | 242 | list_.push_back(lens_2_); | ||
823 | 243 | } | ||
824 | 244 | |||
825 | 245 | private: | ||
826 | 246 | unity::dash::Lens::Ptr lens_1_; | ||
827 | 247 | unity::dash::Lens::Ptr lens_2_; | ||
828 | 248 | }; | ||
829 | 249 | |||
830 | 250 | class ThreeMockTestLenses : public MockTestLenses | ||
831 | 251 | { | ||
832 | 252 | public: | ||
833 | 253 | ThreeMockTestLenses() | ||
834 | 254 | : lens_1_(new MockTestLens("first.lens", "First Lens", "The very first lens", "First search hint")) | ||
835 | 255 | , lens_2_(new MockTestLens("second.lens", "Second Lens", "The second lens", "Second search hint")) | ||
836 | 256 | , lens_3_(new MockTestLens("applications.lens", "Applications", "The applications lens", "Search applications")) | ||
837 | 257 | { | ||
838 | 258 | list_.push_back(lens_1_); | ||
839 | 259 | list_.push_back(lens_2_); | ||
840 | 260 | list_.push_back(lens_3_); | ||
841 | 261 | } | ||
842 | 262 | |||
843 | 263 | private: | ||
844 | 264 | unity::dash::Lens::Ptr lens_1_; | ||
845 | 265 | unity::dash::Lens::Ptr lens_2_; | ||
846 | 266 | unity::dash::Lens::Ptr lens_3_; | ||
847 | 267 | }; | ||
848 | 268 | |||
849 | 269 | } | ||
850 | 270 | |||
851 | 271 | #endif | ||
852 | 0 | 272 | ||
853 | === added file 'tests/test_dash_view.cpp' | |||
854 | --- tests/test_dash_view.cpp 1970-01-01 00:00:00 +0000 | |||
855 | +++ tests/test_dash_view.cpp 2013-03-12 22:36:20 +0000 | |||
856 | @@ -0,0 +1,67 @@ | |||
857 | 1 | /* | ||
858 | 2 | * Copyright (C) 2013 Canonical Ltd | ||
859 | 3 | * | ||
860 | 4 | * This program is free software: you can redistribute it and/or modify | ||
861 | 5 | * it under the terms of the GNU General Public License version 3 as | ||
862 | 6 | * published by the Free Software Foundation. | ||
863 | 7 | * | ||
864 | 8 | * This program is distributed in the hope that it will be useful, | ||
865 | 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
866 | 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
867 | 11 | * GNU General Public License for more details. | ||
868 | 12 | * | ||
869 | 13 | * You should have received a copy of the GNU General Public License | ||
870 | 14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
871 | 15 | * | ||
872 | 16 | * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> | ||
873 | 17 | */ | ||
874 | 18 | |||
875 | 19 | #include <gmock/gmock.h> | ||
876 | 20 | |||
877 | 21 | #include <UnityCore/Lenses.h> | ||
878 | 22 | |||
879 | 23 | #include "ApplicationStarter.h" | ||
880 | 24 | #include "DashView.h" | ||
881 | 25 | #include "unity-shared/DashStyle.h" | ||
882 | 26 | #include "unity-shared/PanelStyle.h" | ||
883 | 27 | #include "unity-shared/UnitySettings.h" | ||
884 | 28 | |||
885 | 29 | #include "mock-lenses.h" | ||
886 | 30 | |||
887 | 31 | using namespace unity::dash; | ||
888 | 32 | using namespace testing; | ||
889 | 33 | |||
890 | 34 | namespace { | ||
891 | 35 | |||
892 | 36 | struct MockApplicationStarter : public unity::ApplicationStarter { | ||
893 | 37 | typedef std::shared_ptr<MockApplicationStarter> Ptr; | ||
894 | 38 | MOCK_METHOD2(Launch, bool(std::string const&, Time)); | ||
895 | 39 | }; | ||
896 | 40 | |||
897 | 41 | |||
898 | 42 | struct TestDashView : public testing::Test { | ||
899 | 43 | TestDashView() | ||
900 | 44 | : lenses_(std::make_shared<testmocks::ThreeMockTestLenses>()) | ||
901 | 45 | , application_starter_(std::make_shared<MockApplicationStarter>()) | ||
902 | 46 | , dash_view_(new DashView(lenses_, application_starter_)) | ||
903 | 47 | {} | ||
904 | 48 | |||
905 | 49 | unity::Settings unity_settings_; | ||
906 | 50 | Style dash_style; | ||
907 | 51 | unity::panel::Style panel_style; | ||
908 | 52 | Lenses::Ptr lenses_; | ||
909 | 53 | MockApplicationStarter::Ptr application_starter_; | ||
910 | 54 | nux::ObjectPtr<DashView> dash_view_; | ||
911 | 55 | }; | ||
912 | 56 | |||
913 | 57 | |||
914 | 58 | TEST_F(TestDashView, LensActivatedSignal) | ||
915 | 59 | { | ||
916 | 60 | EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1); | ||
917 | 61 | lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:application://uri", NOT_HANDLED, Lens::Hints()); | ||
918 | 62 | |||
919 | 63 | EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1); | ||
920 | 64 | lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:unity-runner://uri", NOT_HANDLED, Lens::Hints()); | ||
921 | 65 | } | ||
922 | 66 | |||
923 | 67 | } | ||
924 | 0 | 68 | ||
925 | === modified file 'tests/test_home_lens.cpp' | |||
926 | --- tests/test_home_lens.cpp 2012-11-14 08:57:56 +0000 | |||
927 | +++ tests/test_home_lens.cpp 2013-03-12 22:36:20 +0000 | |||
928 | @@ -1,7 +1,5 @@ | |||
929 | 1 | #include <gtest/gtest.h> | 1 | #include <gtest/gtest.h> |
930 | 2 | #include <glib-object.h> | 2 | #include <glib-object.h> |
931 | 3 | #include <dee.h> | ||
932 | 4 | #include <string> | ||
933 | 5 | #include <iostream> | 3 | #include <iostream> |
934 | 6 | #include <stdexcept> | 4 | #include <stdexcept> |
935 | 7 | #include <map> | 5 | #include <map> |
936 | @@ -9,254 +7,21 @@ | |||
937 | 9 | #include <sigc++/signal.h> | 7 | #include <sigc++/signal.h> |
938 | 10 | #include <sigc++/trackable.h> | 8 | #include <sigc++/trackable.h> |
939 | 11 | 9 | ||
942 | 12 | #include <UnityCore/GLibWrapper.h> | 10 | |
941 | 13 | #include <UnityCore/GLibSource.h> | ||
943 | 14 | #include <UnityCore/Variant.h> | 11 | #include <UnityCore/Variant.h> |
944 | 15 | #include <UnityCore/HomeLens.h> | 12 | #include <UnityCore/HomeLens.h> |
945 | 16 | #include <UnityCore/Lens.h> | ||
946 | 17 | #include <UnityCore/Lenses.h> | ||
947 | 18 | 13 | ||
948 | 19 | #include "test_utils.h" | 14 | #include "test_utils.h" |
949 | 15 | #include "mock-lenses.h" | ||
950 | 20 | 16 | ||
951 | 21 | using namespace std; | 17 | using namespace std; |
952 | 22 | using namespace unity; | 18 | using namespace unity; |
953 | 23 | using namespace unity::dash; | 19 | using namespace unity::dash; |
954 | 20 | using namespace testmocks; | ||
955 | 24 | 21 | ||
956 | 25 | namespace | 22 | namespace |
957 | 26 | { | 23 | { |
958 | 27 | 24 | ||
959 | 28 | /* | ||
960 | 29 | * FORWARDS | ||
961 | 30 | */ | ||
962 | 31 | |||
963 | 32 | class StaticTestLens; | ||
964 | 33 | |||
965 | 34 | /* | ||
966 | 35 | * Mock Lens instance that does not use DBus. The default search does like this: | ||
967 | 36 | * For input "bar" output: | ||
968 | 37 | * | ||
969 | 38 | * i = 0 | ||
970 | 39 | * for letter in "bar": | ||
971 | 40 | * put result row [ "uri+$letter+$lens_id", "icon+$letter+$lens_id", i % 3, "mime+$letter+$lens_id", ...] | ||
972 | 41 | * i++ | ||
973 | 42 | * | ||
974 | 43 | * The mock lens has 3 categories: | ||
975 | 44 | * | ||
976 | 45 | * 0) "cat0+$lens_id" | ||
977 | 46 | * 1) "cat1+$lens_id" | ||
978 | 47 | * 2) "Shared cat" | ||
979 | 48 | */ | ||
980 | 49 | class StaticTestLens : public Lens | ||
981 | 50 | { | ||
982 | 51 | public: | ||
983 | 52 | typedef std::shared_ptr<StaticTestLens> Ptr; | ||
984 | 53 | |||
985 | 54 | StaticTestLens(string const& id, string const& name, string const& description, string const& search_hint) | ||
986 | 55 | : Lens(id, "", "", name, "lens-icon.png", | ||
987 | 56 | description, search_hint, true, "", | ||
988 | 57 | ModelType::LOCAL) | ||
989 | 58 | , num_results_(-1) | ||
990 | 59 | , provides_personal_results_(true) | ||
991 | 60 | { | ||
992 | 61 | search_in_global(true); | ||
993 | 62 | connected.SetGetterFunction(sigc::mem_fun(this, &StaticTestLens::force_connected)); | ||
994 | 63 | provides_personal_content.SetGetterFunction(sigc::mem_fun(this, &StaticTestLens::get_provides_personal_results)); | ||
995 | 64 | |||
996 | 65 | DeeModel* cats = categories()->model(); | ||
997 | 66 | DeeModel* results = global_results()->model(); | ||
998 | 67 | DeeModel* flters = filters()->model(); | ||
999 | 68 | |||
1000 | 69 | // Set model schemas | ||
1001 | 70 | dee_model_set_schema(cats, "s", "s", "s", "a{sv}", NULL); | ||
1002 | 71 | dee_model_set_schema(results, "s", "s", "u", "s", "s", "s", "s", NULL); | ||
1003 | 72 | dee_model_set_schema(flters, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL); | ||
1004 | 73 | |||
1005 | 74 | // Populate categories model | ||
1006 | 75 | ostringstream cat0, cat1; | ||
1007 | 76 | cat0 << "cat0+" << id; | ||
1008 | 77 | cat1 << "cat1+" << id; | ||
1009 | 78 | GVariantBuilder b; | ||
1010 | 79 | g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT); | ||
1011 | 80 | GVariant *asv = g_variant_builder_end(&b); | ||
1012 | 81 | |||
1013 | 82 | dee_model_append(cats, cat0.str().c_str(), "icon.png", "tile-vertical", asv); | ||
1014 | 83 | dee_model_append(cats, cat1.str().c_str(), "icon.png", "tile-vertical", asv); | ||
1015 | 84 | dee_model_append(cats, "Shared cat", "icon.png", "tile-vertical", asv); | ||
1016 | 85 | } | ||
1017 | 86 | |||
1018 | 87 | virtual ~StaticTestLens() {} | ||
1019 | 88 | |||
1020 | 89 | bool force_connected() | ||
1021 | 90 | { | ||
1022 | 91 | return true; | ||
1023 | 92 | } | ||
1024 | 93 | |||
1025 | 94 | bool get_provides_personal_results() | ||
1026 | 95 | { | ||
1027 | 96 | return provides_personal_results_; | ||
1028 | 97 | } | ||
1029 | 98 | |||
1030 | 99 | virtual void DoGlobalSearch(string const& search_string) | ||
1031 | 100 | { | ||
1032 | 101 | DeeModel* model = global_results()->model(); | ||
1033 | 102 | GVariant** row_buf = g_new(GVariant*, 8); | ||
1034 | 103 | |||
1035 | 104 | row_buf[1] = g_variant_new_string(""); | ||
1036 | 105 | row_buf[3] = g_variant_new_string(""); | ||
1037 | 106 | row_buf[5] = g_variant_new_string(""); | ||
1038 | 107 | row_buf[6] = g_variant_new_string(""); | ||
1039 | 108 | row_buf[7] = NULL; | ||
1040 | 109 | |||
1041 | 110 | unsigned int i; | ||
1042 | 111 | unsigned int results_count = search_string.size(); | ||
1043 | 112 | if (num_results_ >= 0) results_count = static_cast<unsigned>(num_results_); | ||
1044 | 113 | for (i = 0; i < results_count; i++) | ||
1045 | 114 | { | ||
1046 | 115 | ostringstream uri; | ||
1047 | 116 | char res_id(i >= search_string.size() ? '-' : search_string.at(i)); | ||
1048 | 117 | uri << "uri+" << res_id << "+" << id(); | ||
1049 | 118 | row_buf[0] = g_variant_new_string(uri.str().c_str()); | ||
1050 | 119 | row_buf[2] = g_variant_new_uint32(i % 3); | ||
1051 | 120 | glib::String name(g_strdup_printf("%s - %d", | ||
1052 | 121 | results_base_name_.empty() ? | ||
1053 | 122 | search_string.c_str() : results_base_name_.c_str(), | ||
1054 | 123 | i)); | ||
1055 | 124 | row_buf[4] = g_variant_new_string(name); | ||
1056 | 125 | |||
1057 | 126 | dee_model_append_row(model, row_buf); | ||
1058 | 127 | } | ||
1059 | 128 | |||
1060 | 129 | g_free(row_buf); | ||
1061 | 130 | } | ||
1062 | 131 | |||
1063 | 132 | void GlobalSearch(string const& search_string, | ||
1064 | 133 | SearchFinishedCallback const& cb) | ||
1065 | 134 | { | ||
1066 | 135 | /* Dispatch search async, because that's what it'd normally do */ | ||
1067 | 136 | source_manager_.Add(new glib::Idle([this, search_string, cb] () | ||
1068 | 137 | { | ||
1069 | 138 | DoGlobalSearch(search_string); | ||
1070 | 139 | cb(Lens::Hints(), glib::Error()); | ||
1071 | 140 | return false; | ||
1072 | 141 | })); | ||
1073 | 142 | } | ||
1074 | 143 | |||
1075 | 144 | void Search(string const& search_string, SearchFinishedCallback const& cb) | ||
1076 | 145 | { | ||
1077 | 146 | /* Dispatch search async, because that's what it'd normally do */ | ||
1078 | 147 | source_manager_.Add(new glib::Idle([search_string, cb] () | ||
1079 | 148 | { | ||
1080 | 149 | cb(Lens::Hints(), glib::Error()); | ||
1081 | 150 | return false; | ||
1082 | 151 | })); | ||
1083 | 152 | } | ||
1084 | 153 | |||
1085 | 154 | void Activate(string const& uri) | ||
1086 | 155 | { | ||
1087 | 156 | |||
1088 | 157 | } | ||
1089 | 158 | |||
1090 | 159 | void Preview(string const& uri) | ||
1091 | 160 | { | ||
1092 | 161 | |||
1093 | 162 | } | ||
1094 | 163 | |||
1095 | 164 | void SetResultsBaseName(string const& name) | ||
1096 | 165 | { | ||
1097 | 166 | results_base_name_ = name; | ||
1098 | 167 | } | ||
1099 | 168 | |||
1100 | 169 | void SetNumResults(int count) | ||
1101 | 170 | { | ||
1102 | 171 | num_results_ = count; | ||
1103 | 172 | } | ||
1104 | 173 | |||
1105 | 174 | void SetProvidesPersonalResults(bool value) | ||
1106 | 175 | { | ||
1107 | 176 | provides_personal_results_ = value; | ||
1108 | 177 | } | ||
1109 | 178 | |||
1110 | 179 | private: | ||
1111 | 180 | string results_base_name_; | ||
1112 | 181 | int num_results_; | ||
1113 | 182 | bool provides_personal_results_; | ||
1114 | 183 | glib::SourceManager source_manager_; | ||
1115 | 184 | }; | ||
1116 | 185 | |||
1117 | 186 | /* | ||
1118 | 187 | * Mock Lenses class | ||
1119 | 188 | */ | ||
1120 | 189 | class StaticTestLenses : public Lenses | ||
1121 | 190 | { | ||
1122 | 191 | public: | ||
1123 | 192 | typedef std::shared_ptr<StaticTestLenses> Ptr; | ||
1124 | 193 | |||
1125 | 194 | StaticTestLenses() | ||
1126 | 195 | { | ||
1127 | 196 | count.SetGetterFunction(sigc::mem_fun(&list_, &Lenses::LensList::size)); | ||
1128 | 197 | } | ||
1129 | 198 | |||
1130 | 199 | virtual ~StaticTestLenses() {} | ||
1131 | 200 | |||
1132 | 201 | Lenses::LensList GetLenses() const | ||
1133 | 202 | { | ||
1134 | 203 | return list_; | ||
1135 | 204 | } | ||
1136 | 205 | |||
1137 | 206 | Lens::Ptr GetLens(std::string const& lens_id) const | ||
1138 | 207 | { | ||
1139 | 208 | for (auto lens : list_) | ||
1140 | 209 | { | ||
1141 | 210 | if (lens->id() == lens_id) | ||
1142 | 211 | return lens; | ||
1143 | 212 | } | ||
1144 | 213 | return Lens::Ptr(); | ||
1145 | 214 | } | ||
1146 | 215 | |||
1147 | 216 | Lens::Ptr GetLensAtIndex(std::size_t index) const | ||
1148 | 217 | { | ||
1149 | 218 | return list_.at(index); | ||
1150 | 219 | } | ||
1151 | 220 | |||
1152 | 221 | protected: | ||
1153 | 222 | Lenses::LensList list_; | ||
1154 | 223 | }; | ||
1155 | 224 | |||
1156 | 225 | class TwoStaticTestLenses : public StaticTestLenses | ||
1157 | 226 | { | ||
1158 | 227 | public: | ||
1159 | 228 | TwoStaticTestLenses() | ||
1160 | 229 | : lens_1_(new StaticTestLens("first.lens", "First Lens", "The very first lens", "First search hint")) | ||
1161 | 230 | , lens_2_(new StaticTestLens("second.lens", "Second Lens", "The second lens", "Second search hint")) | ||
1162 | 231 | { | ||
1163 | 232 | list_.push_back(lens_1_); | ||
1164 | 233 | list_.push_back(lens_2_); | ||
1165 | 234 | } | ||
1166 | 235 | |||
1167 | 236 | private: | ||
1168 | 237 | Lens::Ptr lens_1_; | ||
1169 | 238 | Lens::Ptr lens_2_; | ||
1170 | 239 | }; | ||
1171 | 240 | |||
1172 | 241 | class ThreeStaticTestLenses : public StaticTestLenses | ||
1173 | 242 | { | ||
1174 | 243 | public: | ||
1175 | 244 | ThreeStaticTestLenses() | ||
1176 | 245 | : lens_1_(new StaticTestLens("first.lens", "First Lens", "The very first lens", "First search hint")) | ||
1177 | 246 | , lens_2_(new StaticTestLens("second.lens", "Second Lens", "The second lens", "Second search hint")) | ||
1178 | 247 | , lens_3_(new StaticTestLens("applications.lens", "Applications", "The applications lens", "Search applications")) | ||
1179 | 248 | { | ||
1180 | 249 | list_.push_back(lens_1_); | ||
1181 | 250 | list_.push_back(lens_2_); | ||
1182 | 251 | list_.push_back(lens_3_); | ||
1183 | 252 | } | ||
1184 | 253 | |||
1185 | 254 | private: | ||
1186 | 255 | Lens::Ptr lens_1_; | ||
1187 | 256 | Lens::Ptr lens_2_; | ||
1188 | 257 | Lens::Ptr lens_3_; | ||
1189 | 258 | }; | ||
1190 | 259 | |||
1191 | 260 | TEST(TestHomeLens, TestConstruction) | 25 | TEST(TestHomeLens, TestConstruction) |
1192 | 261 | { | 26 | { |
1193 | 262 | HomeLens home_lens_("name", "description", "searchhint"); | 27 | HomeLens home_lens_("name", "description", "searchhint"); |
1194 | @@ -286,7 +51,7 @@ | |||
1195 | 286 | TEST(TestHomeLens, TestTwoStaticLenses) | 51 | TEST(TestHomeLens, TestTwoStaticLenses) |
1196 | 287 | { | 52 | { |
1197 | 288 | HomeLens home_lens_("name", "description", "searchhint"); | 53 | HomeLens home_lens_("name", "description", "searchhint"); |
1199 | 289 | TwoStaticTestLenses lenses_; | 54 | std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>(); |
1200 | 290 | 55 | ||
1201 | 291 | home_lens_.AddLenses(lenses_); | 56 | home_lens_.AddLenses(lenses_); |
1202 | 292 | 57 | ||
1203 | @@ -312,7 +77,7 @@ | |||
1204 | 312 | { | 77 | { |
1205 | 313 | HomeLens home_lens_("name", "description", "searchhint", | 78 | HomeLens home_lens_("name", "description", "searchhint", |
1206 | 314 | HomeLens::MergeMode::DISPLAY_NAME); | 79 | HomeLens::MergeMode::DISPLAY_NAME); |
1208 | 315 | TwoStaticTestLenses lenses_; | 80 | std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>(); |
1209 | 316 | DeeModel* cats = home_lens_.categories()->model(); | 81 | DeeModel* cats = home_lens_.categories()->model(); |
1210 | 317 | DeeModelIter* iter; | 82 | DeeModelIter* iter; |
1211 | 318 | unsigned int cat0_first = 0, | 83 | unsigned int cat0_first = 0, |
1212 | @@ -347,7 +112,7 @@ | |||
1213 | 347 | { | 112 | { |
1214 | 348 | HomeLens home_lens_("name", "description", "searchhint", | 113 | HomeLens home_lens_("name", "description", "searchhint", |
1215 | 349 | HomeLens::MergeMode::OWNER_LENS); | 114 | HomeLens::MergeMode::OWNER_LENS); |
1217 | 350 | TwoStaticTestLenses lenses_; | 115 | std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>(); |
1218 | 351 | DeeModel* cats = home_lens_.categories()->model(); | 116 | DeeModel* cats = home_lens_.categories()->model(); |
1219 | 352 | DeeModelIter* iter; | 117 | DeeModelIter* iter; |
1220 | 353 | const unsigned int NAME_COLUMN = 0; | 118 | const unsigned int NAME_COLUMN = 0; |
1221 | @@ -371,7 +136,7 @@ | |||
1222 | 371 | TEST(TestHomeLens, TestIgnoreFilters) | 136 | TEST(TestHomeLens, TestIgnoreFilters) |
1223 | 372 | { | 137 | { |
1224 | 373 | HomeLens home_lens_("name", "description", "searchhint"); | 138 | HomeLens home_lens_("name", "description", "searchhint"); |
1226 | 374 | TwoStaticTestLenses lenses_; | 139 | std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>(); |
1227 | 375 | DeeModel* filters = home_lens_.filters()->model(); | 140 | DeeModel* filters = home_lens_.filters()->model(); |
1228 | 376 | 141 | ||
1229 | 377 | EXPECT_EQ(dee_model_get_n_rows(filters), 0); | 142 | EXPECT_EQ(dee_model_get_n_rows(filters), 0); |
1230 | @@ -381,7 +146,7 @@ | |||
1231 | 381 | { | 146 | { |
1232 | 382 | HomeLens home_lens_("name", "description", "searchhint", | 147 | HomeLens home_lens_("name", "description", "searchhint", |
1233 | 383 | HomeLens::MergeMode::DISPLAY_NAME); | 148 | HomeLens::MergeMode::DISPLAY_NAME); |
1235 | 384 | TwoStaticTestLenses lenses_; | 149 | std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>(); |
1236 | 385 | DeeModel* results = home_lens_.results()->model(); | 150 | DeeModel* results = home_lens_.results()->model(); |
1237 | 386 | DeeModel* cats = home_lens_.categories()->model(); | 151 | DeeModel* cats = home_lens_.categories()->model(); |
1238 | 387 | DeeModel* filters = home_lens_.filters()->model(); | 152 | DeeModel* filters = home_lens_.filters()->model(); |
1239 | @@ -440,7 +205,7 @@ | |||
1240 | 440 | { | 205 | { |
1241 | 441 | HomeLens home_lens_("name", "description", "searchhint", | 206 | HomeLens home_lens_("name", "description", "searchhint", |
1242 | 442 | HomeLens::MergeMode::OWNER_LENS); | 207 | HomeLens::MergeMode::OWNER_LENS); |
1244 | 443 | ThreeStaticTestLenses lenses_; | 208 | std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>(); |
1245 | 444 | DeeModel* results = home_lens_.results()->model(); | 209 | DeeModel* results = home_lens_.results()->model(); |
1246 | 445 | DeeModel* cats = home_lens_.categories()->model(); | 210 | DeeModel* cats = home_lens_.categories()->model(); |
1247 | 446 | DeeModel* filters = home_lens_.filters()->model(); | 211 | DeeModel* filters = home_lens_.filters()->model(); |
1248 | @@ -491,14 +256,14 @@ | |||
1249 | 491 | { | 256 | { |
1250 | 492 | HomeLens home_lens_("name", "description", "searchhint", | 257 | HomeLens home_lens_("name", "description", "searchhint", |
1251 | 493 | HomeLens::MergeMode::OWNER_LENS); | 258 | HomeLens::MergeMode::OWNER_LENS); |
1253 | 494 | ThreeStaticTestLenses lenses_; | 259 | std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>(); |
1254 | 495 | // the lens is added as third, so must have cat == 2 | 260 | // the lens is added as third, so must have cat == 2 |
1255 | 496 | unsigned int apps_lens_cat = 2; | 261 | unsigned int apps_lens_cat = 2; |
1256 | 497 | 262 | ||
1257 | 498 | home_lens_.AddLenses(lenses_); | 263 | home_lens_.AddLenses(lenses_); |
1259 | 499 | Lens::Ptr apps_lens = lenses_.GetLens("applications.lens"); | 264 | Lens::Ptr apps_lens = lenses_->GetLens("applications.lens"); |
1260 | 500 | 265 | ||
1262 | 501 | auto static_lens = dynamic_pointer_cast<StaticTestLens>(apps_lens); | 266 | auto static_lens = dynamic_pointer_cast<MockTestLens>(apps_lens); |
1263 | 502 | static_lens->SetNumResults(1); | 267 | static_lens->SetNumResults(1); |
1264 | 503 | 268 | ||
1265 | 504 | bool order_changed = false; | 269 | bool order_changed = false; |
1266 | @@ -535,14 +300,14 @@ | |||
1267 | 535 | { | 300 | { |
1268 | 536 | HomeLens home_lens_("name", "description", "searchhint", | 301 | HomeLens home_lens_("name", "description", "searchhint", |
1269 | 537 | HomeLens::MergeMode::OWNER_LENS); | 302 | HomeLens::MergeMode::OWNER_LENS); |
1271 | 538 | ThreeStaticTestLenses lenses_; | 303 | std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>(); |
1272 | 539 | // the lens is added as third, so must have cat == 2 | 304 | // the lens is added as third, so must have cat == 2 |
1273 | 540 | unsigned int apps_lens_cat = 2; | 305 | unsigned int apps_lens_cat = 2; |
1274 | 541 | 306 | ||
1275 | 542 | home_lens_.AddLenses(lenses_); | 307 | home_lens_.AddLenses(lenses_); |
1277 | 543 | Lens::Ptr apps_lens = lenses_.GetLens("applications.lens"); | 308 | Lens::Ptr apps_lens = lenses_->GetLens("applications.lens"); |
1278 | 544 | 309 | ||
1280 | 545 | auto static_lens = dynamic_pointer_cast<StaticTestLens>(apps_lens); | 310 | auto static_lens = dynamic_pointer_cast<MockTestLens>(apps_lens); |
1281 | 546 | static_lens->SetResultsBaseName("noapes"); | 311 | static_lens->SetResultsBaseName("noapes"); |
1282 | 547 | static_lens->SetNumResults(1); | 312 | static_lens->SetNumResults(1); |
1283 | 548 | 313 | ||
1284 | @@ -579,7 +344,7 @@ | |||
1285 | 579 | { | 344 | { |
1286 | 580 | HomeLens home_lens_("name", "description", "searchhint", | 345 | HomeLens home_lens_("name", "description", "searchhint", |
1287 | 581 | HomeLens::MergeMode::OWNER_LENS); | 346 | HomeLens::MergeMode::OWNER_LENS); |
1289 | 582 | ThreeStaticTestLenses lenses_; | 347 | std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>(); |
1290 | 583 | unsigned int lens1_cat = 0; | 348 | unsigned int lens1_cat = 0; |
1291 | 584 | unsigned int lens2_cat = 1; | 349 | unsigned int lens2_cat = 1; |
1292 | 585 | // the lens is added as third, so must have cat == 2 | 350 | // the lens is added as third, so must have cat == 2 |
1293 | @@ -587,14 +352,14 @@ | |||
1294 | 587 | 352 | ||
1295 | 588 | home_lens_.AddLenses(lenses_); | 353 | home_lens_.AddLenses(lenses_); |
1296 | 589 | 354 | ||
1299 | 590 | Lens::Ptr lens = lenses_.GetLensAtIndex(2); | 355 | Lens::Ptr lens = lenses_->GetLensAtIndex(2); |
1300 | 591 | auto static_lens = dynamic_pointer_cast<StaticTestLens>(lens); | 356 | auto static_lens = dynamic_pointer_cast<MockTestLens>(lens); |
1301 | 592 | static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens | 357 | static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens |
1302 | 593 | static_lens->SetNumResults(2); | 358 | static_lens->SetNumResults(2); |
1303 | 594 | 359 | ||
1305 | 595 | static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(0)); | 360 | static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(0)); |
1306 | 596 | static_lens->SetNumResults(1); | 361 | static_lens->SetNumResults(1); |
1308 | 597 | static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(1)); | 362 | static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(1)); |
1309 | 598 | static_lens->SetNumResults(3); | 363 | static_lens->SetNumResults(3); |
1310 | 599 | 364 | ||
1311 | 600 | bool order_changed = false; | 365 | bool order_changed = false; |
1312 | @@ -638,7 +403,7 @@ | |||
1313 | 638 | { | 403 | { |
1314 | 639 | HomeLens home_lens_("name", "description", "searchhint", | 404 | HomeLens home_lens_("name", "description", "searchhint", |
1315 | 640 | HomeLens::MergeMode::OWNER_LENS); | 405 | HomeLens::MergeMode::OWNER_LENS); |
1317 | 641 | ThreeStaticTestLenses lenses_; | 406 | std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>(); |
1318 | 642 | unsigned int lens1_cat = 0; | 407 | unsigned int lens1_cat = 0; |
1319 | 643 | unsigned int lens2_cat = 1; | 408 | unsigned int lens2_cat = 1; |
1320 | 644 | // the lens is added as third, so must have cat == 2 | 409 | // the lens is added as third, so must have cat == 2 |
1321 | @@ -652,14 +417,14 @@ | |||
1322 | 652 | * lens3 -> 2 results (apps.lens) | 417 | * lens3 -> 2 results (apps.lens) |
1323 | 653 | */ | 418 | */ |
1324 | 654 | 419 | ||
1327 | 655 | Lens::Ptr lens = lenses_.GetLensAtIndex(2); | 420 | Lens::Ptr lens = lenses_->GetLensAtIndex(2); |
1328 | 656 | auto static_lens = dynamic_pointer_cast<StaticTestLens>(lens); | 421 | auto static_lens = dynamic_pointer_cast<MockTestLens>(lens); |
1329 | 657 | static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens | 422 | static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens |
1330 | 658 | static_lens->SetNumResults(2); | 423 | static_lens->SetNumResults(2); |
1331 | 659 | 424 | ||
1333 | 660 | static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(0)); | 425 | static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(0)); |
1334 | 661 | static_lens->SetNumResults(1); | 426 | static_lens->SetNumResults(1); |
1336 | 662 | static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(1)); | 427 | static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(1)); |
1337 | 663 | static_lens->SetNumResults(3); | 428 | static_lens->SetNumResults(3); |
1338 | 664 | static_lens->SetProvidesPersonalResults(false); | 429 | static_lens->SetProvidesPersonalResults(false); |
1339 | 665 | 430 | ||
1340 | @@ -698,7 +463,7 @@ | |||
1341 | 698 | { | 463 | { |
1342 | 699 | HomeLens home_lens_("name", "description", "searchhint", | 464 | HomeLens home_lens_("name", "description", "searchhint", |
1343 | 700 | HomeLens::MergeMode::OWNER_LENS); | 465 | HomeLens::MergeMode::OWNER_LENS); |
1345 | 701 | ThreeStaticTestLenses lenses_; | 466 | std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>(); |
1346 | 702 | unsigned int lens1_cat = 0; | 467 | unsigned int lens1_cat = 0; |
1347 | 703 | unsigned int lens2_cat = 1; | 468 | unsigned int lens2_cat = 1; |
1348 | 704 | // the lens is added as third, so must have cat == 2 | 469 | // the lens is added as third, so must have cat == 2 |
1349 | @@ -712,13 +477,13 @@ | |||
1350 | 712 | * lens3 -> 0 results (apps.lens) | 477 | * lens3 -> 0 results (apps.lens) |
1351 | 713 | */ | 478 | */ |
1352 | 714 | 479 | ||
1355 | 715 | Lens::Ptr lens = lenses_.GetLensAtIndex(2); | 480 | Lens::Ptr lens = lenses_->GetLensAtIndex(2); |
1356 | 716 | auto static_lens = dynamic_pointer_cast<StaticTestLens>(lens); | 481 | auto static_lens = dynamic_pointer_cast<MockTestLens>(lens); |
1357 | 717 | static_lens->SetNumResults(0); | 482 | static_lens->SetNumResults(0); |
1358 | 718 | 483 | ||
1360 | 719 | static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(0)); | 484 | static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(0)); |
1361 | 720 | static_lens->SetNumResults(1); | 485 | static_lens->SetNumResults(1); |
1363 | 721 | static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(1)); | 486 | static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(1)); |
1364 | 722 | static_lens->SetNumResults(3); | 487 | static_lens->SetNumResults(3); |
1365 | 723 | static_lens->SetProvidesPersonalResults(false); | 488 | static_lens->SetProvidesPersonalResults(false); |
1366 | 724 | 489 |
Awesome, confirmed working here. Tests pass. LGTM