aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/metadata-menu-item.vala15
-rw-r--r--src/metadata-widget.c21
-rw-r--r--src/metadata-widget.h2
-rw-r--r--src/mpris-controller-v2.vala28
-rw-r--r--src/mpris-controller.vala61
-rw-r--r--src/music-player-bridge.vala21
-rw-r--r--src/player-controller.vala37
-rw-r--r--src/sound-service.c4
-rw-r--r--src/transport-menu-item.vala20
10 files changed, 195 insertions, 18 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 2a19c3d..ac7beb9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -54,7 +54,9 @@ music_bridge_VALASOURCES = \
music-player-bridge.vala \
transport-menu-item.vala \
metadata-menu-item.vala \
- player-controller.vala
+ player-controller.vala \
+ mpris-controller-v2.vala \
+ mpris-controller.vala
music_bridge_VALAFLAGS = \
--ccode \
diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala
index ef72143..894ad3c 100644
--- a/src/metadata-menu-item.vala
+++ b/src/metadata-menu-item.vala
@@ -13,15 +13,16 @@ public class MetadataMenuitem : Dbusmenu.Menuitem
public MetadataMenuitem()
{
this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_METADATA_MENUITEM_TYPE);
- this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST, "Sonnamble");
- this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_PIECE, "Nocturne");
- this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER, "Seven Months in E minor");
- this.property_set(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, "/home/ronoc/Desktop/Sonnamble/Sonnamble_CD.jpg");
-
- debug("image_path property set %s:", this.property_get(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH));
-
}
+ public void update(HashMap<string, string> data)
+ {
+ this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_ARTIST, data.get("artist"));
+ this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_PIECE, data.get("title"));
+ this.property_set(DBUSMENU_METADATA_MENUITEM_TEXT_CONTAINER, data.get("album"));
+ this.property_set(DBUSMENU_METADATA_MENUITEM_IMAGE_PATH, data.get("arturl"));
+ }
+
public override void handle_event(string name, GLib.Value input_value, uint timestamp)
{
debug("MetadataItem -> handle event caught!");
diff --git a/src/metadata-widget.c b/src/metadata-widget.c
index a451ad7..e69a9dd 100644
--- a/src/metadata-widget.c
+++ b/src/metadata-widget.c
@@ -53,9 +53,9 @@ static gboolean metadata_widget_button_press_event (GtkWidget *menuitem,
static gboolean metadata_widget_button_release_event (GtkWidget *menuitem,
GdkEventButton *event);
// Dbusmenuitem properties update callback
-static void metadata_widget_update_state(gchar * property,
- GValue * value,
- gpointer userdata);
+static void metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property,
+ GValue* value, gpointer userdata);
+
//static void update_content(
@@ -159,9 +159,20 @@ metadata_widget_button_release_event (GtkWidget *menuitem,
return TRUE;
}
-static void metadata_widget_update_state(gchar *property, GValue *value, gpointer userdata)
+static void
+metadata_widget_update_state(DbusmenuMenuitem* item, gchar* property,
+ GValue* value, gpointer userdata)
{
- g_debug("metadata_widget_update_state - with property %s", property);
+ //g_debug("metadata_widget_update_state - with property %s", property);
+ MetadataWidget* mitem = METADATA_WIDGET(userdata);
+ MetadataWidgetPrivate * priv = METADATA_WIDGET_GET_PRIVATE(mitem);
+
+ 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){
+ gtk_label_set_text(GTK_LABEL(priv->piece_label), g_value_get_string(value));
+ }
}
/**
diff --git a/src/metadata-widget.h b/src/metadata-widget.h
index ce7df5f..6f1d4d3 100644
--- a/src/metadata-widget.h
+++ b/src/metadata-widget.h
@@ -25,7 +25,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
G_BEGIN_DECLS
#define METADATA_WIDGET_TYPE (metadata_widget_get_type ())
-#define METADATA_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), METADATA_WIDGET_TYPE, TransportBar))
+#define METADATA_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), METADATA_WIDGET_TYPE, MetadataWidget))
#define METADATA_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), METADATA_WIDGET_TYPE, MetadataWidgetClass))
#define IS_METADATA_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), METADATA_WIDGET_TYPE))
#define IS_METADATA_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), METADATA_WIDGET_TYPE))
diff --git a/src/mpris-controller-v2.vala b/src/mpris-controller-v2.vala
new file mode 100644
index 0000000..0392cfc
--- /dev/null
+++ b/src/mpris-controller-v2.vala
@@ -0,0 +1,28 @@
+/*
+This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
+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 Gee;
+
+public class MprisControllerV2 : MprisController
+{
+ public MprisControllerV2(string name, PlayerController controller){
+ base(name, controller, "org.mpris.MediaPlayer.Player");
+ }
+
+}
diff --git a/src/mpris-controller.vala b/src/mpris-controller.vala
new file mode 100644
index 0000000..f606b32
--- /dev/null
+++ b/src/mpris-controller.vala
@@ -0,0 +1,61 @@
+/*
+This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
+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 Gee;
+
+public class MprisController : GLib.Object
+{
+ private DBus.Connection connection;
+ private dynamic DBus.Object mpris_player;
+ private PlayerController controller;
+
+ public MprisController(string name, PlayerController controller, string mpris_interface="org.freedesktop.MediaPlayer"){
+ try {
+ this.connection = DBus.Bus.get (DBus.BusType.SESSION);
+ } catch (Error e) {
+ error("Problems connecting to the session bus - %s", e.message);
+ }
+ this.controller = controller;
+ this.mpris_player = this.connection.get_object ("org.mpris.".concat(name.down()) , "/Player", mpris_interface);
+ this.mpris_player.TrackChange += onTrackChange;
+ this.controller.update_playing_info(get_track_data());
+ }
+
+ public HashMap<string, string> get_track_data()
+ {
+ return format_metadata(this.mpris_player.GetMetadata());
+ }
+
+ private void onTrackChange(dynamic DBus.Object mpris_client, HashTable<string,Value?> ht)
+ {
+ this.controller.update_playing_info(format_metadata(ht));
+ }
+
+ 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/music-player-bridge.vala b/src/music-player-bridge.vala
index 89f633b..b03ecbd 100644
--- a/src/music-player-bridge.vala
+++ b/src/music-player-bridge.vala
@@ -1,3 +1,23 @@
+/*
+This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
+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 Indicate;
using Dbusmenu;
using Gee;
@@ -23,7 +43,6 @@ public class MusicPlayerBridge : GLib.Object
public void set_root_menu_item(Dbusmenu.Menuitem menu)
{
- debug("MusicPlayerBridge -> set_root_menu_item");
root_menu = menu;
}
diff --git a/src/player-controller.vala b/src/player-controller.vala
index dcb428b..4c09c12 100644
--- a/src/player-controller.vala
+++ b/src/player-controller.vala
@@ -1,12 +1,35 @@
+/*
+This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
+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 PlayerController : GLib.Object
{
+ private const int METADATA = 2;
private Dbusmenu.Menuitem root_menu;
private string name;
private bool is_active;
private ArrayList<Dbusmenu.Menuitem> custom_items;
+ private MprisController mpris_adaptor;
// TODO: pass in the appropriate position for the menu (to handle multiple players)
public PlayerController(Dbusmenu.Menuitem root, string client_name, bool active)
@@ -16,6 +39,12 @@ public class PlayerController : GLib.Object
this.is_active = active;
this.custom_items = new ArrayList<Dbusmenu.Menuitem>();
self_construct();
+ // Temporary scenario to handle both v1 and v2 of MPRIS.
+ if(this.name == "Vlc"){
+ this.mpris_adaptor = new MprisControllerV2(this.name, this);
+ }else{
+ this.mpris_adaptor = new MprisController(this.name, this);
+ }
}
public void vanish()
@@ -52,7 +81,13 @@ public class PlayerController : GLib.Object
}
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);
+ }
private static string format_client_name(string client_name)
{
diff --git a/src/sound-service.c b/src/sound-service.c
index 38e5fba..3ec7a60 100644
--- a/src/sound-service.c
+++ b/src/sound-service.c
@@ -45,8 +45,8 @@ service_shutdown (IndicatorService *service, gpointer user_data)
if (mainloop != NULL) {
g_debug("Service shutdown !");
// TODO: uncomment for release !!
- close_pulse_activites();
- g_main_loop_quit(mainloop);
+ //close_pulse_activites();
+ //g_main_loop_quit(mainloop);
}
return;
}
diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala
index 7687a92..2259e43 100644
--- a/src/transport-menu-item.vala
+++ b/src/transport-menu-item.vala
@@ -1,3 +1,23 @@
+/*
+This service primarily controls PulseAudio and is driven by the sound indicator menu on the panel.
+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;