diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mpris-controller.vala | 15 | ||||
-rw-r--r-- | src/music-player-bridge.vala | 6 | ||||
-rw-r--r-- | src/play-button.c | 13 | ||||
-rw-r--r-- | src/player-controller.vala | 37 | ||||
-rw-r--r-- | src/title-menu-item.vala | 2 | ||||
-rw-r--r-- | src/title-widget.c | 5 | ||||
-rw-r--r-- | src/transport-menu-item.vala | 13 |
7 files changed, 54 insertions, 37 deletions
diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index 61c96e7..2194d44 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -27,9 +27,9 @@ public class MprisController : GLib.Object private PlayerController controller; struct status { public int32 playback; - public int32 shuffle; - public int32 repeat; - public int32 endless; + //public int32 shuffle; // Not used just yet + //public int32 repeat; + //public int32 endless; } public MprisController(string name, PlayerController controller, string mpris_interface="org.freedesktop.MediaPlayer"){ @@ -65,9 +65,10 @@ public class MprisController : GLib.Object * TRUE => Playing * FALSE => Paused **/ - public void transport_event(int command) + public void transport_event(TransportMenuitem.action command) { - if(command == 2){ + debug("transport_event input = %i", (int)command); + if(command == TransportMenuitem.action.PLAY_PAUSE){ status st = this.mpris_player.GetStatus(); bool play_state = st.playback == 1; debug("toggle_playback - initial play state %i", (int)play_state); @@ -82,10 +83,10 @@ public class MprisController : GLib.Object this.mpris_player.Pause(); } } - else if(command == 1){ + else if(command == TransportMenuitem.action.PREVIOUS){ this.mpris_player.previous(); } - else if(command == 3){ + else if(command == TransportMenuitem.action.NEXT){ this.mpris_player.next(); } } diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 46723cb..d771192 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -61,7 +61,7 @@ public class MusicPlayerBridge : GLib.Object GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, app_info.get_name(), - PlayerController.OFFLINE); + 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()); @@ -84,12 +84,12 @@ public class MusicPlayerBridge : GLib.Object // If we have an instance already for this player, ensure it is switched to active if(this.registered_clients.keys.contains(client_name)){ debug("It figured out that it already has an instance for this player already"); - this.registered_clients[client_name].update_state(PlayerController.READY); + this.registered_clients[client_name].update_state(PlayerController.state.READY); this.registered_clients[client_name].activate(); } //else init a new one else{ - PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.READY); + PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.state.READY); registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } diff --git a/src/play-button.c b/src/play-button.c index afb46d8..2fddbcf 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -53,6 +53,13 @@ Uses code from ctk #define PAUSE_X 62.0f #define PAUSE_Y 15.0f +// Transport events +enum { + PREVIOUS, + PLAY_PAUSE, + NEXT +}; + typedef struct _PlayButtonPrivate PlayButtonPrivate; struct _PlayButtonPrivate @@ -358,15 +365,15 @@ determine_button_event(GtkWidget* button, GdkEventButton* event) // For now very simple rectangular collision detection if(event->x > 40 && event->x < 80 && event->y > 22 && event->y < 46){ - result = 1; + result = PREVIOUS; } else if(event->x > 86 && event->x < 118 && event->y > 20 && event->y < 47){ - result = 2; + result = PLAY_PAUSE; } else if(event->x > 122 && event->x < 164 && event->y > 22 && event->y < 46){ - result = 3; + result = NEXT; } return result; diff --git a/src/player-controller.vala b/src/player-controller.vala index dfbf6d3..3fb4750 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -26,13 +26,15 @@ public class PlayerController : GLib.Object public const int METADATA = 2; private const int TRANSPORT = 3; - public static const int OFFLINE = 0; - public static const int INSTANTIATING = 1; - public static const int READY = 2; - public static const int CONNECTED = 3; - public static const int DISCONNECTED = 4; + public enum state{ + OFFLINE, + INSTANTIATING, + READY, + CONNECTED, + DISCONNECTED + } - public int current_state = OFFLINE; + public int current_state = state.OFFLINE; private Dbusmenu.Menuitem root_menu; @@ -41,18 +43,18 @@ public class PlayerController : GLib.Object public MprisController mpris_adaptor; public AppInfo? app_info { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) + public PlayerController(Dbusmenu.Menuitem root, string client_name, state initial_state) { this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList<PlayerItem>(); - this.update_state(state); + this.update_state(initial_state); construct_widgets(); establish_mpris_connection(); update_layout(); } - public void update_state(int new_state) + public void update_state(state new_state) { debug("update_state : new state %i", new_state); this.current_state = new_state; @@ -72,13 +74,18 @@ public class PlayerController : GLib.Object */ public void instantiate() { - this.app_info.launch(null, null); - this.update_state(INSTANTIATING); + try{ + this.app_info.launch(null, null); + this.update_state(state.INSTANTIATING); + } + catch(GLib.Error error){ + warning("Failed to launch app %s with error message: %s", this.name, error.message); + } } private void establish_mpris_connection() { - if(this.current_state != READY){ + if(this.current_state != state.READY){ debug("establish_mpris_connection - Not ready to connect"); return; } @@ -89,10 +96,10 @@ public class PlayerController : GLib.Object this.mpris_adaptor = new MprisController(this.name, this); } if(this.mpris_adaptor.connected() == true){ - this.update_state(CONNECTED); + this.update_state(state.CONNECTED); } else{ - this.update_state(DISCONNECTED); + this.update_state(state.DISCONNECTED); } this.update_layout(); } @@ -107,7 +114,7 @@ public class PlayerController : GLib.Object private void update_layout() { bool visibility = true; - if(this.current_state != CONNECTED){ + if(this.current_state != state.CONNECTED){ visibility = false; } debug("about the set the visibility on both the transport and metadata widget to %s", visibility.to_string()); diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index 0acd97f..612d279 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -32,7 +32,7 @@ public class TitleMenuitem : PlayerItem public override void handle_event(string name, GLib.Value input_value, uint timestamp) { debug("handle_event with bool value %s", input_value.get_boolean().to_string()); - if(this.owner.current_state == PlayerController.OFFLINE) + if(this.owner.current_state == PlayerController.state.OFFLINE) { this.owner.instantiate(); } diff --git a/src/title-widget.c b/src/title-widget.c index 9951754..1b57fe9 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -25,6 +25,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>. #include "title-widget.h" #include "common-defs.h" #include <gtk/gtk.h> +#include <libindicator/indicator-image-helper.h> static DbusmenuMenuitem* twin_item; @@ -91,8 +92,8 @@ title_widget_init (TitleWidget *self) priv->hbox = hbox; g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); - // TODO - waiting theme icon name for correct usage - priv->player_icon = gtk_image_new_from_file("/home/ronoc/branches/sound-menu-v2/finish-indicate/indicator-sound/data/sound_icon.png"); + + priv->player_icon = indicator_image_helper("sound_icon"); gtk_box_pack_start(GTK_BOX (priv->hbox), priv->player_icon, FALSE, FALSE, 0); priv->name = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 7e7bedc..e0710a8 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -23,6 +23,11 @@ using DbusmenuTransport; public class TransportMenuitem : PlayerItem { + public enum action{ + PREVIOUS, + PLAY_PAUSE, + NEXT + } public TransportMenuitem(PlayerController parent) { @@ -38,12 +43,8 @@ public class TransportMenuitem : PlayerItem { int input = input_value.get_int(); debug("handle_event with value %s", input.to_string()); - if(input > 0){ - this.owner.mpris_adaptor.transport_event(input); - } - else{ - debug("A mouse event I'm not interested in"); - } + // Fire and forgot - the widget would not have sent it over it didn't think it was relevant. + this.owner.mpris_adaptor.transport_event((action)input); } public static HashSet<string> attributes_format() |