aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/CMakeLists.txt21
-rw-r--r--data/indicator-sound.conf.in8
-rw-r--r--data/indicator-sound.desktop.in4
-rw-r--r--data/indicator-sound.upstart.desktop.in9
-rw-r--r--debian/indicator-sound-crashdb.conf6
-rwxr-xr-xdebian/rules7
-rw-r--r--debian/source_indicator-sound.py16
-rw-r--r--src/volume-control.vala177
8 files changed, 230 insertions, 18 deletions
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 9694a9e..955a4a4 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -57,6 +57,27 @@ install(
)
###########################
+# Upstart XDG Autostart Override
+###########################
+
+set(
+ INDICATOR_SOUND_UPSTART_XDG_AUTOSTART
+ "${CMAKE_CURRENT_BINARY_DIR}/indicator-sound.upstart.desktop"
+)
+
+configure_file(
+ "indicator-sound.upstart.desktop.in"
+ ${INDICATOR_SOUND_UPSTART_XDG_AUTOSTART}
+ @ONLY
+)
+
+install(
+ FILES "${INDICATOR_SOUND_UPSTART_XDG_AUTOSTART}"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/upstart/xdg/autostart"
+ RENAME "indicator-sound.desktop"
+)
+
+###########################
# GSettings
###########################
diff --git a/data/indicator-sound.conf.in b/data/indicator-sound.conf.in
index a5f4b4d..4912b61 100644
--- a/data/indicator-sound.conf.in
+++ b/data/indicator-sound.conf.in
@@ -1,11 +1,9 @@
-description "Indicator Sound Backend"
+description "Indicator Sound Service"
-# Want to move to indicator-services-[start|end], but that's not all
-# there yet. Use the signals that exist today for now.
-
-start on indicators-loaded or indicator-services-start
+start on indicator-services-start
stop on desktop-end or indicator-services-end
respawn
+respawn limit 2 10
exec @CMAKE_INSTALL_FULL_LIBEXECDIR@/indicator-sound/indicator-sound-service
diff --git a/data/indicator-sound.desktop.in b/data/indicator-sound.desktop.in
index aeb6440..b471893 100644
--- a/data/indicator-sound.desktop.in
+++ b/data/indicator-sound.desktop.in
@@ -2,8 +2,8 @@
Type=Application
Name=Indicator Sound
Exec=@CMAKE_INSTALL_FULL_LIBEXECDIR@/indicator-sound/indicator-sound-service
-NotShowIn=Unity;
+OnlyShowIn=Unity;XFCE;GNOME;
NoDisplay=true
StartupNotify=false
Terminal=false
-
+AutostartCondition=GNOME3 unless-session gnome
diff --git a/data/indicator-sound.upstart.desktop.in b/data/indicator-sound.upstart.desktop.in
new file mode 100644
index 0000000..37dfc7d
--- /dev/null
+++ b/data/indicator-sound.upstart.desktop.in
@@ -0,0 +1,9 @@
+[Desktop Entry]
+Type=Application
+Name=Indicator Sound
+Exec=@CMAKE_INSTALL_FULL_LIBEXECDIR@/indicator-sound/indicator-sound-service
+OnlyShowIn=Unity;XFCE;
+NoDisplay=true
+StartupNotify=false
+Terminal=false
+Hidden=true
diff --git a/debian/indicator-sound-crashdb.conf b/debian/indicator-sound-crashdb.conf
new file mode 100644
index 0000000..42e04f7
--- /dev/null
+++ b/debian/indicator-sound-crashdb.conf
@@ -0,0 +1,6 @@
+
+indicator_sound = {
+ 'impl': 'launchpad',
+ 'project': 'indicator-sound',
+ 'bug_pattern_base': None,
+}
diff --git a/debian/rules b/debian/rules
index 3f1dfeb..8fb0f91 100755
--- a/debian/rules
+++ b/debian/rules
@@ -10,3 +10,10 @@ override_dh_auto_configure:
# So until Debian bug 719148 is fixed, do it ourselves.
dh_auto_configure -- -DCMAKE_INSTALL_LOCALSTATEDIR="/var"
+override_dh_install:
+ mkdir -p debian/indicator-sound/usr/share/apport/package-hooks/
+ install -m 644 debian/source_indicator-sound.py debian/indicator-sound/usr/share/apport/package-hooks/
+ mkdir -p debian/indicator-sound/etc/apport/crashdb.conf.d/
+ install -m 644 debian/indicator-sound-crashdb.conf debian/indicator-sound/etc/apport/crashdb.conf.d/
+ dh_install --fail-missing
+
diff --git a/debian/source_indicator-sound.py b/debian/source_indicator-sound.py
new file mode 100644
index 0000000..90e8f4f
--- /dev/null
+++ b/debian/source_indicator-sound.py
@@ -0,0 +1,16 @@
+import os.path
+from apport.hookutils import *
+
+def attach_command_output(report, command_list, key):
+ log = command_output(command_list)
+ if not log or log[:5] == "Error":
+ return
+ report[key] = log
+
+def add_info(report):
+ if not apport.packaging.is_distro_package(report['Package'].split()[0]):
+ report['ThirdParty'] = 'True'
+ report['CrashDB'] = 'indicator_sound'
+
+ if not 'StackTrace' in report:
+ attach_command_output(report, ['gdbus', 'call', '--session', '--dest', 'com.canonical.indicator.sound', '--object-path', '/com/canonical/indicator/sound', '--method', 'org.gtk.Actions.DescribeAll'], 'ActionStates')
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 03cac0b..889c2d6 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -1,4 +1,5 @@
/*
+ * -*- Mode:Vala; indent-tabs-mode:t; tab-width:4; encoding:utf8 -*-
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
@@ -22,6 +23,13 @@ using PulseAudio;
[CCode(cname="pa_cvolume_set", cheader_filename = "pulse/volume.h")]
extern unowned PulseAudio.CVolume? vol_set (PulseAudio.CVolume? cv, uint channels, PulseAudio.Volume v);
+[DBus (name="com.canonical.UnityGreeter.List")]
+interface GreeterListInterface : Object
+{
+ public abstract async string get_active_entry () throws IOError;
+ public signal void entry_selected (string entry_name);
+}
+
public class VolumeControl : Object
{
/* this is static to ensure it being freed after @context (loop does not have ref counting) */
@@ -35,6 +43,11 @@ public class VolumeControl : Object
private double _volume = 0.0;
private double _mic_volume = 0.0;
+ private DBusProxy _user_proxy;
+ private GreeterListInterface _greeter_proxy;
+ private Cancellable _mute_cancellable;
+ private Cancellable _volume_cancellable;
+
public signal void volume_changed (double v);
public signal void mic_volume_changed (double v);
@@ -49,6 +62,10 @@ public class VolumeControl : Object
if (loop == null)
loop = new PulseAudio.GLibMainLoop ();
+ _mute_cancellable = new Cancellable ();
+ _volume_cancellable = new Cancellable ();
+ setup_accountsservice.begin ();
+
this.reconnect_to_pulse ();
}
@@ -221,14 +238,25 @@ public class VolumeControl : Object
}
/* Mute operations */
- public void set_mute (bool mute)
+ bool set_mute_internal (bool mute)
{
- return_if_fail (context.get_state () == Context.State.READY);
+ return_val_if_fail (context.get_state () == Context.State.READY, false);
+
+ if (_mute != mute) {
+ if (mute)
+ context.get_sink_info_list (sink_info_list_callback_set_mute);
+ else
+ context.get_sink_info_list (sink_info_list_callback_unset_mute);
+ return true;
+ } else {
+ return false;
+ }
+ }
- if (mute)
- context.get_sink_info_list (sink_info_list_callback_set_mute);
- else
- context.get_sink_info_list (sink_info_list_callback_unset_mute);
+ public void set_mute (bool mute)
+ {
+ if (set_mute_internal (mute))
+ sync_mute_to_accountsservice.begin (mute);
}
public void toggle_mute ()
@@ -291,13 +319,23 @@ public class VolumeControl : Object
context.get_sink_info_by_name (i.default_sink_name, sink_info_set_volume_cb);
}
- public void set_volume (double volume)
+ bool set_volume_internal (double volume)
{
- return_if_fail (context.get_state () == Context.State.READY);
-
- _volume = volume;
+ return_val_if_fail (context.get_state () == Context.State.READY, false);
+
+ if (_volume != volume) {
+ _volume = volume;
+ context.get_server_info (server_info_cb_for_set_volume);
+ return true;
+ } else {
+ return false;
+ }
+ }
- context.get_server_info (server_info_cb_for_set_volume);
+ public void set_volume (double volume)
+ {
+ if (set_volume_internal (volume))
+ sync_volume_to_accountsservice.begin (volume);
}
void set_mic_volume_success_cb (Context c, int success)
@@ -332,4 +370,121 @@ public class VolumeControl : Object
{
return _mic_volume;
}
+
+ /* AccountsService operations */
+ private void accountsservice_props_changed_cb (DBusProxy proxy, Variant changed_properties, string[] invalidated_properties)
+ {
+ Variant volume_variant = changed_properties.lookup_value ("Volume", new VariantType ("d"));
+ if (volume_variant != null) {
+ var volume = volume_variant.get_double ();
+ if (volume >= 0)
+ set_volume_internal (volume);
+ }
+
+ Variant mute_variant = changed_properties.lookup_value ("Muted", new VariantType ("b"));
+ if (mute_variant != null) {
+ var mute = mute_variant.get_boolean ();
+ set_mute_internal (mute);
+ }
+ }
+
+ private async void setup_user_proxy (string? username_in = null)
+ {
+ var username = username_in;
+ _user_proxy = null;
+
+ // Look up currently selected greeter user, if asked
+ if (username == null) {
+ try {
+ username = yield _greeter_proxy.get_active_entry ();
+ if (username == "" || username == null)
+ return;
+ } catch (GLib.Error e) {
+ warning ("unable to find Accounts path for user %s: %s", username, e.message);
+ return;
+ }
+ }
+
+ // Get master AccountsService object
+ DBusProxy accounts_proxy;
+ try {
+ accounts_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | DBusProxyFlags.DO_NOT_CONNECT_SIGNALS, null, "org.freedesktop.Accounts", "/org/freedesktop/Accounts", "org.freedesktop.Accounts");
+ } catch (GLib.Error e) {
+ warning ("unable to get greeter proxy: %s", e.message);
+ return;
+ }
+
+ // Find user's AccountsService object
+ try {
+ var user_path_variant = yield accounts_proxy.call ("FindUserByName", new Variant ("(s)", username), DBusCallFlags.NONE, -1);
+ string user_path;
+ user_path_variant.get ("(o)", out user_path);
+ _user_proxy = yield DBusProxy.create_for_bus (BusType.SYSTEM, DBusProxyFlags.GET_INVALIDATED_PROPERTIES, null, "org.freedesktop.Accounts", user_path, "com.ubuntu.AccountsService.Sound");
+ } catch (GLib.Error e) {
+ warning ("unable to find Accounts path for user %s: %s", username, e.message);
+ return;
+ }
+
+ // Get current values and listen for changes
+ _user_proxy.g_properties_changed.connect (accountsservice_props_changed_cb);
+ var props_variant = yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "GetAll", new Variant ("(s)", _user_proxy.get_interface_name ()), null, DBusCallFlags.NONE, -1);
+ Variant props;
+ props_variant.get ("(@a{sv})", out props);
+ accountsservice_props_changed_cb(_user_proxy, props, null);
+ }
+
+ private void greeter_user_changed (string username)
+ {
+ setup_user_proxy.begin (username);
+ }
+
+ private async void setup_accountsservice ()
+ {
+ if (Environment.get_variable ("XDG_SESSION_CLASS") == "greeter") {
+ try {
+ _greeter_proxy = yield Bus.get_proxy (BusType.SESSION, "com.canonical.UnityGreeter", "/list");
+ } catch (GLib.Error e) {
+ warning ("unable to get greeter proxy: %s", e.message);
+ return;
+ }
+ _greeter_proxy.entry_selected.connect (greeter_user_changed);
+ yield setup_user_proxy ();
+ } else {
+ // We are in a user session. We just need our own proxy
+ var username = Environment.get_variable ("USER");
+ if (username != "" && username != null) {
+ yield setup_user_proxy (username);
+ }
+ }
+ }
+
+ private async void sync_mute_to_accountsservice (bool mute)
+ {
+ if (_user_proxy == null)
+ return;
+
+ _mute_cancellable.cancel ();
+ _mute_cancellable.reset ();
+
+ try {
+ yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Muted", new Variant ("b", mute)), null, DBusCallFlags.NONE, -1, _mute_cancellable);
+ } catch (GLib.Error e) {
+ warning ("unable to sync mute to AccountsService: %s", e.message);
+ }
+ }
+
+ private async void sync_volume_to_accountsservice (double volume)
+ {
+ if (_user_proxy == null)
+ return;
+
+ _volume_cancellable.cancel ();
+ _volume_cancellable.reset ();
+
+ try {
+ yield _user_proxy.get_connection ().call (_user_proxy.get_name (), _user_proxy.get_object_path (), "org.freedesktop.DBus.Properties", "Set", new Variant ("(ssv)", _user_proxy.get_interface_name (), "Volume", new Variant ("d", volume)), null, DBusCallFlags.NONE, -1, _volume_cancellable);
+ } catch (GLib.Error e) {
+ warning ("unable to sync volume to AccountsService: %s", e.message);
+ }
+ }
}