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);
#[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"))
}
}
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter