Merge lp:~charlesk/indicator-datetime/lp-1283142 into lp:indicator-datetime/14.04

Proposed by Charles Kerr
Status: Merged
Merged at revision: 317
Proposed branch: lp:~charlesk/indicator-datetime/lp-1283142
Merge into: lp:indicator-datetime/14.04
Diff against target: 111 lines (+68/-7)
1 file modified
src/snap.cpp (+68/-7)
To merge this branch: bzr merge lp:~charlesk/indicator-datetime/lp-1283142
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Lars Karlitski (community) Approve
Sebastien Bacher Needs Information
Review via email: mp+208503@code.launchpad.net

Commit message

When the notification engine is notify-osd, use bubble notifications instead of the phone's snap decisions.

Description of the change

When the notification engine is notify-osd, use bubble notifications instead of the phone's snap decisions.

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
Sebastien Bacher (seb128) wrote :

Thanks Charles! Looks fine to me but I've one small question

> is_notify_osd = !g_strcmp0(name, "notify-osd");

is special casing notify-osd really the right thing to do there? would it make more sense to use notify_get_server_caps() instead?

review: Needs Information
Revision history for this message
Lars Karlitski (larsu) wrote :

I agree with Seb, we should check for the capabilities instead of the server's name.

Why did you remove stop_alarm_sound() from the action callbacks? According to the spec[1], a server doesn't have to send CloseNotification in that case. notify-osd seems to to so, though.

show_notification() handles stopping of sound when the bubble type is snap decision, but not starting the sound. That's decided in notify(). It might make sense to put these together somehow.

I think having sound on the desktop would make a lot of sense as well. Is it gone because there's no easy way to dismiss it without buttons on notifications?

[1] https://developer.gnome.org/notification-spec/

Revision history for this message
Charles Kerr (charlesk) wrote :

>> is special casing notify-osd really the right thing to do there?
>> would it make more sense to use notify_get_server_caps() instead?
>
> I agree with Seb, we should check for the capabilities instead of the server's name.

That's reasonable. We could look to see if the notification server supports actions, which unity-notifications does and notify-osd does not. If actions are supported, then we would use the notify_notification_add_action() block of code in show_notification(). seb, larsu, what do you think of that?

> Why did you remove stop_alarm_sound() from the action callbacks?
> According to the spec[1], a server doesn't have to send CloseNotification
> in that case. notify-osd seems to to so, though.

The spec doesn't seem to say that; could you clarify?

Regardless, I don't mind re-adding the stop_alarm_sound() call to the
action callbacks as a safeguard.

> I think having sound on the desktop would make a lot of sense as well.
> Is it gone because there's no easy way to dismiss it without buttons on
> notifications?

Yes, that's the main issue. You don't want to have a looping sound that
you can't dismiss. :)

OTOH, maybe a one-time sound would be appropriate?

Revision history for this message
Sebastien Bacher (seb128) wrote :

> If actions are supported, then we would use the notify_notification_add_action() block of code in show_notification(). seb, larsu, what do you think of that?

That seems good to me

> OTOH, maybe a one-time sound would be appropriate?

I we have a sound played on the desktop I think we should have an UI somewhere to opt out from playing it...

Revision history for this message
Charles Kerr (charlesk) wrote :

I agree, there needs to be a user-visible way to opt out of audible feedback. We also have higher priority TODO items so close to LTS freeze.

Let's table the audible feedback on desktop for now.

315. By Charles Kerr

when deciding whether to do a bubble or snap notification, see if the server supports actions.

316. By Charles Kerr

when a notify action is activated, call stop_audio_loop() in case the notify server doesn't also send back a 'closed' signal.

Revision history for this message
Charles Kerr (charlesk) wrote :

> I agree with Seb, we should check for the capabilities instead of the server's name.

Fixed r315

> According to the spec[1], a server doesn't have to send CloseNotification

Re-added r316

Revision history for this message
Lars Karlitski (larsu) wrote :

