Merge lp:~renatofilho/indicator-datetime/notify-missing-alarm into lp:indicator-datetime/15.10

Proposed by Renato Araujo Oliveira Filho on 2016-04-19
Status: Merged
Approved by: Charles Kerr on 2016-04-29
Approved revision: 472
Merged at revision: 448
Proposed branch: lp:~renatofilho/indicator-datetime/notify-missing-alarm
Merge into: lp:indicator-datetime/15.10
Prerequisite: lp:~renatofilho/indicator-datetime/fix-1533681
Diff against target: 1157 lines (+401/-218)
19 files modified
CMakeLists.txt (+4/-1)
data/CMakeLists.txt (+1/-1)
data/indicator-datetime.desktop.in (+1/-0)
debian/control (+4/-0)
include/datetime/actions-live.h (+13/-10)
include/datetime/actions.h (+4/-8)
include/notifications/haptic.h (+1/-1)
include/notifications/notifications.h (+8/-1)
src/actions-live.cpp (+71/-63)
src/actions.cpp (+34/-58)
src/haptic.cpp (+15/-9)
src/main.cpp (+3/-1)
src/notifications.cpp (+169/-5)
src/snap.cpp (+14/-3)
tests/actions-mock.h (+18/-38)
tests/test-actions.cpp (+8/-8)
tests/test-live-actions.cpp (+31/-9)
tests/test-notification.cpp (+1/-1)
tests/test-sound.cpp (+1/-1)
To merge this branch: bzr merge lp:~renatofilho/indicator-datetime/notify-missing-alarm
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Needs Fixing on 2016-05-02
Charles Kerr (community) 2016-04-19 Approve on 2016-04-29
Review via email: mp+292270@code.launchpad.net

This proposal supersedes a proposal from 2016-04-19.

Commit message

Post message on messaging menu if the notification get timeout.

Description of the change

QA: Jenkins is failing because it is missing the new version of libubuntu-app-launch2-dev (>= 0.9)

To post a comment you must log in.
463. By Renato Araujo Oliveira Filho on 2016-04-19

Fixed crash when clicking on messaging menu.

464. By Renato Araujo Oliveira Filho on 2016-04-20

Fix memory leak on messaging_menu.

465. By Renato Araujo Oliveira Filho on 2016-04-20

Vibrate only once when notification about calendar events.

Charles Kerr (charlesk) wrote :

I have a lot of questions about this.

review: Needs Information

Some small fixes is on the way.

There is some replies inline.

466. By Renato Araujo Oliveira Filho on 2016-04-26

Fixed as reviewer requested.

467. By Renato Araujo Oliveira Filho on 2016-04-26

Make use of G_USEC_PER_SEC.

468. By Renato Araujo Oliveira Filho on 2016-04-27

Update notifications to use the new calendar icon.

469. By Renato Araujo Oliveira Filho on 2016-04-27

Use calendar app icon.

470. By Renato Araujo Oliveira Filho on 2016-04-27

Only creates messaging menu if calendar app is instaled.
Update tests.

Charles Kerr (charlesk) wrote :

More code-level comments inline. Most are minor/suggestions, two NF

A few larger issues:

1. Again I'd /strongly/ prefer that ical events pass in their source desktop id as an x-prop. Not only would that eliminate the need for libubuntu-app-launch2-dev >= 0.9 but it would also let us have per-app sources, eg alarms wouldn't show up under the calendar icon. The approach in this patch works for calendars but assumes that the whole world is a calendar.

2. If we must use libubuntu-app-launch2-dev, can we confirm that it's going to make it into Xenial? It's awfully early to be breaking build compatibility with Xenial

review: Needs Fixing

> More code-level comments inline. Most are minor/suggestions, two NF
>
> A few larger issues:
>
> 1. Again I'd /strongly/ prefer that ical events pass in their source desktop
> id as an x-prop. Not only would that eliminate the need for libubuntu-app-
> launch2-dev >= 0.9 but it would also let us have per-app sources, eg alarms
> wouldn't show up under the calendar icon. The approach in this patch works for
> calendars but assumes that the whole world is a calendar.
We can not guarantee that ical event will have their source id. I can change calendar app to add that, but old events will not have that. Events created by others apps (syncevolution, evolution, thuderbird, etc...) will not set that.
>
> 2. If we must use libubuntu-app-launch2-dev, can we confirm that it's going to
> make it into Xenial? It's awfully early to be breaking build compatibility
> with Xenial

I believe it is already in xenial, ppa builds it ok: https://launchpad.net/~ci-train-ppa-service/+archive/ubuntu/landing-009/+packages

471. By Renato Araujo Oliveira Filho on 2016-04-28

Small fixes requeted by charles during the review.

472. By Renato Araujo Oliveira Filho on 2016-04-28

Detect desktop to launch applications.

Charles Kerr (charlesk) wrote :

Renato, the rest of the changes look fine, any idea why Jenkins is failing?

Charles Kerr (charlesk) wrote :

I love the changes to open_appointment() :-)

> Renato, the rest of the changes look fine, any idea why Jenkins is failing?

Jenkins still missing the new library: Depends: libubuntu-app-launch2-dev (>= 0.9) but it is not going to be installed.

