From 496ac14d4e3b4e5b9284083cf4ce277cfe5ef343 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 30 Jul 2010 18:51:03 +0100 Subject: refactor the volume slider into its own wrapper gobject --- src/Makefile.am | 2 + src/indicator-sound.c | 47 ++++++++- src/volume-widget.c | 271 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/volume-widget.h | 53 ++++++++++ 4 files changed, 370 insertions(+), 3 deletions(-) create mode 100644 src/volume-widget.c create mode 100644 src/volume-widget.h (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ed3e394..ce7a580 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -20,6 +20,8 @@ libsoundmenu_la_SOURCES = \ title-widget.h \ scrub-widget.c \ scrub-widget.h \ + volume-widget.c \ + volume-widget.h \ dbus-shared-names.h \ sound-service-client.h diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 1c6041b..fee87c8 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -42,6 +42,8 @@ with this program. If not, see . #include "metadata-widget.h" #include "title-widget.h" #include "scrub-widget.h" +#include "volume-widget.h" + #include "dbus-shared-names.h" #include "sound-service-client.h" #include "common-defs.h" @@ -89,6 +91,7 @@ static void scroll (IndicatorObject*io, gint delta, IndicatorScrollDirec //Slider related static GtkWidget *volume_slider = NULL; static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); static void slider_grabbed(GtkWidget *widget, gpointer user_data); @@ -251,7 +254,7 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget); // register Key-press listening on the menu widget as the slider does not allow this. - g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); + g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io); return GTK_MENU(menu); } @@ -398,6 +401,40 @@ new_scrub_bar_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus return TRUE; } +static gboolean +new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + g_debug("indicator-sound: new_volume_slider_widget"); + + GtkWidget* volume_widget = NULL; + IndicatorObject *io = NULL; + + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + + volume_widget = volume_widget_new (newitem); + GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(volume_widget)); + + + io = g_object_get_data (G_OBJECT (client), "indicator"); + // we still need to hold to a reference to the actual slider to + // react to menu wide key events + // not ideal: to be revisited post beta + INDICATOR_SOUND (io)->slider = ido_slider_widget; + + gtk_widget_show_all(ido_slider_widget); + gtk_widget_set_sensitive(ido_slider_widget, + !initial_mute); + + GtkMenuItem *menu_volume_item = GTK_MENU_ITEM(ido_slider_widget); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), + newitem, + menu_volume_item, + parent); + + return TRUE; +} + static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) @@ -564,7 +601,7 @@ start_animation() { blocked_iter = blocked_animation_list; blocked_id = 0; - g_debug("exit from blocked hold start the animation\n"); + //g_debug("exit from blocked hold start the animation\n"); animation_id = g_timeout_add(50, fade_back_to_mute_image, NULL); return FALSE; } @@ -777,7 +814,11 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) { gboolean digested = FALSE; - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + g_return_val_if_fail(IS_INDICATOR_SOUND(data)); + + IndicatorSound *sound = INDICATOR_SOUND (data); + + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)sound->slider); GtkRange* range = (GtkRange*)slider; gdouble current_value = gtk_range_get_value(range); gdouble new_value = current_value; diff --git a/src/volume-widget.c b/src/volume-widget.c new file mode 100644 index 0000000..8b54a32 --- /dev/null +++ b/src/volume-widget.c @@ -0,0 +1,271 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "volume-widget.h" +#include "common-defs.h" +#include + +typedef struct _VolumeWidgetPrivate VolumeWidgetPrivate; + +struct _VolumeWidgetPrivate +{ + DbusmenuMenuitem* twin_item; + GtkWidget* ido_volume_slider; + gboolean grabbed; +}; + +#define VOLUME_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), VOLUME_WIDGET_TYPE, VolumeWidgetPrivate)) + +/* Prototypes */ +static void volume_widget_class_init (VolumeWidgetClass *klass); +static void volume_widget_init (VolumeWidget *self); +static void volume_widget_dispose (GObject *object); +static void volume_widget_finalize (GObject *object); +static void volume_widget_set_twin_item( VolumeWidget* self, + DbusmenuMenuitem* twin_item); +static void volume_widget_set_ido_position(VolumeWidget* self, + gint position, + gint duration); +//callbacks +static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata); +static gboolean volume_widget_change_value_cb (GtkRange *range, + GtkScrollType scroll, + gdouble value, + gpointer user_data); +static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data); +static void volume_widget_slider_released(GtkWidget *widget, gpointer user_data); +static void volume_widget_parent_changed (GtkWidget *widget, gpointer user_data); + +G_DEFINE_TYPE (VolumeWidget, volume_widget, G_TYPE_OBJECT); + +static void +volume_widget_class_init (VolumeWidgetClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (VolumeWidgetPrivate)); + + gobject_class->dispose = volume_widget_dispose; + gobject_class->finalize = volume_widget_finalize; +} + +static void +volume_widget_init (VolumeWidget *self) +{ + g_debug("VolumeWidget::volume_widget_init"); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + + priv->ido_volume_slider = ido_scale_menu_item_new_with_range ("VOLUME", IDO_RANGE_STYLE_DEFAULT, 0, 0, 100, 1); + + ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (priv->ido_volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); + g_object_set(priv->ido_volume_slider, "reverse-scroll-events", TRUE, NULL); + + g_signal_connect (volume_slider, + "notify::parent", G_CALLBACK (slider_parent_changed), + NULL); + + GtkWidget* volume_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + + // register slider changes listening on the range + g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); + g_signal_connect(volume_widget, "value-changed", G_CALLBACK(volume_widget_value_changed_cb), self); + g_signal_connect(priv->ido_volume_slider, "slider-grabbed", G_CALLBACK(volume_widget_slider_grabbed), self); + g_signal_connect(priv->ido_volume_slider, "slider-released", G_CALLBACK(volume_widget_slider_released), self); + + // Set images on the ido + GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)priv->ido_volume_slider); + GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks("audio-volume-low-zero-panel"); + gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU); + g_object_unref(primary_gicon); + + GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)priv->ido_volume_slider); + GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks("audio-volume-high-panel"); + gtk_image_set_from_gicon(GTK_IMAGE(secondary_image), secondary_gicon, GTK_ICON_SIZE_MENU); + g_object_unref(secondary_gicon); + + GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (volume_widget)); + gtk_adjustment_set_step_increment(adj, 3); + + gtk_widget_show_all(volume_widget); +} + +static void +volume_widget_dispose (GObject *object) +{ + G_OBJECT_CLASS (volume_widget_parent_class)->dispose (object); +} + +static void +volume_widget_finalize (GObject *object) +{ + G_OBJECT_CLASS (volume_widget_parent_class)->finalize (object); +} + +static void +volume_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata) +{ + g_debug("scrub-widget::property_update"); + + g_return_if_fail (IS_VOLUME_WIDGET (userdata)); + VolumeWidget* mitem = VOLUME_WIDGET(userdata); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + +} + +static void +volume_widget_set_twin_item(VolumeWidget* self, + DbusmenuMenuitem* twin_item) +{ + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + priv->twin_item = twin_item; + + g_signal_connect(G_OBJECT(twin_item), "property-changed", + G_CALLBACK(volume_widget_property_update), self); + + /*volume_widget_set_ido_position(self, + dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000, + dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION)); + */ +} + +static gboolean +volume_widget_change_value_cb (GtkRange *range, + GtkScrollType scroll, + gdouble new_value, + gpointer user_data) +{ + g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + + // Don't bother when the slider is grabbed + if(priv->grabbed == TRUE) + return FALSE; + + GValue value = {0}; + g_value_init(&value, G_TYPE_DOUBLE); + gdouble clamped = CLAMP(new_value, 0, 100); + g_value_set_double(&value, clamped); + dbusmenu_menuitem_handle_event (priv->twin_item, "grabbed", &value, 0); + return TRUE; +} + +static gboolean +volume_widget_value_changed(GtkRange *range, gpointer user_data) +{ + g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + + gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(priv->ido_volume_slider), 0, 100); + + // Replace with dbus properties inspection + /*if (current_value == exterior_vol_update) { + g_debug("ignore the value changed event - its come from the outside"); + return FALSE; + }*/ + + GValue value = {0}; + g_value_init(&value, G_TYPE_DOUBLE); + g_value_set_double(&value, current_value); + g_debug("volume_widget_value changed callback - = %f", current_value); + dbusmenu_menuitem_handle_event (priv->twin_item, "slider_change", &value, 0); + // This is not ideal in that the icon ui will update on ui actions and not on actual service feedback. + // but necessary for now as the server does not send volume update information if the source of change was this ui. + determine_state_from_volume(current_value); + return FALSE; +} + + +GtkWidget* +volume_widget_get_ido_bar(VolumeWidget* self) +{ + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + return priv->ido_volume_slider; +} + +static void +volume_widget_parent_changed (GtkWidget *widget, + gpointer user_data) +{ + gtk_widget_set_size_request (widget, 200, -1); + g_debug("volume_widget_parent_changed"); +} + + +static void +volume_widget_set_ido_position(VolumeWidget* self, + gint position, + gint duration) +{ + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + gdouble ido_position = position/(gdouble)duration * 100.0; + g_debug("volume_widget_set_ido_position - pos: %i, duration: %i, ido_pos: %f", position, duration, ido_position); + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + GtkRange *range = (GtkRange*)slider; + if(duration == 0) + ido_position = 0.0; + gtk_range_set_value(range, ido_position); +} + +static void +volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data) +{ + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + priv->grabbed = TRUE; +} + +static void +volume_widget_slider_released(GtkWidget *widget, gpointer user_data) +{ + VolumeWidget* mitem = VOLUME_WIDGET(user_data); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + priv->grabbed = FALSE; + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + gdouble new_value = gtk_range_get_value(GTK_RANGE(slider)); + g_debug("okay set the scrub position with %f", new_value); + GValue value = {0}; + g_value_init(&value, G_TYPE_DOUBLE); + gdouble clamped = CLAMP(new_value, 0, 100); + g_value_set_double(&value, clamped); + dbusmenu_menuitem_handle_event (priv->twin_item, "volume-change", &value, 0); +} + + +/** + * volume_widget_new: + * @returns: a new #VolumeWidget. + **/ +GtkWidget* +volume_widget_new(DbusmenuMenuitem *item) +{ + GtkWidget* widget = g_object_new(VOLUME_WIDGET_TYPE, NULL); + volume_widget_set_twin_item((VolumeWidget*)widget, item); + return widget; +} + + diff --git a/src/volume-widget.h b/src/volume-widget.h new file mode 100644 index 0000000..8e3e895 --- /dev/null +++ b/src/volume-widget.h @@ -0,0 +1,53 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ +#ifndef __VOLUME_WIDGET_H__ +#define __VOLUME_WIDGET_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +#define VOLUME_WIDGET_TYPE (volume_widget_get_type ()) +#define VOLUME_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VOLUME_WIDGET_TYPE, VolumeWidget)) +#define VOLUME_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VOLUME_WIDGET_TYPE, VolumeWidgetClass)) +#define IS_VOLUME_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VOLUME_WIDGET_TYPE)) +#define IS_VOLUME_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VOLUME_WIDGET_TYPE)) +#define VOLUME_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VOLUME_WIDGET_TYPE, VolumeWidgetClass)) + +typedef struct _VolumeWidget VolumeWidget; +typedef struct _VolumeWidgetClass VolumeWidgetClass; + +struct _VolumeWidgetClass { + GObjectClass parent_class; +}; + +struct _VolumeWidget { + GObject parent; +}; + +GType volume_widget_get_type (void) G_GNUC_CONST; +GtkWidget* volume_widget_new(DbusmenuMenuitem* twin_item); +GtkWidget* volume_widget_get_ido_bar(VolumeWidget* self); + +G_END_DECLS + +#endif + -- cgit v1.2.3 From 9f7e55264deaaad68280ae33daad95fca604df8b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 2 Aug 2010 19:13:58 +0100 Subject: replaced now needs tweaking --- src/common-defs.h | 3 ++- src/dbus-menu-manager.c | 14 +++++++----- src/dbus-menu-manager.h | 1 + src/indicator-sound.c | 9 ++++---- src/play-button.c | 21 ----------------- src/pulse-manager.c | 10 ++++---- src/slider-menu-item.c | 6 +++-- src/sound-service.c | 4 ++-- src/volume-widget.c | 61 +++++++++++++++++++++++++------------------------ src/volume-widget.h | 2 +- 10 files changed, 60 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index 46ff520..e3b4552 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -27,7 +27,8 @@ with this program. If not, see . #define DBUSMENU_PROPERTY_EMPTY -1 /* DBUS Custom Items */ -#define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-type" +#define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" +#define DBUSMENU_VOLUME_MENUITEM_LEVEL "x-canonical-ido-volume-level" #define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-sound-menu-player-transport-type" #define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-transport-state" diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 4cd4a6b..076b177 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -31,6 +31,7 @@ with this program. If not, see . #include "sound-service-dbus.h" #include "pulse-manager.h" #include "slider-menu-item.h" +#include "common-defs.h" #include "dbus-shared-names.h" @@ -74,13 +75,15 @@ DbusmenuMenuitem* dbus_menu_manager_setup() return root_menuitem; } -/** -teardown: -**/ -void dbus_menu_manager_teardown() + +void dbus_menu_manager_update_volume(gdouble volume) { - //TODO tidy up dbus_interface and items! + GValue value = {0}; + g_value_init(&value, G_TYPE_DOUBLE); + g_value_set_double(&value, volume); + dbusmenu_menuitem_property_set_value(volume_slider_menuitem, DBUSMENU_VOLUME_MENUITEM_LEVEL, &value); } + /** update_pa_state: @@ -123,7 +126,6 @@ void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value) /*-------------------------------------------------------------------------*/ // Private Methods /*-------------------------------------------------------------------------*/ - static void refresh_menu() { g_debug("in the refresh menu method"); diff --git a/src/dbus-menu-manager.h b/src/dbus-menu-manager.h index 926e292..ec2b2e2 100644 --- a/src/dbus-menu-manager.h +++ b/src/dbus-menu-manager.h @@ -25,6 +25,7 @@ with this program. If not, see . 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); diff --git a/src/indicator-sound.c b/src/indicator-sound.c index fee87c8..bf44d15 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -247,7 +247,7 @@ get_menu (IndicatorObject * io) DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); g_object_set_data (G_OBJECT (client), "indicator", io); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_VOLUME_MENUITEM_TYPE, new_volume_slider_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); @@ -814,7 +814,7 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) { gboolean digested = FALSE; - g_return_val_if_fail(IS_INDICATOR_SOUND(data)); + g_return_val_if_fail(IS_INDICATOR_SOUND(data), FALSE); IndicatorSound *sound = INDICATOR_SOUND (data); @@ -882,9 +882,10 @@ style_changed_cb(GtkWidget *widget, gpointer user_data) static void scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) { - if (device_available == FALSE || current_state == STATE_MUTED) - return; + g_debug("Scroll detected"); + if (device_available == FALSE || current_state == STATE_MUTED) + return; IndicatorSound *sound = INDICATOR_SOUND (io); GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (sound->slider)); gdouble value = gtk_range_get_value (GTK_RANGE (sound->slider)); diff --git a/src/play-button.c b/src/play-button.c index e4382c1..94e6f98 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -454,29 +454,8 @@ void play_button_toggle_play_pause(GtkWidget* button, PlayButtonState update) { PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - gboolean changed = priv->current_state != update; priv->current_state = update; g_debug("PlayButton::toggle play state : %i", priv->current_state); - - if(changed == TRUE){ - g_debug("Toggle play pause - changed of state detected - redraw button"); - cairo_t *cr; - - cr = gdk_cairo_create (button->window); - - GList* list = g_hash_table_lookup(priv->command_coordinates, - GINT_TO_POINTER(TRANSPORT_PLAY_PAUSE)); - - cairo_rectangle(cr, - GPOINTER_TO_INT(g_list_nth_data(list, 0)), - GPOINTER_TO_INT(g_list_nth_data(list, 1)), - GPOINTER_TO_INT(g_list_nth_data(list, 2)), - GPOINTER_TO_INT(g_list_nth_data(list, 3))); - - cairo_clip(cr); - draw (button, cr); - cairo_destroy (cr); - } } diff --git a/src/pulse-manager.c b/src/pulse-manager.c index a9a47e4..4ff9e1d 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -211,7 +211,8 @@ static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) if (GPOINTER_TO_INT(user_data) == 1) { sound_service_dbus_update_sink_mute(dbus_service, TRUE); } else { - sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume()); + //sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume()); + dbus_menu_manager_update_volume(get_default_sink_volume()); } /* g_debug("in the pulse manager: mute each sink %i", GPOINTER_TO_INT(user_data));*/ @@ -288,7 +289,7 @@ static void context_success_callback(pa_context *c, int success, void *userdata) /** On Service startup this callback will be called multiple times resulting our sinks_hash container to be filled with the available sinks. -For now this callback it assumes it only used at startup. It may be necessary to use if sinks become available after startup. +For now this callback assumes it only used at startup. It may be necessary to use if sinks become available after startup. Major candidate for refactoring. **/ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, int eol, void *userdata) @@ -399,7 +400,7 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ - sound_service_dbus_update_sink_volume(dbus_service, volume_percent); + dbus_menu_manager_update_volume(volume_percent); } if (mute_changed == TRUE) { @@ -410,7 +411,8 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ - sound_service_dbus_update_sink_volume(dbus_service, volume_percent); + //sound_service_dbus_update_sink_volume(dbus_service, volume_percent); + dbus_menu_manager_update_volume(volume_percent); } } } diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index d56422a..9536ff8 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -90,9 +90,11 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g 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_SLIDER_MENUITEM_TYPE); - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); + dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_VOLUME_MENUITEM_TYPE); + + 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; } diff --git a/src/sound-service.c b/src/sound-service.c index 8768cd3..16fa87c 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/volume-widget.c b/src/volume-widget.c index 8b54a32..9b6e5f7 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -22,6 +22,8 @@ with this program. If not, see . #endif #include +#include +#include #include "volume-widget.h" #include "common-defs.h" #include @@ -45,8 +47,7 @@ static void volume_widget_finalize (GObject *object); static void volume_widget_set_twin_item( VolumeWidget* self, DbusmenuMenuitem* twin_item); static void volume_widget_set_ido_position(VolumeWidget* self, - gint position, - gint duration); + gdouble new_volume); //callbacks static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); @@ -54,6 +55,9 @@ static gboolean volume_widget_change_value_cb (GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data); +static gboolean volume_widget_value_changed_cb(GtkRange *range, + gpointer user_data); + static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data); static void volume_widget_slider_released(GtkWidget *widget, gpointer user_data); static void volume_widget_parent_changed (GtkWidget *widget, gpointer user_data); @@ -82,14 +86,14 @@ volume_widget_init (VolumeWidget *self) ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (priv->ido_volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); g_object_set(priv->ido_volume_slider, "reverse-scroll-events", TRUE, NULL); - g_signal_connect (volume_slider, - "notify::parent", G_CALLBACK (slider_parent_changed), + g_signal_connect (priv->ido_volume_slider, + "notify::parent", G_CALLBACK (volume_widget_parent_changed), NULL); GtkWidget* volume_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); // register slider changes listening on the range - g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); + //g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); g_signal_connect(volume_widget, "value-changed", G_CALLBACK(volume_widget_value_changed_cb), self); g_signal_connect(priv->ido_volume_slider, "slider-grabbed", G_CALLBACK(volume_widget_slider_grabbed), self); g_signal_connect(priv->ido_volume_slider, "slider-released", G_CALLBACK(volume_widget_slider_released), self); @@ -107,8 +111,6 @@ volume_widget_init (VolumeWidget *self) GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (volume_widget)); gtk_adjustment_set_step_increment(adj, 3); - - gtk_widget_show_all(volume_widget); } static void @@ -126,13 +128,18 @@ volume_widget_finalize (GObject *object) static void volume_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) -{ - g_debug("scrub-widget::property_update"); - +{ g_return_if_fail (IS_VOLUME_WIDGET (userdata)); VolumeWidget* mitem = VOLUME_WIDGET(userdata); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - + g_debug("scrub-widget::property_update for prop %s", property); + if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_LEVEL, property) == 0){ + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + GtkRange *range = (GtkRange*)slider; + gdouble update = g_value_get_double (value); + g_debug("volume-widget - update level with value %f", update); + gtk_range_set_value(range, update); + } } static void @@ -174,20 +181,18 @@ volume_widget_change_value_cb (GtkRange *range, } static gboolean -volume_widget_value_changed(GtkRange *range, gpointer user_data) +volume_widget_value_changed_cb(GtkRange *range, gpointer user_data) { g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); VolumeWidget* mitem = VOLUME_WIDGET(user_data); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - - gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(priv->ido_volume_slider), 0, 100); - // Replace with dbus properties inspection - /*if (current_value == exterior_vol_update) { - g_debug("ignore the value changed event - its come from the outside"); - return FALSE; - }*/ - + if(priv->grabbed == TRUE){ + return TRUE; + } + + gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(priv->ido_volume_slider)), 0, 100); + GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); g_value_set_double(&value, current_value); @@ -195,13 +200,13 @@ volume_widget_value_changed(GtkRange *range, gpointer user_data) dbusmenu_menuitem_handle_event (priv->twin_item, "slider_change", &value, 0); // This is not ideal in that the icon ui will update on ui actions and not on actual service feedback. // but necessary for now as the server does not send volume update information if the source of change was this ui. - determine_state_from_volume(current_value); + //determine_state_from_volume(current_value); return FALSE; } GtkWidget* -volume_widget_get_ido_bar(VolumeWidget* self) +volume_widget_get_ido_slider(VolumeWidget* self) { VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); return priv->ido_volume_slider; @@ -215,20 +220,16 @@ volume_widget_parent_changed (GtkWidget *widget, g_debug("volume_widget_parent_changed"); } - + +//TODO: are we using this as convenience function static void volume_widget_set_ido_position(VolumeWidget* self, - gint position, - gint duration) + gdouble new_volume) { VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); - gdouble ido_position = position/(gdouble)duration * 100.0; - g_debug("volume_widget_set_ido_position - pos: %i, duration: %i, ido_pos: %f", position, duration, ido_position); GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; - if(duration == 0) - ido_position = 0.0; - gtk_range_set_value(range, ido_position); + gtk_range_set_value(range, new_volume); } static void diff --git a/src/volume-widget.h b/src/volume-widget.h index 8e3e895..7e6ab84 100644 --- a/src/volume-widget.h +++ b/src/volume-widget.h @@ -45,7 +45,7 @@ struct _VolumeWidget { GType volume_widget_get_type (void) G_GNUC_CONST; GtkWidget* volume_widget_new(DbusmenuMenuitem* twin_item); -GtkWidget* volume_widget_get_ido_bar(VolumeWidget* self); +GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self); G_END_DECLS -- cgit v1.2.3 From fe354978ea13a5d3d8cbfc8f8ec2b3ab20170cf5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 3 Aug 2010 20:33:15 +0100 Subject: almost there --- src/dbus-menu-manager.c | 2 +- src/indicator-sound.c | 327 +++++++++++++----------------------------------- src/indicator-sound.h | 25 +++- src/volume-widget.c | 93 +++++--------- src/volume-widget.h | 1 + 5 files changed, 141 insertions(+), 307 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 076b177..d7d12b2 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -81,7 +81,7 @@ void dbus_menu_manager_update_volume(gdouble volume) GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); g_value_set_double(&value, volume); - dbusmenu_menuitem_property_set_value(volume_slider_menuitem, DBUSMENU_VOLUME_MENUITEM_LEVEL, &value); + dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_VOLUME_MENUITEM_LEVEL, &value); } diff --git a/src/indicator-sound.c b/src/indicator-sound.c index bf44d15..599d969 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -48,30 +48,16 @@ with this program. If not, see . #include "sound-service-client.h" #include "common-defs.h" -// GObject Boiler plate -#define INDICATOR_SOUND_TYPE (indicator_sound_get_type ()) -#define INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SOUND_TYPE, IndicatorSound)) -#define INDICATOR_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SOUND_TYPE, IndicatorSoundClass)) -#define IS_INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SOUND_TYPE)) -#define IS_INDICATOR_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SOUND_TYPE)) -#define INDICATOR_SOUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SOUND_TYPE, IndicatorSoundClass)) - -typedef struct _IndicatorSound IndicatorSound; -typedef struct _IndicatorSoundClass IndicatorSoundClass; - -//GObject class struct -struct _IndicatorSoundClass { - IndicatorObjectClass parent_class; -}; +typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; -//GObject instance struct -struct _IndicatorSound { - IndicatorObject parent; - GtkWidget *slider; - IndicatorServiceManager *service; +struct _IndicatorSoundPrivate +{ + GtkWidget* volume_widget; }; + +#define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) + // GObject Boiler plate -GType indicator_sound_get_type (void); INDICATOR_SET_VERSION INDICATOR_SET_TYPE(INDICATOR_SOUND_TYPE) @@ -86,16 +72,10 @@ G_DEFINE_TYPE (IndicatorSound, indicator_sound, INDICATOR_OBJECT_TYPE); static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); -static void scroll (IndicatorObject*io, gint delta, IndicatorScrollDirection direction); //Slider related -static GtkWidget *volume_slider = NULL; -static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); -static void slider_grabbed(GtkWidget *widget, gpointer user_data); -static void slider_released(GtkWidget *widget, gpointer user_data); static void style_changed_cb(GtkWidget *widget, gpointer user_data); //player widget realisation methods @@ -108,12 +88,10 @@ static gboolean new_scrub_bar_widget(DbusmenuMenuitem * newitem, DbusmenuMenuite static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean value, gpointer userdata); -static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata); static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata); -static void fetch_volume_percent_from_dbus(); static void fetch_mute_value_from_dbus(); -static void fetch_sink_availability_from_dbus(); +static void fetch_sink_availability_from_dbus(IndicatorSound* self); /****Volume States 'members' ***/ static void update_state(const gint state); @@ -132,11 +110,8 @@ static GtkImage *speaker_image = NULL; static gint current_state = 0; static gint previous_state = 0; -static gdouble initial_volume_percent; static gboolean initial_mute ; static gboolean device_available; -static gboolean slider_in_direct_use; -static gdouble exterior_vol_update; static GtkIconSize design_team_size; static gint blocked_id; @@ -160,10 +135,12 @@ indicator_sound_class_init (IndicatorSoundClass *klass) object_class->finalize = indicator_sound_finalize; IndicatorObjectClass *io_class = INDICATOR_OBJECT_CLASS(klass); + + g_type_class_add_private (klass, sizeof (IndicatorSoundPrivate)); + io_class->get_label = get_label; io_class->get_image = get_icon; io_class->get_menu = get_menu; - io_class->scroll = scroll; design_team_size = gtk_icon_size_register("design-team-size", 22, 22); @@ -181,10 +158,11 @@ indicator_sound_init (IndicatorSound *self) blocked_id = 0; initial_mute = FALSE; device_available = TRUE; - slider_in_direct_use = FALSE; - exterior_vol_update = OUT_OF_RANGE; + + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + priv->volume_widget = NULL; - g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); + g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); return; } @@ -205,15 +183,6 @@ indicator_sound_dispose (GObject *object) return; } -static void -free_the_animation_list() -{ - if (blocked_animation_list != NULL) { - g_list_foreach (blocked_animation_list, (GFunc)g_object_unref, NULL); - g_list_free(blocked_animation_list); - blocked_animation_list = NULL; - } -} static void indicator_sound_finalize (GObject *object) @@ -259,69 +228,23 @@ get_menu (IndicatorObject * io) } static void +free_the_animation_list() +{ + if (blocked_animation_list != NULL) { + g_list_foreach (blocked_animation_list, (GFunc)g_object_unref, NULL); + g_list_free(blocked_animation_list); + blocked_animation_list = NULL; + } +} + +/*static void slider_parent_changed (GtkWidget *widget, gpointer user_data) { gtk_widget_set_size_request (widget, 200, -1); g_debug("slider parent changed"); -} - -/** -new_slider_item: -Create a new dBusMenu Slider item. -**/ -static gboolean -new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) -{ - IndicatorObject *io = NULL; - - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); - g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - - io = g_object_get_data (G_OBJECT (client), "indicator"); - - volume_slider = ido_scale_menu_item_new_with_range ("Volume", IDO_RANGE_STYLE_DEFAULT, initial_volume_percent, 0, 100, 1); - ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); - g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); - - g_signal_connect (volume_slider, - "notify::parent", G_CALLBACK (slider_parent_changed), - NULL); - - GtkMenuItem *menu_volume_slider = GTK_MENU_ITEM(volume_slider); - - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent); - - // register slider changes listening on the range - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - - INDICATOR_SOUND (io)->slider = slider; - - g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); - g_signal_connect(volume_slider, "slider-grabbed", G_CALLBACK(slider_grabbed), NULL); - g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL); - g_signal_connect(slider, "style-set", G_CALLBACK(style_changed_cb), NULL); - - // Set images on the ido - GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); - GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO))); - gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU); - g_object_unref(primary_gicon); - - GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); - GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH))); - gtk_image_set_from_gicon(GTK_IMAGE(secondary_image), secondary_gicon, GTK_ICON_SIZE_MENU); - g_object_unref(secondary_gicon); - - gtk_widget_set_sensitive(volume_slider, !initial_mute); - - GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (slider)); - gtk_adjustment_set_step_increment(adj, 3); +}*/ - gtk_widget_show_all(volume_slider); - - return TRUE; -} static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) @@ -415,13 +338,13 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, volume_widget = volume_widget_new (newitem); GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(volume_widget)); - io = g_object_get_data (G_OBJECT (client), "indicator"); - // we still need to hold to a reference to the actual slider to - // react to menu wide key events - // not ideal: to be revisited post beta - INDICATOR_SOUND (io)->slider = ido_slider_widget; - + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + priv->volume_widget = volume_widget; + + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)ido_slider_widget); + g_signal_connect(slider, "style-set", G_CALLBACK(style_changed_cb), NULL); + gtk_widget_show_all(ido_slider_widget); gtk_widget_set_sensitive(ido_slider_widget, !initial_mute); @@ -431,7 +354,9 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, newitem, menu_volume_item, parent); - + fetch_mute_value_from_dbus(); + fetch_sink_availability_from_dbus(INDICATOR_SOUND (io)); + return TRUE; } @@ -457,27 +382,18 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u } g_debug("about to connect to the signals"); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), userdata, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); + g_return_if_fail(IS_INDICATOR_SOUND(userdata)); + // Ensure we are in a coherent state with the service at start up. // Preserve ordering! - fetch_volume_percent_from_dbus(); - fetch_mute_value_from_dbus(); - fetch_sink_availability_from_dbus(); } - - } else { - //TODO : will need to handle this scenario - // Not much can we do here really, if there is no dbus connection tis goosed. } - return; } @@ -535,7 +451,6 @@ prepare_blocked_animation() g_object_unref(blocked_buf); } - gint get_state() { @@ -621,11 +536,27 @@ fade_back_to_mute_image() } } +static void +reset_mute_blocking_animation() +{ + if (animation_id != 0) { + g_debug("about to remove the animation_id callback from the mainloop!!**"); + g_source_remove(animation_id); + animation_id = 0; + } + if (blocked_id != 0) { + g_debug("about to remove the blocked_id callback from the mainloop!!**"); + g_source_remove(blocked_id); + blocked_id = 0; + } +} + + /*******************************************************************/ //DBus method handlers /*******************************************************************/ static void -fetch_sink_availability_from_dbus() +fetch_sink_availability_from_dbus(IndicatorSound* self) { GError * error = NULL; gboolean * available_input; @@ -637,38 +568,28 @@ fetch_sink_availability_from_dbus() g_free(available_input); return; } + device_available = *available_input; if (device_available == FALSE) { update_state(STATE_SINKS_NONE); g_debug("NO DEVICE AVAILABLE"); } + if(IS_INDICATOR_SOUND(self) == FALSE){ + g_warning("okay pointer is arseways"); + } - if (GTK_IS_WIDGET (volume_slider)) - gtk_widget_set_sensitive(volume_slider, device_available); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); + GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); + + g_debug("past it"); + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); + gtk_widget_set_sensitive(slider, device_available); g_free(available_input); g_debug("IndicatorSound::fetch_sink_availability_from_dbus -> AVAILABILTY returned from dbus method is %i", device_available); } -static void -fetch_volume_percent_from_dbus() -{ - GError * error = NULL; - gdouble *volume_percent_input; - volume_percent_input = g_new0(gdouble, 1); - org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error); - if (error != NULL) { - g_warning("Unable to fetch VOLUME at indicator start up: %s", error->message); - g_error_free(error); - g_free(volume_percent_input); - return; - } - initial_volume_percent = *volume_percent_input; - determine_state_from_volume(initial_volume_percent); - g_free(volume_percent_input); - g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent); -} static void fetch_mute_value_from_dbus() @@ -705,22 +626,6 @@ catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gp } -static void -catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) -{ - if (slider_in_direct_use == FALSE) { - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange *range = (GtkRange*)slider; - - // DEBUG - gdouble current_value = gtk_range_get_value(range); - g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); - exterior_vol_update = volume_percent; - gtk_range_set_value(range, volume_percent); - determine_state_from_volume(volume_percent); - } -} - static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) { @@ -732,24 +637,19 @@ catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer u reset_mute_blocking_animation(); } g_debug("signal caught - sink mute update with mute value: %i", mute_value); - gtk_widget_set_sensitive(volume_slider, !mute_value); -} -static void -reset_mute_blocking_animation() -{ - if (animation_id != 0) { - g_debug("about to remove the animation_id callback from the mainloop!!**"); - g_source_remove(animation_id); - animation_id = 0; - } - if (blocked_id != 0) { - g_debug("about to remove the blocked_id callback from the mainloop!!**"); - g_source_remove(blocked_id); - blocked_id = 0; - } + g_return_if_fail(IS_INDICATOR_SOUND(userdata)); + IndicatorSound* indicator = INDICATOR_SOUND(userdata); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + if(priv->volume_widget == NULL){ + return; + } + GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); + gtk_widget_set_sensitive(slider, !mute_value); } + static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata) { @@ -760,51 +660,9 @@ catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_valu g_debug("signal caught - sink availability update with value: %i", available_value); } - - - /*******************************************************************/ //UI callbacks /******************************************************************/ -/** -value_changed_event_cb: -This callback will get triggered irregardless of whether its a user change or a programmatic change. -**/ -static gboolean -value_changed_event_cb(GtkRange *range, gpointer user_data) -{ - gdouble current_value = CLAMP(gtk_range_get_value(range), 0, 100); - if (current_value == exterior_vol_update) { - g_debug("ignore the value changed event - its come from the outside"); - return FALSE; - } - DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - g_value_set_double(&value, current_value); - g_debug("Value changed callback - = %f", current_value); - dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); - // This is not ideal in that the icon ui will update on ui actions and not on actual service feedback. - // but necessary for now as the server does not send volume update information if the source of change was this ui. - determine_state_from_volume(current_value); - return FALSE; -} - - -static void -slider_grabbed (GtkWidget *widget, gpointer user_data) -{ - slider_in_direct_use = TRUE; - g_debug ("!!!!!! grabbed\n"); -} - -static void -slider_released (GtkWidget *widget, gpointer user_data) -{ - slider_in_direct_use = FALSE; - g_debug ("!!!!!! released\n"); -} - /** key_press_cb: @@ -816,9 +674,15 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) g_return_val_if_fail(IS_INDICATOR_SOUND(data), FALSE); - IndicatorSound *sound = INDICATOR_SOUND (data); + IndicatorSound *indicator = INDICATOR_SOUND (data); - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)sound->slider); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + if(priv->volume_widget == NULL){ + return FALSE; + } + + GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); GtkRange* range = (GtkRange*)slider; gdouble current_value = gtk_range_get_value(range); gdouble new_value = current_value; @@ -855,14 +719,10 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) default: break; } - new_value = CLAMP(new_value, 0, 100); if (new_value != current_value && current_state != STATE_MUTED) { g_debug("Attempting to set the range from the key listener to %f", new_value); - // In order to ensure that the exterior filtering does not catch this, reset the exterior_vol_update - // to ensure these updates. - exterior_vol_update = OUT_OF_RANGE; - gtk_range_set_value(range, new_value); + volume_widget_update(VOLUME_WIDGET(priv->volume_widget), new_value); } } return digested; @@ -878,22 +738,3 @@ style_changed_cb(GtkWidget *widget, gpointer user_data) free_the_animation_list(); prepare_blocked_animation(); } - -static void -scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) -{ - g_debug("Scroll detected"); - - if (device_available == FALSE || current_state == STATE_MUTED) - return; - IndicatorSound *sound = INDICATOR_SOUND (io); - GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (sound->slider)); - gdouble value = gtk_range_get_value (GTK_RANGE (sound->slider)); - - if (direction == INDICATOR_OBJECT_SCROLL_UP) { - value += adj->step_increment; - } else { - value -= adj->step_increment; - } - gtk_range_set_value (GTK_RANGE (sound->slider), value); -} diff --git a/src/indicator-sound.h b/src/indicator-sound.h index 386ad2a..cf1535b 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -24,7 +24,30 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -// Essentially these are all exported to faciltiate testing +#define INDICATOR_SOUND_TYPE (indicator_sound_get_type ()) +#define INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SOUND_TYPE, IndicatorSound)) +#define INDICATOR_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), INDICATOR_SOUND_TYPE, IndicatorSoundClass)) +#define IS_INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), INDICATOR_SOUND_TYPE)) +#define IS_INDICATOR_SOUND_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), INDICATOR_SOUND_TYPE)) +#define INDICATOR_SOUND_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), INDICATOR_SOUND_TYPE, IndicatorSoundClass)) + +typedef struct _IndicatorSound IndicatorSound; +typedef struct _IndicatorSoundClass IndicatorSoundClass; + +//GObject class struct +struct _IndicatorSoundClass { + IndicatorObjectClass parent_class; +}; + +//GObject instance struct +struct _IndicatorSound { + IndicatorObject parent; + IndicatorServiceManager *service; +}; + +// GObject Boiler plate +GType indicator_sound_get_type (void); + void prepare_state_machine(); void determine_state_from_volume(gdouble volume_percent); gint get_state(); diff --git a/src/volume-widget.c b/src/volume-widget.c index 9b6e5f7..77c2b25 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -46,9 +46,6 @@ static void volume_widget_dispose (GObject *object); static void volume_widget_finalize (GObject *object); static void volume_widget_set_twin_item( VolumeWidget* self, DbusmenuMenuitem* twin_item); -static void volume_widget_set_ido_position(VolumeWidget* self, - gdouble new_volume); -//callbacks static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); static gboolean volume_widget_change_value_cb (GtkRange *range, @@ -92,13 +89,11 @@ volume_widget_init (VolumeWidget *self) GtkWidget* volume_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); - // register slider changes listening on the range - //g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); + g_signal_connect(volume_widget, "change-value", G_CALLBACK(volume_widget_change_value_cb), self); g_signal_connect(volume_widget, "value-changed", G_CALLBACK(volume_widget_value_changed_cb), self); g_signal_connect(priv->ido_volume_slider, "slider-grabbed", G_CALLBACK(volume_widget_slider_grabbed), self); g_signal_connect(priv->ido_volume_slider, "slider-released", G_CALLBACK(volume_widget_slider_released), self); - // Set images on the ido GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)priv->ido_volume_slider); GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks("audio-volume-low-zero-panel"); gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU); @@ -134,11 +129,14 @@ volume_widget_property_update(DbusmenuMenuitem* item, gchar* property, VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); g_debug("scrub-widget::property_update for prop %s", property); if(g_ascii_strcasecmp(DBUSMENU_VOLUME_MENUITEM_LEVEL, property) == 0){ - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); - GtkRange *range = (GtkRange*)slider; - gdouble update = g_value_get_double (value); - g_debug("volume-widget - update level with value %f", update); - gtk_range_set_value(range, update); + if(priv->grabbed == FALSE){ + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + GtkRange *range = (GtkRange*)slider; + gdouble update = g_value_get_double (value); + g_debug("volume-widget - update level with value %f", update); + gtk_range_set_value(range, update); + determine_state_from_volume(update); + } } } @@ -151,11 +149,6 @@ volume_widget_set_twin_item(VolumeWidget* self, g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(volume_widget_property_update), self); - - /*volume_widget_set_ido_position(self, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_POSITION)/1000, - dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION)); - */ } static gboolean @@ -167,17 +160,9 @@ volume_widget_change_value_cb (GtkRange *range, g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); VolumeWidget* mitem = VOLUME_WIDGET(user_data); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - - // Don't bother when the slider is grabbed - if(priv->grabbed == TRUE) - return FALSE; - - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - gdouble clamped = CLAMP(new_value, 0, 100); - g_value_set_double(&value, clamped); - dbusmenu_menuitem_handle_event (priv->twin_item, "grabbed", &value, 0); - return TRUE; + volume_widget_update(mitem, new_value); + determine_state_from_volume(new_value); + return FALSE; } static gboolean @@ -186,25 +171,30 @@ volume_widget_value_changed_cb(GtkRange *range, gpointer user_data) g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); VolumeWidget* mitem = VOLUME_WIDGET(user_data); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); - - if(priv->grabbed == TRUE){ - return TRUE; - } + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(slider)), 0, 100); - gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(priv->ido_volume_slider)), 0, 100); - - GValue value = {0}; + // We just want this callback to catch mouse icon press events + // which set the slider to 0 or 100 + if(current_value == 0 || current_value == 100){ + volume_widget_update(mitem, current_value); + } + return TRUE; +} + +void +volume_widget_update(VolumeWidget* self, gdouble update) +{ + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); + GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); - g_value_set_double(&value, current_value); - g_debug("volume_widget_value changed callback - = %f", current_value); - dbusmenu_menuitem_handle_event (priv->twin_item, "slider_change", &value, 0); - // This is not ideal in that the icon ui will update on ui actions and not on actual service feedback. - // but necessary for now as the server does not send volume update information if the source of change was this ui. - //determine_state_from_volume(current_value); - return FALSE; + gdouble clamped = CLAMP(update, 0, 100); + g_value_set_double(&value, clamped); + dbusmenu_menuitem_handle_event (priv->twin_item, "update", &value, 0); } + GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self) { @@ -220,18 +210,6 @@ volume_widget_parent_changed (GtkWidget *widget, g_debug("volume_widget_parent_changed"); } - -//TODO: are we using this as convenience function -static void -volume_widget_set_ido_position(VolumeWidget* self, - gdouble new_volume) -{ - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); - GtkRange *range = (GtkRange*)slider; - gtk_range_set_value(range, new_volume); -} - static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data) { @@ -246,17 +224,8 @@ volume_widget_slider_released(GtkWidget *widget, gpointer user_data) VolumeWidget* mitem = VOLUME_WIDGET(user_data); VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); priv->grabbed = FALSE; - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); - gdouble new_value = gtk_range_get_value(GTK_RANGE(slider)); - g_debug("okay set the scrub position with %f", new_value); - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - gdouble clamped = CLAMP(new_value, 0, 100); - g_value_set_double(&value, clamped); - dbusmenu_menuitem_handle_event (priv->twin_item, "volume-change", &value, 0); } - /** * volume_widget_new: * @returns: a new #VolumeWidget. diff --git a/src/volume-widget.h b/src/volume-widget.h index 7e6ab84..2b48c39 100644 --- a/src/volume-widget.h +++ b/src/volume-widget.h @@ -46,6 +46,7 @@ struct _VolumeWidget { GType volume_widget_get_type (void) G_GNUC_CONST; GtkWidget* volume_widget_new(DbusmenuMenuitem* twin_item); GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self); +void volume_widget_update(VolumeWidget* self, gdouble update); G_END_DECLS -- cgit v1.2.3 From 7beb889ea4838851ac5baeaecb30634855f43459 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 4 Aug 2010 11:32:25 +0100 Subject: refactor complete --- src/dbus-menu-manager.c | 2 +- src/indicator-sound.c | 28 ++++++++++++---------------- src/indicator-sound.h | 2 +- src/sound-service-dbus.c | 46 ---------------------------------------------- src/sound-service-dbus.h | 1 - src/sound-service.xml | 14 -------------- src/volume-widget.c | 15 ++++++++++----- 7 files changed, 24 insertions(+), 84 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index d7d12b2..5b97a0d 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -105,7 +105,7 @@ void dbus_menu_manager_update_pa_state(gboolean pa_state, gboolean sink_availabl // 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_volume(dbus_interface, percent); + 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); } diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 599d969..4f449c1 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -335,26 +335,26 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - volume_widget = volume_widget_new (newitem); - GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(volume_widget)); - + volume_widget = volume_widget_new (newitem); io = g_object_get_data (G_OBJECT (client), "indicator"); IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); priv->volume_widget = volume_widget; - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)ido_slider_widget); - g_signal_connect(slider, "style-set", G_CALLBACK(style_changed_cb), NULL); - - gtk_widget_show_all(ido_slider_widget); + GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); + + g_signal_connect(ido_slider_widget, "style-set", G_CALLBACK(style_changed_cb), NULL); gtk_widget_set_sensitive(ido_slider_widget, !initial_mute); + gtk_widget_show_all(ido_slider_widget); + GtkMenuItem *menu_volume_item = GTK_MENU_ITEM(ido_slider_widget); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_item, parent); - fetch_mute_value_from_dbus(); + + fetch_mute_value_from_dbus(); fetch_sink_availability_from_dbus(INDICATOR_SOUND (io)); return TRUE; @@ -579,11 +579,8 @@ fetch_sink_availability_from_dbus(IndicatorSound* self) } IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); - GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); - - g_debug("past it"); - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); - gtk_widget_set_sensitive(slider, device_available); + GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); + gtk_widget_set_sensitive(slider_widget, device_available); g_free(available_input); g_debug("IndicatorSound::fetch_sink_availability_from_dbus -> AVAILABILTY returned from dbus method is %i", device_available); @@ -637,16 +634,15 @@ catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer u reset_mute_blocking_animation(); } g_debug("signal caught - sink mute update with mute value: %i", mute_value); - g_return_if_fail(IS_INDICATOR_SOUND(userdata)); IndicatorSound* indicator = INDICATOR_SOUND(userdata); IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + if(priv->volume_widget == NULL){ return; } GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); - gtk_widget_set_sensitive(slider, !mute_value); + gtk_widget_set_sensitive(slider_widget, !mute_value); } diff --git a/src/indicator-sound.h b/src/indicator-sound.h index cf1535b..251295c 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -49,7 +49,7 @@ struct _IndicatorSound { GType indicator_sound_get_type (void); void prepare_state_machine(); -void determine_state_from_volume(gdouble volume_percent); +extern void determine_state_from_volume(gdouble volume_percent); gint get_state(); gchar* get_state_image_name(gint state); void prepare_for_tests(IndicatorObject * io); diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 85945d0..d553285 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -29,10 +29,8 @@ #include "pulse-manager.h" // DBUS methods -static gboolean sound_service_dbus_get_sink_volume(SoundServiceDbus* service, gdouble* volume_percent_input, GError** gerror); static gboolean sound_service_dbus_get_sink_mute(SoundServiceDbus* service, gboolean* mute_input, GError** gerror); static gboolean sound_service_dbus_get_sink_availability(SoundServiceDbus* service, gboolean* availability_input, GError** gerror); -static void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror); #include "sound-service-server.h" @@ -40,7 +38,6 @@ typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate; struct _SoundServiceDbusPrivate { DBusGConnection *connection; - gdouble volume_percent; gboolean mute; gboolean sink_availability; }; @@ -49,7 +46,6 @@ struct _SoundServiceDbusPrivate { /* Signals */ enum { SINK_INPUT_WHILE_MUTED, - SINK_VOLUME_UPDATE, SINK_MUTE_UPDATE, SINK_AVAILABLE_UPDATE, LAST_SIGNAL @@ -65,7 +61,6 @@ static void sound_service_dbus_init (SoundServiceDbus *self); static void sound_service_dbus_dispose (GObject *object); static void sound_service_dbus_finalize (GObject *object); - /* GObject Boilerplate */ G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); @@ -91,14 +86,6 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - signals[SINK_VOLUME_UPDATE] = g_signal_new("sink-volume-update", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - g_cclosure_marshal_VOID__DOUBLE, - G_TYPE_NONE, 1, G_TYPE_DOUBLE); - signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, @@ -113,9 +100,6 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) NULL, NULL, g_cclosure_marshal_VOID__BOOLEAN, G_TYPE_NONE, 1, G_TYPE_BOOLEAN); - - - } static void @@ -125,7 +109,6 @@ sound_service_dbus_init (SoundServiceDbus *self) SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); priv->connection = NULL; - priv->volume_percent = 0; priv->mute = FALSE; priv->sink_availability = FALSE; @@ -159,23 +142,6 @@ sound_service_dbus_finalize (GObject *object) } -/** -DBUS Method Callbacks -**/ -static void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror) -{ - g_debug("in the set sink volume method in the sound service dbus!, with volume_percent of %i", volume_percent); - set_sink_volume(volume_percent); -} - -static gboolean sound_service_dbus_get_sink_volume (SoundServiceDbus *self, gdouble *volume_percent_input, GError** gerror) -{ - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - g_debug("Get sink volume method in the sound service dbus!, about to send over volume percent of %f", priv->volume_percent); - *volume_percent_input = priv->volume_percent; - return TRUE; -} - static gboolean sound_service_dbus_get_sink_mute (SoundServiceDbus *self, gboolean *mute_input, GError** gerror) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); @@ -205,18 +171,6 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gboolean block_value); } -void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume) -{ - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); - priv->volume_percent = sink_volume; - - /* g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", priv->volume_percent);*/ - g_signal_emit(obj, - signals[SINK_VOLUME_UPDATE], - 0, - priv->volume_percent); -} - void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute) { /* g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute);*/ diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index 72556ad..b6e8193 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -52,7 +52,6 @@ GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the SIGNAL messages across into the sound-service-dbus void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gboolean block_value); -void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute); void sound_service_dbus_update_sink_availability(SoundServiceDbus* obj, gboolean sink_availibity); diff --git a/src/sound-service.xml b/src/sound-service.xml index 12ed03e..ee19ceb 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -1,16 +1,6 @@ - - - - - - - - - - @@ -28,10 +18,6 @@ Our respective UI element should listen to this and therefore will be updated wi - - - - diff --git a/src/volume-widget.c b/src/volume-widget.c index 77c2b25..24fb46d 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -44,7 +44,7 @@ static void volume_widget_class_init (VolumeWidgetClass *klass); static void volume_widget_init (VolumeWidget *self); static void volume_widget_dispose (GObject *object); static void volume_widget_finalize (GObject *object); -static void volume_widget_set_twin_item( VolumeWidget* self, +static void volume_widget_set_twin_item( VolumeWidget* self, DbusmenuMenuitem* twin_item); static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); @@ -52,9 +52,7 @@ static gboolean volume_widget_change_value_cb (GtkRange *range, GtkScrollType scroll, gdouble value, gpointer user_data); -static gboolean volume_widget_value_changed_cb(GtkRange *range, - gpointer user_data); - +static gboolean volume_widget_value_changed_cb(GtkRange *range, gpointer user_data); static void volume_widget_slider_grabbed(GtkWidget *widget, gpointer user_data); static void volume_widget_slider_released(GtkWidget *widget, gpointer user_data); static void volume_widget_parent_changed (GtkWidget *widget, gpointer user_data); @@ -149,6 +147,14 @@ volume_widget_set_twin_item(VolumeWidget* self, g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(volume_widget_property_update), self); + gdouble initial_level = g_value_get_double (dbusmenu_menuitem_property_get_value(twin_item, + DBUSMENU_VOLUME_MENUITEM_LEVEL)); + g_debug("volume_widget_set_twin_item initial level = %f", initial_level); + //volume_widget_update(self, initial_level); + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); + GtkRange *range = (GtkRange*)slider; + gtk_range_set_value(range, initial_level); + determine_state_from_volume(initial_level); } static gboolean @@ -159,7 +165,6 @@ volume_widget_change_value_cb (GtkRange *range, { g_return_val_if_fail (IS_VOLUME_WIDGET (user_data), FALSE); VolumeWidget* mitem = VOLUME_WIDGET(user_data); - VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); volume_widget_update(mitem, new_value); determine_state_from_volume(new_value); return FALSE; -- cgit v1.2.3 From c161dea6be8043d5a4a543ffe1229253e46f02ea Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 4 Aug 2010 11:55:27 +0100 Subject: tidy ups --- src/indicator-sound.c | 1 - src/volume-widget.c | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 4f449c1..ff69fff 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -103,7 +103,6 @@ static const gint STATE_MEDIUM = 3; static const gint STATE_HIGH = 4; static const gint STATE_MUTED_WHILE_INPUT = 5; static const gint STATE_SINKS_NONE = 6; -static const gint OUT_OF_RANGE = -10; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; diff --git a/src/volume-widget.c b/src/volume-widget.c index 24fb46d..69fa28f 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -184,7 +184,7 @@ volume_widget_value_changed_cb(GtkRange *range, gpointer user_data) if(current_value == 0 || current_value == 100){ volume_widget_update(mitem, current_value); } - return TRUE; + return FALSE; } void -- cgit v1.2.3 From 4a23580e7fc69500ae2a843c2b883d6f0d310b23 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 4 Aug 2010 12:25:50 +0100 Subject: tidy ups --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 16fa87c..8768cd3 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 734cf9dc8224140b6b729c09237d598aec546ef3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 6 Aug 2010 13:20:03 +0100 Subject: merge comments have been acted upon --- src/indicator-sound.c | 15 +++++++-------- src/metadata-widget.h | 2 +- src/scrub-widget.h | 2 +- src/slider-menu-item.c | 1 - src/title-widget.h | 2 +- src/transport-widget.h | 2 +- src/volume-widget.c | 11 ++++++----- src/volume-widget.h | 2 +- 8 files changed, 18 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index ff69fff..557ce85 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -557,6 +557,8 @@ reset_mute_blocking_animation() static void fetch_sink_availability_from_dbus(IndicatorSound* self) { + g_return_if_fail(IS_INDICATOR_SOUND(self)); + GError * error = NULL; gboolean * available_input; available_input = g_new0(gboolean, 1); @@ -573,17 +575,13 @@ fetch_sink_availability_from_dbus(IndicatorSound* self) update_state(STATE_SINKS_NONE); g_debug("NO DEVICE AVAILABLE"); } - if(IS_INDICATOR_SOUND(self) == FALSE){ - g_warning("okay pointer is arseways"); - } IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); gtk_widget_set_sensitive(slider_widget, device_available); g_free(available_input); - g_debug("IndicatorSound::fetch_sink_availability_from_dbus -> AVAILABILTY returned from dbus method is %i", device_available); - + g_debug("IndicatorSound::fetch_sink_availability_from_dbus ->%i", device_available); } @@ -621,12 +619,13 @@ catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gp } } - +/* + We can be sure the service won't send a mute signal unless it has changed ! + UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. +*/ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) { - //We can be sure the service won't send a mute signal unless it has changed ! - //UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. if (mute_value == TRUE && device_available == TRUE) { update_state(STATE_MUTED); } else { diff --git a/src/metadata-widget.h b/src/metadata-widget.h index 6f1d4d3..814d5e8 100644 --- a/src/metadata-widget.h +++ b/src/metadata-widget.h @@ -20,7 +20,7 @@ with this program. If not, see . #define __METADATA_WIDGET_H__ #include -#include +#include G_BEGIN_DECLS diff --git a/src/scrub-widget.h b/src/scrub-widget.h index cebe890..e518a80 100644 --- a/src/scrub-widget.h +++ b/src/scrub-widget.h @@ -21,7 +21,7 @@ with this program. If not, see . #include #include -#include +#include G_BEGIN_DECLS diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 9536ff8..77c8635 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -79,7 +79,6 @@ slider_menu_item_finalize (GObject *object) static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp) { - g_debug("in the handle event method of slider_menu_item"); gdouble volume_input = 0; volume_input = g_value_get_double(value); if (value != NULL) diff --git a/src/title-widget.h b/src/title-widget.h index efc0c78..fc8f169 100644 --- a/src/title-widget.h +++ b/src/title-widget.h @@ -20,7 +20,7 @@ with this program. If not, see . #define __TITLE_WIDGET_H__ #include -#include +#include G_BEGIN_DECLS diff --git a/src/transport-widget.h b/src/transport-widget.h index 1d1aa6e..c69836a 100644 --- a/src/transport-widget.h +++ b/src/transport-widget.h @@ -20,7 +20,7 @@ with this program. If not, see . #define __TRANSPORT_WIDGET_H__ #include -#include +#include G_BEGIN_DECLS diff --git a/src/volume-widget.c b/src/volume-widget.c index 69fa28f..bf1ddb9 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -77,7 +77,7 @@ volume_widget_init (VolumeWidget *self) VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); priv->ido_volume_slider = ido_scale_menu_item_new_with_range ("VOLUME", IDO_RANGE_STYLE_DEFAULT, 0, 0, 100, 1); - + g_object_ref (priv->ido_volume_slider); ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM (priv->ido_volume_slider), IDO_SCALE_MENU_ITEM_STYLE_IMAGE); g_object_set(priv->ido_volume_slider, "reverse-scroll-events", TRUE, NULL); @@ -144,13 +144,12 @@ volume_widget_set_twin_item(VolumeWidget* self, { VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(self); priv->twin_item = twin_item; - + g_object_ref(priv->twin_item); g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(volume_widget_property_update), self); gdouble initial_level = g_value_get_double (dbusmenu_menuitem_property_get_value(twin_item, DBUSMENU_VOLUME_MENUITEM_LEVEL)); g_debug("volume_widget_set_twin_item initial level = %f", initial_level); - //volume_widget_update(self, initial_level); GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); GtkRange *range = (GtkRange*)slider; gtk_range_set_value(range, initial_level); @@ -170,6 +169,10 @@ volume_widget_change_value_cb (GtkRange *range, return FALSE; } +/* + We only want this callback to catch mouse icon press events + which set the slider to 0 or 100. Ignore all other events. +*/ static gboolean volume_widget_value_changed_cb(GtkRange *range, gpointer user_data) { @@ -179,8 +182,6 @@ volume_widget_value_changed_cb(GtkRange *range, gpointer user_data) GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_volume_slider); gdouble current_value = CLAMP(gtk_range_get_value(GTK_RANGE(slider)), 0, 100); - // We just want this callback to catch mouse icon press events - // which set the slider to 0 or 100 if(current_value == 0 || current_value == 100){ volume_widget_update(mitem, current_value); } diff --git a/src/volume-widget.h b/src/volume-widget.h index 2b48c39..d4929ec 100644 --- a/src/volume-widget.h +++ b/src/volume-widget.h @@ -21,7 +21,7 @@ with this program. If not, see . #include #include -#include +#include G_BEGIN_DECLS -- cgit v1.2.3 From 85a7764a2aeba260e2a2531dd28be66ec0680d6f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Sat, 7 Aug 2010 12:03:26 +0100 Subject: starting on the re write for mpris handling --- src/mpris-controller-v2.vala | 28 --------- src/mpris2-controller.vala | 139 +++++++++++++++++++++++++++++++++++++++++++ src/player-controller.vala | 1 + src/sound-service.c | 4 +- 4 files changed, 142 insertions(+), 30 deletions(-) delete mode 100644 src/mpris-controller-v2.vala create mode 100644 src/mpris2-controller.vala (limited to 'src') diff --git a/src/mpris-controller-v2.vala b/src/mpris-controller-v2.vala deleted file mode 100644 index efb5084..0000000 --- a/src/mpris-controller-v2.vala +++ /dev/null @@ -1,28 +0,0 @@ -/* -This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. -Copyright 2010 Canonical Ltd. - -Authors: - Conor Curran - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ -using Gee; - -public class MprisControllerV2 : MprisController -{ - public MprisControllerV2(PlayerController ctrl, string inter="org.mpris.MediaPlayer.Player"){ - Object(owner: ctrl, mpris_interface: inter); - } - -} diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala new file mode 100644 index 0000000..4430776 --- /dev/null +++ b/src/mpris2-controller.vala @@ -0,0 +1,139 @@ +/* +This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ +using Gee; +/* + This class will entirely replace mpris-controller.vala hence why there is no + point in trying to get encorporate both into the same object model. + */ +public class Mpris2Controller +{ + private DBus.Connection connection; + public dynamic DBus.Object mpris_root + public dynamic DBus.Object mpris_player + public PlayerController owner {get; construct;} + + public Mpris2Controller(PlayerController ctrl) + { + Object(owner: ctrl); + } + + construct{ + try { + this.connection = DBus.Bus.get (DBus.BusType.SESSION); + } catch (Error e) { + error("Problems connecting to the session bus - %s", e.message); + } + this.mpris_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), + "/org/mpris/MediaPlayer", + "org.mpris.MediaPlayer"); + + this.mpris_player = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , + "/org/mpris/MediaPlayer/Player", + "org.mpris.MediaPlayer.Player"); + + + this.mpris_player.TrackChange += onTrackChange; + this.mpris_player.StatusChange += onStatusChange; + initial_update(); + } + + private void initial_update() + { + status st = this.mpris_player.Status; + int play_state = st.playback; + debug("GetStatusChange - play state %i", play_state); + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris_player.GetMetadata(), + MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), + ScrubMenuitem.attributes_format()); + // temporary fix + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_position(this.mpris_player.PositionGet()); + } + + public void transport_event(TransportMenuitem.action command) + { + debug("transport_event input = %i", (int)command); + if(command == TransportMenuitem.action.PLAY_PAUSE){ + debug("transport_event PLAY_PAUSE"); + this.mpris_player.Pause(); + } + else if(command == TransportMenuitem.action.PREVIOUS){ + this.mpris_player.Prev(); + } + else if(command == TransportMenuitem.action.NEXT){ + this.mpris_player.Next(); + } + } + + public void set_position(double position) + { + debug("Set position with pos (0-100) %f", position); + HashTable data = this.mpris_player.GetMetadata(); + Value? time_value = data.lookup("time"); + if(time_value == null){ + warning("Can't fetch the duration of the track therefore cant set the position"); + return; + } + uint32 total_time = time_value.get_uint(); + debug("total time of track = %i", (int)total_time); + double new_time_position = total_time * position/100.0; + debug("new position = %f", (new_time_position * 1000)); + this.mpris_player.PositionSet((int32)(new_time_position)); + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_position(this.mpris_player.PositionGet()); + } + + public bool connected() + { + return (this.mpris_player != null); + } + + private void onStatusChange(dynamic DBus.Object mpris_client, status st) + { + debug("onStatusChange - signal received"); + status* status = &st; + unowned ValueArray ar = (ValueArray)status; + int play_state = ar.get_nth(0).get_int(); + debug("onStatusChange - play state %i", play_state); + HashTable ht = new HashTable(str_hash, str_equal); + Value v = Value(typeof(int)); + v.set_int(play_state); + ht.insert("state", v); + this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); + } + + private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) + { + debug("onTrackChange"); + this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, + MetadataMenuitem.attributes_format()); + debug("about to update the duration on the scrub bar"); + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), + ScrubMenuitem.attributes_format()); + // temporary fix + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_position(this.mpris_player.PositionGet()); + } +} diff --git a/src/player-controller.vala b/src/player-controller.vala index fc5ca9b..1dac937 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -102,6 +102,7 @@ public class PlayerController : GLib.Object return; } + if(this.name == "Vlc"){ debug("establishing a vlc mpris controller"); this.mpris_adaptor = new MprisController(this, "org.mpris.MediaPlayer.Player"); diff --git a/src/sound-service.c b/src/sound-service.c index 8768cd3..16fa87c 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 383f76b32f0e58da4051a111bd51d01d58fd7e10 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Sat, 7 Aug 2010 14:57:47 +0100 Subject: mpris 2 underway, vala bindings proving troublesome --- src/Makefile.am | 2 +- src/mpris2-controller.vala | 62 +++++++++++++++++++++++++++------------------- src/player-controller.vala | 6 ++--- 3 files changed, 41 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index ce7a580..0f2962a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,8 +65,8 @@ music_bridge_VALASOURCES = \ scrub-menu-item.vala \ title-menu-item.vala \ player-controller.vala \ - mpris-controller-v2.vala \ mpris-controller.vala \ + mpris2-controller.vala \ player-item.vala \ familiar-players-db.vala diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 4430776..8a5f255 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -22,12 +22,20 @@ using Gee; This class will entirely replace mpris-controller.vala hence why there is no point in trying to get encorporate both into the same object model. */ -public class Mpris2Controller +public class Mpris2Controller : GLib.Object { private DBus.Connection connection; - public dynamic DBus.Object mpris_root - public dynamic DBus.Object mpris_player + public dynamic DBus.Object mpris2_root {get; construct;} + public dynamic DBus.Object mpris2_player {get; construct;} public PlayerController owner {get; construct;} + + struct status { + public int32 playback; + public double shuffle; + public bool repeat; + public bool endless; + public bool endlessy; + } public Mpris2Controller(PlayerController ctrl) { @@ -36,37 +44,39 @@ public class Mpris2Controller construct{ try { + debug("going to create this mpris 2 controller"); this.connection = DBus.Bus.get (DBus.BusType.SESSION); } catch (Error e) { error("Problems connecting to the session bus - %s", e.message); } - this.mpris_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), + this.mpris2_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), "/org/mpris/MediaPlayer", "org.mpris.MediaPlayer"); - this.mpris_player = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , + this.mpris2_player = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , "/org/mpris/MediaPlayer/Player", - "org.mpris.MediaPlayer.Player"); + "org.mpris.MediaPlayer.Player"); - this.mpris_player.TrackChange += onTrackChange; - this.mpris_player.StatusChange += onStatusChange; + this.mpris2_player.TrackChange += onTrackChange; + this.mpris2_player.StatusChange += onStatusChange; initial_update(); } private void initial_update() { - status st = this.mpris_player.Status; + status st = {0,0.0, false, false,false}; + this.mpris2_player.get("Status", &st); + int play_state = st.playback; debug("GetStatusChange - play state %i", play_state); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris_player.GetMetadata(), - MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), - ScrubMenuitem.attributes_format()); - // temporary fix + this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris2_player.GetMetadata(), + MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.GetMetadata(), + ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris_player.PositionGet()); + scrub.update_position(this.mpris2_player.PositionGet()); } public void transport_event(TransportMenuitem.action command) @@ -74,20 +84,20 @@ public class Mpris2Controller debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); - this.mpris_player.Pause(); + this.mpris2_player.Pause(); } else if(command == TransportMenuitem.action.PREVIOUS){ - this.mpris_player.Prev(); + this.mpris2_player.Prev(); } else if(command == TransportMenuitem.action.NEXT){ - this.mpris_player.Next(); + this.mpris2_player.Next(); } } public void set_position(double position) { debug("Set position with pos (0-100) %f", position); - HashTable data = this.mpris_player.GetMetadata(); + HashTable data = this.mpris2_player.GetMetadata(); Value? time_value = data.lookup("time"); if(time_value == null){ warning("Can't fetch the duration of the track therefore cant set the position"); @@ -97,14 +107,15 @@ public class Mpris2Controller debug("total time of track = %i", (int)total_time); double new_time_position = total_time * position/100.0; debug("new position = %f", (new_time_position * 1000)); - this.mpris_player.PositionSet((int32)(new_time_position)); + this.mpris2_player.SetPosition((int32)(new_time_position)); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris_player.PositionGet()); + scrub.update_position(this.mpris2_player.PositionGet()); + } public bool connected() { - return (this.mpris_player != null); + return (this.mpris2_player != null); } private void onStatusChange(dynamic DBus.Object mpris_client, status st) @@ -120,6 +131,7 @@ public class Mpris2Controller ht.insert("state", v); this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); + } private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) @@ -130,10 +142,10 @@ public class Mpris2Controller this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, MetadataMenuitem.attributes_format()); debug("about to update the duration on the scrub bar"); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.GetMetadata(), ScrubMenuitem.attributes_format()); - // temporary fix ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris_player.PositionGet()); + scrub.update_position(this.mpris2_player.PositionGet()); + } } diff --git a/src/player-controller.vala b/src/player-controller.vala index 1dac937..60f27ca 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -48,7 +48,7 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - public MprisController mpris_adaptor; + public Mpris2Controller mpris_adaptor; public AppInfo? app_info { get; set;} public int menu_offset { get; set;} @@ -105,10 +105,10 @@ public class PlayerController : GLib.Object if(this.name == "Vlc"){ debug("establishing a vlc mpris controller"); - this.mpris_adaptor = new MprisController(this, "org.mpris.MediaPlayer.Player"); + this.mpris_adaptor = new Mpris2Controller(this); } else{ - this.mpris_adaptor = new MprisController(this); + //this.mpris_adaptor = new MprisController(this); } // TODO refactor if(this.mpris_adaptor.connected() == true){ -- cgit v1.2.3 From e5a739d750c38bdcb1eb033fc9749f1228d9286c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 9 Aug 2010 14:58:10 +0100 Subject: trying to get a static client implementation working --- src/mpris2-controller.vala | 89 +++++++++++++++++++++++++++++++--------------- src/player-controller.vala | 4 +-- 2 files changed, 62 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 8a5f255..4555fca 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -18,6 +18,29 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ using Gee; + +/*struct Status { + public int32 playback; + public double shuffle; + public bool repeat; + public bool endless; + public bool endlessy; +}*/ + +[DBus (name = "org.mpris.mediaplayers.vlc")] +public interface MprisPlayer : Object { + public abstract struct Status { + public int32 Playback_State; + public double Playback_Rate; + public bool Repeat_State; + public bool Shuffle_State; + public bool Endless_State; + } + + + //public abstract struct Status () throws DBus.Error; +} + /* This class will entirely replace mpris-controller.vala hence why there is no point in trying to get encorporate both into the same object model. @@ -26,16 +49,16 @@ public class Mpris2Controller : GLib.Object { private DBus.Connection connection; public dynamic DBus.Object mpris2_root {get; construct;} - public dynamic DBus.Object mpris2_player {get; construct;} + public MprisPlayer mpris2_player {get; construct;} public PlayerController owner {get; construct;} - struct status { - public int32 playback; - public double shuffle; - public bool repeat; - public bool endless; - public bool endlessy; - } + /*struct status { + public int32 Playback_State; + public double Playback_Rate; + public bool Repeat_State; + public bool Shuffle_State; + public bool Endless_State; + }*/ public Mpris2Controller(PlayerController ctrl) { @@ -53,34 +76,38 @@ public class Mpris2Controller : GLib.Object "/org/mpris/MediaPlayer", "org.mpris.MediaPlayer"); - this.mpris2_player = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , - "/org/mpris/MediaPlayer/Player", - "org.mpris.MediaPlayer.Player"); - - - this.mpris2_player.TrackChange += onTrackChange; - this.mpris2_player.StatusChange += onStatusChange; + this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , + "/org/mpris/MediaPlayer/Player", + "org.mpris.MediaPlayer.Player"); + //this.mpris2_player.TrackChange += onTrackChange; + //this.mpris2_player.StatusChange += onStatusChange; initial_update(); } private void initial_update() { - status st = {0,0.0, false, false,false}; - this.mpris2_player.get("Status", &st); + //status st = this.mpris2_player.Status; + //unowned ValueArray ar = (ValueArray)st; + //unowned ValueArray ar = (ValueArray)this.mpris2_player.Status; + bool r = (bool)this.mpris2_player.Status.Shuffle_State; + int32 p = (int32)this.mpris2_player.Status.Playback_State; + + debug("initial update - play state %i", p); + debug("initial update - shuffle state %s", r.to_string()); - int play_state = st.playback; - debug("GetStatusChange - play state %i", play_state); - (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); + /*(this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris2_player.GetMetadata(), MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.GetMetadata(), ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.PositionGet()); + */ } public void transport_event(TransportMenuitem.action command) { + /* debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); @@ -92,10 +119,12 @@ public class Mpris2Controller : GLib.Object else if(command == TransportMenuitem.action.NEXT){ this.mpris2_player.Next(); } + */ } public void set_position(double position) { + /* debug("Set position with pos (0-100) %f", position); HashTable data = this.mpris2_player.GetMetadata(); Value? time_value = data.lookup("time"); @@ -110,7 +139,7 @@ public class Mpris2Controller : GLib.Object this.mpris2_player.SetPosition((int32)(new_time_position)); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.PositionGet()); - + */ } public bool connected() @@ -118,9 +147,10 @@ public class Mpris2Controller : GLib.Object return (this.mpris2_player != null); } - private void onStatusChange(dynamic DBus.Object mpris_client, status st) - { - debug("onStatusChange - signal received"); + //private void onStatusChange(dynamic DBus.Object mpris_client, status st) + //{ + /* + debug("onStatusChange - signal received"); status* status = &st; unowned ValueArray ar = (ValueArray)status; int play_state = ar.get_nth(0).get_int(); @@ -131,12 +161,12 @@ public class Mpris2Controller : GLib.Object ht.insert("state", v); this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); - - } + */ + //} private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) { - debug("onTrackChange"); + /*(debug("onTrackChange"); this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, @@ -146,6 +176,9 @@ public class Mpris2Controller : GLib.Object ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.PositionGet()); - + */ } } + + + diff --git a/src/player-controller.vala b/src/player-controller.vala index 60f27ca..84d2374 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -100,9 +100,7 @@ public class PlayerController : GLib.Object if(this.current_state != state.READY){ debug("establish_mpris_connection - Not ready to connect"); return; - } - - + } if(this.name == "Vlc"){ debug("establishing a vlc mpris controller"); this.mpris_adaptor = new Mpris2Controller(this); -- cgit v1.2.3 From 161d2b1e2d2ca940a37b97627e32b6bb074eaf76 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 9 Aug 2010 21:42:24 +0100 Subject: vala dbus issues resolved --- src/Makefile.am | 1 + src/mpris2-controller.vala | 46 +++++++++++++++++----------------------------- 2 files changed, 18 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 0f2962a..0e22fe4 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -72,6 +72,7 @@ music_bridge_VALASOURCES = \ music_bridge_VALAFLAGS = \ --ccode \ + --disable-dbus-transformation \ -H music-player-bridge.h -d . \ --vapidir=$(top_srcdir)/vapi/ \ --vapidir=./ \ diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 4555fca..750f69a 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -19,26 +19,22 @@ with this program. If not, see . */ using Gee; -/*struct Status { - public int32 playback; - public double shuffle; - public bool repeat; - public bool endless; - public bool endlessy; -}*/ -[DBus (name = "org.mpris.mediaplayers.vlc")] +[DBus (name = "org.mpris.MediaPlayer.Player")] public interface MprisPlayer : Object { - public abstract struct Status { + public struct Status { public int32 Playback_State; public double Playback_Rate; public bool Repeat_State; public bool Shuffle_State; public bool Endless_State; } + public abstract void PlayPause() throws DBus.Error; + public abstract void Pause() throws DBus.Error; + public abstract void Next() throws DBus.Error; + public abstract void Previous() throws DBus.Error; - - //public abstract struct Status () throws DBus.Error; + public abstract signal void StatusChanged(Status update); } /* @@ -51,14 +47,6 @@ public class Mpris2Controller : GLib.Object public dynamic DBus.Object mpris2_root {get; construct;} public MprisPlayer mpris2_player {get; construct;} public PlayerController owner {get; construct;} - - /*struct status { - public int32 Playback_State; - public double Playback_Rate; - public bool Repeat_State; - public bool Shuffle_State; - public bool Endless_State; - }*/ public Mpris2Controller(PlayerController ctrl) { @@ -80,7 +68,7 @@ public class Mpris2Controller : GLib.Object "/org/mpris/MediaPlayer/Player", "org.mpris.MediaPlayer.Player"); //this.mpris2_player.TrackChange += onTrackChange; - //this.mpris2_player.StatusChange += onStatusChange; + this.mpris2_player.StatusChanged += onStatusChanged; initial_update(); } @@ -106,20 +94,18 @@ public class Mpris2Controller : GLib.Object } public void transport_event(TransportMenuitem.action command) - { - /* + { debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); - this.mpris2_player.Pause(); + this.mpris2_player.PlayPause(); } else if(command == TransportMenuitem.action.PREVIOUS){ - this.mpris2_player.Prev(); + this.mpris2_player.Previous(); } else if(command == TransportMenuitem.action.NEXT){ this.mpris2_player.Next(); - } - */ + } } public void set_position(double position) @@ -147,8 +133,10 @@ public class Mpris2Controller : GLib.Object return (this.mpris2_player != null); } - //private void onStatusChange(dynamic DBus.Object mpris_client, status st) - //{ + private void onStatusChanged(MprisPlayer.Status st) + { + debug("on status changed - fucking jesus mother of god"); + debug("new playback state = %i", st.Playback_State); /* debug("onStatusChange - signal received"); status* status = &st; @@ -162,7 +150,7 @@ public class Mpris2Controller : GLib.Object this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); */ - //} + } private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) { -- cgit v1.2.3 From ef6a30946561b140d48006dfc98d2707eccfd304 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 10 Aug 2010 12:16:11 +0100 Subject: mpris 2 controller coming together --- src/mpris2-controller.vala | 51 +++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 750f69a..0f94297 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -22,6 +22,7 @@ using Gee; [DBus (name = "org.mpris.MediaPlayer.Player")] public interface MprisPlayer : Object { + public struct Status { public int32 Playback_State; public double Playback_Rate; @@ -29,12 +30,20 @@ public interface MprisPlayer : Object { public bool Shuffle_State; public bool Endless_State; } + + public abstract HashTable Metadata{owned get;} + public abstract double Volume{get;} + public abstract int32 Capabilities{get;} + public abstract int32 Position{get;} + + public abstract void PlayPause() throws DBus.Error; public abstract void Pause() throws DBus.Error; public abstract void Next() throws DBus.Error; public abstract void Previous() throws DBus.Error; public abstract signal void StatusChanged(Status update); + public abstract signal void TrackChanged(HashTable Metadata); } /* @@ -67,7 +76,7 @@ public class Mpris2Controller : GLib.Object this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , "/org/mpris/MediaPlayer/Player", "org.mpris.MediaPlayer.Player"); - //this.mpris2_player.TrackChange += onTrackChange; + this.mpris2_player.TrackChanged += onTrackChanged; this.mpris2_player.StatusChanged += onStatusChanged; initial_update(); } @@ -83,14 +92,14 @@ public class Mpris2Controller : GLib.Object debug("initial update - play state %i", p); debug("initial update - shuffle state %s", r.to_string()); - /*(this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris2_player.GetMetadata(), + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris2_player.Metadata, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.GetMetadata(), + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.Metadata, ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris2_player.PositionGet()); - */ + scrub.update_position(this.mpris2_player.Position); + } public void transport_event(TransportMenuitem.action command) @@ -135,36 +144,32 @@ public class Mpris2Controller : GLib.Object private void onStatusChanged(MprisPlayer.Status st) { - debug("on status changed - fucking jesus mother of god"); - debug("new playback state = %i", st.Playback_State); - /* - debug("onStatusChange - signal received"); - status* status = &st; - unowned ValueArray ar = (ValueArray)status; - int play_state = ar.get_nth(0).get_int(); - debug("onStatusChange - play state %i", play_state); + debug("onStatusChange - play state %i", st.Playback_State); HashTable ht = new HashTable(str_hash, str_equal); Value v = Value(typeof(int)); - v.set_int(play_state); + v.set_int(st.Playback_State); ht.insert("state", v); this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); - */ + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); } - private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) + private void onTrackChanged(HashTable ht) { - /*(debug("onTrackChange"); this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, MetadataMenuitem.attributes_format()); debug("about to update the duration on the scrub bar"); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.GetMetadata(), + + /*foreach(string s in this.mpris2_player.Metadata.get_keys()){ + debug("key %s has value %s", s, + (string)this.mpris2_player.Metadata.lookup(s)); + }*/ + + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.Metadata, ScrubMenuitem.attributes_format()); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris2_player.PositionGet()); - */ + //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + //scrub.update_position(this.mpris2_player.PositionGet()); } } -- cgit v1.2.3 From 9244bd84d655fae8bbb2772d4aac1550b57a7c1c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 10 Aug 2010 12:37:42 +0100 Subject: mpris 2 controller coming together --- src/mpris2-controller.vala | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 0f94297..00d7bb0 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -19,7 +19,6 @@ with this program. If not, see . */ using Gee; - [DBus (name = "org.mpris.MediaPlayer.Player")] public interface MprisPlayer : Object { @@ -36,7 +35,7 @@ public interface MprisPlayer : Object { public abstract int32 Capabilities{get;} public abstract int32 Position{get;} - + public abstract void SetPosition(string prop, int32 pos) throws DBus.Error; public abstract void PlayPause() throws DBus.Error; public abstract void Pause() throws DBus.Error; public abstract void Next() throws DBus.Error; @@ -83,9 +82,6 @@ public class Mpris2Controller : GLib.Object private void initial_update() { - //status st = this.mpris2_player.Status; - //unowned ValueArray ar = (ValueArray)st; - //unowned ValueArray ar = (ValueArray)this.mpris2_player.Status; bool r = (bool)this.mpris2_player.Status.Shuffle_State; int32 p = (int32)this.mpris2_player.Status.Playback_State; @@ -118,10 +114,9 @@ public class Mpris2Controller : GLib.Object } public void set_position(double position) - { - /* + { debug("Set position with pos (0-100) %f", position); - HashTable data = this.mpris2_player.GetMetadata(); + HashTable data = this.mpris2_player.Metadata; Value? time_value = data.lookup("time"); if(time_value == null){ warning("Can't fetch the duration of the track therefore cant set the position"); @@ -131,10 +126,11 @@ public class Mpris2Controller : GLib.Object debug("total time of track = %i", (int)total_time); double new_time_position = total_time * position/100.0; debug("new position = %f", (new_time_position * 1000)); + int32 trackid = this.mpris2_player.Metadata.lookup("trackid"); + debug("the trackid = %i", trackid); this.mpris2_player.SetPosition((int32)(new_time_position)); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris2_player.PositionGet()); - */ + scrub.update_position(this.mpris2_player.Position); } public bool connected() @@ -160,16 +156,11 @@ public class Mpris2Controller : GLib.Object this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, MetadataMenuitem.attributes_format()); debug("about to update the duration on the scrub bar"); - - /*foreach(string s in this.mpris2_player.Metadata.get_keys()){ - debug("key %s has value %s", s, - (string)this.mpris2_player.Metadata.lookup(s)); - }*/ this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.Metadata, ScrubMenuitem.attributes_format()); - //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - //scrub.update_position(this.mpris2_player.PositionGet()); + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_position(this.mpris2_player.Position); } } -- cgit v1.2.3 From eda68d190faa2919a98b3fb0cb30007148634768 Mon Sep 17 00:00:00 2001 From: Bilal Akhtar Date: Wed, 11 Aug 2010 18:32:56 +0530 Subject: Added --page=applications to command args for running gnome-volume-control --- src/dbus-menu-manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 5b97a0d..6f0af9e 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -174,7 +174,7 @@ Bring up the gnome volume preferences dialog static void show_sound_settings_dialog (DbusmenuMenuitem *mi, gpointer user_data) { GError * error = NULL; - if (!g_spawn_command_line_async("gnome-volume-control", &error) && + if (!g_spawn_command_line_async("gnome-volume-control --page=applications", &error) && !g_spawn_command_line_async("xfce4-mixer", &error)) { g_warning("Unable to show dialog: %s", error->message); -- cgit v1.2.3 From b63691637ebc766e90c0da44e76cc7b9cc49872e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 11 Aug 2010 20:04:04 +0100 Subject: mpris2 working for now, but its all going to change again --- src/mpris-controller.vala | 16 ++++++--- src/mpris2-controller.vala | 25 ++++++++++--- src/music-player-bridge.vala | 6 ++-- src/play-button.c | 8 ++--- src/player-controller.vala | 83 +++++++++++++++++++++++++++++++++++--------- src/player-item.vala | 2 ++ src/scrub-menu-item.vala | 7 +++- src/scrub-widget.c | 2 +- src/sound-service.c | 4 +-- src/transport-menu-item.vala | 2 +- 10 files changed, 116 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index 8ecd20a..c70c6d5 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -124,17 +124,23 @@ public class MprisController : GLib.Object private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) { debug("onTrackChange"); + this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); + HashTable status_hash = new HashTable(str_hash, str_equal); + + status st = this.mpris_player.GetStatus(); + int play_state = st.playback; + debug("GetStatusChange, about to update scrub with play state - %i", play_state); + + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_playstate(play_state); + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), + ScrubMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, MetadataMenuitem.attributes_format()); debug("about to update the duration on the scrub bar"); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), - ScrubMenuitem.attributes_format()); // temporary fix - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris_player.PositionGet()); } - - } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 00d7bb0..20cfc9e 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -126,9 +126,18 @@ public class Mpris2Controller : GLib.Object debug("total time of track = %i", (int)total_time); double new_time_position = total_time * position/100.0; debug("new position = %f", (new_time_position * 1000)); - int32 trackid = this.mpris2_player.Metadata.lookup("trackid"); - debug("the trackid = %i", trackid); - this.mpris2_player.SetPosition((int32)(new_time_position)); + + Value? v = this.mpris2_player.Metadata.lookup("trackid"); + if(v != null){ + if(v.holds (typeof (int))){ + debug("the trackid = %i", v.get_int()); + } + else if(v.holds (typeof (string))){ + debug("the trackid = %s", v.get_string()); + } + } + + //this.mpris2_player.SetPosition((int32)(new_time_position)); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); } @@ -156,12 +165,18 @@ public class Mpris2Controller : GLib.Object this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, MetadataMenuitem.attributes_format()); debug("about to update the duration on the scrub bar"); - - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.Metadata, + Value? v = ht.lookup("time"); + if(v != null) + { + debug("with the duration of %i", (int)v.get_uint()); + debug("with Position of %i", this.mpris2_player.Position); + } + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); } + } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 352ea7f..daad42f 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -116,10 +116,8 @@ public class MusicPlayerBridge : GLib.Object if(server_is_not_of_interest(type)) return; string client_name = type.split(".")[1]; if (root_menu != null && client_name != null){ - registered_clients[client_name].vanish(); - registered_clients.remove(client_name); - debug("Successively removed menu_item for client %s from registered_clients", - client_name); + registered_clients[client_name].hibernate(); + debug("Successively offlined client %s", client_name); } } diff --git a/src/play-button.c b/src/play-button.c index 94e6f98..2f3a553 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -28,7 +28,7 @@ Uses code from ctk #include "play-button.h" #define RECT_WIDTH 130.0f -#define Y 5.0f +#define Y 7.0f #define X 37.0f #define INNER_RADIUS 12.5 #define MIDDLE_RADIUS 13.5f @@ -42,16 +42,16 @@ Uses code from ctk #define TRI_HEIGHT 13.0f #define TRI_OFFSET 6.0f #define PREV_X 35.0f -#define PREV_Y 11.0f +#define PREV_Y 13.0f #define NEXT_X 113.0f -#define NEXT_Y 11.0f //prev_y +#define NEXT_Y 13.0f //prev_y #define PAUSE_WIDTH 21.0f #define PAUSE_HEIGHT 27.0f #define BAR_WIDTH 4.5f #define BAR_HEIGHT 24.0f #define BAR_OFFSET 10.0f #define PAUSE_X 78.0f -#define PAUSE_Y 5.0f +#define PAUSE_Y 7.0f #define PLAY_WIDTH 28.0f #define PLAY_HEIGHT 29.0f #define PLAY_PADDING 5.0f diff --git a/src/player-controller.vala b/src/player-controller.vala index 84d2374..33a5b1a 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -48,12 +48,15 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - public Mpris2Controller mpris_adaptor; + public Mpris2Controller mpris2_adaptor; + public MprisController mpris_adaptor; + public bool mpris2; public AppInfo? app_info { get; set;} public int menu_offset { get; set;} public PlayerController(Dbusmenu.Menuitem root, string client_name, int offset, state initial_state) { + this.mpris2 = false; this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); @@ -74,7 +77,7 @@ public class PlayerController : GLib.Object public void activate() { this.establish_mpris_connection(); - this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); + //this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); } /* @@ -103,19 +106,13 @@ public class PlayerController : GLib.Object } if(this.name == "Vlc"){ debug("establishing a vlc mpris controller"); - this.mpris_adaptor = new Mpris2Controller(this); + this.mpris2_adaptor = new Mpris2Controller(this); + this.mpris2 = true; } else{ - //this.mpris_adaptor = new MprisController(this); - } - // TODO refactor - if(this.mpris_adaptor.connected() == true){ - debug("yup I'm connected"); - this.update_state(state.CONNECTED); - } - else{ - this.update_state(state.DISCONNECTED); + this.mpris_adaptor = new MprisController(this); } + this.determine_state(); } public void vanish() @@ -125,8 +122,17 @@ public class PlayerController : GLib.Object } } + public void hibernate() + { + update_state(PlayerController.state.OFFLINE); + this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format()); + this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + this.custom_items[widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); + } + public void update_layout() - { + { + if(this.current_state != state.CONNECTED){ this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, false); @@ -136,12 +142,13 @@ public class PlayerController : GLib.Object false); this.custom_items[widget_order.PLAYLIST].property_set_bool(MENUITEM_PROP_VISIBLE, false); - return; + return; } - debug("update layout - metadata %s", this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format()).to_string()); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); + //debug("metadata id %i", this.custom_items[widget_order.METADATA].id); + debug("update layout - scrub %s", this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format()).to_string()); this.custom_items[widget_order.SCRUB].property_set_bool(MENUITEM_PROP_VISIBLE, this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format())); @@ -151,7 +158,7 @@ public class PlayerController : GLib.Object true); this.custom_items[widget_order.PLAYLIST].property_set_bool(MENUITEM_PROP_VISIBLE, - true); + true); } private void construct_widgets() @@ -213,4 +220,48 @@ public class PlayerController : GLib.Object return formatted; } + // Temporarily we will need to handle to different mpris implemenations + // Do it for now - a couple of weeks should see this messy carry on out of + // the codebase. + public void set_track_position(double pos) + { + if(this.mpris2 == true){ + this.mpris2_adaptor.set_position(pos); + } + else{ + this.mpris_adaptor.set_position(pos); + } + } + + public void transport_update(TransportMenuitem.action update) + { + if(this.mpris2 == true){ + this.mpris2_adaptor.transport_event(update); + } + else{ + this.mpris_adaptor.transport_event(update); + } + } + + public void determine_state() + { + if(this.mpris2 == true){ + if(this.mpris2_adaptor.connected() == true){ + debug("yup I'm connected"); + this.update_state(state.CONNECTED); + } + else{ + this.update_state(state.DISCONNECTED); + } + } + else{ + if(this.mpris_adaptor.connected() == true){ + debug("yup I'm connected"); + this.update_state(state.CONNECTED); + } + else{ + this.update_state(state.DISCONNECTED); + } + } + } } \ No newline at end of file diff --git a/src/player-item.vala b/src/player-item.vala index 288ac47..e5d8bfc 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -79,9 +79,11 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_int(property, (int)v.get_uint()); } else if(v.holds (typeof (bool))){ + debug("with value : %s", v.get_boolean().to_string()); this.property_set_bool(property, v.get_boolean()); } } + if(this.property_get_bool(MENUITEM_PROP_VISIBLE) == false){ this.property_set_bool(MENUITEM_PROP_VISIBLE, true); } diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index ca81c38..e220612 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -32,13 +32,18 @@ public class ScrubMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event for owner %s with value: %f", this.owner.name, input_value.get_double()); - this.owner.mpris_adaptor.set_position(input_value.get_double()); + this.owner.set_track_position(input_value.get_double()); } public void update_position(int32 new_position) { this.property_set_int(MENUITEM_POSITION, new_position); } + + public void update_playstate(int state) + { + this.property_set_int(MENUITEM_PLAY_STATE, state); + } public static HashSet attributes_format() { diff --git a/src/scrub-widget.c b/src/scrub-widget.c index 52d7b83..a1d45d5 100644 --- a/src/scrub-widget.c +++ b/src/scrub-widget.c @@ -174,7 +174,7 @@ scrub_widget_check_play_state(ScrubWidget* self) ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); gint play_state = dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_PLAY_STATE); - + g_debug("play-state = %i", play_state); if(play_state == 0){ g_debug("START TIMELINE"); ido_timeline_start(priv->time_line); diff --git a/src/sound-service.c b/src/sound-service.c index 16fa87c..8768cd3 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 3d6dcdd..45c2692 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -45,7 +45,7 @@ public class TransportMenuitem : PlayerItem int input = input_value.get_int(); debug("handle_event with value %s", input.to_string()); debug("transport owner name = %s", this.owner.name); - this.owner.mpris_adaptor.transport_event((action)input); + this.owner.transport_update((action)input); } public static HashSet attributes_format() -- cgit v1.2.3 From 72ffb2c3c096cf0e7ece12c93bfeff5b651fed13 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 12 Aug 2010 13:21:57 +0100 Subject: abstracted the mpris handling to accomodate the messy integration issues --- src/Makefile.am | 1 + src/mpris-bridge.vala | 60 ++++++++++++++++++++++++++++++++++++++++ src/mpris-controller.vala | 1 - src/mpris2-controller.vala | 44 +++++++++++++++++++---------- src/player-controller.vala | 66 ++++++-------------------------------------- src/scrub-menu-item.vala | 2 +- src/transport-menu-item.vala | 2 +- 7 files changed, 101 insertions(+), 75 deletions(-) create mode 100644 src/mpris-bridge.vala (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 0e22fe4..5d073c7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,6 +65,7 @@ music_bridge_VALASOURCES = \ scrub-menu-item.vala \ title-menu-item.vala \ player-controller.vala \ + mpris-bridge.vala \ mpris-controller.vala \ mpris2-controller.vala \ player-item.vala \ diff --git a/src/mpris-bridge.vala b/src/mpris-bridge.vala new file mode 100644 index 0000000..682069c --- /dev/null +++ b/src/mpris-bridge.vala @@ -0,0 +1,60 @@ +public class MprisBridge : GLib.Object +{ + private MprisController mpris1_controller; + private Mpris2Controller mpris2_controller; + private enum mode{ + MPRIS_1, + MPRIS_2 + } + private mode mode_in_use; + + public MprisBridge(PlayerController ctrl) + { + this.mpris2_controller == new Mpris2Controller(ctrl); + if(this.mpris2_controller.was_successfull() == true){ + mode_in_use == mode.MPRIS_2; + this.mpris1_controller == null; + this.mpris2_controller.initial_update(); + } + else{ + delete this.mpris2_controller; + this.mpris2_controller == null; + mode_in_use == mode.MPRIS_1; + this.mpris1_controller = new Mpris1Controller(ctrl); + } + } + + // The handling of both mpris controllers can be abstracted further + // once the mpris2 is implemented. This will allow for one instance + // variable to point at the active controller. For now handle both ... + public bool connected() + { + if(this.mode_in_use == mode.MPRIS_1){ + return this.mpris1_controller.connected(); + } + else if(this.mode_in_use == mode.MPRIS_2){ + return this.mpris2_controller.connected(); + } + return false; + } + + public void transport_update(TransportMenuitem.action update) + { + if(this.mode_in_use == mode.MPRIS_1){ + this.mpris1_controller.transport_event(update); + } + else if(this.mode_in_use == mode.MPRIS_2){ + this.mpris2_controller.transport_event(update); + } + } + + public void set_track_position(double pos) + { + if(this.mode_in_use == mode.MPRIS_1){ + this.mpris1_controller.set_position(pos); + } + else if(this.mode_in_use == mode.MPRIS_2){ + this.mpris2_controller.set_position(pos); + } + } +} \ No newline at end of file diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index c70c6d5..db71c70 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -63,7 +63,6 @@ public class MprisController : GLib.Object MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), ScrubMenuitem.attributes_format()); - // temporary fix ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris_player.PositionGet()); } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 20cfc9e..6c1b71a 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -58,30 +58,46 @@ public class Mpris2Controller : GLib.Object public Mpris2Controller(PlayerController ctrl) { - Object(owner: ctrl); + Object(owner: ctrl); + this.mpris2_root = null; + this.mpris2_player = null; } construct{ try { - debug("going to create this mpris 2 controller"); + debug("Going to try and create an mpris 2 controller"); this.connection = DBus.Bus.get (DBus.BusType.SESSION); } catch (Error e) { error("Problems connecting to the session bus - %s", e.message); - } - this.mpris2_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), - "/org/mpris/MediaPlayer", - "org.mpris.MediaPlayer"); - - this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , - "/org/mpris/MediaPlayer/Player", - "org.mpris.MediaPlayer.Player"); - this.mpris2_player.TrackChanged += onTrackChanged; - this.mpris2_player.StatusChanged += onStatusChanged; - initial_update(); + } + + try { + this.mpris2_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), + "/org/mpris/MediaPlayer", + "org.mpris.MediaPlayer"); + this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , + "/org/mpris/MediaPlayer/Player", + "org.mpris.MediaPlayer.Player"); + } + catch(Error e){ + error("Problems connecting to + } + } + + public bool was_successfull(){ + if(this.mpris2_root == null || + this.mpris2_player == null) + { + return false; + } + return true; } - private void initial_update() + public void initial_update() { + this.mpris2_player.TrackChanged += onTrackChanged; + this.mpris2_player.StatusChanged += onStatusChanged; + bool r = (bool)this.mpris2_player.Status.Shuffle_State; int32 p = (int32)this.mpris2_player.Status.Playback_State; diff --git a/src/player-controller.vala b/src/player-controller.vala index 33a5b1a..bccf586 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -43,14 +43,11 @@ public class PlayerController : GLib.Object } public int current_state = state.OFFLINE; - - + private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - public Mpris2Controller mpris2_adaptor; - public MprisController mpris_adaptor; - public bool mpris2; + public MprisBridge mpris_bridge; public AppInfo? app_info { get; set;} public int menu_offset { get; set;} @@ -77,7 +74,6 @@ public class PlayerController : GLib.Object public void activate() { this.establish_mpris_connection(); - //this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); } /* @@ -104,14 +100,7 @@ public class PlayerController : GLib.Object debug("establish_mpris_connection - Not ready to connect"); return; } - if(this.name == "Vlc"){ - debug("establishing a vlc mpris controller"); - this.mpris2_adaptor = new Mpris2Controller(this); - this.mpris2 = true; - } - else{ - this.mpris_adaptor = new MprisController(this); - } + this.mpris_bridge = new MprisBridge(); this.determine_state(); } @@ -144,19 +133,12 @@ public class PlayerController : GLib.Object false); return; } - debug("update layout - metadata %s", this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format()).to_string()); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, - this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); - //debug("metadata id %i", this.custom_items[widget_order.METADATA].id); - - debug("update layout - scrub %s", this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format()).to_string()); + this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); this.custom_items[widget_order.SCRUB].property_set_bool(MENUITEM_PROP_VISIBLE, this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format())); - - this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, true); - this.custom_items[widget_order.PLAYLIST].property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -223,45 +205,13 @@ public class PlayerController : GLib.Object // Temporarily we will need to handle to different mpris implemenations // Do it for now - a couple of weeks should see this messy carry on out of // the codebase. - public void set_track_position(double pos) - { - if(this.mpris2 == true){ - this.mpris2_adaptor.set_position(pos); - } - else{ - this.mpris_adaptor.set_position(pos); - } - } - - public void transport_update(TransportMenuitem.action update) - { - if(this.mpris2 == true){ - this.mpris2_adaptor.transport_event(update); - } - else{ - this.mpris_adaptor.transport_event(update); - } - } - public void determine_state() { - if(this.mpris2 == true){ - if(this.mpris2_adaptor.connected() == true){ - debug("yup I'm connected"); - this.update_state(state.CONNECTED); - } - else{ - this.update_state(state.DISCONNECTED); - } + if(this.mpris_bridge.connected() == true){ + this.update_state(state.CONNECTED); } else{ - if(this.mpris_adaptor.connected() == true){ - debug("yup I'm connected"); - this.update_state(state.CONNECTED); - } - else{ - this.update_state(state.DISCONNECTED); - } - } + this.update_state(state.DISCONNECTED); + } } } \ No newline at end of file diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index e220612..7368a0c 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -32,7 +32,7 @@ public class ScrubMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event for owner %s with value: %f", this.owner.name, input_value.get_double()); - this.owner.set_track_position(input_value.get_double()); + this.owner.mpris_bridge.set_track_position(input_value.get_double()); } public void update_position(int32 new_position) diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 45c2692..8bdd2c8 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -45,7 +45,7 @@ public class TransportMenuitem : PlayerItem int input = input_value.get_int(); debug("handle_event with value %s", input.to_string()); debug("transport owner name = %s", this.owner.name); - this.owner.transport_update((action)input); + this.owner.mpris_bridge.transport_update((action)input); } public static HashSet attributes_format() -- cgit v1.2.3 From 30a697a1027229c23857ced856c0fdbd15b40d14 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 12 Aug 2010 20:36:14 +0100 Subject: moving mpris2 to gdbus, the horror --- src/Makefile.am | 4 +- src/mpris-bridge.vala | 13 +++--- src/mpris2-controller.vala | 105 ++++++++++++++++++++++----------------------- src/player-controller.vala | 3 +- 4 files changed, 61 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 5d073c7..b55b5f9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -83,7 +83,9 @@ music_bridge_VALAFLAGS = \ --pkg Dbusmenu-Glib-0.2 \ --pkg common-defs \ --pkg dbus-glib-1 \ - --pkg gio-unix-2.0 + --pkg gio-2.0 \ + --pkg gio-unix-2.0 + $(MAINTAINER_VALAFLAGS) music_bridge_APIFILES = \ diff --git a/src/mpris-bridge.vala b/src/mpris-bridge.vala index 682069c..bb02550 100644 --- a/src/mpris-bridge.vala +++ b/src/mpris-bridge.vala @@ -10,17 +10,16 @@ public class MprisBridge : GLib.Object public MprisBridge(PlayerController ctrl) { - this.mpris2_controller == new Mpris2Controller(ctrl); + this.mpris2_controller = new Mpris2Controller(ctrl); if(this.mpris2_controller.was_successfull() == true){ - mode_in_use == mode.MPRIS_2; - this.mpris1_controller == null; + this.mode_in_use = mode.MPRIS_2; + this.mpris1_controller = null; this.mpris2_controller.initial_update(); } else{ - delete this.mpris2_controller; - this.mpris2_controller == null; - mode_in_use == mode.MPRIS_1; - this.mpris1_controller = new Mpris1Controller(ctrl); + this.mpris2_controller = null; + this.mode_in_use = mode.MPRIS_1; + this.mpris1_controller = new MprisController(ctrl); } } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 6c1b71a..e8783e7 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -17,32 +17,39 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -using Gee; -[DBus (name = "org.mpris.MediaPlayer.Player")] +using GLib; +using Bus; + +[DBus (name = Mpris2Controller.root_interface)] +public interface MprisRoot : Object { + // properties + public abstract bool HasTracklist{owned get; set;} + public abstract bool CanQuit{owned get; set;} + public abstract bool CanRaise{owned get; set;} + public abstract string Identity{owned get; set;} + public abstract string DesktopEntry{owned get; set;} + // methods + public abstract void Quit() throws IOError; + public abstract void Raise() throws IOError; +} + +[DBus (name = Mpris2Controller.root_interface.concat(".Player"))] public interface MprisPlayer : Object { - public struct Status { - public int32 Playback_State; - public double Playback_Rate; - public bool Repeat_State; - public bool Shuffle_State; - public bool Endless_State; - } - - public abstract HashTable Metadata{owned get;} - public abstract double Volume{get;} - public abstract int32 Capabilities{get;} - public abstract int32 Position{get;} + public abstract HashTable Metadata{owned get; set;} + public abstract double Volume{owned get; set;} + public abstract int32 Capabilities{owned get; set;} + public abstract int32 Position{owned get; set;} - public abstract void SetPosition(string prop, int32 pos) throws DBus.Error; - public abstract void PlayPause() throws DBus.Error; - public abstract void Pause() throws DBus.Error; - public abstract void Next() throws DBus.Error; - public abstract void Previous() throws DBus.Error; - - public abstract signal void StatusChanged(Status update); - public abstract signal void TrackChanged(HashTable Metadata); + public abstract void SetPosition(string prop, int32 pos) throws IOError; + public abstract void PlayPause() throws IOError; + public abstract void Pause() throws IOError; + public abstract void Next() throws IOError; + public abstract void Previous() throws IOError; + + //public abstract signal void StatusChanged(Status update); + //public abstract signal void TrackChanged(HashTable Metadata); } /* @@ -51,43 +58,29 @@ public interface MprisPlayer : Object { */ public class Mpris2Controller : GLib.Object { - private DBus.Connection connection; - public dynamic DBus.Object mpris2_root {get; construct;} + public static const string root_interface = "org.mpris.MediaPlayer2" ; + public MprisRoot mpris2_root {get; construct;} public MprisPlayer mpris2_player {get; construct;} public PlayerController owner {get; construct;} public Mpris2Controller(PlayerController ctrl) { Object(owner: ctrl); - this.mpris2_root = null; - this.mpris2_player = null; } construct{ - try { - debug("Going to try and create an mpris 2 controller"); - this.connection = DBus.Bus.get (DBus.BusType.SESSION); - } catch (Error e) { - error("Problems connecting to the session bus - %s", e.message); - } - - try { - this.mpris2_root = this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()), - "/org/mpris/MediaPlayer", - "org.mpris.MediaPlayer"); - this.mpris2_player = (MprisPlayer)this.connection.get_object ("org.mpris.mediaplayers.".concat(this.owner.name.down()) , - "/org/mpris/MediaPlayer/Player", - "org.mpris.MediaPlayer.Player"); - } - catch(Error e){ - error("Problems connecting to - } - } + this.mpris2_root = Bus.get_proxy_sync (BusType.SESSION, + root_interface.concat(".").concat(this.owner.name.down()), + "/org/mpris/MediaPlayer2"); + + this.mpris2_player = Bus.get_proxy_sync (BusType.SESSION, + root_interface.concat(".").concat(this.owner.name.down()), + "/org/mpris/MediaPlayer2/Player"); + } + public bool was_successfull(){ - if(this.mpris2_root == null || - this.mpris2_player == null) - { + if(this.mpris2_root == null ||this.mpris2_player == null){ return false; } return true; @@ -95,7 +88,7 @@ public class Mpris2Controller : GLib.Object public void initial_update() { - this.mpris2_player.TrackChanged += onTrackChanged; + /*this.mpris2_player.TrackChanged += onTrackChanged; this.mpris2_player.StatusChanged += onStatusChanged; bool r = (bool)this.mpris2_player.Status.Shuffle_State; @@ -111,11 +104,12 @@ public class Mpris2Controller : GLib.Object ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); - + */ } public void transport_event(TransportMenuitem.action command) { + /* debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); @@ -126,11 +120,13 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.NEXT){ this.mpris2_player.Next(); - } + } + */ } public void set_position(double position) - { + { + /* debug("Set position with pos (0-100) %f", position); HashTable data = this.mpris2_player.Metadata; Value? time_value = data.lookup("time"); @@ -156,6 +152,7 @@ public class Mpris2Controller : GLib.Object //this.mpris2_player.SetPosition((int32)(new_time_position)); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); + */ } public bool connected() @@ -163,7 +160,7 @@ public class Mpris2Controller : GLib.Object return (this.mpris2_player != null); } - private void onStatusChanged(MprisPlayer.Status st) + /*private void onStatusChanged(MprisPlayer.Status st) { debug("onStatusChange - play state %i", st.Playback_State); HashTable ht = new HashTable(str_hash, str_equal); @@ -191,7 +188,7 @@ public class Mpris2Controller : GLib.Object ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); - } + }*/ } diff --git a/src/player-controller.vala b/src/player-controller.vala index bccf586..79b63d7 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -53,7 +53,6 @@ public class PlayerController : GLib.Object public PlayerController(Dbusmenu.Menuitem root, string client_name, int offset, state initial_state) { - this.mpris2 = false; this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); @@ -100,7 +99,7 @@ public class PlayerController : GLib.Object debug("establish_mpris_connection - Not ready to connect"); return; } - this.mpris_bridge = new MprisBridge(); + this.mpris_bridge = new MprisBridge(this); this.determine_state(); } -- cgit v1.2.3 From a936550cb2d904f09f712712a38c76779905d3b5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 13 Aug 2010 14:48:29 +0100 Subject: back on dbus-glib-1 and motoring through basic mpris2 --- src/Makefile.am | 1 - src/mpris2-controller.vala | 88 ++++++++++++++++++---------------------------- 2 files changed, 34 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index b55b5f9..74e0297 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -83,7 +83,6 @@ music_bridge_VALAFLAGS = \ --pkg Dbusmenu-Glib-0.2 \ --pkg common-defs \ --pkg dbus-glib-1 \ - --pkg gio-2.0 \ --pkg gio-unix-2.0 $(MAINTAINER_VALAFLAGS) diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index e8783e7..debbd76 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -18,10 +18,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -using GLib; -using Bus; - -[DBus (name = Mpris2Controller.root_interface)] +[DBus (name = "org.mpris.MediaPlayer2")] public interface MprisRoot : Object { // properties public abstract bool HasTracklist{owned get; set;} @@ -30,26 +27,25 @@ public interface MprisRoot : Object { public abstract string Identity{owned get; set;} public abstract string DesktopEntry{owned get; set;} // methods - public abstract void Quit() throws IOError; - public abstract void Raise() throws IOError; + public abstract void Quit() throws DBus.Error; + public abstract void Raise() throws DBus.Error; } -[DBus (name = Mpris2Controller.root_interface.concat(".Player"))] +[DBus (name = "org.mpris.MediaPlayer2.Player")] public interface MprisPlayer : Object { public abstract HashTable Metadata{owned get; set;} - public abstract double Volume{owned get; set;} public abstract int32 Capabilities{owned get; set;} public abstract int32 Position{owned get; set;} + public abstract string PlaybackStatus{owned get; set;} - public abstract void SetPosition(string prop, int32 pos) throws IOError; - public abstract void PlayPause() throws IOError; - public abstract void Pause() throws IOError; - public abstract void Next() throws IOError; - public abstract void Previous() throws IOError; - - //public abstract signal void StatusChanged(Status update); - //public abstract signal void TrackChanged(HashTable Metadata); + public abstract void SetPosition(string prop, int32 pos) throws DBus.Error; + public abstract void PlayPause() throws DBus.Error; + public abstract void Pause() throws DBus.Error; + public abstract void Next() throws DBus.Error; + public abstract void Previous() throws DBus.Error; + + public signal void Seeked(int new_position); } /* @@ -63,20 +59,35 @@ public class Mpris2Controller : GLib.Object public MprisPlayer mpris2_player {get; construct;} public PlayerController owner {get; construct;} + public Mpris2Controller(PlayerController ctrl) { Object(owner: ctrl); } construct{ - this.mpris2_root = Bus.get_proxy_sync (BusType.SESSION, - root_interface.concat(".").concat(this.owner.name.down()), - "/org/mpris/MediaPlayer2"); - - this.mpris2_player = Bus.get_proxy_sync (BusType.SESSION, - root_interface.concat(".").concat(this.owner.name.down()), - "/org/mpris/MediaPlayer2/Player"); + try { + var connection = DBus.Bus.get (DBus.BusType.SESSION); + this.mpris2_root = (MprisRoot) connection.get_object (root_interface.concat(".").concat(this.owner.name.down()), + "/org/mpris/MediaPlayer2", + root_interface); + this.mpris2_player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.name.down()), + "/org/mpris/MediaPlayer2/Player", + root_interface.concat(".Player")); + this.mpris2_player.Seeked += onSeeked; + this.mpris2_player.notify["PlaybackStatus"].connect (property_changed); + + } catch (DBus.Error e) { + error("Problems connecting to the session bus - %s", e.message); + } + } + public void onSeeked(int position){ + debug("Seeked signal callback"); + } + + public void property_changed(Object mpris_player, ParamSpec new_status){ + debug("playback status changed, %s", new_status.get_name()); } public bool was_successfull(){ @@ -109,7 +120,6 @@ public class Mpris2Controller : GLib.Object public void transport_event(TransportMenuitem.action command) { - /* debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); @@ -121,7 +131,6 @@ public class Mpris2Controller : GLib.Object else if(command == TransportMenuitem.action.NEXT){ this.mpris2_player.Next(); } - */ } public void set_position(double position) @@ -160,35 +169,6 @@ public class Mpris2Controller : GLib.Object return (this.mpris2_player != null); } - /*private void onStatusChanged(MprisPlayer.Status st) - { - debug("onStatusChange - play state %i", st.Playback_State); - HashTable ht = new HashTable(str_hash, str_equal); - Value v = Value(typeof(int)); - v.set_int(st.Playback_State); - ht.insert("state", v); - this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); - } - - private void onTrackChanged(HashTable ht) - { - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, - MetadataMenuitem.attributes_format()); - debug("about to update the duration on the scrub bar"); - Value? v = ht.lookup("time"); - if(v != null) - { - debug("with the duration of %i", (int)v.get_uint()); - debug("with Position of %i", this.mpris2_player.Position); - } - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, - ScrubMenuitem.attributes_format()); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris2_player.Position); - }*/ } -- cgit v1.2.3 From f648465adb85a872c97bdb9b9a7d638cb8803049 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 13 Aug 2010 18:57:00 +0100 Subject: player object implemented bar the property signal thing --- src/mpris2-controller.vala | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index debbd76..fb17bea 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -35,7 +35,6 @@ public interface MprisRoot : Object { public interface MprisPlayer : Object { public abstract HashTable Metadata{owned get; set;} - public abstract int32 Capabilities{owned get; set;} public abstract int32 Position{owned get; set;} public abstract string PlaybackStatus{owned get; set;} @@ -96,17 +95,19 @@ public class Mpris2Controller : GLib.Object } return true; } + + private int determine_play_state(){ + string status = this.mpris2_player.PlaybackStatus; + if(status == "Playing"){ + return 0; + } + return 1; + } public void initial_update() { - /*this.mpris2_player.TrackChanged += onTrackChanged; - this.mpris2_player.StatusChanged += onStatusChanged; - - bool r = (bool)this.mpris2_player.Status.Shuffle_State; - int32 p = (int32)this.mpris2_player.Status.Playback_State; - + int32 p = determine_play_state(); debug("initial update - play state %i", p); - debug("initial update - shuffle state %s", r.to_string()); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris2_player.Metadata, @@ -115,7 +116,7 @@ public class Mpris2Controller : GLib.Object ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); - */ + } public void transport_event(TransportMenuitem.action command) @@ -123,13 +124,31 @@ public class Mpris2Controller : GLib.Object debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); - this.mpris2_player.PlayPause(); + try{ + this.mpris2_player.PlayPause(); + } + catch(DBus.Error error){ + warning("DBus Error calling the player objects PlayPause method %s", + error.message); + } } else if(command == TransportMenuitem.action.PREVIOUS){ - this.mpris2_player.Previous(); + try{ + this.mpris2_player.Previous(); + } + catch(DBus.Error error){ + warning("DBus Error calling the player objects Previous method %s", + error.message); + } } else if(command == TransportMenuitem.action.NEXT){ - this.mpris2_player.Next(); + try{ + this.mpris2_player.Next(); + } + catch(DBus.Error error){ + warning("DBus Error calling the player objects Next method %s", + error.message); + } } } -- cgit v1.2.3 From 04af32d9b321d4256cb1f7cf1f94b23387b75774 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 13 Aug 2010 19:12:45 +0100 Subject: a few tidy ups --- src/metadata-widget.c | 2 -- src/mpris-controller.vala | 2 +- src/mpris2-controller.vala | 14 +++++--------- 3 files changed, 6 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 670d983..da18ccc 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -201,11 +201,9 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(g_value_get_int(value) == DBUSMENU_PROPERTY_EMPTY){ g_debug("Metadata widget: property update - reset"); - gchar* empty = ""; GValue new_value = {0}; g_value_init(&new_value, G_TYPE_STRING); g_value_set_string(&new_value, g_strdup("")); - //g_free(empty); value = &new_value; } diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index db71c70..1e1e00a 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -126,7 +126,7 @@ public class MprisController : GLib.Object this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - HashTable status_hash = new HashTable(str_hash, str_equal); + //HashTable status_hash = new HashTable(str_hash, str_equal); status st = this.mpris_player.GetStatus(); int play_state = st.playback; diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index fb17bea..cfe0d68 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -58,7 +58,6 @@ public class Mpris2Controller : GLib.Object public MprisPlayer mpris2_player {get; construct;} public PlayerController owner {get; construct;} - public Mpris2Controller(PlayerController ctrl) { Object(owner: ctrl); @@ -86,7 +85,7 @@ public class Mpris2Controller : GLib.Object } public void property_changed(Object mpris_player, ParamSpec new_status){ - debug("playback status changed, %s", new_status.get_name()); + debug("playback status changed, %s", new_status.get_name()); } public bool was_successfull(){ @@ -153,8 +152,7 @@ public class Mpris2Controller : GLib.Object } public void set_position(double position) - { - /* + { debug("Set position with pos (0-100) %f", position); HashTable data = this.mpris2_player.Metadata; Value? time_value = data.lookup("time"); @@ -175,9 +173,8 @@ public class Mpris2Controller : GLib.Object else if(v.holds (typeof (string))){ debug("the trackid = %s", v.get_string()); } - } - - //this.mpris2_player.SetPosition((int32)(new_time_position)); + } + /*this.mpris2_player.SetPosition((int32)(new_time_position)); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; scrub.update_position(this.mpris2_player.Position); */ @@ -187,8 +184,7 @@ public class Mpris2Controller : GLib.Object { return (this.mpris2_player != null); } - - + } -- cgit v1.2.3 From 7aa4517861e27a0857d36e83844d670446c22ee6 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 17 Aug 2010 17:26:47 +0100 Subject: mpris 2 has landed --- src/mpris-bridge.vala | 11 +++ src/mpris2-controller.vala | 171 ++++++++++++++++++++++++++++++++------------- src/sound-service.c | 4 +- src/title-menu-item.vala | 3 + 4 files changed, 139 insertions(+), 50 deletions(-) (limited to 'src') diff --git a/src/mpris-bridge.vala b/src/mpris-bridge.vala index bb02550..bd9d472 100644 --- a/src/mpris-bridge.vala +++ b/src/mpris-bridge.vala @@ -47,6 +47,17 @@ public class MprisBridge : GLib.Object } } + public void expose() + { + if(this.mode_in_use == mode.MPRIS_2){ + this.mpris2_controller.expose(); + } + else{ + warning("MPRIS1 clients don't have the ability to raise/expose the client"); + } + } + + public void set_track_position(double pos) { if(this.mode_in_use == mode.MPRIS_1){ diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index cfe0d68..c5ca0a5 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -17,9 +17,10 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +using DBus; [DBus (name = "org.mpris.MediaPlayer2")] -public interface MprisRoot : Object { +public interface MprisRoot : DBus.Object { // properties public abstract bool HasTracklist{owned get; set;} public abstract bool CanQuit{owned get; set;} @@ -32,19 +33,25 @@ public interface MprisRoot : Object { } [DBus (name = "org.mpris.MediaPlayer2.Player")] -public interface MprisPlayer : Object { +public interface MprisPlayer : DBus.Object { public abstract HashTable Metadata{owned get; set;} public abstract int32 Position{owned get; set;} public abstract string PlaybackStatus{owned get; set;} - public abstract void SetPosition(string prop, int32 pos) throws DBus.Error; + public abstract void SetPosition(DBus.ObjectPath path, int64 pos) throws DBus.Error; public abstract void PlayPause() throws DBus.Error; public abstract void Pause() throws DBus.Error; public abstract void Next() throws DBus.Error; public abstract void Previous() throws DBus.Error; - public signal void Seeked(int new_position); + public signal void Seeked(int64 new_position); + //public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); +} + +[DBus (name = "org.freedesktop.DBus.Properties")] +public interface FreeDesktopProperties : DBus.Object{ + public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); } /* @@ -55,12 +62,13 @@ public class Mpris2Controller : GLib.Object { public static const string root_interface = "org.mpris.MediaPlayer2" ; public MprisRoot mpris2_root {get; construct;} - public MprisPlayer mpris2_player {get; construct;} - public PlayerController owner {get; construct;} + public MprisPlayer player {get; construct;} + public PlayerController owner {get; construct;} + public FreeDesktopProperties properties_interface {get; construct;} public Mpris2Controller(PlayerController ctrl) { - Object(owner: ctrl); + GLib.Object(owner: ctrl); } construct{ @@ -69,35 +77,68 @@ public class Mpris2Controller : GLib.Object this.mpris2_root = (MprisRoot) connection.get_object (root_interface.concat(".").concat(this.owner.name.down()), "/org/mpris/MediaPlayer2", root_interface); - this.mpris2_player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.name.down()), - "/org/mpris/MediaPlayer2/Player", - root_interface.concat(".Player")); - this.mpris2_player.Seeked += onSeeked; - this.mpris2_player.notify["PlaybackStatus"].connect (property_changed); + this.player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.name.down()), + "/org/mpris/MediaPlayer2", + root_interface.concat(".Player")); + this.player.Seeked += onSeeked; + + this.properties_interface = (FreeDesktopProperties) connection.get_object(root_interface.concat(".").concat(this.owner.name.down()), + "/org/mpris/MediaPlayer2", + "org.freedesktop.DBus.Properties"); + this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { error("Problems connecting to the session bus - %s", e.message); } } - public void onSeeked(int position){ - debug("Seeked signal callback"); - } + public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) + { + debug("properties-changed for interface %s", interface_source); + if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false){ + warning("Property-changed hash is null"); + return; + } + Value? play_v = changed_properties.lookup("PlaybackStatus"); + if(play_v != null){ + string state = play_v.get_string(); + debug("new playback state = %s", state); + int p = this.determine_play_state(state); + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); + (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(p); + } + + Value? pos_v = changed_properties.lookup("Position"); + if(pos_v != null){ + int64 pos = pos_v.get_int64(); + debug("new position = %i", (int)pos); + (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_position((int32)pos); + } - public void property_changed(Object mpris_player, ParamSpec new_status){ - debug("playback status changed, %s", new_status.get_name()); - } - - public bool was_successfull(){ - if(this.mpris2_root == null ||this.mpris2_player == null){ - return false; + Value? meta_v = changed_properties.lookup("Metadata"); + if(meta_v != null){ + debug("metadata is not empty"); + debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); + this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); + if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 || + (int)this.player.Metadata.lookup("artist").get_string().len() > 0){ + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, + ScrubMenuitem.attributes_format()); + } + (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus)); + } - return true; } - - private int determine_play_state(){ - string status = this.mpris2_player.PlaybackStatus; - if(status == "Playing"){ + + private int determine_play_state(string status){ + if(status == null) + return 1; + + if(status != null && status == "Playing"){ + debug("determine play state - state = %s", status); return 0; } return 1; @@ -105,17 +146,22 @@ public class Mpris2Controller : GLib.Object public void initial_update() { - int32 p = determine_play_state(); - debug("initial update - play state %i", p); + int32 status; + if(this.player.PlaybackStatus == null){ + status = 1; + } + else{ + status = determine_play_state(this.player.PlaybackStatus); + } + debug("initial update - play state %i", status); - (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris2_player.Metadata, + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris2_player.Metadata, + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, ScrubMenuitem.attributes_format()); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris2_player.Position); - + scrub.update_position(this.player.Position); } public void transport_event(TransportMenuitem.action command) @@ -124,7 +170,7 @@ public class Mpris2Controller : GLib.Object if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); try{ - this.mpris2_player.PlayPause(); + this.player.PlayPause(); } catch(DBus.Error error){ warning("DBus Error calling the player objects PlayPause method %s", @@ -133,7 +179,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.PREVIOUS){ try{ - this.mpris2_player.Previous(); + this.player.Previous(); } catch(DBus.Error error){ warning("DBus Error calling the player objects Previous method %s", @@ -142,7 +188,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.NEXT){ try{ - this.mpris2_player.Next(); + this.player.Next(); } catch(DBus.Error error){ warning("DBus Error calling the player objects Next method %s", @@ -150,11 +196,14 @@ public class Mpris2Controller : GLib.Object } } } - + /** + TODO: SetPosition on the player object is not working with rhythmbox, + runtime error - "dbus function not supported" + */ public void set_position(double position) { debug("Set position with pos (0-100) %f", position); - HashTable data = this.mpris2_player.Metadata; + HashTable data = this.player.Metadata; Value? time_value = data.lookup("time"); if(time_value == null){ warning("Can't fetch the duration of the track therefore cant set the position"); @@ -165,26 +214,52 @@ public class Mpris2Controller : GLib.Object double new_time_position = total_time * position/100.0; debug("new position = %f", (new_time_position * 1000)); - Value? v = this.mpris2_player.Metadata.lookup("trackid"); + Value? v = this.player.Metadata.lookup("trackid"); if(v != null){ - if(v.holds (typeof (int))){ - debug("the trackid = %i", v.get_int()); - } - else if(v.holds (typeof (string))){ + if(v.holds (typeof (string))){ debug("the trackid = %s", v.get_string()); + DBus.ObjectPath path = new ObjectPath(v.get_string()); + try{ + this.player.SetPosition(path, (int64)(new_time_position * 1000)); + } + catch(DBus.Error error){ + warning("DBus Error calling the player objects SetPosition method %s", + error.message); + } } } - /*this.mpris2_player.SetPosition((int32)(new_time_position)); + } + + public void onSeeked(int64 position){ + debug("Seeked signal callback with pos = %i", (int)position/1000); ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris2_player.Position); - */ + scrub.update_position((int32)position/1000); } public bool connected() { - return (this.mpris2_player != null); + return (this.player != null && this.mpris2_root != null); } + + public bool was_successfull(){ + if(this.mpris2_root == null ||this.player == null){ + return false; + } + return true; + } + + public void expose() + { + if(this.connected() == true){ + try{ + this.mpris2_root.Raise(); + } + catch(DBus.Error e){ + error("Exception thrown while calling root function Raise - %s", e.message); + } + } + } } diff --git a/src/sound-service.c b/src/sound-service.c index 8768cd3..16fa87c 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index d7e16df..ec1cc62 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -35,6 +35,9 @@ public class TitleMenuitem : PlayerItem { this.owner.instantiate(); } + else if(this.owner.current_state == PlayerController.state.CONNECTED){ + this.owner.mpris_bridge.expose(); + } } -- cgit v1.2.3 From f18466945a43718111ec93a79f1936157b02ce3f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 17 Aug 2010 17:43:34 +0100 Subject: we have mpris 2 basic stuff working with rb perfectly --- src/mpris2-controller.vala | 13 ++++++------- src/player-controller.vala | 32 ++------------------------------ src/sound-service.c | 4 ++-- 3 files changed, 10 insertions(+), 39 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index c5ca0a5..8b937b7 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -34,23 +34,24 @@ public interface MprisRoot : DBus.Object { [DBus (name = "org.mpris.MediaPlayer2.Player")] public interface MprisPlayer : DBus.Object { - + + // properties public abstract HashTable Metadata{owned get; set;} public abstract int32 Position{owned get; set;} public abstract string PlaybackStatus{owned get; set;} - + // methods public abstract void SetPosition(DBus.ObjectPath path, int64 pos) throws DBus.Error; public abstract void PlayPause() throws DBus.Error; public abstract void Pause() throws DBus.Error; public abstract void Next() throws DBus.Error; public abstract void Previous() throws DBus.Error; - + // signals public signal void Seeked(int64 new_position); - //public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); } [DBus (name = "org.freedesktop.DBus.Properties")] public interface FreeDesktopProperties : DBus.Object{ + // signals public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); } @@ -96,7 +97,7 @@ public class Mpris2Controller : GLib.Object { debug("properties-changed for interface %s", interface_source); if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false){ - warning("Property-changed hash is null"); + warning("Property-changed hash is null or this is an interface that concerns us"); return; } Value? play_v = changed_properties.lookup("PlaybackStatus"); @@ -160,8 +161,6 @@ public class Mpris2Controller : GLib.Object MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, ScrubMenuitem.attributes_format()); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.player.Position); } public void transport_event(TransportMenuitem.action command) diff --git a/src/player-controller.vala b/src/player-controller.vala index 79b63d7..2aa4382 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -23,7 +23,7 @@ using Gee; public class PlayerController : GLib.Object { - public const int WIDGET_QUANTITY = 6; + public const int WIDGET_QUANTITY = 5; public static enum widget_order{ SEPARATOR, @@ -31,7 +31,6 @@ public class PlayerController : GLib.Object METADATA, SCRUB, TRANSPORT, - PLAYLIST } public enum state{ @@ -128,8 +127,6 @@ public class PlayerController : GLib.Object false); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, false); - this.custom_items[widget_order.PLAYLIST].property_set_bool(MENUITEM_PROP_VISIBLE, - false); return; } this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, @@ -138,8 +135,6 @@ public class PlayerController : GLib.Object this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format())); this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, true); - this.custom_items[widget_order.PLAYLIST].property_set_bool(MENUITEM_PROP_VISIBLE, - true); } private void construct_widgets() @@ -162,34 +157,11 @@ public class PlayerController : GLib.Object // Transport item TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); - - this.custom_items.add(create_playlist()); - + foreach(PlayerItem item in this.custom_items){ root_menu.child_add_position(item, this.menu_offset + this.custom_items.index_of(item)); } } - - private PlayerItem create_playlist() - { - PlayerItem playlist_root = new PlayerItem(CLIENT_TYPES_DEFAULT); - playlist_root.property_set(MENUITEM_PROP_LABEL, "Choose Playlist"); - - PlayerItem subentry_1 = new PlayerItem(CLIENT_TYPES_DEFAULT); - subentry_1.property_set(MENUITEM_PROP_LABEL, "Raster-noton selection"); - - PlayerItem subentry_2 = new PlayerItem(CLIENT_TYPES_DEFAULT); - subentry_2.property_set(MENUITEM_PROP_LABEL, "Rune Grammofon selection"); - - PlayerItem subentry_3 = new PlayerItem(CLIENT_TYPES_DEFAULT); - subentry_3.property_set(MENUITEM_PROP_LABEL, "Kranky selection"); - - playlist_root.child_append(subentry_1); - playlist_root.child_append(subentry_2); - playlist_root.child_append(subentry_3); - - return playlist_root; - } private static string format_client_name(string client_name) { diff --git a/src/sound-service.c b/src/sound-service.c index 16fa87c..8768cd3 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 8c5284005a19897d5e07fdb9bfe62b0a5d126058 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 18 Aug 2010 10:55:43 +0100 Subject: tests fixed, and metadata height reset readjustment fixed --- src/indicator-sound.c | 5 ----- src/indicator-sound.h | 4 ++++ src/metadata-widget.c | 4 ++-- src/sound-service.c | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 557ce85..ba36290 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -32,11 +32,6 @@ with this program. If not, see . #include #include -#include -#include -#include -#include - #include "indicator-sound.h" #include "transport-widget.h" #include "metadata-widget.h" diff --git a/src/indicator-sound.h b/src/indicator-sound.h index 251295c..9f829bb 100644 --- a/src/indicator-sound.h +++ b/src/indicator-sound.h @@ -23,6 +23,10 @@ PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#include +#include +#include +#include #define INDICATOR_SOUND_TYPE (indicator_sound_get_type ()) #define INDICATOR_SOUND(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), INDICATOR_SOUND_TYPE, IndicatorSound)) diff --git a/src/metadata-widget.c b/src/metadata-widget.c index da18ccc..aaf71e2 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -150,8 +150,8 @@ metadata_widget_init (MetadataWidget *self) g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(metadata_widget_property_update), self); gtk_widget_show_all (priv->hbox); - gtk_container_add (GTK_CONTAINER (self), hbox); - + gtk_widget_set_size_request(GTK_WIDGET(self), 200, 60); + gtk_container_add (GTK_CONTAINER (self), hbox); } static gboolean diff --git a/src/sound-service.c b/src/sound-service.c index 8768cd3..16fa87c 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -42,8 +42,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 75ba919b383a4da5d2634e4f9b85a3cdcbaa907d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 18 Aug 2010 11:16:13 +0100 Subject: tests fixed, and metadata height reset readjustment fixed --- src/indicator-sound.c | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index ba36290..3a7abe9 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -231,15 +231,6 @@ free_the_animation_list() } } -/*static void -slider_parent_changed (GtkWidget *widget, - gpointer user_data) -{ - gtk_widget_set_size_request (widget, 200, -1); - g_debug("slider parent changed"); -}*/ - - static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { -- cgit v1.2.3 From 4897f3ce524e6d91ecd0c70142556be0f29367b7 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 18 Aug 2010 11:57:27 +0100 Subject: ready for the merge --- src/mpris2-controller.vala | 13 +++++++------ src/sound-service.c | 5 ++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 8b937b7..65d881a 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -208,10 +208,11 @@ public class Mpris2Controller : GLib.Object warning("Can't fetch the duration of the track therefore cant set the position"); return; } - uint32 total_time = time_value.get_uint(); + // work in microseconds (scale up by 10 TTP-of 3) + uint32 total_time = time_value.get_uint() * 1000; debug("total time of track = %i", (int)total_time); double new_time_position = total_time * position/100.0; - debug("new position = %f", (new_time_position * 1000)); + debug("new position = %f", (new_time_position)); Value? v = this.player.Metadata.lookup("trackid"); if(v != null){ @@ -219,11 +220,11 @@ public class Mpris2Controller : GLib.Object debug("the trackid = %s", v.get_string()); DBus.ObjectPath path = new ObjectPath(v.get_string()); try{ - this.player.SetPosition(path, (int64)(new_time_position * 1000)); + //this.player.SetPosition(path, (int64)(new_time_position)); } - catch(DBus.Error error){ - warning("DBus Error calling the player objects SetPosition method %s", - error.message); + catch(DBus.Error e){ + error("DBus Error calling the player objects SetPosition method %s", + e.message); } } } diff --git a/src/sound-service.c b/src/sound-service.c index 16fa87c..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -25,7 +25,6 @@ with this program. If not, see . static GMainLoop *mainloop = NULL; - /**********************************************************************************************************************/ // Init and exit functions /**********************************************************************************************************************/ @@ -42,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From e6fc3937fd425dfed550884bf9852e16f1cb7401 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 19 Aug 2010 18:20:27 +0100 Subject: set position works without a jumping slider, correct button press behaviour of the title and metadata menuitems clipboard functionality in place --- src/indicator-sound.c | 8 --- src/metadata-widget.c | 137 ++++++++++++++++++++++++++++++--------------- src/mpris2-controller.vala | 16 +++--- src/sound-service.c | 4 +- src/title-widget.c | 25 +-------- 5 files changed, 103 insertions(+), 87 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3a7abe9..63ad72d 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -375,8 +375,6 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u g_return_if_fail(IS_INDICATOR_SOUND(userdata)); - // Ensure we are in a coherent state with the service at start up. - // Preserve ordering! } } return; @@ -464,12 +462,7 @@ tidy_up_hash() static void update_state(const gint state) { - /* g_debug("update state beginning - previous_state = %i", previous_state);*/ - previous_state = current_state; - - /* g_debug("update state 3rd line - previous_state = %i", previous_state);*/ - current_state = state; gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); indicator_image_helper_update(speaker_image, image_name); @@ -479,7 +472,6 @@ update_state(const gint state) void determine_state_from_volume(gdouble volume_percent) { - /* g_debug("determine_state_from_volume - previous_state = %i", previous_state);*/ if (device_available == FALSE) return; gint state = previous_state; diff --git a/src/metadata-widget.c b/src/metadata-widget.c index aaf71e2..34c4b37 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -38,6 +38,8 @@ struct _MetadataWidgetPrivate GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; + GdkColor bevel_colour; + GdkColor eight_note_colour; }; #define METADATA_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), METADATA_WIDGET_TYPE, MetadataWidgetPrivate)) @@ -47,25 +49,24 @@ static void metadata_widget_class_init (MetadataWidgetClass *klass); static void metadata_widget_init (MetadataWidget *self); static void metadata_widget_dispose (GObject *object); static void metadata_widget_finalize (GObject *object); -static gboolean metadata_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); // keyevent consumers static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); -static gboolean metadata_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); // Dbusmenuitem properties update callback static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); -static void update_album_art(MetadataWidget* self); -static void style_artist_text(MetadataWidget* self); -static void style_title_text(MetadataWidget* self); -static void style_album_text(MetadataWidget* self); +static void metadata_widget_update_album_art(MetadataWidget* self); +static void metadata_widget_style_artist_text(MetadataWidget* self); +static void metadata_widget_style_title_text(MetadataWidget* self); +static void metadata_widget_style_album_text(MetadataWidget* self); +static void metadata_widget_draw_album_art_placeholder(MetadataWidget* self); +void metadata_widget_set_style(GtkWidget* button, GtkStyle* style); -G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); +G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); static void @@ -75,8 +76,6 @@ metadata_widget_class_init (MetadataWidgetClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); widget_class->button_press_event = metadata_widget_button_press_event; - widget_class->button_release_event = metadata_widget_button_release_event; - widget_class->expose_event = metadata_widget_expose_event; g_type_class_add_private (klass, sizeof (MetadataWidgetPrivate)); gobject_class->dispose = metadata_widget_dispose; @@ -99,7 +98,12 @@ metadata_widget_init (MetadataWidget *self) // image priv->album_art = gtk_image_new(); priv->image_path = g_strdup(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); - update_album_art(self); + if(priv->image_path != NULL){ + metadata_widget_update_album_art(self); + } + else{ + metadata_widget_draw_album_art_placeholder(self); + } gtk_box_pack_start (GTK_BOX (priv->hbox), priv->album_art, FALSE, FALSE, 0); @@ -115,10 +119,9 @@ metadata_widget_init (MetadataWidget *self) gtk_label_set_width_chars(GTK_LABEL(artist), 15); gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); priv->artist_label = artist; - // Style it up. - style_artist_text(self); + metadata_widget_style_artist_text(self); - // piece + // title GtkWidget* piece; piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TITLE)); @@ -126,8 +129,7 @@ metadata_widget_init (MetadataWidget *self) gtk_label_set_width_chars(GTK_LABEL(piece), 12); gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); priv->piece_label = piece; - // Style it up. - style_title_text(self); + metadata_widget_style_title_text(self); // container GtkWidget* container; @@ -137,10 +139,8 @@ metadata_widget_init (MetadataWidget *self) gtk_label_set_width_chars(GTK_LABEL(container), 15); gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); priv->container_label = container; - // Style it up. - style_album_text(self); + metadata_widget_style_album_text(self); - // Pack in the right order gtk_box_pack_start (GTK_BOX (vbox), priv->piece_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), priv->artist_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), priv->container_label, FALSE, FALSE, 0); @@ -150,19 +150,13 @@ metadata_widget_init (MetadataWidget *self) g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(metadata_widget_property_update), self); gtk_widget_show_all (priv->hbox); + + g_signal_connect(self, "style-set", G_CALLBACK(metadata_widget_set_style), GTK_WIDGET(self)); + gtk_widget_set_size_request(GTK_WIDGET(self), 200, 60); gtk_container_add (GTK_CONTAINER (self), hbox); } -static gboolean -metadata_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) -{ - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); - - gtk_container_propagate_expose(GTK_CONTAINER(widget), priv->hbox, event); - return TRUE; -} - static void metadata_widget_dispose (GObject *object) { @@ -180,16 +174,19 @@ static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { - g_debug("MetadataWidget::menu_press_event"); - return TRUE; -} - -static gboolean -metadata_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event) -{ - g_debug("MetadataWidget::menu_release_event"); - return TRUE; + GtkClipboard* board = gtk_clipboard_get (GDK_NONE); + gchar* title = dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_METADATA_MENUITEM_TITLE); + gchar* artist = dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_METADATA_MENUITEM_ARTIST); + gchar* album = dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_METADATA_MENUITEM_ALBUM); + gchar* contents = g_strdup_printf("artist: %s \ntitle: %s \nalbum: %s", artist, title, album); + g_debug("contents to be copied will be : %s", contents); + gtk_clipboard_set_text (board, contents, -1); + gtk_clipboard_store (board); + g_free(contents); + return FALSE; } // TODO: Manage empty/mangled music details etc. @@ -212,15 +209,15 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTIST, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->artist_label), g_value_get_string(value)); - style_artist_text(mitem); + metadata_widget_style_artist_text(mitem); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TITLE, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value)); - style_title_text(mitem); + metadata_widget_style_title_text(mitem); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ALBUM, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value)); - style_album_text(mitem); + metadata_widget_style_album_text(mitem); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ if(priv->image_path != NULL){ @@ -228,13 +225,44 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } priv->image_path = g_value_dup_string(value); if(priv->image_path != NULL){ - update_album_art(mitem); + metadata_widget_update_album_art(mitem); + } + else{ + metadata_widget_draw_album_art_placeholder(mitem); } } } +static void metadata_widget_draw_album_art_placeholder(MetadataWidget* self) +{ + /*MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); + cairo_t *cr; + cr = gdk_cairo_create (GTK_WIDGET(self)->window); + PangoLayout *layout; + PangoFontDescription *desc; + layout = pango_cairo_create_layout(cr); + + GString* string = g_string_new(""); + gssize size = -1; + gunichar code = g_utf8_get_char_validated("0x266B", size); + g_string_append_unichar (string, code); + + pango_layout_set_text(layout, string->str, -1); + desc = pango_font_description_from_string("Sans Bold 12"); + pango_layout_set_font_description(layout, desc); + pango_font_description_free(desc); + + cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); + pango_cairo_update_layout(cr, layout); + pango_cairo_show_layout(cr, layout); + + g_object_unref(layout); + cairo_destroy (cr); + */ +} + static void -update_album_art(MetadataWidget* self){ +metadata_widget_update_album_art(MetadataWidget* self){ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path, NULL); @@ -247,7 +275,7 @@ update_album_art(MetadataWidget* self){ // TODO refactor next 3 methods into one once the style has been // "signed off" by design static void -style_artist_text(MetadataWidget* self) +metadata_widget_style_artist_text(MetadataWidget* self) { MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); char* markup; @@ -258,7 +286,7 @@ style_artist_text(MetadataWidget* self) } static void -style_title_text(MetadataWidget* self) +metadata_widget_style_title_text(MetadataWidget* self) { MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); @@ -270,7 +298,7 @@ style_title_text(MetadataWidget* self) } static void -style_album_text(MetadataWidget* self) +metadata_widget_style_album_text(MetadataWidget* self) { MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); char* markup; @@ -280,6 +308,23 @@ style_album_text(MetadataWidget* self) g_free(markup); } +void +metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style) +{ + g_return_if_fail(IS_METADATA_WIDGET(metadata)); + MetadataWidget* widg = METADATA_WIDGET(metadata); + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widg); + if(style == NULL){ + g_warning("metadata_widget_set_style -> style is NULL!"); + return; + } + else{ + g_debug("metadata_widget: about to set the style colours"); + priv->eight_note_colour = style->fg[GTK_STATE_NORMAL]; + priv->bevel_colour = style->bg[GTK_STATE_NORMAL]; + } +} + /** * transport_new: * @returns: a new #MetadataWidget. diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 65d881a..815426f 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -119,13 +119,14 @@ public class Mpris2Controller : GLib.Object Value? meta_v = changed_properties.lookup("Metadata"); if(meta_v != null){ debug("metadata is not empty"); - debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); + debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); + this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 || - (int)this.player.Metadata.lookup("artist").get_string().len() > 0){ + (int)this.player.Metadata.lookup("title").get_string().len() > 0){ this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, ScrubMenuitem.attributes_format()); } @@ -208,19 +209,20 @@ public class Mpris2Controller : GLib.Object warning("Can't fetch the duration of the track therefore cant set the position"); return; } - // work in microseconds (scale up by 10 TTP-of 3) - uint32 total_time = time_value.get_uint() * 1000; + // work in microseconds (scale up by 10 TTP-of 6) + uint32 total_time = time_value.get_uint() * 1000000; debug("total time of track = %i", (int)total_time); - double new_time_position = total_time * position/100.0; + double new_time_position = total_time * (position/100.0); debug("new position = %f", (new_time_position)); Value? v = this.player.Metadata.lookup("trackid"); if(v != null){ if(v.holds (typeof (string))){ - debug("the trackid = %s", v.get_string()); DBus.ObjectPath path = new ObjectPath(v.get_string()); try{ - //this.player.SetPosition(path, (int64)(new_time_position)); + this.player.SetPosition(path, (int64)(new_time_position)); + ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + scrub.update_position(((int32)new_time_position) / 1000); } catch(DBus.Error e){ error("DBus Error calling the player objects SetPosition method %s", diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..42ce116 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/title-widget.c b/src/title-widget.c index 8037eb7..7e73f7e 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -49,10 +49,6 @@ static void title_widget_finalize (GObject *object); // keyevent consumers static gboolean title_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); -static gboolean title_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); -static gboolean title_widget_expose_event(GtkWidget* widget, - GdkEventExpose* event); // Dbusmenuitem properties update callback static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, @@ -72,8 +68,6 @@ title_widget_class_init (TitleWidgetClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); widget_class->button_press_event = title_widget_button_press_event; - widget_class->button_release_event = title_widget_button_release_event; - widget_class->expose_event = title_widget_expose_event; g_type_class_add_private (klass, sizeof (TitleWidgetPrivate)); @@ -124,24 +118,7 @@ title_widget_button_press_event (GtkWidget *menuitem, g_value_set_boolean(&value, TRUE); dbusmenu_menuitem_handle_event (priv->twin_item, "Title menu event", &value, 0); - return TRUE; -} - -static gboolean -title_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event) -{ - g_debug("TitleWidget::menu_release_event"); - return TRUE; -} - -static gboolean -title_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) -{ - TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(widget); - - gtk_container_propagate_expose(GTK_CONTAINER(widget), priv->hbox, event); - return TRUE; + return FALSE; } static void -- cgit v1.2.3 From b70e73a6c45992ff93b4ab78683c9e9275329ea9 Mon Sep 17 00:00:00 2001 From: Andrea Cimitan Date: Fri, 20 Aug 2010 18:41:25 +0200 Subject: Some code from the gnome-screensaver lock dialog. Will crash because gtk_widget_get_window (GTK_WIDGET(image)) returns NULL --- src/metadata-widget.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 143 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index aaf71e2..b51dbac 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -233,14 +233,155 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } } + +static cairo_surface_t * +surface_from_pixbuf (GdkPixbuf *pixbuf) +{ + cairo_surface_t *surface; + cairo_t *cr; + + surface = cairo_image_surface_create (gdk_pixbuf_get_has_alpha (pixbuf) ? + CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24, + gdk_pixbuf_get_width (pixbuf), + gdk_pixbuf_get_height (pixbuf)); + cr = cairo_create (surface); + gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0); + cairo_paint (cr); + cairo_destroy (cr); + + return surface; +} + +static void +rounded_rectangle (cairo_t *cr, + gdouble aspect, + gdouble x, + gdouble y, + gdouble corner_radius, + gdouble width, + gdouble height) +{ + gdouble radius; + gdouble degrees; + + radius = corner_radius / aspect; + degrees = G_PI / 180.0; + + cairo_new_sub_path (cr); + cairo_arc (cr, + x + width - radius, + y + radius, + radius, + -90 * degrees, + 0 * degrees); + cairo_arc (cr, + x + width - radius, + y + height - radius, + radius, + 0 * degrees, + 90 * degrees); + cairo_arc (cr, + x + radius, + y + height - radius, + radius, + 90 * degrees, + 180 * degrees); + cairo_arc (cr, + x + radius, + y + radius, + radius, + 180 * degrees, + 270 * degrees); + cairo_close_path (cr); +} + +static void +image_set_from_pixbuf (GtkImage *image, + GdkPixbuf *source) +{ + cairo_t *cr; + cairo_t *cr_mask; + cairo_surface_t *surface; + GdkPixmap *pixmap; + GdkPixmap *bitmask; + int w; + int h; + int frame_width; + double radius; + GdkColor color; + double r; + double g; + double b; + + frame_width = 5; + + w = gdk_pixbuf_get_width (source) + frame_width * 2; + h = gdk_pixbuf_get_height (source) + frame_width * 2; + + radius = w / 10; + + pixmap = gdk_pixmap_new (gtk_widget_get_window (GTK_WIDGET (image)), w, h, -1); + bitmask = gdk_pixmap_new (gtk_widget_get_window (GTK_WIDGET (image)), w, h, 1); + + if (gtk_widget_get_window (GTK_WIDGET (image)) == NULL) + return; + + cr = gdk_cairo_create (pixmap); + cr_mask = gdk_cairo_create (bitmask); + + /* setup mask */ + cairo_rectangle (cr_mask, 0, 0, w, h); + cairo_set_operator (cr_mask, CAIRO_OPERATOR_CLEAR); + cairo_fill (cr_mask); + + rounded_rectangle (cr_mask, 1.0, 0.5, 0.5, radius, w - 1, h - 1); + cairo_set_operator (cr_mask, CAIRO_OPERATOR_OVER); + cairo_set_source_rgb (cr_mask, 1, 1, 1); + cairo_fill (cr_mask); + + color = gtk_widget_get_style (GTK_WIDGET (image))->bg [GTK_STATE_NORMAL]; + r = (float)color.red / 65535.0; + g = (float)color.green / 65535.0; + b = (float)color.blue / 65535.0; + + /* set up image */ + cairo_rectangle (cr, 0, 0, w, h); + cairo_set_source_rgb (cr, r, g, b); + cairo_fill (cr); + + rounded_rectangle (cr, + 1.0, + frame_width + 0.5, + frame_width + 0.5, + radius, + w - frame_width * 2 - 1, + h - frame_width * 2 - 1); + cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.3); + cairo_fill_preserve (cr); + + surface = surface_from_pixbuf (source); + cairo_set_source_surface (cr, surface, frame_width, frame_width); + cairo_fill (cr); + + gtk_image_set_from_pixmap (image, pixmap, bitmask); + + cairo_surface_destroy (surface); + + g_object_unref (bitmask); + g_object_unref (pixmap); + + cairo_destroy (cr_mask); + cairo_destroy (cr); +} + static void update_album_art(MetadataWidget* self){ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path, NULL); - pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); + pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); g_debug("attempting to set the image with path %s", priv->image_path); - gtk_image_set_from_pixbuf(GTK_IMAGE(priv->album_art), pixbuf); + image_set_from_pixbuf (GTK_IMAGE(priv->album_art), pixbuf); g_object_unref(pixbuf); } -- cgit v1.2.3 From 347d89eed160da6338401e71223655594af23c0b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 20 Aug 2010 19:10:10 +0100 Subject: metadata ui tweaks galore --- src/metadata-widget.c | 111 +++++++++++++++++++++++++-------------------- src/mpris2-controller.vala | 10 +++- 2 files changed, 72 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 34c4b37..9a5b855 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -34,7 +34,7 @@ struct _MetadataWidgetPrivate { GtkWidget* hbox; GtkWidget* album_art; - gchar* image_path; + GString* image_path; GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; @@ -49,18 +49,22 @@ static void metadata_widget_class_init (MetadataWidgetClass *klass); static void metadata_widget_init (MetadataWidget *self); static void metadata_widget_dispose (GObject *object); static void metadata_widget_finalize (GObject *object); +static gboolean metadata_image_expose (GtkWidget *image, GdkEventExpose *event, gpointer user_data); // keyevent consumers static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event); // Dbusmenuitem properties update callback -static void metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata); +static void metadata_widget_property_update (DbusmenuMenuitem* item, + gchar* property, + GValue* value, + gpointer userdata); static void metadata_widget_update_album_art(MetadataWidget* self); -static void metadata_widget_style_artist_text(MetadataWidget* self); static void metadata_widget_style_title_text(MetadataWidget* self); -static void metadata_widget_style_album_text(MetadataWidget* self); +static void metadata_widget_style_artist_and_album_label(MetadataWidget* self, + GtkLabel* label); + static void metadata_widget_draw_album_art_placeholder(MetadataWidget* self); void metadata_widget_set_style(GtkWidget* button, GtkStyle* style); @@ -76,6 +80,7 @@ metadata_widget_class_init (MetadataWidgetClass *klass) GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); widget_class->button_press_event = metadata_widget_button_press_event; + g_type_class_add_private (klass, sizeof (MetadataWidgetPrivate)); gobject_class->dispose = metadata_widget_dispose; @@ -97,36 +102,35 @@ metadata_widget_init (MetadataWidget *self) // image priv->album_art = gtk_image_new(); - priv->image_path = g_strdup(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); - if(priv->image_path != NULL){ - metadata_widget_update_album_art(self); - } - else{ - metadata_widget_draw_album_art_placeholder(self); - } + priv->image_path = g_string_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); + g_debug("Metadata::At startup and image path = %s", priv->image_path->str); + + metadata_widget_update_album_art(self); + g_signal_connect(priv->album_art, "expose-event", G_CALLBACK(metadata_image_expose), GTK_WIDGET(self)); + gtk_widget_set_size_request(GTK_WIDGET(priv->album_art), 60, 60); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->album_art, FALSE, FALSE, 0); - GtkWidget* vbox = gtk_vbox_new(FALSE, 0); gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); + // artist GtkWidget* artist; artist = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTIST)); - gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(artist), 15); gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); + metadata_widget_style_artist_and_album_label(self, artist); priv->artist_label = artist; - metadata_widget_style_artist_text(self); // title GtkWidget* piece; piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TITLE)); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(piece), 12); + gtk_label_set_width_chars(GTK_LABEL(piece), 15); gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); priv->piece_label = piece; metadata_widget_style_title_text(self); @@ -138,8 +142,8 @@ metadata_widget_init (MetadataWidget *self) gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(container), 15); gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); + metadata_widget_style_artist_and_album_label(self, container); priv->container_label = container; - metadata_widget_style_album_text(self); gtk_box_pack_start (GTK_BOX (vbox), priv->piece_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), priv->artist_label, FALSE, FALSE, 0); @@ -169,6 +173,35 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } +static gboolean +metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user_data) +{ + g_return_if_fail(IS_METADATA_WIDGET(user_data)); + MetadataWidget* widget = METADATA_WIDGET(user_data); + MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); + + if(priv->image_path->len == 0){ + g_debug("yeah image path is null this should be blank"); + cairo_t *cr; + cr = gdk_cairo_create (metadata->window); + g_debug("metatdata EXPOSE-> dimensions x = %f, y = %f, width = %f, height = %f", + event->area.x, + event->area.y, + event->area.width, + event->area.height); + cairo_rectangle (cr, + 0, 0, + 60, 60); + + cairo_clip(cr); + //draw (button, cr); + cairo_destroy (cr); + + return TRUE; + } + return FALSE; +} + /* Suppress/consume keyevents */ static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, @@ -209,7 +242,7 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTIST, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->artist_label), g_value_get_string(value)); - metadata_widget_style_artist_text(mitem); + metadata_widget_style_artist_and_album_label(mitem, GTK_LABEL(priv->artist_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TITLE, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value)); @@ -217,19 +250,12 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ALBUM, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value)); - metadata_widget_style_album_text(mitem); + metadata_widget_style_artist_and_album_label(mitem, GTK_LABEL(priv->container_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ - if(priv->image_path != NULL){ - g_free(priv->image_path); - } - priv->image_path = g_value_dup_string(value); - if(priv->image_path != NULL){ - metadata_widget_update_album_art(mitem); - } - else{ - metadata_widget_draw_album_art_placeholder(mitem); - } + g_string_erase(priv->image_path, 0, -1); + g_string_overwrite(priv->image_path, 0, g_value_dup_string(value)); + metadata_widget_update_album_art(mitem); } } @@ -265,9 +291,10 @@ static void metadata_widget_update_album_art(MetadataWidget* self){ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); GdkPixbuf* pixbuf; - pixbuf = gdk_pixbuf_new_from_file(priv->image_path, NULL); + pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); + g_debug("metadata_widget_update_album_art -> pixbuf from %s", + priv->image_path->str); pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); - g_debug("attempting to set the image with path %s", priv->image_path); gtk_image_set_from_pixbuf(GTK_IMAGE(priv->album_art), pixbuf); g_object_unref(pixbuf); } @@ -275,14 +302,13 @@ metadata_widget_update_album_art(MetadataWidget* self){ // TODO refactor next 3 methods into one once the style has been // "signed off" by design static void -metadata_widget_style_artist_text(MetadataWidget* self) +metadata_widget_style_artist_and_album_label(MetadataWidget* self, GtkLabel* label) { - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); char* markup; markup = g_markup_printf_escaped ("%s", - gtk_label_get_text(GTK_LABEL(priv->artist_label))); - gtk_label_set_markup (GTK_LABEL (priv->artist_label), markup); - g_free(markup); + gtk_label_get_text(GTK_LABEL(label))); + gtk_label_set_markup (GTK_LABEL (label), markup); + g_free(markup); } static void @@ -291,23 +317,12 @@ metadata_widget_style_title_text(MetadataWidget* self) MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); char* markup; - markup = g_markup_printf_escaped ("%s", + markup = g_markup_printf_escaped ("%s", gtk_label_get_text(GTK_LABEL(priv->piece_label))); gtk_label_set_markup (GTK_LABEL (priv->piece_label), markup); g_free(markup); } -static void -metadata_widget_style_album_text(MetadataWidget* self) -{ - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); - char* markup; - markup = g_markup_printf_escaped ("%s", - gtk_label_get_text(GTK_LABEL(priv->container_label))); - gtk_label_set_markup (GTK_LABEL (priv->container_label), markup); - g_free(markup); -} - void metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style) { diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 815426f..6fa140e 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -120,8 +120,16 @@ public class Mpris2Controller : GLib.Object if(meta_v != null){ debug("metadata is not empty"); debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); + debug("arturl: %s", this.player.Metadata.lookup("arturl").get_string()); + /*try{ + debug("arturl : %s", this.player.Metadata.lookup("arturl").get_string()); + } + catch(GLib.Error e){ + warning("NO ART URL"); + }*/ - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + debug("After the reset the arturl = %i", this.owner.custom_items[PlayerController.widget_order.METADATA].property_get_int("x-canonical-sound-menu-player-metadata-arturl")); this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); -- cgit v1.2.3 From 5f163af57701a168e2704faf951b894e2a7e6365 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 23 Aug 2010 15:44:19 +0100 Subject: new blank cairo drawn image --- src/metadata-widget.c | 104 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 84 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 9a5b855..146f84a 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -173,6 +173,28 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } +/* +static void +_setup (cairo_t** cr, + cairo_surface_t** surf, + gint width, + gint height) +{ + if (!cr || !surf) + return; + + *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); + *cr = cairo_create (*surf); + cairo_scale (*cr, 1.0f, 1.0f); + cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (*cr); + cairo_set_operator (*cr, CAIRO_OPERATOR_OVER); +}*/ + +/** + * We override the expose method to enable primitive drawing of the + * empty album art image (and soon rounded rectangles on the album art) + */ static gboolean metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user_data) { @@ -180,26 +202,68 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user MetadataWidget* widget = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); - if(priv->image_path->len == 0){ - g_debug("yeah image path is null this should be blank"); - cairo_t *cr; - cr = gdk_cairo_create (metadata->window); - g_debug("metatdata EXPOSE-> dimensions x = %f, y = %f, width = %f, height = %f", - event->area.x, - event->area.y, - event->area.width, - event->area.height); - cairo_rectangle (cr, - 0, 0, - 60, 60); - - cairo_clip(cr); - //draw (button, cr); - cairo_destroy (cr); - - return TRUE; - } - return FALSE; + if(priv->image_path->len > 0){ + return FALSE; + } + + cairo_t *cr; + cairo_surface_t* surf = NULL; + + cr = gdk_cairo_create (metadata->window); + GtkAllocation alloc; + gtk_widget_get_allocation (metadata, &alloc); + //_setup(&cr, &surf, alloc.width, alloc.height); + + g_debug("metatdata EXPOSE-> dimensions x = %i, y = %i, width = %i, height = %i", + alloc.x, + alloc.y, + alloc.width, + alloc.height); + + cairo_rectangle (cr, + alloc.x, alloc.y, + alloc.width, alloc.height); + cairo_clip(cr); + + cairo_move_to (cr, alloc.x , alloc.y); + cairo_line_to(cr, alloc.x + alloc.width, + alloc.y); + cairo_line_to(cr, alloc.x + alloc.width, + alloc.y + alloc.height); + cairo_line_to(cr, alloc.x, alloc.y + alloc.height); + cairo_line_to(cr, alloc.x, alloc.y); + + cairo_close_path (cr); + + cairo_set_source_rgba (cr, 123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, .8f); + cairo_set_line_width (cr, 2.0); + + cairo_stroke (cr); + + // Draw the eight note + PangoLayout *layout; + PangoFontDescription *desc; + layout = pango_cairo_create_layout(cr); + + GString* string = g_string_new(""); + gssize size = -1; + gunichar code = g_utf8_get_char_validated("0x266B", size); + g_string_append_unichar (string, code); + + pango_layout_set_text(layout, string->str, -1); + desc = pango_font_description_from_string("Sans Bold 12"); + pango_layout_set_font_description(layout, desc); + pango_font_description_free(desc); + + cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + pango_cairo_update_layout(cr, layout); + pango_cairo_show_layout(cr, layout); + + g_object_unref(layout); + + cairo_destroy (cr); + + return TRUE; } /* Suppress/consume keyevents */ -- cgit v1.2.3 From 97af8d3a53f77c0a2212dbbc58b09bb8c63c5a92 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 23 Aug 2010 16:45:40 +0100 Subject: finally blank art work handling out the door --- src/metadata-widget.c | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 146f84a..167ec88 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -244,19 +244,22 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user PangoLayout *layout; PangoFontDescription *desc; layout = pango_cairo_create_layout(cr); + PangoContext* pcontext = pango_cairo_create_context(cr); + pango_cairo_context_set_resolution (pcontext, 96); GString* string = g_string_new(""); gssize size = -1; - gunichar code = g_utf8_get_char_validated("0x266B", size); + gunichar code = g_utf8_get_char_validated("\342\231\253", size); g_string_append_unichar (string, code); pango_layout_set_text(layout, string->str, -1); - desc = pango_font_description_from_string("Sans Bold 12"); + desc = pango_font_description_from_string("Sans Bold 30"); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); - cairo_set_source_rgb(cr, 0.0, 0.0, 0.0); + cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.8); pango_cairo_update_layout(cr, layout); + cairo_move_to (cr, alloc.x + alloc.width/6, alloc.y); pango_cairo_show_layout(cr, layout); g_object_unref(layout); @@ -323,33 +326,6 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } } -static void metadata_widget_draw_album_art_placeholder(MetadataWidget* self) -{ - /*MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); - cairo_t *cr; - cr = gdk_cairo_create (GTK_WIDGET(self)->window); - PangoLayout *layout; - PangoFontDescription *desc; - layout = pango_cairo_create_layout(cr); - - GString* string = g_string_new(""); - gssize size = -1; - gunichar code = g_utf8_get_char_validated("0x266B", size); - g_string_append_unichar (string, code); - - pango_layout_set_text(layout, string->str, -1); - desc = pango_font_description_from_string("Sans Bold 12"); - pango_layout_set_font_description(layout, desc); - pango_font_description_free(desc); - - cairo_set_source_rgb(cr, 0.0, 0.0, 1.0); - pango_cairo_update_layout(cr, layout); - pango_cairo_show_layout(cr, layout); - - g_object_unref(layout); - cairo_destroy (cr); - */ -} static void metadata_widget_update_album_art(MetadataWidget* self){ -- cgit v1.2.3 From dcf151607e9dbf99d5a0550dd6d4f5efeaf620e0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 23 Aug 2010 17:24:44 +0100 Subject: finished with metadata ui tweaks --- src/metadata-widget.c | 57 +++++++++++++-------------------------------------- src/sound-service.c | 4 ++-- 2 files changed, 16 insertions(+), 45 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 167ec88..c7b2e32 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -65,8 +65,6 @@ static void metadata_widget_style_title_text(MetadataWidget* self); static void metadata_widget_style_artist_and_album_label(MetadataWidget* self, GtkLabel* label); -static void metadata_widget_draw_album_art_placeholder(MetadataWidget* self); - void metadata_widget_set_style(GtkWidget* button, GtkStyle* style); @@ -113,16 +111,16 @@ metadata_widget_init (MetadataWidget *self) gtk_box_pack_start (GTK_BOX (priv->hbox), priv->album_art, FALSE, FALSE, 0); GtkWidget* vbox = gtk_vbox_new(FALSE, 0); - gtk_container_set_border_width(GTK_CONTAINER(vbox), 10); // artist GtkWidget* artist; artist = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTIST)); gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); + gtk_misc_set_padding (GTK_MISC(artist), (gfloat)10, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(artist), 15); gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); - metadata_widget_style_artist_and_album_label(self, artist); + metadata_widget_style_artist_and_album_label(self, GTK_LABEL(artist)); priv->artist_label = artist; // title @@ -130,6 +128,7 @@ metadata_widget_init (MetadataWidget *self) piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TITLE)); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); + gtk_misc_set_padding (GTK_MISC(piece), (gfloat)10, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(piece), 15); gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); priv->piece_label = piece; @@ -140,9 +139,10 @@ metadata_widget_init (MetadataWidget *self) container = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ALBUM)); gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); + gtk_misc_set_padding (GTK_MISC(container), (gfloat)10, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(container), 15); gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); - metadata_widget_style_artist_and_album_label(self, container); + metadata_widget_style_artist_and_album_label(self, GTK_LABEL(container)); priv->container_label = container; gtk_box_pack_start (GTK_BOX (vbox), priv->piece_label, FALSE, FALSE, 0); @@ -173,24 +173,6 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } -/* -static void -_setup (cairo_t** cr, - cairo_surface_t** surf, - gint width, - gint height) -{ - if (!cr || !surf) - return; - - *surf = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); - *cr = cairo_create (*surf); - cairo_scale (*cr, 1.0f, 1.0f); - cairo_set_operator (*cr, CAIRO_OPERATOR_CLEAR); - cairo_paint (*cr); - cairo_set_operator (*cr, CAIRO_OPERATOR_OVER); -}*/ - /** * We override the expose method to enable primitive drawing of the * empty album art image (and soon rounded rectangles on the album art) @@ -198,7 +180,7 @@ _setup (cairo_t** cr, static gboolean metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user_data) { - g_return_if_fail(IS_METADATA_WIDGET(user_data)); + g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE); MetadataWidget* widget = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); @@ -206,20 +188,11 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user return FALSE; } - cairo_t *cr; - cairo_surface_t* surf = NULL; - + cairo_t *cr; cr = gdk_cairo_create (metadata->window); GtkAllocation alloc; gtk_widget_get_allocation (metadata, &alloc); - //_setup(&cr, &surf, alloc.width, alloc.height); - - g_debug("metatdata EXPOSE-> dimensions x = %i, y = %i, width = %i, height = %i", - alloc.x, - alloc.y, - alloc.width, - alloc.height); - + cairo_rectangle (cr, alloc.x, alloc.y, alloc.width, alloc.height); @@ -275,12 +248,12 @@ metadata_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { GtkClipboard* board = gtk_clipboard_get (GDK_NONE); - gchar* title = dbusmenu_menuitem_property_get(twin_item, - DBUSMENU_METADATA_MENUITEM_TITLE); - gchar* artist = dbusmenu_menuitem_property_get(twin_item, - DBUSMENU_METADATA_MENUITEM_ARTIST); - gchar* album = dbusmenu_menuitem_property_get(twin_item, - DBUSMENU_METADATA_MENUITEM_ALBUM); + gchar* title = g_strdup(dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_METADATA_MENUITEM_TITLE)); + gchar* artist = g_strdup(dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_METADATA_MENUITEM_ARTIST)); + gchar* album = g_strdup(dbusmenu_menuitem_property_get(twin_item, + DBUSMENU_METADATA_MENUITEM_ALBUM)); gchar* contents = g_strdup_printf("artist: %s \ntitle: %s \nalbum: %s", artist, title, album); g_debug("contents to be copied will be : %s", contents); gtk_clipboard_set_text (board, contents, -1); @@ -326,7 +299,6 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } } - static void metadata_widget_update_album_art(MetadataWidget* self){ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); @@ -340,7 +312,6 @@ metadata_widget_update_album_art(MetadataWidget* self){ } // TODO refactor next 3 methods into one once the style has been -// "signed off" by design static void metadata_widget_style_artist_and_album_label(MetadataWidget* self, GtkLabel* label) { diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 92d628cf6bff2644d6ccafd9f5d8d31d7659a242 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 23 Aug 2010 17:33:44 +0100 Subject: push up changes --- src/metadata-widget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index c7b2e32..eec98b0 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -236,7 +236,8 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user pango_cairo_show_layout(cr, layout); g_object_unref(layout); - + g_object_unref(p_context); + g_string_free (string); cairo_destroy (cr); return TRUE; -- cgit v1.2.3 From feed9f62a8779febde16e4f4461967a2b2a33e72 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 24 Aug 2010 16:22:35 +0100 Subject: mpris 2 metadata map changes implementated --- src/common-defs.h | 10 ++++----- src/metadata-menu-item.vala | 14 ++++++++++++ src/metadata-widget.c | 9 +++++--- src/mpris2-controller.vala | 53 +++++++++++++++++++++++++-------------------- src/player-item.vala | 8 +++---- src/scrub-menu-item.vala | 2 +- 6 files changed, 59 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index e3b4552..e554c11 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -34,16 +34,16 @@ with this program. If not, see . #define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-transport-state" #define DBUSMENU_METADATA_MENUITEM_TYPE "x-canonical-sound-menu-player-metadata-type" -#define DBUSMENU_METADATA_MENUITEM_ARTIST "x-canonical-sound-menu-player-metadata-artist" -#define DBUSMENU_METADATA_MENUITEM_TITLE "x-canonical-sound-menu-player-metadata-title" -#define DBUSMENU_METADATA_MENUITEM_ALBUM "x-canonical-sound-menu-player-metadata-album" -#define DBUSMENU_METADATA_MENUITEM_ARTURL "x-canonical-sound-menu-player-metadata-arturl" +#define DBUSMENU_METADATA_MENUITEM_ARTIST "x-canonical-sound-menu-player-metadata-xesam:artist" +#define DBUSMENU_METADATA_MENUITEM_TITLE "x-canonical-sound-menu-player-metadata-xesam:title" +#define DBUSMENU_METADATA_MENUITEM_ALBUM "x-canonical-sound-menu-player-metadata-xesam:album" +#define DBUSMENU_METADATA_MENUITEM_ARTURL "x-canonical-sound-menu-player-metadata-mpris:artUrl" #define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-type" #define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name" #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-type" -#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-time" +#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-mpris:length" #define DBUSMENU_SCRUB_MENUITEM_POSITION "x-canonical-sound-menu-player-scrub-position" #define DBUSMENU_SCRUB_MENUITEM_PLAY_STATE "x-canonical-sound-menu-player-scrub-play-state" diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 3818b1c..b13196f 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -29,6 +29,20 @@ public class MetadataMenuitem : PlayerItem reset(attributes_format()); } + public bool needs_reset(GLib.HashTable updates) + { + if(this.property_exist(MENUITEM_ARTURL) == false){ + return true; + } + if(this.property_get_int(MENUITEM_ARTURL) == EMPTY){ + return true; + } + if(strcmp(updates.lookup("xesam:artist").get_string() ,this.property_get(MENUITEM_ARTURL)) != 0){ + return true; + } + return false; + } + public static HashSet attributes_format() { HashSet attrs = new HashSet(); diff --git a/src/metadata-widget.c b/src/metadata-widget.c index eec98b0..aeef670 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -236,8 +236,8 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user pango_cairo_show_layout(cr, layout); g_object_unref(layout); - g_object_unref(p_context); - g_string_free (string); + g_object_unref(pcontext); + g_string_free (string, TRUE); cairo_destroy (cr); return TRUE; @@ -260,6 +260,9 @@ metadata_widget_button_press_event (GtkWidget *menuitem, gtk_clipboard_set_text (board, contents, -1); gtk_clipboard_store (board); g_free(contents); + g_free(title); + g_free(artist); + g_free(album); return FALSE; } @@ -295,7 +298,7 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); - g_string_overwrite(priv->image_path, 0, g_value_dup_string(value)); + g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); metadata_widget_update_album_art(mitem); } } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 6fa140e..d5152c2 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -19,6 +19,7 @@ with this program. If not, see . */ using DBus; + [DBus (name = "org.mpris.MediaPlayer2")] public interface MprisRoot : DBus.Object { // properties @@ -89,7 +90,7 @@ public class Mpris2Controller : GLib.Object this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { - error("Problems connecting to the session bus - %s", e.message); + error("Problems connecting to the session bus - %s", e.message); } } @@ -118,30 +119,34 @@ public class Mpris2Controller : GLib.Object Value? meta_v = changed_properties.lookup("Metadata"); if(meta_v != null){ - debug("metadata is not empty"); - debug("artist : %s", this.player.Metadata.lookup("artist").get_string()); - debug("arturl: %s", this.player.Metadata.lookup("arturl").get_string()); - /*try{ - debug("arturl : %s", this.player.Metadata.lookup("arturl").get_string()); - } - catch(GLib.Error e){ - warning("NO ART URL"); - }*/ + GLib.HashTable changed_updates = clean_metadata(); + + MetadataMenuitem meta = this.owner.custom_items[PlayerController.widget_order.METADATA] as MetadataMenuitem; + meta.reset(MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - debug("After the reset the arturl = %i", this.owner.custom_items[PlayerController.widget_order.METADATA].property_get_int("x-canonical-sound-menu-player-metadata-arturl")); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + this.owner.custom_items[PlayerController.widget_order.METADATA].update(changed_updates, MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - if((int)this.player.Metadata.lookup("artist").get_string().len() > 0 || - (int)this.player.Metadata.lookup("title").get_string().len() > 0){ - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, - ScrubMenuitem.attributes_format()); - } + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(changed_updates, + ScrubMenuitem.attributes_format()); + (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus)); } } + + private GLib.HashTable clean_metadata() + { + GLib.HashTable changed_updates = this.player.Metadata; + string[] artists = (string[])this.player.Metadata.lookup("xesam:artist"); + string display_artists = string.joinv(", ", artists); + changed_updates.replace("xesam:artist", display_artists); + debug("artist : %s", display_artists); + int64 duration = this.player.Metadata.lookup("mpris:length").get_int64(); + changed_updates.replace("mpris:length", duration/1000000); + return changed_updates; + } + private int determine_play_state(string status){ if(status == null) @@ -166,9 +171,10 @@ public class Mpris2Controller : GLib.Object debug("initial update - play state %i", status); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.player.Metadata, + var cleaned_metadata = this.clean_metadata(); + this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.player.Metadata, + this.owner.custom_items[PlayerController.widget_order.SCRUB].update(cleaned_metadata, ScrubMenuitem.attributes_format()); } @@ -211,19 +217,18 @@ public class Mpris2Controller : GLib.Object public void set_position(double position) { debug("Set position with pos (0-100) %f", position); - HashTable data = this.player.Metadata; - Value? time_value = data.lookup("time"); + Value? time_value = this.player.Metadata.lookup("mpris:length"); if(time_value == null){ warning("Can't fetch the duration of the track therefore cant set the position"); return; } // work in microseconds (scale up by 10 TTP-of 6) - uint32 total_time = time_value.get_uint() * 1000000; + int64 total_time = time_value.get_int64(); debug("total time of track = %i", (int)total_time); double new_time_position = total_time * (position/100.0); debug("new position = %f", (new_time_position)); - Value? v = this.player.Metadata.lookup("trackid"); + Value? v = this.player.Metadata.lookup("mpris:trackid"); if(v != null){ if(v.holds (typeof (string))){ DBus.ObjectPath path = new ObjectPath(v.get_string()); diff --git a/src/player-item.vala b/src/player-item.vala index e5d8bfc..fab1f85 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -60,7 +60,7 @@ public class PlayerItem : Dbusmenu.Menuitem string update = v.get_string().strip(); debug("with value : %s", update); // Special case for the arturl URI's. - if(property.contains("arturl")){ + if(property.contains("mpris:artUrl")){ try{ update = Filename.from_uri(update.strip()); } @@ -74,9 +74,9 @@ public class PlayerItem : Dbusmenu.Menuitem debug("with value : %i", v.get_int()); this.property_set_int(property, v.get_int()); } - else if (v.holds (typeof (uint))){ - debug("with value : %i", (int)v.get_uint()); - this.property_set_int(property, (int)v.get_uint()); + else if (v.holds (typeof (int64))){ + debug("with value : %i", (int)v.get_int64()); + this.property_set_int(property, (int)v.get_int64()); } else if(v.holds (typeof (bool))){ debug("with value : %s", v.get_boolean().to_string()); diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index 7368a0c..d7b60a0 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -42,7 +42,7 @@ public class ScrubMenuitem : PlayerItem public void update_playstate(int state) { - this.property_set_int(MENUITEM_PLAY_STATE, state); + this.property_set_int(MENUITEM_PLAY_STATE, state); } public static HashSet attributes_format() -- cgit v1.2.3 From 0cfad99ce347f365d52783a2f3543b25acc94706 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 25 Aug 2010 15:18:45 +0100 Subject: fonts sorted --- src/dbus-menu-manager.c | 6 +++--- src/metadata-widget.c | 20 +++++++++----------- src/mpris-controller.vala | 15 --------------- src/mpris2-controller.vala | 21 ++++----------------- src/player-controller.vala | 15 ++------------- src/sound-service.c | 4 ++-- src/title-widget.c | 4 ++-- 7 files changed, 22 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 6f0af9e..5ea561f 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -119,7 +119,7 @@ void dbus_menu_manager_update_mute_ui(gboolean incoming_mute_value) b_all_muted = incoming_mute_value; dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, - b_all_muted == FALSE ? _("Mute All") : _("Unmute")); + b_all_muted == FALSE ? _("Mute") : _("Unmute")); } @@ -190,7 +190,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service { // Mute button mute_all_menuitem = dbusmenu_menuitem_new(); - dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, b_all_muted == FALSE ? _("Mute All") : _("Unmute")); + dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, b_all_muted == FALSE ? _("Mute") : _("Unmute")); g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute_from_ui), NULL); dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available); @@ -229,7 +229,7 @@ static void set_global_mute_from_ui() toggle_global_mute(b_all_muted); dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, - b_all_muted == FALSE ? _("Mute All") : _("Unmute")); + b_all_muted == FALSE ? _("Mute") : _("Unmute")); } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index aeef670..8aeb862 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -61,9 +61,8 @@ static void metadata_widget_property_update (DbusmenuMenuitem* item, gpointer userdata); static void metadata_widget_update_album_art(MetadataWidget* self); -static void metadata_widget_style_title_text(MetadataWidget* self); -static void metadata_widget_style_artist_and_album_label(MetadataWidget* self, - GtkLabel* label); +static void metadata_widget_style_labels(MetadataWidget* self, + GtkLabel* label); void metadata_widget_set_style(GtkWidget* button, GtkStyle* style); @@ -83,7 +82,6 @@ metadata_widget_class_init (MetadataWidgetClass *klass) gobject_class->dispose = metadata_widget_dispose; gobject_class->finalize = metadata_widget_finalize; - } static void @@ -120,7 +118,7 @@ metadata_widget_init (MetadataWidget *self) gtk_misc_set_padding (GTK_MISC(artist), (gfloat)10, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(artist), 15); gtk_label_set_ellipsize(GTK_LABEL(artist), PANGO_ELLIPSIZE_MIDDLE); - metadata_widget_style_artist_and_album_label(self, GTK_LABEL(artist)); + metadata_widget_style_labels(self, GTK_LABEL(artist)); priv->artist_label = artist; // title @@ -131,8 +129,8 @@ metadata_widget_init (MetadataWidget *self) gtk_misc_set_padding (GTK_MISC(piece), (gfloat)10, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(piece), 15); gtk_label_set_ellipsize(GTK_LABEL(piece), PANGO_ELLIPSIZE_MIDDLE); + metadata_widget_style_labels(self, GTK_LABEL(piece)); priv->piece_label = piece; - metadata_widget_style_title_text(self); // container GtkWidget* container; @@ -142,7 +140,7 @@ metadata_widget_init (MetadataWidget *self) gtk_misc_set_padding (GTK_MISC(container), (gfloat)10, (gfloat)0); gtk_label_set_width_chars(GTK_LABEL(container), 15); gtk_label_set_ellipsize(GTK_LABEL(container), PANGO_ELLIPSIZE_MIDDLE); - metadata_widget_style_artist_and_album_label(self, GTK_LABEL(container)); + metadata_widget_style_labels(self, GTK_LABEL(container)); priv->container_label = container; gtk_box_pack_start (GTK_BOX (vbox), priv->piece_label, FALSE, FALSE, 0); @@ -286,15 +284,15 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTIST, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->artist_label), g_value_get_string(value)); - metadata_widget_style_artist_and_album_label(mitem, GTK_LABEL(priv->artist_label)); + metadata_widget_style_labels(mitem, GTK_LABEL(priv->artist_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TITLE, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value)); - metadata_widget_style_title_text(mitem); + metadata_widget_style_labels(mitem, GTK_LABEL(priv->piece_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ALBUM, property) == 0){ gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value)); - metadata_widget_style_artist_and_album_label(mitem, GTK_LABEL(priv->container_label)); + metadata_widget_style_labels(mitem, GTK_LABEL(priv->container_label)); } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); @@ -317,7 +315,7 @@ metadata_widget_update_album_art(MetadataWidget* self){ // TODO refactor next 3 methods into one once the style has been static void -metadata_widget_style_artist_and_album_label(MetadataWidget* self, GtkLabel* label) +metadata_widget_style_labels(MetadataWidget* self, GtkLabel* label) { char* markup; markup = g_markup_printf_escaped ("%s", diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index 1e1e00a..fc9eee0 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -61,10 +61,6 @@ public class MprisController : GLib.Object (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris_player.GetMetadata(), MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), - ScrubMenuitem.attributes_format()); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris_player.PositionGet()); } public void transport_event(TransportMenuitem.action command) @@ -96,8 +92,6 @@ public class MprisController : GLib.Object double new_time_position = total_time * position/100.0; debug("new position = %f", (new_time_position * 1000)); this.mpris_player.PositionSet((int32)(new_time_position)); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(this.mpris_player.PositionGet()); } public bool connected() @@ -117,7 +111,6 @@ public class MprisController : GLib.Object v.set_int(play_state); ht.insert("state", v); this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(ht, ScrubMenuitem.attributes_format()); } private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) @@ -125,21 +118,13 @@ public class MprisController : GLib.Object debug("onTrackChange"); this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - //HashTable status_hash = new HashTable(str_hash, str_equal); status st = this.mpris_player.GetStatus(); int play_state = st.playback; debug("GetStatusChange, about to update scrub with play state - %i", play_state); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_playstate(play_state); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(this.mpris_player.GetMetadata(), - ScrubMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, MetadataMenuitem.attributes_format()); debug("about to update the duration on the scrub bar"); - // temporary fix - scrub.update_position(this.mpris_player.PositionGet()); } } diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 166d7f4..df2bbd3 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -107,31 +107,20 @@ public class Mpris2Controller : GLib.Object debug("new playback state = %s", state); int p = this.determine_play_state(state); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); - (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(p); } Value? pos_v = changed_properties.lookup("Position"); if(pos_v != null){ int64 pos = pos_v.get_int64(); debug("new position = %i", (int)pos); - (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_position((int32)pos); } Value? meta_v = changed_properties.lookup("Metadata"); if(meta_v != null){ GLib.HashTable changed_updates = clean_metadata(); - - //MetadataMenuitem meta = this.owner.custom_items[PlayerController.widget_order.METADATA] as MetadataMenuitem; - //meta.reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); this.owner.custom_items[PlayerController.widget_order.METADATA].update(changed_updates, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(changed_updates, - ScrubMenuitem.attributes_format()); - - (this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem).update_playstate(this.determine_play_state(this.player.PlaybackStatus)); - } } @@ -180,8 +169,6 @@ public class Mpris2Controller : GLib.Object GLib.HashTable cleaned_metadata = this.clean_metadata(); this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); - this.owner.custom_items[PlayerController.widget_order.SCRUB].update(cleaned_metadata, - ScrubMenuitem.attributes_format()); } public void transport_event(TransportMenuitem.action command) @@ -240,8 +227,8 @@ public class Mpris2Controller : GLib.Object DBus.ObjectPath path = new ObjectPath(v.get_string()); try{ this.player.SetPosition(path, (int64)(new_time_position)); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position(((int32)new_time_position) / 1000); + //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + //scrub.update_position(((int32)new_time_position) / 1000); } catch(DBus.Error e){ error("DBus Error calling the player objects SetPosition method %s", @@ -253,8 +240,8 @@ public class Mpris2Controller : GLib.Object public void onSeeked(int64 position){ debug("Seeked signal callback with pos = %i", (int)position/1000); - ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - scrub.update_position((int32)position/1000); + //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; + //scrub.update_position((int32)position/1000); } public bool connected() diff --git a/src/player-controller.vala b/src/player-controller.vala index 2aa4382..3e12dce 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -23,13 +23,12 @@ using Gee; public class PlayerController : GLib.Object { - public const int WIDGET_QUANTITY = 5; + public const int WIDGET_QUANTITY = 4; public static enum widget_order{ SEPARATOR, TITLE, METADATA, - SCRUB, TRANSPORT, } @@ -114,25 +113,19 @@ public class PlayerController : GLib.Object update_state(PlayerController.state.OFFLINE); this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format()); this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - this.custom_items[widget_order.SCRUB].reset(ScrubMenuitem.attributes_format()); } public void update_layout() - { - + { if(this.current_state != state.CONNECTED){ this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, false); - this.custom_items[widget_order.SCRUB].property_set_bool(MENUITEM_PROP_VISIBLE, - false); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, false); return; } this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, this.custom_items[widget_order.METADATA].populated(MetadataMenuitem.attributes_format())); - this.custom_items[widget_order.SCRUB].property_set_bool(MENUITEM_PROP_VISIBLE, - this.custom_items[widget_order.SCRUB].populated(ScrubMenuitem.attributes_format())); this.custom_items[widget_order.TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -150,10 +143,6 @@ public class PlayerController : GLib.Object MetadataMenuitem metadata_item = new MetadataMenuitem(); this.custom_items.add(metadata_item); - // Scrub item - ScrubMenuitem scrub_item = new ScrubMenuitem(this); - this.custom_items.add(scrub_item); - // Transport item TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..42ce116 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/title-widget.c b/src/title-widget.c index 7e73f7e..b5ed3c0 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -160,12 +160,12 @@ title_widget_style_name_text(TitleWidget* self) TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); char* markup; - markup = g_markup_printf_escaped ("%s", + markup = g_markup_printf_escaped ("%s", gtk_label_get_text(GTK_LABEL(priv->name))); gtk_label_set_markup (GTK_LABEL (priv->name), markup); g_free(markup); } - + /** * transport_new: * @returns: a new #TitleWidget. -- cgit v1.2.3 From 254525b58e75739e8739cc1e13681a38b4beb615 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 25 Aug 2010 18:15:56 +0100 Subject: more tweaks --- src/metadata-widget.c | 14 +---------- src/play-button.c | 64 +++++++++++++++++++++++++-------------------------- src/title-widget.c | 2 +- 3 files changed, 34 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 8aeb862..fae3198 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -318,24 +318,12 @@ static void metadata_widget_style_labels(MetadataWidget* self, GtkLabel* label) { char* markup; - markup = g_markup_printf_escaped ("%s", + markup = g_markup_printf_escaped ("%s", gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup (GTK_LABEL (label), markup); g_free(markup); } -static void -metadata_widget_style_title_text(MetadataWidget* self) -{ - MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); - - char* markup; - markup = g_markup_printf_escaped ("%s", - gtk_label_get_text(GTK_LABEL(priv->piece_label))); - gtk_label_set_markup (GTK_LABEL (priv->piece_label), markup); - g_free(markup); -} - void metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style) { diff --git a/src/play-button.c b/src/play-button.c index 2f3a553..a2eaf2e 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -750,9 +750,9 @@ draw (GtkWidget* button, cairo_t *cr) X, Y + 2, RECT_WIDTH - 4, - INNER_RADIUS, - INNER_START, - INNER_END); + MIDDLE_RADIUS, + MIDDLE_START, + MIDDLE_END); if(priv->current_command == TRANSPORT_PREVIOUS){ draw_gradient (cr, @@ -774,35 +774,35 @@ draw (GtkWidget* button, cairo_t *cr) } // play/pause-background - draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)), - CIRCLE_RADIUS, - OUTER_START, - OUTER_END); - draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 0.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 0.5f, - CIRCLE_RADIUS - 0.75f, - MIDDLE_START, - MIDDLE_END); - - if(priv->current_command == TRANSPORT_PLAY_PAUSE){ - draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.5f, - CIRCLE_RADIUS - 1.5f, - INNER_COMPRESSED_START, - INNER_COMPRESSED_END); - } - else{ - draw_circle (cr, - X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.5f, - Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.5f, - CIRCLE_RADIUS - 1.5f, - INNER_START, - INNER_END); - } + draw_circle (cr, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)), + CIRCLE_RADIUS, + OUTER_START, + OUTER_END); + draw_circle (cr, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 0.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 0.5f, + CIRCLE_RADIUS - 0.75f, + MIDDLE_START, + MIDDLE_END); + + if(priv->current_command == TRANSPORT_PLAY_PAUSE){ + draw_circle (cr, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.5f, + CIRCLE_RADIUS - 1.5f, + INNER_COMPRESSED_START, + INNER_COMPRESSED_END); + } + else{ + draw_circle (cr, + X + RECT_WIDTH / 2.0f - 2.0f * OUTER_RADIUS - 5.5f + 1.5f, + Y - ((CIRCLE_RADIUS - OUTER_RADIUS)) + 1.5f, + CIRCLE_RADIUS - 1.5f, + MIDDLE_START, + MIDDLE_END); + } // draw previous-button drop-shadow _setup (&cr_surf, &surf, PREV_WIDTH, PREV_HEIGHT); _mask_prev (cr_surf, diff --git a/src/title-widget.c b/src/title-widget.c index b5ed3c0..e9f34d6 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -160,7 +160,7 @@ title_widget_style_name_text(TitleWidget* self) TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); char* markup; - markup = g_markup_printf_escaped ("%s", + markup = g_markup_printf_escaped ("%s", gtk_label_get_text(GTK_LABEL(priv->name))); gtk_label_set_markup (GTK_LABEL (priv->name), markup); g_free(markup); -- cgit v1.2.3 From 99755b257b5a7ed2676065cb8f4759e750c4f1ad Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 25 Aug 2010 20:33:25 +0100 Subject: tidied sound service --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 358766335b244a2687469687d0ecacfb4238b221 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 27 Aug 2010 12:25:47 +0100 Subject: remove mpris1 support --- src/Makefile.am | 2 - src/mpris-bridge.vala | 70 ------------------------ src/mpris-controller.vala | 130 --------------------------------------------- src/mpris2-controller.vala | 8 +-- src/player-controller.vala | 9 ++-- 5 files changed, 8 insertions(+), 211 deletions(-) delete mode 100644 src/mpris-bridge.vala delete mode 100644 src/mpris-controller.vala (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 74e0297..2a4e937 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -65,8 +65,6 @@ music_bridge_VALASOURCES = \ scrub-menu-item.vala \ title-menu-item.vala \ player-controller.vala \ - mpris-bridge.vala \ - mpris-controller.vala \ mpris2-controller.vala \ player-item.vala \ familiar-players-db.vala diff --git a/src/mpris-bridge.vala b/src/mpris-bridge.vala deleted file mode 100644 index bd9d472..0000000 --- a/src/mpris-bridge.vala +++ /dev/null @@ -1,70 +0,0 @@ -public class MprisBridge : GLib.Object -{ - private MprisController mpris1_controller; - private Mpris2Controller mpris2_controller; - private enum mode{ - MPRIS_1, - MPRIS_2 - } - private mode mode_in_use; - - public MprisBridge(PlayerController ctrl) - { - this.mpris2_controller = new Mpris2Controller(ctrl); - if(this.mpris2_controller.was_successfull() == true){ - this.mode_in_use = mode.MPRIS_2; - this.mpris1_controller = null; - this.mpris2_controller.initial_update(); - } - else{ - this.mpris2_controller = null; - this.mode_in_use = mode.MPRIS_1; - this.mpris1_controller = new MprisController(ctrl); - } - } - - // The handling of both mpris controllers can be abstracted further - // once the mpris2 is implemented. This will allow for one instance - // variable to point at the active controller. For now handle both ... - public bool connected() - { - if(this.mode_in_use == mode.MPRIS_1){ - return this.mpris1_controller.connected(); - } - else if(this.mode_in_use == mode.MPRIS_2){ - return this.mpris2_controller.connected(); - } - return false; - } - - public void transport_update(TransportMenuitem.action update) - { - if(this.mode_in_use == mode.MPRIS_1){ - this.mpris1_controller.transport_event(update); - } - else if(this.mode_in_use == mode.MPRIS_2){ - this.mpris2_controller.transport_event(update); - } - } - - public void expose() - { - if(this.mode_in_use == mode.MPRIS_2){ - this.mpris2_controller.expose(); - } - else{ - warning("MPRIS1 clients don't have the ability to raise/expose the client"); - } - } - - - public void set_track_position(double pos) - { - if(this.mode_in_use == mode.MPRIS_1){ - this.mpris1_controller.set_position(pos); - } - else if(this.mode_in_use == mode.MPRIS_2){ - this.mpris2_controller.set_position(pos); - } - } -} \ No newline at end of file diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala deleted file mode 100644 index fc9eee0..0000000 --- a/src/mpris-controller.vala +++ /dev/null @@ -1,130 +0,0 @@ -/* -This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. -Copyright 2010 Canonical Ltd. - -Authors: - Conor Curran - -This program is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License version 3, as published -by the Free Software Foundation. - -This program is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranties of -MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR -PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program. If not, see . -*/ - -using Gee; - -public class MprisController : GLib.Object -{ - private DBus.Connection connection; - public dynamic DBus.Object mpris_player{get; construct;} - public PlayerController owner {get; construct;} - public string mpris_interface {get; construct;} - - struct status { - public int32 playback; - public int32 shuffle; - public int32 repeat; - public int32 endless; - } - - public MprisController(PlayerController ctrl, string inter="org.freedesktop.MediaPlayer"){ - Object(owner: ctrl, mpris_interface: inter); - } - - construct{ - try { - this.connection = DBus.Bus.get (DBus.BusType.SESSION); - } catch (Error e) { - error("Problems connecting to the session bus - %s", e.message); - } - this.mpris_player = this.connection.get_object ("org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface); - - debug("Attempting to establish an mpris connection to %s, %s, %s", "org.mpris.".concat(this.owner.name.down()) , "/Player", this.mpris_interface); - - this.mpris_player.TrackChange += onTrackChange; - this.mpris_player.StatusChange += onStatusChange; - initial_update(); - } - - private void initial_update() - { - status st = this.mpris_player.GetStatus(); - int play_state = st.playback; - debug("GetStatusChange - play state %i", play_state); - (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(play_state); - this.owner.custom_items[PlayerController.widget_order.METADATA].update(this.mpris_player.GetMetadata(), - MetadataMenuitem.attributes_format()); - } - - public void transport_event(TransportMenuitem.action command) - { - debug("transport_event input = %i", (int)command); - if(command == TransportMenuitem.action.PLAY_PAUSE){ - debug("transport_event PLAY_PAUSE"); - this.mpris_player.Pause(); - } - else if(command == TransportMenuitem.action.PREVIOUS){ - this.mpris_player.Prev(); - } - else if(command == TransportMenuitem.action.NEXT){ - this.mpris_player.Next(); - } - } - - public void set_position(double position) - { - debug("Set position with pos (0-100) %f", position); - HashTable data = this.mpris_player.GetMetadata(); - Value? time_value = data.lookup("time"); - if(time_value == null){ - warning("Can't fetch the duration of the track therefore cant set the position"); - return; - } - uint32 total_time = time_value.get_uint(); - debug("total time of track = %i", (int)total_time); - double new_time_position = total_time * position/100.0; - debug("new position = %f", (new_time_position * 1000)); - this.mpris_player.PositionSet((int32)(new_time_position)); - } - - public bool connected() - { - return (this.mpris_player != null); - } - - private void onStatusChange(dynamic DBus.Object mpris_client, status st) - { - debug("onStatusChange - signal received"); - status* status = &st; - unowned ValueArray ar = (ValueArray)status; - int play_state = ar.get_nth(0).get_int(); - debug("onStatusChange - play state %i", play_state); - HashTable ht = new HashTable(str_hash, str_equal); - Value v = Value(typeof(int)); - v.set_int(play_state); - ht.insert("state", v); - this.owner.custom_items[PlayerController.widget_order.TRANSPORT].update(ht, TransportMenuitem.attributes_format()); - } - - private void onTrackChange(dynamic DBus.Object mpris_client, HashTable ht) - { - debug("onTrackChange"); - - this.owner.custom_items[PlayerController.widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); - - status st = this.mpris_player.GetStatus(); - int play_state = st.playback; - debug("GetStatusChange, about to update scrub with play state - %i", play_state); - - this.owner.custom_items[PlayerController.widget_order.METADATA].update(ht, - MetadataMenuitem.attributes_format()); - debug("about to update the duration on the scrub bar"); - } -} diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index df2bbd3..dd6a312 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -171,7 +171,7 @@ public class Mpris2Controller : GLib.Object MetadataMenuitem.attributes_format()); } - public void transport_event(TransportMenuitem.action command) + public void transport_update(TransportMenuitem.action command) { debug("transport_event input = %i", (int)command); if(command == TransportMenuitem.action.PLAY_PAUSE){ @@ -207,7 +207,7 @@ public class Mpris2Controller : GLib.Object TODO: SetPosition on the player object is not working with rhythmbox, runtime error - "dbus function not supported" */ - public void set_position(double position) + public void set_track_position(double position) { debug("Set position with pos (0-100) %f", position); Value? time_value = this.player.Metadata.lookup("mpris:length"); @@ -227,8 +227,6 @@ public class Mpris2Controller : GLib.Object DBus.ObjectPath path = new ObjectPath(v.get_string()); try{ this.player.SetPosition(path, (int64)(new_time_position)); - //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - //scrub.update_position(((int32)new_time_position) / 1000); } catch(DBus.Error e){ error("DBus Error calling the player objects SetPosition method %s", @@ -240,8 +238,6 @@ public class Mpris2Controller : GLib.Object public void onSeeked(int64 position){ debug("Seeked signal callback with pos = %i", (int)position/1000); - //ScrubMenuitem scrub = this.owner.custom_items[PlayerController.widget_order.SCRUB] as ScrubMenuitem; - //scrub.update_position((int32)position/1000); } public bool connected() diff --git a/src/player-controller.vala b/src/player-controller.vala index 3e12dce..4d9f054 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -45,11 +45,14 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - public MprisBridge mpris_bridge; + public Mpris2Controller mpris_bridge; public AppInfo? app_info { get; set;} public int menu_offset { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, int offset, state initial_state) + public PlayerController(Dbusmenu.Menuitem root, + string client_name, + int offset, + state initial_state) { this.root_menu = root; this.name = format_client_name(client_name.strip()); @@ -97,7 +100,7 @@ public class PlayerController : GLib.Object debug("establish_mpris_connection - Not ready to connect"); return; } - this.mpris_bridge = new MprisBridge(this); + this.mpris_bridge = new Mpris2Controller(this); this.determine_state(); } -- cgit v1.2.3 From a9a0b28e5f0410bc1172a21ea7e40bb3c76ece8c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 31 Aug 2010 12:08:03 +0100 Subject: fixed the scrolling regression --- src/indicator-sound.c | 29 ++++++++++++++++++++++++++++- src/volume-widget.c | 4 +++- 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 63ad72d..a454600 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -67,6 +67,8 @@ G_DEFINE_TYPE (IndicatorSound, indicator_sound, INDICATOR_OBJECT_TYPE); static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); +static void indicator_sound_scroll (IndicatorObject* io, gint delta, IndicatorScrollDirection direction); + //Slider related static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); @@ -135,7 +137,7 @@ indicator_sound_class_init (IndicatorSoundClass *klass) io_class->get_label = get_label; io_class->get_image = get_icon; io_class->get_menu = get_menu; - + io_class->scroll = indicator_sound_scroll; design_team_size = gtk_icon_size_register("design-team-size", 22, 22); return; @@ -710,3 +712,28 @@ style_changed_cb(GtkWidget *widget, gpointer user_data) free_the_animation_list(); prepare_blocked_animation(); } + +static void +indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirection direction) +{ + g_debug("indicator-sound-scroll - current slider value"); + + if (device_available == FALSE || current_state == STATE_MUTED) + return; + + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + + GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); + GtkRange* range = (GtkRange*)slider; + gdouble value = gtk_range_get_value(range); + GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (slider)); + g_debug("indicator-sound-scroll - current slider value %f", value); + if (direction == INDICATOR_OBJECT_SCROLL_UP) { + value += adj->step_increment; + } else { + value -= adj->step_increment; + } + g_debug("indicator-sound-scroll - update slider with value %f", value); + volume_widget_update(VOLUME_WIDGET(priv->volume_widget), value); +} \ No newline at end of file diff --git a/src/volume-widget.c b/src/volume-widget.c index bf1ddb9..5e7cf9f 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -1,3 +1,4 @@ + /* Copyright 2010 Canonical Ltd. @@ -48,6 +49,7 @@ static void volume_widget_set_twin_item( VolumeWidget* self, DbusmenuMenuitem* twin_item); static void volume_widget_property_update( DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); + static gboolean volume_widget_change_value_cb (GtkRange *range, GtkScrollType scroll, gdouble value, @@ -103,7 +105,7 @@ volume_widget_init (VolumeWidget *self) g_object_unref(secondary_gicon); GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (volume_widget)); - gtk_adjustment_set_step_increment(adj, 3); + gtk_adjustment_set_step_increment(adj, 4); } static void -- cgit v1.2.3 From 262ef2532f8aa20018a750307f3d4815933e3c47 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 1 Sep 2010 00:31:55 +0100 Subject: first legit attempt at icon gutter placement failed --- src/indicator-sound.c | 38 +++++++++++++++++++++++++++++--------- src/sound-service.c | 4 ++-- src/title-widget.c | 16 +++++++++++----- src/title-widget.h | 6 +++--- 4 files changed, 45 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 63ad72d..0f0c32d 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -48,6 +48,7 @@ typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; struct _IndicatorSoundPrivate { GtkWidget* volume_widget; + DbusmenuGtkMenu* menu; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -194,8 +195,10 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) { - gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - g_debug("At start-up attempting to set the image to %s", current_name); + gchar* current_name = g_hash_table_lookup(volume_states, + GINT_TO_POINTER(current_state)); + g_debug("At start-up attempting to set the image to %s", + current_name); speaker_image = indicator_image_helper(current_name); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; @@ -207,7 +210,10 @@ get_icon (IndicatorObject * io) static GtkMenu * get_menu (IndicatorObject * io) { - DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); + DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + priv->menu = menu; + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); g_object_set_data (G_OBJECT (client), "indicator", io); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_VOLUME_MENUITEM_TYPE, new_volume_slider_widget); @@ -215,10 +221,11 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget); - // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io); - return GTK_MENU(menu); + priv->menu = menu; + + return GTK_MENU(menu); } static void @@ -274,18 +281,31 @@ new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu { g_debug("indicator-sound: new_title_widget"); - GtkWidget* title = NULL; - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + GtkWidget* title = NULL; + IndicatorObject *io = NULL; + title = title_widget_new (newitem); GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title); - gtk_widget_show_all(title); + io = g_object_get_data (G_OBJECT (client), "indicator"); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + + GtkWidget* image_item = gtk_image_menu_item_new(); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(image_item), + title_widget_get_player_icon(TITLE_WIDGET(title))); - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent); + gtk_widget_show_all(image_item); + gtk_menu_append(priv->menu, image_item); + + gtk_widget_show_all(title); + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), + newitem, + menu_title_widget, parent); return TRUE; } diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..42ce116 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/title-widget.c b/src/title-widget.c index e9f34d6..8f0c3c5 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -35,6 +35,7 @@ struct _TitleWidgetPrivate GtkWidget* hbox; GtkWidget* name; GtkWidget* player_icon; + GtkWidget* image_item; DbusmenuMenuitem* twin_item; }; @@ -73,7 +74,6 @@ title_widget_class_init (TitleWidgetClass *klass) gobject_class->dispose = title_widget_dispose; gobject_class->finalize = title_widget_finalize; - } static void @@ -84,12 +84,12 @@ title_widget_init (TitleWidget *self) TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); GtkWidget *hbox; - + hbox = gtk_hbox_new(FALSE, 0); priv->hbox = hbox; - priv->player_icon = indicator_image_helper("sound_icon"); - gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0); + + //gtk_box_pack_start(GTK_BOX (priv->hbox), priv->image_item, FALSE, FALSE, 0); } static void @@ -165,7 +165,13 @@ title_widget_style_name_text(TitleWidget* self) gtk_label_set_markup (GTK_LABEL (priv->name), markup); g_free(markup); } - + +GtkWidget* title_widget_get_player_icon(TitleWidget* self) +{ + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); + return priv->player_icon; +} + /** * transport_new: * @returns: a new #TitleWidget. diff --git a/src/title-widget.h b/src/title-widget.h index fc8f169..827a8f3 100644 --- a/src/title-widget.h +++ b/src/title-widget.h @@ -35,16 +35,16 @@ typedef struct _TitleWidget TitleWidget; typedef struct _TitleWidgetClass TitleWidgetClass; struct _TitleWidgetClass { - GtkMenuItemClass parent_class; + GtkMenuItemClass parent_class; }; struct _TitleWidget { - GtkMenuItem parent; + GtkMenuItem parent; }; GType title_widget_get_type (void); GtkWidget* title_widget_new(DbusmenuMenuitem *twin_item); - +GtkWidget* title_widget_get_player_icon(TitleWidget* self); G_END_DECLS #endif -- cgit v1.2.3 From 67bdc60671c338045771b52a670c8788e565fcb3 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 1 Sep 2010 15:29:26 +0100 Subject: now has the ability to fetch album art from last fm --- src/Makefile.am | 8 ++++-- src/fetch-file.vala | 65 +++++++++++++++++++++++++++++++++++++++++++++ src/metadata-menu-item.vala | 2 +- src/metadata-widget.c | 1 + src/player-item.vala | 56 ++++++++++++++++++++++++++++++++++---- src/sound-service.c | 4 +-- 6 files changed, 126 insertions(+), 10 deletions(-) create mode 100644 src/fetch-file.vala (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 2a4e937..e85ed93 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -67,7 +67,9 @@ music_bridge_VALASOURCES = \ player-controller.vala \ mpris2-controller.vala \ player-item.vala \ - familiar-players-db.vala + familiar-players-db.vala \ + fetch-file.vala + music_bridge_VALAFLAGS = \ --ccode \ @@ -81,7 +83,9 @@ music_bridge_VALAFLAGS = \ --pkg Dbusmenu-Glib-0.2 \ --pkg common-defs \ --pkg dbus-glib-1 \ - --pkg gio-unix-2.0 + --pkg gio-unix-2.0 \ + --pkg gdk-pixbuf-2.0 + $(MAINTAINER_VALAFLAGS) diff --git a/src/fetch-file.vala b/src/fetch-file.vala new file mode 100644 index 0000000..55bfdc3 --- /dev/null +++ b/src/fetch-file.vala @@ -0,0 +1,65 @@ +public class FetchFile : Object +{ + /* public variables */ + public string uri {get; construct;} + + /* private variables */ + private DataInputStream stream; + private File? file; + private ByteArray data; + + /* public signals */ + public signal void failed (); + public signal void completed (ByteArray data); + + public FetchFile (string uri) + { + Object (uri: uri); + } + + construct + { + this.file = File.new_for_uri(this.uri); + this.data = new ByteArray (); + } + + public async void fetch_data () + { + //grab our data from our uri + try { + this.stream = new DataInputStream(this.file.read(null)); + this.stream.set_byte_order (DataStreamByteOrder.LITTLE_ENDIAN); + } catch (GLib.Error e) { + this.failed (); + } + this.read_something_async (); + } + + private async void read_something_async () + { + ssize_t size = 1024; + uint8[] buffer = new uint8[size]; + + ssize_t bufsize = 1; + do { + try { + bufsize = yield this.stream.read_async (buffer, size, GLib.Priority.DEFAULT, null); + if (bufsize < 1) { break;} + + if (bufsize != size) + { + uint8[] cpybuf = new uint8[bufsize]; + Memory.copy (cpybuf, buffer, bufsize); + this.data.append (cpybuf); + } + else + { + this.data.append (buffer); + } + } catch (Error e) { + this.failed (); + } + } while (bufsize > 0); + this.completed (this.data); + } +} diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 0bb4a85..090952b 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -17,9 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -using Dbusmenu; using Gee; using DbusmenuMetadata; +using Gdk; public class MetadataMenuitem : PlayerItem { diff --git a/src/metadata-widget.c b/src/metadata-widget.c index f600238..5e75b29 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -190,6 +190,7 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user if(priv->image_path->len > 0){ if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ + GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); g_debug("metadata_widget_expose, album art update -> pixbuf from %s", diff --git a/src/player-item.vala b/src/player-item.vala index fbfacbd..82b9f07 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -61,14 +61,20 @@ public class PlayerItem : Dbusmenu.Menuitem debug("with value : %s", update); // Special case for the arturl URI's. if(property.contains("mpris:artUrl")){ - try{ - update = Filename.from_uri(update.strip()); + if(update.has_prefix("http://")){ } - catch(ConvertError e){ - warning("Problem converting URI %s to file path", update); + else{ + // The file is local, just parse the string + try{ + update = Filename.from_uri(update.strip()); + } + catch(ConvertError e){ + warning("Problem converting URI %s to file path", + update); + } } } - this.property_set(property, update); + this.property_set(property, update); } else if (v.holds (typeof (int))){ debug("with value : %i", v.get_int()); @@ -101,5 +107,45 @@ public class PlayerItem : Dbusmenu.Menuitem } return false; } + + public fetch_remote_art(uri) + { + this.fetcher = new FetchFile (uri); + this.fetcher.failed.connect (() => { this.on_fetcher_failed ();}); + this.fetcher.completed.connect (this.on_fetcher_completed); + this.fetcher.fetch_data (); + } + + public string parse_art_url(string update) + { + if(update == null) + return null; + string temp_path = "/home/ronoc/Desktop/tempy.jpg"; + string local_path = ""; + string temp_name = ""; + + debug("MetadataMenuitem: parse art url - result %s", local_path); + return local_path; + } + + public extract_downloaded_file() + { + try{ + PixbufLoader loader = new PixbufLoader (); + bool write_result = loader.write (update.data, update.len()); + loader.close (); + unowned PixbufFormat format = loader.get_format(); + debug("the bloody format name is %s", format.get_name()); + debug("is the format null %s", (format == null).to_string()); + Pixbuf icon = loader.get_pixbuf (); + temp_name = loader.get_format().get_name(); + icon.save (temp_path, "jpeg"); + local_path = temp_path; + } + catch(GLib.Error e){ + warning("Problem taking file from the interweb - error: %s and name: %s", + e.message, + temp_name); + } } diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..42ce116 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 9ab9b175e1f77457157211f5f93c54e8ae87e3dc Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 1 Sep 2010 17:22:55 +0100 Subject: almost bug free --- src/common-defs.h | 1 + src/fetch-file.vala | 9 +++++---- src/metadata-menu-item.vala | 1 - src/metadata-widget.c | 22 +++++++++++++++------ src/player-item.vala | 48 +++++++++++++++++++++------------------------ 5 files changed, 44 insertions(+), 37 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index e554c11..faffcb2 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,6 +25,7 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 +#define DBUSMENU_PLAYERITEM_REMOTE_FILEPATH "/home/ronoc/Desktop/tempy" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/fetch-file.vala b/src/fetch-file.vala index 55bfdc3..f172853 100644 --- a/src/fetch-file.vala +++ b/src/fetch-file.vala @@ -2,6 +2,7 @@ public class FetchFile : Object { /* public variables */ public string uri {get; construct;} + public string intended_property {get; construct;} /* private variables */ private DataInputStream stream; @@ -10,11 +11,11 @@ public class FetchFile : Object /* public signals */ public signal void failed (); - public signal void completed (ByteArray data); + public signal void completed (ByteArray data, string property); - public FetchFile (string uri) + public FetchFile (string uri, string prop) { - Object (uri: uri); + Object (uri: uri, intended_property: prop); } construct @@ -60,6 +61,6 @@ public class FetchFile : Object this.failed (); } } while (bufsize > 0); - this.completed (this.data); + this.completed (this.data, this.intended_property); } } diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 090952b..04284d4 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -19,7 +19,6 @@ with this program. If not, see . using Gee; using DbusmenuMetadata; -using Gdk; public class MetadataMenuitem : PlayerItem { diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 5e75b29..72acc8c 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -36,6 +36,7 @@ struct _MetadataWidgetPrivate GtkWidget* album_art; GString* image_path; GString* old_image_path; + GString* remote_image_path; GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; @@ -104,6 +105,7 @@ metadata_widget_init (MetadataWidget *self) priv->album_art = gtk_image_new(); priv->image_path = g_string_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); priv->old_image_path = g_string_new(""); + priv->remote_image_path = g_string_new(DBUSMENU_PLAYERITEM_REMOTE_FILEPATH); g_debug("Metadata::At startup and image path = %s", priv->image_path->str); g_signal_connect(priv->album_art, "expose-event", @@ -176,6 +178,10 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } +static void metadata_load_new_image(MetadataWidget* self) +{ +} + /** * We override the expose method to enable primitive drawing of the * empty album art image (and soon rounded rectangles on the album art) @@ -188,19 +194,20 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); if(priv->image_path->len > 0){ - - if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ - + if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || + (g_string_equal(priv->image_path, priv->remote_image_path) == TRUE && + g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); - g_debug("metadata_widget_expose, album art update -> pixbuf from %s", - priv->image_path->str); + g_debug("metadata_load_new_image -> pixbuf from %s", + priv->image_path->str); pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); image_set_from_pixbuf (metadata, widget, pixbuf); g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->old_image_path, 0, priv->image_path->str); - g_object_unref(pixbuf); + g_object_unref(pixbuf); + } return FALSE; } @@ -315,7 +322,10 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); + //gchar* empty = ""; + g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); + //g_free(empty); } } diff --git a/src/player-item.vala b/src/player-item.vala index 82b9f07..7de6840 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -19,13 +19,15 @@ with this program. If not, see . using Dbusmenu; using Gee; +using Gdk; public class PlayerItem : Dbusmenu.Menuitem { public PlayerController owner {get; construct;} public string item_type { get; construct; } private const int EMPTY = -1; - + private FetchFile fetcher; + public PlayerItem(string type) { Object(item_type: type); @@ -62,6 +64,9 @@ public class PlayerItem : Dbusmenu.Menuitem // Special case for the arturl URI's. if(property.contains("mpris:artUrl")){ if(update.has_prefix("http://")){ + // This is asyncronous so handle it offline + this.fetch_remote_art(update.strip(), property); + continue; } else{ // The file is local, just parse the string @@ -108,44 +113,35 @@ public class PlayerItem : Dbusmenu.Menuitem return false; } - public fetch_remote_art(uri) + public void fetch_remote_art(string uri, string prop) { - this.fetcher = new FetchFile (uri); + this.fetcher = new FetchFile (uri, prop); this.fetcher.failed.connect (() => { this.on_fetcher_failed ();}); this.fetcher.completed.connect (this.on_fetcher_completed); this.fetcher.fetch_data (); } - - public string parse_art_url(string update) - { - if(update == null) - return null; - string temp_path = "/home/ronoc/Desktop/tempy.jpg"; - string local_path = ""; - string temp_name = ""; - debug("MetadataMenuitem: parse art url - result %s", local_path); - return local_path; + private void on_fetcher_failed () + { + warning("on_fetcher_failed -> could not fetch artwork"); } - - public extract_downloaded_file() + + private void on_fetcher_completed(ByteArray update, string property) { + string temp_path = "/home/ronoc/Desktop/tempy"; + //"/tmp/indicator-sound-remote-image"; try{ PixbufLoader loader = new PixbufLoader (); - bool write_result = loader.write (update.data, update.len()); + loader.write (update.data, update.len); loader.close (); - unowned PixbufFormat format = loader.get_format(); - debug("the bloody format name is %s", format.get_name()); - debug("is the format null %s", (format == null).to_string()); Pixbuf icon = loader.get_pixbuf (); - temp_name = loader.get_format().get_name(); - icon.save (temp_path, "jpeg"); - local_path = temp_path; + icon.save (temp_path, loader.get_format().get_name()); + this.property_set(property, temp_path); } catch(GLib.Error e){ - warning("Problem taking file from the interweb - error: %s and name: %s", - e.message, - temp_name); - } + warning("Problem taking file from the interweb - error: %s", + e.message); + } + } } -- cgit v1.2.3 From bb73e65c4fd9f698050ff1d2ddb71fc35bac6803 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 1 Sep 2010 17:51:30 +0100 Subject: last fm art work should load correctly now --- src/common-defs.h | 2 +- src/fetch-file.vala | 22 +++++++++++++++++++++- src/metadata-widget.c | 14 ++++++-------- src/player-item.vala | 9 ++++----- src/sound-service.c | 4 ++-- 5 files changed, 34 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index faffcb2..2590692 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,7 +25,7 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 -#define DBUSMENU_PLAYERITEM_REMOTE_FILEPATH "/home/ronoc/Desktop/tempy" +#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/home/ronoc/Desktop/tempy" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/fetch-file.vala b/src/fetch-file.vala index f172853..1811cc1 100644 --- a/src/fetch-file.vala +++ b/src/fetch-file.vala @@ -1,3 +1,24 @@ +/* + * Copyright (C) 2010 Canonical, Ltd. + * + * This library is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License + * version 3.0 as published by the Free Software Foundation. + * + * This library 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 version 3.0 for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Authors + * Gordon Allott + * Conor Curran + */ + public class FetchFile : Object { /* public variables */ @@ -26,7 +47,6 @@ public class FetchFile : Object public async void fetch_data () { - //grab our data from our uri try { this.stream = new DataInputStream(this.file.read(null)); this.stream.set_byte_order (DataStreamByteOrder.LITTLE_ENDIAN); diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 72acc8c..cfff098 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -105,7 +105,7 @@ metadata_widget_init (MetadataWidget *self) priv->album_art = gtk_image_new(); priv->image_path = g_string_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); priv->old_image_path = g_string_new(""); - priv->remote_image_path = g_string_new(DBUSMENU_PLAYERITEM_REMOTE_FILEPATH); + priv->remote_image_path = g_string_new(DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH); g_debug("Metadata::At startup and image path = %s", priv->image_path->str); g_signal_connect(priv->album_art, "expose-event", @@ -178,10 +178,6 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } -static void metadata_load_new_image(MetadataWidget* self) -{ -} - /** * We override the expose method to enable primitive drawing of the * empty album art image (and soon rounded rectangles on the album art) @@ -322,10 +318,12 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); - //gchar* empty = ""; - g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); - //g_free(empty); + // Basically force expose the reload the image because we have an image update + // but we are using remote images i.e. the same file + if(g_string_equal(priv->image_path, priv->remote_image_path) == TRUE){ + g_string_erase(priv->old_image_path, 0, -1); + } } } diff --git a/src/player-item.vala b/src/player-item.vala index 7de6840..1e16742 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -20,6 +20,7 @@ with this program. If not, see . using Dbusmenu; using Gee; using Gdk; +using DbusmenuPlayer; public class PlayerItem : Dbusmenu.Menuitem { @@ -128,18 +129,16 @@ public class PlayerItem : Dbusmenu.Menuitem private void on_fetcher_completed(ByteArray update, string property) { - string temp_path = "/home/ronoc/Desktop/tempy"; - //"/tmp/indicator-sound-remote-image"; try{ PixbufLoader loader = new PixbufLoader (); loader.write (update.data, update.len); loader.close (); Pixbuf icon = loader.get_pixbuf (); - icon.save (temp_path, loader.get_format().get_name()); - this.property_set(property, temp_path); + icon.save (ITEM_REMOTE_FILEPATH, loader.get_format().get_name()); + this.property_set(property, ITEM_REMOTE_FILEPATH); } catch(GLib.Error e){ - warning("Problem taking file from the interweb - error: %s", + warning("Problem fetching file from the interweb - error: %s", e.message); } } diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 136b92dbb90bd3c9d1905d0f039b8776aa1a1c73 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Sep 2010 11:27:23 +0100 Subject: album art from remote location working --- src/common-defs.h | 2 +- src/metadata-widget.c | 29 ++++++++++++++++++++--------- src/sound-service.c | 3 +-- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index 2590692..fc4e323 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,7 +25,7 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 -#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/home/ronoc/Desktop/tempy" +#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/tmp/indicator-sound-downloaded-album-art" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/metadata-widget.c b/src/metadata-widget.c index cfff098..3e01aec 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -70,7 +70,7 @@ static void image_set_from_pixbuf (GtkWidget *widget, MetadataWidget* metadata, GdkPixbuf *source); - +static void draw_album_art_placeholder(GtkWidget *metadata); G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); @@ -180,7 +180,7 @@ metadata_widget_finalize (GObject *object) /** * We override the expose method to enable primitive drawing of the - * empty album art image (and soon rounded rectangles on the album art) + * empty album art image and rounded rectangles on the album art. */ static gboolean metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user_data) @@ -188,26 +188,37 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE); MetadataWidget* widget = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); - + g_debug("expose"); if(priv->image_path->len > 0){ if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || (g_string_equal(priv->image_path, priv->remote_image_path) == TRUE && - g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ + g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ + g_debug("and we are in"); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); g_debug("metadata_load_new_image -> pixbuf from %s", priv->image_path->str); + if(GDK_IS_PIXBUF(pixbuf) == FALSE){ + g_debug("problem loading the downloaded image just use the placeholder instead"); + draw_album_art_placeholder(metadata); + return TRUE; + } pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR); image_set_from_pixbuf (metadata, widget, pixbuf); g_string_erase(priv->old_image_path, 0, -1); g_string_overwrite(priv->old_image_path, 0, priv->image_path->str); g_object_unref(pixbuf); - } return FALSE; } - + draw_album_art_placeholder(metadata); + return TRUE; +} + +static void draw_album_art_placeholder(GtkWidget *metadata) +{ + cairo_t *cr; cr = gdk_cairo_create (metadata->window); GtkAllocation alloc; @@ -259,8 +270,7 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user g_object_unref(pcontext); g_string_free (string, TRUE); cairo_destroy (cr); - - return TRUE; + } /* Suppress/consume keyevents */ @@ -320,9 +330,10 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, g_string_erase(priv->image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); // Basically force expose the reload the image because we have an image update - // but we are using remote images i.e. the same file + // but we are using remote images i.e. the same file path but different images if(g_string_equal(priv->image_path, priv->remote_image_path) == TRUE){ g_string_erase(priv->old_image_path, 0, -1); + gtk_widget_queue_draw(GTK_WIDGET(mitem)); } } } diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -40,14 +40,13 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { g_debug("Service shutdown !"); - // TODO: uncomment for release !! + //TODO: uncomment for release !! close_pulse_activites(); g_main_loop_quit(mainloop); } return; } - /** main: **/ -- cgit v1.2.3 From 0c040b86cd7a05c8284662bb3032dccbf6707e90 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Sep 2010 15:42:54 +0100 Subject: added the image as advised, still no showA --- src/indicator-sound.c | 25 +++++++------------------ src/title-widget.c | 34 +++++++++++++++++++++++++++++----- src/title-widget.h | 6 +++--- 3 files changed, 39 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 0f0c32d..937ed68 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -48,7 +48,7 @@ typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; struct _IndicatorSoundPrivate { GtkWidget* volume_widget; - DbusmenuGtkMenu* menu; + //DbusmenuGtkMenu* menu; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -211,8 +211,8 @@ static GtkMenu * get_menu (IndicatorObject * io) { DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - priv->menu = menu; + //IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); + //priv->menu = menu; DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); g_object_set_data (G_OBJECT (client), "indicator", io); @@ -223,7 +223,7 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget); // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io); - priv->menu = menu; + //priv->menu = menu; return GTK_MENU(menu); } @@ -279,27 +279,16 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { - g_debug("indicator-sound: new_title_widget"); - + g_debug("indicator-sound: new_title_widget"); g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + g_debug ("%s (\"%s\")", __func__, dbusmenu_menuitem_property_get(newitem, DBUSMENU_TITLE_MENUITEM_NAME)); + GtkWidget* title = NULL; - IndicatorObject *io = NULL; title = title_widget_new (newitem); GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title); - - io = g_object_get_data (G_OBJECT (client), "indicator"); - IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - - GtkWidget* image_item = gtk_image_menu_item_new(); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(image_item), - title_widget_get_player_icon(TITLE_WIDGET(title))); - - gtk_widget_show_all(image_item); - - gtk_menu_append(priv->menu, image_item); gtk_widget_show_all(title); diff --git a/src/title-widget.c b/src/title-widget.c index 8f0c3c5..0a59cca 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -58,7 +58,7 @@ static void title_widget_set_twin_item( TitleWidget* self, DbusmenuMenuitem* twin_item); static void title_widget_style_name_text(TitleWidget* self); -G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM); +G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_IMAGE_MENU_ITEM); @@ -87,8 +87,31 @@ title_widget_init (TitleWidget *self) hbox = gtk_hbox_new(FALSE, 0); priv->hbox = hbox; - priv->player_icon = indicator_image_helper("sound_icon"); + // Add image to the 'gutter' + gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); + + gint padding = 4; + gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL); + + gint width, height; + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + + //priv->player_icon = indicator_image_helper("sound_icon"); + GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); + + gtk_widget_set_size_request(icon, width + + 5 /* ref triangle is 5x9 pixels */ + + 2 /* padding */, + height); + gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), icon); + gtk_widget_show(icon); + + GtkImageType type = gtk_image_get_storage_type(GTK_IMAGE(icon)); + g_debug("gtk_image_storage_type = %i", type); + + //gtk_container_add(GTK_CONTAINER(gmi), priv->hbox); //gtk_box_pack_start(GTK_BOX (priv->hbox), priv->image_item, FALSE, FALSE, 0); } @@ -143,15 +166,16 @@ title_widget_set_twin_item(TitleWidget* self, priv->twin_item = twin_item; g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); + // Add the application name priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_TITLE_MENUITEM_NAME)); - gtk_misc_set_padding(GTK_MISC(priv->name), 10, 0); + gtk_misc_set_padding(GTK_MISC(priv->name), 0, 0); gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0); title_widget_style_name_text(self); - gtk_widget_show_all (priv->hbox); - gtk_container_add (GTK_CONTAINER (self), priv->hbox); + gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET(priv->hbox)); + gtk_widget_show_all (priv->hbox); } static void diff --git a/src/title-widget.h b/src/title-widget.h index 827a8f3..3e3ada8 100644 --- a/src/title-widget.h +++ b/src/title-widget.h @@ -19,7 +19,7 @@ with this program. If not, see . #ifndef __TITLE_WIDGET_H__ #define __TITLE_WIDGET_H__ -#include +#include #include G_BEGIN_DECLS @@ -35,11 +35,11 @@ typedef struct _TitleWidget TitleWidget; typedef struct _TitleWidgetClass TitleWidgetClass; struct _TitleWidgetClass { - GtkMenuItemClass parent_class; + GtkImageMenuItemClass parent_class; }; struct _TitleWidget { - GtkMenuItem parent; + GtkImageMenuItem parent; }; GType title_widget_get_type (void); -- cgit v1.2.3 From 966137c8c0547f1c749fa7b13955c6f536539129 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Sep 2010 16:31:30 +0100 Subject: tidy up --- src/title-widget.c | 15 +++------------ src/title-widget.h | 2 +- 2 files changed, 4 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index 0a59cca..04471c0 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -34,7 +34,6 @@ struct _TitleWidgetPrivate { GtkWidget* hbox; GtkWidget* name; - GtkWidget* player_icon; GtkWidget* image_item; DbusmenuMenuitem* twin_item; }; @@ -88,7 +87,7 @@ title_widget_init (TitleWidget *self) hbox = gtk_hbox_new(FALSE, 0); priv->hbox = hbox; - // Add image to the 'gutter' + // Add image to the 'gutter' gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); gint padding = 4; @@ -97,7 +96,6 @@ title_widget_init (TitleWidget *self) gint width, height; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); - //priv->player_icon = indicator_image_helper("sound_icon"); GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); gtk_widget_set_size_request(icon, width @@ -107,12 +105,11 @@ title_widget_init (TitleWidget *self) gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), icon); gtk_widget_show(icon); - + gtk_widget_show(GTK_WIDGET(self)); + GtkImageType type = gtk_image_get_storage_type(GTK_IMAGE(icon)); g_debug("gtk_image_storage_type = %i", type); - //gtk_container_add(GTK_CONTAINER(gmi), priv->hbox); - //gtk_box_pack_start(GTK_BOX (priv->hbox), priv->image_item, FALSE, FALSE, 0); } static void @@ -190,12 +187,6 @@ title_widget_style_name_text(TitleWidget* self) g_free(markup); } -GtkWidget* title_widget_get_player_icon(TitleWidget* self) -{ - TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); - return priv->player_icon; -} - /** * transport_new: * @returns: a new #TitleWidget. diff --git a/src/title-widget.h b/src/title-widget.h index 3e3ada8..574a2b1 100644 --- a/src/title-widget.h +++ b/src/title-widget.h @@ -44,7 +44,7 @@ struct _TitleWidget { GType title_widget_get_type (void); GtkWidget* title_widget_new(DbusmenuMenuitem *twin_item); -GtkWidget* title_widget_get_player_icon(TitleWidget* self); + G_END_DECLS #endif -- cgit v1.2.3 From 0125f59bd6229cc8c98314b86795814ca5df6c42 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Sep 2010 18:04:41 +0100 Subject: active triangle now in place --- src/common-defs.h | 1 + src/player-controller.vala | 4 ++++ src/title-menu-item.vala | 7 +++++- src/title-widget.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 67 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index e554c11..e268aaa 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -41,6 +41,7 @@ with this program. If not, see . #define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-type" #define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name" +#define DBUSMENU_TITLE_MENUITEM_RUNNING "x-canonical-sound-menu-player-title-running" #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-type" #define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-mpris:length" diff --git a/src/player-controller.vala b/src/player-controller.vala index 4d9f054..2ea9331 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -116,6 +116,8 @@ public class PlayerController : GLib.Object update_state(PlayerController.state.OFFLINE); this.custom_items[widget_order.TRANSPORT].reset(TransportMenuitem.attributes_format()); this.custom_items[widget_order.METADATA].reset(MetadataMenuitem.attributes_format()); + TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; + title.toggle_active_triangle(false); } public void update_layout() @@ -172,6 +174,8 @@ public class PlayerController : GLib.Object { if(this.mpris_bridge.connected() == true){ this.update_state(state.CONNECTED); + TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; + title.toggle_active_triangle(true); } else{ this.update_state(state.DISCONNECTED); diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index ec1cc62..bb3d103 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -27,6 +27,7 @@ public class TitleMenuitem : PlayerItem { Object(item_type: MENUITEM_TYPE, owner: parent); this.property_set(MENUITEM_NAME, parent.name); + this.property_set_bool(MENUITEM_RUNNING, false); } public override void handle_event(string name, GLib.Value input_value, uint timestamp) @@ -39,7 +40,11 @@ public class TitleMenuitem : PlayerItem this.owner.mpris_bridge.expose(); } } - + + public void toggle_active_triangle(bool update) + { + this.property_set_bool(MENUITEM_RUNNING, update); + } public static HashSet attributes_format() { diff --git a/src/title-widget.c b/src/title-widget.c index 04471c0..4b77cb2 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -57,6 +57,10 @@ static void title_widget_set_twin_item( TitleWidget* self, DbusmenuMenuitem* twin_item); static void title_widget_style_name_text(TitleWidget* self); +static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, + GdkEventExpose *event, + gpointer data); + G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_IMAGE_MENU_ITEM); @@ -104,9 +108,9 @@ title_widget_init (TitleWidget *self) height); gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), icon); - gtk_widget_show(icon); - gtk_widget_show(GTK_WIDGET(self)); + gtk_widget_show_all(icon); + // DEBUG GtkImageType type = gtk_image_get_storage_type(GTK_IMAGE(icon)); g_debug("gtk_image_storage_type = %i", type); @@ -163,6 +167,9 @@ title_widget_set_twin_item(TitleWidget* self, priv->twin_item = twin_item; g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); + g_signal_connect_after(G_OBJECT (self), + "expose_event", G_CALLBACK (title_widget_triangle_draw_cb), twin_item); + // Add the application name priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, DBUSMENU_TITLE_MENUITEM_NAME)); @@ -187,6 +194,53 @@ title_widget_style_name_text(TitleWidget* self) g_free(markup); } +static gboolean +title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GtkStyle *style; + cairo_t *cr; + int x, y, arrow_width, arrow_height; + + if (!GTK_IS_WIDGET (widget)) return FALSE; + if (!DBUSMENU_IS_MENUITEM (data)) return FALSE; + + /* render the triangle indicator only if the application is running */ + if (! dbusmenu_menuitem_property_get_bool (DBUSMENU_MENUITEM(data), + DBUSMENU_TITLE_MENUITEM_RUNNING)){ + return FALSE; + } + + /* get style */ + style = gtk_widget_get_style (widget); + + /* set arrow position / dimensions */ + arrow_width = 5; /* the pixel-based reference triangle is 5x9 */ + arrow_height = 9; + x = widget->allocation.x; + y = widget->allocation.y + widget->allocation.height/2.0 - (double)arrow_height/2.0; + + /* initialize cairo drawing area */ + cr = (cairo_t*) gdk_cairo_create (widget->window); + + /* set line width */ + cairo_set_line_width (cr, 1.0); + + /* cairo drawing code */ + cairo_move_to (cr, x, y); + cairo_line_to (cr, x, y + arrow_height); + cairo_line_to (cr, x + arrow_width, y + (double)arrow_height/2.0); + cairo_close_path (cr); + cairo_set_source_rgb (cr, style->fg[gtk_widget_get_state(widget)].red/65535.0, + style->fg[gtk_widget_get_state(widget)].green/65535.0, + style->fg[gtk_widget_get_state(widget)].blue/65535.0); + cairo_fill (cr); + + /* remember to destroy cairo context to avoid leaks */ + cairo_destroy (cr); + + return FALSE; +} + /** * transport_new: * @returns: a new #TitleWidget. -- cgit v1.2.3 From 0d231118f14f622ca025ac29db0b2cd0eeaec004 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 2 Sep 2010 23:21:00 +0100 Subject: tidied the transport backend --- src/mpris2-controller.vala | 22 +++++++++++----------- src/player-controller.vala | 2 ++ src/transport-menu-item.vala | 11 +++++++++-- 3 files changed, 22 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index dd6a312..41c8ca8 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -105,7 +105,7 @@ public class Mpris2Controller : GLib.Object if(play_v != null){ string state = play_v.get_string(); debug("new playback state = %s", state); - int p = this.determine_play_state(state); + TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); } @@ -143,29 +143,29 @@ public class Mpris2Controller : GLib.Object } - private int determine_play_state(string status){ + private TransportMenuitem.state determine_play_state(string status){ if(status == null) - return 1; + return TransportMenuitem.state.PAUSED; if(status != null && status == "Playing"){ debug("determine play state - state = %s", status); - return 0; + return TransportMenuitem.state.PLAYING; } - return 1; + return TransportMenuitem.state.PAUSED; } public void initial_update() { - int32 status; + TransportMenuitem.state update; if(this.player.PlaybackStatus == null){ - status = 1; + update = TransportMenuitem.state.PAUSED; } else{ - status = determine_play_state(this.player.PlaybackStatus); + update = determine_play_state(this.player.PlaybackStatus); } - debug("initial update - play state %i", status); + debug("initial update - play state %i", (int)update); - (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(status); + (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(update); GLib.HashTable cleaned_metadata = this.clean_metadata(); this.owner.custom_items[PlayerController.widget_order.METADATA].update(cleaned_metadata, MetadataMenuitem.attributes_format()); @@ -260,7 +260,7 @@ public class Mpris2Controller : GLib.Object this.mpris2_root.Raise(); } catch(DBus.Error e){ - error("Exception thrown while calling root function Raise - %s", e.message); + error("Exception thrown while calling function Raise - %s", e.message); } } } diff --git a/src/player-controller.vala b/src/player-controller.vala index 2ea9331..f5ec205 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -176,6 +176,8 @@ public class PlayerController : GLib.Object this.update_state(state.CONNECTED); TitleMenuitem title = this.custom_items[widget_order.TITLE] as TitleMenuitem; title.toggle_active_triangle(true); + TransportMenuitem transport = this.custom_items[widget_order.TRANSPORT] as TransportMenuitem; + transport.change_play_state(TransportMenuitem.state.PAUSED); } else{ this.update_state(state.DISCONNECTED); diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 8bdd2c8..7faadb5 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -28,6 +28,11 @@ public class TransportMenuitem : PlayerItem PLAY_PAUSE, NEXT } + + public enum state{ + PLAYING, + PAUSED + } public TransportMenuitem(PlayerController parent) { @@ -35,9 +40,9 @@ public class TransportMenuitem : PlayerItem this.property_set_int(MENUITEM_PLAY_STATE, 1); } - public void change_play_state(int state) + public void change_play_state(state update) { - this.property_set_int(MENUITEM_PLAY_STATE, state); + this.property_set_int(MENUITEM_PLAY_STATE, update); } public override void handle_event(string name, GLib.Value input_value, uint timestamp) @@ -54,4 +59,6 @@ public class TransportMenuitem : PlayerItem attrs.add(MENUITEM_PLAY_STATE); return attrs; } + + } \ No newline at end of file -- cgit v1.2.3 From 779bb004a88acc14c7a505e531731e7d89d65eeb Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Sep 2010 14:06:00 +0100 Subject: reworked album art handling using gio exclusively with mkstemp --- src/common-defs.h | 1 - src/metadata-menu-item.vala | 2 +- src/metadata-widget.c | 15 ++++------- src/player-item.vala | 62 +++++++++++++++++++++++++++------------------ 4 files changed, 44 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index fc4e323..e554c11 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -25,7 +25,6 @@ with this program. If not, see . #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" #define DBUSMENU_PROPERTY_EMPTY -1 -#define DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH "/tmp/indicator-sound-downloaded-album-art" /* DBUS Custom Items */ #define DBUSMENU_VOLUME_MENUITEM_TYPE "x-canonical-ido-volume-type" diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 04284d4..6e7230b 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -38,5 +38,5 @@ public class MetadataMenuitem : PlayerItem attrs.add(MENUITEM_ARTURL); return attrs; } - + } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 3e01aec..a88d38c 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -36,7 +36,6 @@ struct _MetadataWidgetPrivate GtkWidget* album_art; GString* image_path; GString* old_image_path; - GString* remote_image_path; GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; @@ -105,7 +104,6 @@ metadata_widget_init (MetadataWidget *self) priv->album_art = gtk_image_new(); priv->image_path = g_string_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL)); priv->old_image_path = g_string_new(""); - priv->remote_image_path = g_string_new(DBUSMENU_PLAYER_ITEM_REMOTE_FILEPATH); g_debug("Metadata::At startup and image path = %s", priv->image_path->str); g_signal_connect(priv->album_art, "expose-event", @@ -190,9 +188,7 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); g_debug("expose"); if(priv->image_path->len > 0){ - if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || - (g_string_equal(priv->image_path, priv->remote_image_path) == TRUE && - g_string_equal(priv->old_image_path, priv->remote_image_path) == FALSE)){ + if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ g_debug("and we are in"); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); @@ -328,11 +324,10 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, } else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){ g_string_erase(priv->image_path, 0, -1); - g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); - // Basically force expose the reload the image because we have an image update - // but we are using remote images i.e. the same file path but different images - if(g_string_equal(priv->image_path, priv->remote_image_path) == TRUE){ - g_string_erase(priv->old_image_path, 0, -1); + g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); + // if its a remote image queue a redraw incase the download took too long + if (g_str_has_prefix(g_value_get_string (value), get_user_special_dir(GUserDirectory.PICTURES))){ + g_debug("the image update is a download so redraw"); gtk_widget_queue_draw(GTK_WIDGET(mitem)); } } diff --git a/src/player-item.vala b/src/player-item.vala index 1e16742..83b19d6 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -20,7 +20,6 @@ with this program. If not, see . using Dbusmenu; using Gee; using Gdk; -using DbusmenuPlayer; public class PlayerItem : Dbusmenu.Menuitem { @@ -28,6 +27,7 @@ public class PlayerItem : Dbusmenu.Menuitem public string item_type { get; construct; } private const int EMPTY = -1; private FetchFile fetcher; + private string previous_temp_album_art_path; public PlayerItem(string type) { @@ -36,6 +36,7 @@ public class PlayerItem : Dbusmenu.Menuitem construct { this.property_set(MENUITEM_PROP_TYPE, item_type); + this.previous_temp_album_art_path = null; } public void reset(HashSet attrs){ @@ -45,6 +46,12 @@ public class PlayerItem : Dbusmenu.Menuitem } } + /** + * update() + * Base update method for playeritems, takes the attributes and the incoming updates + * and attmepts to update the appropriate props on the object. + * Album art is handled separately to deal with remote and local file paths. + */ public void update(HashTable data, HashSet attributes) { debug("PlayerItem::update()"); @@ -62,25 +69,11 @@ public class PlayerItem : Dbusmenu.Menuitem if (v.holds (typeof (string))){ string update = v.get_string().strip(); debug("with value : %s", update); - // Special case for the arturl URI's. if(property.contains("mpris:artUrl")){ - if(update.has_prefix("http://")){ - // This is asyncronous so handle it offline - this.fetch_remote_art(update.strip(), property); + this.fetch_art(update.strip(), property); continue; - } - else{ - // The file is local, just parse the string - try{ - update = Filename.from_uri(update.strip()); - } - catch(ConvertError e){ - warning("Problem converting URI %s to file path", - update); - } - } } - this.property_set(property, update); + this.property_set(property, update); } else if (v.holds (typeof (int))){ debug("with value : %i", v.get_int()); @@ -95,7 +88,6 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_bool(property, v.get_boolean()); } } - if(this.property_get_bool(MENUITEM_PROP_VISIBLE) == false){ this.property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -114,14 +106,29 @@ public class PlayerItem : Dbusmenu.Menuitem return false; } - public void fetch_remote_art(string uri, string prop) - { + public void fetch_art(string uri, string prop) + { + File art_file = File.new_for_uri(uri); + if(art_file.is_native() == true){ + string path; + try{ + path = Filename.from_uri(uri.strip()); + this.property_set(prop, path); + } + catch(ConvertError e){ + warning("Problem converting URI %s to file path", + uri); + } + // eitherway return, the artwork was local + return; + } + // otherwise go remote this.fetcher = new FetchFile (uri, prop); this.fetcher.failed.connect (() => { this.on_fetcher_failed ();}); this.fetcher.completed.connect (this.on_fetcher_completed); this.fetcher.fetch_data (); } - + private void on_fetcher_failed () { warning("on_fetcher_failed -> could not fetch artwork"); @@ -134,13 +141,20 @@ public class PlayerItem : Dbusmenu.Menuitem loader.write (update.data, update.len); loader.close (); Pixbuf icon = loader.get_pixbuf (); - icon.save (ITEM_REMOTE_FILEPATH, loader.get_format().get_name()); - this.property_set(property, ITEM_REMOTE_FILEPATH); + string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat("/indicator-sound-XXXXXX"); + int r = FileUtils.mkstemp(path); + icon.save (path, loader.get_format().get_name()); + if(this.previous_temp_album_art_path != null){ + FileUtils.remove(this.previous_temp_album_art_path); + } + this.previous_temp_album_art_path = path; + this.property_set(property, path); } catch(GLib.Error e){ - warning("Problem fetching file from the interweb - error: %s", + warning("Problem creating file from bytearray fetched from the interweb - error: %s", e.message); } } + } -- cgit v1.2.3 From eeefcb48bf469a2268601978353790f4e449db5f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Sep 2010 15:24:46 +0100 Subject: working nicely --- src/metadata-widget.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index a88d38c..1d50779 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -25,6 +25,7 @@ with this program. If not, see . #include "metadata-widget.h" #include "common-defs.h" #include +#include static DbusmenuMenuitem* twin_item; @@ -326,7 +327,7 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, g_string_erase(priv->image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); // if its a remote image queue a redraw incase the download took too long - if (g_str_has_prefix(g_value_get_string (value), get_user_special_dir(GUserDirectory.PICTURES))){ + if (g_str_has_prefix(g_value_get_string (value), g_get_user_special_dir(G_USER_DIRECTORY_PICTURES))){ g_debug("the image update is a download so redraw"); gtk_widget_queue_draw(GTK_WIDGET(mitem)); } -- cgit v1.2.3 From de523f44dbe55351c8fb8375823fe872a7d362e1 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 3 Sep 2010 20:05:42 +0100 Subject: big refactor --- src/metadata-menu-item.vala | 132 +++++++++++++++++++++++++++++++++++++++++++- src/metadata-widget.c | 2 - src/player-item.vala | 61 ++------------------ src/sound-service.c | 4 +- 4 files changed, 137 insertions(+), 62 deletions(-) (limited to 'src') diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 6e7230b..941fafd 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -19,15 +19,144 @@ with this program. If not, see . using Gee; using DbusmenuMetadata; +using Gdk; public class MetadataMenuitem : PlayerItem { + public const string ALBUM_ART_DIR_SUFFIX = "/sound-menu-album-art"; + public static string album_art_cache_dir; + private static FetchFile fetcher; + private string previous_temp_album_art_path; + public MetadataMenuitem() { Object(item_type: MENUITEM_TYPE); reset(attributes_format()); } + + construct{ + MetadataMenuitem.clean_album_art_temp_dir(); + this.previous_temp_album_art_path = null; + this.album_art_cache_dir = MetadataMenuitem.create_album_art_temp_dir(); + } + + private static void clean_album_art_temp_dir() + { + string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat(ALBUM_ART_DIR_SUFFIX); + + GLib.File? album_art_dir = GLib.File.new_for_uri(path); + + if(album_art_dir == null || album_art_dir.query_exists(null) == false){ + warning("here %s %s", (album_art_dir.query_exists(null) == false).to_string(), path); + return; + } + + if(delete_album_art_contents(album_art_dir) == true) + { + if(DirUtils.remove(path) == -1){ + warning("could not remove the temp album art directory %s", path); + } + } + } + + private static string? create_album_art_temp_dir() + { + string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat(ALBUM_ART_DIR_SUFFIX); + if(DirUtils.create(path, 0700) == -1){ + warning("could not create a temp dir for remote album art - that means we are not going to bother with remote art"); + return null; + } + return path; + } + + private static bool delete_album_art_contents (GLib.File dir) + { + bool result = true; + try { + var e = dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME + "," + FILE_ATTRIBUTE_STANDARD_TYPE , + FileQueryInfoFlags.NOFOLLOW_SYMLINKS, + null); + while (true) + { + var file = e.next_file (null); + if (file == null) + break; + + var child = dir.get_child (file.get_name ()); + + try { + child.delete (null); + } catch (Error error_) { + warning (@"Unable to delete file '$(child.get_basename ()): $(error_.message)"); + result = false; + } + } + } catch (Error error) { + warning (@"Unable to read files from directory '$(dir.get_basename ())': %s", + error.message); + result = false; + } + return result; + } + + public void fetch_art(string uri, string prop) + { + File art_file = File.new_for_uri(uri); + if(art_file.is_native() == true){ + string path; + try{ + path = Filename.from_uri(uri.strip()); + this.property_set(prop, path); + } + catch(ConvertError e){ + warning("Problem converting URI %s to file path", + uri); + } + // eitherway return, the artwork was local + return; + } + // If we didn't manage to create the temp dir + // don't bother with remote + debug("fetch_art -remotely %s", this.album_art_cache_dir); + + if(this.album_art_cache_dir == null){ + return; + } + // green light to go remote + this.fetcher = new FetchFile (uri, prop); + this.fetcher.failed.connect (() => { this.on_fetcher_failed ();}); + this.fetcher.completed.connect (this.on_fetcher_completed); + this.fetcher.fetch_data (); + } + + private void on_fetcher_failed () + { + warning("on_fetcher_failed -> could not fetch artwork"); + } + private void on_fetcher_completed(ByteArray update, string property) + { + try{ + PixbufLoader loader = new PixbufLoader (); + loader.write (update.data, update.len); + loader.close (); + Pixbuf icon = loader.get_pixbuf (); + string path = this.album_art_cache_dir.concat("/XXXXXX"); + int r = FileUtils.mkstemp(path); + if(r != -1){ + icon.save (path, loader.get_format().get_name()); + this.property_set(property, path); + if(this.previous_temp_album_art_path != null){ + FileUtils.remove(this.previous_temp_album_art_path); + } + this.previous_temp_album_art_path = path; + } + } + catch(GLib.Error e){ + warning("Problem creating file from bytearray fetched from the interweb - error: %s", + e.message); + } + } public static HashSet attributes_format() { @@ -37,6 +166,5 @@ public class MetadataMenuitem : PlayerItem attrs.add(MENUITEM_ALBUM); attrs.add(MENUITEM_ARTURL); return attrs; - } - + } } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 1d50779..dc6aaa6 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -187,10 +187,8 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user g_return_val_if_fail(IS_METADATA_WIDGET(user_data), FALSE); MetadataWidget* widget = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); - g_debug("expose"); if(priv->image_path->len > 0){ if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ - g_debug("and we are in"); GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); g_debug("metadata_load_new_image -> pixbuf from %s", diff --git a/src/player-item.vala b/src/player-item.vala index 83b19d6..68ae6ef 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -19,15 +19,12 @@ with this program. If not, see . using Dbusmenu; using Gee; -using Gdk; public class PlayerItem : Dbusmenu.Menuitem { public PlayerController owner {get; construct;} public string item_type { get; construct; } private const int EMPTY = -1; - private FetchFile fetcher; - private string previous_temp_album_art_path; public PlayerItem(string type) { @@ -36,7 +33,6 @@ public class PlayerItem : Dbusmenu.Menuitem construct { this.property_set(MENUITEM_PROP_TYPE, item_type); - this.previous_temp_album_art_path = null; } public void reset(HashSet attrs){ @@ -69,8 +65,11 @@ public class PlayerItem : Dbusmenu.Menuitem if (v.holds (typeof (string))){ string update = v.get_string().strip(); debug("with value : %s", update); - if(property.contains("mpris:artUrl")){ - this.fetch_art(update.strip(), property); + if(property.contains("mpris:artUrl")){ + // We know its a metadata instance because thats the only + // object with the arturl prop + MetadataMenuitem metadata = this as MetadataMenuitem; + metadata.fetch_art(update.strip(), property); continue; } this.property_set(property, update); @@ -106,55 +105,5 @@ public class PlayerItem : Dbusmenu.Menuitem return false; } - public void fetch_art(string uri, string prop) - { - File art_file = File.new_for_uri(uri); - if(art_file.is_native() == true){ - string path; - try{ - path = Filename.from_uri(uri.strip()); - this.property_set(prop, path); - } - catch(ConvertError e){ - warning("Problem converting URI %s to file path", - uri); - } - // eitherway return, the artwork was local - return; - } - // otherwise go remote - this.fetcher = new FetchFile (uri, prop); - this.fetcher.failed.connect (() => { this.on_fetcher_failed ();}); - this.fetcher.completed.connect (this.on_fetcher_completed); - this.fetcher.fetch_data (); - } - - private void on_fetcher_failed () - { - warning("on_fetcher_failed -> could not fetch artwork"); - } - - private void on_fetcher_completed(ByteArray update, string property) - { - try{ - PixbufLoader loader = new PixbufLoader (); - loader.write (update.data, update.len); - loader.close (); - Pixbuf icon = loader.get_pixbuf (); - string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat("/indicator-sound-XXXXXX"); - int r = FileUtils.mkstemp(path); - icon.save (path, loader.get_format().get_name()); - if(this.previous_temp_album_art_path != null){ - FileUtils.remove(this.previous_temp_album_art_path); - } - this.previous_temp_album_art_path = path; - this.property_set(property, path); - } - catch(GLib.Error e){ - warning("Problem creating file from bytearray fetched from the interweb - error: %s", - e.message); - } - } - } diff --git a/src/sound-service.c b/src/sound-service.c index f19379d..51f5f37 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 0c8770bdf288089fe2e0dce4e3c4b2743bb7a15d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Sep 2010 10:32:30 +0100 Subject: shifted to use the more appropriate cache dir --- src/metadata-menu-item.vala | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 941fafd..4e66bb0 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -23,7 +23,8 @@ using Gdk; public class MetadataMenuitem : PlayerItem { - public const string ALBUM_ART_DIR_SUFFIX = "/sound-menu-album-art"; + public const string ALBUM_ART_DIR_SUFFIX = "/indicators/sound/album-art-cache"; + public static string album_art_cache_dir; private static FetchFile fetcher; private string previous_temp_album_art_path; @@ -42,29 +43,27 @@ public class MetadataMenuitem : PlayerItem private static void clean_album_art_temp_dir() { - string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat(ALBUM_ART_DIR_SUFFIX); + string path = Environment.get_user_cache_dir().dup().concat(ALBUM_ART_DIR_SUFFIX); GLib.File? album_art_dir = GLib.File.new_for_uri(path); - if(album_art_dir == null || album_art_dir.query_exists(null) == false){ + /*if(album_art_dir == null || album_art_dir.query_exists(null) == false){ warning("here %s %s", (album_art_dir.query_exists(null) == false).to_string(), path); return; } + */ - if(delete_album_art_contents(album_art_dir) == true) + if(delete_album_art_contents(album_art_dir) == false) { - if(DirUtils.remove(path) == -1){ - warning("could not remove the temp album art directory %s", path); - } + warning("could not remove the temp album art files %s", path); } } private static string? create_album_art_temp_dir() { - string path = Environment.get_user_special_dir(UserDirectory.PICTURES).dup().concat(ALBUM_ART_DIR_SUFFIX); + string path = Environment.get_user_cache_dir().dup().concat(ALBUM_ART_DIR_SUFFIX); if(DirUtils.create(path, 0700) == -1){ - warning("could not create a temp dir for remote album art - that means we are not going to bother with remote art"); - return null; + warning("could not create a temp dir for remote album art, it must have been created already"); } return path; } @@ -79,7 +78,10 @@ public class MetadataMenuitem : PlayerItem while (true) { var file = e.next_file (null); - if (file == null) + + debug("file name = %s", file.get_name()); + + if (file == null) break; var child = dir.get_child (file.get_name ()); -- cgit v1.2.3 From 0a4c3a239cf405642ad829b6841925140792d33f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Sep 2010 11:49:17 +0100 Subject: scroll fix merged --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 41b5b22e56892b7246f5bcfc270d685f052c0f70 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Sep 2010 13:19:53 +0100 Subject: tried everything, the image will not show on the menu --- src/indicator-sound.c | 4 ---- src/title-widget.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 937ed68..4f954c3 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -48,7 +48,6 @@ typedef struct _IndicatorSoundPrivate IndicatorSoundPrivate; struct _IndicatorSoundPrivate { GtkWidget* volume_widget; - //DbusmenuGtkMenu* menu; }; #define INDICATOR_SOUND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), INDICATOR_SOUND_TYPE, IndicatorSoundPrivate)) @@ -211,8 +210,6 @@ static GtkMenu * get_menu (IndicatorObject * io) { DbusmenuGtkMenu* menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); - //IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - //priv->menu = menu; DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); g_object_set_data (G_OBJECT (client), "indicator", io); @@ -223,7 +220,6 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget); // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io); - //priv->menu = menu; return GTK_MENU(menu); } diff --git a/src/title-widget.c b/src/title-widget.c index 4b77cb2..d34dc7f 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -92,28 +92,54 @@ title_widget_init (TitleWidget *self) priv->hbox = hbox; // Add image to the 'gutter' - gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); - + gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); + gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(self), FALSE); + gint padding = 4; gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL); gint width, height; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); + g_debug("title widget init - height and weight = %i and %i", height, width); + + GtkImage * image = indicator_image_helper("sound_icon"); + GdkPixbuf* buf = gtk_image_get_pixbuf (image); + g_debug("Is it a pixbuf : %i", GDK_IS_PIXBUF(buf)); GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); + + g_debug("title widget init - icon pixel size = %i", gtk_image_get_pixel_size (GTK_IMAGE(icon))); + g_debug("title widget init - image pixel size = %i", gtk_image_get_pixel_size (image)); gtk_widget_set_size_request(icon, width + 5 /* ref triangle is 5x9 pixels */ + 2 /* padding */, height); gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), icon); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(image)); + gtk_widget_show_all(icon); + GtkWidget* returned_image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(self)); + g_debug("returned image is not null %i", GTK_IS_IMAGE(returned_image)); // DEBUG - GtkImageType type = gtk_image_get_storage_type(GTK_IMAGE(icon)); - g_debug("gtk_image_storage_type = %i", type); + GtkImageType type; + type = gtk_image_get_storage_type(GTK_IMAGE(icon)); + g_debug("gtk_image_storage_type on widget = %i", type); + type = gtk_image_get_storage_type(image); + g_debug("gtk_image_storage_type on image = %i", type); + + gboolean* use_stock; + use_stock = g_new0(gboolean, 1); + gboolean* show_image; + show_image = g_new0(gboolean, 1); + + g_object_get(GTK_WIDGET(self), "use-stock", use_stock, NULL ); + g_object_get(GTK_WIDGET(self), "always-show-image", show_image, NULL); + g_debug("title widget init : use-stock = %i and show image = %i", *use_stock, *show_image); + g_free(use_stock); + g_free(show_image); } static void -- cgit v1.2.3 From 2cd77a2b3065b638bc9f02239700a989e02a1142 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Sep 2010 18:07:15 +0100 Subject: album art rounded fixed --- src/indicator-sound.c | 2 -- src/metadata-widget.c | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index a454600..b59eb98 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -495,7 +495,6 @@ start_animation() { blocked_iter = blocked_animation_list; blocked_id = 0; - //g_debug("exit from blocked hold start the animation\n"); animation_id = g_timeout_add(50, fade_back_to_mute_image, NULL); return FALSE; } @@ -504,7 +503,6 @@ static gboolean fade_back_to_mute_image() { if (blocked_iter != NULL) { - g_debug("in animation 'loop'\n"); gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); blocked_iter = blocked_iter->next; return TRUE; diff --git a/src/metadata-widget.c b/src/metadata-widget.c index f600238..740ad6d 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -160,7 +160,7 @@ metadata_widget_init (MetadataWidget *self) g_signal_connect(self, "style-set", G_CALLBACK(metadata_widget_set_style), GTK_WIDGET(self)); - gtk_widget_set_size_request(GTK_WIDGET(self), 200, 60); + gtk_widget_set_size_request(GTK_WIDGET(self), 200, 65); gtk_container_add (GTK_CONTAINER (self), hbox); } @@ -348,10 +348,9 @@ rounded_rectangle (cairo_t *cr, { gdouble radius; gdouble degrees; - + radius = corner_radius / aspect; degrees = G_PI / 180.0; - cairo_new_sub_path (cr); cairo_arc (cr, x + width - radius, @@ -377,6 +376,7 @@ rounded_rectangle (cairo_t *cr, radius, 180 * degrees, 270 * degrees); + cairo_close_path (cr); } @@ -401,12 +401,12 @@ image_set_from_pixbuf (GtkWidget *widget, MetadataWidgetPrivate* priv = METADATA_WIDGET_GET_PRIVATE(metadata); GtkImage* image = GTK_IMAGE(priv->album_art); - frame_width = 5; + frame_width = 3; w = gdk_pixbuf_get_width (source) + frame_width * 2; h = gdk_pixbuf_get_height (source) + frame_width * 2; - radius = w / 10; + radius = 10; pixmap = gdk_pixmap_new (gtk_widget_get_window (widget), w, h, -1); bitmask = gdk_pixmap_new (gtk_widget_get_window (widget), w, h, 1); -- cgit v1.2.3 From 066b6a521cbda456ffb8f25ff01e1dd7d127fdd2 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Sep 2010 19:30:48 +0100 Subject: events from transport bar now are sent on button release --- src/play-button.c | 12 ++++++++---- src/play-button.h | 4 ++-- src/sound-service.c | 4 ++-- src/transport-widget.c | 24 ++++++++++++------------ 4 files changed, 24 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index a2eaf2e..0c2a59a 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -409,11 +409,12 @@ play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent command) g_return_if_fail(IS_PLAY_BUTTON(button)); PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); priv->current_command = command; - + cairo_t *cr; cr = gdk_cairo_create (button->window); - GList* list = g_hash_table_lookup(priv->command_coordinates, GINT_TO_POINTER(command)); + GList* list = g_hash_table_lookup(priv->command_coordinates, + GINT_TO_POINTER(priv->current_command)); cairo_rectangle(cr, GPOINTER_TO_INT(g_list_nth_data(list, 0)), GPOINTER_TO_INT(g_list_nth_data(list, 1)), @@ -426,10 +427,12 @@ play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent command) void -play_button_react_to_button_release(GtkWidget* button) +play_button_react_to_button_release(GtkWidget* button, PlayButtonEvent command) { g_return_if_fail(IS_PLAY_BUTTON(button)); PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); + priv->current_command = command; + cairo_t *cr; cr = gdk_cairo_create (button->window); @@ -437,7 +440,7 @@ play_button_react_to_button_release(GtkWidget* button) GINT_TO_POINTER(priv->current_command)); priv->current_command = TRANSPORT_NADA; - + cairo_rectangle(cr, GPOINTER_TO_INT(g_list_nth_data(list, 0)), GPOINTER_TO_INT(g_list_nth_data(list, 1)), @@ -456,6 +459,7 @@ play_button_toggle_play_pause(GtkWidget* button, PlayButtonState update) PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); priv->current_state = update; g_debug("PlayButton::toggle play state : %i", priv->current_state); + gtk_widget_queue_draw (GTK_WIDGET(button)); } diff --git a/src/play-button.h b/src/play-button.h index 727a489..6bacac7 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -56,8 +56,8 @@ struct _PlayButton { GType play_button_get_type (void); void play_button_set_style(GtkWidget* button, GtkStyle* style); PlayButtonEvent determine_button_event(GtkWidget* button, GdkEventButton* event); -void play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent command); -void play_button_react_to_button_release(GtkWidget* button); +void play_button_react_to_button_press(GtkWidget* button, PlayButtonEvent command); +void play_button_react_to_button_release(GtkWidget* button, PlayButtonEvent command); void play_button_toggle_play_pause(GtkWidget* button, PlayButtonState update); GtkWidget* play_button_new(); diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..42ce116 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index 702b472..4e7ea9c 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -136,22 +136,12 @@ transport_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { g_return_val_if_fail(IS_TRANSPORT_WIDGET(menuitem), FALSE); - TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - - GtkWidget *parent; - - parent = gtk_widget_get_parent (GTK_WIDGET (menuitem)); - + PlayButtonEvent result = determine_button_event(priv->play_button, event); if(result != TRANSPORT_NADA){ - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); - g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); - g_value_set_int(&value, (int)result); play_button_react_to_button_press(priv->play_button, result); - dbusmenu_menuitem_handle_event (priv->twin_item, "Transport state change", &value, 0); } return TRUE; } @@ -164,8 +154,17 @@ transport_widget_button_release_event (GtkWidget *menuitem, g_debug("TransportWidget::menu_release_event"); g_return_val_if_fail(IS_TRANSPORT_WIDGET(menuitem), FALSE); TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - play_button_react_to_button_release(priv->play_button); + PlayButtonEvent result = determine_button_event(priv->play_button, event); + + if(result != TRANSPORT_NADA){ + GValue value = {0}; + g_value_init(&value, G_TYPE_INT); + g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); + g_value_set_int(&value, (int)result); + play_button_react_to_button_release(priv->play_button, result); + dbusmenu_menuitem_handle_event (priv->twin_item, "Transport state change", &value, 0); + } return TRUE; } @@ -187,6 +186,7 @@ transport_widget_property_update(DbusmenuMenuitem* item, gchar* property, int update_value = g_value_get_int(value); g_debug("transport_widget_update_state - with value %i", update_value); play_button_toggle_play_pause(priv->play_button, (PlayButtonState)update_value); + } } -- cgit v1.2.3 From 03142793ea7975e1e915cad125d19c37de508b27 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 6 Sep 2010 21:14:15 +0100 Subject: highlighted odd playback status issue --- src/mpris2-controller.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index dd6a312..cf5a39e 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -96,7 +96,7 @@ public class Mpris2Controller : GLib.Object public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) { - debug("properties-changed for interface %s", interface_source); + debug("properties-changed for interface %s and owner %s", interface_source, this.owner.name.down()); if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false){ warning("Property-changed hash is null or this is an interface that concerns us"); return; -- cgit v1.2.3 From 71f036ce6cbd106f3754d7008303d1b108433ae2 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 09:21:07 +0100 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 32442108b50ade909fa9076513139d73cde577a1 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 10:04:07 +0100 Subject: button release outside of control now acts as it should do --- src/play-button.c | 9 ++++++++- src/sound-service.c | 4 ++-- src/transport-widget.c | 5 +++-- 3 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 0c2a59a..84af260 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -431,7 +431,14 @@ play_button_react_to_button_release(GtkWidget* button, PlayButtonEvent command) { g_return_if_fail(IS_PLAY_BUTTON(button)); PlayButtonPrivate* priv = PLAY_BUTTON_GET_PRIVATE(button); - priv->current_command = command; + if(priv->current_command == TRANSPORT_NADA){ + g_debug("returning from the playbutton release because my previous command was nada"); + return; + } + else if(priv->current_command != TRANSPORT_NADA && + command != TRANSPORT_NADA){ + priv->current_command = command; + } cairo_t *cr; diff --git a/src/sound-service.c b/src/sound-service.c index 12f067e..42ce116 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } diff --git a/src/transport-widget.c b/src/transport-widget.c index 4e7ea9c..979f6fd 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -162,9 +162,10 @@ transport_widget_button_release_event (GtkWidget *menuitem, g_value_init(&value, G_TYPE_INT); g_debug("TransportWidget::menu_press_event - going to send value %i", (int)result); g_value_set_int(&value, (int)result); - play_button_react_to_button_release(priv->play_button, result); dbusmenu_menuitem_handle_event (priv->twin_item, "Transport state change", &value, 0); - } + } + play_button_react_to_button_release(priv->play_button, result); + return TRUE; } -- cgit v1.2.3 From 6f82956f269c047fe0b94a188c18ceed50bc74ea Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 10:52:23 +0100 Subject: tidy up --- src/play-button.c | 1 - src/sound-service.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index 84af260..ccc23cb 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -966,7 +966,6 @@ draw (GtkWidget* button, cairo_t *cr) } - /** * play_button_new: * @returns: a new #PlayButton. diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 5abb5a08c0d6282c5ef3569c8a561db15f88473f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 15:12:08 +0100 Subject: allow multiple players on the menu --- src/familiar-players-db.vala | 2 +- src/music-player-bridge.vala | 40 ++++++++++++++++++---------------------- 2 files changed, 19 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/familiar-players-db.vala b/src/familiar-players-db.vala index 2bc0a3c..894447c 100644 --- a/src/familiar-players-db.vala +++ b/src/familiar-players-db.vala @@ -83,7 +83,7 @@ public class FamiliarPlayersDB : GLib.Object private bool load_data_from_key_file(){ try{ string[] desktops = this.key_file.get_string_list(GROUP_NAME, - KEY_NAME); + KEY_NAME); foreach(string s in desktops){ this.players_DB.set(s, true); } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index daad42f..c677d15 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -44,30 +44,26 @@ public class MusicPlayerBridge : GLib.Object } private void try_to_add_inactive_familiar_clients(){ - // TODO handle multple players - just working with one right now - int count = 0; foreach(string app in this.playersDB.records()){ - if(count == 0){ - if(app == null){ - warning("App string in keyfile is null therefore moving on to next player"); - continue; - } - DesktopAppInfo info = new DesktopAppInfo.from_filename(app); - if(info == null){ - warning("Could not create a desktopappinfo instance from app: %s", app); - continue; - } - GLib.AppInfo app_info = info as GLib.AppInfo; - PlayerController ctrl = new PlayerController(this.root_menu, - app_info.get_name(), - calculate_menu_position(), - PlayerController.state.OFFLINE); - ctrl.set("app_info", app_info); - this.registered_clients.set(app_info.get_name().down().strip(), ctrl); - debug("Created a player controller for %s which was found in the cache file", app_info.get_name().down().strip()); - count += 1; + if(app == null){ + warning("App string in keyfile is null therefore moving on to next player"); + continue; + } + + debug("attempting to make an app info from %s", app); + + DesktopAppInfo info = new DesktopAppInfo.from_filename(app); + if(info == null){ + warning("Could not create a desktopappinfo instance from app: %s", app); + continue; } - break; + GLib.AppInfo app_info = info as GLib.AppInfo; + PlayerController ctrl = new PlayerController(this.root_menu, + app_info.get_name(), + calculate_menu_position(), + PlayerController.state.OFFLINE); + ctrl.set("app_info", app_info); + this.registered_clients.set(app_info.get_name().down().strip(), ctrl); } } -- cgit v1.2.3 From b69ebdb28bb8b2d508c5788977d3c49f1d2fd28a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 15:34:18 +0100 Subject: tidy up on the print outs --- src/metadata-menu-item.vala | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 4e66bb0..581fa10 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -46,12 +46,6 @@ public class MetadataMenuitem : PlayerItem string path = Environment.get_user_cache_dir().dup().concat(ALBUM_ART_DIR_SUFFIX); GLib.File? album_art_dir = GLib.File.new_for_uri(path); - - /*if(album_art_dir == null || album_art_dir.query_exists(null) == false){ - warning("here %s %s", (album_art_dir.query_exists(null) == false).to_string(), path); - return; - } - */ if(delete_album_art_contents(album_art_dir) == false) { @@ -72,7 +66,7 @@ public class MetadataMenuitem : PlayerItem { bool result = true; try { - var e = dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME + "," + FILE_ATTRIBUTE_STANDARD_TYPE , + var e = dir.enumerate_children (FILE_ATTRIBUTE_STANDARD_NAME, FileQueryInfoFlags.NOFOLLOW_SYMLINKS, null); while (true) @@ -117,10 +111,9 @@ public class MetadataMenuitem : PlayerItem // eitherway return, the artwork was local return; } - // If we didn't manage to create the temp dir - // don't bother with remote debug("fetch_art -remotely %s", this.album_art_cache_dir); - + // If we didn't manage to create the temp dir + // don't bother with remote if(this.album_art_cache_dir == null){ return; } -- cgit v1.2.3 From cfd5b54dfa45a7d469059b93e0201401c5017ece Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 16:10:41 +0100 Subject: remote art url fixed --- src/metadata-menu-item.vala | 8 ++++---- src/metadata-widget.c | 2 +- src/sound-service.c | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 581fa10..cd50129 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -23,7 +23,7 @@ using Gdk; public class MetadataMenuitem : PlayerItem { - public const string ALBUM_ART_DIR_SUFFIX = "/indicators/sound/album-art-cache"; + public const string ALBUM_ART_DIR_SUFFIX = "indicators/sound/album-art-cache"; public static string album_art_cache_dir; private static FetchFile fetcher; @@ -43,9 +43,9 @@ public class MetadataMenuitem : PlayerItem private static void clean_album_art_temp_dir() { - string path = Environment.get_user_cache_dir().dup().concat(ALBUM_ART_DIR_SUFFIX); + string path = GLib.Path.build_filename(Environment.get_user_cache_dir(), ALBUM_ART_DIR_SUFFIX); - GLib.File? album_art_dir = GLib.File.new_for_uri(path); + GLib.File? album_art_dir = GLib.File.new_for_path(path); if(delete_album_art_contents(album_art_dir) == false) { @@ -55,7 +55,7 @@ public class MetadataMenuitem : PlayerItem private static string? create_album_art_temp_dir() { - string path = Environment.get_user_cache_dir().dup().concat(ALBUM_ART_DIR_SUFFIX); + string path = GLib.Path.build_filename(Environment.get_user_cache_dir(), ALBUM_ART_DIR_SUFFIX); if(DirUtils.create(path, 0700) == -1){ warning("could not create a temp dir for remote album art, it must have been created already"); } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index dc6aaa6..2bca072 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -325,7 +325,7 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property, g_string_erase(priv->image_path, 0, -1); g_string_overwrite(priv->image_path, 0, g_value_get_string (value)); // if its a remote image queue a redraw incase the download took too long - if (g_str_has_prefix(g_value_get_string (value), g_get_user_special_dir(G_USER_DIRECTORY_PICTURES))){ + if (g_str_has_prefix(g_value_get_string (value), g_get_user_cache_dir())){ g_debug("the image update is a download so redraw"); gtk_widget_queue_draw(GTK_WIDGET(mitem)); } diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From b7c9529e1830961e50ecf664b53b7a64b6643c41 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 16:29:33 +0100 Subject: changed temp name to be more telling of its purpose --- src/metadata-menu-item.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index cd50129..3f71653 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -136,7 +136,7 @@ public class MetadataMenuitem : PlayerItem loader.write (update.data, update.len); loader.close (); Pixbuf icon = loader.get_pixbuf (); - string path = this.album_art_cache_dir.concat("/XXXXXX"); + string path = this.album_art_cache_dir.concat("/downloaded-coverart-XXXXXX"); int r = FileUtils.mkstemp(path); if(r != -1){ icon.save (path, loader.get_format().get_name()); -- cgit v1.2.3 From 3461e88ae36e6237ad20b7e9c8069b364974fdd0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 19:01:38 +0100 Subject: alloc stuff --- src/title-widget.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index d34dc7f..0315a8e 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -110,13 +110,14 @@ title_widget_init (TitleWidget *self) g_debug("title widget init - icon pixel size = %i", gtk_image_get_pixel_size (GTK_IMAGE(icon))); g_debug("title widget init - image pixel size = %i", gtk_image_get_pixel_size (image)); - + gtk_widget_set_size_request(icon, width + 5 /* ref triangle is 5x9 pixels */ + 2 /* padding */, height); gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(image)); + + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); gtk_widget_show_all(icon); GtkWidget* returned_image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(self)); @@ -136,6 +137,23 @@ title_widget_init (TitleWidget *self) g_object_get(GTK_WIDGET(self), "use-stock", use_stock, NULL ); g_object_get(GTK_WIDGET(self), "always-show-image", show_image, NULL); + + GtkAllocation new_alloc; + new_alloc.width = 16; + new_alloc.height = 16; + new_alloc.x = 16; + new_alloc.y = 16; + + gtk_widget_set_allocation(icon, &new_alloc); + + GtkAllocation alloc; + gtk_widget_get_allocation(icon, &alloc); + + g_debug("title widget init - alloc for icon: width : %i, height : %i, x : %i and y : %i", + alloc.width, + alloc.height, + alloc.x, + alloc.y); g_debug("title widget init : use-stock = %i and show image = %i", *use_stock, *show_image); g_free(use_stock); -- cgit v1.2.3 From 86423311e123d01b3528365b2010f25dc292625d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 19:16:24 +0100 Subject: tidied up debug statements --- src/title-widget.c | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index 0315a8e..fbcac0a 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -101,34 +101,46 @@ title_widget_init (TitleWidget *self) gint width, height; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); - g_debug("title widget init - height and weight = %i and %i", height, width); - GtkImage * image = indicator_image_helper("sound_icon"); GdkPixbuf* buf = gtk_image_get_pixbuf (image); - g_debug("Is it a pixbuf : %i", GDK_IS_PIXBUF(buf)); - GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); - - g_debug("title widget init - icon pixel size = %i", gtk_image_get_pixel_size (GTK_IMAGE(icon))); - g_debug("title widget init - image pixel size = %i", gtk_image_get_pixel_size (image)); - + + //GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); + GtkWidget * icon = gtk_image_new_from_file("/usr/share/icons/ubuntu-mono-dark/status/16/sound_icon.png"); + + GtkAllocation new_alloc; + new_alloc.width = 16; + new_alloc.height = 16; + new_alloc.x = 16; + new_alloc.y = 16; + + gtk_widget_set_allocation(icon, &new_alloc); + gtk_widget_set_size_request(icon, width + 5 /* ref triangle is 5x9 pixels */ + 2 /* padding */, height); gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); - + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); gtk_widget_show_all(icon); - GtkWidget* returned_image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(self)); - g_debug("returned image is not null %i", GTK_IS_IMAGE(returned_image)); // DEBUG + g_debug("title widget init - Is there a pixbuf from image loaded with helper : %i", GDK_IS_PIXBUF(buf)); + + g_debug("title widget init - icon pixel size = %i", gtk_image_get_pixel_size (GTK_IMAGE(icon))); + g_debug("title widget init - image pixel size = %i", gtk_image_get_pixel_size (image)); + + g_debug("title widget init - height and weight = %i and %i", height, width); + GtkImageType type; type = gtk_image_get_storage_type(GTK_IMAGE(icon)); - g_debug("gtk_image_storage_type on widget = %i", type); + g_debug("title widget init - gtk_image_storage_type on widget = %i", type); type = gtk_image_get_storage_type(image); - g_debug("gtk_image_storage_type on image = %i", type); + g_debug("title widget init - gtk_image_storage_type on image = %i", type); + + GtkWidget* returned_image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(self)); + g_debug("title widget init - returned image is not null %i", GTK_IS_IMAGE(returned_image)); gboolean* use_stock; use_stock = g_new0(gboolean, 1); @@ -137,14 +149,6 @@ title_widget_init (TitleWidget *self) g_object_get(GTK_WIDGET(self), "use-stock", use_stock, NULL ); g_object_get(GTK_WIDGET(self), "always-show-image", show_image, NULL); - - GtkAllocation new_alloc; - new_alloc.width = 16; - new_alloc.height = 16; - new_alloc.x = 16; - new_alloc.y = 16; - - gtk_widget_set_allocation(icon, &new_alloc); GtkAllocation alloc; gtk_widget_get_allocation(icon, &alloc); -- cgit v1.2.3 From 39680a792b250f478fcdd430c7c09a734ab35590 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 21:00:08 +0100 Subject: removed unnecessary hbox and label and set the text directly on the menuitem --- src/title-widget.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index fbcac0a..245c14c 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -32,8 +32,8 @@ typedef struct _TitleWidgetPrivate TitleWidgetPrivate; struct _TitleWidgetPrivate { - GtkWidget* hbox; - GtkWidget* name; + //GtkWidget* hbox; + //GtkWidget* name; GtkWidget* image_item; DbusmenuMenuitem* twin_item; }; @@ -55,7 +55,7 @@ static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property GValue* value, gpointer userdata); static void title_widget_set_twin_item( TitleWidget* self, DbusmenuMenuitem* twin_item); -static void title_widget_style_name_text(TitleWidget* self); +//static void title_widget_style_name_text(TitleWidget* self); static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, @@ -86,10 +86,10 @@ title_widget_init (TitleWidget *self) TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); - GtkWidget *hbox; + //GtkWidget *hbox; - hbox = gtk_hbox_new(FALSE, 0); - priv->hbox = hbox; + //hbox = gtk_hbox_new(FALSE, 0); + //priv->hbox = hbox; // Add image to the 'gutter' gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); @@ -123,7 +123,7 @@ title_widget_init (TitleWidget *self) gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); - gtk_widget_show_all(icon); + //gtk_widget_show_all(icon); // DEBUG g_debug("title widget init - Is there a pixbuf from image loaded with helper : %i", GDK_IS_PIXBUF(buf)); @@ -202,8 +202,10 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(mitem); if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ - gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value)); - title_widget_style_name_text(mitem); + gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), + g_value_get_string(value)); + //gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value)); + //title_widget_style_name_text(mitem); } } @@ -219,18 +221,21 @@ title_widget_set_twin_item(TitleWidget* self, "expose_event", G_CALLBACK (title_widget_triangle_draw_cb), twin_item); // Add the application name - priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, - DBUSMENU_TITLE_MENUITEM_NAME)); - gtk_misc_set_padding(GTK_MISC(priv->name), 0, 0); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0); - - title_widget_style_name_text(self); - - gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET(priv->hbox)); - gtk_widget_show_all (priv->hbox); + //priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, + // DBUSMENU_TITLE_MENUITEM_NAME)); + //gtk_misc_set_padding(GTK_MISC(priv->name), 0, 0); + //gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0); + + //title_widget_style_name_text(self); + gtk_menu_item_set_label (GTK_MENU_ITEM(self), + dbusmenu_menuitem_property_get(priv->twin_item, + DBUSMENU_TITLE_MENUITEM_NAME)); + + //gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET(priv->hbox)); + gtk_widget_show_all (GTK_WIDGET(self)); } -static void +/*static void title_widget_style_name_text(TitleWidget* self) { TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); @@ -240,7 +245,7 @@ title_widget_style_name_text(TitleWidget* self) gtk_label_get_text(GTK_LABEL(priv->name))); gtk_label_set_markup (GTK_LABEL (priv->name), markup); g_free(markup); -} +}*/ static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) -- cgit v1.2.3 From 7569d1ceb769afcd429eec614c3a0c0b9ca0a2c0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 21:03:57 +0100 Subject: removed unnecessary hbox and label and set the text directly on the menuitem --- src/title-widget.c | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index 245c14c..1925b6d 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -32,8 +32,6 @@ typedef struct _TitleWidgetPrivate TitleWidgetPrivate; struct _TitleWidgetPrivate { - //GtkWidget* hbox; - //GtkWidget* name; GtkWidget* image_item; DbusmenuMenuitem* twin_item; }; @@ -55,8 +53,6 @@ static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property GValue* value, gpointer userdata); static void title_widget_set_twin_item( TitleWidget* self, DbusmenuMenuitem* twin_item); -//static void title_widget_style_name_text(TitleWidget* self); - static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data); @@ -86,10 +82,6 @@ title_widget_init (TitleWidget *self) TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); - //GtkWidget *hbox; - - //hbox = gtk_hbox_new(FALSE, 0); - //priv->hbox = hbox; // Add image to the 'gutter' gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); @@ -123,7 +115,7 @@ title_widget_init (TitleWidget *self) gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); - //gtk_widget_show_all(icon); + gtk_widget_show_all(icon); // DEBUG g_debug("title widget init - Is there a pixbuf from image loaded with helper : %i", GDK_IS_PIXBUF(buf)); @@ -204,8 +196,6 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), g_value_get_string(value)); - //gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value)); - //title_widget_style_name_text(mitem); } } @@ -220,33 +210,12 @@ title_widget_set_twin_item(TitleWidget* self, g_signal_connect_after(G_OBJECT (self), "expose_event", G_CALLBACK (title_widget_triangle_draw_cb), twin_item); - // Add the application name - //priv->name = gtk_label_new(dbusmenu_menuitem_property_get(priv->twin_item, - // DBUSMENU_TITLE_MENUITEM_NAME)); - //gtk_misc_set_padding(GTK_MISC(priv->name), 0, 0); - //gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0); - - //title_widget_style_name_text(self); gtk_menu_item_set_label (GTK_MENU_ITEM(self), dbusmenu_menuitem_property_get(priv->twin_item, - DBUSMENU_TITLE_MENUITEM_NAME)); - - //gtk_container_add (GTK_CONTAINER (self), GTK_WIDGET(priv->hbox)); - gtk_widget_show_all (GTK_WIDGET(self)); + DBUSMENU_TITLE_MENUITEM_NAME)); + //gtk_widget_show_all (GTK_WIDGET(self)); } -/*static void -title_widget_style_name_text(TitleWidget* self) -{ - TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); - - char* markup; - markup = g_markup_printf_escaped ("%s", - gtk_label_get_text(GTK_LABEL(priv->name))); - gtk_label_set_markup (GTK_LABEL (priv->name), markup); - g_free(markup); -}*/ - static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data) { -- cgit v1.2.3 From 9840130d7059edec3acd634d18f8f601c2afc28a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 21:04:47 +0100 Subject: removed unnecessary hbox and label and set the text directly on the menuitem --- src/title-widget.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index 1925b6d..1021c89 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -80,9 +80,6 @@ title_widget_init (TitleWidget *self) { g_debug("TitleWidget::title_widget_init"); - TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); - - // Add image to the 'gutter' gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(self), FALSE); @@ -191,7 +188,6 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, { g_return_if_fail (IS_TITLE_WIDGET (userdata)); TitleWidget* mitem = TITLE_WIDGET(userdata); - TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(mitem); if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), -- cgit v1.2.3 From dad11c32d68b0f09eb52232a3d3da300e2e63702 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 7 Sep 2010 21:39:28 +0100 Subject: ready for 0.4.2 --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 1f038d6725571f8e80530a96112d427d5b051022 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 8 Sep 2010 15:51:52 +0100 Subject: title widget now shows the icon in the right place, play button have been alter accordingly --- src/play-button.c | 11 ++--- src/sound-service.c | 4 +- src/title-widget.c | 117 ++++++++++++++++------------------------------------ 3 files changed, 43 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/play-button.c b/src/play-button.c index a2eaf2e..2164527 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -388,19 +388,20 @@ determine_button_event(GtkWidget* button, GdkEventButton* event) g_debug("event y coordinate = %f", event->y); PlayButtonEvent button_event = TRANSPORT_NADA; // For now very simple rectangular collision detection - if(event->x > 55 && event->x < 95 + if(event->x > 67 && event->x < 112 && event->y > 12 && event->y < 40){ button_event = TRANSPORT_PREVIOUS; } - else if(event->x > 99 && event->x < 136 + else if(event->x > 111 && event->x < 153 && event->y > 5 && event->y < 47){ button_event = TRANSPORT_PLAY_PAUSE; } - else if(event->x > 137 && event->x < 179 + else if(event->x > 152 && event->x < 197 && event->y > 12 && event->y < 40){ button_event = TRANSPORT_NEXT; } return button_event; + } void @@ -719,8 +720,8 @@ draw (GtkWidget* button, cairo_t *cr) cairo_surface_t* surf = NULL; cairo_t* cr_surf = NULL; - double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f}; - double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f}; + //double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f}; + //double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f}; double MIDDLE_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; double MIDDLE_END[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f}; double OUTER_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; diff --git a/src/sound-service.c b/src/sound-service.c index 42ce116..12f067e 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } diff --git a/src/title-widget.c b/src/title-widget.c index 1021c89..1146818 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -32,8 +32,7 @@ typedef struct _TitleWidgetPrivate TitleWidgetPrivate; struct _TitleWidgetPrivate { - GtkWidget* image_item; - DbusmenuMenuitem* twin_item; + DbusmenuMenuitem* twin_item; }; #define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate)) @@ -52,7 +51,7 @@ static gboolean title_widget_button_press_event (GtkWidget *menuitem, static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); static void title_widget_set_twin_item( TitleWidget* self, - DbusmenuMenuitem* twin_item); + DbusmenuMenuitem* twin_item); static gboolean title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointer data); @@ -80,77 +79,22 @@ title_widget_init (TitleWidget *self) { g_debug("TitleWidget::title_widget_init"); - // Add image to the 'gutter' - gtk_image_menu_item_set_always_show_image(GTK_IMAGE_MENU_ITEM(self), TRUE); - gtk_image_menu_item_set_use_stock(GTK_IMAGE_MENU_ITEM(self), FALSE); - - gint padding = 4; + gint padding = 0; gtk_widget_style_get(GTK_WIDGET(self), "horizontal-padding", &padding, NULL); gint width, height; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); - GtkImage * image = indicator_image_helper("sound_icon"); - GdkPixbuf* buf = gtk_image_get_pixbuf (image); - - //GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); - GtkWidget * icon = gtk_image_new_from_file("/usr/share/icons/ubuntu-mono-dark/status/16/sound_icon.png"); - - GtkAllocation new_alloc; - new_alloc.width = 16; - new_alloc.height = 16; - new_alloc.x = 16; - new_alloc.y = 16; - - gtk_widget_set_allocation(icon, &new_alloc); - - gtk_widget_set_size_request(icon, width - + 5 /* ref triangle is 5x9 pixels */ - + 2 /* padding */, - height); - gtk_misc_set_alignment(GTK_MISC(icon), 1.0 /* right aligned */, 0.5); - - gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); - - gtk_widget_show_all(icon); - - // DEBUG - g_debug("title widget init - Is there a pixbuf from image loaded with helper : %i", GDK_IS_PIXBUF(buf)); + GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); - g_debug("title widget init - icon pixel size = %i", gtk_image_get_pixel_size (GTK_IMAGE(icon))); - g_debug("title widget init - image pixel size = %i", gtk_image_get_pixel_size (image)); + gtk_widget_set_size_request(icon, width + + 5 /* ref triangle is 5x9 pixels */ + + 1 /* padding */, + height); + gtk_misc_set_alignment(GTK_MISC(icon), 0.5 /* right aligned */, 0); + gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(self), GTK_WIDGET(icon)); + gtk_widget_show(icon); - g_debug("title widget init - height and weight = %i and %i", height, width); - - GtkImageType type; - type = gtk_image_get_storage_type(GTK_IMAGE(icon)); - g_debug("title widget init - gtk_image_storage_type on widget = %i", type); - type = gtk_image_get_storage_type(image); - g_debug("title widget init - gtk_image_storage_type on image = %i", type); - - GtkWidget* returned_image = gtk_image_menu_item_get_image(GTK_IMAGE_MENU_ITEM(self)); - g_debug("title widget init - returned image is not null %i", GTK_IS_IMAGE(returned_image)); - - gboolean* use_stock; - use_stock = g_new0(gboolean, 1); - gboolean* show_image; - show_image = g_new0(gboolean, 1); - - g_object_get(GTK_WIDGET(self), "use-stock", use_stock, NULL ); - g_object_get(GTK_WIDGET(self), "always-show-image", show_image, NULL); - - GtkAllocation alloc; - gtk_widget_get_allocation(icon, &alloc); - - g_debug("title widget init - alloc for icon: width : %i, height : %i, x : %i and y : %i", - alloc.width, - alloc.height, - alloc.x, - alloc.y); - - g_debug("title widget init : use-stock = %i and show image = %i", *use_stock, *show_image); - g_free(use_stock); - g_free(show_image); } static void @@ -188,10 +132,10 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, { g_return_if_fail (IS_TITLE_WIDGET (userdata)); TitleWidget* mitem = TITLE_WIDGET(userdata); - - if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ - gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), - g_value_get_string(value)); + + if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_NAME, property) == 0){ + gtk_menu_item_set_label (GTK_MENU_ITEM(mitem), + g_value_get_string(value)); } } @@ -199,17 +143,23 @@ static void title_widget_set_twin_item(TitleWidget* self, DbusmenuMenuitem* twin_item) { - TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); - priv->twin_item = twin_item; - g_signal_connect(G_OBJECT(twin_item), "property-changed", - G_CALLBACK(title_widget_property_update), self); - g_signal_connect_after(G_OBJECT (self), - "expose_event", G_CALLBACK (title_widget_triangle_draw_cb), twin_item); - - gtk_menu_item_set_label (GTK_MENU_ITEM(self), + TitleWidgetPrivate *priv = TITLE_WIDGET_GET_PRIVATE(self); + + priv->twin_item = twin_item; + + g_signal_connect (G_OBJECT (twin_item), + "property-changed", + G_CALLBACK (title_widget_property_update), + self); + g_signal_connect_after (G_OBJECT (self), + "expose_event", + G_CALLBACK (title_widget_triangle_draw_cb), + twin_item); + + gtk_menu_item_set_label (GTK_MENU_ITEM(self), dbusmenu_menuitem_property_get(priv->twin_item, - DBUSMENU_TITLE_MENUITEM_NAME)); - //gtk_widget_show_all (GTK_WIDGET(self)); + DBUSMENU_TITLE_MENUITEM_NAME)); + } static gboolean @@ -266,8 +216,11 @@ title_widget_triangle_draw_cb (GtkWidget *widget, GdkEventExpose *event, gpointe GtkWidget* title_widget_new(DbusmenuMenuitem *item) { - GtkWidget* widget = g_object_new(TITLE_WIDGET_TYPE, NULL); + GtkWidget* widget = g_object_new (TITLE_WIDGET_TYPE, + NULL); + gtk_image_menu_item_set_always_show_image (GTK_IMAGE_MENU_ITEM (widget), TRUE); title_widget_set_twin_item((TitleWidget*)widget, item); + return widget; } -- cgit v1.2.3 From 8034c9103ba03b8fa782ca3bccbb293282ff5a4c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 8 Sep 2010 18:06:26 +0100 Subject: some defensive code in place to protect against rare seg-fault on the volume slider --- src/indicator-sound.c | 3 +++ src/sound-service.c | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 0e631fa..4cab754 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -661,6 +661,7 @@ key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data) GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); GtkRange* range = (GtkRange*)slider; + g_return_val_if_fail(GTK_IS_RANGE(range), FALSE); gdouble current_value = gtk_range_get_value(range); gdouble new_value = current_value; const gdouble five_percent = 5; @@ -729,6 +730,8 @@ indicator_sound_scroll (IndicatorObject *io, gint delta, IndicatorScrollDirectio GtkWidget* slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)slider_widget); GtkRange* range = (GtkRange*)slider; + g_return_if_fail(GTK_IS_RANGE(range)); + gdouble value = gtk_range_get_value(range); GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (slider)); g_debug("indicator-sound-scroll - current slider value %f", value); diff --git a/src/sound-service.c b/src/sound-service.c index f19379d..51f5f37 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 6f8a97048c533ea6cc2623bc6ed5773336ec2587 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 9 Sep 2010 17:07:19 +0100 Subject: reversed colours on buttons --- src/mpris2-controller.vala | 12 ++++++++---- src/music-player-bridge.vala | 19 ++++++++++++++++--- src/play-button.c | 16 ++++++++-------- 3 files changed, 32 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index dab5e2c..5f284b2 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -53,7 +53,9 @@ public interface MprisPlayer : DBus.Object { [DBus (name = "org.freedesktop.DBus.Properties")] public interface FreeDesktopProperties : DBus.Object{ // signals - public signal void PropertiesChanged(string source, HashTable changed_properties, string[] invalid); + public signal void PropertiesChanged(string source, HashTable changed_properties, + string[] invalid); } /* @@ -85,8 +87,7 @@ public class Mpris2Controller : GLib.Object this.player.Seeked += onSeeked; this.properties_interface = (FreeDesktopProperties) connection.get_object(root_interface.concat(".").concat(this.owner.name.down()), - "/org/mpris/MediaPlayer2", - "org.freedesktop.DBus.Properties"); + "/org/mpris/MediaPlayer2"); this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { @@ -97,7 +98,10 @@ public class Mpris2Controller : GLib.Object public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) { debug("properties-changed for interface %s and owner %s", interface_source, this.owner.name.down()); - if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false){ + debug("is the invalid array null : %s", (invalid == null).to_string()); + debug("invalid length : %i", invalid.length); + + if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){ warning("Property-changed hash is null or this is an interface that concerns us"); return; } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index c677d15..3929916 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -59,14 +59,27 @@ public class MusicPlayerBridge : GLib.Object } GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, - app_info.get_name(), + truncate_player_name(app_info.get_name()), calculate_menu_position(), PlayerController.state.OFFLINE); - ctrl.set("app_info", app_info); - this.registered_clients.set(app_info.get_name().down().strip(), ctrl); + ctrl.app_info = app_info; + this.registered_clients.set(truncate_player_name(app_info.get_name()), ctrl); } } + private static string truncate_player_name(string app_info_name) + { + string result = app_info_name.down().strip(); + + var tokens = result.split(" "); + + if(tokens.length > 1){ + result = tokens[0]; + } + debug("truncate player name %s", result); + return result; + } + private int calculate_menu_position() { if(this.registered_clients.size == 0){ diff --git a/src/play-button.c b/src/play-button.c index 0c934e5..a40b683 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -733,15 +733,15 @@ draw (GtkWidget* button, cairo_t *cr) //double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f}; //double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f}; - double MIDDLE_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; - double MIDDLE_END[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f}; - double OUTER_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; - double OUTER_END[] = {123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, 1.0f}; - double BUTTON_START[] = {252.0f / 255.0f, 251.0f / 255.0f, 251.0f / 255.0f,1.0f}; - double BUTTON_END[] = {186.0f / 255.0f,180.0f / 255.0f, 170.0f / 255.0f, 1.0f}; + double MIDDLE_END[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; + double MIDDLE_START[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f}; + double OUTER_END[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; + double OUTER_START[] = {123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, 1.0f}; + double BUTTON_END[] = {252.0f / 255.0f, 251.0f / 255.0f, 251.0f / 255.0f,1.0f}; + double BUTTON_START[] = {186.0f / 255.0f,180.0f / 255.0f, 170.0f / 255.0f, 1.0f}; double BUTTON_SHADOW[] = {0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 0.75f}; - double INNER_COMPRESSED_END[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; - double INNER_COMPRESSED_START[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; + double INNER_COMPRESSED_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; + double INNER_COMPRESSED_END[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; // prev/next-background draw_gradient (cr, -- cgit v1.2.3 From 768c373bdbc94e64bf7eb8e4bbc845be97090b90 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 10 Sep 2010 09:58:11 +0100 Subject: banshee menu bug fixed --- src/music-player-bridge.vala | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 3929916..26bf2c2 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -63,6 +63,9 @@ public class MusicPlayerBridge : GLib.Object calculate_menu_position(), PlayerController.state.OFFLINE); ctrl.app_info = app_info; + if(ctrl.app_info == null) + warning("for some reason the app info is null"); + this.registered_clients.set(truncate_player_name(app_info.get_name()), ctrl); } } -- cgit v1.2.3 From 977925a7005678226be7faa1762c6117b240c231 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 10 Sep 2010 12:28:57 +0100 Subject: play button and metadata widgets now handle theme changes --- src/metadata-widget.c | 64 ++++++----- src/music-player-bridge.vala | 2 + src/play-button.c | 261 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 289 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index 18ebd38..c98877f 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -33,6 +33,7 @@ typedef struct _MetadataWidgetPrivate MetadataWidgetPrivate; struct _MetadataWidgetPrivate { + gboolean theme_change_occured; GtkWidget* hbox; GtkWidget* album_art; GString* image_path; @@ -40,18 +41,18 @@ struct _MetadataWidgetPrivate GtkWidget* artist_label; GtkWidget* piece_label; GtkWidget* container_label; - GdkColor bevel_colour; - GdkColor eight_note_colour; }; #define METADATA_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), METADATA_WIDGET_TYPE, MetadataWidgetPrivate)) /* Prototypes */ -static void metadata_widget_class_init (MetadataWidgetClass *klass); -static void metadata_widget_init (MetadataWidget *self); -static void metadata_widget_dispose (GObject *object); -static void metadata_widget_finalize (GObject *object); -static gboolean metadata_image_expose (GtkWidget *image, GdkEventExpose *event, gpointer user_data); +static void metadata_widget_class_init (MetadataWidgetClass *klass); +static void metadata_widget_init (MetadataWidget *self); +static void metadata_widget_dispose (GObject *object); +static void metadata_widget_finalize (GObject *object); +static gboolean metadata_image_expose (GtkWidget *image, GdkEventExpose *event, gpointer user_data); +//static void metadata_widget_style_changed_cb(GtkWidget *widget, gpointer user_data); +static void metadata_widget_set_style (GtkWidget* button, GtkStyle* style); // keyevent consumers static gboolean metadata_widget_button_press_event (GtkWidget *menuitem, @@ -61,15 +62,11 @@ static void metadata_widget_property_update (DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); - static void metadata_widget_style_labels(MetadataWidget* self, GtkLabel* label); - -void metadata_widget_set_style(GtkWidget* button, GtkStyle* style); static void image_set_from_pixbuf (GtkWidget *widget, MetadataWidget* metadata, GdkPixbuf *source); - static void draw_album_art_placeholder(GtkWidget *metadata); G_DEFINE_TYPE (MetadataWidget, metadata_widget, GTK_TYPE_MENU_ITEM); @@ -95,7 +92,6 @@ metadata_widget_init (MetadataWidget *self) g_debug("MetadataWidget::metadata_widget_init"); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self); - GtkWidget *hbox; hbox = gtk_hbox_new(FALSE, 0); @@ -114,7 +110,9 @@ metadata_widget_init (MetadataWidget *self) gtk_box_pack_start (GTK_BOX (priv->hbox), priv->album_art, FALSE, FALSE, 0); - GtkWidget* vbox = gtk_vbox_new(FALSE, 0); + priv->theme_change_occured = FALSE; + + GtkWidget* vbox = gtk_vbox_new(FALSE, 0); // artist GtkWidget* artist; @@ -177,6 +175,12 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } +static void metadata_widget_style_changed_cb(GtkWidget *widget, + gpointer user_data) +{ + +} + /** * We override the expose method to enable primitive drawing of the * empty album art image and rounded rectangles on the album art. @@ -188,7 +192,9 @@ metadata_image_expose (GtkWidget *metadata, GdkEventExpose *event, gpointer user MetadataWidget* widget = METADATA_WIDGET(user_data); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widget); if(priv->image_path->len > 0){ - if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE){ + if(g_string_equal(priv->image_path, priv->old_image_path) == FALSE || + priv->theme_change_occured == TRUE){ + priv->theme_change_occured = FALSE; GdkPixbuf* pixbuf; pixbuf = gdk_pixbuf_new_from_file(priv->image_path->str, NULL); g_debug("metadata_load_new_image -> pixbuf from %s", @@ -216,6 +222,9 @@ static void draw_album_art_placeholder(GtkWidget *metadata) cairo_t *cr; cr = gdk_cairo_create (metadata->window); + GtkStyle *style; + style = gtk_widget_get_style (metadata); + GtkAllocation alloc; gtk_widget_get_allocation (metadata, &alloc); @@ -234,7 +243,11 @@ static void draw_album_art_placeholder(GtkWidget *metadata) cairo_close_path (cr); - cairo_set_source_rgba (cr, 123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, .8f); + cairo_set_source_rgba (cr, + style->fg[0].red/65535.0, + style->fg[0].green/65535.0, + style->fg[0].blue/65535.0, + 0.6); cairo_set_line_width (cr, 2.0); cairo_stroke (cr); @@ -256,7 +269,12 @@ static void draw_album_art_placeholder(GtkWidget *metadata) pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); - cairo_set_source_rgba(cr, 1.0, 1.0, 1.0, 0.8); + cairo_set_source_rgba (cr, + style->fg[0].red/65535.0, + style->fg[0].green/65535.0, + style->fg[0].blue/65535.0, + 0.8); + pango_cairo_update_layout(cr, layout); cairo_move_to (cr, alloc.x + alloc.width/6, alloc.y); pango_cairo_show_layout(cr, layout); @@ -487,21 +505,15 @@ metadata_widget_style_labels(MetadataWidget* self, GtkLabel* label) g_free(markup); } -void +static void metadata_widget_set_style(GtkWidget* metadata, GtkStyle* style) { g_return_if_fail(IS_METADATA_WIDGET(metadata)); MetadataWidget* widg = METADATA_WIDGET(metadata); MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(widg); - if(style == NULL){ - g_warning("metadata_widget_set_style -> style is NULL!"); - return; - } - else{ - g_debug("metadata_widget: about to set the style colours"); - priv->eight_note_colour = style->fg[GTK_STATE_NORMAL]; - priv->bevel_colour = style->bg[GTK_STATE_NORMAL]; - } + priv->theme_change_occured = TRUE; + gtk_widget_queue_draw(GTK_WIDGET(metadata)); + g_debug("metadata_widget: theme change"); } /** diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 26bf2c2..61dfa2e 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -58,6 +58,8 @@ public class MusicPlayerBridge : GLib.Object continue; } GLib.AppInfo app_info = info as GLib.AppInfo; + // TODO refactor to remove need for further name refactoring in the player controller + // truncate should not do a down() on the name PlayerController ctrl = new PlayerController(this.root_menu, truncate_player_name(app_info.get_name()), calculate_menu_position(), diff --git a/src/play-button.c b/src/play-button.c index a40b683..31cdf5a 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -55,6 +55,18 @@ Uses code from ctk #define PLAY_WIDTH 28.0f #define PLAY_HEIGHT 29.0f #define PLAY_PADDING 5.0f +#define INNER_START_SHADE 0.98 +#define INNER_END_SHADE 0.98 +#define MIDDLE_START_SHADE 0.7 +#define MIDDLE_END_SHADE 1.4 +#define OUTER_START_SHADE 0.96 +#define OUTER_END_SHADE 0.96 +#define BUTTON_START_SHADE 1.1 +#define BUTTON_END_SHADE 0.9 +#define BUTTON_SHADOW_SHADE 0.8 +#define INNER_COMPRESSED_START_SHADE 0.95 +#define INNER_COMPRESSED_END_SHADE 1.05 + typedef struct _PlayButtonPrivate PlayButtonPrivate; @@ -70,6 +82,14 @@ struct _PlayButtonPrivate GHashTable* command_coordinates; }; +typedef struct +{ + double r; + double g; + double b; +} CairoColorRGB; + + #define PLAY_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PLAY_BUTTON_TYPE, PlayButtonPrivate)) /* Gobject boiler plate */ @@ -722,6 +742,198 @@ _finalize (cairo_t* cr, cairo_destroy (*cr_surf); } +static void +_color_rgb_to_hls (gdouble *r, + gdouble *g, + gdouble *b) +{ + gdouble min; + gdouble max; + gdouble red; + gdouble green; + gdouble blue; + gdouble h, l, s; + gdouble delta; + + red = *r; + green = *g; + blue = *b; + + if (red > green) + { + if (red > blue) + max = red; + else + max = blue; + + if (green < blue) + min = green; + else + min = blue; + } + else + { + if (green > blue) + max = green; + else + max = blue; + + if (red < blue) + min = red; + else + min = blue; + } + l = (max+min)/2; + if (fabs (max-min) < 0.0001) + { + h = 0; + s = 0; + } + else + { + if (l <= 0.5) + s = (max-min)/(max+min); + else + s = (max-min)/(2-max-min); + + delta = max -min; + if (red == max) + h = (green-blue)/delta; + else if (green == max) + h = 2+(blue-red)/delta; + else if (blue == max) + h = 4+(red-green)/delta; + + h *= 60; + if (h < 0.0) + h += 360; + } + + *r = h; + *g = l; + *b = s; +} + +static void +_color_hls_to_rgb (gdouble *h, + gdouble *l, + gdouble *s) +{ + gdouble hue; + gdouble lightness; + gdouble saturation; + gdouble m1, m2; + gdouble r, g, b; + + lightness = *l; + saturation = *s; + + if (lightness <= 0.5) + m2 = lightness*(1+saturation); + else + m2 = lightness+saturation-lightness*saturation; + + m1 = 2*lightness-m2; + + if (saturation == 0) + { + *h = lightness; + *l = lightness; + *s = lightness; + } + else + { + hue = *h+120; + while (hue > 360) + hue -= 360; + while (hue < 0) + hue += 360; + + if (hue < 60) + r = m1+(m2-m1)*hue/60; + else if (hue < 180) + r = m2; + else if (hue < 240) + r = m1+(m2-m1)*(240-hue)/60; + else + r = m1; + + hue = *h; + while (hue > 360) + hue -= 360; + while (hue < 0) + hue += 360; + + if (hue < 60) + g = m1+(m2-m1)*hue/60; + else if (hue < 180) + g = m2; + else if (hue < 240) + g = m1+(m2-m1)*(240-hue)/60; + else + g = m1; + + hue = *h-120; + while (hue > 360) + hue -= 360; + while (hue < 0) + hue += 360; + + if (hue < 60) + b = m1+(m2-m1)*hue/60; + else if (hue < 180) + b = m2; + else if (hue < 240) + b = m1+(m2-m1)*(240-hue)/60; + else + b = m1; + + *h = r; + *l = g; + *s = b; + } +} + +static void +_color_shade (const CairoColorRGB *a, float k, CairoColorRGB *b) +{ + double red; + double green; + double blue; + + red = a->r; + green = a->g; + blue = a->b; + + if (k == 1.0) + { + b->r = red; + b->g = green; + b->b = blue; + return; + } + + _color_rgb_to_hls (&red, &green, &blue); + + green *= k; + if (green > 1.0) + green = 1.0; + else if (green < 0.0) + green = 0.0; + + blue *= k; + if (blue > 1.0) + blue = 1.0; + else if (blue < 0.0) + blue = 0.0; + + _color_hls_to_rgb (&red, &green, &blue); + + b->r = red; + b->g = green; + b->b = blue; +} + static void draw (GtkWidget* button, cairo_t *cr) { @@ -731,18 +943,43 @@ draw (GtkWidget* button, cairo_t *cr) cairo_surface_t* surf = NULL; cairo_t* cr_surf = NULL; - //double INNER_START[] = {229.0f/255.0f, 223.0f/255.0f, 215.0f/255.0f, 1.0f}; - //double INNER_END[] = {183.0f / 255.0f, 178.0f / 255.0f, 172.0f / 255.0f, 1.0f}; - double MIDDLE_END[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; - double MIDDLE_START[] = {94.0f / 255.0f,93.0f / 255.0f, 90.0f / 255.0f,1.0f}; - double OUTER_END[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; - double OUTER_START[] = {123.0f / 255.0f, 123.0f / 255.0f, 120.0f / 255.0f, 1.0f}; - double BUTTON_END[] = {252.0f / 255.0f, 251.0f / 255.0f, 251.0f / 255.0f,1.0f}; - double BUTTON_START[] = {186.0f / 255.0f,180.0f / 255.0f, 170.0f / 255.0f, 1.0f}; - double BUTTON_SHADOW[] = {0.0f / 255.0f, 0.0f / 255.0f, 0.0f / 255.0f, 0.75f}; - double INNER_COMPRESSED_START[] = {61.0f / 255.0f, 60.0f / 255.0f, 57.0f / 255.0f, 1.0f}; - double INNER_COMPRESSED_END[] = {36.0f / 255.0f, 35.0f / 255.0f, 33.0f / 255.0f, 1.0f}; - + GtkStyle *style; + + CairoColorRGB bg_normal, fg_normal; + CairoColorRGB color_inner[2], color_middle[2], color_outer[2], color_button[3], color_inner_compressed[2]; + + style = gtk_widget_get_style (button); + + bg_normal.r = style->bg[0].red/65535.0; + bg_normal.g = style->bg[0].green/65535.0; + bg_normal.b = style->bg[0].blue/65535.0; + + fg_normal.r = style->fg[0].red/65535.0; + fg_normal.g = style->fg[0].green/65535.0; + fg_normal.b = style->fg[0].blue/65535.0; + + _color_shade (&bg_normal, INNER_START_SHADE, &color_inner[0]); + _color_shade (&bg_normal, INNER_END_SHADE, &color_inner[1]); + _color_shade (&bg_normal, MIDDLE_START_SHADE, &color_middle[0]); + _color_shade (&bg_normal, MIDDLE_END_SHADE, &color_middle[1]); + _color_shade (&bg_normal, OUTER_START_SHADE, &color_outer[0]); + _color_shade (&bg_normal, OUTER_END_SHADE, &color_outer[1]); + _color_shade (&fg_normal, BUTTON_START_SHADE, &color_button[0]); + _color_shade (&fg_normal, BUTTON_END_SHADE, &color_button[1]); + _color_shade (&bg_normal, BUTTON_SHADOW_SHADE, &color_button[2]); + _color_shade (&bg_normal, INNER_COMPRESSED_START_SHADE, &color_inner_compressed[0]); + _color_shade (&bg_normal, INNER_COMPRESSED_END_SHADE, &color_inner_compressed[1]); + + double MIDDLE_END[] = {color_middle[0].r, color_middle[0].g, color_middle[0].b, 1.0f}; + double MIDDLE_START[] = {color_middle[1].r, color_middle[1].g, color_middle[1].b, 1.0f}; + double OUTER_END[] = {color_outer[0].r, color_outer[0].g, color_outer[0].b, 1.0f}; + double OUTER_START[] = {color_outer[1].r, color_outer[1].g, color_outer[1].b, 1.0f}; + double BUTTON_END[] = {color_button[0].r, color_button[0].g, color_button[0].b, 1.0f}; + double BUTTON_START[] = {color_button[1].r, color_button[1].g, color_button[1].b, 1.0f}; + double BUTTON_SHADOW[] = {color_button[2].r, color_button[2].g, color_button[2].b, 0.75f}; + double INNER_COMPRESSED_END[] = {color_inner_compressed[1].r, color_inner_compressed[1].g, color_inner_compressed[1].b, 1.0f}; + double INNER_COMPRESSED_START[] = {color_inner_compressed[0].r, color_inner_compressed[0].g, color_inner_compressed[0].b, 1.0f}; + // prev/next-background draw_gradient (cr, X, -- cgit v1.2.3 From 9f2da5fe1ce6d18c9df2c36822bcc943cd948794 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 10 Sep 2010 12:29:20 +0100 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From ac27a7a650aba27b1dd73eaaffc7629fa1a650e0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 10 Sep 2010 14:00:43 +0100 Subject: merge comments acted upon --- src/metadata-widget.c | 5 ----- src/play-button.c | 5 ++++- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/metadata-widget.c b/src/metadata-widget.c index c98877f..7179014 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -175,11 +175,6 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } -static void metadata_widget_style_changed_cb(GtkWidget *widget, - gpointer user_data) -{ - -} /** * We override the expose method to enable primitive drawing of the diff --git a/src/play-button.c b/src/play-button.c index 31cdf5a..2ab5fc8 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -796,7 +796,10 @@ _color_rgb_to_hls (gdouble *r, else s = (max-min)/(2-max-min); - delta = max -min; + delta = (max -min) != 0 ? (max -min) : 1; + + if(delta == 0) + delta = 1; if (red == max) h = (green-blue)/delta; else if (green == max) -- cgit v1.2.3 From fc3c998e6bbec4528a9b1682665064679ac590ac Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Sep 2010 11:57:41 +0100 Subject: playback status investigations --- src/mpris2-controller.vala | 6 +++--- src/sound-service.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 5f284b2..b6d2333 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -1,5 +1,4 @@ /* -This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel. Copyright 2010 Canonical Ltd. Authors: @@ -86,8 +85,9 @@ public class Mpris2Controller : GLib.Object root_interface.concat(".Player")); this.player.Seeked += onSeeked; - this.properties_interface = (FreeDesktopProperties) connection.get_object(root_interface.concat(".").concat(this.owner.name.down()), + this.properties_interface = (FreeDesktopProperties) connection.get_object("org.freedesktop.Properties.PropertiesChanged",//root_interface.concat(".").concat(this.owner.name.down()), "/org/mpris/MediaPlayer2"); + this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { @@ -102,7 +102,7 @@ public class Mpris2Controller : GLib.Object debug("invalid length : %i", invalid.length); if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){ - warning("Property-changed hash is null or this is an interface that concerns us"); + warning("Property-changed hash is null or this is an interface that doesn't concerns us"); return; } Value? play_v = changed_properties.lookup("PlaybackStatus"); diff --git a/src/sound-service.c b/src/sound-service.c index f19379d..51f5f37 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From 40cde0089157e7ac2475b32ff2afad9ea031260b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Sep 2010 12:15:15 +0100 Subject: playback status fix --- src/mpris2-controller.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index b6d2333..4717f41 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -107,7 +107,7 @@ public class Mpris2Controller : GLib.Object } Value? play_v = changed_properties.lookup("PlaybackStatus"); if(play_v != null){ - string state = play_v.get_string(); + string state = this.player.PlaybackStatus; debug("new playback state = %s", state); TransportMenuitem.state p = (TransportMenuitem.state)this.determine_play_state(state); (this.owner.custom_items[PlayerController.widget_order.TRANSPORT] as TransportMenuitem).change_play_state(p); -- cgit v1.2.3 From 61f5618272f6e9ef010965b546344d67f39650f7 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Sep 2010 12:49:01 +0100 Subject: removed redundant scrub code --- src/Makefile.am | 1 - src/mpris2-controller.vala | 43 +------------------------------------------ src/transport-widget.c | 1 - 3 files changed, 1 insertion(+), 44 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index e85ed93..4bc6ff8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -62,7 +62,6 @@ music_bridge_VALASOURCES = \ music-player-bridge.vala \ transport-menu-item.vala \ metadata-menu-item.vala \ - scrub-menu-item.vala \ title-menu-item.vala \ player-controller.vala \ mpris2-controller.vala \ diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 4717f41..bab20ae 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -83,11 +83,8 @@ public class Mpris2Controller : GLib.Object this.player = (MprisPlayer) connection.get_object (root_interface.concat(".").concat(this.owner.name.down()), "/org/mpris/MediaPlayer2", root_interface.concat(".Player")); - this.player.Seeked += onSeeked; - this.properties_interface = (FreeDesktopProperties) connection.get_object("org.freedesktop.Properties.PropertiesChanged",//root_interface.concat(".").concat(this.owner.name.down()), - "/org/mpris/MediaPlayer2"); - + "/org/mpris/MediaPlayer2"); this.properties_interface.PropertiesChanged += property_changed_cb; } catch (DBus.Error e) { @@ -98,8 +95,6 @@ public class Mpris2Controller : GLib.Object public void property_changed_cb(string interface_source, HashTable changed_properties, string[] invalid ) { debug("properties-changed for interface %s and owner %s", interface_source, this.owner.name.down()); - debug("is the invalid array null : %s", (invalid == null).to_string()); - debug("invalid length : %i", invalid.length); if(changed_properties == null || interface_source.has_prefix(this.root_interface) == false ){ warning("Property-changed hash is null or this is an interface that doesn't concerns us"); @@ -207,42 +202,6 @@ public class Mpris2Controller : GLib.Object } } } - /** - TODO: SetPosition on the player object is not working with rhythmbox, - runtime error - "dbus function not supported" - */ - public void set_track_position(double position) - { - debug("Set position with pos (0-100) %f", position); - Value? time_value = this.player.Metadata.lookup("mpris:length"); - if(time_value == null){ - warning("Can't fetch the duration of the track therefore cant set the position"); - return; - } - // work in microseconds (scale up by 10 TTP-of 6) - int64 total_time = time_value.get_int64(); - debug("total time of track = %i", (int)total_time); - double new_time_position = total_time * (position/100.0); - debug("new position = %f", (new_time_position)); - - Value? v = this.player.Metadata.lookup("mpris:trackid"); - if(v != null){ - if(v.holds (typeof (string))){ - DBus.ObjectPath path = new ObjectPath(v.get_string()); - try{ - this.player.SetPosition(path, (int64)(new_time_position)); - } - catch(DBus.Error e){ - error("DBus Error calling the player objects SetPosition method %s", - e.message); - } - } - } - } - - public void onSeeked(int64 position){ - debug("Seeked signal callback with pos = %i", (int)position/1000); - } public bool connected() { diff --git a/src/transport-widget.c b/src/transport-widget.c index 979f6fd..2dfcbef 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -46,7 +46,6 @@ static void transport_widget_finalize (GObject *object); static void transport_widget_set_twin_item(TransportWidget* self, DbusmenuMenuitem* twin_item); - static gboolean transport_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); -- cgit v1.2.3 From ae5428d1367a17f34263b1e2178cab0de5b72e60 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Sep 2010 13:32:34 +0100 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From ee3d307dffee6f7ce5cdd09ba8d34c846f66596b Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Sep 2010 13:35:28 +0100 Subject: removed scrub stuff indicator side --- src/Makefile.am | 2 -- src/indicator-sound.c | 23 ----------------------- 2 files changed, 25 deletions(-) (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 4bc6ff8..aa5fdc7 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,8 +18,6 @@ libsoundmenu_la_SOURCES = \ indicator-sound.c \ title-widget.c \ title-widget.h \ - scrub-widget.c \ - scrub-widget.h \ volume-widget.c \ volume-widget.h \ dbus-shared-names.h \ diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 4cab754..7f3b94b 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -36,7 +36,6 @@ with this program. If not, see . #include "transport-widget.h" #include "metadata-widget.h" #include "title-widget.h" -#include "scrub-widget.h" #include "volume-widget.h" #include "dbus-shared-names.h" @@ -79,7 +78,6 @@ static void style_changed_cb(GtkWidget *widget, gpointer user_data); static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean new_scrub_bar_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -219,7 +217,6 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SCRUB_MENUITEM_TYPE, new_scrub_bar_widget); // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), io); @@ -296,26 +293,6 @@ new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu return TRUE; } -static gboolean -new_scrub_bar_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) -{ - g_debug("indicator-sound: new_scrub_bar_widget"); - - GtkWidget* scrub_bar = NULL; - - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); - g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - - scrub_bar = scrub_widget_new (newitem); - GtkMenuItem *menu_scrub_widget = GTK_MENU_ITEM(scrub_widget_get_ido_bar(SCRUB_WIDGET(scrub_bar))); - - gtk_widget_show_all(scrub_widget_get_ido_bar(SCRUB_WIDGET(scrub_bar))); - - dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_scrub_widget, parent); - - return TRUE; -} - static gboolean new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) { -- cgit v1.2.3 From 198a4eed0247f8795a93aee73af73a55d2ab2d4a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 13 Sep 2010 15:56:12 +0100 Subject: fixed autotools --- src/title-widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/title-widget.c b/src/title-widget.c index 1146818..bc1d453 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -85,7 +85,7 @@ title_widget_init (TitleWidget *self) gint width, height; gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height); - GtkWidget * icon = gtk_image_new_from_icon_name("sound_icon", GTK_ICON_SIZE_MENU); + GtkWidget * icon = gtk_image_new_from_icon_name("sound-icon", GTK_ICON_SIZE_MENU); gtk_widget_set_size_request(icon, width + 5 /* ref triangle is 5x9 pixels */ -- cgit v1.2.3 From b68421bc7f4f36342463498b44e2a3fb4b11fe7e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 12:35:15 +0100 Subject: async the root dbus method calls --- src/mpris2-controller.vala | 8 ++++---- src/sound-service.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index bab20ae..696fd09 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -28,8 +28,8 @@ public interface MprisRoot : DBus.Object { public abstract string Identity{owned get; set;} public abstract string DesktopEntry{owned get; set;} // methods - public abstract void Quit() throws DBus.Error; - public abstract void Raise() throws DBus.Error; + public abstract async void Quit() throws DBus.Error; + public abstract async void Raise() throws DBus.Error; } [DBus (name = "org.mpris.MediaPlayer2.Player")] @@ -215,12 +215,12 @@ public class Mpris2Controller : GLib.Object } return true; } - + public void expose() { if(this.connected() == true){ try{ - this.mpris2_root.Raise(); + this.mpris2_root.Raise.begin(); } catch(DBus.Error e){ error("Exception thrown while calling function Raise - %s", e.message); diff --git a/src/sound-service.c b/src/sound-service.c index f19379d..51f5f37 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - close_pulse_activites(); - g_main_loop_quit(mainloop); + //close_pulse_activites(); + //g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From edb20cb04d9f977c7ddf70f6edc707546e2997c0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 12:43:23 +0100 Subject: all dbus method calls now async --- src/mpris2-controller.vala | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/mpris2-controller.vala b/src/mpris2-controller.vala index 696fd09..2f5bcde 100644 --- a/src/mpris2-controller.vala +++ b/src/mpris2-controller.vala @@ -40,11 +40,9 @@ public interface MprisPlayer : DBus.Object { public abstract int32 Position{owned get; set;} public abstract string PlaybackStatus{owned get; set;} // methods - public abstract void SetPosition(DBus.ObjectPath path, int64 pos) throws DBus.Error; - public abstract void PlayPause() throws DBus.Error; - public abstract void Pause() throws DBus.Error; - public abstract void Next() throws DBus.Error; - public abstract void Previous() throws DBus.Error; + public abstract async void PlayPause() throws DBus.Error; + public abstract async void Next() throws DBus.Error; + public abstract async void Previous() throws DBus.Error; // signals public signal void Seeked(int64 new_position); } @@ -176,7 +174,7 @@ public class Mpris2Controller : GLib.Object if(command == TransportMenuitem.action.PLAY_PAUSE){ debug("transport_event PLAY_PAUSE"); try{ - this.player.PlayPause(); + this.player.PlayPause.begin(); } catch(DBus.Error error){ warning("DBus Error calling the player objects PlayPause method %s", @@ -185,7 +183,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.PREVIOUS){ try{ - this.player.Previous(); + this.player.Previous.begin(); } catch(DBus.Error error){ warning("DBus Error calling the player objects Previous method %s", @@ -194,7 +192,7 @@ public class Mpris2Controller : GLib.Object } else if(command == TransportMenuitem.action.NEXT){ try{ - this.player.Next(); + this.player.Next.begin(); } catch(DBus.Error error){ warning("DBus Error calling the player objects Next method %s", -- cgit v1.2.3 From 484518d33c44914196f85c19b92f3fac07d1b2e0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 18:21:02 +0100 Subject: indicator should handle any service problems gracefully --- src/dbus-menu-manager.c | 19 ++++++++++-- src/indicator-sound.c | 82 ++++++++++++++++++++++++++++++------------------- src/pulse-manager.c | 10 +++--- src/slider-menu-item.c | 3 +- src/volume-widget.c | 21 +++++++++++-- src/volume-widget.h | 2 ++ 6 files changed, 94 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 5ea561f..222affa 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -50,8 +50,11 @@ 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, SoundServiceDbus *service); +static void rebuild_sound_menu(DbusmenuMenuitem *root, + SoundServiceDbus *service); static void refresh_menu(); +static void remove_previous_children(gpointer obj, gpointer user_data); + /*-------------------------------------------------------------------------*/ // Public Methods @@ -71,10 +74,22 @@ DbusmenuMenuitem* dbus_menu_manager_setup() DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_DBUS_OBJECT); dbusmenu_server_set_root(server, root_menuitem); + + /*GList* previous_children = dbusmenu_menuitem_get_children(root_menuitem); + if(previous_children != NULL){ + g_list_foreach(previous_children, remove_previous_children, NULL); + }*/ establish_pulse_activities(dbus_interface); return root_menuitem; } +/*static void remove_previous_children(gpointer obj, gpointer user_data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem*)obj; + if(child != NULL){ + dbusmenu_menuitem_child_delete(root_menuitem, child); + } +}*/ void dbus_menu_manager_update_volume(gdouble volume) { @@ -213,7 +228,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service // Sound preferences dialog DbusmenuMenuitem *settings_mi = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(settings_mi, DBUSMENU_MENUITEM_PROP_LABEL, _("Sound Preferences...")); -//_("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); diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 7f3b94b..0aa93b3 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -156,7 +156,9 @@ indicator_sound_init (IndicatorSound *self) IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(self); priv->volume_widget = NULL; - g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); + g_signal_connect(G_OBJECT(self->service), + INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, + G_CALLBACK(connection_changed), self); return; } @@ -307,7 +309,7 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, volume_widget = volume_widget_new (newitem); io = g_object_get_data (G_OBJECT (client), "indicator"); IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(INDICATOR_SOUND (io)); - priv->volume_widget = volume_widget; + priv->volume_widget = volume_widget; GtkWidget* ido_slider_widget = volume_widget_get_ido_slider(VOLUME_WIDGET(priv->volume_widget)); @@ -321,47 +323,65 @@ new_volume_slider_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_item, - parent); - - fetch_mute_value_from_dbus(); - fetch_sink_availability_from_dbus(INDICATOR_SOUND (io)); - + parent); return TRUE; } static void -connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) +connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer user_data) { if (connected) { - if (sound_dbus_proxy == NULL) { - GError * error = NULL; + gboolean service_restart = FALSE; + if (sound_dbus_proxy != NULL) { + g_object_unref (sound_dbus_proxy); + sound_dbus_proxy = NULL; + service_restart = TRUE; + } + GError * error = NULL; - DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + DBusGConnection * sbus = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); - sound_dbus_proxy = dbus_g_proxy_new_for_name_owner(sbus, - INDICATOR_SOUND_DBUS_NAME, - INDICATOR_SOUND_SERVICE_DBUS_OBJECT, - INDICATOR_SOUND_SERVICE_DBUS_INTERFACE, - &error); + sound_dbus_proxy = dbus_g_proxy_new_for_name_owner(sbus, + INDICATOR_SOUND_DBUS_NAME, + INDICATOR_SOUND_SERVICE_DBUS_OBJECT, + INDICATOR_SOUND_SERVICE_DBUS_INTERFACE, + &error); - if (error != NULL) { - g_warning("Unable to get status proxy: %s", error->message); - g_error_free(error); - } - g_debug("about to connect to the signals"); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), userdata, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); - - g_return_if_fail(IS_INDICATOR_SOUND(userdata)); - + if (error != NULL) { + g_warning("Unable to get status proxy: %s", error->message); + g_error_free(error); } + g_debug("about to connect to the signals"); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), user_data, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_update), NULL, NULL); + if( service_restart == TRUE){ + fetch_mute_value_from_dbus(); + // Ensure UI is in sync with service again. + IndicatorSound* indicator = INDICATOR_SOUND(user_data); + fetch_sink_availability_from_dbus(indicator); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + determine_state_from_volume (volume_widget_get_current_volume(priv->volume_widget)); + } + } + else{ + g_warning("Indicator has been disconnected from the service -> SHOCK HORROR"); + IndicatorSound* indicator = INDICATOR_SOUND(user_data); + IndicatorSoundPrivate* priv = INDICATOR_SOUND_GET_PRIVATE(indicator); + + if(priv->volume_widget != NULL){ + g_warning("indicator still has a slider, service must have crashed"); + volume_widget_tidy_up(priv->volume_widget); + g_object_unref(G_OBJECT(priv->volume_widget)); + priv->volume_widget = NULL; + } + device_available = FALSE; + update_state(STATE_SINKS_NONE); } - return; } /* diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 4ff9e1d..f93368e 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -50,8 +50,8 @@ static pa_cvolume construct_mono_volume(const pa_cvolume* vol); /** Future Refactoring notes - - Push all UI updates out through update PA state in the service. - - Collapse 3 update_sink_info into one. The essentially do the same thing from different contexts. + - rewrite in vala. + - make sure all state is kept in the service for volume icon switching. **/ /** @@ -147,7 +147,7 @@ static gboolean determine_sink_availability() // Firstly check to see if we have any sinks // if not get the hell out of here ! if (g_hash_table_size(sink_hash) < 1) { - /* g_debug("Sink_available returning false because sinks_hash is empty !!!"); */ + g_debug("Sink_available returning false because sinks_hash is empty !!!"); DEFAULT_SINK_INDEX = -1; return FALSE; } @@ -163,7 +163,7 @@ static gboolean determine_sink_availability() // Thirdly ensure the default sink index does not have the name "auto_null" sink_info* s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - // Up until now the most rebust method to test this is to manually remove the available sink device + // Up until now the most robust method to test this is to manually remove the available sink device // kernel module and then reload (rmmod & modprobe). // TODO: Edge case of dynamic loading and unloading of sinks should be handled also. /* g_debug("About to test for to see if the available sink is null - s->name = %s", s->name);*/ @@ -211,7 +211,6 @@ static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) if (GPOINTER_TO_INT(user_data) == 1) { sound_service_dbus_update_sink_mute(dbus_service, TRUE); } else { - //sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume()); dbus_menu_manager_update_volume(get_default_sink_volume()); } @@ -411,7 +410,6 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v pa_volume_t vol = pa_cvolume_max(&s->volume); gdouble volume_percent = ((gdouble) vol * 100) / PA_VOLUME_NORM; /* g_debug("Updating volume from PA manager with volume = %f", volume_percent);*/ - //sound_service_dbus_update_sink_volume(dbus_service, volume_percent); dbus_menu_manager_update_volume(volume_percent); } } diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 77c8635..c850cdc 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -88,8 +88,7 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g 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); diff --git a/src/volume-widget.c b/src/volume-widget.c index 5e7cf9f..1cfdcc4 100644 --- a/src/volume-widget.c +++ b/src/volume-widget.c @@ -61,6 +61,7 @@ static void volume_widget_parent_changed (GtkWidget *widget, gpointer user_data) G_DEFINE_TYPE (VolumeWidget, volume_widget, G_TYPE_OBJECT); + static void volume_widget_class_init (VolumeWidgetClass *klass) { @@ -201,8 +202,6 @@ volume_widget_update(VolumeWidget* self, gdouble update) dbusmenu_menuitem_handle_event (priv->twin_item, "update", &value, 0); } - - GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self) { @@ -234,6 +233,24 @@ volume_widget_slider_released(GtkWidget *widget, gpointer user_data) priv->grabbed = FALSE; } +void +volume_widget_tidy_up (GtkWidget *widget) +{ + VolumeWidget* mitem = VOLUME_WIDGET(widget); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + gtk_widget_destroy (priv->ido_volume_slider); +} + +gdouble +volume_widget_get_current_volume ( GtkWidget *widget ) +{ + VolumeWidget* mitem = VOLUME_WIDGET(widget); + VolumeWidgetPrivate * priv = VOLUME_WIDGET_GET_PRIVATE(mitem); + gdouble vol = g_value_get_double ( dbusmenu_menuitem_property_get_value( priv->twin_item, + DBUSMENU_VOLUME_MENUITEM_LEVEL)); + return vol; +} + /** * volume_widget_new: * @returns: a new #VolumeWidget. diff --git a/src/volume-widget.h b/src/volume-widget.h index d4929ec..202bbb3 100644 --- a/src/volume-widget.h +++ b/src/volume-widget.h @@ -47,6 +47,8 @@ GType volume_widget_get_type (void) G_GNUC_CONST; GtkWidget* volume_widget_new(DbusmenuMenuitem* twin_item); GtkWidget* volume_widget_get_ido_slider(VolumeWidget* self); void volume_widget_update(VolumeWidget* self, gdouble update); +void volume_widget_tidy_up (GtkWidget *widget); +gdouble volume_widget_get_current_volume ( GtkWidget *widget ); G_END_DECLS -- cgit v1.2.3 From 21c38af8ec53f8ccdcf5b434b5cda807f27c9a3c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 18:21:32 +0100 Subject: tidy up --- src/sound-service.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/sound-service.c b/src/sound-service.c index 51f5f37..f19379d 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -41,8 +41,8 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown !"); //TODO: uncomment for release !! - //close_pulse_activites(); - //g_main_loop_quit(mainloop); + close_pulse_activites(); + g_main_loop_quit(mainloop); } return; } -- cgit v1.2.3 From bab2f6616d4ad90243d3551513ad9e90c0df692e Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 14 Sep 2010 18:30:03 +0100 Subject: removed redundant code --- src/dbus-menu-manager.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'src') diff --git a/src/dbus-menu-manager.c b/src/dbus-menu-manager.c index 222affa..63e91b4 100644 --- a/src/dbus-menu-manager.c +++ b/src/dbus-menu-manager.c @@ -53,7 +53,6 @@ static gboolean idle_routine (gpointer data); static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service); static void refresh_menu(); -static void remove_previous_children(gpointer obj, gpointer user_data); /*-------------------------------------------------------------------------*/ @@ -74,23 +73,10 @@ DbusmenuMenuitem* dbus_menu_manager_setup() DbusmenuServer *server = dbusmenu_server_new(INDICATOR_SOUND_DBUS_OBJECT); dbusmenu_server_set_root(server, root_menuitem); - - /*GList* previous_children = dbusmenu_menuitem_get_children(root_menuitem); - if(previous_children != NULL){ - g_list_foreach(previous_children, remove_previous_children, NULL); - }*/ establish_pulse_activities(dbus_interface); return root_menuitem; } -/*static void remove_previous_children(gpointer obj, gpointer user_data) -{ - DbusmenuMenuitem *child = (DbusmenuMenuitem*)obj; - if(child != NULL){ - dbusmenu_menuitem_child_delete(root_menuitem, child); - } -}*/ - void dbus_menu_manager_update_volume(gdouble volume) { GValue value = {0}; -- cgit v1.2.3