Merge lp:~charlesk/indicator-location/use-properties-cpp into lp:indicator-location/16.04

Proposed by Charles Kerr
Status: Merged
Approved by: Charles Kerr
Approved revision: 161
Merged at revision: 152
Proposed branch: lp:~charlesk/indicator-location/use-properties-cpp
Merge into: lp:indicator-location/16.04
Prerequisite: lp:~charlesk/indicator-location/lp-1535353-remove-here-tos
Diff against target: 764 lines (+141/-190)
13 files modified
CMakeLists.txt (+2/-1)
src/controller.cc (+0/-46)
src/controller.h (+8/-34)
src/location-service-controller.cc (+26/-33)
src/location-service-controller.h (+6/-6)
src/phone.cc (+44/-27)
src/phone.h (+7/-4)
src/service.cc (+12/-12)
src/service.h (+1/-1)
tests/controller-mock.h (+8/-12)
tests/gtest-dbus-fixture.h (+3/-3)
tests/gtest-dbus-indicator-fixture.h (+5/-5)
tests/phone-test.cc (+19/-6)
To merge this branch: bzr merge lp:~charlesk/indicator-location/use-properties-cpp
Reviewer Review Type Date Requested Status
Xavi Garcia Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+283676@code.launchpad.net

Commit message

Use core::Property<X> fields to notify the indicator when location settings change

Description of the change

A minor cleanup branch of something that's irritated me for awhile in indicator-location, the use of Java-style Listener interface classes for observer/observable to know when CUALC's location settings change.

This MP replaces the Listener interfaces with use of core::Property<X> objects to signal when a value changes.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Xavi Garcia (xavi-garcia-mena) wrote :

