aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorConor Curran <conor.curran@canonical.com>2010-07-06 18:55:05 +0100
committerConor Curran <conor.curran@canonical.com>2010-07-06 18:55:05 +0100
commit7555ea6755750dd64a6c4652b852a0bdc0d0bfeb (patch)
treef636897b4b133057a06dcc60e650e0b8f95acd2d /src
parentedac78eadc5ddceb17b93bffa101eeffbab4437c (diff)
downloadayatana-indicator-sound-7555ea6755750dd64a6c4652b852a0bdc0d0bfeb.tar.gz
ayatana-indicator-sound-7555ea6755750dd64a6c4652b852a0bdc0d0bfeb.tar.bz2
ayatana-indicator-sound-7555ea6755750dd64a6c4652b852a0bdc0d0bfeb.zip
whole new widget to house the customised title item
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am3
-rw-r--r--src/common-defs.h3
-rw-r--r--src/metadata-menu-item.vala2
-rw-r--r--src/mpris-controller.vala5
-rw-r--r--src/music-player-bridge.vala17
-rw-r--r--src/player-controller.vala97
-rw-r--r--src/player-item.vala30
-rw-r--r--src/title-menu-item.vala37
-rw-r--r--src/title-widget.c155
-rw-r--r--src/title-widget.h51
-rw-r--r--src/transport-menu-item.vala4
-rw-r--r--src/transport-widget.c2
12 files changed, 355 insertions, 51 deletions
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 <http://www.gnu.org/licenses/>.
#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<string> 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<PlayerItem> 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<PlayerItem>();
- 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<string> 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 <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 DbusmenuTitle;
+using Gee;
+
+public class TitleMenuitem : PlayerItem
+{
+ public TitleMenuitem()
+ {
+ Object(item_type: MENUITEM_TYPE);
+ }
+
+ public static HashSet<string> attributes_format()
+ {
+ HashSet<string> attrs = new HashSet<string>();
+ 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 <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/>.
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib/gi18n.h>
+#include "title-widget.h"
+#include "common-defs.h"
+#include <gtk/gtk.h>
+
+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 <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/>.
+*/
+#ifndef __TITLE_WIDGET_H__
+#define __TITLE_WIDGET_H__
+
+#include <gtk/gtkmenuitem.h>
+#include <libdbusmenu-gtk/menu.h>
+
+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 <http://www.gnu.org/licenses/>.
#include "common-defs.h"
#include <gtk/gtk.h>
-// TODO: think about leakage: ted !
-
static DbusmenuMenuitem* twin_item;
typedef struct _TransportWidgetPrivate TransportWidgetPrivate;