EpisodeWidget: Change the byte unit based on the size. Closes #18.
This commit is contained in:
parent
c8310b1eb9
commit
378b8609aa
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -611,6 +611,7 @@ dependencies = [
|
||||
"gtk 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hammond-data 0.1.0",
|
||||
"hammond-downloader 0.1.0",
|
||||
"humansize 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"loggerv 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -637,6 +638,11 @@ name = "httparse"
|
||||
version = "1.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "humansize"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "0.11.9"
|
||||
@ -1680,6 +1686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum gtk-sys 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "905fcfbaaad1b44ec0b4bba9e4d527d728284c62bc2ba41fccedace2b096766f"
|
||||
"checksum html5ever 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba3a1fd1857a714d410c191364c5d7bf8a6487c0ab5575146d37dd7eb17ef523"
|
||||
"checksum httparse 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "af2f2dd97457e8fb1ae7c5a420db346af389926e36f43768b96f101546b04a07"
|
||||
"checksum humansize 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d99804bdb0790b0c312a5a1115f83804b821f1a96d80759fbb57ce796d1f3778"
|
||||
"checksum hyper 0.11.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e0594792d2109069d0caffd176f674d770a84adf024c5bb48e686b1ee5ac7659"
|
||||
"checksum hyper-tls 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9c81fa95203e2a6087242c38691a0210f23e9f3f8f944350bd676522132e2985"
|
||||
"checksum idna 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "014b298351066f1512874135335d62a789ffe78a9974f94b43ed5621951eaf7d"
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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]
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user