diff options
-rw-r--r-- | src/common-defs.h | 2 | ||||
-rw-r--r-- | src/mpris-controller.vala | 17 | ||||
-rw-r--r-- | src/player-item.vala | 5 | ||||
-rw-r--r-- | src/scrub-menu-item.vala | 7 | ||||
-rw-r--r-- | src/scrub-widget.c | 66 | ||||
-rw-r--r-- | src/sound-service.c | 1 |
6 files changed, 75 insertions, 23 deletions
diff --git a/src/common-defs.h b/src/common-defs.h index 3b54dd0..76e9558 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -39,6 +39,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define DBUSMENU_TITLE_MENUITEM_NAME "x-canonical-sound-menu-player-title-name" #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-menu-item" -#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-duration" +#define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-time" #define DBUSMENU_SCRUB_MENUITEM_POSITION "x-canonical-sound-menu-player-scrub-position" diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index f40614c..5e4dce2 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -50,23 +50,38 @@ public class MprisController : GLib.Object 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()); + 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()); } - private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> 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()); } public void transport_event(TransportMenuitem.action command) diff --git a/src/player-item.vala b/src/player-item.vala index e7f7c67..4bdb60d 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -38,6 +38,7 @@ public class PlayerItem : Dbusmenu.Menuitem foreach(string s in attrs){ debug("attempting to set prop %s to null", s); this.property_set(s, null); + this.property_set_int(s, 0); } } @@ -73,6 +74,10 @@ 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 (bool))){ this.property_set_bool(property, v.get_boolean()); } diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index 9988378..cfd6312 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -25,7 +25,6 @@ public class ScrubMenuitem : PlayerItem { public ScrubMenuitem(PlayerController parent) { - debug("Transport object constructor - service side"); Object(item_type: MENUITEM_TYPE, owner: parent); } @@ -34,6 +33,12 @@ public class ScrubMenuitem : PlayerItem 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()); } + + public void update_position(int32 new_position) + { + this.property_set_int(MENUITEM_POSITION, new_position); + } + public static HashSet<string> attributes_format() { diff --git a/src/scrub-widget.c b/src/scrub-widget.c index 4595ede..799f81e 100644 --- a/src/scrub-widget.c +++ b/src/scrub-widget.c @@ -32,7 +32,6 @@ struct _ScrubWidgetPrivate { DbusmenuMenuitem* twin_item; GtkWidget* ido_scrub_bar; - GtkStyle* style; }; #define SCRUB_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SCRUB_WIDGET_TYPE, ScrubWidgetPrivate)) @@ -46,8 +45,10 @@ static void scrub_widget_property_update( DbusmenuMenuitem* item, gchar* propert GValue* value, gpointer userdata); static void scrub_widget_set_twin_item( ScrubWidget* self, DbusmenuMenuitem* twin_item); -static void scrub_widget_parent_changed ( GtkWidget *widget, gpointer user_data); static gchar* scrub_widget_format_time(gint time); +static void scrub_widget_set_ido_position(ScrubWidget* self, + gint position, + gint duration); static gboolean scrub_widget_change_value_cb (GtkRange *range, GtkScrollType scroll, gdouble value, @@ -76,13 +77,8 @@ scrub_widget_init (ScrubWidget *self) priv->ido_scrub_bar = ido_scale_menu_item_new_with_range ("Scrub", 0, 0, 100, 1); ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), IDO_SCALE_MENU_ITEM_STYLE_LABEL); - ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), "00:00"); - ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), "05:35"); + g_object_set(priv->ido_scrub_bar, "reverse-scroll-events", TRUE, NULL); - - //g_signal_connect (priv->ido_scrub_bar, - // "notify::parent", G_CALLBACK (scrub_widget_parent_changed), - // NULL); // register slider changes listening on the range GtkWidget* scrub_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); @@ -103,30 +99,30 @@ scrub_widget_finalize (GObject *object) static void scrub_widget_property_update(DbusmenuMenuitem* item, gchar* property, - GValue* value, gpointer userdata) + GValue* value, gpointer userdata) { + g_debug("scrub-widget::property_update"); + g_return_if_fail (IS_SCRUB_WIDGET (userdata)); ScrubWidget* mitem = SCRUB_WIDGET(userdata); ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_DURATION, property) == 0){ + g_debug("scrub-widget::update length = %i", g_value_get_int(value)); ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), scrub_widget_format_time(g_value_get_int(value))); } else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_POSITION, property) == 0){ + g_debug("scrub-widget::update position = %i", g_value_get_int(value)); ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), - scrub_widget_format_time(g_value_get_int(value))); + scrub_widget_format_time(g_value_get_int(value)/1000)); } + scrub_widget_set_ido_position(mitem, + 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 void -scrub_widget_parent_changed (GtkWidget *widget, - gpointer user_data) -{ - gtk_widget_set_size_request (widget, 200, -1); - g_debug("slider parent changed"); -}*/ - static void scrub_widget_set_twin_item(ScrubWidget* self, DbusmenuMenuitem* twin_item) @@ -136,6 +132,19 @@ scrub_widget_set_twin_item(ScrubWidget* self, g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(scrub_widget_property_update), self); + + gchar* left_text = scrub_widget_format_time(dbusmenu_menuitem_property_get_int(priv->twin_item, + DBUSMENU_SCRUB_MENUITEM_POSITION)/1000); + gchar* right_text = scrub_widget_format_time(dbusmenu_menuitem_property_get_int(priv->twin_item, + DBUSMENU_SCRUB_MENUITEM_DURATION)); + scrub_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)); + + ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), left_text); + ido_scale_menu_item_set_secondary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), right_text); + g_free(left_text); + g_free(right_text); } static gboolean @@ -171,10 +180,29 @@ scrub_widget_format_time(gint time) gint minutes = time/60; gint seconds = time % 60; gchar* prefix="0"; + gchar* seconds_prefix="0"; if(minutes > 9) prefix=""; - return g_strdup_printf("%s%i:%i", prefix, minutes, seconds); + if(seconds > 9) + seconds_prefix=""; + return g_strdup_printf("%s%i:%s%i", prefix, minutes, seconds_prefix, seconds); } + +static void +scrub_widget_set_ido_position(ScrubWidget* self, + gint position, + gint duration) +{ + ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); + gdouble ido_position = position/(gdouble)duration * 100.0; + g_debug("scrub_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_scrub_bar); + GtkRange *range = (GtkRange*)slider; + if(duration == 0) + ido_position = 0.0; + gtk_range_set_value(range, ido_position); +} + /** * scrub_widget_new: diff --git a/src/sound-service.c b/src/sound-service.c index 8f4e941..8768cd3 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -39,7 +39,6 @@ should follow it. void service_shutdown (IndicatorService *service, gpointer user_data) { - if (mainloop != NULL) { g_debug("Service shutdown !"); // TODO: uncomment for release !! |