aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-06-22 15:03:33 +0100
committerConor Curran <conor.curran@canonical.com>2010-06-22 15:03:33 +0100
commit8939506a486c50d83c57a1ce21354243f71af4ab (patch)
treebe27299b86e8186e4750ccfd80e0b72def6fe4ad
parent9bba58ee4dae536ce92f396854e2c0e671d9b7f0 (diff)
parentb77c81f85bc219790f5a079e9b888b6ae3627739 (diff)
downloadayatana-indicator-sound-8939506a486c50d83c57a1ce21354243f71af4ab.tar.gz
ayatana-indicator-sound-8939506a486c50d83c57a1ce21354243f71af4ab.tar.bz2
ayatana-indicator-sound-8939506a486c50d83c57a1ce21354243f71af4ab.zip
merged refactoring branch plus automatic status updates
-rw-r--r--src/Makefile.am5
-rw-r--r--src/common-defs.h8
-rw-r--r--src/metadata-menu-item.vala57
-rw-r--r--src/metadata-widget.c14
-rw-r--r--src/mpris-controller.vala49
-rw-r--r--src/player-controller.vala36
-rw-r--r--src/player-item.vala89
-rw-r--r--src/transport-menu-item.vala28
-rw-r--r--src/transport-widget.c53
-rw-r--r--vapi/common-defs.vapi33
10 files changed, 249 insertions, 123 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 5a42dc6..a2a54e8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,17 +56,20 @@ music_bridge_VALASOURCES = \
metadata-menu-item.vala \
player-controller.vala \
mpris-controller-v2.vala \
- mpris-controller.vala
+ mpris-controller.vala \
+ player-item.vala
music_bridge_VALAFLAGS = \
--ccode \
-H music-player-bridge.h -d . \
--library music-bridge \
--vapidir=./ \
+ --vapidir=../vapi/ \
--thread \
--pkg gee-1.0 \
--pkg Indicate-0.2 \
--pkg Dbusmenu-Glib-0.2 \
+ --pkg common-defs \
--pkg dbus-glib-1
$(MAINTAINER_VALAFLAGS)
diff --git a/src/common-defs.h b/src/common-defs.h
index 014d864..dca21cc 100644
--- a/src/common-defs.h
+++ b/src/common-defs.h
@@ -27,10 +27,10 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
/* DBUS Custom Items */
#define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item"
#define DBUSMENU_TRANSPORT_MENUITEM_TYPE "x-canonical-transport-bar"
-#define DBUSMENU_TRANSPORT_MENUITEM_STATE "x-canonical-transport-state"
+#define DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE "x-canonical-transport-play-state"
#define DBUSMENU_METADATA_MENUITEM_TYPE "x-canonical-metadata-menu-item"
#define DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST "x-canonical-metadata-text-artist"
-#define DBUSMENU_METADATA_MENUITEM_TEXT_PIECE "x-canonical-metadata-text-piece"
-#define DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER "x-canonical-metadata-text-container"
-#define DBUSMENU_METADATA_MENUITEM_IMAGE_PATH "x-canonical-metadata-image"
+#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"
diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala
index 82926b1..f62cd46 100644
--- a/src/metadata-menu-item.vala
+++ b/src/metadata-menu-item.vala
@@ -1,40 +1,41 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+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 <http://www.gnu.org/licenses/>.
+*/
+
using Dbusmenu;
using Gee;
+using DbusmenuMetadata;
-public class MetadataMenuitem : Dbusmenu.Menuitem
+public class MetadataMenuitem : PlayerItem
{
- /* Not ideal duplicate definition of const - see common-defs/h */
- const string DBUSMENU_METADATA_MENUITEM_TYPE = "x-canonical-metadata-menu-item";
- const string DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST = "x-canonical-metadata-text-artist";
- const string DBUSMENU_METADATA_MENUITEM_TEXT_PIECE = "x-canonical-metadata-text-piece";
- const string DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER = "x-canonical-metadata-text-container";
- const string DBUSMENU_METADATA_MENUITEM_IMAGE_PATH = "x-canonical-metadata-image";
-
public MetadataMenuitem()
{
- this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_METADATA_MENUITEM_TYPE);
+ this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE);
}
- public void update(HashMap<string, string> data)
+ public static HashSet<string> attributes_format()
{
- this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST, data.get("artist").strip());
- this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_PIECE, data.get("title").strip());
- this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER, data.get("album").strip());
- this.property_set(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, sanitize_image_path(data.get("arturl")));
- }
-
- public static string sanitize_image_path(string path)
- {
- string result = path.strip();
- if(result.has_prefix("file:///")){
- result = result.slice(7, result.len());
- }
- debug("Sanitize image path - result = %s", result);
- return result;
+ HashSet<string> attrs = new HashSet<string>();
+ attrs.add(MENUITEM_TEXT_TITLE);
+ attrs.add(MENUITEM_TEXT_ARTIST);
+ attrs.add(MENUITEM_TEXT_ALBUM);
+ attrs.add(MENUITEM_ARTURL);
+ return attrs;
}
- public override void handle_event(string name, GLib.Value input_value, uint timestamp)
- {
- debug("MetadataItem -> handle event caught!");
- }
} \ No newline at end of file
diff --git a/src/metadata-widget.c b/src/metadata-widget.c
index c4d3b50..66e8cac 100644
--- a/src/metadata-widget.c
+++ b/src/metadata-widget.c
@@ -93,7 +93,7 @@ metadata_widget_init (MetadataWidget *self)
// image
priv->album_art = gtk_image_new();
- priv->image_path = g_strdup(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_IMAGE_PATH));
+ priv->image_path = g_strdup(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_ARTURL));
update_album_art(self);
gtk_box_pack_start (GTK_BOX (priv->hbox), priv->album_art, FALSE, FALSE, 0);
GtkWidget* vbox = gtk_vbox_new(TRUE, 0);
@@ -106,13 +106,13 @@ metadata_widget_init (MetadataWidget *self)
// piece
GtkWidget* piece;
- piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_PIECE));
+ piece = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_TITLE));
priv->piece_label = piece;
// container
GtkWidget* container;
- container = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER));
+ container = gtk_label_new(dbusmenu_menuitem_property_get(twin_item, DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM));
priv->container_label = container;
// Pack in the right order
@@ -171,13 +171,13 @@ metadata_widget_property_update(DbusmenuMenuitem* item, gchar* property,
if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST, property) == 0){
gtk_label_set_text(GTK_LABEL(priv->artist_label), g_value_get_string(value));
}
- else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_PIECE, property) == 0){
+ else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_TITLE, property) == 0){
gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value));
}
- else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER, property) == 0){
+ else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_TEXT_ALBUM, property) == 0){
gtk_label_set_text(GTK_LABEL(priv->container_label), g_value_get_string(value));
}
- else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, property) == 0){
+ else if(g_ascii_strcasecmp(DBUSMENU_METADATA_MENUITEM_ARTURL, property) == 0){
if(priv->image_path != NULL){
g_free(priv->image_path);
}
@@ -194,7 +194,7 @@ static void update_album_art(MetadataWidget* self){
MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(self);
GdkPixbuf* pixbuf;
pixbuf = gdk_pixbuf_new_from_file(priv->image_path, NULL);
- pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60,GDK_INTERP_BILINEAR);
+ pixbuf = gdk_pixbuf_scale_simple(pixbuf,60, 60, GDK_INTERP_BILINEAR);
g_debug("attempting to set the image with path %s", priv->image_path);
gtk_image_set_from_pixbuf(GTK_IMAGE(priv->album_art), pixbuf);
g_object_unref(pixbuf);
diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala
index 7e65594..a6d27be 100644
--- a/src/mpris-controller.vala
+++ b/src/mpris-controller.vala
@@ -20,7 +20,6 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Gee;
-
public class MprisController : GLib.Object
{
private DBus.Connection connection;
@@ -33,7 +32,6 @@ public class MprisController : GLib.Object
public int32 endless;
}
-
public MprisController(string name, PlayerController controller, string mpris_interface="org.freedesktop.MediaPlayer"){
try {
this.connection = DBus.Bus.get (DBus.BusType.SESSION);
@@ -43,18 +41,23 @@ public class MprisController : GLib.Object
this.controller = controller;
this.mpris_player = this.connection.get_object ("org.mpris.".concat(name.down()) , "/Player", mpris_interface);
this.mpris_player.TrackChange += onTrackChange;
- this.mpris_player.StatusChange += onStatusChange;
- this.controller.update_playing_info(get_track_data());
- }
+ this.mpris_player.StatusChange += onStatusChange;
- public HashMap<string, string> get_track_data()
- {
- return format_metadata(this.mpris_player.GetMetadata());
+ status st = this.mpris_player.GetStatus();
+ int play_state = st.playback;
+ debug("GetStatusChange - play state %i", play_state);
+ (this.controller.custom_items[this.controller.TRANSPORT] as TransportMenuitem).change_play_state(play_state);
+ this.controller.custom_items[this.controller.METADATA].update(this.mpris_player.GetMetadata(),
+ MetadataMenuitem.attributes_format());
+
}
+
private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> ht)
{
- this.controller.update_playing_info(format_metadata(ht));
+ debug("onTrackChange");
+ this.controller.custom_items[this.controller.METADATA].update(ht,
+ MetadataMenuitem.attributes_format());
}
/**
@@ -76,26 +79,16 @@ public class MprisController : GLib.Object
private void onStatusChange(dynamic DBus.Object mpris_client, status st)
{
debug("onStatusChange - signal received");
- //ValueArray a = new ValueArray(4);
- //Value v = new Value(typeof(int32));
- //v.set_int(st.playback);
- //a.append(v);
- //debug("onStatusChange - play %i", a.get_nth(0).get_int());
- //int playback = (ValueArray)st.get_nth(0).get_int();
- //int shuffle = ar.get_nth(1).get_int();
- //int repeat = ar.get_nth(2).get_int();
- //int endless = ar.get_nth(3).get_int();
+ status* status = &st;
+ unowned ValueArray ar = (ValueArray)status;
+ int play_state = ar.get_nth(0).get_int();
+ debug("onStatusChange - play state %i", play_state);
+ HashTable<string, Value?> ht = new HashTable<string, Value?>(str_hash, str_equal);
+ Value v = Value(typeof(int));
+ v.set_int(play_state);
+ ht.insert("state", v);
+ this.controller.custom_items[this.controller.TRANSPORT].update(ht, TransportMenuitem.attributes_format());
}
- private static HashMap<string, string> format_metadata(HashTable<string,Value?> data)
- {
- HashMap<string,string> results = new HashMap<string, string>();
- debug("format_metadata - title = %s", (string)data.lookup("title"));
- results.set("title", (string)data.lookup("title"));
- results.set("artist", (string)data.lookup("artist"));
- results.set("album", (string)data.lookup("album"));
- results.set("arturl", (string)data.lookup("arturl"));
- return results;
- }
}
diff --git a/src/player-controller.vala b/src/player-controller.vala
index aa72cac..862bb29 100644
--- a/src/player-controller.vala
+++ b/src/player-controller.vala
@@ -23,13 +23,13 @@ using Gee;
public class PlayerController : GLib.Object
{
- private const int METADATA = 2;
+ public const int METADATA = 2;
private const int TRANSPORT = 3;
private Dbusmenu.Menuitem root_menu;
private string name;
private bool is_active;
- private ArrayList<Dbusmenu.Menuitem> custom_items;
+ public ArrayList<PlayerItem> custom_items;
private MprisController mpris_adaptor;
public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active)
@@ -37,7 +37,7 @@ public class PlayerController : GLib.Object
this.root_menu = root;
this.name = format_client_name(client_name.strip());
this.is_active = active;
- this.custom_items = new ArrayList<Dbusmenu.Menuitem>();
+ this.custom_items = new ArrayList<PlayerItem>();
self_construct();
// Temporary scenario to handle both v1 and v2 of MPRIS.
@@ -47,12 +47,7 @@ public class PlayerController : GLib.Object
else{
this.mpris_adaptor = new MprisController(this.name, this);
}
-
- // TODO subclass dbusmenuMenuitem to something like a playermenuitem
- // and use this type to collectively
- // control widgets.
- TransportMenuitem t = (TransportMenuitem)this.custom_items[TRANSPORT];
- t.set_adaptor(this.mpris_adaptor);
+ this.custom_items[TRANSPORT].set_adaptor(this.mpris_adaptor);
}
public void vanish()
@@ -65,15 +60,10 @@ public class PlayerController : GLib.Object
private bool self_construct()
{
// 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);
+ this.custom_items.add(PlayerItem.new_separator_item());
// Title item
- Dbusmenu.Menuitem title_item = new Dbusmenu.Menuitem();
- title_item.property_set(MENUITEM_PROP_LABEL, this.name);
- title_item.property_set(MENUITEM_PROP_ICON_NAME, "applications-multimedia");
- this.custom_items.add(title_item);
+ this.custom_items.add(PlayerItem.new_title_item(this.name));
// Metadata item
MetadataMenuitem metadata_item = new MetadataMenuitem();
@@ -84,18 +74,18 @@ public class PlayerController : GLib.Object
this.custom_items.add(transport_item);
int offset = 2;
- foreach(Dbusmenu.Menuitem item in this.custom_items){
+ foreach(PlayerItem item in this.custom_items){
root_menu.child_add_position(item, offset + this.custom_items.index_of(item));
}
return true;
}
- public void update_playing_info(HashMap<string, string> data)
- {
- debug("PlayerController - update_playing_info");
- MetadataMenuitem item = (MetadataMenuitem)this.custom_items[METADATA];
- item.update(data);
- }
+ //public void update_playing_info(HashMap<string, string> data)
+ //{
+ // debug("PlayerController - update_playing_info");
+ // MetadataMenuitem item = this.custom_items[METADATA] as MetadataMenuitem;
+ // item.update(data, MetadataMenuitem.attributes_format());
+ //}
private static string format_client_name(string client_name)
{
diff --git a/src/player-item.vala b/src/player-item.vala
new file mode 100644
index 0000000..09b0e6b
--- /dev/null
+++ b/src/player-item.vala
@@ -0,0 +1,89 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+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 <http://www.gnu.org/licenses/>.
+*/
+
+using Dbusmenu;
+using Gee;
+
+public class PlayerItem : Dbusmenu.Menuitem
+{
+ public MprisController mpris_adaptor;
+
+ public PlayerItem()
+ {
+ }
+
+ public void update(HashTable<string, Value?> data, HashSet<string> attributes)
+ {
+ debug("PlayerItem::update()");
+ foreach(string property in attributes){
+ string[] input_keys = property.split("-");
+ string search_key = input_keys[input_keys.length-1 : input_keys.length][0];
+ debug("search key = %s", search_key);
+
+ Value v = data.lookup(search_key);
+
+ if (v.holds (typeof (string))){
+ this.property_set(property, this.sanitize_string(v.get_string()));
+ }
+ else if (v.holds (typeof (int))){
+ debug("with value : %i", v.get_int());
+ this.property_set_int(property, v.get_int());
+ }
+ else if(v.holds (typeof (bool))){
+ this.property_set_bool(property, v.get_boolean());
+ }
+ }
+ }
+
+ public void set_adaptor(MprisController adaptor)
+ {
+ this.mpris_adaptor = adaptor;
+ }
+
+
+ public static string sanitize_string(string st)
+ {
+ string result = st.strip();
+ if(result.has_prefix("file:///")){
+ result = result.slice(7, result.len());
+ }
+ debug("Sanitize string - result = %s", result);
+ 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();
+ separator.property_set(MENUITEM_PROP_TYPE, CLIENT_TYPES_SEPARATOR);
+ return separator;
+ }
+}
+
diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala
index 2e1ed0b..39a0cab 100644
--- a/src/transport-menu-item.vala
+++ b/src/transport-menu-item.vala
@@ -1,5 +1,4 @@
/*
-This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
Copyright 2010 Canonical Ltd.
Authors:
@@ -20,35 +19,32 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Dbusmenu;
using Gee;
+using DbusmenuTransport;
-public class TransportMenuitem : Dbusmenu.Menuitem
+public class TransportMenuitem : PlayerItem
{
- /* 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";
- private MprisController mpris_adaptor;
public TransportMenuitem()
{
- this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_TYPE);
- // Hardcode the set up state until we can get the struct vala bug fixed
- this.property_set_bool(DBUSMENU_TRANSPORT_MENUITEM_STATE, false);
+ this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE);
debug("transport on the vala side");
}
- public void set_adaptor(MprisController adaptor)
+ public void change_play_state(int state)
{
- this.mpris_adaptor = adaptor;
+ this.property_set_int(MENUITEM_PLAY_STATE, state);
}
- /**
- Callback method for the handle_event
- * TRUE => Playing
- * FALSE => Paused
- **/
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 static HashSet<string> attributes_format()
+ {
+ HashSet<string> attrs = new HashSet<string>();
+ attrs.add(MENUITEM_PLAY_STATE);
+ return attrs;
}
} \ No newline at end of file
diff --git a/src/transport-widget.c b/src/transport-widget.c
index c53513d..bc9df53 100644
--- a/src/transport-widget.c
+++ b/src/transport-widget.c
@@ -61,13 +61,15 @@ static gboolean transport_widget_button_press_event (GtkWidget *men
GdkEventButton *event);
static gboolean transport_widget_button_release_event (GtkWidget *menuitem,
GdkEventButton *event);
-
+static void transport_widget_play_clicked (GtkWidget* button,
+ TransportWidget* self);
+
static void transport_widget_property_update(DbusmenuMenuitem* item,
gchar * property,
GValue * value,
gpointer userdata);
// utility methods
-static gchar* transport_widget_toggle_play_label(const gchar* state);
+static gchar* transport_widget_toggle_play_label(gint state);
G_DEFINE_TYPE (TransportWidget, transport_widget, GTK_TYPE_MENU_ITEM);
@@ -78,7 +80,9 @@ transport_widget_class_init (TransportWidgetClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkMenuItemClass *menu_item_class = GTK_MENU_ITEM_CLASS(klass);
+ menu_item_class->hide_on_activate = FALSE;
widget_class->button_press_event = transport_widget_button_press_event;
widget_class->button_release_event = transport_widget_button_release_event;
@@ -130,19 +134,17 @@ transport_widget_init (TransportWidget *self)
GtkWidget *hbox;
hbox = gtk_hbox_new(TRUE, 2);
-
- gchar* label = ">";
- if(dbusmenu_menuitem_property_get_bool(twin_item, DBUSMENU_TRANSPORT_MENUITEM_STATE) == TRUE){
- label = "||";
- }
-
- priv->play_button = gtk_button_new_with_label(g_strdup(label));
+ gchar* symbol = transport_widget_toggle_play_label(dbusmenu_menuitem_property_get_int(twin_item, DBUSMENU_TRANSPORT_MENUITEM_PLAY_STATE));
+ priv->play_button = gtk_button_new_with_label(symbol);
+ //g_free(symbol);
gtk_box_pack_start (GTK_BOX (hbox), priv->play_button, FALSE, TRUE, 0);
priv->hbox = hbox;
g_signal_connect(G_OBJECT(twin_item), "property-changed", G_CALLBACK(transport_widget_property_update), self);
+ g_signal_connect(priv->play_button, "clicked", G_CALLBACK(transport_widget_play_clicked), self);
+
gtk_container_add (GTK_CONTAINER (self), priv->hbox);
gtk_widget_show_all (priv->hbox);
@@ -166,11 +168,16 @@ transport_widget_button_press_event (GtkWidget *menuitem,
GdkEventButton *event)
{
g_debug("TransportWidget::menu_press_event");
+ if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){
+ return FALSE;
+ }
+
TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem));
+ gtk_widget_event (priv->hbox, (GdkEvent*)event);
gboolean state = g_ascii_strcasecmp(gtk_button_get_label(GTK_BUTTON(priv->play_button)), ">") == 0;
- gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label(gtk_button_get_label(GTK_BUTTON(priv->play_button))));
+ gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label((gint)state));
GValue value = {0};
g_value_init(&value, G_TYPE_BOOLEAN);
g_debug("TransportWidget::menu_press_event - going to send value %i", state);
@@ -181,11 +188,25 @@ transport_widget_button_press_event (GtkWidget *menuitem,
return TRUE;
}
+static void
+transport_widget_play_clicked(GtkWidget* button,
+ TransportWidget* self)
+{
+ g_debug("Transport_widget_play_clicked");
+}
+
static gboolean
transport_widget_button_release_event (GtkWidget *menuitem,
GdkEventButton *event)
{
g_debug("TransportWidget::menu_release_event");
+ if(IS_TRANSPORT_WIDGET(menuitem) == FALSE){
+ return FALSE;
+ }
+
+ TransportWidgetPrivate * priv = TRANSPORT_WIDGET_GET_PRIVATE(TRANSPORT_WIDGET(menuitem));
+ gtk_widget_event (priv->hbox, (GdkEvent*)event);
+
return TRUE;
}
@@ -195,23 +216,23 @@ transport_widget_button_release_event (GtkWidget *menuitem,
**/
static void
transport_widget_property_update(DbusmenuMenuitem* item, gchar* property,
- GValue* value, gpointer userdata)
+ GValue* value, gpointer userdata)
{
g_debug("transport_widget_update_state - with property %s", property);
- gchar* input = g_strdup(g_value_get_string(value));
- g_debug("transport_widget_update_state - with value %s", input);
+ int update_value = g_value_get_int(value);
+ g_debug("transport_widget_update_state - with value %i", update_value);
TransportWidget* bar = (TransportWidget*)userdata;
TransportWidgetPrivate *priv = TRANSPORT_WIDGET_GET_PRIVATE(bar);
- gtk_button_set_label(GTK_BUTTON(priv->play_button), g_strdup(transport_widget_toggle_play_label(property)));
+ gtk_button_set_label(GTK_BUTTON(priv->play_button), transport_widget_toggle_play_label(update_value));
}
// will be needed for image swapping
-static gchar* transport_widget_toggle_play_label(const gchar* state)
+static gchar* transport_widget_toggle_play_label(int play_state)
{
gchar* label = ">";
- if(g_strcmp0(state, ">") == 0){
+ if(play_state == 1){
label = "||";
}
return label;
diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi
new file mode 100644
index 0000000..222fb67
--- /dev/null
+++ b/vapi/common-defs.vapi
@@ -0,0 +1,33 @@
+/*
+Copyright 2010 Canonical Ltd.
+
+Authors:
+ Conor Curran <conor.curran@canonical.com>
+
+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 <http://www.gnu.org/licenses/>.
+*/
+
+[CCode (cheader_filename = "common-defs.h")]
+namespace DbusmenuMetadata{
+ public const string MENUITEM_TYPE;
+ public const string MENUITEM_TEXT_ARTIST;
+ public const string MENUITEM_TEXT_TITLE;
+ public const string MENUITEM_TEXT_ALBUM;
+ public const string MENUITEM_ARTURL;
+}
+
+[CCode (cheader_filename = "common-defs.h")]
+namespace DbusmenuTransport{
+ public const string MENUITEM_TYPE;
+ public const string MENUITEM_PLAY_STATE;
+} \ No newline at end of file