Looks good to me now. Thanks!

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/snap.cpp'
2--- src/snap.cpp 2014-02-05 23:04:00 +0000
3+++ src/snap.cpp 2014-02-27 16:15:19 +0000
4@@ -27,6 +27,9 @@
5 #include <glib/gi18n.h>
6 #include <glib.h>
7
8+#include <set>
9+#include <string>
10+
11 #define ALARM_SOUND_FILENAME "/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg"
12
13 namespace unity {
14@@ -169,12 +172,57 @@
15 data->dismiss(data->appointment);
16 }
17
18+void on_snap_closed(NotifyNotification*, gpointer)
19+{
20+ stop_alarm_sound();
21+}
22+
23 void snap_data_destroy_notify(gpointer gdata)
24 {
25 delete static_cast<SnapData*>(gdata);
26 }
27
28-void show_snap_decision(SnapData* data)
29+std::set<std::string> get_server_caps()
30+{
31+ std::set<std::string> caps_set;
32+ auto caps_gl = notify_get_server_caps();
33+ for(auto l=caps_gl; l!=nullptr; l=l->next)
34+ caps_set.insert((const char*)l->data);
35+ g_list_free_full(caps_gl, g_free);
36+ return caps_set;
37+}
38+
39+typedef enum
40+{
41+ // just a bubble... no actions, no audio
42+ NOTIFY_MODE_BUBBLE,
43+
44+ // a snap decision popup dialog + audio
45+ NOTIFY_MODE_SNAP
46+}
47+NotifyMode;
48+
49+NotifyMode get_notify_mode()
50+{
51+ static NotifyMode mode;
52+ static bool mode_inited = false;
53+
54+ if (G_UNLIKELY(!mode_inited))
55+ {
56+ const auto caps = get_server_caps();
57+
58+ if (caps.count("actions"))
59+ mode = NOTIFY_MODE_SNAP;
60+ else
61+ mode = NOTIFY_MODE_BUBBLE;
62+
63+ mode_inited = true;
64+ }
65+
66+ return mode;
67+}
68+
69+void show_notification (SnapData* data, NotifyMode mode)
70 {
71 const Appointment& appointment = data->appointment;
72
73@@ -184,10 +232,14 @@
74 const gchar* icon_name = "alarm-clock";
75
76 auto nn = notify_notification_new(title, body.c_str(), icon_name);
77- notify_notification_set_hint_string(nn, "x-canonical-snap-decisions", "true");
78- notify_notification_set_hint_string(nn, "x-canonical-private-button-tint", "true");
79- notify_notification_add_action(nn, "show", _("Show"), on_snap_show, data, nullptr);
80- notify_notification_add_action(nn, "dismiss", _("Dismiss"), on_snap_dismiss, data, nullptr);
81+ if (mode == NOTIFY_MODE_SNAP)
82+ {
83+ notify_notification_set_hint_string(nn, "x-canonical-snap-decisions", "true");
84+ notify_notification_set_hint_string(nn, "x-canonical-private-button-tint", "true");
85+ notify_notification_add_action(nn, "show", _("Show"), on_snap_show, data, nullptr);
86+ notify_notification_add_action(nn, "dismiss", _("Dismiss"), on_snap_dismiss, data, nullptr);
87+ g_signal_connect(G_OBJECT(nn), "closed", G_CALLBACK(on_snap_closed), data);
88+ }
89 g_object_set_data_full(G_OBJECT(nn), "snap-data", data, snap_data_destroy_notify);
90
91 GError * error = nullptr;
92@@ -215,8 +267,17 @@
93 data->show = show;
94 data->dismiss = dismiss;
95
96- play_alarm_sound();
97- show_snap_decision(data);
98+ switch (get_notify_mode())
99+ {
100+ case NOTIFY_MODE_BUBBLE:
101+ show_notification(data, NOTIFY_MODE_BUBBLE);
102+ break;
103+
104+ default:
105+ show_notification(data, NOTIFY_MODE_SNAP);
106+ play_alarm_sound();
107+ break;
108+ }
109 }
110
111 } // unnamed namespace

Subscribers

People subscribed via source and target branches