aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2011-01-12 17:55:05 -0600
committerConor Curran <conor.curran@canonical.com>2011-01-12 17:55:05 -0600
commit6db28ce9134db40a0808a3c67df5f9dd223303b5 (patch)
tree4508dfbf263ee3778476418a5ba230f535ffa8c0
parent055df674f70f7961c6d47e3b031881e142f6dea8 (diff)
downloadayatana-indicator-sound-6db28ce9134db40a0808a3c67df5f9dd223303b5.tar.gz
ayatana-indicator-sound-6db28ce9134db40a0808a3c67df5f9dd223303b5.tar.bz2
ayatana-indicator-sound-6db28ce9134db40a0808a3c67df5f9dd223303b5.zip
stage one of the refactor on the server side complete
-rw-r--r--src/dbus-menu-manager.c204
-rw-r--r--src/dbus-menu-manager.h22
-rw-r--r--src/mute-menu-item.c16
-rw-r--r--src/mute-menu-item.h1
-rw-r--r--src/pulse-manager.c2
-rw-r--r--src/slider-menu-item.c39
-rw-r--r--src/slider-menu-item.h8
-rw-r--r--src/sound-service.xml5
8 files changed, 125 insertions, 172 deletions
diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c
index 8c255e3..7de5844 100644
--- a/src/dbus-menu-manager.c
+++ b/src/dbus-menu-manager.c
@@ -22,6 +22,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
* Makes this a proper GObject
**/
+
#include <unistd.h>
#include <glib/gi18n.h>
@@ -44,24 +45,15 @@ static SliderMenuItem *volume_slider_menuitem = NULL;
static MuteMenuItem *mute_menuitem = NULL;
static SoundServiceDbus *dbus_interface = NULL;
-// PULSEAUDIO
-static gboolean b_sink_available = FALSE;
-static gboolean b_pulse_ready = FALSE;
static gboolean b_startup = TRUE;
-static gdouble volume_percent = 0.0;
-static void set_global_mute_from_ui();
static gboolean idle_routine (gpointer data);
-static void rebuild_sound_menu(DbusmenuMenuitem *root,
+static void build_sound_menu(DbusmenuMenuitem *root,
gboolean mute_update,
gboolean availability,
gdouble volume);
-static void refresh_menu();
-
-
-/*-------------------------------------------------------------------------*/
-// Public Methods
-/*-------------------------------------------------------------------------*/
+static void show_sound_settings_dialog (DbusmenuMenuitem *mi,
+ gpointer user_data);
/**
setup:
@@ -81,104 +73,96 @@ DbusmenuMenuitem* dbus_menu_manager_setup()
return root_menuitem;
}
-void dbus_menu_manager_update_volume(gdouble volume)
+/**
+build_sound_menu's default items (without the any player items):
+**/
+static void build_sound_menu (DbusmenuMenuitem *root,
+ gboolean mute_update,
+ gboolean availability,
+ gdouble volume)
{
- GVariant* new_volume = g_variant_new_double(volume);
- dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_VOLUME_MENUITEM_LEVEL,
- new_volume);
+ // Mute button
+ mute_menuitem = mute_menu_item_new ( mute_update, availability);
+ dbusmenu_menuitem_child_append (root, DBUSMENU_MENUITEM(mute_menuitem));
+
+ // Slider
+ volume_slider_menuitem = slider_menu_item_new ( availability, volume );
+ dbusmenu_menuitem_child_append (root, DBUSMENU_MENUITEM ( volume_slider_menuitem ));
+
+ // Separator
+ DbusmenuMenuitem *separator = dbusmenu_menuitem_new();
+ dbusmenu_menuitem_property_set( separator,
+ DBUSMENU_MENUITEM_PROP_TYPE,
+ DBUSMENU_CLIENT_TYPES_SEPARATOR);
+ dbusmenu_menuitem_child_append(root, separator);
+
+ // Sound preferences dialog
+ DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new();
+ dbusmenu_menuitem_property_set( settings_mi,
+ DBUSMENU_MENUITEM_PROP_LABEL,
+ _("Sound Preferences..."));
+
+ //_("Sound Preferences..."));
+ dbusmenu_menuitem_child_append(root, settings_mi);
+ g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
+ G_CALLBACK(show_sound_settings_dialog), NULL);
}
-
/**
update_pa_state:
**/
void dbus_menu_manager_update_pa_state (gboolean pa_state,
- gboolean sink_available,
+ gboolean pulse_available,
gboolean sink_muted,
gdouble percent)
{
- b_sink_available = sink_available;
- b_pulse_ready = pa_state;
- volume_percent = percent;
- g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, sink_available, sink_muted, volume_percent);
- // Only rebuild the menu on start up...
+ g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, pulse_available, sink_muted, percent);
+
if (b_startup == TRUE) {
- rebuild_sound_menu(root_menuitem, dbus_interface);
+ build_sound_menu(root_menuitem, sink_muted, pulse_available, percent);
b_startup = FALSE;
- } else {
- refresh_menu();
+ return;
}
+
+ mute_menu_item_update ( mute_menuitem,
+ sink_muted );
+ slider_menu_item_update ( volume_slider_menuitem,
+ percent );
+
+ mute_menu_item_enable ( mute_menuitem, pulse_available);
+ slider_menu_item_enable ( volume_slider_menuitem,
+ pulse_available );
+
// Emit the signals after the menus are setup/torn down
// preserve ordering !
- sound_service_dbus_update_sink_availability(dbus_interface, sink_available);
+ /*sound_service_dbus_update_sink_availability(dbus_interface, sink_available);
dbus_menu_manager_update_volume(percent);
sound_service_dbus_update_sink_mute(dbus_interface, sink_muted);
- dbus_menu_manager_update_mute_ui(b_all_muted);
+ dbus_menu_manager_update_mute_ui(b_all_muted);*/
}
/**
update_mute_ui:
'public' method allowing the pa manager to update the mute menu item.
+ These are wrappers until we figure out this refactor
**/
-void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value)
-{
-
- dbusmenu_menuitem_property_set(DBUSMENUITEM(mute_all_menuitem),
- DBUSMENU_MENUITEM_PROP_LABEL,
- b_all_muted == FALSE ? _("Mute") : _("Unmute"));
+void dbus_menu_manager_update_mute(gboolean incoming_mute_value)
+{
+ mute_menu_item_update (mute_menuitem, incoming_mute_value);
}
-
-/*-------------------------------------------------------------------------*/
-// Private Methods
-/*-------------------------------------------------------------------------*/
-static void refresh_menu()
-{
- g_debug("in the refresh menu method");
- if (b_sink_available == FALSE || b_pulse_ready == FALSE) {
-
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_MENUITEM_PROP_ENABLED,
- FALSE);
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- FALSE);
- dbusmenu_menuitem_property_set_bool(mute_all_menuitem,
- DBUSMENU_MENUITEM_PROP_ENABLED,
- FALSE);
-
- } else if (b_sink_available == TRUE && b_pulse_ready == TRUE) {
-
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_MENUITEM_PROP_ENABLED,
- TRUE);
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- TRUE);
- dbusmenu_menuitem_property_set_bool(mute_all_menuitem,
- DBUSMENU_MENUITEM_PROP_ENABLED,
- TRUE);
- }
-}
-
-
-/**
-idle_routine:
-Something for glip mainloop to do when idle
-**/
-static gboolean idle_routine (gpointer data)
+void dbus_menu_manager_update_volume(gdouble volume)
{
- return FALSE;
+ slider_menu_item_update (volume_slider_menuitem, volume);
}
-
/**
show_sound_settings_dialog:
Bring up the gnome volume preferences dialog
**/
-static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data)
+static void show_sound_settings_dialog (DbusmenuMenuitem *mi,
+ gpointer user_data)
{
GError * error = NULL;
if (!g_spawn_command_line_async("gnome-volume-control --page=applications", &error) &&
@@ -190,68 +174,12 @@ static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data
}
/**
-build_sound_menu's default items (without the any player items):
-**/
-static void build_sound_menu (DbusmenuMenuitem *root,
- gboolean mute_update,
- gboolean availability,
- gdouble volume);
-
-{
- // Mute button
- mute_all_menuitem = mute_menu_item_new ( mute_update, availability);
- dbusmenu_menuitem_child_append(root, mute_all_menuitem);
-
- // Slider
- volume_slider_menuitem = slider_menu_item_new(available, volume);
- dbusmenu_menuitem_child_append(root, DBUSMENU_MENUITEM(volume_slider_menuitem));
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_MENUITEM_PROP_ENABLED,
- b_sink_available && !b_all_muted);
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(volume_slider_menuitem),
- DBUSMENU_MENUITEM_PROP_VISIBLE,
- b_sink_available);
- // Separator
- DbusmenuMenuitem *separator = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set( separator,
- DBUSMENU_MENUITEM_PROP_TYPE,
- DBUSMENU_CLIENT_TYPES_SEPARATOR);
- dbusmenu_menuitem_child_append(root, separator);
-
- // Sound preferences dialog
- DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new();
- dbusmenu_menuitem_property_set( settings_mi,
- DBUSMENU_MENUITEM_PROP_LABEL,
- _("Sound Preferences..."));
-
- //_("Sound Preferences..."));
- dbusmenu_menuitem_child_append(root, settings_mi);
- g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
- G_CALLBACK(show_sound_settings_dialog), NULL);
-}
-
-/**
-set_global_mute_from_ui:
-Callback for the dbusmenuitem button
+TODO: what are you doing with this
+idle_routine:
+Something for glip mainloop to do when idle
**/
-static void set_global_mute_from_ui()
-{
- b_all_muted = !b_all_muted;
- toggle_global_mute(b_all_muted);
- dbusmenu_menuitem_property_set((DBUSMENU_MENUITEM)mute_all_menuitem,
- DBUSMENU_MENUITEM_PROP_LABEL,
- b_all_muted == FALSE ? _("Mute") : _("Unmute"));
-}
-
-
-/*
- TODO: use these temporary wrappers around pulsemanager for the short term
- Until I get to the point where I can refactor it entirely.
-*/
-
-void dbmm_pa_wrapper_toggle_mute(gboolean update)
+static gboolean idle_routine (gpointer data)
{
- toggle_global_mute (update);
+ return FALSE;
}
-
diff --git a/src/dbus-menu-manager.h b/src/dbus-menu-manager.h
index 5b6544e..27976b3 100644
--- a/src/dbus-menu-manager.h
+++ b/src/dbus-menu-manager.h
@@ -1,10 +1,7 @@
#ifndef __INCLUDE_DBUS_MENU_MANAGER_H__
#define __INCLUDE_DBUS_MENU_MANAGER_H__
-#include <libdbusmenu-glib/menuitem.h>
-
/*
-This handles the management of the dbusmeneu items.
Copyright 2010 Canonical Ltd.
Authors:
@@ -23,12 +20,19 @@ You should have received a copy of the GNU General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <libdbusmenu-glib/menuitem.h>
+
+// Entry point
DbusmenuMenuitem* dbus_menu_manager_setup();
-void dbus_menu_manager_teardown();
-void dbus_menu_manager_update_volume(gdouble volume);
-void dbus_menu_manager_update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_muted, gdouble current_vol);
-// TODO update pa_state should incorporate the method below !
-void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value);
-void dbmm_pa_wrapper_toggle_mute(gboolean update);
+
+void dbus_menu_manager_update_pa_state (gboolean pa_state,
+ gboolean sink_available,
+ gboolean sink_muted,
+ gdouble current_vol);
+
+// Temporary wrappers on the pulsemanager inward calls
+// until the refactor is complete
+void dbus_menu_manager_update_mute (gboolean incoming_mute_value);
+void dbus_menu_manager_update_volume (gdouble volume);
#endif
diff --git a/src/mute-menu-item.c b/src/mute-menu-item.c
index bc96a2a..9e79dd1 100644
--- a/src/mute-menu-item.c
+++ b/src/mute-menu-item.c
@@ -23,14 +23,11 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
#include "common-defs.h"
#include <glib/gi18n.h>
#include "mute-menu-item.h"
-#include "common-defs.h"
-
-#include "dbus-menu-manager.h"
+#include "pulse-manager.h"
typedef struct _MuteMenuItemPrivate MuteMenuItemPrivate;
struct _MuteMenuItemPrivate {
- gboolean mute_all;
};
#define MUTE_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), MUTE_MENU_ITEM_TYPE, MuteMenuItemPrivate))
@@ -96,7 +93,8 @@ handle_event (DbusmenuMenuitem * mi,
}
gboolean mute_input = g_variant_get_boolean(input);
- dbmm_pa_wrapper_toggle_mute (input);
+ // TODO: use the pulse wrapper directly
+ toggle_global_mute (mute_input);
g_variant_unref (input);
}
@@ -104,10 +102,10 @@ void mute_menu_item_update(MuteMenuItem* item, gboolean value_update)
{
dbusmenu_menuitem_property_set_bool (DBUSMENU_MENUITEM(item),
DBUSMENU_MUTE_MENUITEM_VALUE,
- update);
- dbusmenu_menuitem_property_set (DBUSMENUITEM(item),
+ value_update);
+ dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(item),
DBUSMENU_MENUITEM_PROP_LABEL,
- update == FALSE ? _("Mute") : _("Unmute"));
+ value_update == FALSE ? _("Mute") : _("Unmute"));
}
void mute_menu_item_enable(MuteMenuItem* item, gboolean active)
@@ -124,7 +122,7 @@ MuteMenuItem* mute_menu_item_new (gboolean initial_update, gboolean enabled)
dbusmenu_menuitem_property_set (DBUSMENU_MENUITEM(self),
DBUSMENU_MENUITEM_PROP_TYPE,
DBUSMENU_MUTE_MENUITEM_TYPE);
- mute_menu_item_enable (self, enabled);
mute_menu_item_update (self, initial_update);
+ mute_menu_item_enable (self, enabled);
return self;
}
diff --git a/src/mute-menu-item.h b/src/mute-menu-item.h
index d7232d0..1432de1 100644
--- a/src/mute-menu-item.h
+++ b/src/mute-menu-item.h
@@ -50,6 +50,7 @@ GType mute_menu_item_get_type (void);
MuteMenuItem* mute_menu_item_new();
void mute_menu_item_update(MuteMenuItem* item, gboolean update);
+void mute_menu_item_enable(MuteMenuItem* item, gboolean active);
G_END_DECLS
diff --git a/src/pulse-manager.c b/src/pulse-manager.c
index 4443044..15a449b 100644
--- a/src/pulse-manager.c
+++ b/src/pulse-manager.c
@@ -414,7 +414,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v
if (mute_changed == TRUE) {
/* g_debug("Updating Mute from PA manager with mute = %i", s->mute);*/
sound_service_dbus_update_sink_mute(dbus_service, s->mute);
- dbus_menu_manager_update_mute_ui(s->mute);
+ dbus_menu_manager_update_mute(s->mute);
if (s->mute == FALSE) {
pa_volume_t vol = pa_cvolume_max(&s->volume);
gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM;
diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c
index 0f2f07b..d41ff85 100644
--- a/src/slider-menu-item.c
+++ b/src/slider-menu-item.c
@@ -29,7 +29,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
typedef struct _SliderMenuItemPrivate SliderMenuItemPrivate;
struct _SliderMenuItemPrivate {
- gdouble slider_value;
};
#define SLIDER_MENU_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SLIDER_MENU_ITEM_TYPE, SliderMenuItemPrivate))
@@ -76,14 +75,12 @@ slider_menu_item_finalize (GObject *object)
G_OBJECT_CLASS (slider_menu_item_parent_class)->finalize (object);
}
-
static void
handle_event (DbusmenuMenuitem * mi,
const gchar * name,
GVariant * value,
guint timestamp)
{
- gdouble volume_input = 0;
/*g_debug ( "handle-event in the slider at the backend, input is of type %s",
g_variant_get_type_string(value));*/
@@ -96,25 +93,41 @@ handle_event (DbusmenuMenuitem * mi,
input = g_variant_get_variant(value);
}
- volume_input = g_variant_get_double(input);
+ gboolean volume_input = g_variant_get_double(input);
if (value != NULL){
set_sink_volume(volume_input);
}
g_variant_unref (input);
}
+void slider_menu_item_update (SliderMenuItem* item,
+ gdouble update)
+{
+ // TODO
+ // Check if that variant below will leak !!!
+ GVariant* new_volume = g_variant_new_double(update);
+ dbusmenu_menuitem_property_set_variant(DBUSMENU_MENUITEM(item),
+ DBUSMENU_VOLUME_MENUITEM_LEVEL,
+ new_volume);
+}
+void slider_menu_item_enable (SliderMenuItem* item,
+ gboolean active)
+{
+ dbusmenu_menuitem_property_set_bool( DBUSMENU_MENUITEM(item),
+ DBUSMENU_MENUITEM_PROP_ENABLED,
+ active );
+}
-SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_volume)
+SliderMenuItem* slider_menu_item_new (gboolean sinks_available,
+ gdouble start_volume)
{
SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL);
- dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_VOLUME_MENUITEM_TYPE);
+ dbusmenu_menuitem_property_set( DBUSMENU_MENUITEM(self),
+ DBUSMENU_MENUITEM_PROP_TYPE,
+ DBUSMENU_VOLUME_MENUITEM_TYPE );
+ slider_menu_item_update (self, start_volume);
+ slider_menu_item_enable (self, sinks_available);
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available);
- dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_VISIBLE, sinks_available);
return self;
-}
-
-
-
-
+} \ No newline at end of file
diff --git a/src/slider-menu-item.h b/src/slider-menu-item.h
index 763944f..51336ae 100644
--- a/src/slider-menu-item.h
+++ b/src/slider-menu-item.h
@@ -45,8 +45,12 @@ struct _SliderMenuItem {
};
GType slider_menu_item_get_type (void);
-// TODO for now the volume percent param is not being used - remove once init mystery is solved
-SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble current_vol);
+
+void slider_menu_item_update(SliderMenuItem* item, gdouble update);
+void slider_menu_item_enable(SliderMenuItem* item, gboolean active);
+
+SliderMenuItem* slider_menu_item_new (gboolean sinks_available,
+ gdouble current_vol);
G_END_DECLS
diff --git a/src/sound-service.xml b/src/sound-service.xml
index a552d52..da3ac18 100644
--- a/src/sound-service.xml
+++ b/src/sound-service.xml
@@ -6,6 +6,11 @@
<arg type='b' name='mute_input' direction="out"/>
</method>
+ <method name = "BlacklistMediaPlayer">
+ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_blacklist_media_player"/>
+ <arg type='s' name='player_desktop_name' direction="in"/>
+ </method>
+
<method name = "GetSinkAvailability">
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="sound_service_dbus_get_sink_availability"/>
<arg type='b' name='availability_input' direction="out"/>