Skip to content
Extraits de code Groupes Projets
Vérifiée Valider a18d5035 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MPRIS: Correctly name objects paths -> /org/mpris/MediaPlayer2 is reserved!

parent 33aa0f80
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -30,11 +30,12 @@ pub struct TimeMicroSec(i64); ...@@ -30,11 +30,12 @@ pub struct TimeMicroSec(i64);
#[zvariant(signature = "a{sv}")] #[zvariant(signature = "a{sv}")]
pub struct TrackMetadata(HashMap<String, String>); pub struct TrackMetadata(HashMap<String, String>);
/// A valid path must be prefiexed by `/org/mpris/MediaPlayer2`. After that we /// A valid path must be prefiexed by `/org/lektor/MPRIS`. After that we have
/// have the variant name, then a `/`, then the ascii only value. For example /// the variant name, then a `/`, then the ascii only value. For example we can
/// we can have: /// have:
/// - `/org/mpris/MediaPlayer2/Id/42` /// - `/org/lektor/MPRIS/Id/42`
/// - `/org/mpris/MediaPlayer2/None` /// - `/org/lektor/MPRIS/Position/0`
/// - `/org/lektor/MPRIS/None`
/// - `/org/mpris/MediaPlayer2/TrackList/NoTrack` is a special case... /// - `/org/mpris/MediaPlayer2/TrackList/NoTrack` is a special case...
#[derive(Debug, Serialize, Deserialize, ZType, Clone, Copy, PartialEq, Eq, Default)] #[derive(Debug, Serialize, Deserialize, ZType, Clone, Copy, PartialEq, Eq, Default)]
#[zvariant(signature = "o")] #[zvariant(signature = "o")]
...@@ -104,13 +105,13 @@ impl From<ZValue<'_>> for ObjectPath { ...@@ -104,13 +105,13 @@ impl From<ZValue<'_>> for ObjectPath {
let value = value.trim_start_matches('/'); let value = value.trim_start_matches('/');
match value.split('/').collect::<Vec<_>>()[..] { match value.split('/').collect::<Vec<_>>()[..] {
["org", "mpris", "MediaPlayer2", "TrackList", "NoTrack"] => Self::NoTrack, ["org", "mpris", "MediaPlayer2", "TrackList", "NoTrack"] => Self::NoTrack,
["org", "mpris", "MediaPlayer2", "None"] => Self::None, ["org", "lektor", "MPRIS", "None"] => Self::None,
["org", "mpris", "MediaPlayer2", "Position", position] => position ["org", "lektor", "MPRIS", "Position", position] => position
.parse::<i64>() .parse::<i64>()
.map(Self::Position) .map(ObjectPath::Position)
.unwrap_or_default(), .unwrap_or_default(),
["org", "mpris", "MediaPlayer2", "Id", id] => { ["org", "lektor", "MPRIS", "Id", id] => {
id.parse::<i64>().map(Self::Id).unwrap_or_default() id.parse::<i64>().map(ObjectPath::Id).unwrap_or_default()
} }
_ => Default::default(), _ => Default::default(),
} }
...@@ -119,18 +120,24 @@ impl From<ZValue<'_>> for ObjectPath { ...@@ -119,18 +120,24 @@ impl From<ZValue<'_>> for ObjectPath {
impl From<ObjectPath> for ZValue<'_> { impl From<ObjectPath> for ZValue<'_> {
fn from(value: ObjectPath) -> Self { fn from(value: ObjectPath) -> Self {
let string = 'string: {
use ObjectPath::*; use ObjectPath::*;
ZValue::ObjectPath( return ZValue::ObjectPath(
match value { match value {
None => ZObjectPath::try_from("/org/mpris/MediaPlayer2/None"), // Static things
NoTrack => ZObjectPath::try_from("/org/mpris/MediaPlayer2/TrackList/NoTrack"), NoTrack => ZObjectPath::try_from("/org/mpris/MediaPlayer2/TrackList/NoTrack"),
Id(id) => ZObjectPath::try_from(format!("/org/mpris/MediaPlayer2/Id/{id}")), None => ZObjectPath::try_from("/org/lektor/MPRIS/None"),
// Formated as strings
Id(id) => break 'string format!("/org/lektor/MPRIS/Id/{id}"),
Position(position) => { Position(position) => {
ZObjectPath::try_from(format!("/org/mpris/MediaPlayer2/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"))
} }
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter