From 6272c2ce0798306045ea4d70af8ea4670bf61c5f Mon Sep 17 00:00:00 2001 From: Erica Z Date: Fri, 1 Nov 2024 14:54:09 +0100 Subject: [PATCH] dog shit metadata map --- src/mpris/player.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) 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)]