diff options
author | Conor Curran <conor.curran@canonical.com> | 2010-07-08 17:52:51 +0100 |
---|---|---|
committer | Conor Curran <conor.curran@canonical.com> | 2010-07-08 17:52:51 +0100 |
commit | 50b2e070852b5eab299b8c3612a86adf6d21e901 (patch) | |
tree | 18c40c1b61ce93552767ef3f02055a3d9e92dfcb | |
parent | 41747b032d2032c97fd7f1766157e2d846626880 (diff) | |
parent | 0f2a6b2736713951fb4b88848e79849a8f1dc72a (diff) | |
download | ayatana-indicator-sound-50b2e070852b5eab299b8c3612a86adf6d21e901.tar.gz ayatana-indicator-sound-50b2e070852b5eab299b8c3612a86adf6d21e901.tar.bz2 ayatana-indicator-sound-50b2e070852b5eab299b8c3612a86adf6d21e901.zip |
merged the event handling plus code tidy ups and proper icon loading from the theme
-rw-r--r-- | data/album_artwork.png | bin | 552 -> 0 bytes | |||
-rw-r--r-- | data/sound_icon.png | bin | 467 -> 0 bytes | |||
-rw-r--r-- | src/indicator-sound.c | 6 | ||||
-rw-r--r-- | src/metadata-widget.c | 6 | ||||
-rw-r--r-- | src/mpris-controller.vala | 36 | ||||
-rw-r--r-- | src/music-player-bridge.vala | 6 | ||||
-rw-r--r-- | src/play-button.c | 30 | ||||
-rw-r--r-- | src/play-button.h | 2 | ||||
-rw-r--r-- | src/player-controller.vala | 38 | ||||
-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 | 11 | ||||
-rw-r--r-- | src/transport-widget.c | 23 |
13 files changed, 118 insertions, 47 deletions
diff --git a/data/album_artwork.png b/data/album_artwork.png Binary files differdeleted file mode 100644 index 940a69b..0000000 --- a/data/album_artwork.png +++ /dev/null diff --git a/data/sound_icon.png b/data/sound_icon.png Binary files differdeleted file mode 100644 index b52d6c4..0000000 --- a/data/sound_icon.png +++ /dev/null diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 10333fe..8be97b4 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -328,10 +328,9 @@ new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbus bar = transport_widget_new(newitem); GtkMenuItem *menu_transport_bar = GTK_MENU_ITEM(bar); + gtk_widget_show_all(bar); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_transport_bar, parent); - gtk_widget_show_all(bar); - return TRUE; } @@ -348,10 +347,9 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm metadata = metadata_widget_new (newitem); GtkMenuItem *menu_metadata_widget = GTK_MENU_ITEM(metadata); + gtk_widget_show_all(metadata); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_metadata_widget, parent); - gtk_widget_show_all(metadata); - return TRUE; } diff --git a/src/metadata-widget.c b/src/metadata-widget.c index bb9c8a8..8235725 100644 --- a/src/metadata-widget.c +++ b/src/metadata-widget.c @@ -112,7 +112,7 @@ metadata_widget_init (MetadataWidget *self) DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST)); gtk_misc_set_alignment(GTK_MISC(artist), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(artist), 20); + 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. @@ -123,7 +123,7 @@ metadata_widget_init (MetadataWidget *self) piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_TITLE)); gtk_misc_set_alignment(GTK_MISC(piece), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(piece), 16); + 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. @@ -134,7 +134,7 @@ metadata_widget_init (MetadataWidget *self) container = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM)); gtk_misc_set_alignment(GTK_MISC(container), (gfloat)0, (gfloat)0); - gtk_label_set_width_chars(GTK_LABEL(container), 20); + 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. diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index b1e66f3..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,16 +65,30 @@ public class MprisController : GLib.Object * TRUE => Playing * FALSE => Paused **/ - public void toggle_playback(bool state) + public void transport_event(TransportMenuitem.action command) { - if(state == true){ - debug("about to play"); - this.mpris_player.Play(); + 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); + bool new_play_state = !play_state; + debug("toggle_playback - new play state %i", (int)new_play_state); + if(new_play_state == true){ + debug("about to play"); + this.mpris_player.Play(); + } + else{ + debug("about to pause"); + this.mpris_player.Pause(); + } + } + else if(command == TransportMenuitem.action.PREVIOUS){ + this.mpris_player.previous(); + } + else if(command == TransportMenuitem.action.NEXT){ + this.mpris_player.next(); } - else{ - debug("about to pause"); - this.mpris_player.Pause(); - } } public bool connected() 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 136f25d..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 @@ -349,6 +356,29 @@ play_button_expose (GtkWidget *button, GdkEventExpose *event) } +gint +determine_button_event(GtkWidget* button, GdkEventButton* event) +{ + g_debug("event x coordinate = %f", event->x); + g_debug("event y coordinate = %f", event->y); + gint result = 0; + // For now very simple rectangular collision detection + if(event->x > 40 && event->x < 80 + && event->y > 22 && event->y < 46){ + result = PREVIOUS; + } + else if(event->x > 86 && event->x < 118 + && event->y > 20 && event->y < 47){ + result = PLAY_PAUSE; + } + else if(event->x > 122 && event->x < 164 + && event->y > 22 && event->y < 46){ + result = NEXT; + } + + return result; +} + void play_button_set_style(GtkWidget* button, GtkStyle* style) { diff --git a/src/play-button.h b/src/play-button.h index 6c6aee3..3eaabcc 100644 --- a/src/play-button.h +++ b/src/play-button.h @@ -43,6 +43,8 @@ struct _PlayButton { GType play_button_get_type (void); void play_button_set_style(GtkWidget* button, GtkStyle* style); +gint determine_button_event(GtkWidget* button, GdkEventButton* event); + GtkWidget* play_button_new(); G_END_DECLS diff --git a/src/player-controller.vala b/src/player-controller.vala index 88dc3a7..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,9 +114,10 @@ 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()); this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); } 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 7a1bb4a..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) { @@ -36,8 +41,10 @@ public class TransportMenuitem : 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()); - this.owner.mpris_adaptor.toggle_playback(input_value.get_boolean()); + int input = input_value.get_int(); + debug("handle_event with value %s", input.to_string()); + // 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() diff --git a/src/transport-widget.c b/src/transport-widget.c index 6d39a03..9852b50 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -132,13 +132,24 @@ transport_widget_button_press_event (GtkWidget *menuitem, return FALSE; } - //TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); + TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem)); - //GValue value = {0}; - //g_value_init(&value, G_TYPE_BOOLEAN); - //g_debug("TransportWidget::menu_press_event - going to send value %i", state); - //g_value_set_boolean(&value, state); - //dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); + GtkWidget *parent; + + // can we block emissions of "grab-notify" on parent?? + parent = gtk_widget_get_parent (GTK_WIDGET (menuitem)); + gint result = determine_button_event(priv->play_button, event); + + //GTK_OBJECT_FLAGS (scale) |= GTK_HAS_GRAB; + //gtk_widget_event (scale, + //((GdkEvent *)(void*)(event))); + //GTK_OBJECT_FLAGS (scale) &= ~(GTK_HAS_GRAB); + + GValue value = {0}; + g_value_init(&value, G_TYPE_INT); + g_debug("TransportWidget::menu_press_event - going to send value %i", result); + g_value_set_int(&value, result); + dbusmenu_menuitem_handle_event (twin_item, "Transport state change", &value, 0); return TRUE; } |