LGTM, thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2015-04-16 00:44:22 +0000
+++ CMakeLists.txt 2016-01-22 18:23:42 +0000
@@ -35,7 +35,8 @@
35 ubuntu-app-launch-235 ubuntu-app-launch-2
36 url-dispatcher-136 url-dispatcher-1
37 gio-unix-2.0>=2.3637 gio-unix-2.0>=2.36
38 glib-2.0>=2.36)38 glib-2.0>=2.36
39 properties-cpp>=0.0.1)
39include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS})40include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS})
4041
41##42##
4243
=== removed file 'src/controller.cc'
--- src/controller.cc 2013-08-25 20:31:26 +0000
+++ src/controller.cc 1970-01-01 00:00:00 +0000
@@ -1,46 +0,0 @@
1/*
2 * Copyright 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 as published by
6 * the Free Software Foundation; version 3.
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 Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Charles Kerr <charles.kerr@canonical.com>
18 */
19
20#include "controller.h"
21
22void
23Controller :: add_listener (ControllerListener * l)
24{
25 listeners.insert (l);
26}
27
28void
29Controller :: remove_listener (ControllerListener * l)
30{
31 listeners.erase (l);
32}
33
34void
35Controller :: notify_gps_enabled (bool enabled)
36{
37 for (auto it : listeners)
38 it->on_gps_enabled_changed (enabled);
39}
40
41void
42Controller :: notify_location_service_enabled (bool enabled)
43{
44 for (auto it : listeners)
45 it->on_location_service_enabled_changed (enabled);
46}
470
=== modified file 'src/controller.h'
--- src/controller.h 2015-04-15 13:42:24 +0000
+++ src/controller.h 2016-01-22 18:23:42 +0000
@@ -20,48 +20,22 @@
20#ifndef __INDICATOR_LOCATION_CONTROLLER_H__20#ifndef __INDICATOR_LOCATION_CONTROLLER_H__
21#define __INDICATOR_LOCATION_CONTROLLER_H__21#define __INDICATOR_LOCATION_CONTROLLER_H__
2222
23#include <set>
24
25#include <core/property.h>23#include <core/property.h>
2624
27class ControllerListener
28{
29 public:
30 ControllerListener() {}
31 virtual ~ControllerListener() {}
32
33 public:
34 virtual void on_gps_enabled_changed (bool is_enabled) = 0;
35 virtual void on_location_service_enabled_changed (bool is_enabled) = 0;
36};
37
38class Controller25class Controller
39{26{
40 public:27public:
4128 Controller();
42 Controller () {}29 virtual ~Controller();
43 virtual ~Controller() {}
44
45 void add_listener (ControllerListener *);
46 void remove_listener (ControllerListener *);
4730
48 /// True iff we've gotten status info from the location service31 /// True iff we've gotten status info from the location service
49 virtual const core::Property<bool>& is_valid() const =0;32 virtual const core::Property<bool>& is_valid() const =0;
5033
51 virtual bool is_gps_enabled () const = 0;34 virtual const core::Property<bool>& gps_enabled() const =0;
52 virtual bool is_location_service_enabled () const = 0;35 virtual const core::Property<bool>& location_service_enabled() const =0;
5336
54 virtual void set_gps_enabled (bool enabled) = 0;37 virtual void set_gps_enabled (bool enabled) =0;
55 virtual void set_location_service_enabled (bool enabled) = 0;38 virtual void set_location_service_enabled (bool enabled) =0;
56
57 private:
58
59 std::set<ControllerListener*> listeners;
60
61 protected:
62
63 void notify_gps_enabled (bool);
64 void notify_location_service_enabled (bool);
65};39};
6640
67#endif // __INDICATOR_LOCATION_CONTROLLER_H__41#endif // __INDICATOR_LOCATION_CONTROLLER_H__
6842
=== modified file 'src/location-service-controller.cc'
--- src/location-service-controller.cc 2015-04-17 16:44:53 +0000
+++ src/location-service-controller.cc 2016-01-22 18:23:42 +0000
@@ -31,21 +31,13 @@
31{31{
32public:32public:
3333
34 Impl(LocationServiceController& owner)34 Impl()
35 {35 {
36 m_cancellable.reset(g_cancellable_new(), [](GCancellable* c) {36 m_cancellable.reset(g_cancellable_new(), [](GCancellable* c) {
37 g_cancellable_cancel(c);37 g_cancellable_cancel(c);
38 g_object_unref(c);38 g_object_unref(c);
39 });39 });
4040
41 m_gps_enabled.changed().connect([&owner](bool b){
42 owner.notify_gps_enabled(b);
43 });
44
45 m_loc_enabled.changed().connect([&owner](bool b){
46 owner.notify_location_service_enabled(b);
47 });
48
49 g_bus_get(G_BUS_TYPE_SYSTEM,41 g_bus_get(G_BUS_TYPE_SYSTEM,
50 m_cancellable.get(),42 m_cancellable.get(),
51 on_system_bus_ready,43 on_system_bus_ready,
@@ -59,14 +51,14 @@
59 return m_is_valid;51 return m_is_valid;
60 }52 }
6153
62 bool is_gps_enabled() const54 const core::Property<bool>& gps_enabled() const
63 {55 {
64 return m_gps_enabled.get();56 return m_gps_enabled;
65 }57 }
6658
67 bool is_location_service_enabled() const59 const core::Property<bool>& location_service_enabled() const
68 {60 {
69 return m_loc_enabled.get();61 return m_loc_enabled;
70 }62 }
7163
72 void set_gps_enabled(bool enabled)64 void set_gps_enabled(bool enabled)
@@ -108,9 +100,9 @@
108 nullptr);100 nullptr);
109101
110 // manage the name_tag's lifespan102 // manage the name_tag's lifespan
111 self->m_name_tag.reset(new guint{name_tag}, [](guint* name_tag){103 self->m_name_tag.reset(new guint{name_tag}, [](guint* tag){
112 g_bus_unwatch_name(*name_tag);104 g_bus_unwatch_name(*tag);
113 delete name_tag;105 delete tag;
114 });106 });
115 }107 }
116 else if (error != nullptr)108 else if (error != nullptr)
@@ -122,9 +114,9 @@
122 }114 }
123115
124 static void on_name_appeared(GDBusConnection * system_bus,116 static void on_name_appeared(GDBusConnection * system_bus,
125 const gchar * bus_name,117 const gchar * /*bus_name*/,
126 const gchar * name_owner,118 const gchar * name_owner,
127 gpointer gself)119 gpointer gself)
128 {120 {
129 auto self = static_cast<Impl*>(gself);121 auto self = static_cast<Impl*>(gself);
130122
@@ -275,7 +267,7 @@
275 {267 {
276 bool success, value;268 bool success, value;
277 std::tie(success, value) = get_bool_reply_from_call(source_object, res);269 std::tie(success, value) = get_bool_reply_from_call(source_object, res);
278 g_debug("service loc reply: success %d value %d", (int)success, (int)value);270 g_debug("service loc reply: success %d value %d", int(success), int(value));
279 if (success)271 if (success)
280 static_cast<Impl*>(gself)->m_loc_enabled.set(value);272 static_cast<Impl*>(gself)->m_loc_enabled.set(value);
281 }273 }
@@ -286,7 +278,7 @@
286 {278 {
287 bool success, value;279 bool success, value;
288 std::tie(success, value) = get_bool_reply_from_call(source_object, res);280 std::tie(success, value) = get_bool_reply_from_call(source_object, res);
289 g_debug("service gps reply: success %d value %d", (int)success, (int)value);281 g_debug("service gps reply: success %d value %d", int(success), int(value));
290 if (success)282 if (success)
291 static_cast<Impl*>(gself)->m_gps_enabled.set(value);283 static_cast<Impl*>(gself)->m_gps_enabled.set(value);
292 }284 }
@@ -319,7 +311,7 @@
319311
320 static void check_method_call_reply(GObject *connection,312 static void check_method_call_reply(GObject *connection,
321 GAsyncResult *res,313 GAsyncResult *res,
322 gpointer gself)314 gpointer /*gself*/)
323 {315 {
324 GError * error;316 GError * error;
325 GVariant * v;317 GVariant * v;
@@ -368,7 +360,7 @@
368***/360***/
369361
370LocationServiceController::LocationServiceController():362LocationServiceController::LocationServiceController():
371 impl{new Impl{*this}}363 impl{new Impl{}}
372{364{
373}365}
374366
@@ -382,17 +374,18 @@
382 return impl->is_valid();374 return impl->is_valid();
383}375}
384376
385bool377const core::Property<bool>&
386LocationServiceController::is_gps_enabled() const378LocationServiceController::gps_enabled() const
387{379{
388 return impl->is_gps_enabled();380 return impl->gps_enabled();
389}381}
390382
391bool383const core::Property<bool>&
392LocationServiceController::is_location_service_enabled() const384LocationServiceController::location_service_enabled() const
393{385{
394 return impl->is_location_service_enabled();386 return impl->location_service_enabled();
395}387}
388
396void389void
397LocationServiceController::set_gps_enabled(bool enabled)390LocationServiceController::set_gps_enabled(bool enabled)
398{391{
399392
=== modified file 'src/location-service-controller.h'
--- src/location-service-controller.h 2015-04-17 16:51:19 +0000
+++ src/location-service-controller.h 2016-01-22 18:23:42 +0000
@@ -20,26 +20,26 @@
20#ifndef INDICATOR_LOCATION_CONTROLLER_LOCATION_SERVICE20#ifndef INDICATOR_LOCATION_CONTROLLER_LOCATION_SERVICE
21#define INDICATOR_LOCATION_CONTROLLER_LOCATION_SERVICE21#define INDICATOR_LOCATION_CONTROLLER_LOCATION_SERVICE
2222
23#include "controller.h"23#include "controller.h" // parent class
2424
25#include <memory> // std::unique_ptr25#include <memory> // std::unique_ptr
2626
27class LocationServiceController: public Controller27class LocationServiceController: public Controller
28{28{
29 public:29public:
30 LocationServiceController();30 LocationServiceController();
31 virtual ~LocationServiceController();31 virtual ~LocationServiceController();
3232
33 virtual const core::Property<bool>& is_valid() const override;33 const core::Property<bool>& is_valid() const override;
34 bool is_gps_enabled () const override;34 const core::Property<bool>& gps_enabled() const override;
35 bool is_location_service_enabled () const override;35 const core::Property<bool>& location_service_enabled() const override;
36 void set_gps_enabled (bool enabled) override;36 void set_gps_enabled (bool enabled) override;
37 void set_location_service_enabled (bool enabled) override;37 void set_location_service_enabled (bool enabled) override;
3838
39 LocationServiceController(const LocationServiceController&) =delete;39 LocationServiceController(const LocationServiceController&) =delete;
40 LocationServiceController& operator=(const LocationServiceController&) =delete;40 LocationServiceController& operator=(const LocationServiceController&) =delete;
4141
42 private:42private:
43 friend class Impl;43 friend class Impl;
44 class Impl;44 class Impl;
45 std::unique_ptr<Impl> impl;45 std::unique_ptr<Impl> impl;
4646
=== modified file 'src/phone.cc'
--- src/phone.cc 2016-01-22 18:23:42 +0000
+++ src/phone.cc 2016-01-22 18:23:42 +0000
@@ -38,7 +38,29 @@
38 action_group (action_group_)38 action_group (action_group_)
39{39{
40 create_menu ();40 create_menu ();
41 controller->add_listener (this);41
42 auto on_gps = [this](bool enabled){
43 update_gps_enabled_action();
44 update_header();
45 };
46 controller_connections.push_back(
47 controller->gps_enabled().changed().connect(on_gps)
48 );
49
50 auto on_loc = [this](bool enabled){
51 update_detection_enabled_action();
52 update_header();
53 };
54 controller_connections.push_back(
55 controller->location_service_enabled().changed().connect(on_loc)
56 );
57
58 auto on_valid = [this](bool valid){
59 update_actions_enabled();
60 };
61 controller_connections.push_back(
62 controller->is_valid().changed().connect(on_valid)
63 );
4264
43 /* create the actions & add them to the group */65 /* create the actions & add them to the group */
44 std::array<GSimpleAction*, 4> actions = { create_root_action(),66 std::array<GSimpleAction*, 4> actions = { create_root_action(),
@@ -51,14 +73,11 @@
51 g_object_unref (a);73 g_object_unref (a);
52 }74 }
5375
54 // the profile should track whether the controller is valid or not76 update_actions_enabled();
55 controller->is_valid().changed().connect([this](bool){on_is_valid_changed();});
56 on_is_valid_changed();
57}77}
5878
59Phone :: ~Phone ()79Phone :: ~Phone ()
60{80{
61 controller->remove_listener (this);
62}81}
6382
64/***83/***
@@ -73,7 +92,7 @@
7392
74 // as per "Indicators - RTM Usability Fix" document:93 // as per "Indicators - RTM Usability Fix" document:
75 // visible iff location is enabled94 // visible iff location is enabled
76 return controller->is_location_service_enabled();95 return controller->location_service_enabled().get();
77}96}
7897
79GVariant *98GVariant *
@@ -123,7 +142,7 @@
123}142}
124143
125void144void
126Phone :: on_is_valid_changed()145Phone :: update_actions_enabled()
127{146{
128 const auto map = G_ACTION_MAP(action_group.get());147 const auto map = G_ACTION_MAP(action_group.get());
129 const bool is_valid = controller->is_valid().get();148 const bool is_valid = controller->is_valid().get();
@@ -141,15 +160,7 @@
141GVariant *160GVariant *
142Phone :: action_state_for_location_detection ()161Phone :: action_state_for_location_detection ()
143{162{
144 return g_variant_new_boolean (controller->is_location_service_enabled());163 return g_variant_new_boolean (controller->location_service_enabled().get());
145}
146
147void
148Phone :: on_location_service_enabled_changed (bool is_enabled G_GNUC_UNUSED)
149{
150 GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), LOCATION_ACTION_KEY);
151 g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_location_detection());
152 update_header();
153}164}
154165
155void166void
@@ -177,6 +188,13 @@
177 return action;188 return action;
178}189}
179190
191void
192Phone::update_detection_enabled_action()
193{
194 GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), LOCATION_ACTION_KEY);
195 g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_location_detection());
196}
197
180/***198/***
181****199****
182***/200***/
@@ -184,15 +202,7 @@
184GVariant *202GVariant *
185Phone :: action_state_for_gps_detection ()203Phone :: action_state_for_gps_detection ()
186{204{
187 return g_variant_new_boolean (controller->is_gps_enabled());205 return g_variant_new_boolean (controller->gps_enabled().get());
188}
189
190void
191Phone :: on_gps_enabled_changed (bool is_enabled G_GNUC_UNUSED)
192{
193 GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), GPS_ACTION_KEY);
194 g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_gps_detection());
195 update_header();
196}206}
197207
198void208void
@@ -206,7 +216,7 @@
206}216}
207217
208GSimpleAction *218GSimpleAction *
209Phone :: create_gps_enabled_action ()219Phone :: create_gps_enabled_action()
210{220{
211 GSimpleAction * action;221 GSimpleAction * action;
212222
@@ -220,6 +230,13 @@
220 return action;230 return action;
221}231}
222232
233void
234Phone::update_gps_enabled_action()
235{
236 GAction * action = g_action_map_lookup_action (G_ACTION_MAP(action_group.get()), GPS_ACTION_KEY);
237 g_simple_action_set_state (G_SIMPLE_ACTION(action), action_state_for_gps_detection());
238}
239
223/***240/***
224****241****
225***/242***/
@@ -230,7 +247,7 @@
230{247{
231 void248 void
232 on_uri_dispatched (const gchar * uri,249 on_uri_dispatched (const gchar * uri,
233 gboolean success G_GNUC_UNUSED,250 gboolean success,
234 gpointer user_data G_GNUC_UNUSED)251 gpointer user_data G_GNUC_UNUSED)
235 {252 {
236 if (!success)253 if (!success)
237254
=== modified file 'src/phone.h'
--- src/phone.h 2016-01-22 18:23:42 +0000
+++ src/phone.h 2016-01-22 18:23:42 +0000
@@ -21,13 +21,14 @@
21#define __INDICATOR_LOCATION_PHONE_H__21#define __INDICATOR_LOCATION_PHONE_H__
2222
23#include <memory>23#include <memory>
24#include <vector>
2425
25#include <glib.h>26#include <glib.h>
26#include <gio/gio.h>27#include <gio/gio.h>
2728
28#include "controller.h"29#include "controller.h"
2930
30class Phone: public ControllerListener31class Phone
31{32{
32 public:33 public:
33 Phone (const std::shared_ptr<Controller>& controller,34 Phone (const std::shared_ptr<Controller>& controller,
@@ -37,9 +38,7 @@
3738
38 protected:39 protected:
39 std::shared_ptr<Controller> controller;40 std::shared_ptr<Controller> controller;
40 virtual void on_is_valid_changed();41 std::vector<core::ScopedConnection> controller_connections;
41 virtual void on_gps_enabled_changed (bool is_enabled);
42 virtual void on_location_service_enabled_changed (bool is_enabled);
4342
44 private:43 private:
45 std::shared_ptr<GMenu> menu;44 std::shared_ptr<GMenu> menu;
@@ -55,15 +54,19 @@
55 GVariant * action_state_for_root () const;54 GVariant * action_state_for_root () const;
56 GSimpleAction * create_root_action ();55 GSimpleAction * create_root_action ();
57 void update_header();56 void update_header();
57 void update_actions_enabled();
5858
59 private:59 private:
60 GVariant * action_state_for_location_detection ();60 GVariant * action_state_for_location_detection ();
61 GSimpleAction * create_detection_enabled_action ();61 GSimpleAction * create_detection_enabled_action ();
62 void update_detection_enabled_action();
62 static void on_detection_location_activated (GSimpleAction*, GVariant*, gpointer);63 static void on_detection_location_activated (GSimpleAction*, GVariant*, gpointer);
6364
65
64 private:66 private:
65 GVariant * action_state_for_gps_detection ();67 GVariant * action_state_for_gps_detection ();
66 GSimpleAction * create_gps_enabled_action ();68 GSimpleAction * create_gps_enabled_action ();
69 void update_gps_enabled_action();
67 static void on_detection_gps_activated (GSimpleAction*, GVariant*, gpointer);70 static void on_detection_gps_activated (GSimpleAction*, GVariant*, gpointer);
6871
69 private:72 private:
7073
=== modified file 'src/service.cc'
--- src/service.cc 2016-01-22 18:23:42 +0000
+++ src/service.cc 2016-01-22 18:23:42 +0000
@@ -84,44 +84,44 @@
84***/84***/
8585
86void86void
87Service :: on_name_lost (GDBusConnection * connection,87Service :: on_name_lost (GDBusConnection * conn,
88 const char * name,88 const char * name,
89 gpointer gself)89 gpointer gself)
90{90{
91 g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, connection);91 g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, conn);
9292
93 static_cast<Service*>(gself)->on_name_lost (connection, name);93 static_cast<Service*>(gself)->on_name_lost (conn, name);
94}94}
95void95void
96Service :: on_name_lost (GDBusConnection * connection,96Service :: on_name_lost (GDBusConnection * conn,
97 const char * name)97 const char * name)
98{98{
99 g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, connection);99 g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, conn);
100100
101 if (name_lost_callback != nullptr)101 if (name_lost_callback != nullptr)
102 (name_lost_callback)(this, name_lost_user_data);102 (name_lost_callback)(this, name_lost_user_data);
103}103}
104104
105void105void
106Service :: on_bus_acquired (GDBusConnection * connection,106Service :: on_bus_acquired (GDBusConnection * conn,
107 const char * name,107 const char * name,
108 gpointer gself)108 gpointer gself)
109{109{
110 static_cast<Service*>(gself)->on_bus_acquired (connection, name);110 static_cast<Service*>(gself)->on_bus_acquired (conn, name);
111}111}
112void112void
113Service :: on_bus_acquired (GDBusConnection * connection,113Service :: on_bus_acquired (GDBusConnection * conn,
114 const char * name)114 const char * name)
115{115{
116 g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, connection);116 g_debug ("%s::%s: %s %p", G_STRLOC, G_STRFUNC, name, conn);
117117
118 this->connection.reset (G_DBUS_CONNECTION (g_object_ref(connection)));118 this->connection.reset (G_DBUS_CONNECTION (g_object_ref(conn)));
119119
120 GError * error = nullptr;120 GError * error = nullptr;
121121
122 /* export the action group */122 /* export the action group */
123123
124 unsigned int export_id = g_dbus_connection_export_action_group (connection,124 unsigned int export_id = g_dbus_connection_export_action_group (conn,
125 INDICATOR_OBJECT_PATH,125 INDICATOR_OBJECT_PATH,
126 G_ACTION_GROUP (action_group.get()),126 G_ACTION_GROUP (action_group.get()),
127 &error);127 &error);
@@ -146,7 +146,7 @@
146146
147 for (unsigned int i=0, n=G_N_ELEMENTS(menus); i<n; i++)147 for (unsigned int i=0, n=G_N_ELEMENTS(menus); i<n; i++)
148 { 148 {
149 export_id = g_dbus_connection_export_menu_model (connection,149 export_id = g_dbus_connection_export_menu_model (conn,
150 menus[i].path,150 menus[i].path,
151 G_MENU_MODEL (menus[i].menu.get()),151 G_MENU_MODEL (menus[i].menu.get()),
152 &error);152 &error);
153153
=== modified file 'src/service.h'
--- src/service.h 2016-01-22 18:23:42 +0000
+++ src/service.h 2016-01-22 18:23:42 +0000
@@ -30,7 +30,7 @@
30class Service30class Service
31{31{
32 public:32 public:
33 Service (const std::shared_ptr<Controller>& controller);33 explicit Service (const std::shared_ptr<Controller>& controller);
34 virtual ~Service ();34 virtual ~Service ();
3535
36 private:36 private:
3737
=== renamed file 'src/controller-mock.h' => 'tests/controller-mock.h'
--- src/controller-mock.h 2015-04-15 14:24:14 +0000
+++ tests/controller-mock.h 2016-01-22 18:23:42 +0000
@@ -17,10 +17,9 @@
17 * Charles Kerr <charles.kerr@canonical.com>17 * Charles Kerr <charles.kerr@canonical.com>
18 */18 */
1919
20#ifndef __INDICATOR_LOCATION_CONTROLLER_MOCK__H__20#pragma once
21#define __INDICATOR_LOCATION_CONTROLLER_MOCK__H__
2221
23#include "controller.h"22#include <src/controller.h>
2423
25class MockController: public Controller24class MockController: public Controller
26{25{
@@ -31,19 +30,16 @@
3130
32 core::Property<bool>& is_valid() { return m_is_valid; }31 core::Property<bool>& is_valid() { return m_is_valid; }
33 const core::Property<bool>& is_valid() const override { return m_is_valid; }32 const core::Property<bool>& is_valid() const override { return m_is_valid; }
34 bool is_gps_enabled () const { return gps; }33 const core::Property<bool>& gps_enabled() const override { return m_gps_enabled; }
35 bool is_location_service_enabled () const { return loc; }34 const core::Property<bool>& location_service_enabled() const override { return m_location_service_enabled; }
3635
37 void set_gps_enabled (bool enabled) { notify_gps_enabled (gps=enabled); }36 void set_gps_enabled (bool enabled) override { m_gps_enabled=enabled; }
38 void set_location_service_enabled (bool enabled) { notify_location_service_enabled (loc=enabled); }37 void set_location_service_enabled (bool enabled) override { m_location_service_enabled=enabled; }
3938
40 private:39 private:
4140
42 core::Property<bool> m_is_valid {true};41 core::Property<bool> m_is_valid {true};
43 bool gps { false };42 core::Property<bool> m_gps_enabled {false};
44 bool loc { false };43 core::Property<bool> m_location_service_enabled {false};
45};44};
4645
47#endif // __INDICATOR_LOCATION_CONTROLLER_MOCK__H__
48
49
5046
=== modified file 'tests/gtest-dbus-fixture.h'
--- tests/gtest-dbus-fixture.h 2014-01-27 00:02:51 +0000
+++ tests/gtest-dbus-fixture.h 2016-01-22 18:23:42 +0000
@@ -57,7 +57,7 @@
57 static gboolean57 static gboolean
58 wait_for_signal__timeout (gpointer name)58 wait_for_signal__timeout (gpointer name)
59 {59 {
60 g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name);60 g_error ("%s: timed out waiting for signal '%s'", G_STRLOC, name);
61 return G_SOURCE_REMOVE;61 return G_SOURCE_REMOVE;
62 }62 }
6363
@@ -113,7 +113,7 @@
113 protected:113 protected:
114114
115 /* convenience func to loop while waiting for a GObject's signal */115 /* convenience func to loop while waiting for a GObject's signal */
116 void wait_for_signal(gpointer o, const gchar * signal, const int timeout_seconds=5)116 void wait_for_signal(gpointer o, const gchar * signal, const guint timeout_seconds=5)
117 {117 {
118 // wait for the signal or for timeout, whichever comes first118 // wait for the signal or for timeout, whichever comes first
119 const auto handler_id = g_signal_connect_swapped(o, signal,119 const auto handler_id = g_signal_connect_swapped(o, signal,
@@ -128,7 +128,7 @@
128 }128 }
129129
130 /* convenience func to loop for N msec */130 /* convenience func to loop for N msec */
131 void wait_msec(int msec=50)131 void wait_msec(guint msec=50)
132 {132 {
133 const auto id = g_timeout_add(msec, wait_msec__timeout, loop);133 const auto id = g_timeout_add(msec, wait_msec__timeout, loop);
134 g_main_loop_run(loop);134 g_main_loop_run(loop);
135135
=== modified file 'tests/gtest-dbus-indicator-fixture.h'
--- tests/gtest-dbus-indicator-fixture.h 2015-04-15 14:24:14 +0000
+++ tests/gtest-dbus-indicator-fixture.h 2016-01-22 18:23:42 +0000
@@ -44,9 +44,9 @@
44 gint position G_GNUC_UNUSED,44 gint position G_GNUC_UNUSED,
45 gint removed G_GNUC_UNUSED,45 gint removed G_GNUC_UNUSED,
46 gint added G_GNUC_UNUSED,46 gint added G_GNUC_UNUSED,
47 gpointer any_item_changed)47 gpointer gany_item_changed)
48 {48 {
49 *((gboolean*)any_item_changed) = true;49 *static_cast<gboolean*>(gany_item_changed) = true;
50 }50 }
5151
52 protected:52 protected:
@@ -83,7 +83,7 @@
8383
84 void sync_menu (void)84 void sync_menu (void)
85 {85 {
86 g_slist_free_full (menu_references, (GDestroyNotify)g_object_unref);86 g_slist_free_full (menu_references, GDestroyNotify(g_object_unref));
87 menu_references = nullptr;87 menu_references = nullptr;
88 activate_subtree (G_MENU_MODEL (menu_model));88 activate_subtree (G_MENU_MODEL (menu_model));
89 }89 }
@@ -111,7 +111,7 @@
111 G_BUS_NAME_WATCHER_FLAGS_NONE,111 G_BUS_NAME_WATCHER_FLAGS_NONE,
112 on_name_appeared, // quits the loop112 on_name_appeared, // quits the loop
113 nullptr, this, nullptr);113 nullptr, this, nullptr);
114 const guint timer_id = g_timeout_add_seconds (TIME_LIMIT_SEC, (GSourceFunc)g_main_loop_quit, loop);114 const guint timer_id = g_timeout_add_seconds (TIME_LIMIT_SEC, GSourceFunc(g_main_loop_quit), loop);
115 g_main_loop_run (loop);115 g_main_loop_run (loop);
116 g_source_remove (timer_id);116 g_source_remove (timer_id);
117 g_bus_unwatch_name (watch_id);117 g_bus_unwatch_name (watch_id);
@@ -136,7 +136,7 @@
136 {136 {
137 g_clear_pointer (&timer, g_timer_destroy);137 g_clear_pointer (&timer, g_timer_destroy);
138138
139 g_slist_free_full (menu_references, (GDestroyNotify)g_object_unref);139 g_slist_free_full (menu_references, GDestroyNotify(g_object_unref));
140 menu_references = nullptr;140 menu_references = nullptr;
141 g_clear_object (&menu_model);141 g_clear_object (&menu_model);
142142
143143
=== modified file 'tests/phone-test.cc'
--- tests/phone-test.cc 2016-01-22 18:23:42 +0000
+++ tests/phone-test.cc 2016-01-22 18:23:42 +0000
@@ -21,12 +21,11 @@
21#define INDICATOR_PROFILE "phone"21#define INDICATOR_PROFILE "phone"
22#include "gtest-dbus-indicator-fixture.h"22#include "gtest-dbus-indicator-fixture.h"
2323
24#include "controller-mock.h"
24#include "src/dbus-shared.h"25#include "src/dbus-shared.h"
25#include "src/controller-mock.h"
26#include "src/service.h"26#include "src/service.h"
2727
28class PhoneTest: public GTestDBusIndicatorFixture,28class PhoneTest: public GTestDBusIndicatorFixture
29 public ControllerListener
30{29{
31 protected:30 protected:
3231
@@ -37,6 +36,7 @@
3736
38 std::shared_ptr<MockController> myController;37 std::shared_ptr<MockController> myController;
39 std::shared_ptr<Service> myService;38 std::shared_ptr<Service> myService;
39 std::vector<core::ScopedConnection> myConnections;
4040
41 public:41 public:
4242
@@ -72,14 +72,27 @@
72 virtual void setup_service ()72 virtual void setup_service ()
73 {73 {
74 myController.reset (new MockController ());74 myController.reset (new MockController ());
75 myController->add_listener (this);
76 myService.reset (new Service (myController));75 myService.reset (new Service (myController));
76
77 myConnections.push_back(
78 myController->gps_enabled().changed().connect([this](bool enabled){
79 gps_enabled_changed = true;
80 gps_enabled = enabled;
81 })
82 );
83
84 myConnections.push_back(
85 myController->location_service_enabled().changed().connect([this](bool enabled){
86 loc_enabled_changed = true;
87 loc_enabled = enabled;
88 })
89 );
77 }90 }
7891
79 virtual void teardown_service ()92 virtual void teardown_service ()
80 {93 {
81 myService.reset ();94 myService.reset ();
82 myController->remove_listener (this);95 myConnections.clear ();
83 myController.reset ();96 myController.reset ();
84 }97 }
85};98};
@@ -123,7 +136,7 @@
123TEST_F (PhoneTest, IsValidVisible)136TEST_F (PhoneTest, IsValidVisible)
124{137{
125 // make sure something's enabled so that the indicator should be visible138 // make sure something's enabled so that the indicator should be visible
126 if (!myController->is_location_service_enabled()) {139 if (!myController->location_service_enabled().get()) {
127 myController->set_location_service_enabled(true);140 myController->set_location_service_enabled(true);
128 wait_for_action_state_change("location-detection-enabled");141 wait_for_action_state_change("location-detection-enabled");
129 }142 }

Subscribers

People subscribed via source and target branches