diff options
-rw-r--r-- | src/common-defs.h | 1 | ||||
-rw-r--r-- | src/metadata-menu-item.vala | 6 | ||||
-rw-r--r-- | src/mpris-controller.vala | 14 | ||||
-rw-r--r-- | src/music-player-bridge.vala | 7 | ||||
-rw-r--r-- | src/play-button.c | 5 | ||||
-rw-r--r-- | src/player-controller.vala | 13 | ||||
-rw-r--r-- | src/player-item.vala | 4 | ||||
-rw-r--r-- | src/scrub-menu-item.vala | 4 | ||||
-rw-r--r-- | src/scrub-widget.c | 178 | ||||
-rw-r--r-- | src/transport-menu-item.vala | 1 | ||||
-rw-r--r-- | vapi/common-defs.vapi | 1 |
11 files changed, 193 insertions, 41 deletions
diff --git a/src/common-defs.h b/src/common-defs.h index 76e9558..208c8cb 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -41,4 +41,5 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #define DBUSMENU_SCRUB_MENUITEM_TYPE "x-canonical-sound-menu-player-scrub-menu-item" #define DBUSMENU_SCRUB_MENUITEM_DURATION "x-canonical-sound-menu-player-scrub-time" #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 3af9ff1..388ef81 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -38,10 +38,10 @@ public class MetadataMenuitem : PlayerItem return attrs; } - public bool populated() + public bool not_populated() { - return (this.property_get(MENUITEM_TITLE) != null && - this.property_get(MENUITEM_TITLE) != ""); + return (this.property_get(MENUITEM_TITLE) == null && + this.property_get(MENUITEM_TITLE) == ""); } }
\ No newline at end of file diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index 8e43131..8ecd20a 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -65,8 +65,7 @@ public class MprisController : GLib.Object 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.mpris_player.PositionGet()); } public void transport_event(TransportMenuitem.action command) @@ -86,7 +85,7 @@ public class MprisController : GLib.Object public void set_position(double position) { - //debug("Set position with pos (0-100) %f", position); + debug("Set position with pos (0-100) %f", position); HashTable<string, Value?> data = this.mpris_player.GetMetadata(); Value? time_value = data.lookup("time"); if(time_value == null){ @@ -94,10 +93,12 @@ public class MprisController : GLib.Object return; } uint32 total_time = time_value.get_uint(); - //debug("total time of track = %i", (int)total_time); + 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 * 1000)); + 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,6 +118,7 @@ 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<string,Value?> ht) diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 3ee7b55..352ea7f 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -35,7 +35,7 @@ public class MusicPlayerBridge : GLib.Object playersDB = new FamiliarPlayersDB(); registered_clients = new HashMap<string, PlayerController> (); listener = Listener.ref_default(); - listener.indicator_added.connect(on_indicator_added); + listener.indicator_added += on_indicator_added; listener.indicator_removed.connect(on_indicator_removed); listener.indicator_modified.connect(on_indicator_modified); listener.server_added.connect(on_server_added); @@ -99,8 +99,7 @@ public class MusicPlayerBridge : GLib.Object client_name, calculate_menu_position(), PlayerController.state.READY); - registered_clients.set(client_name, ctrl); - + registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } // irregardless check that it has a desktop file if not kick off a request for it @@ -162,7 +161,7 @@ public class MusicPlayerBridge : GLib.Object { debug("MusicPlayerBridge-> on_server_count_changed with value %u", i); } - public void on_indicator_added(Indicate.ListenerServer object, Indicate.ListenerIndicator p0) + public void on_indicator_added(ListenerServer object, ListenerIndicator p0) { debug("MusicPlayerBridge-> on_indicator_added"); } diff --git a/src/play-button.c b/src/play-button.c index 539b2b2..1aeff12 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -328,7 +328,7 @@ play_button_init (PlayButton *self) priv->command_coordinates = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, - g_list_free); + (GDestroyNotify)g_list_free); GList* previous_list = NULL; previous_list = g_list_insert(previous_list, GINT_TO_POINTER(15), 0); previous_list = g_list_insert(previous_list, GINT_TO_POINTER(10), 1); @@ -939,7 +939,6 @@ draw (GtkWidget* button, cairo_t *cr) BUTTON_SHADOW, BUTTON_SHADOW, FALSE); - cairo_surface_write_to_png(surf, "/tmp/drop_shadow.png"); _surface_blur (surf, 1); _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y + 1.0f); // draw play-button @@ -960,8 +959,6 @@ draw (GtkWidget* button, cairo_t *cr) BUTTON_START, BUTTON_END, FALSE); - cairo_surface_write_to_png(surf, "/tmp/play.png"); - _finalize (cr, &cr_surf, &surf, PAUSE_X, PAUSE_Y); } diff --git a/src/player-controller.vala b/src/player-controller.vala index 48416b9..f824d6f 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -60,13 +60,14 @@ public class PlayerController : GLib.Object this.menu_offset = offset; construct_widgets(); establish_mpris_connection(); - update_layout(); + this.update_layout(); } public void update_state(state new_state) { debug("update_state - player controller %s : new state %i", this.name, new_state); this.current_state = new_state; + //this.update_layout(); } public void activate() @@ -125,10 +126,12 @@ public class PlayerController : GLib.Object } } - private void update_layout() + public void update_layout() { bool visibility = true; - if(this.current_state != state.CONNECTED){ + MetadataMenuitem meta_item = this.custom_items[widget_order.METADATA] as MetadataMenuitem; + if(this.current_state != state.CONNECTED /*|| + meta_item.not_populated()*/){ visibility = false; } debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string()); @@ -136,8 +139,8 @@ public class PlayerController : GLib.Object this.custom_items[widget_order.SCRUB].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); this.custom_items[widget_order.METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); // DEBUG - if(this.mpris_adaptor == null){ - warning("Why is the mpris object null"); + if(visibility == false){ + warning("Update layout of client %s is setting widgets to invisibile!", this.name); } } diff --git a/src/player-item.vala b/src/player-item.vala index 4bdb60d..2952f71 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -89,10 +89,10 @@ public class PlayerItem : Dbusmenu.Menuitem if(data == null){ return false; } - if(data.size() < attributes.size){ + /*if(data.size() < attributes.size){ warning("update hash was too small for the target"); return false; - } + }*/ return true; } diff --git a/src/scrub-menu-item.vala b/src/scrub-menu-item.vala index cfd6312..29fa903 100644 --- a/src/scrub-menu-item.vala +++ b/src/scrub-menu-item.vala @@ -37,14 +37,14 @@ public class ScrubMenuitem : PlayerItem public void update_position(int32 new_position) { this.property_set_int(MENUITEM_POSITION, new_position); - } - + } public static HashSet<string> attributes_format() { HashSet<string> attrs = new HashSet<string>(); attrs.add(MENUITEM_DURATION); attrs.add(MENUITEM_POSITION); + attrs.add(MENUITEM_PLAY_STATE); return attrs; } }
\ No newline at end of file diff --git a/src/scrub-widget.c b/src/scrub-widget.c index dbbbdf3..fa290e0 100644 --- a/src/scrub-widget.c +++ b/src/scrub-widget.c @@ -25,6 +25,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "scrub-widget.h" #include "common-defs.h" #include <libido/idoscalemenuitem.h> +#include <libido/idotimeline.h> typedef struct _ScrubWidgetPrivate ScrubWidgetPrivate; @@ -32,6 +33,8 @@ struct _ScrubWidgetPrivate { DbusmenuMenuitem* twin_item; GtkWidget* ido_scrub_bar; + IdoTimeline* time_line; + gboolean scrubbing; }; #define SCRUB_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SCRUB_WIDGET_TYPE, ScrubWidgetPrivate)) @@ -54,6 +57,19 @@ static gboolean scrub_widget_change_value_cb (GtkRange *range, gdouble value, gpointer user_data); +static void scrub_widget_timeline_frame_cb(IdoTimeline *timeline, + gdouble progress, + gpointer userdata); +static void scrub_widget_timeline_started_cb(IdoTimeline *timeline, + gpointer userdata); +static void scrub_widget_timeline_finished_cb(IdoTimeline *timeline, + gpointer userdata); +static gdouble scrub_widget_calculate_progress(ScrubWidget* widget); +static void scrub_widget_check_play_state(ScrubWidget* self); +static void scrub_widget_slider_grabbed(GtkWidget *widget, gpointer user_data); +static void scrub_widget_slider_released(GtkWidget *widget, gpointer user_data); + + G_DEFINE_TYPE (ScrubWidget, scrub_widget, G_TYPE_OBJECT); @@ -68,7 +84,6 @@ scrub_widget_class_init (ScrubWidgetClass *klass) gobject_class->finalize = scrub_widget_finalize; } - static void scrub_widget_init (ScrubWidget *self) { @@ -76,13 +91,20 @@ scrub_widget_init (ScrubWidget *self) ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(self); priv->ido_scrub_bar = ido_scale_menu_item_new_with_range ("Scrub", IDO_RANGE_STYLE_SMALL, 0, 0, 100, 1); - ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), IDO_SCALE_MENU_ITEM_STYLE_LABEL); + priv->time_line = ido_timeline_new(0); + ido_scale_menu_item_set_style (IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), IDO_SCALE_MENU_ITEM_STYLE_LABEL); g_object_set(priv->ido_scrub_bar, "reverse-scroll-events", TRUE, NULL); + priv->scrubbing = FALSE; // register slider changes listening on the range GtkWidget* scrub_widget = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); g_signal_connect(scrub_widget, "change-value", G_CALLBACK(scrub_widget_change_value_cb), self); + g_signal_connect(priv->time_line, "frame", G_CALLBACK(scrub_widget_timeline_frame_cb), self); + g_signal_connect(priv->time_line, "started", G_CALLBACK(scrub_widget_timeline_started_cb), self); + g_signal_connect(priv->time_line, "finished", G_CALLBACK(scrub_widget_timeline_finished_cb), self); + g_signal_connect(priv->ido_scrub_bar, "slider-grabbed", G_CALLBACK(scrub_widget_slider_grabbed), self); + g_signal_connect(priv->ido_scrub_bar, "slider-released", G_CALLBACK(scrub_widget_slider_released), self); } static void @@ -110,17 +132,50 @@ scrub_widget_property_update(DbusmenuMenuitem* item, gchar* property, 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))); + scrub_widget_format_time(g_value_get_int(value))); + + ido_timeline_set_duration(priv->time_line, g_value_get_int(value) * 1000); + ido_timeline_rewind(priv->time_line); + scrub_widget_check_play_state(mitem); + g_debug("timeline is running: %i", (gint)ido_timeline_is_running(priv->time_line)); + g_debug("timeline duration = %i", ido_timeline_get_duration(priv->time_line)); + + 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)); } else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_POSITION, property) == 0){ g_debug("scrub-widget::update position = %i", g_value_get_int(value)); + ido_timeline_pause(priv->time_line); ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), 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)); + + ido_timeline_set_progress(priv->time_line, scrub_widget_calculate_progress(mitem)*1000); + scrub_widget_set_ido_position(mitem, g_value_get_int(value)/1000, + dbusmenu_menuitem_property_get_int(priv->twin_item, DBUSMENU_SCRUB_MENUITEM_DURATION)); + ido_timeline_start(priv->time_line); + + } + else if(g_ascii_strcasecmp(DBUSMENU_SCRUB_MENUITEM_PLAY_STATE, property) == 0){ + scrub_widget_check_play_state(mitem); + } +} + +static void +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); + if(play_state == 0){ + g_debug("START TIMELINE"); + ido_timeline_start(priv->time_line); + } + else{ + g_debug("PAUSE TIMELINE"); + ido_timeline_pause(priv->time_line); + } } static void @@ -133,13 +188,12 @@ 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* 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)); + 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); @@ -153,7 +207,7 @@ scrub_widget_change_value_cb (GtkRange *range, gdouble new_value, gpointer user_data) { - g_return_val_if_fail (IS_SCRUB_WIDGET (user_data), FALSE); + /*g_return_val_if_fail (IS_SCRUB_WIDGET (user_data), FALSE); ScrubWidget* mitem = SCRUB_WIDGET(user_data); ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); @@ -161,8 +215,13 @@ scrub_widget_change_value_cb (GtkRange *range, g_value_init(&value, G_TYPE_DOUBLE); gdouble clamped = CLAMP(new_value, 0, 100); g_value_set_double(&value, clamped); - g_debug("scrub-widget-change-value callback - = %f", clamped); - dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0); + //g_debug("scrub-widget-change-value callback - = %f", clamped); + if(priv->scrubbing == FALSE){ + dbusmenu_menuitem_handle_event (priv->twin_item, "scrubbing", &value, 0); + } + else{ + g_debug("blocking scrubbing because the slider is still grabbed" + }*/ return FALSE; } @@ -203,8 +262,96 @@ scrub_widget_set_ido_position(ScrubWidget* self, gtk_range_set_value(range, ido_position); } +static gdouble +scrub_widget_calculate_progress(ScrubWidget* widget) +{ + ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(widget); + gint position = dbusmenu_menuitem_property_get_int(priv->twin_item, + DBUSMENU_SCRUB_MENUITEM_POSITION)/1000; + gint duration = dbusmenu_menuitem_property_get_int(priv->twin_item, + DBUSMENU_SCRUB_MENUITEM_DURATION); + gdouble ido_position = position/(gdouble)duration; + g_debug("scrub_widget_calculate_progress %f", ido_position); + + return ido_position; +} + + +static void +scrub_widget_timeline_frame_cb( IdoTimeline *timeline, + gdouble progress, + gpointer user_data) +{ + + //g_debug("Timeline CB : %f", progress); + g_return_if_fail (IS_SCRUB_WIDGET (user_data)); + ScrubWidget* mitem = SCRUB_WIDGET(user_data); + ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); + if(priv->scrubbing == TRUE) + { + //g_debug("don't update the slider or timeline, slider is being scrubbed"); + return; + } + gint position = progress * dbusmenu_menuitem_property_get_int(priv->twin_item, + DBUSMENU_SCRUB_MENUITEM_DURATION); + gchar* left_text = scrub_widget_format_time(position); + ido_scale_menu_item_set_primary_label(IDO_SCALE_MENU_ITEM(priv->ido_scrub_bar), left_text); + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); + GtkRange *range = (GtkRange*)slider; + gtk_range_set_value(range, progress * 100); + + /*g_debug("position in seconds %i and in words %s", position, left_text); + g_debug("timeline is running: %i", (gint)ido_timeline_is_running(priv->time_line)); + g_debug("timeline duration = %i", ido_timeline_get_duration(priv->time_line)); + */ + g_free(left_text); +} + + +static void +scrub_widget_slider_released(GtkWidget *widget, gpointer user_data) +{ + ScrubWidget* mitem = SCRUB_WIDGET(user_data); + ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); + priv->scrubbing = FALSE; + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)priv->ido_scrub_bar); + 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, "scrubbing", &value, 0); +} + +static void +scrub_widget_slider_grabbed(GtkWidget *widget, gpointer user_data) +{ + ScrubWidget* mitem = SCRUB_WIDGET(user_data); + ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); + priv->scrubbing = TRUE; + +} + +static void +scrub_widget_timeline_started_cb( IdoTimeline *timeline, + gpointer user_data) +{ + g_debug("Timeline Started!"); +} - /** +static void +scrub_widget_timeline_finished_cb(IdoTimeline *timeline, + gpointer user_data) +{ + g_debug("Timeline Finished!"); + /*g_return_if_fail (IS_SCRUB_WIDGET (user_data)); + ScrubWidget* mitem = SCRUB_WIDGET(user_data); + ScrubWidgetPrivate * priv = SCRUB_WIDGET_GET_PRIVATE(mitem); + ido_timeline_rewind(priv->time_line);*/ +} + +/** * scrub_widget_new: * @returns: a new #ScrubWidget. **/ @@ -216,3 +363,4 @@ scrub_widget_new(DbusmenuMenuitem *item) return widget; } + diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 8e837c2..3d6dcdd 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -32,6 +32,7 @@ public class TransportMenuitem : PlayerItem public TransportMenuitem(PlayerController parent) { Object(item_type: MENUITEM_TYPE, owner: parent); + this.property_set_int(MENUITEM_PLAY_STATE, 1); } public void change_play_state(int state) diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index 24344ce..c083e2a 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -43,4 +43,5 @@ namespace DbusmenuScrub{ public const string MENUITEM_TYPE; public const string MENUITEM_POSITION; public const string MENUITEM_DURATION; + public const string MENUITEM_PLAY_STATE; }
\ No newline at end of file |