mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
67 lines
1.8 KiB
Rust
67 lines
1.8 KiB
Rust
|
|
use gtk::{glib, glib::Properties, prelude::*, subclass::prelude::*};
|
||
|
|
use std::{
|
||
|
|
cell::OnceCell,
|
||
|
|
path::{Path, PathBuf},
|
||
|
|
};
|
||
|
|
|
||
|
|
mod imp {
|
||
|
|
use super::*;
|
||
|
|
|
||
|
|
#[derive(Properties, Default)]
|
||
|
|
#[properties(wrapper_type = super::PlaylistItem)]
|
||
|
|
pub struct PlaylistItem {
|
||
|
|
#[property(get, construct_only)]
|
||
|
|
pub is_title: OnceCell<bool>,
|
||
|
|
|
||
|
|
#[property(get, construct_only, nullable)]
|
||
|
|
pub title: OnceCell<Option<String>>,
|
||
|
|
|
||
|
|
#[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>,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[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(
|
||
|
|
title: &str,
|
||
|
|
performers: Option<&str>,
|
||
|
|
part_title: Option<&str>,
|
||
|
|
path: impl AsRef<Path>,
|
||
|
|
) -> Self {
|
||
|
|
glib::Object::builder()
|
||
|
|
.property("is-title", true)
|
||
|
|
.property("title", title)
|
||
|
|
.property("performers", performers)
|
||
|
|
.property("part-title", part_title)
|
||
|
|
.property("path", path.as_ref())
|
||
|
|
.build()
|
||
|
|
}
|
||
|
|
|
||
|
|
pub fn new_part(part_title: &str, path: impl AsRef<Path>) -> Self {
|
||
|
|
glib::Object::builder()
|
||
|
|
.property("is-title", false)
|
||
|
|
.property("part-title", part_title)
|
||
|
|
.property("path", path.as_ref())
|
||
|
|
.build()
|
||
|
|
}
|
||
|
|
}
|