2023-10-25 17:45:32 +02:00
|
|
|
use gtk::{glib, glib::Properties, prelude::*, subclass::prelude::*};
|
|
|
|
|
use std::{
|
2023-10-26 11:48:42 +02:00
|
|
|
cell::{Cell, OnceCell},
|
2023-10-25 17:45:32 +02:00
|
|
|
path::{Path, PathBuf},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
mod imp {
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
#[derive(Properties, Default)]
|
|
|
|
|
#[properties(wrapper_type = super::PlaylistItem)]
|
|
|
|
|
pub struct PlaylistItem {
|
2023-10-26 11:48:42 +02:00
|
|
|
#[property(get, set)]
|
|
|
|
|
pub is_playing: Cell<bool>,
|
|
|
|
|
|
2023-10-25 17:45:32 +02:00
|
|
|
#[property(get, construct_only)]
|
|
|
|
|
pub is_title: OnceCell<bool>,
|
|
|
|
|
|
2023-10-27 14:15:05 +02:00
|
|
|
#[property(get, construct_only)]
|
|
|
|
|
pub title: OnceCell<String>,
|
2023-10-25 17:45:32 +02:00
|
|
|
|
|
|
|
|
#[property(get, construct_only, nullable)]
|
|
|
|
|
pub performers: OnceCell<Option<String>>,
|
|
|
|
|
|
|
|
|
|
#[property(get, construct_only, nullable)]
|
|
|
|
|
pub part_title: OnceCell<Option<String>>,
|
|
|
|
|
|
|
|
|
|
#[property(get, construct_only)]
|
|
|
|
|
pub path: OnceCell<PathBuf>,
|
2024-06-10 20:53:15 +02:00
|
|
|
|
|
|
|
|
#[property(get, construct_only)]
|
|
|
|
|
pub track_id: OnceCell<String>,
|
2023-10-25 17:45:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::object_subclass]
|
|
|
|
|
impl ObjectSubclass for PlaylistItem {
|
|
|
|
|
const NAME: &'static str = "MusicusPlaylistItem";
|
|
|
|
|
type Type = super::PlaylistItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[glib::derived_properties]
|
|
|
|
|
impl ObjectImpl for PlaylistItem {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glib::wrapper! {
|
|
|
|
|
pub struct PlaylistItem(ObjectSubclass<imp::PlaylistItem>);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl PlaylistItem {
|
|
|
|
|
pub fn new(
|
2023-10-27 14:15:05 +02:00
|
|
|
is_title: bool,
|
2023-10-25 17:45:32 +02:00
|
|
|
title: &str,
|
|
|
|
|
performers: Option<&str>,
|
|
|
|
|
part_title: Option<&str>,
|
|
|
|
|
path: impl AsRef<Path>,
|
2024-06-10 20:53:15 +02:00
|
|
|
track_id: &str,
|
2023-10-25 17:45:32 +02:00
|
|
|
) -> Self {
|
|
|
|
|
glib::Object::builder()
|
2023-10-27 14:15:05 +02:00
|
|
|
.property("is-title", is_title)
|
2023-10-25 17:45:32 +02:00
|
|
|
.property("title", title)
|
|
|
|
|
.property("performers", performers)
|
|
|
|
|
.property("part-title", part_title)
|
|
|
|
|
.property("path", path.as_ref())
|
2024-06-10 20:53:15 +02:00
|
|
|
.property("track-id", track_id)
|
2023-10-25 17:45:32 +02:00
|
|
|
.build()
|
|
|
|
|
}
|
2023-11-03 18:20:41 +01:00
|
|
|
|
|
|
|
|
pub fn make_title(&self) -> String {
|
|
|
|
|
let mut title = self.title();
|
|
|
|
|
|
|
|
|
|
if let Some(part_title) = self.part_title() {
|
|
|
|
|
title.push_str(": ");
|
|
|
|
|
title.push_str(&part_title);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
title
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn make_subtitle(&self) -> Option<String> {
|
|
|
|
|
self.performers()
|
|
|
|
|
}
|
2023-10-25 17:45:32 +02:00
|
|
|
}
|