diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 2ea06e4..9be58b9 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -1,11 +1,35 @@ use glib::SendWeakRef; use gtk::glib; +use std::collections::HashMap; use zbus::object_server::SignalEmitter; -use zbus::zvariant::{ObjectPath, Value}; +use zbus::zvariant::{ObjectPath, OwnedObjectPath, Type, Value}; + +#[derive(Clone, Value, Type)] +#[zvariant(signature = "a{sv}")] +struct MetadataMap { + pub trackid: OwnedObjectPath, + // rest: TODO +} + +impl MetadataMap { + fn as_hash_map(&self) -> HashMap<&'static str, Value> { + HashMap::from([("mpris:trackid", Value::new(self.trackid.as_ref()))]) + } +} + +impl Default for MetadataMap { + fn default() -> Self { + Self { + trackid: "/org/mpris/MediaPlayer2/TrackList/NoTrack" + .try_into() + .unwrap(), + } + } +} pub struct Player { playbin: SendWeakRef, - metadata: Vec<(String, String)>, + metadata: MetadataMap, } impl Player { @@ -124,11 +148,8 @@ impl Player { } #[zbus(property)] - fn metadata(&self) -> Vec<(String, Value)> { - self.metadata - .iter() - .map(|(k, v)| (k.clone(), v.into())) - .collect() + fn metadata(&self) -> HashMap<&'static str, Value> { + self.metadata.as_hash_map() } #[zbus(property)]