Merge lp:~dylanmccall/indicator-sound/notifications-use-new-volume into lp:~indicator-applet-developers/indicator-sound/trunk_3

Proposed by Dylan McCall
Status: Merged
Merge reported by: Conor Curran
Merged at revision: not available
Proposed branch: lp:~dylanmccall/indicator-sound/notifications-use-new-volume
Merge into: lp:~indicator-applet-developers/indicator-sound/trunk_3
Diff against target: 179 lines (+88/-21)
5 files modified
src/Makefile.am (+4/-0)
src/device.c (+2/-15)
src/sound-state-manager.c (+8/-6)
src/sound-state.c (+43/-0)
src/sound-state.h (+31/-0)
To merge this branch: bzr merge lp:~dylanmccall/indicator-sound/notifications-use-new-volume
Reviewer Review Type Date Requested Status
Conor Curran (community) Approve
Review via email: mp+56284@code.launchpad.net

Description of the change

This fixes the issue in bug #748831. Further pixel counting revealed that the issue was not the entire notification, but the icon selected for the notification. sound_state_manager_show_notification was calling a function that returned the _current_ SoundState in order to choose a notification, but the function itself is called before the sound state changes. (From the looks of it, that is unavoidable without some deep changes).

The only reason for calling this function is to figure out which of the four sound levels the volume fits in. So, I split the code to get a SoundState object from the volume into its own function (sound_state_get_from_volume), called by sound_state_manager_show_notification and device_get_state_from_volume.

The notification function seems to already make the assumption that it isn't going to be called for anything with SoundState == UNAVAILABLE, so I'm sticking to that assumption here.

I couldn't find a particularly nice place to put the new sound_state function, so I made a new pair of source files: sound-state.c and sound-state.h.

While I was at it, I happened to change the function to use the notification-audio-volume-* icons instead of just the audio-volume-* ones. This has no visible change with the existing icon themes, but it lines us up with gnome-settings-daemon, which uses those.

To post a comment you must log in.
Revision history for this message
Conor Curran (cjcurran) wrote :

