mod imp;
use crate::utils::csv_song_history::{Song, SongHistoryRecord};
glib::wrapper! {
pub struct HistoryEntry(ObjectSubclass<imp::HistoryEntry>);
}
impl HistoryEntry {
pub fn new(song: &SongHistoryRecord) -> Self {
glib::Object::builder()
.property("song_name", song.song_name.clone())
.property("album", song.album.clone())
.property("track_key", song.track_key.clone())
.property("release_year", song.release_year.clone())
.property("genre", song.genre.clone())
.property("recognition_date", song.recognition_date.clone())
.build()
}
pub fn get_song_history_record(&self) -> SongHistoryRecord {
SongHistoryRecord {
song_name: self.song_name(),
album: self.album(),
track_key: self.track_key(),
release_year: self.release_year(),
genre: self.genre(),
recognition_date: self.recognition_date(),
}
}
pub fn get_song(&self) -> Song {
Song {
song_name: self.song_name(),
album: match self.album() {
Some(val) => {
if &val == "" {
None
} else {
Some(val)
}
}
None => None,
},
track_key: match self.track_key() {
Some(val) => {
if &val == "" {
None
} else {
Some(val)
}
}
None => None,
},
release_year: match self.release_year() {
Some(val) => {
if &val == "" {
None
} else {
Some(val)
}
}
None => None,
},
genre: match self.genre() {
Some(val) => {
if &val == "" {
None
} else {
Some(val)
}
}
None => None,
},
}
}
}