EpisodeWidget: Change the byte unit based on the size. Closes #18.

This commit is contained in:
Jordan Petridis
2017-12-21 21:31:25 +02:00
parent c8310b1eb9
commit 378b8609aa
5 changed files with 18 additions and 2 deletions
+1
View File
@@ -12,6 +12,7 @@ gdk = "0.7.0"
gdk-pixbuf = "0.3.0"
gio = "0.3.0"
glib = "0.4.0"
humansize = "1.0.2"
lazy_static = "1.0.0"
log = "0.3.8"
loggerv = "0.6.0"
@@ -122,6 +122,7 @@
<object class="GtkLabel" id="size_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="no_show_all">True</property>
<property name="label" translatable="yes">42 MB</property>
<property name="single_line_mode">True</property>
<property name="track_visited_links">False</property>
+1
View File
@@ -11,6 +11,7 @@ extern crate diesel;
extern crate dissolve;
extern crate hammond_data;
extern crate hammond_downloader;
extern crate humansize;
#[macro_use]
extern crate lazy_static;
#[macro_use]
+8 -2
View File
@@ -5,6 +5,7 @@ use gtk::prelude::*;
use chrono::prelude::*;
use open;
use humansize::{file_size_opts as size_opts, FileSize};
use hammond_data::dbqueries;
use hammond_data::{EpisodeWidgetQuery, Podcast};
@@ -101,9 +102,14 @@ impl EpisodeWidget {
.map(|c| c.add_class("dim-label"));
}
// TODO: configure it so it will not show decimal places.
if let Some(size) = episode.length() {
let megabytes = size / 1024 / 1024; // episode.length represents bytes
self.size.set_text(&format!("{} MB", megabytes))
let s = size.file_size(size_opts::CONVENTIONAL);
if let Ok(s) = s {
self.size.set_text(&s);
} else {
self.size.hide();
}
};
let date = Utc.timestamp(i64::from(episode.epoch()), 0)