aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-07-25 18:16:23 +0000
committerTarmac <Unknown>2013-07-25 18:16:23 +0000
commit305b46f4ef6c442aaf34b0506899f26dcd281b37 (patch)
tree6b79121bfa3ec25ebdf2c031f31abe24ef175df4
parent5fab6aa432dde109fd764de11a44bd51eff8cd87 (diff)
parent79749756d267168e1a5fd3e5c15a3e956357aee8 (diff)
downloadayatana-indicator-sound-305b46f4ef6c442aaf34b0506899f26dcd281b37.tar.gz
ayatana-indicator-sound-305b46f4ef6c442aaf34b0506899f26dcd281b37.tar.bz2
ayatana-indicator-sound-305b46f4ef6c442aaf34b0506899f26dcd281b37.zip
Actually export a phone menu.
Approved by Charles Kerr, PS Jenkins bot.
-rw-r--r--data/com.canonical.indicator.sound2
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/Makefile.am3
-rw-r--r--src/service.vala150
-rw-r--r--src/sound-menu.vala164
5 files changed, 191 insertions, 129 deletions
diff --git a/data/com.canonical.indicator.sound b/data/com.canonical.indicator.sound
index ccea589..adefae9 100644
--- a/data/com.canonical.indicator.sound
+++ b/data/com.canonical.indicator.sound
@@ -7,7 +7,7 @@ Position=30
ObjectPath=/com/canonical/indicator/sound/desktop
[phone]
-ObjectPath=/com/canonical/indicator/sound/desktop
+ObjectPath=/com/canonical/indicator/sound/phone
[desktop_greeter]
ObjectPath=/com/canonical/indicator/sound/desktop
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 09797c8..39a320f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,3 +1,4 @@
[encoding: UTF-8]
src/service.vala
src/service.c
+src/sound-menu.c
diff --git a/src/Makefile.am b/src/Makefile.am
index da3df5b..8af02ce 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,8 @@ indicator_sound_service_SOURCES = \
media-player-list.vala \
mpris2-interfaces.vala \
mpris2-watcher.vala \
- freedesktop-interfaces.vala
+ freedesktop-interfaces.vala \
+ sound-menu.vala
indicator_sound_service_VALAFLAGS = \
--ccode \
diff --git a/src/service.vala b/src/service.vala
index e13c02e..8fbd871 100644
--- a/src/service.vala
+++ b/src/service.vala
@@ -25,7 +25,6 @@ public class IndicatorSound.Service {
this.settings = new Settings ("com.canonical.indicator.sound");
this.volume_control = new VolumeControl ();
- this.volume_control.notify["active-mic"].connect (active_mic_changed);
this.players = new MediaPlayerList ();
this.players.player_added.connect (this.player_added);
@@ -37,8 +36,13 @@ public class IndicatorSound.Service {
this.actions.add_action (this.create_volume_action ());
this.actions.add_action (this.create_mic_volume_action ());
- this.menu = create_menu ();
- this.root_menu = create_root_menu (this.menu);
+ this.menus = new HashTable<string, SoundMenu> (str_hash, str_equal);
+ this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings"));
+ this.menus.insert ("phone", new SoundMenu ("indicator.phone-settings"));
+
+ this.menus.@foreach ( (profile, menu) => {
+ this.volume_control.bind_property ("active-mic", menu, "show-mic-volume", BindingFlags.SYNC_CREATE);
+ });
this.players.sync (settings.get_strv ("interested-media-players"));
this.settings.changed["interested-media-players"].connect ( () => {
@@ -63,19 +67,19 @@ public class IndicatorSound.Service {
const ActionEntry[] action_entries = {
{ "root", null, null, "@a{sv} {}", null },
- { "settings", activate_settings, null, null, null },
+ { "desktop-settings", activate_desktop_settings, null, null, null },
+ { "phone-settings", activate_phone_settings, null, null, null },
};
MainLoop loop;
SimpleActionGroup actions;
- Menu root_menu;
- Menu menu;
+ HashTable<string, SoundMenu> menus;
Settings settings;
VolumeControl volume_control;
MediaPlayerList players;
uint player_action_update_id;
- void activate_settings (SimpleAction action, Variant? param) {
+ void activate_desktop_settings (SimpleAction action, Variant? param) {
var env = Environment.get_variable ("DESKTOP_SESSION");
string cmd;
if (env == "unity")
@@ -92,6 +96,14 @@ public class IndicatorSound.Service {
}
}
+ void activate_phone_settings (SimpleAction action, Variant? param) {
+ try {
+ Process.spawn_command_line_async ("system-settings sound");
+ } catch (Error e) {
+ warning ("unable to launch sound settings: %s", e.message);
+ }
+ }
+
/* Returns a serialized version of @icon_name suited for the panel */
static Variant serialize_themed_icon (string icon_name)
{
@@ -99,57 +111,6 @@ public class IndicatorSound.Service {
return g_icon_serialize (icon);
}
- static Menu create_root_menu (Menu submenu) {
- var root = new MenuItem (null, "indicator.root");
- root.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root");
- root.set_submenu (submenu);
-
- var menu = new Menu ();
- menu.append_item (root);
-
- return menu;
- }
-
- static Menu create_menu () {
- var volume_section = new Menu ();
- volume_section.append (_("Mute"), "indicator.mute");
-
- var slider = new MenuItem (null, "indicator.volume");
- slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider");
- slider.set_attribute_value ("min-icon", serialize_themed_icon ("audio-volume-low-zero-panel"));
- slider.set_attribute_value ("max-icon", serialize_themed_icon ("audio-volume-high-panel"));
- slider.set_attribute ("min-value", "d", 0.0);
- slider.set_attribute ("max-value", "d", 1.0);
- slider.set_attribute ("step", "d", 0.01);
- volume_section.append_item (slider);
-
- var menu = new Menu ();
- menu.append_section (null, volume_section);
- menu.append (_("Sound Settingsā€¦"), "indicator.settings");
-
- return menu;
- }
-
- void active_mic_changed () {
- var volume_section = this.menu.get_item_link (0, "section") as Menu;
- if (this.volume_control.active_mic) {
- if (volume_section.get_n_items () < 3) {
- var slider = new MenuItem (null, "indicator.mic-volume");
- slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider");
- slider.set_attribute_value ("min-icon", serialize_themed_icon ("audio-input-microphone-low-zero-panel"));
- slider.set_attribute_value ("max-icon", serialize_themed_icon ("audio-input-microphone-high-panel"));
- slider.set_attribute ("min-value", "d", 0.0);
- slider.set_attribute ("max-value", "d", 1.0);
- slider.set_attribute ("step", "d", 0.01);
- volume_section.append_item (slider);
- }
- }
- else {
- if (volume_section.get_n_items () > 2)
- volume_section.remove (2);
- }
- }
-
void update_root_icon () {
double volume = this.volume_control.get_volume ();
string icon;
@@ -227,10 +188,11 @@ public class IndicatorSound.Service {
void bus_acquired (DBusConnection connection, string name) {
try {
connection.export_action_group ("/com/canonical/indicator/sound", this.actions);
- connection.export_menu_model ("/com/canonical/indicator/sound/desktop", this.root_menu);
} catch (Error e) {
critical ("%s", e.message);
}
+
+ this.menus.@foreach ( (profile, menu) => menu.export (connection, @"/com/canonical/indicator/sound/$profile"));
}
void name_lost (DBusConnection connection, string name) {
@@ -273,53 +235,8 @@ public class IndicatorSound.Service {
this.settings.set_value ("interested-media-players", builder.end ());
}
- void update_playlists (MediaPlayer player) {
- int index = find_player_section (player);
- if (index < 0)
- return;
-
- var section = this.menu.get_item_link (index, Menu.LINK_SECTION) as Menu;
-
- /* if a section has three items, the playlists menu is in it */
- if (section.get_n_items () == 3)
- section.remove (2);
-
- if (!player.is_running)
- return;
-
- var count = player.get_n_playlists ();
- if (count == 0)
- return;
-
- var playlists_section = new Menu ();
- for (int i = 0; i < count; i++) {
- var playlist_id = player.get_playlist_id (i);
- playlists_section.append (player.get_playlist_name (i),
- @"indicator.play-playlist.$(player.id)::$playlist_id");
-
- }
-
- var submenu = new Menu ();
- submenu.append_section (null, playlists_section);
- section.append_submenu ("Choose Playlist", submenu);
- }
-
void player_added (MediaPlayer player) {
- var player_item = new MenuItem (player.name, "indicator." + player.id);
- player_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player");
- player_item.set_attribute_value ("icon", g_icon_serialize (player.icon));
-
- var playback_item = new MenuItem (null, null);
- playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item");
- playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
- playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id);
- playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
-
- var section = new Menu ();
- section.append_item (player_item);
- section.append_item (playback_item);
-
- this.menu.insert_section (this.menu.get_n_items () -1, null, section);
+ this.menus.@foreach ( (profile, menu) => menu.add_player (player));
SimpleAction action = new SimpleAction.stateful (player.id, null, this.action_state_for_player (player));
action.activate.connect ( () => { player.launch (); });
@@ -347,28 +264,9 @@ public class IndicatorSound.Service {
player.notify.connect (this.eventually_update_player_actions);
- player.playlists_changed.connect (this.update_playlists);
- player.notify["is-running"].connect ( () => this.update_playlists (player) );
- update_playlists (player);
-
this.update_preferred_players ();
}
- /* returns the position in this.menu of the section that's associated with @player */
- int find_player_section (MediaPlayer player) {
- string action_name = @"indicator.$(player.id)";
- int n = this.menu.get_n_items () -1;
- for (int i = 1; i < n; i++) {
- var section = this.menu.get_item_link (i, Menu.LINK_SECTION);
- string action;
- section.get_item_attribute (0, "action", "s", out action);
- if (action == action_name)
- return i;
- }
-
- return -1;
- }
-
void player_removed (MediaPlayer player) {
this.actions.remove (player.id);
this.actions.remove ("play." + player.id);
@@ -376,9 +274,7 @@ public class IndicatorSound.Service {
this.actions.remove ("previous." + player.id);
this.actions.remove ("play-playlist." + player.id);
- int index = this.find_player_section (player);
- if (index >= 0)
- this.menu.remove (index);
+ this.menus.@foreach ( (profile, menu) => menu.remove_player (player));
this.update_preferred_players ();
}
diff --git a/src/sound-menu.vala b/src/sound-menu.vala
new file mode 100644
index 0000000..dd50f12
--- /dev/null
+++ b/src/sound-menu.vala
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2013 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Lars Uebernickel <lars.uebernickel@canonical.com>
+ */
+
+class SoundMenu: Object
+{
+ public SoundMenu (string settings_action) {
+ /* A sound menu always has at least two sections: the volume section (this.volume_section)
+ * at the start of the menu, and the settings section at the end. Between those two,
+ * it has a dynamic amount of player sections, one for each registered player.
+ */
+
+ this.volume_section = new Menu ();
+ volume_section.append (_("Mute"), "indicator.mute");
+ volume_section.append_item (this.create_slider_menu_item ("indicator.volume", 0.0, 1.0, 0.01,
+ "audio-volume-low-zero-panel",
+ "audio-volume-low-high-panel"));
+
+ this.menu = new Menu ();
+ this.menu.append_section (null, volume_section);
+ this.menu.append (_("Sound Settingsā€¦"), settings_action);
+
+ var root_item = new MenuItem (null, "indicator.root");
+ root_item.set_attribute ("x-canonical-type", "s", "com.canonical.indicator.root");
+ root_item.set_submenu (this.menu);
+
+ this.root = new Menu ();
+ root.append_item (root_item);
+ }
+
+ public void export (DBusConnection connection, string object_path) {
+ try {
+ connection.export_menu_model (object_path, this.root);
+ } catch (Error e) {
+ critical ("%s", e.message);
+ }
+ }
+
+ public bool show_mic_volume {
+ get {
+ return this.volume_section.get_n_items () == 3;
+ }
+ set {
+ if (value && this.volume_section.get_n_items () < 3) {
+ var slider = this.create_slider_menu_item ("indicator.mic-volume", 0.0, 1.0, 0.01,
+ "audio-input-microphone-low-zero-panel",
+ "audio-input-microphone-high-panel");
+ volume_section.append_item (slider);
+ }
+ else if (!value && this.volume_section.get_n_items () > 2) {
+ this.volume_section.remove (2);
+ }
+ }
+ }
+
+ public void add_player (MediaPlayer player) {
+ /* Add new players to the end of the player sections, just before the settings */
+ var player_item = new MenuItem (player.name, "indicator." + player.id);
+ player_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.media-player");
+ player_item.set_attribute_value ("icon", g_icon_serialize (player.icon));
+
+ var playback_item = new MenuItem (null, null);
+ playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item");
+ playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
+ playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id);
+ playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
+
+ var section = new Menu ();
+ section.append_item (player_item);
+ section.append_item (playback_item);
+
+ player.playlists_changed.connect (this.update_playlists);
+ player.notify["is-running"].connect ( () => this.update_playlists (player) );
+ update_playlists (player);
+
+ this.menu.insert_section (this.menu.get_n_items () -1, null, section);
+ }
+
+ public void remove_player (MediaPlayer player) {
+ int index = this.find_player_section (player);
+ if (index >= 0)
+ this.menu.remove (index);
+ }
+
+ Menu root;
+ Menu menu;
+ Menu volume_section;
+
+ /* returns the position in this.menu of the section that's associated with @player */
+ int find_player_section (MediaPlayer player) {
+ string action_name = @"indicator.$(player.id)";
+ int n = this.menu.get_n_items () -1;
+ for (int i = 1; i < n; i++) {
+ var section = this.menu.get_item_link (i, Menu.LINK_SECTION);
+ string action;
+ section.get_item_attribute (0, "action", "s", out action);
+ if (action == action_name)
+ return i;
+ }
+
+ return -1;
+ }
+
+ void update_playlists (MediaPlayer player) {
+ int index = find_player_section (player);
+ if (index < 0)
+ return;
+
+ var player_section = this.menu.get_item_link (index, Menu.LINK_SECTION) as Menu;
+
+ /* if a section has three items, the playlists menu is in it */
+ if (player_section.get_n_items () == 3)
+ player_section.remove (2);
+
+ if (!player.is_running)
+ return;
+
+ var count = player.get_n_playlists ();
+ if (count == 0)
+ return;
+
+ var playlists_section = new Menu ();
+ for (int i = 0; i < count; i++) {
+ var playlist_id = player.get_playlist_id (i);
+ playlists_section.append (player.get_playlist_name (i),
+ @"indicator.play-playlist.$(player.id)::$playlist_id");
+
+ }
+
+ var submenu = new Menu ();
+ submenu.append_section (null, playlists_section);
+ player_section.append_submenu ("Choose Playlist", submenu);
+ }
+
+ MenuItem create_slider_menu_item (string action, double min, double max, double step, string min_icon_name, string max_icon_name) {
+ var min_icon = new ThemedIcon.with_default_fallbacks (min_icon_name);
+ var max_icon = new ThemedIcon.with_default_fallbacks (max_icon_name);
+
+ var slider = new MenuItem (null, action);
+ slider.set_attribute ("x-canonical-type", "s", "com.canonical.unity.slider");
+ slider.set_attribute_value ("min-icon", g_icon_serialize (min_icon));
+ slider.set_attribute_value ("max-icon", g_icon_serialize (max_icon));
+ slider.set_attribute ("min-value", "d", min);
+ slider.set_attribute ("max-value", "d", max);
+ slider.set_attribute ("step", "d", step);
+
+ return slider;
+ }
+}