Merge lp:~pete-woods/indicator-location/here-licence into lp:indicator-location/14.10
- here-licence
- Merge into trunk.14.10
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | 137 |
Merged at revision: | 119 |
Proposed branch: | lp:~pete-woods/indicator-location/here-licence |
Merge into: | lp:indicator-location/14.10 |
Diff against target: |
825 lines (+518/-40) 16 files modified
CMakeLists.txt (+1/-0) debian/control (+1/-0) po/indicator-location.pot (+10/-7) src/CMakeLists.txt (+8/-1) src/accounts-service-license-controller.cc (+168/-0) src/accounts-service-license-controller.h (+52/-0) src/license-controller.cc (+50/-0) src/license-controller.h (+75/-0) src/main.cc (+3/-1) src/mock-license-controller.h (+46/-0) src/phone.cc (+85/-25) src/phone.h (+12/-2) src/service.cc (+2/-2) src/service.h (+2/-1) src/utils.h (+1/-0) tests/phone-test.cc (+2/-1) |
To merge this branch: | bzr merge lp:~pete-woods/indicator-location/here-licence |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Charles Kerr (community) | Approve | ||
Review via email: mp+232874@code.launchpad.net |
Commit message
Add here licence action (new dependency on libUAL)
Description of the change
Add here licence action (new dependency on libUAL)
- 119. By Pete Woods
-
Update translations file
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:119
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 120. By Pete Woods
-
Whoops!
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:120
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 121. By Pete Woods
-
This returns variants
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:121
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 122. By Pete Woods
-
It's a tuple of variants
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:122
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 123. By Pete Woods
-
This might actually work now..
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:123
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 124. By Pete Woods
-
Build a URI from the provided path
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:124
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 125. By Pete Woods
-
Add license controller and associated listeners
- 126. By Pete Woods
-
Use libUAL to launch the web browser
- 127. By Pete Woods
-
Check the correct path
- 128. By Pete Woods
-
Unncessary import
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:125
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 129. By Pete Woods
-
Minimise diff
- 130. By Pete Woods
-
Respond to charles' review comments
- 131. By Pete Woods
-
Null pointer paranoia
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:129
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 132. By Pete Woods
-
Rebuild the submenu when the license accept state changes
- 133. By Pete Woods
-
Use GObjectDeleter
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:131
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 134. By Pete Woods
-
Line numbers changed again
- 135. By Pete Woods
-
Don't hang onto a reference to a temporary
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:133
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
- 136. By Pete Woods
-
Didn't null-terminate the list
- 137. By Pete Woods
-
Update line numbers
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2014-05-27 15:34:07 +0000 |
3 | +++ CMakeLists.txt 2014-09-02 18:21:47 +0000 |
4 | @@ -33,6 +33,7 @@ |
5 | include (FindPkgConfig) |
6 | pkg_check_modules (SERVICE_DEPS REQUIRED |
7 | ubuntu-platform-api>=1.0.0 |
8 | + ubuntu-app-launch-2 |
9 | url-dispatcher-1 |
10 | gio-unix-2.0>=2.36 |
11 | glib-2.0>=2.36) |
12 | |
13 | === modified file 'debian/control' |
14 | --- debian/control 2014-08-19 14:50:32 +0000 |
15 | +++ debian/control 2014-09-02 18:21:47 +0000 |
16 | @@ -11,6 +11,7 @@ |
17 | intltool (>= 0.35.0), |
18 | libglib2.0-dev (>= 2.36), |
19 | libgtest-dev, |
20 | + libubuntu-app-launch2-dev, |
21 | liburl-dispatcher1-dev, |
22 | libubuntu-application-api-dev, |
23 | python, |
24 | |
25 | === modified file 'po/indicator-location.pot' |
26 | --- po/indicator-location.pot 2014-08-09 23:23:01 +0000 |
27 | +++ po/indicator-location.pot 2014-09-02 18:21:47 +0000 |
28 | @@ -1,14 +1,14 @@ |
29 | # SOME DESCRIPTIVE TITLE. |
30 | -# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER |
31 | +# Copyright (C) YEAR Canonical Ltd. |
32 | # This file is distributed under the same license as the PACKAGE package. |
33 | # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. |
34 | # |
35 | #, fuzzy |
36 | msgid "" |
37 | msgstr "" |
38 | -"Project-Id-Version: PACKAGE VERSION\n" |
39 | +"Project-Id-Version: indicator-location\n" |
40 | "Report-Msgid-Bugs-To: \n" |
41 | -"POT-Creation-Date: 2014-08-09 18:22-0500\n" |
42 | +"POT-Creation-Date: 2014-09-02 19:21+0100\n" |
43 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" |
44 | "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" |
45 | "Language-Team: LANGUAGE <LL@li.org>\n" |
46 | @@ -17,15 +17,18 @@ |
47 | "Content-Type: text/plain; charset=CHARSET\n" |
48 | "Content-Transfer-Encoding: 8bit\n" |
49 | |
50 | -#: /home/charles/canonical/src/indicator-location/lp-1354058-use-standard-translations-cmake-file/po/../src//phone.cc:77 |
51 | -#: /home/charles/canonical/src/indicator-location/lp-1354058-use-standard-translations-cmake-file/po/../src//phone.cc:80 |
52 | +#: src/phone.cc:83 src/phone.cc:86 |
53 | msgid "Location" |
54 | msgstr "" |
55 | |
56 | -#: /home/charles/canonical/src/indicator-location/lp-1354058-use-standard-translations-cmake-file/po/../src//phone.cc:260 |
57 | +#: src/phone.cc:327 |
58 | msgid "Location detection" |
59 | msgstr "" |
60 | |
61 | -#: /home/charles/canonical/src/indicator-location/lp-1354058-use-standard-translations-cmake-file/po/../src//phone.cc:265 |
62 | +#: src/phone.cc:336 |
63 | +msgid "View HERE terms and conditions" |
64 | +msgstr "" |
65 | + |
66 | +#: src/phone.cc:340 |
67 | msgid "GPS" |
68 | msgstr "" |
69 | |
70 | === modified file 'src/CMakeLists.txt' |
71 | --- src/CMakeLists.txt 2014-05-27 15:34:07 +0000 |
72 | +++ src/CMakeLists.txt 2014-09-02 18:21:47 +0000 |
73 | @@ -13,7 +13,14 @@ |
74 | ### it's built apart from main() as a convenience for tests/ |
75 | ### |
76 | |
77 | -add_library (${SERVICE_LIB} STATIC controller.cc phone.cc service.cc controller-ualc.cc) |
78 | +add_library (${SERVICE_LIB} STATIC |
79 | + controller.cc |
80 | + phone.cc |
81 | + service.cc |
82 | + controller-ualc.cc |
83 | + accounts-service-license-controller.cc |
84 | + license-controller.cc |
85 | +) |
86 | include_directories (${CMAKE_SOURCE_DIR}) |
87 | link_directories (${SERVICE_DEPS_LIBRARY_DIRS}) |
88 | |
89 | |
90 | === added file 'src/accounts-service-license-controller.cc' |
91 | --- src/accounts-service-license-controller.cc 1970-01-01 00:00:00 +0000 |
92 | +++ src/accounts-service-license-controller.cc 2014-09-02 18:21:47 +0000 |
93 | @@ -0,0 +1,168 @@ |
94 | +/* |
95 | + * Copyright 2014 Canonical Ltd. |
96 | + * |
97 | + * This program is free software; you can redistribute it and/or modify |
98 | + * it under the terms of the GNU General Public License as published by |
99 | + * the Free Software Foundation; version 3. |
100 | + * |
101 | + * This program is distributed in the hope that it will be useful, |
102 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
103 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
104 | + * GNU Lesser General Public License for more details. |
105 | + * |
106 | + * You should have received a copy of the GNU Lesser General Public License |
107 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
108 | + * |
109 | + * Authors: |
110 | + * Pete Woods <pete.woods@canonical.com> |
111 | + */ |
112 | + |
113 | +#include "accounts-service-license-controller.h" |
114 | +#include "utils.h" |
115 | + |
116 | +#define ACCOUNTS_NAME "org.freedesktop.Accounts" |
117 | +#define ACCOUNTS_SERVICE "com.ubuntu.location.providers.here.AccountsService" |
118 | + |
119 | +namespace |
120 | +{ |
121 | + |
122 | +std::string |
123 | +user_path() |
124 | +{ |
125 | + return "/org/freedesktop/Accounts/User" + std::to_string(getuid()); |
126 | +} |
127 | + |
128 | +std::string |
129 | +make_path(const std::string& path, const std::string& lang) |
130 | +{ |
131 | + return path + "/" + lang + ".html"; |
132 | +} |
133 | + |
134 | +std::string |
135 | +build_full_path(const std::string & path) |
136 | +{ |
137 | + std::string result; |
138 | + char * lang_char = getenv("LANG"); |
139 | + if (lang_char) |
140 | + { |
141 | + std::string lang = lang_char; |
142 | + auto pos = lang.find('.'); |
143 | + if (pos != std::string::npos) |
144 | + { |
145 | + lang = lang.substr(0, pos); |
146 | + } |
147 | + result = make_path(path, lang); |
148 | + } |
149 | + |
150 | + if (!g_file_test(result.c_str(), G_FILE_TEST_EXISTS)) |
151 | + { |
152 | + result = make_path(path, "en_US"); |
153 | + } |
154 | + |
155 | + return std::string("file://") + result; |
156 | +} |
157 | + |
158 | +} |
159 | + |
160 | +AccountsServiceLicenseController::AccountsServiceLicenseController() |
161 | +{ |
162 | + GError * error = nullptr; |
163 | + proxy.reset( |
164 | + g_dbus_proxy_new_for_bus_sync( |
165 | + G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_GET_INVALIDATED_PROPERTIES, |
166 | + nullptr, ACCOUNTS_NAME, user_path().c_str(), |
167 | + ACCOUNTS_SERVICE, |
168 | + nullptr, &error), |
169 | + GObjectDeleter()); |
170 | + |
171 | + if (proxy.get() == nullptr) |
172 | + { |
173 | + g_warning("Could not get AccountsService proxy '%s'", error->message); |
174 | + g_error_free(error); |
175 | + return; |
176 | + } |
177 | + |
178 | + g_signal_connect(proxy.get(), "g-properties-changed", |
179 | + G_CALLBACK (on_properties_changed), |
180 | + static_cast<void*>(this)); |
181 | +} |
182 | + |
183 | +bool |
184 | +AccountsServiceLicenseController::license_accepted() const |
185 | +{ |
186 | + bool result = false; |
187 | + |
188 | + GVariant * accepted_variant = g_dbus_proxy_get_cached_property( |
189 | + proxy.get(), "LicenseAccepted"); |
190 | + if (accepted_variant) |
191 | + { |
192 | + result = g_variant_get_boolean(accepted_variant); |
193 | + g_variant_unref(accepted_variant); |
194 | + } |
195 | + |
196 | + return result; |
197 | +} |
198 | + |
199 | +std::string |
200 | +AccountsServiceLicenseController::license_path() const |
201 | +{ |
202 | + std::string path; |
203 | + |
204 | + GVariant * base_path_variant = g_dbus_proxy_get_cached_property( |
205 | + proxy.get(), "LicenseBasePath"); |
206 | + if (base_path_variant) |
207 | + { |
208 | + const char * temp = g_variant_get_string(base_path_variant, NULL); |
209 | + if (temp) |
210 | + { |
211 | + path = temp; |
212 | + } |
213 | + g_variant_unref(base_path_variant); |
214 | + } |
215 | + |
216 | + return build_full_path(path); |
217 | +} |
218 | + |
219 | +void |
220 | +AccountsServiceLicenseController::on_properties_changed( |
221 | + GDBusProxy *proxy, GVariant *changed_properties, |
222 | + const gchar* const *invalidated_properties, gpointer user_data) |
223 | +{ |
224 | + AccountsServiceLicenseController * self = |
225 | + static_cast<AccountsServiceLicenseController *>(user_data); |
226 | + |
227 | + if (g_variant_n_children(changed_properties) > 0) |
228 | + { |
229 | + GVariantIter *iter; |
230 | + const gchar *key; |
231 | + GVariant *value; |
232 | + std::string property_name; |
233 | + |
234 | + g_variant_get(changed_properties, "a{sv}", &iter); |
235 | + while (g_variant_iter_loop(iter, "{&sv}", &key, &value)) |
236 | + { |
237 | + if (!key) |
238 | + { |
239 | + continue; |
240 | + } |
241 | + |
242 | + property_name = key; |
243 | + |
244 | + if (property_name == "LicenseAccepted") |
245 | + { |
246 | + self->notify_license_accepted(g_variant_get_boolean(value)); |
247 | + } |
248 | + else if (property_name == "LicenseBasePath") |
249 | + { |
250 | + const gchar * temp = g_variant_get_string(value, NULL); |
251 | + std::string path; |
252 | + if (temp) |
253 | + { |
254 | + path = temp; |
255 | + } |
256 | + self->notify_license_path(build_full_path(path)); |
257 | + } |
258 | + } |
259 | + g_variant_iter_free(iter); |
260 | + } |
261 | +} |
262 | |
263 | === added file 'src/accounts-service-license-controller.h' |
264 | --- src/accounts-service-license-controller.h 1970-01-01 00:00:00 +0000 |
265 | +++ src/accounts-service-license-controller.h 2014-09-02 18:21:47 +0000 |
266 | @@ -0,0 +1,52 @@ |
267 | +/* |
268 | + * Copyright 2014 Canonical Ltd. |
269 | + * |
270 | + * This program is free software; you can redistribute it and/or modify |
271 | + * it under the terms of the GNU General Public License as published by |
272 | + * the Free Software Foundation; version 3. |
273 | + * |
274 | + * This program is distributed in the hope that it will be useful, |
275 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
276 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
277 | + * GNU Lesser General Public License for more details. |
278 | + * |
279 | + * You should have received a copy of the GNU Lesser General Public License |
280 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
281 | + * |
282 | + * Authors: |
283 | + * Pete Woods <pete.woods@canonical.com> |
284 | + */ |
285 | + |
286 | +#ifndef __INDICATOR_LOCATION_ACCOUNTS_SERVICE_LICENSE_CONTROLLER__H__ |
287 | +#define __INDICATOR_LOCATION_ACCOUNTS_SERVICE_LICENSE_CONTROLLER__H__ |
288 | + |
289 | +#include "license-controller.h" |
290 | + |
291 | +#include <gio/gio.h> |
292 | +#include <memory> |
293 | + |
294 | +class AccountsServiceLicenseController : public LicenseController |
295 | +{ |
296 | +public: |
297 | + AccountsServiceLicenseController(); |
298 | + |
299 | + ~AccountsServiceLicenseController() |
300 | + { |
301 | + } |
302 | + |
303 | + bool |
304 | + license_accepted() const override; |
305 | + |
306 | + std::string |
307 | + license_path() const override; |
308 | + |
309 | +private: |
310 | + std::shared_ptr<GDBusProxy> proxy; |
311 | + |
312 | + static void |
313 | + on_properties_changed(GDBusProxy *proxy, GVariant *changed_properties, |
314 | + const gchar* const *invalidated_properties, |
315 | + gpointer user_data); |
316 | +}; |
317 | + |
318 | +#endif // __INDICATOR_LOCATION_ACCOUNTS_SERVICE_LICENSE_CONTROLLER__H__ |
319 | |
320 | === added file 'src/license-controller.cc' |
321 | --- src/license-controller.cc 1970-01-01 00:00:00 +0000 |
322 | +++ src/license-controller.cc 2014-09-02 18:21:47 +0000 |
323 | @@ -0,0 +1,50 @@ |
324 | +/* |
325 | + * Copyright 2014 Canonical Ltd. |
326 | + * |
327 | + * This program is free software; you can redistribute it and/or modify |
328 | + * it under the terms of the GNU General Public License as published by |
329 | + * the Free Software Foundation; version 3. |
330 | + * |
331 | + * This program is distributed in the hope that it will be useful, |
332 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
333 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
334 | + * GNU Lesser General Public License for more details. |
335 | + * |
336 | + * You should have received a copy of the GNU Lesser General Public License |
337 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
338 | + * |
339 | + * Authors: |
340 | + * Pete Woods <pete.woods@canonical.com> |
341 | + */ |
342 | + |
343 | +#include "license-controller.h" |
344 | + |
345 | +void |
346 | +LicenseController::add_listener(LicenseControllerListener * const l) |
347 | +{ |
348 | + listeners.insert(l); |
349 | +} |
350 | + |
351 | +void |
352 | +LicenseController::remove_listener(LicenseControllerListener * const l) |
353 | +{ |
354 | + listeners.erase(l); |
355 | +} |
356 | + |
357 | +void |
358 | +LicenseController::notify_license_accepted(bool license_accepted) |
359 | +{ |
360 | + for (auto it : listeners) |
361 | + { |
362 | + it->on_license_accepted_changed(license_accepted); |
363 | + } |
364 | +} |
365 | + |
366 | +void |
367 | +LicenseController::notify_license_path(const std::string & license_path) |
368 | +{ |
369 | + for (auto it : listeners) |
370 | + { |
371 | + it->on_license_path_changed(license_path); |
372 | + } |
373 | +} |
374 | |
375 | === added file 'src/license-controller.h' |
376 | --- src/license-controller.h 1970-01-01 00:00:00 +0000 |
377 | +++ src/license-controller.h 2014-09-02 18:21:47 +0000 |
378 | @@ -0,0 +1,75 @@ |
379 | +/* |
380 | + * Copyright 2014 Canonical Ltd. |
381 | + * |
382 | + * This program is free software; you can redistribute it and/or modify |
383 | + * it under the terms of the GNU General Public License as published by |
384 | + * the Free Software Foundation; version 3. |
385 | + * |
386 | + * This program is distributed in the hope that it will be useful, |
387 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
388 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
389 | + * GNU Lesser General Public License for more details. |
390 | + * |
391 | + * You should have received a copy of the GNU Lesser General Public License |
392 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
393 | + * |
394 | + * Authors: |
395 | + * Pete Woods <pete.woods@canonical.com> |
396 | + */ |
397 | + |
398 | +#ifndef __INDICATOR_LOCATION_LICENSE_CONTROLLER__H__ |
399 | +#define __INDICATOR_LOCATION_LICENSE_CONTROLLER__H__ |
400 | + |
401 | +#include <memory> |
402 | +#include <string> |
403 | +#include <unordered_set> |
404 | + |
405 | +class LicenseControllerListener |
406 | +{ |
407 | +public: |
408 | + LicenseControllerListener() = default; |
409 | + |
410 | + virtual |
411 | + ~LicenseControllerListener() = default; |
412 | + |
413 | +public: |
414 | + virtual void |
415 | + on_license_accepted_changed(bool license_accepted) = 0; |
416 | + |
417 | + virtual void |
418 | + on_license_path_changed(const std::string & license_path) = 0; |
419 | +}; |
420 | + |
421 | +class LicenseController |
422 | +{ |
423 | +public: |
424 | + LicenseController() = default; |
425 | + |
426 | + virtual |
427 | + ~LicenseController() = default; |
428 | + |
429 | + virtual bool |
430 | + license_accepted() const = 0; |
431 | + |
432 | + virtual std::string |
433 | + license_path() const = 0; |
434 | + |
435 | + void |
436 | + add_listener(LicenseControllerListener * const); |
437 | + |
438 | + void |
439 | + remove_listener(LicenseControllerListener * const); |
440 | + |
441 | +protected: |
442 | + |
443 | + void |
444 | + notify_license_accepted(bool); |
445 | + |
446 | + void |
447 | + notify_license_path(const std::string & license_path); |
448 | + |
449 | +private: |
450 | + std::unordered_set<LicenseControllerListener *> listeners; |
451 | +}; |
452 | + |
453 | +#endif // __INDICATOR_LOCATION_LICENSE_CONTROLLER__H__ |
454 | |
455 | === modified file 'src/main.cc' |
456 | --- src/main.cc 2013-08-29 17:48:37 +0000 |
457 | +++ src/main.cc 2014-09-02 18:21:47 +0000 |
458 | @@ -21,6 +21,7 @@ |
459 | #include <glib/gi18n.h> |
460 | #include <glib.h> |
461 | |
462 | +#include "accounts-service-license-controller.h" |
463 | #include "controller-ualc.h" |
464 | #include "service.h" |
465 | |
466 | @@ -43,7 +44,8 @@ |
467 | /* set up the service */ |
468 | loop = g_main_loop_new (nullptr, false); |
469 | std::shared_ptr<Controller> controller (new UbuntuAppLocController ()); |
470 | - Service service (controller); |
471 | + auto license_controller = std::make_shared<AccountsServiceLicenseController>(); |
472 | + Service service (controller, license_controller); |
473 | service.set_name_lost_callback (on_name_lost, loop); |
474 | g_main_loop_run (loop); |
475 | |
476 | |
477 | === added file 'src/mock-license-controller.h' |
478 | --- src/mock-license-controller.h 1970-01-01 00:00:00 +0000 |
479 | +++ src/mock-license-controller.h 2014-09-02 18:21:47 +0000 |
480 | @@ -0,0 +1,46 @@ |
481 | +/* |
482 | + * Copyright 2014 Canonical Ltd. |
483 | + * |
484 | + * This program is free software; you can redistribute it and/or modify |
485 | + * it under the terms of the GNU General Public License as published by |
486 | + * the Free Software Foundation; version 3. |
487 | + * |
488 | + * This program is distributed in the hope that it will be useful, |
489 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
490 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
491 | + * GNU Lesser General Public License for more details. |
492 | + * |
493 | + * You should have received a copy of the GNU Lesser General Public License |
494 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
495 | + * |
496 | + * Authors: |
497 | + * Pete Woods <pete.woods@canonical.com> |
498 | + */ |
499 | + |
500 | +#ifndef __INDICATOR_LOCATION_MOCK_LICENSE_CONTROLLER__H__ |
501 | +#define __INDICATOR_LOCATION_MOCK_LICENSE_CONTROLLER__H__ |
502 | + |
503 | +#include "license-controller.h" |
504 | + |
505 | +class MockLicenseController : public LicenseController |
506 | +{ |
507 | +public: |
508 | + MockLicenseController() = default; |
509 | + |
510 | + ~MockLicenseController() |
511 | + { |
512 | + } |
513 | + |
514 | + bool |
515 | + license_accepted() const override |
516 | + { |
517 | + return true; |
518 | + } |
519 | + |
520 | + std::string |
521 | + license_path() const override{ |
522 | + return "file:///foo/bar/en_US.html"; |
523 | + } |
524 | +}; |
525 | + |
526 | +#endif // __INDICATOR_LOCATION_MOCK_LICENSE_CONTROLLER__H__ |
527 | |
528 | === modified file 'src/phone.cc' |
529 | --- src/phone.cc 2013-11-08 17:28:46 +0000 |
530 | +++ src/phone.cc 2014-09-02 18:21:47 +0000 |
531 | @@ -22,6 +22,7 @@ |
532 | #include <glib/gi18n.h> |
533 | |
534 | #include <url-dispatcher.h> |
535 | +#include <ubuntu-app-launch.h> |
536 | |
537 | #include "phone.h" |
538 | #include "utils.h" // GObjectDeleter |
539 | @@ -29,18 +30,22 @@ |
540 | #define PROFILE_NAME "phone" |
541 | |
542 | Phone :: Phone (const std::shared_ptr<Controller>& controller_, |
543 | + const std::shared_ptr<LicenseController>& license_controller_, |
544 | const std::shared_ptr<GSimpleActionGroup>& action_group_): |
545 | controller (controller_), |
546 | - menu (create_menu ()), |
547 | + license_controller (license_controller_), |
548 | action_group (action_group_) |
549 | { |
550 | + create_menu (); |
551 | controller->add_listener (this); |
552 | + license_controller->add_listener (this); |
553 | |
554 | /* create the actions & add them to the group */ |
555 | - std::array<GSimpleAction*, 4> actions = { create_root_action(), |
556 | + std::array<GSimpleAction*, 5> actions = { create_root_action(), |
557 | create_detection_enabled_action(), |
558 | create_gps_enabled_action(), |
559 | - create_settings_action() }; |
560 | + create_settings_action(), |
561 | + create_licence_action() }; |
562 | for (auto a : actions) |
563 | { |
564 | g_action_map_add_action (G_ACTION_MAP(action_group.get()), G_ACTION(a)); |
565 | @@ -51,6 +56,7 @@ |
566 | Phone :: ~Phone () |
567 | { |
568 | controller->remove_listener (this); |
569 | + license_controller->remove_listener (this); |
570 | } |
571 | |
572 | /*** |
573 | @@ -126,6 +132,17 @@ |
574 | } |
575 | |
576 | void |
577 | +Phone::on_license_accepted_changed(bool license_accepted) |
578 | +{ |
579 | + rebuild_submenu(); |
580 | +} |
581 | + |
582 | +void |
583 | +Phone::on_license_path_changed(const std::string & license_path) |
584 | +{ |
585 | +} |
586 | + |
587 | +void |
588 | Phone :: on_detection_location_activated (GSimpleAction * action, |
589 | GVariant * parameter G_GNUC_UNUSED, |
590 | gpointer gself) |
591 | @@ -198,6 +215,38 @@ |
592 | return action; |
593 | } |
594 | |
595 | +/*** |
596 | +**** |
597 | +***/ |
598 | + |
599 | +#define LICENCE_ACTION_KEY "licence" |
600 | + |
601 | +namespace |
602 | +{ |
603 | + void |
604 | + on_licence_activated (GSimpleAction * simple G_GNUC_UNUSED, |
605 | + GVariant * parameter, |
606 | + gpointer user_data G_GNUC_UNUSED) |
607 | + { |
608 | + LicenseController * license_controller = static_cast<LicenseController *>(user_data); |
609 | + std::string path = license_controller->license_path(); |
610 | + const gchar * urls[2] = {path.c_str(), nullptr}; |
611 | + ubuntu_app_launch_start_application("webbrowser-app", urls); |
612 | + } |
613 | +} |
614 | + |
615 | +GSimpleAction * |
616 | +Phone :: create_licence_action () |
617 | +{ |
618 | + GSimpleAction * action; |
619 | + |
620 | + action = g_simple_action_new (LICENCE_ACTION_KEY, nullptr); |
621 | + |
622 | + g_signal_connect(action, "activate", G_CALLBACK(on_licence_activated), |
623 | + static_cast<void *>(license_controller.get())); |
624 | + |
625 | + return action; |
626 | +} |
627 | |
628 | /*** |
629 | **** |
630 | @@ -245,27 +294,16 @@ |
631 | **** |
632 | ***/ |
633 | |
634 | -std::shared_ptr <GMenu> |
635 | +void |
636 | Phone :: create_menu () |
637 | { |
638 | - GMenu * menu; |
639 | - GMenu * submenu; |
640 | GMenuItem * header; |
641 | - GMenuItem * location; |
642 | - GMenuItem * gps; |
643 | |
644 | /* create the submenu */ |
645 | - submenu = g_menu_new (); |
646 | - |
647 | - location = g_menu_item_new (_("Location detection"), "indicator." LOCATION_ACTION_KEY); |
648 | - g_menu_item_set_attribute (location, "x-canonical-type", "s", "com.canonical.indicator.switch"); |
649 | - g_menu_append_item (submenu, location); |
650 | - g_object_unref (location); |
651 | - |
652 | - gps = g_menu_item_new (_("GPS"), "indicator." GPS_ACTION_KEY); |
653 | - g_menu_item_set_attribute (gps, "x-canonical-type", "s", "com.canonical.indicator.switch"); |
654 | - g_menu_append_item (submenu, gps); |
655 | - g_object_unref (gps); |
656 | + submenu.reset(g_menu_new (), GObjectDeleter()); |
657 | + |
658 | + /* populate the submenu */ |
659 | + rebuild_submenu(); |
660 | |
661 | // disabled for 13.04 -- the location settings panel isn't complete |
662 | // g_menu_append (submenu, _("Location settingsā¦"), "indicator." SETTINGS_ACTION_KEY "::location"); |
663 | @@ -273,13 +311,35 @@ |
664 | /* add the submenu to a new header */ |
665 | header = g_menu_item_new (nullptr, "indicator." HEADER_ACTION_KEY); |
666 | g_menu_item_set_attribute (header, "x-canonical-type", "s", "com.canonical.indicator.root"); |
667 | - g_menu_item_set_submenu (header, G_MENU_MODEL (submenu)); |
668 | - g_object_unref (submenu); |
669 | + g_menu_item_set_submenu (header, G_MENU_MODEL (submenu.get())); |
670 | |
671 | /* add the header to a new menu */ |
672 | - menu = g_menu_new (); |
673 | - g_menu_append_item (menu, header); |
674 | + menu.reset(g_menu_new (), GObjectDeleter()); |
675 | + g_menu_append_item (menu.get(), header); |
676 | g_object_unref (header); |
677 | - |
678 | - return std::shared_ptr<GMenu>(menu, GObjectDeleter()); |
679 | +} |
680 | + |
681 | +void |
682 | +Phone::rebuild_submenu() |
683 | +{ |
684 | + g_menu_remove_all(submenu.get()); |
685 | + |
686 | + GMenuItem * location = g_menu_item_new(_("Location detection"), |
687 | + "indicator." LOCATION_ACTION_KEY); |
688 | + g_menu_item_set_attribute(location, "x-canonical-type", "s", |
689 | + "com.canonical.indicator.switch"); |
690 | + g_menu_append_item(submenu.get(), location); |
691 | + g_object_unref(location); |
692 | + |
693 | + if (license_controller->license_accepted()) |
694 | + { |
695 | + g_menu_append(submenu.get(), _("View HERE terms and conditions"), |
696 | + "indicator." LICENCE_ACTION_KEY); |
697 | + } |
698 | + |
699 | + GMenuItem * gps = g_menu_item_new(_("GPS"), "indicator." GPS_ACTION_KEY); |
700 | + g_menu_item_set_attribute(gps, "x-canonical-type", "s", |
701 | + "com.canonical.indicator.switch"); |
702 | + g_menu_append_item(submenu.get(), gps); |
703 | + g_object_unref(gps); |
704 | } |
705 | |
706 | === modified file 'src/phone.h' |
707 | --- src/phone.h 2013-10-31 18:54:01 +0000 |
708 | +++ src/phone.h 2014-09-02 18:21:47 +0000 |
709 | @@ -25,27 +25,34 @@ |
710 | #include <glib.h> |
711 | #include <gio/gio.h> |
712 | |
713 | +#include "license-controller.h" |
714 | #include "controller.h" |
715 | |
716 | -class Phone: public ControllerListener |
717 | +class Phone: public ControllerListener, public LicenseControllerListener |
718 | { |
719 | public: |
720 | Phone (const std::shared_ptr<Controller>& controller, |
721 | + const std::shared_ptr<LicenseController>& license_controller, |
722 | const std::shared_ptr<GSimpleActionGroup>& action_group); |
723 | virtual ~Phone (); |
724 | std::shared_ptr<GMenu> get_menu () { return menu; } |
725 | |
726 | protected: |
727 | std::shared_ptr<Controller> controller; |
728 | + std::shared_ptr<LicenseController> license_controller; |
729 | virtual void on_gps_enabled_changed (bool is_enabled); |
730 | virtual void on_location_service_enabled_changed (bool is_enabled); |
731 | + void on_license_accepted_changed(bool license_accepted) override; |
732 | + void on_license_path_changed(const std::string & license_path) override; |
733 | |
734 | private: |
735 | std::shared_ptr<GMenu> menu; |
736 | + std::shared_ptr<GMenu> submenu; |
737 | std::shared_ptr<GSimpleActionGroup> action_group; |
738 | |
739 | private: |
740 | - std::shared_ptr<GMenu> create_menu (); |
741 | + void create_menu (); |
742 | + void rebuild_submenu(); |
743 | |
744 | private: |
745 | bool should_be_visible (); |
746 | @@ -64,6 +71,9 @@ |
747 | |
748 | private: |
749 | GSimpleAction * create_settings_action (); |
750 | + |
751 | + private: |
752 | + GSimpleAction * create_licence_action (); |
753 | }; |
754 | |
755 | #endif /* __INDICATOR_LOCATION_PHONE_H__ */ |
756 | |
757 | === modified file 'src/service.cc' |
758 | --- src/service.cc 2013-10-31 18:54:01 +0000 |
759 | +++ src/service.cc 2014-09-02 18:21:47 +0000 |
760 | @@ -29,9 +29,9 @@ |
761 | *** |
762 | **/ |
763 | |
764 | -Service :: Service (const std::shared_ptr<Controller>& controller): |
765 | +Service :: Service (const std::shared_ptr<Controller>& controller, const std::shared_ptr<LicenseController>& license_controller): |
766 | action_group (g_simple_action_group_new(), GObjectDeleter()), |
767 | - phone_profile (controller, action_group), |
768 | + phone_profile (controller, license_controller, action_group), |
769 | name_lost_callback (nullptr), |
770 | name_lost_user_data (0), |
771 | action_group_export_id (0), |
772 | |
773 | === modified file 'src/service.h' |
774 | --- src/service.h 2013-10-31 18:54:01 +0000 |
775 | +++ src/service.h 2014-09-02 18:21:47 +0000 |
776 | @@ -23,6 +23,7 @@ |
777 | #include <memory> |
778 | #include <set> |
779 | |
780 | +#include "license-controller.h" |
781 | #include "controller.h" |
782 | #include "phone.h" |
783 | #include "utils.h" // GObjectDeleter |
784 | @@ -30,7 +31,7 @@ |
785 | class Service |
786 | { |
787 | public: |
788 | - Service (const std::shared_ptr<Controller>& controller); |
789 | + Service (const std::shared_ptr<Controller>& controller, const std::shared_ptr<LicenseController>& license_controller); |
790 | virtual ~Service (); |
791 | |
792 | private: |
793 | |
794 | === modified file 'src/utils.h' |
795 | --- src/utils.h 2013-08-22 13:56:02 +0000 |
796 | +++ src/utils.h 2014-09-02 18:21:47 +0000 |
797 | @@ -28,6 +28,7 @@ |
798 | void operator()(GObject * o) { g_object_unref (o); } |
799 | |
800 | void operator()(GMenu * o) { operator()(G_OBJECT(o)); } |
801 | + void operator()(GDBusProxy * o) { operator()(G_OBJECT(o)); } |
802 | void operator()(GDBusConnection * o) { operator()(G_OBJECT(o)); } |
803 | void operator()(GSimpleActionGroup * o) { operator()(G_OBJECT(o)); } |
804 | }; |
805 | |
806 | === modified file 'tests/phone-test.cc' |
807 | --- tests/phone-test.cc 2013-10-08 18:10:12 +0000 |
808 | +++ tests/phone-test.cc 2014-09-02 18:21:47 +0000 |
809 | @@ -22,6 +22,7 @@ |
810 | #define INDICATOR_PROFILE "phone" |
811 | #include "gtest-dbus-indicator-fixture.h" |
812 | |
813 | +#include "src/mock-license-controller.h" |
814 | #include "src/controller-mock.h" |
815 | #include "src/service.h" |
816 | |
817 | @@ -73,7 +74,7 @@ |
818 | { |
819 | myController.reset (new MockController ()); |
820 | myController->add_listener (this); |
821 | - myService.reset (new Service (myController)); |
822 | + myService.reset (new Service (myController, std::make_shared<MockLicenseController>())); |
823 | } |
824 | |
825 | virtual void teardown_service () |
PASSED: Continuous integration, rev:118 jenkins. qa.ubuntu. com/job/ indicator- location- ci/44/ jenkins. qa.ubuntu. com/job/ indicator- location- utopic- amd64-ci/ 10 jenkins. qa.ubuntu. com/job/ indicator- location- utopic- armhf-ci/ 10 jenkins. qa.ubuntu. com/job/ indicator- location- utopic- armhf-ci/ 10/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- location- ci/44/rebuild
http://