Charles Kerr (charlesk) :
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 2016-04-28 14:56:46 +0000
+++ CMakeLists.txt 2016-04-28 14:56:46 +0000
@@ -48,7 +48,10 @@
48 libnotify>=0.7.648 libnotify>=0.7.6
49 url-dispatcher-1>=149 url-dispatcher-1>=1
50 properties-cpp>=0.0.150 properties-cpp>=0.0.1
51 libaccounts-glib>=1.18)51 libaccounts-glib>=1.18
52 messaging-menu>=12.10
53 uuid>=2.25
54 ubuntu-app-launch-2)
52include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS})55include_directories (SYSTEM ${SERVICE_DEPS_INCLUDE_DIRS})
5356
54##57##
5558
=== modified file 'data/CMakeLists.txt'
--- data/CMakeLists.txt 2015-10-13 15:06:25 +0000
+++ data/CMakeLists.txt 2016-04-28 14:56:46 +0000
@@ -52,7 +52,7 @@
52set (pkglibexecdir "${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}")52set (pkglibexecdir "${CMAKE_INSTALL_FULL_PKGLIBEXECDIR}")
53configure_file ("${XDG_AUTOSTART_FILE_IN}" "${XDG_AUTOSTART_FILE}")53configure_file ("${XDG_AUTOSTART_FILE_IN}" "${XDG_AUTOSTART_FILE}")
5454
55# install it55# install XDG autostart
56install (FILES "${XDG_AUTOSTART_FILE}"56install (FILES "${XDG_AUTOSTART_FILE}"
57 DESTINATION "${XDG_AUTOSTART_DIR}")57 DESTINATION "${XDG_AUTOSTART_DIR}")
5858
5959
=== modified file 'data/indicator-datetime.desktop.in'
--- data/indicator-datetime.desktop.in 2014-04-04 13:05:59 +0000
+++ data/indicator-datetime.desktop.in 2016-04-28 14:56:46 +0000
@@ -7,3 +7,4 @@
7StartupNotify=false7StartupNotify=false
8Terminal=false8Terminal=false
9AutostartCondition=GNOME3 unless-session gnome9AutostartCondition=GNOME3 unless-session gnome
10Icon=@messaging_menu_icon@
1011
=== modified file 'debian/control'
--- debian/control 2016-04-28 14:56:46 +0000
+++ debian/control 2016-04-28 14:56:46 +0000
@@ -31,6 +31,10 @@
31 ubuntu-touch-sounds,31 ubuntu-touch-sounds,
32# for query user e-mails based on accounts32# for query user e-mails based on accounts
33 libaccounts-glib-dev,33 libaccounts-glib-dev,
34# messaging menu integration
35 libmessaging-menu-dev,
36 uuid-dev,
37 libubuntu-app-launch2-dev (>= 0.9),
34Standards-Version: 3.9.338Standards-Version: 3.9.3
35Homepage: https://launchpad.net/indicator-datetime39Homepage: https://launchpad.net/indicator-datetime
36# If you aren't a member of ~indicator-applet-developers but need to upload40# If you aren't a member of ~indicator-applet-developers but need to upload
3741
=== modified file 'include/datetime/actions-live.h'
--- include/datetime/actions-live.h 2016-04-05 21:00:09 +0000
+++ include/datetime/actions-live.h 2016-04-28 14:56:46 +0000
@@ -36,26 +36,29 @@
36class LiveActions: public Actions36class LiveActions: public Actions
37{37{
38public:38public:
39 enum Desktop {
40 OTHER = 0,
41 UNITY7,
42 UNITY8,
43 };
44
39 explicit LiveActions(const std::shared_ptr<State>& state_in);45 explicit LiveActions(const std::shared_ptr<State>& state_in);
40 virtual ~LiveActions() =default;46 virtual ~LiveActions() =default;
4147
42 bool desktop_has_calendar_app() const override;48 bool desktop_has_calendar_app() const override;
43 void desktop_open_alarm_app() override;49 void open_alarm_app() override;
44 void desktop_open_appointment(const Appointment&, const DateTime&) override;50 void open_appointment(const Appointment&, const DateTime&) override;
45 void desktop_open_calendar_app(const DateTime&) override;51 void open_calendar_app(const DateTime&) override;
46 void desktop_open_settings_app() override;52 void open_settings_app() override;
47
48 void phone_open_alarm_app() override;
49 void phone_open_appointment(const Appointment&, const DateTime &) override;
50 void phone_open_calendar_app(const DateTime&) override;
51 void phone_open_settings_app() override;
5253
53 void set_location(const std::string& zone, const std::string& name) override;54 void set_location(const std::string& zone, const std::string& name) override;
5455
55protected:56protected:
56 static bool is_unity();57 virtual Desktop get_desktop();
57 virtual void execute_command(const std::string& command);58 virtual void execute_command(const std::string& command);
58 virtual void dispatch_url(const std::string& url);59 virtual void dispatch_url(const std::string& url);
60
61 void unity8_open_appointment(const Appointment& appt, const DateTime& date);
59};62};
6063
61} // namespace datetime64} // namespace datetime
6265
=== modified file 'include/datetime/actions.h'
--- include/datetime/actions.h 2016-03-21 17:32:39 +0000
+++ include/datetime/actions.h 2016-04-28 14:56:46 +0000
@@ -44,15 +44,11 @@
44public:44public:
4545
46 virtual bool desktop_has_calendar_app() const =0;46 virtual bool desktop_has_calendar_app() const =0;
47 virtual void desktop_open_alarm_app() =0;
48 virtual void desktop_open_appointment(const Appointment&, const DateTime&) =0;
49 virtual void desktop_open_calendar_app(const DateTime&) =0;
50 virtual void desktop_open_settings_app() =0;
5147
52 virtual void phone_open_alarm_app() =0;48 virtual void open_alarm_app() =0;
53 virtual void phone_open_appointment(const Appointment&, const DateTime&) =0;49 virtual void open_appointment(const Appointment&, const DateTime&) =0;
54 virtual void phone_open_calendar_app(const DateTime&) =0;50 virtual void open_calendar_app(const DateTime&) =0;
55 virtual void phone_open_settings_app() =0;51 virtual void open_settings_app() =0;
5652
57 virtual void set_location(const std::string& zone, const std::string& name)=0;53 virtual void set_location(const std::string& zone, const std::string& name)=0;
5854
5955
=== modified file 'include/notifications/haptic.h'
--- include/notifications/haptic.h 2014-09-17 16:51:51 +0000
+++ include/notifications/haptic.h 2016-04-28 14:56:46 +0000
@@ -41,7 +41,7 @@
41 MODE_PULSE41 MODE_PULSE
42 };42 };
4343
44 explicit Haptic(const Mode& mode = MODE_PULSE);44 explicit Haptic(const Mode& mode = MODE_PULSE, bool repeat = false);
45 ~Haptic();45 ~Haptic();
4646
47private:47private:
4848
=== modified file 'include/notifications/notifications.h'
--- include/notifications/notifications.h 2014-09-19 14:35:07 +0000
+++ include/notifications/notifications.h 2016-04-28 14:56:46 +0000
@@ -50,6 +50,8 @@
5050
51 void set_icon_name (const std::string& icon_name);51 void set_icon_name (const std::string& icon_name);
5252
53 void set_start_time(uint64_t time);
54
53 /* Set an interval, after which the notification will automatically55 /* Set an interval, after which the notification will automatically
54 be closed. If not set, the notification server's default timeout56 be closed. If not set, the notification server's default timeout
55 is used. */57 is used. */
@@ -62,15 +64,20 @@
62 static constexpr char const * HINT_NONSHAPED_ICON {"x-canonical-non-shaped-icon"};64 static constexpr char const * HINT_NONSHAPED_ICON {"x-canonical-non-shaped-icon"};
63 static constexpr char const * HINT_AFFIRMATIVE_HINT {"x-canonical-private-affirmative-tint"};65 static constexpr char const * HINT_AFFIRMATIVE_HINT {"x-canonical-private-affirmative-tint"};
64 static constexpr char const * HINT_REJECTION_TINT {"x-canonical-private-rejection-tint"};66 static constexpr char const * HINT_REJECTION_TINT {"x-canonical-private-rejection-tint"};
67 static constexpr char const * HINT_INTERACTIVE {"x-canonical-switch-to-application"};
6568
66 /* Add an action button.69 /* Add an action button.
67 This may fail if the Engine doesn't support actions.70 This may fail if the Engine doesn't support actions.
68 @see Engine::supports_actions() */71 @see Engine::supports_actions() */
69 void add_action (const std::string& action, const std::string& label);72 void add_action (const std::string& action, const std::string& label);
7073
71 /** Sets the closed callback. This will be called exactly once. */74 /** Sets the closed callback. This will be called exactly once. After notification dissapear */
72 void set_closed_callback (std::function<void(const std::string& action)>);75 void set_closed_callback (std::function<void(const std::string& action)>);
7376
77 /** Sets the time-out callback. This will be called exactly once. */
78 void set_timeout_callback (std::function<void()>);
79
80
74private:81private:
75 friend class Engine;82 friend class Engine;
76 class Impl;83 class Impl;
7784
=== modified file 'src/actions-live.cpp'
--- src/actions-live.cpp 2016-04-10 00:03:57 +0000
+++ src/actions-live.cpp 2016-04-28 14:56:46 +0000
@@ -62,48 +62,94 @@
62****62****
63***/63***/
6464
65bool LiveActions::is_unity()65LiveActions::Desktop LiveActions::get_desktop()
66{66{
67 static bool cached = false;67 static bool cached = false;
68 static bool result;68 static LiveActions::Desktop result = LiveActions::OTHER;
6969
70 if (cached) {70 if (cached) {
71 return result;71 return result;
72 }72 }
7373
74 result = false;74 // check for unity8
75 const gchar *xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");75 if (g_getenv ("MIR_SOCKET") != nullptr) {
7676 result = LiveActions::UNITY8;
77 if (xdg_current_desktop != NULL) {77 } else {
78 gchar **desktop_names = g_strsplit (xdg_current_desktop, ":", 0);78 const gchar *xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
79 for (size_t i = 0; desktop_names[i]; ++i) {79 if (xdg_current_desktop != NULL) {
80 if (!g_strcmp0 (desktop_names[i], "Unity")) {80 gchar **desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
81 result = true;81 for (size_t i = 0; desktop_names[i]; ++i) {
82 break;82 if (!g_strcmp0 (desktop_names[i], "Unity")) {
83 result = LiveActions::UNITY7;
84 break;
85 }
83 }86 }
87 g_strfreev (desktop_names);
84 }88 }
85 g_strfreev (desktop_names);
86 }89 }
87 cached = true;90 cached = true;
88 return result;91 return result;
89}92}
9093
91void LiveActions::desktop_open_settings_app()94void LiveActions::open_alarm_app()
92{95{
93 if (g_getenv ("MIR_SOCKET") != nullptr)96 switch(get_desktop()) {
94 {97 case LiveActions::UNITY8:
98 dispatch_url("appid://com.ubuntu.clock/clock/current-user-version");
99 break;
100 case LiveActions::UNITY7:
101 default:
102 execute_command("evolution -c calendar");
103 }
104}
105
106void LiveActions::open_appointment(const Appointment& appt, const DateTime& date)
107{
108 switch(get_desktop()) {
109 case LiveActions::UNITY8:
110 unity8_open_appointment(appt, date);
111 break;
112 case LiveActions::UNITY7:
113 default:
114 open_calendar_app(date);
115 }
116}
117
118void LiveActions::open_calendar_app(const DateTime& dt)
119{
120 switch(get_desktop()) {
121 case LiveActions::UNITY8:
122 {
123 const auto utc = dt.to_timezone("UTC");
124 auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00");
125 dispatch_url(cmd);
126 break;
127 }
128 case LiveActions::UNITY7:
129 default:
130 {
131 const auto utc = dt.start_of_day().to_timezone("UTC");
132 auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\"");
133 execute_command(cmd.c_str());
134 }
135 }
136}
137
138void LiveActions::open_settings_app()
139{
140 switch(get_desktop()) {
141 case LiveActions::UNITY8:
95 dispatch_url("settings:///system/time-date");142 dispatch_url("settings:///system/time-date");
96 }143 break;
97 else if (is_unity())144 case LiveActions::UNITY7:
98 {
99 execute_command("unity-control-center datetime");145 execute_command("unity-control-center datetime");
100 }146 break;
101 else147 default:
102 {
103 execute_command("gnome-control-center datetime");148 execute_command("gnome-control-center datetime");
104 }149 }
105}150}
106151
152
107bool LiveActions::desktop_has_calendar_app() const153bool LiveActions::desktop_has_calendar_app() const
108{154{
109 static bool inited = false;155 static bool inited = false;
@@ -136,33 +182,7 @@
136 return have_calendar;182 return have_calendar;
137}183}
138184
139void LiveActions::desktop_open_alarm_app()185void LiveActions::unity8_open_appointment(const Appointment& appt, const DateTime& date)
140{
141 execute_command("evolution -c calendar");
142}
143
144void LiveActions::desktop_open_appointment(const Appointment&, const DateTime& date)
145{
146 desktop_open_calendar_app(date);
147}
148
149void LiveActions::desktop_open_calendar_app(const DateTime& dt)
150{
151 const auto utc = dt.start_of_day().to_timezone("UTC");
152 auto cmd = utc.format("evolution \"calendar:///?startdate=%Y%m%dT%H%M%SZ\"");
153 execute_command(cmd.c_str());
154}
155
156/***
157****
158***/
159
160void LiveActions::phone_open_alarm_app()
161{
162 dispatch_url("appid://com.ubuntu.clock/clock/current-user-version");
163}
164
165void LiveActions::phone_open_appointment(const Appointment& appt, const DateTime& date)
166{186{
167 if (!appt.activation_url.empty())187 if (!appt.activation_url.empty())
168 {188 {
@@ -171,28 +191,16 @@
171 else switch (appt.type)191 else switch (appt.type)
172 {192 {
173 case Appointment::UBUNTU_ALARM:193 case Appointment::UBUNTU_ALARM:
174 phone_open_alarm_app();194 open_alarm_app();
175 break;195 break;
176196
177 case Appointment::EVENT:197 case Appointment::EVENT:
178 default:198 default:
179 phone_open_calendar_app(date);199 open_calendar_app(date);
180 break;200 break;
181 }201 }
182}202}
183203
184void LiveActions::phone_open_calendar_app(const DateTime& dt)
185{
186 const auto utc = dt.to_timezone("UTC");
187 auto cmd = utc.format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00");
188 dispatch_url(cmd);
189}
190
191void LiveActions::phone_open_settings_app()
192{
193 dispatch_url("settings:///system/time-date");
194}
195
196/***204/***
197****205****
198***/206***/
199207
=== modified file 'src/actions.cpp'
--- src/actions.cpp 2016-03-21 17:32:39 +0000
+++ src/actions.cpp 2016-04-28 14:56:46 +0000
@@ -62,52 +62,28 @@
62 return false;62 return false;
63}63}
6464
65void on_desktop_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself)65void on_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself)
66{66{
67 auto self = static_cast<Actions*>(gself);67 auto self = static_cast<Actions*>(gself);
68 Appointment appt;68 Appointment appt;
69 const gchar* uid = nullptr;69 const gchar* uid = nullptr;
70 gint64 time = 0;70 gint64 time = 0;
71 g_variant_get(vdata, "(&sx)", &uid, &time);71 g_variant_get(vdata, "(&sx)", &uid, &time);
72 if (lookup_appointment_by_uid(self->state(), uid, appt))72 if (lookup_appointment_by_uid(self->state(), uid, appt))
73 self->desktop_open_appointment(appt, DateTime::Local(time));73 self->open_appointment(appt, DateTime::Local(time));
74}74}
75void on_desktop_alarm_activated (GSimpleAction*, GVariant*, gpointer gself)75void on_alarm_activated (GSimpleAction*, GVariant*, gpointer gself)
76{76{
77 static_cast<Actions*>(gself)->desktop_open_alarm_app();77 static_cast<Actions*>(gself)->open_alarm_app();
78}78}
79void on_desktop_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself)79void on_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself)
80{80{
81 const auto dt = datetime_from_timet_variant(vt);81 const auto dt = datetime_from_timet_variant(vt);
82 static_cast<Actions*>(gself)->desktop_open_calendar_app(dt);82 static_cast<Actions*>(gself)->open_calendar_app(dt);
83}83}
84void on_desktop_settings_activated (GSimpleAction*, GVariant*, gpointer gself)84void on_settings_activated (GSimpleAction*, GVariant*, gpointer gself)
85{85{
86 static_cast<Actions*>(gself)->desktop_open_settings_app();86 static_cast<Actions*>(gself)->open_settings_app();
87}
88
89void on_phone_appointment_activated (GSimpleAction*, GVariant *vdata, gpointer gself)
90{
91 auto self = static_cast<Actions*>(gself);
92 Appointment appt;
93 const gchar* uid = nullptr;
94 gint64 time = 0;
95 g_variant_get(vdata, "(&sx)", &uid, &time);
96 if (lookup_appointment_by_uid(self->state(), uid, appt))
97 self->phone_open_appointment(appt, DateTime::Local(time));
98}
99void on_phone_alarm_activated (GSimpleAction*, GVariant*, gpointer gself)
100{
101 static_cast<Actions*>(gself)->phone_open_alarm_app();
102}
103void on_phone_calendar_activated (GSimpleAction*, GVariant* vt, gpointer gself)
104{
105 const auto dt = datetime_from_timet_variant(vt);
106 static_cast<Actions*>(gself)->phone_open_calendar_app(dt);
107}
108void on_phone_settings_activated (GSimpleAction*, GVariant*, gpointer gself)
109{
110 static_cast<Actions*>(gself)->phone_open_settings_app();
111}87}
11288
11389
@@ -136,9 +112,9 @@
136 }112 }
137}113}
138114
139void on_calendar_activated(GSimpleAction * /*action*/,115void on_calendar_date_activated(GSimpleAction * /*action*/,
140 GVariant * state,116 GVariant * state,
141 gpointer gself)117 gpointer gself)
142{118{
143 const time_t t = g_variant_get_int64(state);119 const time_t t = g_variant_get_int64(state);
144120
@@ -200,15 +176,15 @@
200{176{
201 GActionEntry entries[] = {177 GActionEntry entries[] = {
202178
203 { "desktop.open-appointment", on_desktop_appointment_activated, "(sx)", nullptr },179 { "desktop.open-appointment", on_appointment_activated, "(sx)", nullptr },
204 { "desktop.open-alarm-app", on_desktop_alarm_activated },180 { "desktop.open-alarm-app", on_alarm_activated },
205 { "desktop.open-calendar-app", on_desktop_calendar_activated, "x", nullptr },181 { "desktop.open-calendar-app", on_calendar_activated, "x", nullptr },
206 { "desktop.open-settings-app", on_desktop_settings_activated },182 { "desktop.open-settings-app", on_settings_activated },
207183
208 { "phone.open-appointment", on_phone_appointment_activated, "(sx)", nullptr },184 { "phone.open-appointment", on_appointment_activated, "(sx)", nullptr },
209 { "phone.open-alarm-app", on_phone_alarm_activated },185 { "phone.open-alarm-app", on_alarm_activated },
210 { "phone.open-calendar-app", on_phone_calendar_activated, "x", nullptr },186 { "phone.open-calendar-app", on_calendar_activated, "x", nullptr },
211 { "phone.open-settings-app", on_phone_settings_activated },187 { "phone.open-settings-app", on_settings_activated },
212188
213 { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed },189 { "calendar-active", nullptr, nullptr, "false", on_calendar_active_changed },
214 { "set-location", on_set_location, "s" }190 { "set-location", on_set_location, "s" }
@@ -242,7 +218,7 @@
242 v = create_calendar_state(state);218 v = create_calendar_state(state);
243 a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v);219 a = g_simple_action_new_stateful("calendar", G_VARIANT_TYPE_INT64, v);
244 g_action_map_add_action(gam, G_ACTION(a));220 g_action_map_add_action(gam, G_ACTION(a));
245 g_signal_connect(a, "activate", G_CALLBACK(on_calendar_activated), this);221 g_signal_connect(a, "activate", G_CALLBACK(on_calendar_date_activated), this);
246 g_object_unref(a);222 g_object_unref(a);
247223
248 ///224 ///
249225
=== modified file 'src/haptic.cpp'
--- src/haptic.cpp 2014-08-01 00:52:42 +0000
+++ src/haptic.cpp 2016-04-28 14:56:46 +0000
@@ -37,9 +37,10 @@
37{37{
38public:38public:
3939
40 Impl(const Mode& mode):40 Impl(const Mode& mode, bool repeat):
41 m_mode(mode),41 m_mode(mode),
42 m_cancellable(g_cancellable_new())42 m_cancellable(g_cancellable_new()),
43 m_repeat(repeat)
43 {44 {
44 g_bus_get (G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready, this);45 g_bus_get (G_BUS_TYPE_SESSION, m_cancellable, on_bus_ready, this);
45 }46 }
@@ -93,11 +94,15 @@
93 // one second on, one second off.94 // one second on, one second off.
94 m_pattern = std::vector<uint32_t>({1000u, 1000u});95 m_pattern = std::vector<uint32_t>({1000u, 1000u});
95 break;96 break;
96 }97
9798 }
98 // Set up a loop to keep repeating the pattern99
99 auto msec = std::accumulate(m_pattern.begin(), m_pattern.end(), 0u);100 if (m_repeat)
100 m_tag = g_timeout_add(msec, call_vibrate_pattern_static, this);101 {
102 // Set up a loop to keep repeating the pattern
103 auto msec = std::accumulate(m_pattern.begin(), m_pattern.end(), 0u);
104 m_tag = g_timeout_add(msec, call_vibrate_pattern_static, this);
105 }
101 call_vibrate_pattern();106 call_vibrate_pattern();
102 }107 }
103108
@@ -146,14 +151,15 @@
146 GDBusConnection * m_bus = nullptr;151 GDBusConnection * m_bus = nullptr;
147 std::vector<uint32_t> m_pattern;152 std::vector<uint32_t> m_pattern;
148 guint m_tag = 0;153 guint m_tag = 0;
154 bool m_repeat = false;
149};155};
150156
151/***157/***
152****158****
153***/159***/
154160
155Haptic::Haptic(const Mode& mode):161Haptic::Haptic(const Mode& mode, bool repeat):
156 impl(new Impl (mode))162 impl(new Impl (mode, repeat))
157{163{
158}164}
159165
160166
=== modified file 'src/main.cpp'
--- src/main.cpp 2016-04-28 14:56:46 +0000
+++ src/main.cpp 2016-04-28 14:56:46 +0000
@@ -152,7 +152,9 @@
152 auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) {152 auto on_snooze = [snooze_planner](const Appointment& appointment, const Alarm& alarm) {
153 snooze_planner->add(appointment, alarm);153 snooze_planner->add(appointment, alarm);
154 };154 };
155 auto on_ok = [](const Appointment&, const Alarm&){};155 auto on_ok = [actions](const Appointment& app, const Alarm&){
156 actions->open_appointment(app, app.begin);
157 };
156 auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) {158 auto on_alarm_reached = [&engine, &snap, &on_snooze, &on_ok](const Appointment& appointment, const Alarm& alarm) {
157 (*snap)(appointment, alarm, on_snooze, on_ok);159 (*snap)(appointment, alarm, on_snooze, on_ok);
158 engine->disable_ubuntu_alarm(appointment);160 engine->disable_ubuntu_alarm(appointment);
159161
=== modified file 'src/notifications.cpp'
--- src/notifications.cpp 2014-09-17 17:08:01 +0000
+++ src/notifications.cpp 2016-04-28 14:56:46 +0000
@@ -21,10 +21,21 @@
2121
22#include <libnotify/notify.h>22#include <libnotify/notify.h>
2323
24#include <messaging-menu/messaging-menu-app.h>
25#include <messaging-menu/messaging-menu-message.h>
26
27#include <libubuntu-app-launch-2/ubuntu-app-launch/appid.h>
28
29#include <uuid/uuid.h>
30
31#include <gio/gdesktopappinfo.h>
32
24#include <map>33#include <map>
25#include <set>34#include <set>
26#include <string>35#include <string>
27#include <vector>36#include <vector>
37#include <memory>
38
2839
29namespace unity {40namespace unity {
30namespace indicator {41namespace indicator {
@@ -45,9 +56,11 @@
45 std::string m_body;56 std::string m_body;
46 std::string m_icon_name;57 std::string m_icon_name;
47 std::chrono::seconds m_duration;58 std::chrono::seconds m_duration;
59 gint64 m_start_time {};
48 std::set<std::string> m_string_hints;60 std::set<std::string> m_string_hints;
49 std::vector<std::pair<std::string,std::string>> m_actions;61 std::vector<std::pair<std::string,std::string>> m_actions;
50 std::function<void(const std::string&)> m_closed_callback;62 std::function<void(const std::string&)> m_closed_callback;
63 std::function<void()> m_timeout_callback;
51};64};
5265
53Builder::Builder():66Builder::Builder():
@@ -101,6 +114,18 @@
101 impl->m_closed_callback.swap (cb);114 impl->m_closed_callback.swap (cb);
102}115}
103116
117void
118Builder::set_timeout_callback (std::function<void()> cb)
119{
120 impl->m_timeout_callback.swap (cb);
121}
122
123void
124Builder::set_start_time (uint64_t time)
125{
126 impl->m_start_time = time;
127}
128
104/***129/***
105****130****
106***/131***/
@@ -110,7 +135,14 @@
110 struct notification_data135 struct notification_data
111 {136 {
112 std::shared_ptr<NotifyNotification> nn;137 std::shared_ptr<NotifyNotification> nn;
113 std::function<void(const std::string&)> closed_callback;138 Builder::Impl data;
139 };
140
141 struct messaging_menu_data
142 {
143 std::string msg_id;
144 std::function<void()> callback;
145 Engine::Impl *self;
114 };146 };
115147
116public:148public:
@@ -120,13 +152,23 @@
120 {152 {
121 if (!notify_init(app_name.c_str()))153 if (!notify_init(app_name.c_str()))
122 g_critical("Unable to initialize libnotify!");154 g_critical("Unable to initialize libnotify!");
155
156 // messaging menu
157 auto app_id = calendar_app_id();
158 if (!app_id.empty()) {
159 m_messaging_app.reset(messaging_menu_app_new(app_id.c_str()), g_object_unref);
160 messaging_menu_app_register(m_messaging_app.get());
161 }
123 }162 }
124163
125 ~Impl()164 ~Impl()
126 {165 {
127 close_all ();166 close_all ();
167 remove_all ();
128168
129 notify_uninit ();169 notify_uninit ();
170 if (m_messaging_app)
171 messaging_menu_app_unregister (m_messaging_app.get());
130 }172 }
131173
132 const std::string& app_name() const174 const std::string& app_name() const
@@ -217,7 +259,7 @@
217 notification_key_quark(),259 notification_key_quark(),
218 GINT_TO_POINTER(key));260 GINT_TO_POINTER(key));
219261
220 m_notifications[key] = { nn, info.m_closed_callback };262 m_notifications[key] = { nn, info };
221 g_signal_connect (nn.get(), "closed",263 g_signal_connect (nn.get(), "closed",
222 G_CALLBACK(on_notification_closed), this);264 G_CALLBACK(on_notification_closed), this);
223 265
@@ -238,6 +280,72 @@
238 return ret;280 return ret;
239 }281 }
240282
283 std::string post(const Builder::Impl& data)
284 {
285 if (!m_messaging_app) {
286 return std::string();
287 }
288 uuid_t message_uuid;
289 uuid_generate(message_uuid);
290
291 char uuid_buf[37];
292 uuid_unparse(message_uuid, uuid_buf);
293 const std::string message_id(uuid_buf);
294
295 // use full icon path name, "calendar-app" does not work with themed icons
296 auto icon_file = g_file_new_for_path(calendar_app_icon().c_str());
297 // messaging_menu_message_new: will take control of icon object
298 GIcon *icon = g_file_icon_new(icon_file);
299 g_object_unref(icon_file);
300
301 // check if source exists
302 if (!messaging_menu_app_has_source(m_messaging_app.get(), m_app_name.c_str()))
303 messaging_menu_app_append_source(m_messaging_app.get(), m_app_name.c_str(), nullptr, "Calendar");
304
305 auto msg = messaging_menu_message_new(message_id.c_str(),
306 icon,
307 data.m_title.c_str(),
308 nullptr,
309 data.m_body.c_str(),
310 data.m_start_time * G_USEC_PER_SEC); // secs -> microsecs
311 if (msg)
312 {
313 std::shared_ptr<messaging_menu_data> msg_data(new messaging_menu_data{message_id, data.m_timeout_callback, this});
314 m_messaging_messages[message_id] = msg_data;
315 g_signal_connect(G_OBJECT(msg), "activate",
316 G_CALLBACK(on_message_activated), msg_data.get());
317 messaging_menu_app_append_message(m_messaging_app.get(), msg, m_app_name.c_str(), false);
318
319 // we use that to keep track of messaging, in case of message get cleared from menu
320 g_object_set_data_full(G_OBJECT(msg), "destroy-notify", msg_data.get(), on_message_destroyed);
321 // keep the message control with message_menu
322 g_object_unref(msg);
323
324 return message_id;
325 } else {
326 g_warning("Fail to create messaging menu message");
327 }
328 return "";
329 }
330
331 void remove (const std::string &key)
332 {
333 auto it = m_messaging_messages.find(key);
334 if (it != m_messaging_messages.end())
335 {
336 // tell the server to remove message
337 messaging_menu_app_remove_message_by_id(m_messaging_app.get(), it->second->msg_id.c_str());
338 // message will be remove by on_message_destroyed cb.
339 }
340 }
341
342 void remove_all ()
343 {
344 // call remove() on all our keys
345 while (!m_messaging_messages.empty())
346 remove(m_messaging_messages.begin()->first);
347 }
348
241private:349private:
242350
243 const std::set<std::string>& server_caps() const351 const std::set<std::string>& server_caps() const
@@ -279,6 +387,28 @@
279 static_cast<Impl*>(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey));387 static_cast<Impl*>(gself)->remove_closed_notification(GPOINTER_TO_INT(gkey));
280 }388 }
281389
390 static void on_message_activated (MessagingMenuMessage *,
391 const char *,
392 GVariant *,
393 gpointer data)
394 {
395 auto msg_data = static_cast<messaging_menu_data*>(data);
396 auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id);
397 g_return_if_fail (it != msg_data->self->m_messaging_messages.end());
398 const auto& ndata = it->second;
399
400 if (ndata->callback)
401 ndata->callback();
402 }
403
404 static void on_message_destroyed(gpointer data)
405 {
406 auto msg_data = static_cast<messaging_menu_data*>(data);
407 auto it = msg_data->self->m_messaging_messages.find(msg_data->msg_id);
408 if (it != msg_data->self->m_messaging_messages.end())
409 msg_data->self->m_messaging_messages.erase(it);
410 }
411
282 void remove_closed_notification (int key)412 void remove_closed_notification (int key)
283 {413 {
284 auto it = m_notifications.find(key);414 auto it = m_notifications.find(key);
@@ -286,25 +416,59 @@
286416
287 const auto& ndata = it->second;417 const auto& ndata = it->second;
288 auto nn = ndata.nn.get();418 auto nn = ndata.nn.get();
289 if (ndata.closed_callback)419
420 if (ndata.data.m_closed_callback)
290 {421 {
291 std::string action;422 std::string action;
292
293 const GQuark q = notification_action_quark();423 const GQuark q = notification_action_quark();
294 const gpointer p = g_object_get_qdata(G_OBJECT(nn), q);424 const gpointer p = g_object_get_qdata(G_OBJECT(nn), q);
295 if (p != nullptr)425 if (p != nullptr)
296 action = static_cast<const char*>(p);426 action = static_cast<const char*>(p);
297427
298 ndata.closed_callback (action);428 ndata.data.m_closed_callback (action);
429 // empty action means that the notification got timeout
430 // post a message on messaging menu
431 if (action.empty())
432 post(ndata.data);
299 }433 }
300434
301 m_notifications.erase(it);435 m_notifications.erase(it);
302 }436 }
303437
438 static std::string calendar_app_id()
439 {
440 auto app_id = ubuntu::app_launch::AppID::discover("com.ubuntu.calendar");
441 if (!app_id.empty())
442 // Due the use of old API by messaging_menu we need append a extra ".desktop" to the app_id.
443 return std::string(app_id) + ".desktop";
444 else
445 return std::string();
446 }
447
448 static std::string calendar_app_icon()
449 {
450 auto app_desktop = g_desktop_app_info_new(calendar_app_id().c_str());
451 if (app_desktop != nullptr) {
452 auto icon_name = g_desktop_app_info_get_string(app_desktop, "Icon");
453 g_object_unref(app_desktop);
454 if (icon_name) {
455 std::string result(icon_name);
456 g_free(icon_name);
457 return result;
458 }
459 }
460 g_warning("Fail to get calendar icon");
461 return std::string();
462 }
463
304 /***464 /***
305 ****465 ****
306 ***/466 ***/
307467
468 // messaging menu
469 std::shared_ptr<MessagingMenuApp> m_messaging_app;
470 std::map<std::string, std::shared_ptr<messaging_menu_data> > m_messaging_messages;
471
308 const std::string m_app_name;472 const std::string m_app_name;
309473
310 // key-to-data474 // key-to-data
311475
=== modified file 'src/snap.cpp'
--- src/snap.cpp 2016-04-28 14:56:46 +0000
+++ src/snap.cpp 2016-04-28 14:56:46 +0000
@@ -116,15 +116,16 @@
116 if (should_vibrate()) {116 if (should_vibrate()) {
117 const auto haptic_mode = m_settings->alarm_haptic.get();117 const auto haptic_mode = m_settings->alarm_haptic.get();
118 if (haptic_mode == "pulse")118 if (haptic_mode == "pulse")
119 haptic = std::make_shared<uin::Haptic>(uin::Haptic::MODE_PULSE);119 haptic = std::make_shared<uin::Haptic>(uin::Haptic::MODE_PULSE, appointment.is_ubuntu_alarm());
120 }120 }
121121
122 // show a notification...122 // show a notification...
123 const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get());123 const auto minutes = std::chrono::minutes(m_settings->alarm_duration.get());
124 uin::Builder b;124 uin::Builder b;
125 b.set_body (appointment.summary);125 b.set_body (appointment.summary);
126 b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "reminder");126 b.set_icon_name (appointment.is_ubuntu_alarm() ? "alarm-clock" : "calendar-app");
127 b.add_hint (uin::Builder::HINT_NONSHAPED_ICON);127 b.add_hint (uin::Builder::HINT_NONSHAPED_ICON);
128 b.set_start_time (appointment.begin.to_unix());
128129
129 const char * timefmt;130 const char * timefmt;
130 if (is_locale_12h()) {131 if (is_locale_12h()) {
@@ -150,6 +151,9 @@
150 b.add_hint (uin::Builder::HINT_AFFIRMATIVE_HINT);151 b.add_hint (uin::Builder::HINT_AFFIRMATIVE_HINT);
151 b.add_action ("ok", _("OK"));152 b.add_action ("ok", _("OK"));
152 b.add_action ("snooze", _("Snooze"));153 b.add_action ("snooze", _("Snooze"));
154 } else {
155 b.add_hint (uin::Builder::HINT_INTERACTIVE);
156 b.add_action ("ok", _("OK"));
153 }157 }
154158
155 // add 'sound', 'haptic', and 'awake' objects to the capture so159 // add 'sound', 'haptic', and 'awake' objects to the capture so
@@ -159,10 +163,17 @@
159 (const std::string& action){163 (const std::string& action){
160 if (action == "snooze")164 if (action == "snooze")
161 snooze(appointment, alarm);165 snooze(appointment, alarm);
162 else166 else if (action == "ok")
163 ok(appointment, alarm);167 ok(appointment, alarm);
164 });168 });
165169
170 //TODO: we need to extend it to support alarms appoitments
171 if (!appointment.is_ubuntu_alarm()) {
172 b.set_timeout_callback([appointment, alarm, ok](){
173 ok(appointment, alarm);
174 });
175 }
176
166 const auto key = m_engine->show(b);177 const auto key = m_engine->show(b);
167 if (key)178 if (key)
168 m_notifications.insert (key);179 m_notifications.insert (key);
169180
=== modified file 'tests/actions-mock.h'
--- tests/actions-mock.h 2016-03-21 17:32:39 +0000
+++ tests/actions-mock.h 2016-04-28 14:56:46 +0000
@@ -34,14 +34,10 @@
34 explicit MockActions(const std::shared_ptr<State>& state_in): Actions(state_in) {}34 explicit MockActions(const std::shared_ptr<State>& state_in): Actions(state_in) {}
35 ~MockActions() =default;35 ~MockActions() =default;
3636
37 enum Action { DesktopOpenAlarmApp,37 enum Action { OpenAlarmApp,
38 DesktopOpenAppt,38 OpenAppt,
39 DesktopOpenCalendarApp,39 OpenCalendarApp,
40 DesktopOpenSettingsApp,40 OpenSettingsApp,
41 PhoneOpenAlarmApp,
42 PhoneOpenAppt,
43 PhoneOpenCalendarApp,
44 PhoneOpenSettingsApp,
45 SetLocation };41 SetLocation };
4642
47 const std::vector<Action>& history() const { return m_history; }43 const std::vector<Action>& history() const { return m_history; }
@@ -54,36 +50,20 @@
54 bool desktop_has_calendar_app() const {50 bool desktop_has_calendar_app() const {
55 return m_desktop_has_calendar_app;51 return m_desktop_has_calendar_app;
56 }52 }
57 void desktop_open_alarm_app() {53 void open_alarm_app() {
58 m_history.push_back(DesktopOpenAlarmApp);54 m_history.push_back(OpenAlarmApp);
59 }55 }
60 void desktop_open_appointment(const Appointment& appt, const DateTime& dt) {56 void open_appointment(const Appointment& appt, const DateTime& dt) {
61 m_appt = appt;57 m_appt = appt;
62 m_date_time = dt;58 m_date_time = dt;
63 m_history.push_back(DesktopOpenAppt);59 m_history.push_back(OpenAppt);
64 }60 }
65 void desktop_open_calendar_app(const DateTime& dt) {61 void open_calendar_app(const DateTime& dt) {
66 m_date_time = dt;62 m_date_time = dt;
67 m_history.push_back(DesktopOpenCalendarApp);63 m_history.push_back(OpenCalendarApp);
68 }64 }
69 void desktop_open_settings_app() {65 void open_settings_app() {
70 m_history.push_back(DesktopOpenSettingsApp);66 m_history.push_back(OpenSettingsApp);
71 }
72
73 void phone_open_alarm_app() {
74 m_history.push_back(PhoneOpenAlarmApp);
75 }
76 void phone_open_appointment(const Appointment& appt, const DateTime& dt) {
77 m_appt = appt;
78 m_date_time = dt;
79 m_history.push_back(PhoneOpenAppt);
80 }
81 void phone_open_calendar_app(const DateTime& dt) {
82 m_date_time = dt;
83 m_history.push_back(PhoneOpenCalendarApp);
84 }
85 void phone_open_settings_app() {
86 m_history.push_back(PhoneOpenSettingsApp);
87 }67 }
8868
89 void set_location(const std::string& zone_, const std::string& name_) {69 void set_location(const std::string& zone_, const std::string& name_) {
9070
=== modified file 'tests/test-actions.cpp'
--- tests/test-actions.cpp 2016-03-21 17:32:39 +0000
+++ tests/test-actions.cpp 2016-04-28 14:56:46 +0000
@@ -175,25 +175,25 @@
175TEST_F(ActionsFixture, DesktopOpenAlarmApp)175TEST_F(ActionsFixture, DesktopOpenAlarmApp)
176{176{
177 test_action_with_no_args("desktop.open-alarm-app",177 test_action_with_no_args("desktop.open-alarm-app",
178 MockActions::DesktopOpenAlarmApp);178 MockActions::OpenAlarmApp);
179}179}
180180
181TEST_F(ActionsFixture, DesktopOpenAppointment)181TEST_F(ActionsFixture, DesktopOpenAppointment)
182{182{
183 test_action_with_appt_arg("desktop.open-appointment",183 test_action_with_appt_arg("desktop.open-appointment",
184 MockActions::DesktopOpenAppt);184 MockActions::OpenAppt);
185}185}
186186
187TEST_F(ActionsFixture, DesktopOpenCalendarApp)187TEST_F(ActionsFixture, DesktopOpenCalendarApp)
188{188{
189 test_action_with_time_arg("desktop.open-calendar-app",189 test_action_with_time_arg("desktop.open-calendar-app",
190 MockActions::DesktopOpenCalendarApp);190 MockActions::OpenCalendarApp);
191}191}
192192
193TEST_F(ActionsFixture, DesktopOpenSettingsApp)193TEST_F(ActionsFixture, DesktopOpenSettingsApp)
194{194{
195 test_action_with_no_args("desktop.open-settings-app",195 test_action_with_no_args("desktop.open-settings-app",
196 MockActions::DesktopOpenSettingsApp);196 MockActions::OpenSettingsApp);
197}197}
198198
199/***199/***
@@ -203,25 +203,25 @@
203TEST_F(ActionsFixture, PhoneOpenAlarmApp)203TEST_F(ActionsFixture, PhoneOpenAlarmApp)
204{204{
205 test_action_with_no_args("phone.open-alarm-app",205 test_action_with_no_args("phone.open-alarm-app",
206 MockActions::PhoneOpenAlarmApp);206 MockActions::OpenAlarmApp);
207}207}
208208
209TEST_F(ActionsFixture, PhoneOpenAppointment)209TEST_F(ActionsFixture, PhoneOpenAppointment)
210{210{
211 test_action_with_appt_arg("phone.open-appointment",211 test_action_with_appt_arg("phone.open-appointment",
212 MockActions::PhoneOpenAppt);212 MockActions::OpenAppt);
213}213}
214214
215TEST_F(ActionsFixture, PhoneOpenCalendarApp)215TEST_F(ActionsFixture, PhoneOpenCalendarApp)
216{216{
217 test_action_with_time_arg("phone.open-calendar-app",217 test_action_with_time_arg("phone.open-calendar-app",
218 MockActions::PhoneOpenCalendarApp);218 MockActions::OpenCalendarApp);
219}219}
220220
221TEST_F(ActionsFixture, PhoneOpenSettingsApp)221TEST_F(ActionsFixture, PhoneOpenSettingsApp)
222{222{
223 test_action_with_no_args("phone.open-settings-app",223 test_action_with_no_args("phone.open-settings-app",
224 MockActions::PhoneOpenSettingsApp);224 MockActions::OpenSettingsApp);
225}225}
226226
227/***227/***
228228
=== modified file 'tests/test-live-actions.cpp'
--- tests/test-live-actions.cpp 2016-04-10 00:07:04 +0000
+++ tests/test-live-actions.cpp 2016-04-28 14:56:46 +0000
@@ -29,10 +29,16 @@
29public:29public:
30 std::string last_cmd;30 std::string last_cmd;
31 std::string last_url;31 std::string last_url;
32
33
32 explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {}34 explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {}
33 ~MockLiveActions() {}35 ~MockLiveActions() {}
36 void set_desktop(LiveActions::Desktop desktop) { m_desktop = desktop; }
3437
35protected:38protected:
39 LiveActions::Desktop m_desktop;
40
41 LiveActions::Desktop get_desktop() override { return m_desktop; }
36 void dispatch_url(const std::string& url) override { last_url = url; }42 void dispatch_url(const std::string& url) override { last_url = url; }
37 void execute_command(const std::string& cmd) override { last_cmd = cmd; }43 void execute_command(const std::string& cmd) override { last_cmd = cmd; }
38};44};
@@ -112,31 +118,39 @@
112118
113TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp)119TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp)
114{120{
115 m_actions->desktop_open_alarm_app();121 m_live_actions->set_desktop(LiveActions::UNITY7);
122
123 m_actions->open_alarm_app();
116 const std::string expected = "evolution -c calendar";124 const std::string expected = "evolution -c calendar";
117 EXPECT_EQ(expected, m_live_actions->last_cmd);125 EXPECT_EQ(expected, m_live_actions->last_cmd);
118}126}
119127
120TEST_F(TestLiveActionsFixture, DesktopOpenAppointment)128TEST_F(TestLiveActionsFixture, DesktopOpenAppointment)
121{129{
130 m_live_actions->set_desktop(LiveActions::UNITY7);
131
122 Appointment a;132 Appointment a;
123 a.uid = "some-uid";133 a.uid = "some-uid";
124 a.begin = DateTime::NowLocal();134 a.begin = DateTime::NowLocal();
125 m_actions->desktop_open_appointment(a, a.begin);135 m_actions->open_appointment(a, a.begin);
126 const std::string expected_substr = "evolution \"calendar:///?startdate=";136 const std::string expected_substr = "evolution \"calendar:///?startdate=";
127 EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);137 EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);
128}138}
129139
130TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp)140TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp)
131{141{
132 m_actions->desktop_open_calendar_app(DateTime::NowLocal());142 m_live_actions->set_desktop(LiveActions::UNITY7);
143
144 m_actions->open_calendar_app(DateTime::NowLocal());
133 const std::string expected_substr = "evolution \"calendar:///?startdate=";145 const std::string expected_substr = "evolution \"calendar:///?startdate=";
134 EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);146 EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);
135}147}
136148
137TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp)149TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp)
138{150{
139 m_actions->desktop_open_settings_app();151 m_live_actions->set_desktop(LiveActions::UNITY7);
152
153 m_actions->open_settings_app();
140 const std::string expected_substr = "control-center";154 const std::string expected_substr = "control-center";
141 EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);155 EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos);
142}156}
@@ -152,12 +166,16 @@
152166
153TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp)167TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp)
154{168{
155 m_actions->phone_open_alarm_app();169 m_live_actions->set_desktop(LiveActions::UNITY8);
170
171 m_actions->open_alarm_app();
156 EXPECT_EQ(clock_app_url, m_live_actions->last_url);172 EXPECT_EQ(clock_app_url, m_live_actions->last_url);
157}173}
158174
159TEST_F(TestLiveActionsFixture, PhoneOpenAppointment)175TEST_F(TestLiveActionsFixture, PhoneOpenAppointment)
160{176{
177 m_live_actions->set_desktop(LiveActions::UNITY8);
178
161 Appointment a;179 Appointment a;
162180
163 a.uid = "event-uid";181 a.uid = "event-uid";
@@ -165,19 +183,21 @@
165 a.begin = DateTime::NowLocal();183 a.begin = DateTime::NowLocal();
166 a.type = Appointment::EVENT;184 a.type = Appointment::EVENT;
167 auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0);185 auto ocurrenceDate = DateTime::Local(2014, 1, 1, 0, 0, 0);
168 m_actions->phone_open_appointment(a, ocurrenceDate);186 m_actions->open_appointment(a, ocurrenceDate);
169 const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00");187 const std::string appointment_app_url = ocurrenceDate.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00");
170 EXPECT_EQ(appointment_app_url, m_live_actions->last_url);188 EXPECT_EQ(appointment_app_url, m_live_actions->last_url);
171189
172 a.type = Appointment::UBUNTU_ALARM;190 a.type = Appointment::UBUNTU_ALARM;
173 m_actions->phone_open_appointment(a, a.begin);191 m_actions->open_appointment(a, a.begin);
174 EXPECT_EQ(clock_app_url, m_live_actions->last_url);192 EXPECT_EQ(clock_app_url, m_live_actions->last_url);
175}193}
176194
177TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp)195TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp)
178{196{
197 m_live_actions->set_desktop(LiveActions::UNITY8);
198
179 auto now = DateTime::NowLocal();199 auto now = DateTime::NowLocal();
180 m_actions->phone_open_calendar_app(now);200 m_actions->open_calendar_app(now);
181 const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00");201 const std::string expected = now.to_timezone("UTC").format("calendar://startdate=%Y-%m-%dT%H:%M:%S+00:00");
182 EXPECT_EQ(expected, m_live_actions->last_url);202 EXPECT_EQ(expected, m_live_actions->last_url);
183}203}
@@ -185,7 +205,9 @@
185205
186TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp)206TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp)
187{207{
188 m_actions->phone_open_settings_app();208 m_live_actions->set_desktop(LiveActions::UNITY8);
209
210 m_actions->open_settings_app();
189 const std::string expected = "settings:///system/time-date";211 const std::string expected = "settings:///system/time-date";
190 EXPECT_EQ(expected, m_live_actions->last_url);212 EXPECT_EQ(expected, m_live_actions->last_url);
191}213}
192214
=== modified file 'tests/test-notification.cpp'
--- tests/test-notification.cpp 2016-02-11 04:30:46 +0000
+++ tests/test-notification.cpp 2016-04-28 14:56:46 +0000
@@ -63,7 +63,7 @@
63 bool expected_notify_called;63 bool expected_notify_called;
64 bool expected_vibrate_called;64 bool expected_vibrate_called;
65 } test_appts[] = {65 } test_appts[] = {
66 { appt, "reminder", "Event", true, true },66 { appt, "calendar-app", "Event", true, true },
67 { ualarm, "alarm-clock", "Alarm", true, true }67 { ualarm, "alarm-clock", "Alarm", true, true }
68 };68 };
6969
7070
=== modified file 'tests/test-sound.cpp'
--- tests/test-sound.cpp 2016-02-10 20:49:01 +0000
+++ tests/test-sound.cpp 2016-04-28 14:56:46 +0000
@@ -85,7 +85,7 @@
8585
86 // confirm that the icon passed to Notify was "alarm-clock"86 // confirm that the icon passed to Notify was "alarm-clock"
87 g_variant_get_child (params, 2, "&s", &str);87 g_variant_get_child (params, 2, "&s", &str);
88 ASSERT_STREQ("reminder", str);88 ASSERT_STREQ("calendar-app", str);
8989
90 // confirm that the hints passed to Notify included a timeout matching duration_minutes90 // confirm that the hints passed to Notify included a timeout matching duration_minutes
91 int32_t i32;91 int32_t i32;

Subscribers

People subscribed via source and target branches