1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
use std::fmt;
use serde::Deserialize;
use zbus::zvariant::{Type, Value};
/// Specifies the ordering of returned playlists.
///
/// <details><summary>Rationale</summary>
///
/// Some media players may allow users to order playlists
/// as they wish. This ordering allows playlists to be retrieved
/// in that order.
///
/// </details>
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Type)]
#[zvariant(signature = "s")]
#[doc(alias = "Playlist_Ordering")]
pub enum PlaylistOrdering {
/// Alphabetical ordering by name, ascending.
Alphabetical,
/// Ordering by creation date, oldest first.
CreationDate,
/// Ordering by last modified date, oldest first.
ModifiedDate,
/// Ordering by date of last playback, oldest first.
LastPlayDate,
/// A user-defined ordering.
UserDefined,
}
impl PlaylistOrdering {
/// Returns the string representation of this playlist ordering.
pub fn as_str(&self) -> &'static str {
match self {
Self::Alphabetical => "Alphabetical",
Self::CreationDate => "Created",
Self::ModifiedDate => "Modified",
Self::LastPlayDate => "Played",
Self::UserDefined => "User",
}
}
}
impl fmt::Display for PlaylistOrdering {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.as_str())
}
}
impl<'a> From<PlaylistOrdering> for Value<'a> {
fn from(status: PlaylistOrdering) -> Self {
Value::new(status.as_str())
}
}