diff --git a/src/rust/mpris/src/types.rs b/src/rust/mpris/src/types.rs index d4ce97facfef4eb42a4cd38a4f61831fdfb2ce05..840fda9e2dc8523ed5a573dcb4c30a22cfeccb55 100644 --- a/src/rust/mpris/src/types.rs +++ b/src/rust/mpris/src/types.rs @@ -30,11 +30,12 @@ pub struct TimeMicroSec(i64); #[zvariant(signature = "a{sv}")] pub struct TrackMetadata(HashMap<String, String>); -/// A valid path must be prefiexed by `/org/mpris/MediaPlayer2`. After that we -/// have the variant name, then a `/`, then the ascii only value. For example -/// we can have: -/// - `/org/mpris/MediaPlayer2/Id/42` -/// - `/org/mpris/MediaPlayer2/None` +/// A valid path must be prefiexed by `/org/lektor/MPRIS`. After that we have +/// the variant name, then a `/`, then the ascii only value. For example we can +/// have: +/// - `/org/lektor/MPRIS/Id/42` +/// - `/org/lektor/MPRIS/Position/0` +/// - `/org/lektor/MPRIS/None` /// - `/org/mpris/MediaPlayer2/TrackList/NoTrack` is a special case... #[derive(Debug, Serialize, Deserialize, ZType, Clone, Copy, PartialEq, Eq, Default)] #[zvariant(signature = "o")] @@ -104,13 +105,13 @@ impl From<ZValue<'_>> for ObjectPath { let value = value.trim_start_matches('/'); match value.split('/').collect::<Vec<_>>()[..] { ["org", "mpris", "MediaPlayer2", "TrackList", "NoTrack"] => Self::NoTrack, - ["org", "mpris", "MediaPlayer2", "None"] => Self::None, - ["org", "mpris", "MediaPlayer2", "Position", position] => position + ["org", "lektor", "MPRIS", "None"] => Self::None, + ["org", "lektor", "MPRIS", "Position", position] => position .parse::<i64>() - .map(Self::Position) + .map(ObjectPath::Position) .unwrap_or_default(), - ["org", "mpris", "MediaPlayer2", "Id", id] => { - id.parse::<i64>().map(Self::Id).unwrap_or_default() + ["org", "lektor", "MPRIS", "Id", id] => { + id.parse::<i64>().map(ObjectPath::Id).unwrap_or_default() } _ => Default::default(), } @@ -119,18 +120,24 @@ impl From<ZValue<'_>> for ObjectPath { impl From<ObjectPath> for ZValue<'_> { fn from(value: ObjectPath) -> Self { - use ObjectPath::*; - ZValue::ObjectPath( - match value { - None => ZObjectPath::try_from("/org/mpris/MediaPlayer2/None"), - NoTrack => ZObjectPath::try_from("/org/mpris/MediaPlayer2/TrackList/NoTrack"), - Id(id) => ZObjectPath::try_from(format!("/org/mpris/MediaPlayer2/Id/{id}")), - Position(position) => { - ZObjectPath::try_from(format!("/org/mpris/MediaPlayer2/Position/{position}")) + let string = 'string: { + use ObjectPath::*; + return ZValue::ObjectPath( + match value { + // Static things + NoTrack => ZObjectPath::try_from("/org/mpris/MediaPlayer2/TrackList/NoTrack"), + None => ZObjectPath::try_from("/org/lektor/MPRIS/None"), + + // Formated as strings + Id(id) => break 'string format!("/org/lektor/MPRIS/Id/{id}"), + Position(position) => { + break 'string format!("/org/lektor/MPRIS/Position/{position}") + } } - } - .expect("incorrect serialization"), - ) + .expect("incorrect serialization"), + ); + }; + ZValue::ObjectPath(ZObjectPath::try_from(string).expect("incorrect serialization")) } }