From 80f0f138f3df9bb872c9abebde712c7a3b94fd66 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Wed, 18 Oct 2017 03:13:16 +0300 Subject: [PATCH] Wired playbutton to use xdg-open for the files. --- Cargo.lock | 7 +++++++ hammond-gtk/Cargo.toml | 1 + hammond-gtk/gtk/EpisodeWidget.ui | 1 - hammond-gtk/src/main.rs | 28 +++++++++++++++++++++------- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52e2e54..a6d7ada 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12,6 +12,7 @@ dependencies = [ "hammond-downloader 0.1.0", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "loggerv 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -940,6 +941,11 @@ dependencies = [ "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "open" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "openssl" version = "0.9.20" @@ -1703,6 +1709,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum num-iter 0.1.34 (registry+https://github.com/rust-lang/crates.io-index)" = "7485fcc84f85b4ecd0ea527b14189281cf27d60e583ae65ebc9c088b13dffe01" "checksum num-traits 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "99843c856d68d8b4313b03a17e33c4bb42ae8f6610ea81b28abe076ac721b9b0" "checksum num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "514f0d73e64be53ff320680ca671b64fe3fb91da01e1ae2ddc99eb51d453b20d" +"checksum open 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c281318d992e4432cfa799969467003d05921582a7489a8325e37f8a450d5113" "checksum openssl 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)" = "8bf434ff6117485dc16478d77a4f5c84eccc9c3645c4da8323b287ad6a15a638" "checksum openssl-sys 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)" = "0ad395f1cee51b64a8d07cc8063498dc7554db62d5f3ca87a67f4eed2791d0c8" "checksum pango 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5afa4b4c5380315b12075e7767d9bdd62d53beeb6087d9287ef6990e57a6b643" diff --git a/hammond-gtk/Cargo.toml b/hammond-gtk/Cargo.toml index 2d64830..08095f3 100644 --- a/hammond-gtk/Cargo.toml +++ b/hammond-gtk/Cargo.toml @@ -14,6 +14,7 @@ gdk-pixbuf = "0.2" diesel = { version = "0.16", features = ["sqlite"] } loggerv = "0.3" log = "0.3" +open = "1.2" hammond-data = {path = "../hammond-data"} hammond-downloader = {path = "../hammond-downloader"} diff --git a/hammond-gtk/gtk/EpisodeWidget.ui b/hammond-gtk/gtk/EpisodeWidget.ui index 9a79b4e..96cbf12 100644 --- a/hammond-gtk/gtk/EpisodeWidget.ui +++ b/hammond-gtk/gtk/EpisodeWidget.ui @@ -83,7 +83,6 @@ - True True True center diff --git a/hammond-gtk/src/main.rs b/hammond-gtk/src/main.rs index 7e42c28..e8b2992 100644 --- a/hammond-gtk/src/main.rs +++ b/hammond-gtk/src/main.rs @@ -1,20 +1,22 @@ // extern crate glib; -extern crate diesel; extern crate gdk; extern crate gdk_pixbuf; extern crate gio; extern crate gtk; +extern crate diesel; extern crate hammond_data; extern crate hammond_downloader; #[macro_use] extern crate log; extern crate loggerv; +extern crate open; use log::LogLevel; use diesel::prelude::*; use hammond_data::dbqueries; +use hammond_data::models::Episode; use std::rc; use std::thread; @@ -109,14 +111,14 @@ fn podcast_widget( pd_widget } -fn epidose_widget(title: Option<&str>, description: Option<&str>) -> gtk::Box { +fn epidose_widget(episode: &Episode) -> gtk::Box { // This is just a prototype and will be reworked probably. let builder = include_str!("../gtk/EpisodeWidget.ui"); let builder = gtk::Builder::new_from_string(builder); let ep: gtk::Box = builder.get_object("episode_box").unwrap(); - let _dl_button: gtk::Button = builder.get_object("download_button").unwrap(); - let _play_button: gtk::Button = builder.get_object("play_button").unwrap(); + let dl_button: gtk::Button = builder.get_object("download_button").unwrap(); + let play_button: gtk::Button = builder.get_object("play_button").unwrap(); let title_label: gtk::Label = builder.get_object("title_label").unwrap(); let desc_label: gtk::Label = builder.get_object("desc_label").unwrap(); @@ -124,14 +126,26 @@ fn epidose_widget(title: Option<&str>, description: Option<&str>) -> gtk::Box { title_label.set_xalign(0.0); desc_label.set_xalign(0.0); - if let Some(t) = title { + if let Some(t) = episode.title() { title_label.set_text(t); } - if let Some(d) = description { + if let Some(d) = episode.description() { desc_label.set_text(d); } + if let Some(_) = episode.local_uri() { + dl_button.hide(); + play_button.show(); + let uri = episode.local_uri().unwrap().to_owned(); + play_button.connect_clicked(move |_| { + let e = open::that(&uri); + if e.is_err() { + error!("Error while trying to open: {}", uri); + } + }); + } + ep } @@ -141,7 +155,7 @@ fn episodes_listbox(connection: &SqliteConnection, pd_title: &str) -> gtk::ListB let list = gtk::ListBox::new(); episodes.iter().for_each(|ep| { - let w = epidose_widget(ep.title(), ep.description()); + let w = epidose_widget(ep); list.add(&w) });