From da91c666d6b66163077ddb9e59bf556fb4d44953 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 11 Jun 2010 08:59:06 +0100 Subject: --- src/common-defs.h | 6 +++--- src/indicator-sound.c | 2 +- src/player-controller.vala | 40 ++++++++++++++++++++++++++++++---------- src/transport-bar.c | 34 +++++++++++++++++++++++++--------- src/transport-bar.h | 2 ++ src/transport-menu-item.vala | 4 +++- 6 files changed, 64 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index 94c178e..5393400 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -24,7 +24,7 @@ with this program. If not, see . #define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" #define SIGNAL_SINK_AVAILABLE_UPDATE "SinkAvailableUpdate" -// DBUS items +/* DBUS Custom Items */ #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" -#define DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME "volume" -#define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-transport-bar" +#define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-transport-bar" +#define DBUSMENU_TRANSPORT_MENUITEM_STATE "x-canonical-transport-state" \ No newline at end of file diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 48fde56..a3856c4 100755 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -319,7 +319,7 @@ static gboolean new_transport_bar(DbusmenuMenuitem * newitem, DbusmenuMenuitem * g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - bar = transport_bar_new(); + bar = transport_bar_new(newitem); GtkMenuItem *menu_transport_bar = GTK_MENU_ITEM(bar); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_transport_bar, parent); diff --git a/src/player-controller.vala b/src/player-controller.vala index 86f0e0f..a92d8bf 100644 --- a/src/player-controller.vala +++ b/src/player-controller.vala @@ -7,7 +7,8 @@ public class PlayerController : GLib.Object private string name; private bool is_active; private ArrayList custom_items; - + + // TODO: pass in the appropriate position for the menu public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active) { this.root_menu = root; @@ -24,21 +25,40 @@ public class PlayerController : GLib.Object } } - private void self_construct() + private bool self_construct() { - Dbusmenu.Menuitem client_item = new Dbusmenu.Menuitem(); - this.custom_items.add(client_item); - client_item.property_set(MENUITEM_PROP_LABEL, this.name.concat("")); - TransportMenuItem transport_item = new TransportMenuItem(); + // Separator item + Dbusmenu.Menuitem separator_item = new Dbusmenu.Menuitem(); + separator_item.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR); + this.custom_items.add(separator_item); + + // Title item + Dbusmenu.Menuitem title_item = new Dbusmenu.Menuitem(); + title_item.property_set(MENUITEM_PROP_LABEL, this.name.concat("")); + title_item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia"); + this.custom_items.add(title_item); + + // Transport item + TransportMenuItem transport_item = new TransportMenuItem(); this.custom_items.add(transport_item); - root_menu.child_append(client_item); - root_menu.child_append(transport_item); - } + + int offset = 2; + foreach(Dbusmenu.Menuitem item in this.custom_items){ + root_menu.child_add_position(item, offset + this.custom_items.index_of(item)); + } + return true; + } +// if(!root_menu.child_add_position(client_item, 2) || +// !root_menu.child_add_position(transport_item, 3)){ +// //TODO raise here! +// return false; +// } +// return true; + private static string format_client_name(string client_name) { string formatted = client_name; - //debug("PlayerController->format_client_name"); if(formatted.len() > 1){ formatted = client_name.up(1).concat(client_name.slice(1, client_name.len())); debug("PlayerController->format_client_name - : %s", formatted); diff --git a/src/transport-bar.c b/src/transport-bar.c index aa618d2..46611dc 100644 --- a/src/transport-bar.c +++ b/src/transport-bar.c @@ -26,6 +26,9 @@ with this program. If not, see . #include "common-defs.h" #include +// TODO: think about leakage: ted ! + + typedef struct _TransportBarPrivate TransportBarPrivate; struct _TransportBarPrivate @@ -59,10 +62,11 @@ static gboolean transport_bar_button_press_event (GtkWidget *menuite GdkEventButton *event); static gboolean transport_bar_button_release_event (GtkWidget *menuitem, GdkEventButton *event); -static gboolean transport_bar_play_button_trigger (GtkWidget* widget, - GdkEventButton *event, - gpointer user_data); - +static gboolean transport_bar_play_button_trigger (GtkWidget *widget, + GdkEventButton *event, + gpointer user_data); +static void transport_bar_update_state(gchar * property, + GValue * value); G_DEFINE_TYPE (TransportBar, transport_bar, GTK_TYPE_MENU_ITEM); @@ -132,19 +136,22 @@ transport_bar_init (TransportBar *self) gtk_box_pack_start (GTK_BOX (hbox), priv->next_button, FALSE, FALSE, 0); g_signal_connect(priv->play_button, "button-press-event", G_CALLBACK(transport_bar_play_button_trigger), NULL); - - priv->hbox = hbox; + + g_signal_connect(DBUSMENU_MENUITEM(self), "property-changed", G_CALLBACK(transport_bar_update_state), NULL); gtk_widget_show_all (priv->hbox); gtk_container_add (GTK_CONTAINER (self), hbox); - } static void transport_bar_dispose (GObject *object) { + //if(IS_TRANSPORT_BAR(object) == TRUE){ + // TransportBarPrivate * priv = TRANSPORT_BAR_GET_PRIVATE(TRANSPORT_BAR(object)); + // g_object_unref(priv->previous_button); + //} G_OBJECT_CLASS (transport_bar_parent_class)->dispose (object); } @@ -174,13 +181,22 @@ transport_bar_button_release_event (GtkWidget *menuitem, /* Individual keyevents on the buttons */ static gboolean transport_bar_play_button_trigger(GtkWidget* widget, - GdkEventButton *event, - gpointer user_data) + GdkEventButton *event, + gpointer user_data) { g_debug("TransportBar::PLAY button_press_event"); return FALSE; } +static void transport_bar_update_state(gchar *property, GValue *value) +{ + g_debug("transport_bar_update_state - %s", property); +} + +void transport_bar_connect_with_other_half(TransportBar *self, DbusmenuMenuitem *twin_item) +{ + +} /** * transport_new: * @returns: a new #TransportBar. diff --git a/src/transport-bar.h b/src/transport-bar.h index e90e39c..93136e1 100644 --- a/src/transport-bar.h +++ b/src/transport-bar.h @@ -20,6 +20,7 @@ with this program. If not, see . #define __TRANSPORT_BAR_H__ #include +#include G_BEGIN_DECLS @@ -43,6 +44,7 @@ struct _TransportBar { GType transport_bar_get_type (void); GtkWidget* transport_bar_new(); +void connect_with_other_half(DbusmenuMenuitem *twin_item); G_END_DECLS diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala index 11120b0..9af52d1 100644 --- a/src/transport-menu-item.vala +++ b/src/transport-menu-item.vala @@ -5,10 +5,12 @@ public class TransportMenuItem : Dbusmenu.Menuitem { /* Not ideal duplicate definition of const - see common-defs/h */ const string DBUSMENU_TRANSPORT_MENUITEM_TYPE = "x-canonical-transport-bar"; + const string DBUSMENU_TRANSPORT_MENUITEM_STATE = "x-canonical-transport-state"; public TransportMenuItem() { - this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_TYPE); + this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_TYPE); + this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_STATE); } public override void handle_event(string name, GLib.Value input_value, uint timestamp) -- cgit v1.2.3