dog shit metadata map

This commit is contained in:
Erica Z 2024-11-01 14:54:09 +01:00
parent 519424d42f
commit 6272c2ce07

View file

@ -1,11 +1,35 @@
use glib::SendWeakRef; use glib::SendWeakRef;
use gtk::glib; use gtk::glib;
use std::collections::HashMap;
use zbus::object_server::SignalEmitter; 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 { pub struct Player {
playbin: SendWeakRef<crate::Playbin>, playbin: SendWeakRef<crate::Playbin>,
metadata: Vec<(String, String)>, metadata: MetadataMap,
} }
impl Player { impl Player {
@ -124,11 +148,8 @@ impl Player {
} }
#[zbus(property)] #[zbus(property)]
fn metadata(&self) -> Vec<(String, Value)> { fn metadata(&self) -> HashMap<&'static str, Value> {
self.metadata self.metadata.as_hash_map()
.iter()
.map(|(k, v)| (k.clone(), v.into()))
.collect()
} }
#[zbus(property)] #[zbus(property)]