diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/indicator-sound.c | 3 | ||||
-rw-r--r-- | src/metadata-widget.c | 59 | ||||
-rw-r--r-- | src/mpris2-controller.c | 90 | ||||
-rw-r--r-- | src/mpris2-controller.vala | 12 | ||||
-rw-r--r-- | src/music-player-bridge.c | 101 | ||||
-rw-r--r-- | src/music-player-bridge.vala | 24 | ||||
-rw-r--r-- | src/play-button.c | 264 |
7 files changed, 435 insertions, 118 deletions
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/metadata-widget.c b/src/metadata-widget.c index 18ebd38..7179014 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,7 @@ metadata_widget_finalize (GObject *object) G_OBJECT_CLASS (metadata_widget_parent_class)->finalize (object); } + /** * We override the expose method to enable primitive drawing of the * empty album art image and rounded rectangles on the album art. @@ -188,7 +187,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 +217,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 +238,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 +264,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 +500,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/mpris2-controller.c b/src/mpris2-controller.c index ff75bd2..54e905d 100644 --- a/src/mpris2-controller.c +++ b/src/mpris2-controller.c @@ -4658,6 +4658,18 @@ Mpris2Controller* mpris2_controller_new (PlayerController* ctrl) { } +static char* bool_to_string (gboolean self) { + char* result = NULL; + if (self) { + result = g_strdup ("true"); + return result; + } else { + result = g_strdup ("false"); + return result; + } +} + + static GValue* _g_value_dup (GValue* self) { return g_boxed_copy (G_TYPE_VALUE, self); } @@ -4676,23 +4688,27 @@ static void _vala_GValue_free (GValue* self) { void mpris2_controller_property_changed_cb (Mpris2Controller* self, const char* interface_source, GHashTable* changed_properties, char** invalid, int invalid_length1) { char* _tmp0_; - gboolean _tmp1_ = FALSE; + char* _tmp1_; + gboolean _tmp2_ = FALSE; GValue* play_v; GValue* pos_v; GValue* meta_v; g_return_if_fail (self != NULL); g_return_if_fail (interface_source != NULL); g_return_if_fail (changed_properties != NULL); - g_debug ("mpris2-controller.vala:99: properties-changed for interface %s and own" \ -"er %s", interface_source, _tmp0_ = g_utf8_strdown (player_controller_get_name (self->priv->_owner), -1)); + g_debug ("mpris2-controller.vala:100: properties-changed for interface %s and ow" \ +"ner %s", interface_source, _tmp0_ = g_utf8_strdown (player_controller_get_name (self->priv->_owner), -1)); _g_free0 (_tmp0_); + g_debug ("mpris2-controller.vala:101: is the invalid array null : %s", _tmp1_ = bool_to_string (invalid == NULL)); + _g_free0 (_tmp1_); + g_debug ("mpris2-controller.vala:102: invalid length : %i", invalid_length1); if (changed_properties == NULL) { - _tmp1_ = TRUE; + _tmp2_ = TRUE; } else { - _tmp1_ = g_str_has_prefix (interface_source, MPRIS2_CONTROLLER_root_interface) == FALSE; + _tmp2_ = g_str_has_prefix (interface_source, MPRIS2_CONTROLLER_root_interface) == FALSE; } - if (_tmp1_) { - g_warning ("mpris2-controller.vala:101: Property-changed hash is null or this is a" \ + if (_tmp2_) { + g_warning ("mpris2-controller.vala:105: Property-changed hash is null or this is a" \ "n interface that concerns us"); return; } @@ -4700,35 +4716,35 @@ void mpris2_controller_property_changed_cb (Mpris2Controller* self, const char* if (play_v != NULL) { char* state; TransportMenuitemstate p; - PlayerItem* _tmp2_; - TransportMenuitem* _tmp3_; + PlayerItem* _tmp3_; + TransportMenuitem* _tmp4_; state = g_strdup (g_value_get_string (play_v)); - g_debug ("mpris2-controller.vala:107: new playback state = %s", state); + g_debug ("mpris2-controller.vala:111: new playback state = %s", state); p = (TransportMenuitemstate) mpris2_controller_determine_play_state (self, state); - transport_menuitem_change_play_state (_tmp3_ = (_tmp2_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp2_) ? ((TransportMenuitem*) _tmp2_) : NULL), p); - _g_object_unref0 (_tmp3_); + transport_menuitem_change_play_state (_tmp4_ = (_tmp3_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp3_) ? ((TransportMenuitem*) _tmp3_) : NULL), p); + _g_object_unref0 (_tmp4_); _g_free0 (state); } pos_v = __g_value_dup0 ((GValue*) g_hash_table_lookup (changed_properties, "Position")); if (pos_v != NULL) { gint64 pos; pos = g_value_get_int64 (pos_v); - g_debug ("mpris2-controller.vala:115: new position = %i", (gint) pos); + g_debug ("mpris2-controller.vala:119: new position = %i", (gint) pos); } meta_v = __g_value_dup0 ((GValue*) g_hash_table_lookup (changed_properties, "Metadata")); if (meta_v != NULL) { GHashTable* changed_updates; - PlayerItem* _tmp4_; - GeeHashSet* _tmp5_; - PlayerItem* _tmp6_; - GeeHashSet* _tmp7_; + PlayerItem* _tmp5_; + GeeHashSet* _tmp6_; + PlayerItem* _tmp7_; + GeeHashSet* _tmp8_; changed_updates = mpris2_controller_clean_metadata (self); - player_item_reset (_tmp4_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_METADATA), _tmp5_ = metadata_menuitem_attributes_format ()); + player_item_reset (_tmp5_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_METADATA), _tmp6_ = metadata_menuitem_attributes_format ()); + _g_object_unref0 (_tmp6_); _g_object_unref0 (_tmp5_); - _g_object_unref0 (_tmp4_); - player_item_update (_tmp6_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_METADATA), changed_updates, _tmp7_ = metadata_menuitem_attributes_format ()); + player_item_update (_tmp7_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_METADATA), changed_updates, _tmp8_ = metadata_menuitem_attributes_format ()); + _g_object_unref0 (_tmp8_); _g_object_unref0 (_tmp7_); - _g_object_unref0 (_tmp6_); _g_hash_table_unref0 (changed_updates); } __vala_GValue_free0 (meta_v); @@ -4773,7 +4789,7 @@ static GHashTable* mpris2_controller_clean_metadata (Mpris2Controller* self) { artists = (_tmp5_ = (_tmp4_ = (_tmp3_ = g_value_get_boxed ((GValue*) g_hash_table_lookup (_tmp2_ = mpris_player_get_Metadata (self->priv->_player), "xesam:artist")), (_tmp3_ == NULL) ? ((gpointer) _tmp3_) : _vala_array_dup1 (_tmp3_, g_strv_length (g_value_get_boxed ((GValue*) g_hash_table_lookup (_tmp2_ = mpris_player_get_Metadata (self->priv->_player), "xesam:artist"))))), _g_hash_table_unref0 (_tmp2_), _tmp4_), artists_length1 = g_strv_length (g_value_get_boxed ((GValue*) g_hash_table_lookup (_tmp2_ = mpris_player_get_Metadata (self->priv->_player), "xesam:artist"))), _artists_size_ = artists_length1, _tmp5_); display_artists = g_strjoinv (", ", artists); g_hash_table_replace (changed_updates, g_strdup ("xesam:artist"), (_tmp6_ = g_new0 (GValue, 1), g_value_init (_tmp6_, G_TYPE_STRING), g_value_set_string (_tmp6_, display_artists), _tmp6_)); - g_debug ("mpris2-controller.vala:135: artist : %s", display_artists); + g_debug ("mpris2-controller.vala:139: artist : %s", display_artists); _g_free0 (display_artists); artists = (_vala_array_free (artists, artists_length1, (GDestroyNotify) g_free), NULL); } @@ -4808,7 +4824,7 @@ static TransportMenuitemstate mpris2_controller_determine_play_state (Mpris2Cont _tmp0_ = FALSE; } if (_tmp0_) { - g_debug ("mpris2-controller.vala:151: determine play state - state = %s", status); + g_debug ("mpris2-controller.vala:155: determine play state - state = %s", status); result = TRANSPORT_MENUITEM_STATE_PLAYING; return result; } @@ -4834,7 +4850,7 @@ void mpris2_controller_initial_update (Mpris2Controller* self) { update = mpris2_controller_determine_play_state (self, _tmp2_ = mpris_player_get_PlaybackStatus (self->priv->_player)); _g_free0 (_tmp2_); } - g_debug ("mpris2-controller.vala:166: initial update - play state %i", (gint) update); + g_debug ("mpris2-controller.vala:170: initial update - play state %i", (gint) update); transport_menuitem_change_play_state (_tmp4_ = (_tmp3_ = (PlayerItem*) gee_abstract_list_get ((GeeAbstractList*) self->priv->_owner->custom_items, (gint) PLAYER_CONTROLLER_WIDGET_ORDER_TRANSPORT), IS_TRANSPORT_MENUITEM (_tmp3_) ? ((TransportMenuitem*) _tmp3_) : NULL), update); _g_object_unref0 (_tmp4_); cleaned_metadata = mpris2_controller_clean_metadata (self); @@ -4848,9 +4864,9 @@ void mpris2_controller_initial_update (Mpris2Controller* self) { void mpris2_controller_transport_update (Mpris2Controller* self, TransportMenuitemaction command) { GError * _inner_error_ = NULL; g_return_if_fail (self != NULL); - g_debug ("mpris2-controller.vala:176: transport_event input = %i", (gint) command); + g_debug ("mpris2-controller.vala:180: transport_event input = %i", (gint) command); if (command == TRANSPORT_MENUITEM_ACTION_PLAY_PAUSE) { - g_debug ("mpris2-controller.vala:178: transport_event PLAY_PAUSE"); + g_debug ("mpris2-controller.vala:182: transport_event PLAY_PAUSE"); { mpris_player_PlayPause (self->priv->_player, &_inner_error_); if (_inner_error_ != NULL) { @@ -4869,7 +4885,7 @@ void mpris2_controller_transport_update (Mpris2Controller* self, TransportMenuit _error_ = _inner_error_; _inner_error_ = NULL; { - g_warning ("mpris2-controller.vala:183: DBus Error calling the player objects Play" \ + g_warning ("mpris2-controller.vala:187: DBus Error calling the player objects Play" \ "Pause method %s", _error_->message); _g_error_free0 (_error_); } @@ -4900,7 +4916,7 @@ void mpris2_controller_transport_update (Mpris2Controller* self, TransportMenuit _error_ = _inner_error_; _inner_error_ = NULL; { - g_warning ("mpris2-controller.vala:192: DBus Error calling the player objects Prev" \ + g_warning ("mpris2-controller.vala:196: DBus Error calling the player objects Prev" \ "ious method %s", _error_->message); _g_error_free0 (_error_); } @@ -4931,7 +4947,7 @@ void mpris2_controller_transport_update (Mpris2Controller* self, TransportMenuit _error_ = _inner_error_; _inner_error_ = NULL; { - g_warning ("mpris2-controller.vala:201: DBus Error calling the player objects Next" \ + g_warning ("mpris2-controller.vala:205: DBus Error calling the player objects Next" \ " method %s", _error_->message); _g_error_free0 (_error_); } @@ -4963,18 +4979,18 @@ void mpris2_controller_set_track_position (Mpris2Controller* self, double positi GValue* v; GError * _inner_error_ = NULL; g_return_if_fail (self != NULL); - g_debug ("mpris2-controller.vala:212: Set position with pos (0-100) %f", position); + g_debug ("mpris2-controller.vala:216: Set position with pos (0-100) %f", position); time_value = (_tmp1_ = __g_value_dup0 ((GValue*) g_hash_table_lookup (_tmp0_ = mpris_player_get_Metadata (self->priv->_player), "mpris:length")), _g_hash_table_unref0 (_tmp0_), _tmp1_); if (time_value == NULL) { - g_warning ("mpris2-controller.vala:215: Can't fetch the duration of the track ther" \ + g_warning ("mpris2-controller.vala:219: Can't fetch the duration of the track ther" \ "efore cant set the position"); __vala_GValue_free0 (time_value); return; } total_time = g_value_get_int64 (time_value); - g_debug ("mpris2-controller.vala:220: total time of track = %i", (gint) total_time); + g_debug ("mpris2-controller.vala:224: total time of track = %i", (gint) total_time); new_time_position = total_time * (position / 100.0); - g_debug ("mpris2-controller.vala:222: new position = %f", new_time_position); + g_debug ("mpris2-controller.vala:226: new position = %f", new_time_position); v = (_tmp3_ = __g_value_dup0 ((GValue*) g_hash_table_lookup (_tmp2_ = mpris_player_get_Metadata (self->priv->_player), "mpris:trackid")), _g_hash_table_unref0 (_tmp2_), _tmp3_); if (v != NULL) { if (G_VALUE_HOLDS (v, G_TYPE_STRING)) { @@ -5001,7 +5017,7 @@ void mpris2_controller_set_track_position (Mpris2Controller* self, double positi e = _inner_error_; _inner_error_ = NULL; { - g_error ("mpris2-controller.vala:232: DBus Error calling the player objects SetP" \ + g_error ("mpris2-controller.vala:236: DBus Error calling the player objects SetP" \ "osition method %s", e->message); _g_error_free0 (e); } @@ -5025,7 +5041,7 @@ void mpris2_controller_set_track_position (Mpris2Controller* self, double positi void mpris2_controller_onSeeked (Mpris2Controller* self, gint64 position) { g_return_if_fail (self != NULL); - g_debug ("mpris2-controller.vala:240: Seeked signal callback with pos = %i", ((gint) position) / 1000); + g_debug ("mpris2-controller.vala:244: Seeked signal callback with pos = %i", ((gint) position) / 1000); } @@ -5083,7 +5099,7 @@ void mpris2_controller_expose (Mpris2Controller* self) { e = _inner_error_; _inner_error_ = NULL; { - g_error ("mpris2-controller.vala:263: Exception thrown while calling function Ra" \ + g_error ("mpris2-controller.vala:267: Exception thrown while calling function Ra" \ "ise - %s", e->message); _g_error_free0 (e); } @@ -5255,7 +5271,7 @@ static GObject * mpris2_controller_constructor (GType type, guint n_construct_pr e = _inner_error_; _inner_error_ = NULL; { - g_error ("mpris2-controller.vala:93: Problems connecting to the session bus - %s", e->message); + g_error ("mpris2-controller.vala:94: Problems connecting to the session bus - %s", e->message); _g_error_free0 (e); } } 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<string, Value?> changed_properties, string[] invalid); + public signal void PropertiesChanged(string source, HashTable<string, + Value?> 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<string, Value?> 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.c b/src/music-player-bridge.c index 0f513ae..f139738 100644 --- a/src/music-player-bridge.c +++ b/src/music-player-bridge.c @@ -125,15 +125,17 @@ void music_player_bridge_on_server_count_changed (MusicPlayerBridge* self, Indic static void _music_player_bridge_on_server_count_changed_indicate_listener_server_count_changed (IndicateListener* _sender, IndicateListenerServer* object, guint p0, gpointer self); static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlayerBridge* self); GeeSet* familiar_players_db_records (FamiliarPlayersDB* self); +static char* music_player_bridge_truncate_player_name (const char* app_info_name); static gint music_player_bridge_calculate_menu_position (MusicPlayerBridge* self); GType player_controller_state_get_type (void) G_GNUC_CONST; PlayerController* player_controller_new (DbusmenuMenuitem* root, const char* client_name, gint offset, PlayerControllerstate initial_state); PlayerController* player_controller_construct (GType object_type, DbusmenuMenuitem* root, const char* client_name, gint offset, PlayerControllerstate initial_state); +void player_controller_set_app_info (PlayerController* self, GAppInfo* value); +GAppInfo* player_controller_get_app_info (PlayerController* self); #define PLAYER_CONTROLLER_WIDGET_QUANTITY 4 static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge* self, const char* type); void player_controller_update_state (PlayerController* self, PlayerControllerstate new_state); void player_controller_activate (PlayerController* self); -GAppInfo* player_controller_get_app_info (PlayerController* self); static void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, IndicateListenerServer* server, char* path, void* data); void player_controller_hibernate (PlayerController* self); gboolean familiar_players_db_already_familiar (FamiliarPlayersDB* self, const char* desktop); @@ -206,17 +208,6 @@ static gpointer _g_object_ref0 (gpointer self) { } -static char* string_strip (const char* self) { - char* result = NULL; - char* _result_; - g_return_val_if_fail (self != NULL, NULL); - _result_ = g_strdup (self); - g_strstrip (_result_); - result = _result_; - return result; -} - - static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlayerBridge* self) { g_return_if_fail (self != NULL); { @@ -229,9 +220,10 @@ static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlaye GDesktopAppInfo* info; GDesktopAppInfo* _tmp2_; GAppInfo* app_info; - PlayerController* ctrl; char* _tmp3_; - char* _tmp4_; + PlayerController* _tmp4_; + PlayerController* ctrl; + char* _tmp5_; if (!gee_iterator_next (_app_it)) { break; } @@ -252,11 +244,13 @@ static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlaye continue; } app_info = _g_object_ref0 ((_tmp2_ = info, G_IS_APP_INFO (_tmp2_) ? ((GAppInfo*) _tmp2_) : NULL)); - ctrl = player_controller_new (self->priv->root_menu, g_app_info_get_name (app_info), music_player_bridge_calculate_menu_position (self), PLAYER_CONTROLLER_STATE_OFFLINE); - g_object_set ((GObject*) ctrl, "app_info", app_info, NULL); - gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, _tmp4_ = string_strip (_tmp3_ = g_utf8_strdown (g_app_info_get_name (app_info), -1)), ctrl); - _g_free0 (_tmp4_); - _g_free0 (_tmp3_); + ctrl = (_tmp4_ = player_controller_new (self->priv->root_menu, _tmp3_ = music_player_bridge_truncate_player_name (g_app_info_get_name (app_info)), music_player_bridge_calculate_menu_position (self), PLAYER_CONTROLLER_STATE_OFFLINE), _g_free0 (_tmp3_), _tmp4_); + player_controller_set_app_info (ctrl, app_info); + if (player_controller_get_app_info (ctrl) == NULL) { + g_warning ("music-player-bridge.vala:69: for some reason the app info is null"); + } + gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, _tmp5_ = music_player_bridge_truncate_player_name (g_app_info_get_name (app_info)), ctrl); + _g_free0 (_tmp5_); _g_object_unref0 (ctrl); _g_object_unref0 (app_info); _g_object_unref0 (info); @@ -267,6 +261,41 @@ static void music_player_bridge_try_to_add_inactive_familiar_clients (MusicPlaye } +static char* string_strip (const char* self) { + char* result = NULL; + char* _result_; + g_return_val_if_fail (self != NULL, NULL); + _result_ = g_strdup (self); + g_strstrip (_result_); + result = _result_; + return result; +} + + +static char* music_player_bridge_truncate_player_name (const char* app_info_name) { + char* result = NULL; + char* _tmp0_; + char* _tmp1_; + char* _result_; + gint tokens_length1; + gint _tokens_size_; + char** _tmp3_; + char** _tmp2_; + char** tokens; + g_return_val_if_fail (app_info_name != NULL, NULL); + _result_ = (_tmp1_ = string_strip (_tmp0_ = g_utf8_strdown (app_info_name, -1)), _g_free0 (_tmp0_), _tmp1_); + tokens = (_tmp3_ = _tmp2_ = g_strsplit (_result_, " ", 0), tokens_length1 = _vala_array_length (_tmp2_), _tokens_size_ = tokens_length1, _tmp3_); + if (tokens_length1 > 1) { + char* _tmp4_; + _result_ = (_tmp4_ = g_strdup (tokens[0]), _g_free0 (_result_), _tmp4_); + } + g_debug ("music-player-bridge.vala:84: truncate player name %s", _result_); + result = _result_; + tokens = (_vala_array_free (tokens, tokens_length1, (GDestroyNotify) g_free), NULL); + return result; +} + + static gint music_player_bridge_calculate_menu_position (MusicPlayerBridge* self) { gint result = 0; g_return_val_if_fail (self != NULL, 0); @@ -289,8 +318,8 @@ void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListe gboolean _tmp3_ = FALSE; g_return_if_fail (self != NULL); g_return_if_fail (type != NULL); - g_debug ("music-player-bridge.vala:82: MusicPlayerBridge -> on_server_added with" \ -" value %s", type); + g_debug ("music-player-bridge.vala:100: MusicPlayerBridge -> on_server_added wit" \ +"h value %s", type); if (music_player_bridge_server_is_not_of_interest (self, type)) { return; } @@ -308,8 +337,8 @@ void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListe if ((_tmp5_ = gee_collection_contains ((GeeCollection*) (_tmp4_ = gee_map_get_keys ((GeeMap*) self->priv->registered_clients)), client_name), _g_object_unref0 (_tmp4_), _tmp5_)) { PlayerController* _tmp6_; PlayerController* _tmp7_; - g_debug ("music-player-bridge.vala:88: It figured out that it already has an ins" \ -"tance for this player already"); + g_debug ("music-player-bridge.vala:106: It figured out that it already has an in" \ +"stance for this player already"); player_controller_update_state (_tmp6_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name), PLAYER_CONTROLLER_STATE_READY); _g_object_unref0 (_tmp6_); player_controller_activate (_tmp7_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name)); @@ -318,8 +347,8 @@ void music_player_bridge_on_server_added (MusicPlayerBridge* self, IndicateListe PlayerController* ctrl; ctrl = player_controller_new (self->priv->root_menu, client_name, music_player_bridge_calculate_menu_position (self), PLAYER_CONTROLLER_STATE_READY); gee_abstract_map_set ((GeeAbstractMap*) self->priv->registered_clients, client_name, ctrl); - g_debug ("music-player-bridge.vala:99: New Client of name %s has successfully re" \ -"gistered with us", client_name); + g_debug ("music-player-bridge.vala:117: New Client of name %s has successfully r" \ +"egistered with us", client_name); _g_object_unref0 (ctrl); } if ((_tmp9_ = player_controller_get_app_info (_tmp8_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name)) == NULL, _g_object_unref0 (_tmp8_), _tmp9_)) { @@ -341,7 +370,7 @@ void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateLis gboolean _tmp3_ = FALSE; g_return_if_fail (self != NULL); g_return_if_fail (type != NULL); - g_debug ("music-player-bridge.vala:111: MusicPlayerBridge -> on_server_removed w" \ + g_debug ("music-player-bridge.vala:129: MusicPlayerBridge -> on_server_removed w" \ "ith value %s", type); if (music_player_bridge_server_is_not_of_interest (self, type)) { return; @@ -356,7 +385,7 @@ void music_player_bridge_on_server_removed (MusicPlayerBridge* self, IndicateLis PlayerController* _tmp4_; player_controller_hibernate (_tmp4_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) self->priv->registered_clients, client_name)); _g_object_unref0 (_tmp4_); - g_debug ("music-player-bridge.vala:116: Successively offlined client %s", client_name); + g_debug ("music-player-bridge.vala:134: Successively offlined client %s", client_name); } _g_free0 (client_name); } @@ -380,7 +409,7 @@ static gboolean music_player_bridge_server_is_not_of_interest (MusicPlayerBridge return result; } if (string_contains (type, "music") == FALSE) { - g_debug ("music-player-bridge.vala:123: server is of no interest, it is not an " \ + g_debug ("music-player-bridge.vala:141: server is of no interest, it is not an " \ "music server"); result = TRUE; return result; @@ -404,7 +433,7 @@ static void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, } if (_tmp1_) { GAppInfo* app_info; - g_debug ("music-player-bridge.vala:134: About to store desktop file path: %s", path); + g_debug ("music-player-bridge.vala:152: About to store desktop file path: %s", path); familiar_players_db_insert (bridge->priv->playersDB, path); app_info = music_player_bridge_create_app_info (path); if (app_info != NULL) { @@ -414,13 +443,13 @@ static void music_player_bridge_desktop_info_callback (MusicPlayerBridge* self, PlayerController* ctrl; ctrl = (_tmp4_ = (PlayerController*) gee_abstract_map_get ((GeeAbstractMap*) bridge->priv->registered_clients, _tmp3_ = string_strip (_tmp2_ = g_utf8_strdown (g_app_info_get_name (app_info), -1))), _g_free0 (_tmp3_), _g_free0 (_tmp2_), _tmp4_); g_object_set ((GObject*) ctrl, "app_info", app_info, NULL); - g_debug ("music-player-bridge.vala:140: successfully created appinfo from path a" \ + g_debug ("music-player-bridge.vala:158: successfully created appinfo from path a" \ "nd set it on the respective instance"); _g_object_unref0 (ctrl); } _g_object_unref0 (app_info); } else { - g_debug ("music-player-bridge.vala:144: Ignoring desktop file path because its e" \ + g_debug ("music-player-bridge.vala:162: Ignoring desktop file path because its e" \ "ither invalid of the db cache file has it already: %s", path); } _g_object_unref0 (bridge); @@ -439,20 +468,20 @@ void music_player_bridge_set_root_menu_item (MusicPlayerBridge* self, DbusmenuMe void music_player_bridge_on_server_count_changed (MusicPlayerBridge* self, IndicateListenerServer* object, guint i) { g_return_if_fail (self != NULL); - g_debug ("music-player-bridge.vala:156: MusicPlayerBridge-> on_server_count_chan" \ + g_debug ("music-player-bridge.vala:174: MusicPlayerBridge-> on_server_count_chan" \ "ged with value %u", i); } void music_player_bridge_on_indicator_added (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0) { g_return_if_fail (self != NULL); - g_debug ("music-player-bridge.vala:160: MusicPlayerBridge-> on_indicator_added"); + g_debug ("music-player-bridge.vala:178: MusicPlayerBridge-> on_indicator_added"); } void music_player_bridge_on_indicator_removed (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0) { g_return_if_fail (self != NULL); - g_debug ("music-player-bridge.vala:165: MusicPlayerBridge -> on_indicator_remove" \ + g_debug ("music-player-bridge.vala:183: MusicPlayerBridge -> on_indicator_remove" \ "d"); } @@ -460,7 +489,7 @@ void music_player_bridge_on_indicator_removed (MusicPlayerBridge* self, Indicate void music_player_bridge_on_indicator_modified (MusicPlayerBridge* self, IndicateListenerServer* object, IndicateListenerIndicator* p0, const char* s) { g_return_if_fail (self != NULL); g_return_if_fail (s != NULL); - g_debug ("music-player-bridge.vala:170: MusicPlayerBridge -> indicator_modified " \ + g_debug ("music-player-bridge.vala:188: MusicPlayerBridge -> indicator_modified " \ "with vale %s", s); } @@ -473,7 +502,7 @@ GAppInfo* music_player_bridge_create_app_info (const char* path) { g_return_val_if_fail (path != NULL, NULL); info = g_desktop_app_info_new_from_filename (path); if (path == NULL) { - g_warning ("music-player-bridge.vala:177: Could not create a desktopappinfo instan" \ + g_warning ("music-player-bridge.vala:195: Could not create a desktopappinfo instan" \ "ce from app: %s", path); result = NULL; _g_object_unref0 (info); diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index c677d15..61dfa2e 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -58,15 +58,33 @@ 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, - 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; + 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); } } + 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..2ab5fc8 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 */ @@ -723,6 +743,201 @@ _finalize (cairo_t* cr, } 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) != 0 ? (max -min) : 1; + + if(delta == 0) + delta = 1; + 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) { g_return_if_fail(IS_PLAY_BUTTON(button)); @@ -731,18 +946,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_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 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}; - + 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, |