EpisodeWidget: Do not display size if it's 0 bytes.

This commit is contained in:
Jordan Petridis 2017-12-23 15:44:28 +02:00
parent 37dbfff766
commit 2d6f02c407
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
3 changed files with 12 additions and 8 deletions

View File

@ -63,7 +63,7 @@ pub(crate) fn new_episode(item: &Item, parent_id: i32) -> Result<NewEpisode> {
let pub_date = date.map(|x| x.to_rfc2822()).ok(); let pub_date = date.map(|x| x.to_rfc2822()).ok();
let epoch = date.map(|x| x.timestamp() as i32).unwrap_or(0); let epoch = date.map(|x| x.timestamp() as i32).unwrap_or(0);
let length = item.enclosure().map(|x| x.length().parse().unwrap_or(0)); let length = || -> Option<i32> { item.enclosure().map(|x| x.length().parse().ok())? }();
let duration = parse_itunes_duration(item); let duration = parse_itunes_duration(item);
Ok(NewEpisodeBuilder::default() Ok(NewEpisodeBuilder::default()

View File

@ -104,8 +104,8 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="separator2"> <object class="GtkLabel" id="separator2">
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes">·</property> <property name="label" translatable="yes">·</property>
<property name="track_visited_links">False</property> <property name="track_visited_links">False</property>
<style> <style>
@ -120,7 +120,6 @@
</child> </child>
<child> <child>
<object class="GtkLabel" id="size_label"> <object class="GtkLabel" id="size_label">
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="no_show_all">True</property> <property name="no_show_all">True</property>
<property name="label" translatable="yes">42 MB</property> <property name="label" translatable="yes">42 MB</property>

View File

@ -47,6 +47,7 @@ pub struct EpisodeWidget {
progress: gtk::ProgressBar, progress: gtk::ProgressBar,
progress_label: gtk::Label, progress_label: gtk::Label,
separator1: gtk::Label, separator1: gtk::Label,
separator2: gtk::Label,
} }
impl Default for EpisodeWidget { impl Default for EpisodeWidget {
@ -68,6 +69,7 @@ impl Default for EpisodeWidget {
let progress_label: gtk::Label = builder.get_object("progress_label").unwrap(); let progress_label: gtk::Label = builder.get_object("progress_label").unwrap();
let separator1: gtk::Label = builder.get_object("separator1").unwrap(); let separator1: gtk::Label = builder.get_object("separator1").unwrap();
let separator2: gtk::Label = builder.get_object("separator2").unwrap();
EpisodeWidget { EpisodeWidget {
container, container,
@ -82,6 +84,7 @@ impl Default for EpisodeWidget {
date, date,
progress_label, progress_label,
separator1, separator1,
separator2,
} }
} }
} }
@ -120,11 +123,13 @@ impl EpisodeWidget {
}; };
if let Some(size) = episode.length() { if let Some(size) = episode.length() {
let s = size.file_size(custom_options); if size != 0 {
if let Ok(s) = s { let s = size.file_size(custom_options);
self.size.set_text(&s); if let Ok(s) = s {
} else { self.size.set_text(&s);
self.size.hide(); self.size.show();
self.separator2.show();
}
} }
}; };