aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/indicator-sound.c24
-rw-r--r--src/metadata-menu-item.vala5
-rw-r--r--src/player-controller.vala7
-rw-r--r--src/player-item.vala33
-rw-r--r--src/title-menu-item.vala15
-rw-r--r--src/title-widget.c48
-rw-r--r--src/transport-menu-item.vala13
7 files changed, 84 insertions, 61 deletions
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 <http://www.gnu.org/licenses/>.
#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<PlayerItem> 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<string, Value?> data, HashSet<string> 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<string> attributes_format()
{
HashSet<string> attrs = new HashSet<string>();
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 ("<span weight=\"bold\">%s</span>",
+ 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<string> attributes_format()
{