Added date label into EpisodeWidget.
This commit is contained in:
parent
e3b540170a
commit
0ac78fcff1
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -601,6 +601,7 @@ dependencies = [
|
|||||||
name = "hammond-gtk"
|
name = "hammond-gtk"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
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)",
|
"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)",
|
"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)",
|
"gdk 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|||||||
@ -33,6 +33,7 @@ pub(crate) fn new_podcast(chan: &Channel, source_id: i32) -> NewPodcast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Parses an `rss::Item` into a `NewEpisode` Struct.
|
/// Parses an `rss::Item` into a `NewEpisode` Struct.
|
||||||
|
// TODO: parse itunes duration extension.
|
||||||
pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
|
pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
|
||||||
if item.title().is_none() {
|
if item.title().is_none() {
|
||||||
bail!("No title specified for the item.")
|
bail!("No title specified for the item.")
|
||||||
|
|||||||
@ -6,6 +6,7 @@ version = "0.1.0"
|
|||||||
workspace = "../"
|
workspace = "../"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
chrono = "0.4.0"
|
||||||
dissolve = "0.2.2"
|
dissolve = "0.2.2"
|
||||||
gdk = "0.7.0"
|
gdk = "0.7.0"
|
||||||
gdk-pixbuf = "0.3.0"
|
gdk-pixbuf = "0.3.0"
|
||||||
|
|||||||
@ -17,6 +17,10 @@
|
|||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="orientation">vertical</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="spacing">5</property>
|
<property name="spacing">5</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="title_label">
|
<object class="GtkLabel" id="title_label">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@ -26,8 +30,16 @@
|
|||||||
<property name="use_markup">True</property>
|
<property name="use_markup">True</property>
|
||||||
<property name="wrap">True</property>
|
<property name="wrap">True</property>
|
||||||
<property name="ellipsize">end</property>
|
<property name="ellipsize">end</property>
|
||||||
|
<property name="track_visited_links">False</property>
|
||||||
<property name="lines">1</property>
|
<property name="lines">1</property>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
@ -40,10 +52,11 @@
|
|||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="spacing">5</property>
|
<property name="spacing">5</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="duration_label">
|
<object class="GtkLabel" id="date_label">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="label" translatable="yes">42 min</property>
|
<property name="label" translatable="yes">1970/01/01</property>
|
||||||
|
<property name="track_visited_links">False</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -52,10 +65,10 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkLabel" id="size_label">
|
<object class="GtkLabel">
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="label" translatable="yes">42 mb</property>
|
<property name="no_show_all">True</property>
|
||||||
|
<property name="label" translatable="yes">·</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -64,9 +77,11 @@
|
|||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="an_indicator">
|
<object class="GtkLabel" id="duration_label">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="icon_name">document-save-symbolic</property>
|
<property name="no_show_all">True</property>
|
||||||
|
<property name="label" translatable="yes">42 min</property>
|
||||||
|
<property name="track_visited_links">False</property>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
@ -74,6 +89,44 @@
|
|||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">·</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="size_label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label" translatable="yes">42 MB</property>
|
||||||
|
<property name="track_visited_links">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">4</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="progress_label">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="no_show_all">True</property>
|
||||||
|
<property name="label" translatable="yes">12 MB / 42 MB</property>
|
||||||
|
<property name="track_visited_links">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">5</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
@ -185,7 +238,6 @@
|
|||||||
<packing>
|
<packing>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="padding">5</property>
|
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
|||||||
@ -6,6 +6,7 @@ extern crate gio;
|
|||||||
extern crate glib;
|
extern crate glib;
|
||||||
extern crate gtk;
|
extern crate gtk;
|
||||||
|
|
||||||
|
extern crate chrono;
|
||||||
extern crate diesel;
|
extern crate diesel;
|
||||||
extern crate dissolve;
|
extern crate dissolve;
|
||||||
extern crate hammond_data;
|
extern crate hammond_data;
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
use glib;
|
use glib;
|
||||||
use gtk;
|
use gtk;
|
||||||
|
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
use chrono::prelude::*;
|
||||||
|
|
||||||
use open;
|
use open;
|
||||||
|
|
||||||
@ -38,10 +40,11 @@ struct EpisodeWidget {
|
|||||||
download: gtk::Button,
|
download: gtk::Button,
|
||||||
cancel: gtk::Button,
|
cancel: gtk::Button,
|
||||||
title: gtk::Label,
|
title: gtk::Label,
|
||||||
|
date: gtk::Label,
|
||||||
duration: gtk::Label,
|
duration: gtk::Label,
|
||||||
size: gtk::Label,
|
size: gtk::Label,
|
||||||
progress: gtk::ProgressBar,
|
progress: gtk::ProgressBar,
|
||||||
an_indicator: gtk::Image,
|
progress_label: gtk::Label,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EpisodeWidget {
|
impl EpisodeWidget {
|
||||||
@ -49,9 +52,7 @@ impl EpisodeWidget {
|
|||||||
let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/episode_widget.ui");
|
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 container: gtk::Box = builder.get_object("episode_container").unwrap();
|
||||||
|
|
||||||
let progress: gtk::ProgressBar = builder.get_object("progress_bar").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 download: gtk::Button = builder.get_object("download_button").unwrap();
|
||||||
let play: gtk::Button = builder.get_object("play_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 cancel: gtk::Button = builder.get_object("cancel_button").unwrap();
|
||||||
|
|
||||||
let title: gtk::Label = builder.get_object("title_label").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 duration: gtk::Label = builder.get_object("duration_label").unwrap();
|
||||||
let size: gtk::Label = builder.get_object("size_label").unwrap();
|
let size: gtk::Label = builder.get_object("size_label").unwrap();
|
||||||
|
let progress_label: gtk::Label = builder.get_object("progress_label").unwrap();
|
||||||
|
|
||||||
EpisodeWidget {
|
EpisodeWidget {
|
||||||
container,
|
container,
|
||||||
progress,
|
progress,
|
||||||
an_indicator,
|
|
||||||
download,
|
download,
|
||||||
play,
|
play,
|
||||||
cancel,
|
cancel,
|
||||||
@ -73,6 +75,8 @@ impl EpisodeWidget {
|
|||||||
title,
|
title,
|
||||||
duration,
|
duration,
|
||||||
size,
|
size,
|
||||||
|
date,
|
||||||
|
progress_label,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +90,6 @@ impl EpisodeWidget {
|
|||||||
// TODO: wire the progress_bar to the downloader.
|
// TODO: wire the progress_bar to the downloader.
|
||||||
// TODO: wire the cancel button.
|
// TODO: wire the cancel button.
|
||||||
fn init(&self, episode: &mut EpisodeWidgetQuery, pd: &Podcast) {
|
fn init(&self, episode: &mut EpisodeWidgetQuery, pd: &Podcast) {
|
||||||
self.duration.hide();
|
|
||||||
self.title.set_xalign(0.0);
|
self.title.set_xalign(0.0);
|
||||||
self.title.set_text(episode.title());
|
self.title.set_text(episode.title());
|
||||||
self.progress.set_pulse_step(0.1);
|
self.progress.set_pulse_step(0.1);
|
||||||
@ -98,10 +101,15 @@ impl EpisodeWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if let Some(size) = episode.length() {
|
if let Some(size) = episode.length() {
|
||||||
let megabytes: f32 = size as f32 / 1024.0 / 1024.0; // episode.length represents bytes
|
let megabytes = size / 1024 / 1024; // episode.length represents bytes
|
||||||
self.size.set_text(&format!("{:.1} mb", megabytes))
|
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.
|
// Show or hide the play/delete/download buttons upon widget initialization.
|
||||||
let local_uri = episode.local_uri();
|
let local_uri = episode.local_uri();
|
||||||
if local_uri.is_some() && Path::new(local_uri.unwrap()).exists() {
|
if local_uri.is_some() && Path::new(local_uri.unwrap()).exists() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user