Looks good to me ! Thanks Dylan

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Makefile.am'
2--- src/Makefile.am 2011-03-17 16:10:03 +0000
3+++ src/Makefile.am 2011-04-05 03:33:00 +0000
4@@ -10,6 +10,8 @@
5 common-defs.h \
6 indicator-sound.h \
7 indicator-sound.c \
8+ sound-state.c \
9+ sound-state.h \
10 sound-state-manager.c \
11 sound-state-manager.h \
12 transport-widget.c \
13@@ -90,6 +92,8 @@
14 common-defs.h \
15 sound-service.h \
16 sound-service.c \
17+ sound-state.c \
18+ sound-state.h \
19 pulseaudio-mgr.h \
20 pulseaudio-mgr.c \
21 device.c \
22
23=== modified file 'src/device.c'
24--- src/device.c 2011-03-15 15:23:09 +0000
25+++ src/device.c 2011-04-05 03:33:00 +0000
26@@ -23,6 +23,7 @@
27 #include "mute-menu-item.h"
28 #include "voip-input-menu-item.h"
29 #include "pulseaudio-mgr.h"
30+#include "sound-state.h"
31
32 typedef struct _DevicePrivate DevicePrivate;
33
34@@ -164,21 +165,7 @@
35 DBUSMENU_VOLUME_MENUITEM_LEVEL);
36 gdouble volume_percent = g_variant_get_double (v);
37
38- SoundState state = LOW_LEVEL;
39-
40- if (volume_percent < 30.0 && volume_percent > 0) {
41- state = LOW_LEVEL;
42- }
43- else if (volume_percent < 70.0 && volume_percent >= 30.0) {
44- state = MEDIUM_LEVEL;
45- }
46- else if (volume_percent >= 70.0) {
47- state = HIGH_LEVEL;
48- }
49- else if (volume_percent == 0.0) {
50- state = ZERO_LEVEL;
51- }
52- return state;
53+ return sound_state_get_from_volume ((int)volume_percent);
54 }
55
56 void
57
58=== modified file 'src/sound-state-manager.c'
59--- src/sound-state-manager.c 2011-03-05 20:27:39 +0000
60+++ src/sound-state-manager.c 2011-04-05 03:33:00 +0000
61@@ -24,6 +24,7 @@
62
63 #include "sound-state-manager.h"
64 #include "dbus-shared-names.h"
65+#include "sound-state.h"
66
67 typedef struct _SoundStateManagerPrivate SoundStateManagerPrivate;
68
69@@ -170,19 +171,20 @@
70
71 char *icon;
72 const int notify_value = CLAMP((int)value, -1, 101);
73- SoundState state = sound_state_manager_get_current_state (self);
74+
75+ SoundState state = sound_state_get_from_volume ((int)value);
76
77 if (state == ZERO_LEVEL) {
78 // Not available for all the themes
79- icon = "audio-volume-off";
80+ icon = "notification-audio-volume-off";
81 } else if (state == LOW_LEVEL) {
82- icon = "audio-volume-low";
83+ icon = "notification-audio-volume-low";
84 } else if (state == MEDIUM_LEVEL) {
85- icon = "audio-volume-medium";
86+ icon = "notification-audio-volume-medium";
87 } else if (state == HIGH_LEVEL) {
88- icon = "audio-volume-high";
89+ icon = "notification-audio-volume-high";
90 } else {
91- icon = "audio-volume-muted";
92+ icon = "notification-audio-volume-muted";
93 }
94
95 notify_notification_update(priv->notification, PACKAGE_NAME, NULL, icon);
96
97=== added file 'src/sound-state.c'
98--- src/sound-state.c 1970-01-01 00:00:00 +0000
99+++ src/sound-state.c 2011-04-05 03:33:00 +0000
100@@ -0,0 +1,43 @@
101+/*
102+Copyright 2010 Canonical Ltd.
103+
104+Authors:
105+ Conor Curran <conor.curran@canonical.com>
106+
107+This program is free software: you can redistribute it and/or modify it
108+under the terms of the GNU General Public License version 3, as published
109+by the Free Software Foundation.
110+
111+This program is distributed in the hope that it will be useful, but
112+WITHOUT ANY WARRANTY; without even the implied warranties of
113+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
114+PURPOSE. See the GNU General Public License for more details.
115+
116+You should have received a copy of the GNU General Public License along
117+with this program. If not, see <http://www.gnu.org/licenses/>.
118+*/
119+
120+#include "config.h"
121+
122+#include "sound-state.h"
123+
124+SoundState
125+sound_state_get_from_volume (int volume_percent)
126+{
127+ SoundState state = LOW_LEVEL;
128+
129+ if (volume_percent < 30 && volume_percent > 0) {
130+ state = LOW_LEVEL;
131+ }
132+ else if (volume_percent < 70 && volume_percent >= 30) {
133+ state = MEDIUM_LEVEL;
134+ }
135+ else if (volume_percent >= 70) {
136+ state = HIGH_LEVEL;
137+ }
138+ else if (volume_percent <= 0) {
139+ state = ZERO_LEVEL;
140+ }
141+ return state;
142+}
143+
144
145=== added file 'src/sound-state.h'
146--- src/sound-state.h 1970-01-01 00:00:00 +0000
147+++ src/sound-state.h 2011-04-05 03:33:00 +0000
148@@ -0,0 +1,31 @@
149+/*
150+Copyright 2011 Canonical Ltd.
151+
152+Authors:
153+ Conor Curran <conor.curran@canonical.com>
154+
155+This program is free software: you can redistribute it and/or modify it
156+under the terms of the GNU General Public License version 3, as published
157+by the Free Software Foundation.
158+
159+This program is distributed in the hope that it will be useful, but
160+WITHOUT ANY WARRANTY; without even the implied warranties of
161+MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
162+PURPOSE. See the GNU General Public License for more details.
163+
164+You should have received a copy of the GNU General Public License along
165+with this program. If not, see <http://www.gnu.org/licenses/>.
166+*/
167+
168+#ifndef _SOUND_STATE_H_
169+#define _SOUND_STATE_H_
170+
171+#include <glib.h>
172+#include "common-defs.h"
173+
174+/* Helper functions for determining SOUNDSTATE */
175+
176+SoundState sound_state_get_from_volume (int volume_percent);
177+
178+#endif /* _SOUND_STATE_H_ */
179+

Subscribers

People subscribed via source and target branches