diff --git a/Cargo.lock b/Cargo.lock index 95d51b2..500afb9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -601,6 +601,7 @@ dependencies = [ name = "hammond-gtk" version = "0.1.0" dependencies = [ + "chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "diesel 0.99.0 (registry+https://github.com/rust-lang/crates.io-index)", "dissolve 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/hammond-data/src/parser.rs b/hammond-data/src/parser.rs index 393ac54..566b06f 100644 --- a/hammond-data/src/parser.rs +++ b/hammond-data/src/parser.rs @@ -33,6 +33,7 @@ pub(crate) fn new_podcast(chan: &Channel, source_id: i32) -> NewPodcast { } /// Parses an `rss::Item` into a `NewEpisode` Struct. +// TODO: parse itunes duration extension. pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result { if item.title().is_none() { bail!("No title specified for the item.") diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index 810cbbb..b1cf01e 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -6,6 +6,7 @@ version = "0.1.0" workspace = "../" [dependencies] +chrono = "0.4.0" dissolve = "0.2.2" gdk = "0.7.0" gdk-pixbuf = "0.3.0" diff --git a/hammond-gtk/resources/gtk/episode_widget.ui b/hammond-gtk/resources/gtk/episode_widget.ui index 7e6106d..2e7558e 100644 --- a/hammond-gtk/resources/gtk/episode_widget.ui +++ b/hammond-gtk/resources/gtk/episode_widget.ui @@ -18,15 +18,27 @@ vertical 5 - + True False - start - Episode Title - True - True - end - 1 + + + True + False + start + Episode Title + True + True + end + False + 1 + + + False + True + 0 + + True @@ -40,10 +52,11 @@ False 5 - + True False - 42 min + 1970/01/01 + False False @@ -52,10 +65,10 @@ - - True + False - 42 mb + True + · False @@ -64,9 +77,11 @@ - + False - document-save-symbolic + True + 42 min + False False @@ -74,6 +89,44 @@ 2 + + + True + False + · + + + False + True + 3 + + + + + True + False + 42 MB + False + + + False + True + 4 + + + + + False + True + 12 MB / 42 MB + False + + + False + True + 5 + + True @@ -185,7 +238,6 @@ True True - 5 0 diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 0c594b9..5b1bac6 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -6,6 +6,7 @@ extern crate gio; extern crate glib; extern crate gtk; +extern crate chrono; extern crate diesel; extern crate dissolve; extern crate hammond_data; diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 746ea53..54d2620 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -1,6 +1,8 @@ use glib; use gtk; + use gtk::prelude::*; +use chrono::prelude::*; use open; @@ -38,10 +40,11 @@ struct EpisodeWidget { download: gtk::Button, cancel: gtk::Button, title: gtk::Label, + date: gtk::Label, duration: gtk::Label, size: gtk::Label, progress: gtk::ProgressBar, - an_indicator: gtk::Image, + progress_label: gtk::Label, } impl EpisodeWidget { @@ -49,9 +52,7 @@ impl EpisodeWidget { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui"); let container: gtk::Box = builder.get_object("episode_container").unwrap(); - let progress: gtk::ProgressBar = builder.get_object("progress_bar").unwrap(); - let an_indicator: gtk::Image = builder.get_object("an_indicator").unwrap(); let download: gtk::Button = builder.get_object("download_button").unwrap(); let play: gtk::Button = builder.get_object("play_button").unwrap(); @@ -59,13 +60,14 @@ impl EpisodeWidget { let cancel: gtk::Button = builder.get_object("cancel_button").unwrap(); let title: gtk::Label = builder.get_object("title_label").unwrap(); + let date: gtk::Label = builder.get_object("date_label").unwrap(); let duration: gtk::Label = builder.get_object("duration_label").unwrap(); let size: gtk::Label = builder.get_object("size_label").unwrap(); + let progress_label: gtk::Label = builder.get_object("progress_label").unwrap(); EpisodeWidget { container, progress, - an_indicator, download, play, cancel, @@ -73,6 +75,8 @@ impl EpisodeWidget { title, duration, size, + date, + progress_label, } } @@ -86,7 +90,6 @@ impl EpisodeWidget { // TODO: wire the progress_bar to the downloader. // TODO: wire the cancel button. fn init(&self, episode: &mut EpisodeWidgetQuery, pd: &Podcast) { - self.duration.hide(); self.title.set_xalign(0.0); self.title.set_text(episode.title()); self.progress.set_pulse_step(0.1); @@ -98,10 +101,15 @@ impl EpisodeWidget { }); if let Some(size) = episode.length() { - let megabytes: f32 = size as f32 / 1024.0 / 1024.0; // episode.length represents bytes - self.size.set_text(&format!("{:.1} mb", megabytes)) + let megabytes = size / 1024 / 1024; // episode.length represents bytes + self.size.set_text(&format!("{} MB", megabytes)) }; + let date = Utc.timestamp(i64::from(episode.epoch()), 0) + .format("%b %e") + .to_string(); + self.date.set_text(&date); + // Show or hide the play/delete/download buttons upon widget initialization. let local_uri = episode.local_uri(); if local_uri.is_some() && Path::new(local_uri.unwrap()).exists() {