From edac78eadc5ddceb17b93bffa101eeffbab4437c Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 30 Jun 2010 18:02:53 +0100 Subject: correct startup behaviour in place --- src/player-controller.vala | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/player-controller.vala') diff --git a/src/player-controller.vala b/src/player-controller.vala index 0d8dc01..dfc2659 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -27,19 +27,20 @@ public class PlayerController : GLib.Object private const int TRANSPORT = 3; private Dbusmenu.Menuitem root_menu; - private string name; - private bool is_active; + public string name { get; set;} + public bool active { get; set;} public ArrayList custom_items; private MprisController mpris_adaptor; - private string desktop_path; - - public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active) + public AppInfo app_info { get; set;} + + public PlayerController(Dbusmenu.Menuitem root, string client_name, AppInfo? info = null) { this.root_menu = root; this.name = format_client_name(client_name.strip()); - this.is_active = active; this.custom_items = new ArrayList(); + this.app_info = info; self_construct(); + //app_info.launch(null, null); // Temporary scenario to handle both v1 and v2 of MPRIS. if(this.name == "Vlc"){ @@ -61,6 +62,14 @@ public class PlayerController : GLib.Object root_menu.child_delete(item); } } + + //public void switch_active(bool active){ + // this.is_active = active; + //} + + //public bool has_app_info(){ + // return (this.app_info != null); + //} private bool self_construct() { @@ -84,7 +93,7 @@ public class PlayerController : GLib.Object } return true; } - + private static string format_client_name(string client_name) { string formatted = client_name; @@ -94,5 +103,5 @@ public class PlayerController : GLib.Object } return formatted; } - + } \ No newline at end of file -- cgit v1.2.3 From 7555ea6755750dd64a6c4652b852a0bdc0d0bfeb Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 6 Jul 2010 18:55:05 +0100 Subject: whole new widget to house the customised title item --- src/Makefile.am | 3 + src/common-defs.h | 3 + src/metadata-menu-item.vala | 2 +- src/mpris-controller.vala | 5 ++ src/music-player-bridge.vala | 17 +++-- src/player-controller.vala | 97 +++++++++++++++++++-------- src/player-item.vala | 30 ++++++--- src/title-menu-item.vala | 37 +++++++++++ src/title-widget.c | 155 +++++++++++++++++++++++++++++++++++++++++++ src/title-widget.h | 51 ++++++++++++++ src/transport-menu-item.vala | 4 +- src/transport-widget.c | 2 - vapi/common-defs.vapi | 6 ++ 13 files changed, 361 insertions(+), 51 deletions(-) create mode 100644 src/title-menu-item.vala create mode 100644 src/title-widget.c create mode 100644 src/title-widget.h (limited to 'src/player-controller.vala') diff --git a/src/Makefile.am b/src/Makefile.am index b33107d..327fcbb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -14,6 +14,8 @@ libsoundmenu_la_SOURCES = \ metadata-widget.c \ metadata-widget.h \ indicator-sound.c \ + title-widget.c \ + title-widget.h \ dbus-shared-names.h \ sound-service-client.h @@ -54,6 +56,7 @@ music_bridge_VALASOURCES = \ music-player-bridge.vala \ transport-menu-item.vala \ metadata-menu-item.vala \ + title-menu-item.vala \ player-controller.vala \ mpris-controller-v2.vala \ mpris-controller.vala \ diff --git a/src/common-defs.h b/src/common-defs.h index dca21cc..9c1fbab 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -34,3 +34,6 @@ with this program. If not, see . #define DBUSMENU_METADATA_MENUITEM_TEXT_TITLE "x-canonical-metadata-text-title" #define DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM "x-canonical-metadata-text-album" #define DBUSMENU_METADATA_MENUITEM_ARTURL "x-canonical-metadata-arturl" + +#define DBUSMENU_TITLE_MENUITEM_TYPE "x-canonical-sound-menu-player-title-menu-item" +#define DBUSMENU_TITLE_MENUITEM_TEXT_NAME "x-canonical-sound-menu-player-title-name" diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 541fbf4..7eb112a 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -25,7 +25,7 @@ public class MetadataMenuitem : PlayerItem { public MetadataMenuitem() { - this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE); } public static HashSet attributes_format() diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala index beaf02c..b1e66f3 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -76,6 +76,11 @@ public class MprisController : GLib.Object this.mpris_player.Pause(); } } + + public bool connected() + { + return (this.mpris_player != null); + } private void onStatusChange(dynamic DBus.Object mpris_client, status st) { diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 84bf3df..77341a4 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -44,6 +44,7 @@ public class MusicPlayerBridge : GLib.Object } private void try_to_add_inactive_familiar_clients(){ + // TODO handle multple players - just working with one right now int count = 0; foreach(string app in this.playersDB.records()){ if(count == 0){ @@ -59,9 +60,9 @@ public class MusicPlayerBridge : GLib.Object } GLib.AppInfo app_info = info as GLib.AppInfo; PlayerController ctrl = new PlayerController(this.root_menu, - app_info.get_name(), - app_info); - ctrl.set("active", false); + app_info.get_name(), + PlayerController.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()); count += 1; @@ -83,11 +84,11 @@ 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].set("active", true); + this.registered_clients[client_name].activate(); } //else init a new one else{ - PlayerController ctrl = new PlayerController(root_menu, client_name); + PlayerController ctrl = new PlayerController(root_menu, client_name, PlayerController.READY); registered_clients.set(client_name, ctrl); debug("New Client of name %s has successfully registered with us", client_name); } @@ -125,14 +126,12 @@ public class MusicPlayerBridge : GLib.Object owned string path, void* data) { MusicPlayerBridge bridge = data as MusicPlayerBridge; - // Not the most secure validation - // TODO revisit validation mechanism if(path.contains("/") && bridge.playersDB.already_familiar(path) == false){ debug("About to store desktop file path: %s", path); bridge.playersDB.insert(path); AppInfo? app_info = create_app_info(path); if(app_info != null){ - PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; + PlayerController ctrl = bridge.registered_clients[app_info.get_name().down().strip()]; ctrl.set("app_info", app_info); debug("successfully created appinfo from path and set it on the respective instance"); } @@ -169,7 +168,7 @@ public class MusicPlayerBridge : GLib.Object public static AppInfo? create_app_info(string path) { - DesktopAppInfo info = new DesktopAppInfo.from_filename(path); + DesktopAppInfo info = new DesktopAppInfo.from_filename(path); if(path == null){ warning("Could not create a desktopappinfo instance from app: %s", path); return null; diff --git a/src/player-controller.vala b/src/player-controller.vala index dfc2659..dd55f3d 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -25,37 +25,79 @@ 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 int current_state = OFFLINE; + private Dbusmenu.Menuitem root_menu; public string name { get; set;} - public bool active { get; set;} public ArrayList custom_items; private MprisController mpris_adaptor; - public AppInfo app_info { get; set;} + public AppInfo? app_info { get; set;} - public PlayerController(Dbusmenu.Menuitem root, string client_name, AppInfo? info = null) + public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) { this.root_menu = root; this.name = format_client_name(client_name.strip()); this.custom_items = new ArrayList(); - this.app_info = info; - self_construct(); - //app_info.launch(null, null); - - // Temporary scenario to handle both v1 and v2 of MPRIS. + this.update_state(state); + construct_widgets(); + establish_mpris_connection(); + update_layout(); + } + + public void update_state(int new_state) + { + debug("update_state : new state %i", new_state); + this.current_state = new_state; + } + + public void activate() + { + debug("about to try to establish an mpris connection"); + this.establish_mpris_connection(); + this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); + } + + /* + instantiate() + The user should be able to start the app from the transport bar when in an offline state + There is a need to wait before the application is on DBus before attempting to access its mpris address + Hence only when the it has registered with us via libindicate do we attempt to kick off mpris communication + */ + public void instantiate() + { + this.app_info.launch(null, null); + this.update_state(INSTANTIATING); + } + + private void establish_mpris_connection() + { + if(this.current_state != READY){ + debug("establish_mpris_connection - Not ready to connect"); + return; + } if(this.name == "Vlc"){ this.mpris_adaptor = new MprisControllerV2(this.name, this); } else{ this.mpris_adaptor = new MprisController(this.name, this); - } - this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); - - // At start up if there is no metadata then hide the item. - // TODO: NOT working -> dbus menu bug ? - //((MetadataMenuitem)this.custom_items[METADATA]).check_layout(); + } + if(this.mpris_adaptor.connected() == true){ + this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); + this.update_state(CONNECTED); + } + else{ + this.update_state(DISCONNECTED); + } } - + public void vanish() { foreach(Dbusmenu.Menuitem item in this.custom_items){ @@ -63,21 +105,25 @@ public class PlayerController : GLib.Object } } - //public void switch_active(bool active){ - // this.is_active = active; - //} - - //public bool has_app_info(){ - // return (this.app_info != null); - //} + private void update_layout() + { + bool visibility = true; + if(this.current_state != CONNECTED){ + visibility = false; + } + this.custom_items[TRANSPORT].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); + this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, visibility); + } + - private bool self_construct() + private void construct_widgets() { // Separator item - this.custom_items.add(PlayerItem.new_separator_item()); + this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR)); // Title item - this.custom_items.add(PlayerItem.new_title_item(this.name)); + TitleMenuitem title_menu_item = new TitleMenuitem(); + this.custom_items.add(title_menu_item); // Metadata item MetadataMenuitem metadata_item = new MetadataMenuitem(); @@ -91,7 +137,6 @@ public class PlayerController : GLib.Object foreach(PlayerItem item in this.custom_items){ root_menu.child_add_position(item, offset + this.custom_items.index_of(item)); } - return true; } private static string format_client_name(string client_name) diff --git a/src/player-item.vala b/src/player-item.vala index a5c5512..88e1dd3 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -22,10 +22,18 @@ using Gee; public class PlayerItem : Dbusmenu.Menuitem { + public MprisController mpris_adaptor; - - public PlayerItem() + public string item_type { get; construct; } + + public PlayerItem(string type) { + Object(item_type: type); + } + + construct { + debug("in the base constructor for %s", item_type); + this.property_set(MENUITEM_PROP_TYPE, item_type); } public void reset(HashSet attrs){ @@ -94,19 +102,19 @@ public class PlayerItem : Dbusmenu.Menuitem //----- Custom constructors for player items ----------------// // Title item - public static PlayerItem new_title_item(dynamic string name) - { - PlayerItem item = new PlayerItem(); - item.property_set(MENUITEM_PROP_LABEL, name); - item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); - return item; - } + //public static PlayerItem new_title_item(dynamic string name) + //{ + // PlayerItem item = new PlayerItem(); + // item.property_set(MENUITEM_PROP_LABEL, name); + // item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); + // return item; + //} // Separator item public static PlayerItem new_separator_item() { - PlayerItem separator = new PlayerItem(); - separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); + PlayerItem separator = new PlayerItem(CLIENT_TYPES_SEPARATOR); + //separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); return separator; } diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala new file mode 100644 index 0000000..f29d970 --- /dev/null +++ b/src/title-menu-item.vala @@ -0,0 +1,37 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +using Dbusmenu; +using DbusmenuTitle; +using Gee; + +public class TitleMenuitem : PlayerItem +{ + public TitleMenuitem() + { + Object(item_type: MENUITEM_TYPE); + } + + public static HashSet attributes_format() + { + HashSet attrs = new HashSet(); + attrs.add(MENUITEM_TEXT_NAME); + return attrs; + } +} \ No newline at end of file diff --git a/src/title-widget.c b/src/title-widget.c new file mode 100644 index 0000000..f5af09e --- /dev/null +++ b/src/title-widget.c @@ -0,0 +1,155 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include "title-widget.h" +#include "common-defs.h" +#include + +static DbusmenuMenuitem* twin_item; + +typedef struct _TitleWidgetPrivate TitleWidgetPrivate; + +struct _TitleWidgetPrivate +{ + GtkWidget* hbox; +}; + +#define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate)) + +/* Prototypes */ +static void title_widget_class_init (TitleWidgetClass *klass); +static void title_widget_init (TitleWidget *self); +static void title_widget_dispose (GObject *object); +static void title_widget_finalize (GObject *object); +// keyevent consumers +static gboolean title_widget_button_press_event (GtkWidget *menuitem, + GdkEventButton *event); +static gboolean title_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event); +static gboolean title_widget_expose_event(GtkWidget* widget, + GdkEventExpose* event); + +// Dbusmenuitem properties update callback +static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata); + + +G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM); + + + +static void +title_widget_class_init (TitleWidgetClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); + + widget_class->button_press_event = title_widget_button_press_event; + widget_class->button_release_event = title_widget_button_release_event; + widget_class->expose_event = title_widget_expose_event; + + g_type_class_add_private (klass, sizeof (TitleWidgetPrivate)); + + gobject_class->dispose = title_widget_dispose; + gobject_class->finalize = title_widget_finalize; + +} + +static void +title_widget_init (TitleWidget *self) +{ + g_debug("TitleWidget::title_widget_init"); + + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); + + GtkWidget *hbox; + + hbox = gtk_hbox_new(FALSE, 0); + priv->hbox = hbox; + + g_signal_connect(G_OBJECT(twin_item), "property-changed", + G_CALLBACK(title_widget_property_update), self); + gtk_widget_show_all (priv->hbox); + gtk_container_add (GTK_CONTAINER (self), hbox); + +} + +static void +title_widget_dispose (GObject *object) +{ + G_OBJECT_CLASS (title_widget_parent_class)->dispose (object); +} + +static void +title_widget_finalize (GObject *object) +{ + G_OBJECT_CLASS (title_widget_parent_class)->finalize (object); +} + +/* Suppress/consume keyevents */ +static gboolean +title_widget_button_press_event (GtkWidget *menuitem, + GdkEventButton *event) +{ + g_debug("TitleWidget::menu_press_event"); + return TRUE; +} + +static gboolean +title_widget_button_release_event (GtkWidget *menuitem, + GdkEventButton *event) +{ + g_debug("TitleWidget::menu_release_event"); + return TRUE; +} + +static gboolean +title_widget_expose_event(GtkWidget* widget, GdkEventExpose* event) +{ + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(widget); + + gtk_container_propagate_expose(GTK_CONTAINER(widget), priv->hbox, event); + return TRUE; +} + +static void +title_widget_property_update(DbusmenuMenuitem* item, gchar* property, + GValue* value, gpointer userdata) +{ + g_return_if_fail (IS_TITLE_WIDGET (userdata)); + +} + + + /** + * transport_new: + * @returns: a new #TitleWidget. + **/ +GtkWidget* +title_widget_new(DbusmenuMenuitem *item) +{ + twin_item = item; + return g_object_new(TITLE_WIDGET_TYPE, NULL); +} + diff --git a/src/title-widget.h b/src/title-widget.h new file mode 100644 index 0000000..efc0c78 --- /dev/null +++ b/src/title-widget.h @@ -0,0 +1,51 @@ +/* +Copyright 2010 Canonical Ltd. + +Authors: + Conor Curran + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ +#ifndef __TITLE_WIDGET_H__ +#define __TITLE_WIDGET_H__ + +#include +#include + +G_BEGIN_DECLS + +#define TITLE_WIDGET_TYPE (title_widget_get_type ()) +#define TITLE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TITLE_WIDGET_TYPE, TitleWidget)) +#define TITLE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TITLE_WIDGET_TYPE, TitleWidgetClass)) +#define IS_TITLE_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TITLE_WIDGET_TYPE)) +#define IS_TITLE_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TITLE_WIDGET_TYPE)) +#define TITLE_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TITLE_WIDGET_TYPE, TitleWidgetClass)) + +typedef struct _TitleWidget TitleWidget; +typedef struct _TitleWidgetClass TitleWidgetClass; + +struct _TitleWidgetClass { + GtkMenuItemClass parent_class; +}; + +struct _TitleWidget { + GtkMenuItem parent; +}; + +GType title_widget_get_type (void); +GtkWidget* title_widget_new(DbusmenuMenuitem *twin_item); + +G_END_DECLS + +#endif + diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index e0d241e..af71df4 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -26,7 +26,7 @@ public class TransportMenuitem : PlayerItem public TransportMenuitem() { - this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE); } public void change_play_state(int state) @@ -37,7 +37,7 @@ 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.mpris_adaptor.toggle_playback(input_value.get_boolean()); + this.mpris_adaptor.toggle_playback(input_value.get_boolean()); } public override void check_layout(){ diff --git a/src/transport-widget.c b/src/transport-widget.c index bc9df53..a05bda2 100644 --- a/src/transport-widget.c +++ b/src/transport-widget.c @@ -26,8 +26,6 @@ with this program. If not, see . #include "common-defs.h" #include -// TODO: think about leakage: ted ! - static DbusmenuMenuitem* twin_item; typedef struct _TransportWidgetPrivate TransportWidgetPrivate; diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi index 222fb67..6649b26 100644 --- a/vapi/common-defs.vapi +++ b/vapi/common-defs.vapi @@ -30,4 +30,10 @@ namespace DbusmenuMetadata{ namespace DbusmenuTransport{ public const string MENUITEM_TYPE; public const string MENUITEM_PLAY_STATE; +} + +[CCode (cheader_filename = "common-defs.h")] +namespace DbusmenuTitle{ + public const string MENUITEM_TYPE; + public const string MENUITEM_TEXT_NAME; } \ No newline at end of file -- cgit v1.2.3 From 410965575fa1039cbcc6c6ef7f7ef316438118ed Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 13:22:18 +0100 Subject: alot of work around the title menu stuff --- data/album_artwork.png | Bin 0 -> 552 bytes data/sound_icon.png | Bin 0 -> 467 bytes src/indicator-sound.c | 24 +++++++++++++++++++--- src/metadata-menu-item.vala | 5 ----- src/player-controller.vala | 7 +++---- src/player-item.vala | 33 +---------------------------- src/title-menu-item.vala | 15 ++++++++++++-- src/title-widget.c | 48 +++++++++++++++++++++++++++++++++++++------ src/transport-menu-item.vala | 13 ++++-------- 9 files changed, 84 insertions(+), 61 deletions(-) create mode 100644 data/album_artwork.png create mode 100644 data/sound_icon.png (limited to 'src/player-controller.vala') diff --git a/data/album_artwork.png b/data/album_artwork.png new file mode 100644 index 0000000..940a69b Binary files /dev/null and b/data/album_artwork.png differ diff --git a/data/sound_icon.png b/data/sound_icon.png new file mode 100644 index 0000000..b52d6c4 Binary files /dev/null and b/data/sound_icon.png differ diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3f0d2d3..10333fe 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -40,6 +40,7 @@ with this program. If not, see . #include "indicator-sound.h" #include "transport-widget.h" #include "metadata-widget.h" +#include "title-widget.h" #include "dbus-shared-names.h" #include "sound-service-client.h" #include "common-defs.h" @@ -96,6 +97,7 @@ static void style_changed_cb(GtkWidget *widget, gpointer user_data); //player widgets related static gboolean new_transport_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -243,7 +245,7 @@ get_menu (IndicatorObject * io) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TRANSPORT_MENUITEM_TYPE, new_transport_widget); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_METADATA_MENUITEM_TYPE, new_metadata_widget); - + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_TITLE_MENUITEM_TYPE, new_title_widget); // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); return GTK_MENU(menu); @@ -353,9 +355,25 @@ new_metadata_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm return TRUE; } -//const gchar* path = dbusmenu_menuitem_property_get(new_item, DBUSMENU_METADATA_MENUITEM_IMAGE_PATH); +static gboolean +new_title_widget(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + g_debug("indicator-sound: new_title_widget"); + + GtkWidget* title = NULL; + + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + + title = title_widget_new (newitem); + GtkMenuItem *menu_title_widget = GTK_MENU_ITEM(title); + + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_title_widget, parent); -//g_debug("New transport bar path = %s", path); + gtk_widget_show_all(title); + + return TRUE; +} static void diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala index 7eb112a..cfcb3bc 100644 --- a/src/metadata-menu-item.vala +++ b/src/metadata-menu-item.vala @@ -37,11 +37,6 @@ public class MetadataMenuitem : PlayerItem attrs.add(MENUITEM_ARTURL); return attrs; } - - public override void check_layout(){ - this.property_set_bool(MENUITEM_PROP_VISIBLE, this.populated()); - debug("check layout for the metadata = %s", this.populated().to_string()); - } public bool populated() { diff --git a/src/player-controller.vala b/src/player-controller.vala index dd55f3d..75c251c 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -38,7 +38,7 @@ public class PlayerController : GLib.Object private Dbusmenu.Menuitem root_menu; public string name { get; set;} public ArrayList custom_items; - private MprisController mpris_adaptor; + public MprisController mpris_adaptor; public AppInfo? app_info { get; set;} public PlayerController(Dbusmenu.Menuitem root, string client_name, int state = OFFLINE) @@ -90,7 +90,6 @@ public class PlayerController : GLib.Object this.mpris_adaptor = new MprisController(this.name, this); } if(this.mpris_adaptor.connected() == true){ - this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor); this.update_state(CONNECTED); } else{ @@ -122,7 +121,7 @@ public class PlayerController : GLib.Object this.custom_items.add(new PlayerItem(CLIENT_TYPES_SEPARATOR)); // Title item - TitleMenuitem title_menu_item = new TitleMenuitem(); + TitleMenuitem title_menu_item = new TitleMenuitem(this, this.name); this.custom_items.add(title_menu_item); // Metadata item @@ -130,7 +129,7 @@ public class PlayerController : GLib.Object this.custom_items.add(metadata_item); // Transport item - TransportMenuitem transport_item = new TransportMenuitem(); + TransportMenuitem transport_item = new TransportMenuitem(this); this.custom_items.add(transport_item); int offset = 2; diff --git a/src/player-item.vala b/src/player-item.vala index 88e1dd3..171c140 100644 --- a/src/player-item.vala +++ b/src/player-item.vala @@ -22,8 +22,7 @@ using Gee; public class PlayerItem : Dbusmenu.Menuitem { - - public MprisController mpris_adaptor; + public PlayerController owner {get; construct;} public string item_type { get; construct; } public PlayerItem(string type) @@ -32,7 +31,6 @@ public class PlayerItem : Dbusmenu.Menuitem } construct { - debug("in the base constructor for %s", item_type); this.property_set(MENUITEM_PROP_TYPE, item_type); } @@ -68,15 +66,8 @@ public class PlayerItem : Dbusmenu.Menuitem this.property_set_bool(property, v.get_boolean()); } } - // TODO: not working - //this.check_layout(); } - public void set_adaptor(MprisController adaptor) - { - this.mpris_adaptor = adaptor; - } - private static bool ensure_valid_updates(HashTable data, HashSet attributes) { if(data == null){ @@ -99,27 +90,5 @@ public class PlayerItem : Dbusmenu.Menuitem return result; } - - //----- Custom constructors for player items ----------------// - // Title item - //public static PlayerItem new_title_item(dynamic string name) - //{ - // PlayerItem item = new PlayerItem(); - // item.property_set(MENUITEM_PROP_LABEL, name); - // item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); - // return item; - //} - - // Separator item - public static PlayerItem new_separator_item() - { - PlayerItem separator = new PlayerItem(CLIENT_TYPES_SEPARATOR); - //separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); - return separator; - } - - public virtual void check_layout(){ - warning("this should not be hit"); - } } diff --git a/src/title-menu-item.vala b/src/title-menu-item.vala index f29d970..0acd97f 100644 --- a/src/title-menu-item.vala +++ b/src/title-menu-item.vala @@ -23,11 +23,22 @@ using Gee; public class TitleMenuitem : PlayerItem { - public TitleMenuitem() + public TitleMenuitem(PlayerController parent, string name) { - Object(item_type: MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE, owner: parent); + this.property_set(MENUITEM_TEXT_NAME, name); } + 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) + { + this.owner.instantiate(); + } + } + + public static HashSet attributes_format() { HashSet attrs = new HashSet(); diff --git a/src/title-widget.c b/src/title-widget.c index f5af09e..45f918f 100644 --- a/src/title-widget.c +++ b/src/title-widget.c @@ -33,6 +33,8 @@ typedef struct _TitleWidgetPrivate TitleWidgetPrivate; struct _TitleWidgetPrivate { GtkWidget* hbox; + GtkWidget* name; + GtkWidget* player_icon; }; #define TITLE_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TITLE_WIDGET_TYPE, TitleWidgetPrivate)) @@ -42,19 +44,19 @@ static void title_widget_class_init (TitleWidgetClass *klass); static void title_widget_init (TitleWidget *self); static void title_widget_dispose (GObject *object); static void title_widget_finalize (GObject *object); + // keyevent consumers static gboolean title_widget_button_press_event (GtkWidget *menuitem, - GdkEventButton *event); + GdkEventButton *event); static gboolean title_widget_button_release_event (GtkWidget *menuitem, - GdkEventButton *event); + GdkEventButton *event); static gboolean title_widget_expose_event(GtkWidget* widget, GdkEventExpose* event); // Dbusmenuitem properties update callback static void title_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata); - - +static void style_name_text(TitleWidget* self); G_DEFINE_TYPE (TitleWidget, title_widget, GTK_TYPE_MENU_ITEM); @@ -87,9 +89,19 @@ title_widget_init (TitleWidget *self) hbox = gtk_hbox_new(FALSE, 0); priv->hbox = hbox; - g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(title_widget_property_update), self); + + priv->player_icon = gtk_image_new_from_file("/home/ronoc/branches/sound-menu-v2/finish-indicate/indicator-sound/data/sound_icon.png"); + 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, + DBUSMENU_TITLE_MENUITEM_TEXT_NAME)); + gtk_misc_set_padding(GTK_MISC(priv->name), 10, 0); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->name, FALSE, FALSE, 0); + + style_name_text(self); + gtk_widget_show_all (priv->hbox); gtk_container_add (GTK_CONTAINER (self), hbox); @@ -113,6 +125,13 @@ title_widget_button_press_event (GtkWidget *menuitem, GdkEventButton *event) { g_debug("TitleWidget::menu_press_event"); + + GValue value = {0}; + g_value_init(&value, G_TYPE_BOOLEAN); + + g_value_set_boolean(&value, TRUE); + dbusmenu_menuitem_handle_event (twin_item, "Title menu event", &value, 0); + return TRUE; } @@ -138,9 +157,26 @@ title_widget_property_update(DbusmenuMenuitem* item, gchar* property, GValue* value, gpointer userdata) { g_return_if_fail (IS_TITLE_WIDGET (userdata)); - + TitleWidget* mitem = TITLE_WIDGET(userdata); + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(mitem); + + if(g_ascii_strcasecmp(DBUSMENU_TITLE_MENUITEM_TEXT_NAME, property) == 0){ + gtk_label_set_text(GTK_LABEL(priv->name), g_value_get_string(value)); + style_name_text(mitem); + } } +static void +style_name_text(TitleWidget* self) +{ + TitleWidgetPrivate * priv = TITLE_WIDGET_GET_PRIVATE(self); + + char* markup; + markup = g_markup_printf_escaped ("%s", + gtk_label_get_text(GTK_LABEL(priv->name))); + gtk_label_set_markup (GTK_LABEL (priv->name), markup); + g_free(markup); +} /** * transport_new: diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index af71df4..7a1bb4a 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -24,9 +24,9 @@ using DbusmenuTransport; public class TransportMenuitem : PlayerItem { - public TransportMenuitem() + public TransportMenuitem(PlayerController parent) { - Object(item_type: MENUITEM_TYPE); + Object(item_type: MENUITEM_TYPE, owner: parent); } public void change_play_state(int state) @@ -37,13 +37,8 @@ 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.mpris_adaptor.toggle_playback(input_value.get_boolean()); - } - - public override void check_layout(){ - // nothing to be done for this item - always active - } - + this.owner.mpris_adaptor.toggle_playback(input_value.get_boolean()); + } public static HashSet attributes_format() { -- cgit v1.2.3 From caf13b4dccb20aff410ffc0da63c298cabbcca5f Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 7 Jul 2010 13:36:56 +0100 Subject: fixed the mpris connection problems --- src/music-player-bridge.vala | 1 + src/player-controller.vala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'src/player-controller.vala') diff --git a/src/music-player-bridge.vala b/src/music-player-bridge.vala index 77341a4..46723cb 100644 --- a/src/music-player-bridge.vala +++ b/src/music-player-bridge.vala @@ -84,6 +84,7 @@ 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].activate(); } //else init a new one diff --git a/src/player-controller.vala b/src/player-controller.vala index 75c251c..88dc3a7 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -60,7 +60,6 @@ public class PlayerController : GLib.Object public void activate() { - debug("about to try to establish an mpris connection"); this.establish_mpris_connection(); this.custom_items[METADATA].property_set_bool(MENUITEM_PROP_VISIBLE, true); } @@ -95,6 +94,7 @@ public class PlayerController : GLib.Object else{ this.update_state(DISCONNECTED); } + this.update_layout(); } public void vanish() -- cgit v1.2.3 From e4f900efd1e48814a70e4351cc3d878312daef37 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 16:12:59 +0100 Subject: event handling now plugged in crudely --- src/indicator-sound.c | 6 ++---- src/metadata-widget.c | 6 +++--- src/mpris-controller.vala | 29 +++++++++++++++++++++-------- src/play-button.c | 23 +++++++++++++++++++++++ src/play-button.h | 2 ++ src/player-controller.vala | 1 + src/transport-menu-item.vala | 10 ++++++++-- src/transport-widget.c | 23 +++++++++++++++++------ 8 files changed, 77 insertions(+), 23 deletions(-) (limited to 'src/player-controller.vala') 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..61c96e7 100644 --- a/src/mpris-controller.vala +++ b/src/mpris-controller.vala @@ -65,16 +65,29 @@ public class MprisController : GLib.Object * TRUE => Playing * FALSE => Paused **/ - public void toggle_playback(bool state) + public void transport_event(int command) { - if(state == true){ - debug("about to play"); - this.mpris_player.Play(); + if(command == 2){ + 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 == 1){ + this.mpris_player.previous(); + } + else if(command == 3){ + this.mpris_player.next(); } - else{ - debug("about to pause"); - this.mpris_player.Pause(); - } } public bool connected() diff --git a/src/play-button.c b/src/play-button.c index 136f25d..afb46d8 100644 --- a/src/play-button.c +++ b/src/play-button.c @@ -349,6 +349,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 = 1; + } + else if(event->x > 86 && event->x < 118 + && event->y > 20 && event->y < 47){ + result = 2; + } + else if(event->x > 122 && event->x < 164 + && event->y > 22 && event->y < 46){ + result = 3; + } + + 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..dfbf6d3 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -110,6 +110,7 @@ public class PlayerController : GLib.Object if(this.current_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/transport-menu-item.vala b/src/transport-menu-item.vala index 7a1bb4a..7e7bedc 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -36,8 +36,14 @@ 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()); + if(input > 0){ + this.owner.mpris_adaptor.transport_event(input); + } + else{ + debug("A mouse event I'm not interested in"); + } } public static HashSet 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; } -- cgit v1.2.3 From 0f2a6b2736713951fb4b88848e79849a8f1dc72a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 8 Jul 2010 17:47:28 +0100 Subject: constants replaced and enums and title image now fetched from the mono theme --- src/mpris-controller.vala | 15 ++++++++------- src/music-player-bridge.vala | 6 +++--- src/play-button.c | 13 ++++++++++--- src/player-controller.vala | 37 ++++++++++++++++++++++--------------- src/title-menu-item.vala | 2 +- src/title-widget.c | 5 +++-- src/transport-menu-item.vala | 13 +++++++------ 7 files changed, 54 insertions(+), 37 deletions(-) (limited to 'src/player-controller.vala') 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(); - 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 . #include "title-widget.h" #include "common-defs.h" #include +#include 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 attributes_format() -- cgit v1.2.3