Merge lp:~ted/indicator-sound/silent-mode into lp:~ted/indicator-sound/lp1358340-greeter-data

Proposed by Ted Gould
Status: Superseded
Proposed branch: lp:~ted/indicator-sound/silent-mode
Merge into: lp:~ted/indicator-sound/lp1358340-greeter-data
Diff against target: 284 lines (+141/-17)
5 files modified
src/CMakeLists.txt (+4/-0)
src/accounts-service-system-sound-settings.vala (+25/-0)
src/accounts-service-user.vala (+40/-0)
src/service.vala (+63/-16)
src/sound-menu.vala (+9/-1)
To merge this branch: bzr merge lp:~ted/indicator-sound/silent-mode
Reviewer Review Type Date Requested Status
Ted Gould Pending
Review via email: mp+236969@code.launchpad.net

This proposal has been superseded by a proposal from 2014-10-02.

Commit message

Show a silent mode checkbox and respond to state in the icon

Description of the change

Silent mode doesn't appear to actually do anything, and I can't figure out who should be doing something about that. But now it shows in the indicator and on the panel.

To post a comment you must log in.
lp:~ted/indicator-sound/silent-mode updated
458. By Ted Gould

Don't represent silent mode in the indicator

459. By Ted Gould

Update to current trunk

Unmerged revisions

459. By Ted Gould

Update to current trunk

458. By Ted Gould

Don't represent silent mode in the indicator

457. By Ted Gould

Build the volume control first

456. By Ted Gould

Make it a switch

455. By Ted Gould

Add a silent mode menu item

454. By Ted Gould

Pull complex logic into its own function

453. By Ted Gould

Create a silent mode action

452. By Ted Gould

Backup the properties with a local value and set the proxy

451. By Ted Gould

Use silent mode to determine the icon on the panel

450. By Ted Gould

