Merge lp:~azzar1/unity/lp-1152733 into lp:unity

Proposed by Andrea Azzarone
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
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 ApplicationStarter*::Launch is getting called.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Awesome, confirmed working here. Tests pass. LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Approved!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'UnityCore/FilesystemLenses.h'
--- UnityCore/FilesystemLenses.h 2012-03-29 04:40:53 +0000
+++ UnityCore/FilesystemLenses.h 2013-03-12 22:36:20 +0000
@@ -82,10 +82,10 @@
8282
83 ~FilesystemLenses();83 ~FilesystemLenses();
8484
85 LensList GetLenses() const;85 LensList GetLenses() const override;
86 Lens::Ptr GetLens(std::string const& lens_id) const;86 Lens::Ptr GetLens(std::string const& lens_id) const override;
87 Lens::Ptr GetLensAtIndex(std::size_t index) const;87 Lens::Ptr GetLensAtIndex(std::size_t index) const override;
88 Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const;88 Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const override;
8989
90 sigc::signal<void> lenses_loaded;90 sigc::signal<void> lenses_loaded;
9191
9292
=== modified file 'UnityCore/HomeLens.cpp'
--- UnityCore/HomeLens.cpp 2012-11-14 08:57:56 +0000
+++ UnityCore/HomeLens.cpp 2013-03-12 22:36:20 +0000
@@ -1116,14 +1116,14 @@
1116 delete pimpl;1116 delete pimpl;
1117}1117}
11181118
1119void HomeLens::AddLenses(Lenses& lenses)1119void HomeLens::AddLenses(Lenses::Ptr const& lenses)
1120{1120{
1121 for (auto lens : lenses.GetLenses())1121 for (auto lens : lenses->GetLenses())
1122 {1122 {
1123 pimpl->OnLensAdded(lens);1123 pimpl->OnLensAdded(lens);
1124 }1124 }
11251125
1126 lenses.lens_added.connect(sigc::mem_fun(pimpl, &HomeLens::Impl::OnLensAdded));1126 lenses->lens_added.connect(sigc::mem_fun(pimpl, &HomeLens::Impl::OnLensAdded));
1127}1127}
11281128
1129Lenses::LensList HomeLens::GetLenses() const1129Lenses::LensList HomeLens::GetLenses() const
@@ -1158,6 +1158,11 @@
1158 return Lens::Ptr();1158 return Lens::Ptr();
1159}1159}
11601160
1161Lens::Ptr HomeLens::GetLensForShortcut(std::string const& lens_shortcut) const
1162{
1163 return Lens::Ptr();
1164}
1165
1161void HomeLens::GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb)1166void HomeLens::GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb)
1162{1167{
1163 LOG_WARN(logger) << "Global search not enabled for HomeLens class."1168 LOG_WARN(logger) << "Global search not enabled for HomeLens class."
11641169
=== modified file 'UnityCore/HomeLens.h'
--- UnityCore/HomeLens.h 2012-11-12 11:07:23 +0000
+++ UnityCore/HomeLens.h 2013-03-12 22:36:20 +0000
@@ -63,11 +63,12 @@
63 MergeMode merge_mode = MergeMode::OWNER_LENS);63 MergeMode merge_mode = MergeMode::OWNER_LENS);
64 virtual ~HomeLens();64 virtual ~HomeLens();
6565
66 void AddLenses(Lenses& lenses);66 void AddLenses(Lenses::Ptr const& lenses);
6767
68 Lenses::LensList GetLenses() const;68 Lenses::LensList GetLenses() const override;
69 Lens::Ptr GetLens(std::string const& lens_id) const;69 Lens::Ptr GetLens(std::string const& lens_id) const override;
70 Lens::Ptr GetLensAtIndex(std::size_t index) const;70 Lens::Ptr GetLensAtIndex(std::size_t index) const override;
71 Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const override;
7172
72 void GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb);73 void GlobalSearch(std::string const& search_string, SearchFinishedCallback const& cb);
73 void Search(std::string const& search_string, SearchFinishedCallback const& cb);74 void Search(std::string const& search_string, SearchFinishedCallback const& cb);
7475
=== modified file 'UnityCore/Lenses.h'
--- UnityCore/Lenses.h 2011-07-27 17:35:31 +0000
+++ UnityCore/Lenses.h 2013-03-12 22:36:20 +0000
@@ -20,6 +20,7 @@
20#ifndef UNITY_LENSES_H20#ifndef UNITY_LENSES_H
21#define UNITY_LENSES_H21#define UNITY_LENSES_H
2222
23#include <memory>
23#include <sigc++/trackable.h>24#include <sigc++/trackable.h>
24#include <sigc++/signal.h>25#include <sigc++/signal.h>
2526
@@ -33,6 +34,7 @@
33class Lenses : public sigc::trackable, boost::noncopyable34class Lenses : public sigc::trackable, boost::noncopyable
34{35{
35public:36public:
37 typedef std::shared_ptr<Lenses> Ptr;
36 typedef std::vector<Lens::Ptr> LensList;38 typedef std::vector<Lens::Ptr> LensList;
3739
38 /**40 /**
@@ -45,6 +47,7 @@
45 virtual LensList GetLenses() const = 0;47 virtual LensList GetLenses() const = 0;
46 virtual Lens::Ptr GetLens(std::string const& lens_id) const = 0;48 virtual Lens::Ptr GetLens(std::string const& lens_id) const = 0;
47 virtual Lens::Ptr GetLensAtIndex(std::size_t index) const = 0;49 virtual Lens::Ptr GetLensAtIndex(std::size_t index) const = 0;
50 virtual Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const = 0;
4851
49 nux::ROProperty<std::size_t> count;52 nux::ROProperty<std::size_t> count;
5053
5154
=== added file 'dash/ApplicationStarter.h'
--- dash/ApplicationStarter.h 1970-01-01 00:00:00 +0000
+++ dash/ApplicationStarter.h 2013-03-12 22:36:20 +0000
@@ -0,0 +1,40 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#ifndef UNITY_SHARED_APPLICATION_STARTER_H
20#define UNITY_SHARED_APPLICATION_STARTER_H
21
22#include <boost/noncopyable.hpp>
23#include <memory>
24#include <string>
25
26#include <X11/X.h>
27
28namespace unity {
29
30class ApplicationStarter : boost::noncopyable
31{
32public:
33 typedef std::shared_ptr<ApplicationStarter> Ptr;
34
35 virtual bool Launch(std::string const& application_name, Time timestamp) = 0;
36};
37
38}
39
40#endif
041
=== added file 'dash/ApplicationStarterImp.cpp'
--- dash/ApplicationStarterImp.cpp 1970-01-01 00:00:00 +0000
+++ dash/ApplicationStarterImp.cpp 2013-03-12 22:36:20 +0000
@@ -0,0 +1,72 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#include "ApplicationStarterImp.h"
20
21#include <gdk/gdk.h>
22#include <gio/gdesktopappinfo.h>
23
24#include <NuxCore/Logger.h>
25#include <UnityCore/GLibWrapper.h>
26
27namespace unity {
28
29DECLARE_LOGGER(logger, "unity.applicationstarterimp");
30
31bool ApplicationStarterImp::Launch(std::string const& application_name, Time timestamp)
32{
33 std::string id = application_name;
34
35 LOG_DEBUG(logger) << "Launching " << id;
36
37 GdkDisplay* display = gdk_display_get_default();
38 glib::Object<GdkAppLaunchContext> app_launch_context(gdk_display_get_app_launch_context(display));
39
40 if (timestamp >= 0)
41 gdk_app_launch_context_set_timestamp(app_launch_context, timestamp);
42
43 while (true)
44 {
45 glib::Object<GDesktopAppInfo> info(g_desktop_app_info_new(id.c_str()));
46
47 if (info)
48 {
49 glib::Error error;
50 g_app_info_launch(glib::object_cast<GAppInfo>(info), nullptr,
51 glib::object_cast<GAppLaunchContext>(app_launch_context), &error);
52
53 if (error)
54 LOG_WARNING(logger) << "Unable to launch " << id << ":" << error;
55 else
56 return true;
57
58 break;
59 }
60
61 // Try to replace the next - with a / and do the lookup again.
62 auto pos = id.find_first_of('-');
63 if (pos != std::string::npos)
64 id.replace(pos, 1, "/");
65 else
66 break;
67 }
68
69 return false;
70}
71
72}
073
=== added file 'dash/ApplicationStarterImp.h'
--- dash/ApplicationStarterImp.h 1970-01-01 00:00:00 +0000
+++ dash/ApplicationStarterImp.h 2013-03-12 22:36:20 +0000
@@ -0,0 +1,34 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#ifndef UNITY_SHARED_APPLICATION_STARTER_IMP_H
20#define UNITY_SHARED_APPLICATION_STARTER_IMP_H
21
22#include "ApplicationStarter.h"
23
24namespace unity {
25
26class ApplicationStarterImp : public ApplicationStarter
27{
28public:
29 bool Launch(std::string const& application_name, Time timestamp) override;
30};
31
32}
33
34#endif
035
=== modified file 'dash/CMakeLists.txt'
--- dash/CMakeLists.txt 2013-01-28 23:57:38 +0000
+++ dash/CMakeLists.txt 2013-03-12 22:36:20 +0000
@@ -19,6 +19,7 @@
19# Headers & Sources19# Headers & Sources
20#20#
21set (DASH_SOURCES21set (DASH_SOURCES
22 ApplicationStarterImp.cpp
22 CoverflowResultView.cpp23 CoverflowResultView.cpp
23 DashController.cpp24 DashController.cpp
24 DashView.cpp25 DashView.cpp
2526
=== modified file 'dash/DashController.cpp'
--- dash/DashController.cpp 2013-03-06 13:13:37 +0000
+++ dash/DashController.cpp 2013-03-12 22:36:20 +0000
@@ -23,6 +23,7 @@
23#include <Nux/HLayout.h>23#include <Nux/HLayout.h>
24#include <UnityCore/GLibWrapper.h>24#include <UnityCore/GLibWrapper.h>
2525
26#include "ApplicationStarterImp.h"
26#include "unity-shared/DashStyle.h"27#include "unity-shared/DashStyle.h"
27#include "unity-shared/PanelStyle.h"28#include "unity-shared/PanelStyle.h"
28#include "unity-shared/UBusMessages.h"29#include "unity-shared/UBusMessages.h"
@@ -139,7 +140,7 @@
139140
140void Controller::SetupDashView()141void Controller::SetupDashView()
141{142{
142 view_ = new DashView();143 view_ = new DashView(std::make_shared<FilesystemLenses>(), std::make_shared<ApplicationStarterImp>());
143 AddChild(view_);144 AddChild(view_);
144145
145 nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION);146 nux::HLayout* layout = new nux::HLayout(NUX_TRACKER_LOCATION);
146147
=== modified file 'dash/DashView.cpp'
--- dash/DashView.cpp 2013-02-26 12:57:59 +0000
+++ dash/DashView.cpp 2013-03-12 22:36:20 +0000
@@ -24,7 +24,6 @@
2424
25#include <math.h>25#include <math.h>
2626
27#include <gio/gdesktopappinfo.h>
28#include <glib/gi18n-lib.h>27#include <glib/gi18n-lib.h>
29#include <gtk/gtk.h>28#include <gtk/gtk.h>
3029
@@ -110,13 +109,16 @@
110109
111NUX_IMPLEMENT_OBJECT_TYPE(DashView);110NUX_IMPLEMENT_OBJECT_TYPE(DashView);
112111
113DashView::DashView()112DashView::DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter)
114 : nux::View(NUX_TRACKER_LOCATION)113 : nux::View(NUX_TRACKER_LOCATION)
114 , lenses_(lenses)
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")))
116 , application_starter_(application_starter)
116 , preview_container_(nullptr)117 , preview_container_(nullptr)
117 , preview_displaying_(false)118 , preview_displaying_(false)
118 , preview_navigation_mode_(previews::Navigation::NONE)119 , preview_navigation_mode_(previews::Navigation::NONE)
119 , last_activated_uri_("")120 , last_activated_uri_("")
121 , last_activated_timestamp_(0)
120 , search_in_progress_(false)122 , search_in_progress_(false)
121 , activate_on_finish_(false)123 , activate_on_finish_(false)
122 , visible_(false)124 , visible_(false)
@@ -137,11 +139,14 @@
137 SetupViews();139 SetupViews();
138 SetupUBusConnections();140 SetupUBusConnections();
139141
140 lenses_.lens_added.connect(sigc::mem_fun(this, &DashView::OnLensAdded));142 lenses_->lens_added.connect(sigc::mem_fun(this, &DashView::OnLensAdded));
141 mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown));143 mouse_down.connect(sigc::mem_fun(this, &DashView::OnMouseButtonDown));
142 preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview));144 preview_state_machine_.PreviewActivated.connect(sigc::mem_fun(this, &DashView::BuildPreview));
143 Relayout();145 Relayout();
144146
147 for (auto lens : lenses_->GetLenses())
148 lenses_->lens_added.emit(lens);
149
145 home_lens_->AddLenses(lenses_);150 home_lens_->AddLenses(lenses_);
146 lens_bar_->Activate("home.lens");151 lens_bar_->Activate("home.lens");
147152
@@ -195,7 +200,8 @@
195 int row_height = 0;200 int row_height = 0;
196 int results_to_the_left = 0;201 int results_to_the_left = 0;
197 int results_to_the_right = 0;202 int results_to_the_right = 0;
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);
204
199 preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, row_y);205 preview_state_machine_.SetSplitPosition(SplitPosition::CONTENT_AREA, row_y);
200 preview_state_machine_.left_results = results_to_the_left;206 preview_state_machine_.left_results = results_to_the_left;
201 preview_state_machine_.right_results = results_to_the_right;207 preview_state_machine_.right_results = results_to_the_right;
@@ -470,7 +476,7 @@
470476
471 if (active_lens_view_->lens()->id() == "home.lens")477 if (active_lens_view_->lens()->id() == "home.lens")
472 {478 {
473 for (auto lens : lenses_.GetLenses())479 for (auto lens : lenses_->GetLenses())
474 {480 {
475 lens->view_type = ViewType::HOME_VIEW;481 lens->view_type = ViewType::HOME_VIEW;
476 LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HOME_VIEW482 LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HOME_VIEW
@@ -508,7 +514,7 @@
508 visible_ = false;514 visible_ = false;
509 renderer_.AboutToHide();515 renderer_.AboutToHide();
510516
511 for (auto lens : lenses_.GetLenses())517 for (auto lens : lenses_->GetLenses())
512 {518 {
513 lens->view_type = ViewType::HIDDEN;519 lens->view_type = ViewType::HIDDEN;
514 LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN520 LOG_DEBUG(logger) << "Setting ViewType " << ViewType::HIDDEN
@@ -1152,9 +1158,9 @@
11521158
1153void DashView::UpdateLensFilter(std::string lens_id, std::string filter_name, std::string value)1159void DashView::UpdateLensFilter(std::string lens_id, std::string filter_name, std::string value)
1154{1160{
1155 if (lenses_.GetLens(lens_id))1161 if (lenses_->GetLens(lens_id))
1156 {1162 {
1157 Lens::Ptr lens = lenses_.GetLens(lens_id);1163 Lens::Ptr lens = lenses_->GetLens(lens_id);
11581164
1159 Filters::Ptr filters = lens->filters;1165 Filters::Ptr filters = lens->filters;
11601166
@@ -1219,7 +1225,6 @@
12191225
1220void DashView::OnLensAdded(Lens::Ptr& lens)1226void DashView::OnLensAdded(Lens::Ptr& lens)
1221{1227{
1222 std::string id = lens->id;
1223 lens_bar_->AddLens(lens);1228 lens_bar_->AddLens(lens);
12241229
1225 nux::ObjectPtr<LensView> view(new LensView(lens, search_bar_->show_filters()));1230 nux::ObjectPtr<LensView> view(new LensView(lens, search_bar_->show_filters()));
@@ -1366,70 +1371,20 @@
13661371
1367 if (g_str_has_prefix(uri.c_str(), "application://"))1372 if (g_str_has_prefix(uri.c_str(), "application://"))
1368 {1373 {
1369 std::string appname = uri.substr(14);1374 std::string const& appname = uri.substr(14);
1370 return LaunchApp(appname);1375 return application_starter_->Launch(appname, last_activated_timestamp_);
1371 }1376 }
1372 else if (g_str_has_prefix(uri.c_str(), "unity-runner://"))1377 else if (g_str_has_prefix(uri.c_str(), "unity-runner://"))
1373 {1378 {
1374 std::string appname = uri.substr(15);1379 std::string const& appname = uri.substr(15);
1375 return LaunchApp(appname);1380 return application_starter_->Launch(appname, last_activated_timestamp_);
1376 }1381 }
1377 else1382 else
1378 return gtk_show_uri(NULL, uri.c_str(), CurrentTime, NULL);1383 return gtk_show_uri(NULL, uri.c_str(), last_activated_timestamp_, NULL);
13791384
1380 return false;1385 return false;
1381}1386}
13821387
1383bool DashView::LaunchApp(std::string const& appname)
1384{
1385 GDesktopAppInfo* info;
1386 bool ret = false;
1387 char *id = g_strdup(appname.c_str());
1388 int i = 0;
1389
1390 LOG_DEBUG(logger) << "Launching " << appname;
1391
1392 while (id != NULL)
1393 {
1394 info = g_desktop_app_info_new(id);
1395 if (info != NULL)
1396 {
1397 GError* error = NULL;
1398
1399 g_app_info_launch(G_APP_INFO(info), NULL, NULL, &error);
1400 if (error)
1401 {
1402 g_warning("Unable to launch %s: %s", id, error->message);
1403 g_error_free(error);
1404 }
1405 else
1406 ret = true;
1407 g_object_unref(info);
1408 break;
1409 }
1410
1411 /* Try to replace the next - with a / and do the lookup again.
1412 * If we set id=NULL we'll exit the outer loop */
1413 for (i = 0; ; i++)
1414 {
1415 if (id[i] == '-')
1416 {
1417 id[i] = '/';
1418 break;
1419 }
1420 else if (id[i] == '\0')
1421 {
1422 g_free(id);
1423 id = NULL;
1424 break;
1425 }
1426 }
1427 }
1428
1429 g_free(id);
1430 return ret;
1431}
1432
1433void DashView::DisableBlur()1388void DashView::DisableBlur()
1434{1389{
1435 renderer_.DisableBlur();1390 renderer_.DisableBlur();
@@ -1452,7 +1407,7 @@
14521407
1453std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const1408std::string const DashView::GetIdForShortcutActivation(std::string const& shortcut) const
1454{1409{
1455 Lens::Ptr lens = lenses_.GetLensForShortcut(shortcut);1410 Lens::Ptr lens = lenses_->GetLensForShortcut(shortcut);
1456 if (lens)1411 if (lens)
1457 return lens->id;1412 return lens->id;
1458 return "";1413 return "";
@@ -1462,7 +1417,7 @@
1462{1417{
1463 std::vector<char> result;1418 std::vector<char> result;
14641419
1465 for (Lens::Ptr lens: lenses_.GetLenses())1420 for (Lens::Ptr lens: lenses_->GetLenses())
1466 {1421 {
1467 std::string shortcut = lens->shortcut;1422 std::string shortcut = lens->shortcut;
1468 if(shortcut.size() > 0)1423 if(shortcut.size() > 0)
14691424
=== modified file 'dash/DashView.h'
--- dash/DashView.h 2013-01-28 23:57:38 +0000
+++ dash/DashView.h 2013-03-12 22:36:20 +0000
@@ -28,6 +28,7 @@
28#include <UnityCore/HomeLens.h>28#include <UnityCore/HomeLens.h>
29#include <UnityCore/GLibSource.h>29#include <UnityCore/GLibSource.h>
3030
31#include "ApplicationStarter.h"
31#include "LensBar.h"32#include "LensBar.h"
32#include "LensView.h"33#include "LensView.h"
33#include "previews/PreviewContainer.h"34#include "previews/PreviewContainer.h"
@@ -58,7 +59,7 @@
58 typedef std::map<std::string, nux::ObjectPtr<LensView>> LensViews;59 typedef std::map<std::string, nux::ObjectPtr<LensView>> LensViews;
5960
60public:61public:
61 DashView();62 DashView(Lenses::Ptr const& lenses, ApplicationStarter::Ptr const& application_starter);
62 ~DashView();63 ~DashView();
6364
64 void AboutToShow();65 void AboutToShow();
@@ -131,10 +132,12 @@
131 nux::Area* KeyNavIteration(nux::KeyNavDirection direction);132 nux::Area* KeyNavIteration(nux::KeyNavDirection direction);
132133
133 UBusManager ubus_manager_;134 UBusManager ubus_manager_;
134 FilesystemLenses lenses_;135 Lenses::Ptr lenses_;
135 HomeLens::Ptr home_lens_;136 HomeLens::Ptr home_lens_;
136 LensViews lens_views_;137 LensViews lens_views_;
137138
139 ApplicationStarter::Ptr application_starter_;
140
138 // View related141 // View related
139 PreviewStateMachine preview_state_machine_;142 PreviewStateMachine preview_state_machine_;
140 previews::PreviewContainer::Ptr preview_container_;143 previews::PreviewContainer::Ptr preview_container_;
@@ -159,7 +162,7 @@
159 OverlayRenderer renderer_;162 OverlayRenderer renderer_;
160163
161 std::string last_activated_uri_;164 std::string last_activated_uri_;
162 // we're passing this back to g_* functions, so we'll keep the g* type165 Time last_activated_timestamp_;
163 bool search_in_progress_;166 bool search_in_progress_;
164 bool activate_on_finish_;167 bool activate_on_finish_;
165168
166169
=== modified file 'dash/ResultViewGrid.cpp'
--- dash/ResultViewGrid.cpp 2013-01-09 13:33:36 +0000
+++ dash/ResultViewGrid.cpp 2013-03-12 22:36:20 +0000
@@ -208,7 +208,8 @@
208 }208 }
209209
210 active_index_ = index;210 active_index_ = index;
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;
212 glib::Variant data(g_variant_new("(iiiiiii)", timestamp, column_x, row_y, column_width, row_height, left_results, right_results));
212 UriActivated.emit(uri, type, data);213 UriActivated.emit(uri, type, data);
213}214}
214215
215216
=== modified file 'dash/StandaloneDash.cpp'
--- dash/StandaloneDash.cpp 2012-11-29 10:19:01 +0000
+++ dash/StandaloneDash.cpp 2013-03-12 22:36:20 +0000
@@ -28,6 +28,7 @@
28#include <NuxCore/AnimationController.h>28#include <NuxCore/AnimationController.h>
29#include <NuxCore/Logger.h>29#include <NuxCore/Logger.h>
3030
31#include "ApplicationStarterImp.h"
31#include "unity-shared/BGHash.h"32#include "unity-shared/BGHash.h"
32#include "unity-shared/FontSettings.h"33#include "unity-shared/FontSettings.h"
33#include "DashView.h"34#include "DashView.h"
@@ -64,7 +65,8 @@
64{65{
65 layout = new nux::HLayout(NUX_TRACKER_LOCATION);66 layout = new nux::HLayout(NUX_TRACKER_LOCATION);
6667
67 DashView* view = new DashView();68 DashView* view = new DashView(std::make_shared<unity::dash::FilesystemLenses>(),
69 std::make_shared<unity::ApplicationStarterImp>());
68 view->DisableBlur();70 view->DisableBlur();
69 view->SetMinMaxSize(WIDTH, HEIGHT);71 view->SetMinMaxSize(WIDTH, HEIGHT);
70 layout->AddView (view, 1, nux::MINOR_POSITION_CENTER);72 layout->AddView (view, 1, nux::MINOR_POSITION_CENTER);
7173
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2013-03-08 12:46:41 +0000
+++ tests/CMakeLists.txt 2013-03-12 22:36:20 +0000
@@ -202,6 +202,7 @@
202 test_application_launcher_icon.cpp202 test_application_launcher_icon.cpp
203 test_bamf_application.cpp203 test_bamf_application.cpp
204 test_bfb_launcher_icon.cpp204 test_bfb_launcher_icon.cpp
205 test_dash_view.cpp
205 test_dashview_impl.cpp206 test_dashview_impl.cpp
206 test_dash_controller.cpp207 test_dash_controller.cpp
207 test_desktop_launcher_icon.cpp208 test_desktop_launcher_icon.cpp
208209
=== added file 'tests/mock-lenses.h'
--- tests/mock-lenses.h 1970-01-01 00:00:00 +0000
+++ tests/mock-lenses.h 2013-03-12 22:36:20 +0000
@@ -0,0 +1,271 @@
1// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2/*
3* Copyright (C) 2013 Canonical Ltd
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License version 3 as
7* published by the Free Software Foundation.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with this program. If not, see <http://www.gnu.org/licenses/>.
16*
17*/
18
19#ifndef UNITY_TESTS_MOCK_LENSES_H
20#define UNITY_TESTS_MOCK_LENSES_H
21
22#include <dee.h>
23
24#include <UnityCore/GLibWrapper.h>
25#include <UnityCore/GLibSource.h>
26#include <UnityCore/Lens.h>
27#include <UnityCore/Lenses.h>
28
29namespace testmocks {
30
31/*
32 * FORWARDS
33 */
34
35class MockTestLens;
36
37/*
38 * Mock Lens instance that does not use DBus. The default search does like this:
39 * For input "bar" output:
40 *
41 * i = 0
42 * for letter in "bar":
43 * put result row [ "uri+$letter+$lens_id", "icon+$letter+$lens_id", i % 3, "mime+$letter+$lens_id", ...]
44 * i++
45 *
46 * The mock lens has 3 categories:
47 *
48 * 0) "cat0+$lens_id"
49 * 1) "cat1+$lens_id"
50 * 2) "Shared cat"
51 */
52class MockTestLens : public unity::dash::Lens
53{
54public:
55 typedef std::shared_ptr<MockTestLens> Ptr;
56
57 MockTestLens(std::string const& id, std::string const& name, std::string const& description, std::string const& search_hint)
58 : Lens(id, "", "", name, "lens-icon.png",
59 description, search_hint, true, "",
60 unity::dash::ModelType::LOCAL)
61 , num_results_(-1)
62 , provides_personal_results_(true)
63 {
64 search_in_global(true);
65 connected.SetGetterFunction(sigc::mem_fun(this, &MockTestLens::force_connected));
66 provides_personal_content.SetGetterFunction(sigc::mem_fun(this, &MockTestLens::get_provides_personal_results));
67
68 DeeModel* cats = categories()->model();
69 DeeModel* results = global_results()->model();
70 DeeModel* flters = filters()->model();
71
72 // Set model schemas
73 dee_model_set_schema(cats, "s", "s", "s", "a{sv}", NULL);
74 dee_model_set_schema(results, "s", "s", "u", "s", "s", "s", "s", NULL);
75 dee_model_set_schema(flters, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL);
76
77 // Populate categories model
78 std::ostringstream cat0, cat1;
79 cat0 << "cat0+" << id;
80 cat1 << "cat1+" << id;
81 GVariantBuilder b;
82 g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT);
83 GVariant *asv = g_variant_builder_end(&b);
84
85 dee_model_append(cats, cat0.str().c_str(), "icon.png", "tile-vertical", asv);
86 dee_model_append(cats, cat1.str().c_str(), "icon.png", "tile-vertical", asv);
87 dee_model_append(cats, "Shared cat", "icon.png", "tile-vertical", asv);
88 }
89
90 virtual ~MockTestLens() {}
91
92 bool force_connected()
93 {
94 return true;
95 }
96
97 bool get_provides_personal_results()
98 {
99 return provides_personal_results_;
100 }
101
102 virtual void DoGlobalSearch(std::string const& search_string)
103 {
104 DeeModel* model = global_results()->model();
105 GVariant** row_buf = g_new(GVariant*, 8);
106
107 row_buf[1] = g_variant_new_string("");
108 row_buf[3] = g_variant_new_string("");
109 row_buf[5] = g_variant_new_string("");
110 row_buf[6] = g_variant_new_string("");
111 row_buf[7] = NULL;
112
113 unsigned int i;
114 unsigned int results_count = search_string.size();
115 if (num_results_ >= 0) results_count = static_cast<unsigned>(num_results_);
116 for (i = 0; i < results_count; i++)
117 {
118 std::ostringstream uri;
119 char res_id(i >= search_string.size() ? '-' : search_string.at(i));
120 uri << "uri+" << res_id << "+" << id();
121 row_buf[0] = g_variant_new_string(uri.str().c_str());
122 row_buf[2] = g_variant_new_uint32(i % 3);
123 unity::glib::String name(g_strdup_printf("%s - %d",
124 results_base_name_.empty() ?
125 search_string.c_str() : results_base_name_.c_str(),
126 i));
127 row_buf[4] = g_variant_new_string(name);
128
129 dee_model_append_row(model, row_buf);
130 }
131
132 g_free(row_buf);
133 }
134
135 void GlobalSearch(std::string const& search_string,
136 SearchFinishedCallback const& cb)
137 {
138 /* Dispatch search async, because that's what it'd normally do */
139 source_manager_.Add(new unity::glib::Idle([this, search_string, cb] ()
140 {
141 DoGlobalSearch(search_string);
142 cb(Lens::Hints(), unity::glib::Error());
143 return false;
144 }));
145 }
146
147 void Search(std::string const& search_string, SearchFinishedCallback const& cb)
148 {
149 /* Dispatch search async, because that's what it'd normally do */
150 source_manager_.Add(new unity::glib::Idle([search_string, cb] ()
151 {
152 cb(Lens::Hints(), unity::glib::Error());
153 return false;
154 }));
155 }
156
157 void Activate(std::string const& uri)
158 {
159
160 }
161
162 void Preview(std::string const& uri)
163 {
164
165 }
166
167 void SetResultsBaseName(std::string const& name)
168 {
169 results_base_name_ = name;
170 }
171
172 void SetNumResults(int count)
173 {
174 num_results_ = count;
175 }
176
177 void SetProvidesPersonalResults(bool value)
178 {
179 provides_personal_results_ = value;
180 }
181
182private:
183 std::string results_base_name_;
184 int num_results_;
185 bool provides_personal_results_;
186 unity::glib::SourceManager source_manager_;
187};
188
189/*
190 * Mock Lenses class
191 */
192class MockTestLenses : public unity::dash::Lenses
193{
194public:
195 typedef std::shared_ptr<MockTestLenses> Ptr;
196
197 MockTestLenses()
198 {
199 count.SetGetterFunction(sigc::mem_fun(&list_, &unity::dash::Lenses::LensList::size));
200 }
201
202 virtual ~MockTestLenses() {}
203
204 unity::dash::Lenses::LensList GetLenses() const
205 {
206 return list_;
207 }
208
209 unity::dash::Lens::Ptr GetLens(std::string const& lens_id) const
210 {
211 for (auto lens : list_)
212 {
213 if (lens->id() == lens_id)
214 return lens;
215 }
216 return unity::dash::Lens::Ptr();
217 }
218
219 unity::dash::Lens::Ptr GetLensAtIndex(std::size_t index) const
220 {
221 return list_.at(index);
222 }
223
224 unity::dash::Lens::Ptr GetLensForShortcut(std::string const& lens_shortcut) const override
225 {
226 return unity::dash::Lens::Ptr();
227 }
228
229
230protected:
231 unity::dash::Lenses::LensList list_;
232};
233
234class TwoMockTestLenses : public MockTestLenses
235{
236public:
237 TwoMockTestLenses()
238 : lens_1_(new MockTestLens("first.lens", "First Lens", "The very first lens", "First search hint"))
239 , lens_2_(new MockTestLens("second.lens", "Second Lens", "The second lens", "Second search hint"))
240 {
241 list_.push_back(lens_1_);
242 list_.push_back(lens_2_);
243 }
244
245private:
246 unity::dash::Lens::Ptr lens_1_;
247 unity::dash::Lens::Ptr lens_2_;
248};
249
250class ThreeMockTestLenses : public MockTestLenses
251{
252public:
253 ThreeMockTestLenses()
254 : lens_1_(new MockTestLens("first.lens", "First Lens", "The very first lens", "First search hint"))
255 , lens_2_(new MockTestLens("second.lens", "Second Lens", "The second lens", "Second search hint"))
256 , lens_3_(new MockTestLens("applications.lens", "Applications", "The applications lens", "Search applications"))
257 {
258 list_.push_back(lens_1_);
259 list_.push_back(lens_2_);
260 list_.push_back(lens_3_);
261 }
262
263private:
264 unity::dash::Lens::Ptr lens_1_;
265 unity::dash::Lens::Ptr lens_2_;
266 unity::dash::Lens::Ptr lens_3_;
267};
268
269}
270
271#endif
0272
=== added file 'tests/test_dash_view.cpp'
--- tests/test_dash_view.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_dash_view.cpp 2013-03-12 22:36:20 +0000
@@ -0,0 +1,67 @@
1/*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
17 */
18
19#include <gmock/gmock.h>
20
21#include <UnityCore/Lenses.h>
22
23#include "ApplicationStarter.h"
24#include "DashView.h"
25#include "unity-shared/DashStyle.h"
26#include "unity-shared/PanelStyle.h"
27#include "unity-shared/UnitySettings.h"
28
29#include "mock-lenses.h"
30
31using namespace unity::dash;
32using namespace testing;
33
34namespace {
35
36struct MockApplicationStarter : public unity::ApplicationStarter {
37 typedef std::shared_ptr<MockApplicationStarter> Ptr;
38 MOCK_METHOD2(Launch, bool(std::string const&, Time));
39};
40
41
42struct TestDashView : public testing::Test {
43 TestDashView()
44 : lenses_(std::make_shared<testmocks::ThreeMockTestLenses>())
45 , application_starter_(std::make_shared<MockApplicationStarter>())
46 , dash_view_(new DashView(lenses_, application_starter_))
47 {}
48
49 unity::Settings unity_settings_;
50 Style dash_style;
51 unity::panel::Style panel_style;
52 Lenses::Ptr lenses_;
53 MockApplicationStarter::Ptr application_starter_;
54 nux::ObjectPtr<DashView> dash_view_;
55};
56
57
58TEST_F(TestDashView, LensActivatedSignal)
59{
60 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
61 lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:application://uri", NOT_HANDLED, Lens::Hints());
62
63 EXPECT_CALL(*application_starter_, Launch("uri", _)).Times(1);
64 lenses_->GetLensAtIndex(0)->activated.emit("0xaabbcc:unity-runner://uri", NOT_HANDLED, Lens::Hints());
65}
66
67}
068
=== modified file 'tests/test_home_lens.cpp'
--- tests/test_home_lens.cpp 2012-11-14 08:57:56 +0000
+++ tests/test_home_lens.cpp 2013-03-12 22:36:20 +0000
@@ -1,7 +1,5 @@
1#include <gtest/gtest.h>1#include <gtest/gtest.h>
2#include <glib-object.h>2#include <glib-object.h>
3#include <dee.h>
4#include <string>
5#include <iostream>3#include <iostream>
6#include <stdexcept>4#include <stdexcept>
7#include <map>5#include <map>
@@ -9,254 +7,21 @@
9#include <sigc++/signal.h>7#include <sigc++/signal.h>
10#include <sigc++/trackable.h>8#include <sigc++/trackable.h>
119
12#include <UnityCore/GLibWrapper.h>10
13#include <UnityCore/GLibSource.h>
14#include <UnityCore/Variant.h>11#include <UnityCore/Variant.h>
15#include <UnityCore/HomeLens.h>12#include <UnityCore/HomeLens.h>
16#include <UnityCore/Lens.h>
17#include <UnityCore/Lenses.h>
1813
19#include "test_utils.h"14#include "test_utils.h"
15#include "mock-lenses.h"
2016
21using namespace std;17using namespace std;
22using namespace unity;18using namespace unity;
23using namespace unity::dash;19using namespace unity::dash;
20using namespace testmocks;
2421
25namespace22namespace
26{23{
2724
28/*
29 * FORWARDS
30 */
31
32class StaticTestLens;
33
34/*
35 * Mock Lens instance that does not use DBus. The default search does like this:
36 * For input "bar" output:
37 *
38 * i = 0
39 * for letter in "bar":
40 * put result row [ "uri+$letter+$lens_id", "icon+$letter+$lens_id", i % 3, "mime+$letter+$lens_id", ...]
41 * i++
42 *
43 * The mock lens has 3 categories:
44 *
45 * 0) "cat0+$lens_id"
46 * 1) "cat1+$lens_id"
47 * 2) "Shared cat"
48 */
49class StaticTestLens : public Lens
50{
51public:
52 typedef std::shared_ptr<StaticTestLens> Ptr;
53
54 StaticTestLens(string const& id, string const& name, string const& description, string const& search_hint)
55 : Lens(id, "", "", name, "lens-icon.png",
56 description, search_hint, true, "",
57 ModelType::LOCAL)
58 , num_results_(-1)
59 , provides_personal_results_(true)
60 {
61 search_in_global(true);
62 connected.SetGetterFunction(sigc::mem_fun(this, &StaticTestLens::force_connected));
63 provides_personal_content.SetGetterFunction(sigc::mem_fun(this, &StaticTestLens::get_provides_personal_results));
64
65 DeeModel* cats = categories()->model();
66 DeeModel* results = global_results()->model();
67 DeeModel* flters = filters()->model();
68
69 // Set model schemas
70 dee_model_set_schema(cats, "s", "s", "s", "a{sv}", NULL);
71 dee_model_set_schema(results, "s", "s", "u", "s", "s", "s", "s", NULL);
72 dee_model_set_schema(flters, "s", "s", "s", "s", "a{sv}", "b", "b", "b", NULL);
73
74 // Populate categories model
75 ostringstream cat0, cat1;
76 cat0 << "cat0+" << id;
77 cat1 << "cat1+" << id;
78 GVariantBuilder b;
79 g_variant_builder_init(&b, G_VARIANT_TYPE_VARDICT);
80 GVariant *asv = g_variant_builder_end(&b);
81
82 dee_model_append(cats, cat0.str().c_str(), "icon.png", "tile-vertical", asv);
83 dee_model_append(cats, cat1.str().c_str(), "icon.png", "tile-vertical", asv);
84 dee_model_append(cats, "Shared cat", "icon.png", "tile-vertical", asv);
85 }
86
87 virtual ~StaticTestLens() {}
88
89 bool force_connected()
90 {
91 return true;
92 }
93
94 bool get_provides_personal_results()
95 {
96 return provides_personal_results_;
97 }
98
99 virtual void DoGlobalSearch(string const& search_string)
100 {
101 DeeModel* model = global_results()->model();
102 GVariant** row_buf = g_new(GVariant*, 8);
103
104 row_buf[1] = g_variant_new_string("");
105 row_buf[3] = g_variant_new_string("");
106 row_buf[5] = g_variant_new_string("");
107 row_buf[6] = g_variant_new_string("");
108 row_buf[7] = NULL;
109
110 unsigned int i;
111 unsigned int results_count = search_string.size();
112 if (num_results_ >= 0) results_count = static_cast<unsigned>(num_results_);
113 for (i = 0; i < results_count; i++)
114 {
115 ostringstream uri;
116 char res_id(i >= search_string.size() ? '-' : search_string.at(i));
117 uri << "uri+" << res_id << "+" << id();
118 row_buf[0] = g_variant_new_string(uri.str().c_str());
119 row_buf[2] = g_variant_new_uint32(i % 3);
120 glib::String name(g_strdup_printf("%s - %d",
121 results_base_name_.empty() ?
122 search_string.c_str() : results_base_name_.c_str(),
123 i));
124 row_buf[4] = g_variant_new_string(name);
125
126 dee_model_append_row(model, row_buf);
127 }
128
129 g_free(row_buf);
130 }
131
132 void GlobalSearch(string const& search_string,
133 SearchFinishedCallback const& cb)
134 {
135 /* Dispatch search async, because that's what it'd normally do */
136 source_manager_.Add(new glib::Idle([this, search_string, cb] ()
137 {
138 DoGlobalSearch(search_string);
139 cb(Lens::Hints(), glib::Error());
140 return false;
141 }));
142 }
143
144 void Search(string const& search_string, SearchFinishedCallback const& cb)
145 {
146 /* Dispatch search async, because that's what it'd normally do */
147 source_manager_.Add(new glib::Idle([search_string, cb] ()
148 {
149 cb(Lens::Hints(), glib::Error());
150 return false;
151 }));
152 }
153
154 void Activate(string const& uri)
155 {
156
157 }
158
159 void Preview(string const& uri)
160 {
161
162 }
163
164 void SetResultsBaseName(string const& name)
165 {
166 results_base_name_ = name;
167 }
168
169 void SetNumResults(int count)
170 {
171 num_results_ = count;
172 }
173
174 void SetProvidesPersonalResults(bool value)
175 {
176 provides_personal_results_ = value;
177 }
178
179private:
180 string results_base_name_;
181 int num_results_;
182 bool provides_personal_results_;
183 glib::SourceManager source_manager_;
184};
185
186/*
187 * Mock Lenses class
188 */
189class StaticTestLenses : public Lenses
190{
191public:
192 typedef std::shared_ptr<StaticTestLenses> Ptr;
193
194 StaticTestLenses()
195 {
196 count.SetGetterFunction(sigc::mem_fun(&list_, &Lenses::LensList::size));
197 }
198
199 virtual ~StaticTestLenses() {}
200
201 Lenses::LensList GetLenses() const
202 {
203 return list_;
204 }
205
206 Lens::Ptr GetLens(std::string const& lens_id) const
207 {
208 for (auto lens : list_)
209 {
210 if (lens->id() == lens_id)
211 return lens;
212 }
213 return Lens::Ptr();
214 }
215
216 Lens::Ptr GetLensAtIndex(std::size_t index) const
217 {
218 return list_.at(index);
219 }
220
221protected:
222 Lenses::LensList list_;
223};
224
225class TwoStaticTestLenses : public StaticTestLenses
226{
227public:
228 TwoStaticTestLenses()
229 : lens_1_(new StaticTestLens("first.lens", "First Lens", "The very first lens", "First search hint"))
230 , lens_2_(new StaticTestLens("second.lens", "Second Lens", "The second lens", "Second search hint"))
231 {
232 list_.push_back(lens_1_);
233 list_.push_back(lens_2_);
234 }
235
236private:
237 Lens::Ptr lens_1_;
238 Lens::Ptr lens_2_;
239};
240
241class ThreeStaticTestLenses : public StaticTestLenses
242{
243public:
244 ThreeStaticTestLenses()
245 : lens_1_(new StaticTestLens("first.lens", "First Lens", "The very first lens", "First search hint"))
246 , lens_2_(new StaticTestLens("second.lens", "Second Lens", "The second lens", "Second search hint"))
247 , lens_3_(new StaticTestLens("applications.lens", "Applications", "The applications lens", "Search applications"))
248 {
249 list_.push_back(lens_1_);
250 list_.push_back(lens_2_);
251 list_.push_back(lens_3_);
252 }
253
254private:
255 Lens::Ptr lens_1_;
256 Lens::Ptr lens_2_;
257 Lens::Ptr lens_3_;
258};
259
260TEST(TestHomeLens, TestConstruction)25TEST(TestHomeLens, TestConstruction)
261{26{
262 HomeLens home_lens_("name", "description", "searchhint");27 HomeLens home_lens_("name", "description", "searchhint");
@@ -286,7 +51,7 @@
286TEST(TestHomeLens, TestTwoStaticLenses)51TEST(TestHomeLens, TestTwoStaticLenses)
287{52{
288 HomeLens home_lens_("name", "description", "searchhint");53 HomeLens home_lens_("name", "description", "searchhint");
289 TwoStaticTestLenses lenses_;54 std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>();
29055
291 home_lens_.AddLenses(lenses_);56 home_lens_.AddLenses(lenses_);
29257
@@ -312,7 +77,7 @@
312{77{
313 HomeLens home_lens_("name", "description", "searchhint",78 HomeLens home_lens_("name", "description", "searchhint",
314 HomeLens::MergeMode::DISPLAY_NAME);79 HomeLens::MergeMode::DISPLAY_NAME);
315 TwoStaticTestLenses lenses_;80 std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>();
316 DeeModel* cats = home_lens_.categories()->model();81 DeeModel* cats = home_lens_.categories()->model();
317 DeeModelIter* iter;82 DeeModelIter* iter;
318 unsigned int cat0_first = 0,83 unsigned int cat0_first = 0,
@@ -347,7 +112,7 @@
347{112{
348 HomeLens home_lens_("name", "description", "searchhint",113 HomeLens home_lens_("name", "description", "searchhint",
349 HomeLens::MergeMode::OWNER_LENS);114 HomeLens::MergeMode::OWNER_LENS);
350 TwoStaticTestLenses lenses_;115 std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>();
351 DeeModel* cats = home_lens_.categories()->model();116 DeeModel* cats = home_lens_.categories()->model();
352 DeeModelIter* iter;117 DeeModelIter* iter;
353 const unsigned int NAME_COLUMN = 0;118 const unsigned int NAME_COLUMN = 0;
@@ -371,7 +136,7 @@
371TEST(TestHomeLens, TestIgnoreFilters)136TEST(TestHomeLens, TestIgnoreFilters)
372{137{
373 HomeLens home_lens_("name", "description", "searchhint");138 HomeLens home_lens_("name", "description", "searchhint");
374 TwoStaticTestLenses lenses_;139 std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>();
375 DeeModel* filters = home_lens_.filters()->model();140 DeeModel* filters = home_lens_.filters()->model();
376141
377 EXPECT_EQ(dee_model_get_n_rows(filters), 0);142 EXPECT_EQ(dee_model_get_n_rows(filters), 0);
@@ -381,7 +146,7 @@
381{146{
382 HomeLens home_lens_("name", "description", "searchhint",147 HomeLens home_lens_("name", "description", "searchhint",
383 HomeLens::MergeMode::DISPLAY_NAME);148 HomeLens::MergeMode::DISPLAY_NAME);
384 TwoStaticTestLenses lenses_;149 std::shared_ptr<Lenses> lenses_ = std::make_shared<TwoMockTestLenses>();
385 DeeModel* results = home_lens_.results()->model();150 DeeModel* results = home_lens_.results()->model();
386 DeeModel* cats = home_lens_.categories()->model();151 DeeModel* cats = home_lens_.categories()->model();
387 DeeModel* filters = home_lens_.filters()->model();152 DeeModel* filters = home_lens_.filters()->model();
@@ -440,7 +205,7 @@
440{205{
441 HomeLens home_lens_("name", "description", "searchhint",206 HomeLens home_lens_("name", "description", "searchhint",
442 HomeLens::MergeMode::OWNER_LENS);207 HomeLens::MergeMode::OWNER_LENS);
443 ThreeStaticTestLenses lenses_;208 std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>();
444 DeeModel* results = home_lens_.results()->model();209 DeeModel* results = home_lens_.results()->model();
445 DeeModel* cats = home_lens_.categories()->model();210 DeeModel* cats = home_lens_.categories()->model();
446 DeeModel* filters = home_lens_.filters()->model();211 DeeModel* filters = home_lens_.filters()->model();
@@ -491,14 +256,14 @@
491{256{
492 HomeLens home_lens_("name", "description", "searchhint",257 HomeLens home_lens_("name", "description", "searchhint",
493 HomeLens::MergeMode::OWNER_LENS);258 HomeLens::MergeMode::OWNER_LENS);
494 ThreeStaticTestLenses lenses_;259 std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>();
495 // the lens is added as third, so must have cat == 2260 // the lens is added as third, so must have cat == 2
496 unsigned int apps_lens_cat = 2;261 unsigned int apps_lens_cat = 2;
497262
498 home_lens_.AddLenses(lenses_);263 home_lens_.AddLenses(lenses_);
499 Lens::Ptr apps_lens = lenses_.GetLens("applications.lens");264 Lens::Ptr apps_lens = lenses_->GetLens("applications.lens");
500265
501 auto static_lens = dynamic_pointer_cast<StaticTestLens>(apps_lens);266 auto static_lens = dynamic_pointer_cast<MockTestLens>(apps_lens);
502 static_lens->SetNumResults(1);267 static_lens->SetNumResults(1);
503268
504 bool order_changed = false;269 bool order_changed = false;
@@ -535,14 +300,14 @@
535{300{
536 HomeLens home_lens_("name", "description", "searchhint",301 HomeLens home_lens_("name", "description", "searchhint",
537 HomeLens::MergeMode::OWNER_LENS);302 HomeLens::MergeMode::OWNER_LENS);
538 ThreeStaticTestLenses lenses_;303 std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>();
539 // the lens is added as third, so must have cat == 2304 // the lens is added as third, so must have cat == 2
540 unsigned int apps_lens_cat = 2;305 unsigned int apps_lens_cat = 2;
541306
542 home_lens_.AddLenses(lenses_);307 home_lens_.AddLenses(lenses_);
543 Lens::Ptr apps_lens = lenses_.GetLens("applications.lens");308 Lens::Ptr apps_lens = lenses_->GetLens("applications.lens");
544309
545 auto static_lens = dynamic_pointer_cast<StaticTestLens>(apps_lens);310 auto static_lens = dynamic_pointer_cast<MockTestLens>(apps_lens);
546 static_lens->SetResultsBaseName("noapes");311 static_lens->SetResultsBaseName("noapes");
547 static_lens->SetNumResults(1);312 static_lens->SetNumResults(1);
548313
@@ -579,7 +344,7 @@
579{344{
580 HomeLens home_lens_("name", "description", "searchhint",345 HomeLens home_lens_("name", "description", "searchhint",
581 HomeLens::MergeMode::OWNER_LENS);346 HomeLens::MergeMode::OWNER_LENS);
582 ThreeStaticTestLenses lenses_;347 std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>();
583 unsigned int lens1_cat = 0;348 unsigned int lens1_cat = 0;
584 unsigned int lens2_cat = 1;349 unsigned int lens2_cat = 1;
585 // the lens is added as third, so must have cat == 2350 // the lens is added as third, so must have cat == 2
@@ -587,14 +352,14 @@
587352
588 home_lens_.AddLenses(lenses_);353 home_lens_.AddLenses(lenses_);
589354
590 Lens::Ptr lens = lenses_.GetLensAtIndex(2);355 Lens::Ptr lens = lenses_->GetLensAtIndex(2);
591 auto static_lens = dynamic_pointer_cast<StaticTestLens>(lens);356 auto static_lens = dynamic_pointer_cast<MockTestLens>(lens);
592 static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens357 static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens
593 static_lens->SetNumResults(2);358 static_lens->SetNumResults(2);
594359
595 static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(0));360 static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(0));
596 static_lens->SetNumResults(1);361 static_lens->SetNumResults(1);
597 static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(1));362 static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(1));
598 static_lens->SetNumResults(3);363 static_lens->SetNumResults(3);
599364
600 bool order_changed = false;365 bool order_changed = false;
@@ -638,7 +403,7 @@
638{403{
639 HomeLens home_lens_("name", "description", "searchhint",404 HomeLens home_lens_("name", "description", "searchhint",
640 HomeLens::MergeMode::OWNER_LENS);405 HomeLens::MergeMode::OWNER_LENS);
641 ThreeStaticTestLenses lenses_;406 std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>();
642 unsigned int lens1_cat = 0;407 unsigned int lens1_cat = 0;
643 unsigned int lens2_cat = 1;408 unsigned int lens2_cat = 1;
644 // the lens is added as third, so must have cat == 2409 // the lens is added as third, so must have cat == 2
@@ -652,14 +417,14 @@
652 * lens3 -> 2 results (apps.lens)417 * lens3 -> 2 results (apps.lens)
653 */418 */
654419
655 Lens::Ptr lens = lenses_.GetLensAtIndex(2);420 Lens::Ptr lens = lenses_->GetLensAtIndex(2);
656 auto static_lens = dynamic_pointer_cast<StaticTestLens>(lens);421 auto static_lens = dynamic_pointer_cast<MockTestLens>(lens);
657 static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens422 static_lens->SetResultsBaseName("noapes"); // no exact match in apps lens
658 static_lens->SetNumResults(2);423 static_lens->SetNumResults(2);
659424
660 static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(0));425 static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(0));
661 static_lens->SetNumResults(1);426 static_lens->SetNumResults(1);
662 static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(1));427 static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(1));
663 static_lens->SetNumResults(3);428 static_lens->SetNumResults(3);
664 static_lens->SetProvidesPersonalResults(false);429 static_lens->SetProvidesPersonalResults(false);
665430
@@ -698,7 +463,7 @@
698{463{
699 HomeLens home_lens_("name", "description", "searchhint",464 HomeLens home_lens_("name", "description", "searchhint",
700 HomeLens::MergeMode::OWNER_LENS);465 HomeLens::MergeMode::OWNER_LENS);
701 ThreeStaticTestLenses lenses_;466 std::shared_ptr<Lenses> lenses_ = std::make_shared<ThreeMockTestLenses>();
702 unsigned int lens1_cat = 0;467 unsigned int lens1_cat = 0;
703 unsigned int lens2_cat = 1;468 unsigned int lens2_cat = 1;
704 // the lens is added as third, so must have cat == 2469 // the lens is added as third, so must have cat == 2
@@ -712,13 +477,13 @@
712 * lens3 -> 0 results (apps.lens)477 * lens3 -> 0 results (apps.lens)
713 */478 */
714479
715 Lens::Ptr lens = lenses_.GetLensAtIndex(2);480 Lens::Ptr lens = lenses_->GetLensAtIndex(2);
716 auto static_lens = dynamic_pointer_cast<StaticTestLens>(lens);481 auto static_lens = dynamic_pointer_cast<MockTestLens>(lens);
717 static_lens->SetNumResults(0);482 static_lens->SetNumResults(0);
718483
719 static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(0));484 static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(0));
720 static_lens->SetNumResults(1);485 static_lens->SetNumResults(1);
721 static_lens = dynamic_pointer_cast<StaticTestLens>(lenses_.GetLensAtIndex(1));486 static_lens = dynamic_pointer_cast<MockTestLens>(lenses_->GetLensAtIndex(1));
722 static_lens->SetNumResults(3);487 static_lens->SetNumResults(3);
723 static_lens->SetProvidesPersonalResults(false);488 static_lens->SetProvidesPersonalResults(false);
724489