aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/metadata-menu-item.vala32
-rw-r--r--src/player-item.vala54
-rw-r--r--src/transport-menu-item.vala13
-rw-r--r--vapi/common-defs.vapi6
4 files changed, 40 insertions, 65 deletions
diff --git a/src/metadata-menu-item.vala b/src/metadata-menu-item.vala
index 8d626ca..08b1b85 100644
--- a/src/metadata-menu-item.vala
+++ b/src/metadata-menu-item.vala
@@ -9,32 +9,14 @@ public class MetadataMenuitem : PlayerItem
this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE);
}
- //public override void update(HashMap<string, string> data)
- //{
- // this.property_set(MENUITEM_TEXT_ARTIST, data.get("artist").strip());
- // this.property_set(MENUITEM_TEXT_TITLE, data.get("title").strip());
- // this.property_set(MENUITEM_TEXT_ALBUM, data.get("album").strip());
- // this.property_set(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;
- }
-
- public static HashMap<string, Type> attributes_format()
+ public static HashSet<string> attributes_format()
{
- HashMap<string,Type> results = new HashMap<string, Type>();
- results.set(MENUITEM_TEXT_TITLE, typeof(string));
- results.set(MENUITEM_TEXT_ARTIST, typeof(string));
- results.set(MENUITEM_TEXT_ALBUM, typeof(string));
- results.set(MENUITEM_ARTURL, typeof(string));
- return results;
+ 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;
}
} \ No newline at end of file
diff --git a/src/player-item.vala b/src/player-item.vala
index ee09074..7bf1063 100644
--- a/src/player-item.vala
+++ b/src/player-item.vala
@@ -28,49 +28,43 @@ public class PlayerItem : Dbusmenu.Menuitem
public PlayerItem()
{
}
-
- public void update(HashTable<string, Value?> data, HashMap<string, Type> attributes)
+
+ public void update(HashTable<string, Value?> data, HashSet<string> attributes)
{
debug("PlayerItem::update()");
- foreach(var property in attributes){
- //debug("property value = %s", attributes.get(property.key).name());
- GLib.Object obj = GLib.Object.new(attributes.get(property.key));
- debug("bang line");
- Type t = obj.get_type();
- if(t.is_a(typeof(string)) == true){
- debug("obj is a string !!! we can tell -halla fucking lula!");
+ foreach(string property in attributes){
+ string[] input_keys = property.split("-");
+ string search_key = input_keys[input_keys.length-1 : input_keys.length][0];
+ if (data.lookup(search_key).holds (typeof (string))){
+ this.property_set(property, this.sanitize_string(data.lookup(search_key) as string));
+ }
+ else if (data.lookup(search_key).holds (typeof (int))){
+ // Circumvent weird vala bug
+ int* v = (int*)data.lookup(search_key);
+ int r = *v;
+ this.property_set_int(property, r);
}
- //string[] input_keys = property.key.split("-");
- //string search_key = input_keys[input_keys.length-1 : input_keys.length][0];
- //debug("key parsed from properties is %s", search_key);
- //debug("and the bloody type should be %s", property.value.name());
- //var input_value = data.lookup(search_key) as property.value.name();
- //foreach(var s in input_keys){
- // debug("string = %s", s);
- //}
- //string[] st = input_keys[input_keys.length-1 : input_keys.length];
- //property.value as attributes.get(property.key)
- //this.property_set(property.key, );
}
- }
+ }
public void set_adaptor(MprisController adaptor)
{
this.mpris_adaptor = adaptor;
}
- public static HashMap<string, string> format_updates(HashTable<string,Value?> ht)
+
+ public static string sanitize_string(string st)
{
- HashMap<string,string> results = new HashMap<string, string>();
- //HashMap<string, Type> attrs = attributes_format();
- //results.set(MENUITEM_TEXT_TITLE, (string)data.lookup("title").strip());
- //results.set(MENUITEM_TEXT_ARTIST, (string)data.lookup("artist").strip());
- //results.set(MENUITEM_TEXT_ALBUM, (string)data.lookup("album").strip(), typeof(string));
- //results.set(MENUITEM_TEXT_ARTURL, sanitize_image_path((string)data.lookup("arturl").strip()), typeof(string));
- return results;
+ string result = st.strip();
+ if(result.has_prefix("file:///")){
+ result = result.slice(7, result.len());
+ }
+ debug("Sanitize string - result = %s", result);
+ return result;
}
+
- // Bespoke constructors for player items
+ //----- Custom constructors for player items ----------------//
// Title item
public static PlayerItem new_title_item(dynamic string name)
{
diff --git a/src/transport-menu-item.vala b/src/transport-menu-item.vala
index bfa81d3..3c49e1c 100644
--- a/src/transport-menu-item.vala
+++ b/src/transport-menu-item.vala
@@ -20,25 +20,18 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
using Dbusmenu;
using Gee;
+using DbusmenuTransport;
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";
public TransportMenuitem()
{
- this.property_set(MENUITEM_PROP_TYPE, DBUSMENU_TRANSPORT_MENUITEM_TYPE);
- this.property_set_bool(DBUSMENU_TRANSPORT_MENUITEM_STATE, false);
+ this.property_set(MENUITEM_PROP_TYPE, MENUITEM_TYPE);
+ this.property_set_bool(MENUITEM_STATE, false);
debug("transport on the vala side");
}
- //public override void update(HashMap<string, string> data)
- //{
- // debug("TransportMenuitem::update()");
- //}
-
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());
diff --git a/vapi/common-defs.vapi b/vapi/common-defs.vapi
index ce77929..67dc1f3 100644
--- a/vapi/common-defs.vapi
+++ b/vapi/common-defs.vapi
@@ -6,4 +6,10 @@ namespace DbusmenuMetadata{
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_STATE;
} \ No newline at end of file