Turn the system sound proxy into a silent mode property

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2014-09-23 16:18:17 +0000
3+++ src/CMakeLists.txt 2014-10-02 21:55:45 +0000
4@@ -104,6 +104,7 @@
5 mpris2-interfaces
6 accounts-service-sound-settings
7 accounts-service-privacy-settings
8+ accounts-service-system-sound-settings
9 greeter-broadcast
10 )
11 vala_add(indicator-sound-service
12@@ -113,6 +114,9 @@
13 accounts-service-privacy-settings.vala
14 )
15 vala_add(indicator-sound-service
16+ accounts-service-system-sound-settings.vala
17+)
18+vala_add(indicator-sound-service
19 greeter-broadcast.vala
20 )
21
22
23=== added file 'src/accounts-service-system-sound-settings.vala'
24--- src/accounts-service-system-sound-settings.vala 1970-01-01 00:00:00 +0000
25+++ src/accounts-service-system-sound-settings.vala 2014-10-02 21:55:45 +0000
26@@ -0,0 +1,25 @@
27+/*
28+ * Copyright 2014 © Canonical Ltd.
29+ *
30+ * This program is free software; you can redistribute it and/or modify
31+ * it under the terms of the GNU General Public License as published by
32+ * the Free Software Foundation; version 3.
33+ *
34+ * This program is distributed in the hope that it will be useful,
35+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
36+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37+ * GNU General Public License for more details.
38+ *
39+ * You should have received a copy of the GNU General Public License
40+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
41+ *
42+ * Authors:
43+ * Ted Gould <ted@canonical.com>
44+ */
45+
46+[DBus (name = "com.ubuntu.touch.AccountsService.Sound")]
47+public interface AccountsServiceSystemSoundSettings : Object {
48+ // properties
49+ public abstract bool silent_mode {owned get; set;}
50+}
51+
52
53=== modified file 'src/accounts-service-user.vala'
54--- src/accounts-service-user.vala 2014-10-01 21:53:31 +0000
55+++ src/accounts-service-user.vala 2014-10-02 21:55:45 +0000
56@@ -22,12 +22,24 @@
57 Act.User? user = null;
58 AccountsServiceSoundSettings? proxy = null;
59 AccountsServicePrivacySettings? privacyproxy = null;
60+ AccountsServiceSystemSoundSettings? syssoundproxy = null;
61 uint timer = 0;
62 MediaPlayer? _player = null;
63 GreeterBroadcast? greeter = null;
64
65 public bool showDataOnGreeter { get; set; }
66
67+ bool _silentMode = false;
68+ public bool silentMode {
69+ get {
70+ return _silentMode;
71+ }
72+ set {
73+ if (syssoundproxy != null)
74+ syssoundproxy.silent_mode = value;
75+ }
76+ }
77+
78 public MediaPlayer? player {
79 set {
80 this._player = value;
81@@ -136,6 +148,14 @@
82 DBusProxyFlags.GET_INVALIDATED_PROPERTIES,
83 null,
84 new_privacy_proxy);
85+
86+ Bus.get_proxy.begin<AccountsServiceSystemSoundSettings> (
87+ BusType.SYSTEM,
88+ "org.freedesktop.Accounts",
89+ user.get_object_path(),
90+ DBusProxyFlags.GET_INVALIDATED_PROPERTIES,
91+ null,
92+ new_system_sound_proxy);
93 }
94 }
95
96@@ -178,6 +198,26 @@
97 }
98 }
99
100+ void new_system_sound_proxy (GLib.Object? obj, AsyncResult res) {
101+ try {
102+ this.syssoundproxy = Bus.get_proxy.end (res);
103+
104+ (this.syssoundproxy as DBusProxy).g_properties_changed.connect((proxy, changed, invalid) => {
105+ var silentvar = changed.lookup_value("SilentMode", new VariantType("b"));
106+ if (silentvar != null) {
107+ debug("Silent Mode changed");
108+ this._silentMode = silentvar.get_boolean();
109+ this.notify_property("silentMode");
110+ }
111+ });
112+
113+ this.silentMode = this.syssoundproxy.silent_mode;
114+ } catch (Error e) {
115+ this.syssoundproxy = null;
116+ warning("Unable to get proxy to system sound settings: %s", e.message);
117+ }
118+ }
119+
120 void greeter_proxy_new (GLib.Object? obj, AsyncResult res) {
121 try {
122 this.greeter = Bus.get_proxy.end (res);
123
124=== modified file 'src/service.vala'
125--- src/service.vala 2014-09-26 19:25:25 +0000
126+++ src/service.vala 2014-10-02 21:55:45 +0000
127@@ -27,38 +27,39 @@
128
129 this.volume_control = new VolumeControl ();
130
131+ /* If we're on the greeter, don't export */
132+ if (GLib.Environment.get_user_name() != "lightdm") {
133+ this.accounts_service = new AccountsServiceUser();
134+
135+ this.accounts_service.notify["showDataOnGreeter"].connect(() => {
136+ this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
137+ eventually_update_player_actions();
138+ });
139+
140+ this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
141+ }
142+
143 this.players = playerlist;
144 this.players.player_added.connect (this.player_added);
145 this.players.player_removed.connect (this.player_removed);
146
147 this.actions = new SimpleActionGroup ();
148 this.actions.add_action_entries (action_entries, this);
149+ this.actions.add_action (this.create_silent_mode_action ());
150 this.actions.add_action (this.create_mute_action ());
151 this.actions.add_action (this.create_volume_action ());
152 this.actions.add_action (this.create_mic_volume_action ());
153
154 this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal);
155 this.menus.insert ("desktop_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
156- this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
157+ this.menus.insert ("phone_greeter", new SoundMenu (null, SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS | SoundMenu.DisplayFlags.GREETER_PLAYERS));
158 this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE));
159- this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
160+ this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings", SoundMenu.DisplayFlags.SHOW_SILENT_MODE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
161
162 this.menus.@foreach ( (profile, menu) => {
163 this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE);
164 });
165
166- /* If we're on the greeter, don't export */
167- if (GLib.Environment.get_user_name() != "lightdm") {
168- this.accounts_service = new AccountsServiceUser();
169-
170- this.accounts_service.notify["showDataOnGreeter"].connect(() => {
171- this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
172- eventually_update_player_actions();
173- });
174-
175- this.export_to_accounts_service = this.accounts_service.showDataOnGreeter;
176- }
177-
178 this.sync_preferred_players ();
179 this.settings.changed["interested-media-players"].connect ( () => {
180 this.sync_preferred_players ();
181@@ -226,10 +227,26 @@
182 return icon.serialize ();
183 }
184
185+ /* This kinda got complex with both mute and silent mode. So we're
186+ gonna put it into a function */
187+ bool user_sound_output () {
188+ if (this.volume_control.mute) {
189+ return false;
190+ }
191+
192+ if (this.accounts_service != null) {
193+ if (this.accounts_service.silentMode) {
194+ return false;
195+ }
196+ }
197+
198+ return true;
199+ }
200+
201 void update_root_icon () {
202 double volume = this.volume_control.get_volume ();
203 string icon;
204- if (this.volume_control.mute)
205+ if (!user_sound_output())
206 icon = this.mute_blocks_sound ? "audio-volume-muted-blocking-panel" : "audio-volume-muted-panel";
207 else if (volume <= 0.0)
208 icon = "audio-volume-low-zero-panel";
209@@ -241,7 +258,7 @@
210 icon = "audio-volume-high-panel";
211
212 string accessible_name;
213- if (this.volume_control.mute) {
214+ if (!user_sound_output()) {
215 accessible_name = _("Volume (muted)");
216 } else {
217 int volume_int = (int)(volume * 100);
218@@ -257,6 +274,36 @@
219 root_action.set_state (builder.end());
220 }
221
222+ Action create_silent_mode_action () {
223+ bool silentNow = false;
224+ if (this.accounts_service != null) {
225+ silentNow = this.accounts_service.silentMode;
226+ }
227+
228+ var silent_action = new SimpleAction.stateful ("silent-mode", null, new Variant.boolean (silentNow));
229+
230+ /* If we're not dealing with accounts service, we'll just always be out
231+ of silent mode and that's cool. */
232+ if (this.accounts_service == null) {
233+ return silent_action;
234+ }
235+
236+ this.accounts_service.notify["silentMode"].connect(() => {
237+ silent_action.set_state(new Variant.boolean(this.accounts_service.silentMode));
238+ this.update_root_icon ();
239+ });
240+
241+ silent_action.activate.connect ((action, param) => {
242+ action.change_state (new Variant.boolean (!action.get_state().get_boolean()));
243+ });
244+
245+ silent_action.change_state.connect ((action, val) => {
246+ this.accounts_service.silentMode = val.get_boolean();
247+ });
248+
249+ return silent_action;
250+ }
251+
252 Action create_mute_action () {
253 var mute_action = new SimpleAction.stateful ("mute", null, new Variant.boolean (this.volume_control.mute));
254
255
256=== modified file 'src/sound-menu.vala'
257--- src/sound-menu.vala 2014-09-23 15:31:16 +0000
258+++ src/sound-menu.vala 2014-10-02 21:55:45 +0000
259@@ -24,7 +24,8 @@
260 SHOW_MUTE = 1,
261 HIDE_INACTIVE_PLAYERS = 2,
262 HIDE_PLAYERS = 4,
263- GREETER_PLAYERS = 8
264+ GREETER_PLAYERS = 8,
265+ SHOW_SILENT_MODE = 16
266 }
267
268 public SoundMenu (string? settings_action, DisplayFlags flags) {
269@@ -34,8 +35,15 @@
270 */
271
272 this.volume_section = new Menu ();
273+
274 if ((flags & DisplayFlags.SHOW_MUTE) != 0)
275 volume_section.append (_("Mute"), "indicator.mute");
276+ if ((flags & DisplayFlags.SHOW_SILENT_MODE) != 0) {
277+ var item = new MenuItem(_("Silent Mode"), "indicator.silent-mode");
278+ item.set_attribute("x-canonical-type", "s", "com.canonical.indicator.switch");
279+ volume_section.append_item(item);
280+ }
281+
282 volume_section.append_item (this.create_slider_menu_item ("indicator.volume(0)", 0.0, 1.0, 0.01,
283 "audio-volume-low-zero-panel",
284 "audio-volume-high-panel"));

Subscribers

People subscribed via source and target branches

to all changes: